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 bool wilc_enable_ps = true;
17 static int dev_state_ev_handler(struct notifier_block *this,
18 unsigned long event, void *ptr)
20 struct in_ifaddr *dev_iface = ptr;
21 struct wilc_priv *priv;
22 struct host_if_drv *hif_drv;
23 struct net_device *dev;
27 char wlan_dev_name[5] = "wlan0";
29 if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
32 if (memcmp(dev_iface->ifa_label, "wlan0", 5) &&
33 memcmp(dev_iface->ifa_label, "p2p0", 4))
36 dev = (struct net_device *)dev_iface->ifa_dev->dev;
37 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
40 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
44 hif_drv = (struct host_if_drv *)priv->hif_drv;
45 vif = netdev_priv(dev);
51 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
53 wilc_optaining_ip = false;
54 del_timer(&wilc_during_ip_timer);
58 wilc_set_power_mgmt(vif, 1, 0);
60 netdev_dbg(dev, "[%s] Up IP\n", dev_iface->ifa_label);
62 ip_addr_buf = (char *)&dev_iface->ifa_address;
63 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
64 ip_addr_buf[0], ip_addr_buf[1],
65 ip_addr_buf[2], ip_addr_buf[3]);
66 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
71 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
73 wilc_optaining_ip = false;
76 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
77 wilc_set_power_mgmt(vif, 0, 0);
79 wilc_resolve_disconnect_aberration(vif);
81 netdev_dbg(dev, "[%s] Down IP\n", dev_iface->ifa_label);
83 ip_addr_buf = null_ip;
84 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
85 ip_addr_buf[0], ip_addr_buf[1],
86 ip_addr_buf[2], ip_addr_buf[3]);
88 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
99 static irqreturn_t isr_uh_routine(int irq, void *user_data)
101 struct net_device *dev = user_data;
102 struct wilc_vif *vif = netdev_priv(dev);
103 struct wilc *wilc = vif->wilc;
106 netdev_err(dev, "Can't handle UH interrupt\n");
109 return IRQ_WAKE_THREAD;
112 static irqreturn_t isr_bh_routine(int irq, void *userdata)
114 struct net_device *dev = userdata;
115 struct wilc_vif *vif = netdev_priv(userdata);
116 struct wilc *wilc = vif->wilc;
119 netdev_err(dev, "Can't handle BH interrupt\n");
123 wilc_handle_isr(wilc);
128 static int init_irq(struct net_device *dev)
131 struct wilc_vif *vif = netdev_priv(dev);
132 struct wilc *wl = vif->wilc;
134 ret = gpiod_direction_input(wl->gpio_irq);
136 netdev_err(dev, "could not obtain gpio for WILC_INTR\n");
140 wl->dev_irq_num = gpiod_to_irq(wl->gpio_irq);
142 ret = request_threaded_irq(wl->dev_irq_num, isr_uh_routine,
144 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
147 netdev_err(dev, "Failed to request IRQ\n");
149 netdev_dbg(dev, "IRQ request succeeded IRQ-NUM= %d\n",
155 static void deinit_irq(struct net_device *dev)
157 struct wilc_vif *vif = netdev_priv(dev);
158 struct wilc *wilc = vif->wilc;
160 /* Deinitialize IRQ */
161 if (wilc->dev_irq_num)
162 free_irq(wilc->dev_irq_num, wilc);
165 void wilc_mac_indicate(struct wilc *wilc)
169 wilc_wlan_cfg_get_val(WID_STATUS, (unsigned char *)&status, 4);
170 if (wilc->mac_status == MAC_STATUS_INIT) {
171 wilc->mac_status = status;
172 complete(&wilc->sync_event);
174 wilc->mac_status = status;
178 static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
183 bssid = mac_header + 10;
184 bssid1 = mac_header + 4;
186 for (i = 0; i < wilc->vif_num; i++) {
187 if (wilc->vif[i]->mode == STATION_MODE)
188 if (ether_addr_equal_unaligned(bssid,
189 wilc->vif[i]->bssid))
190 return wilc->vif[i]->ndev;
191 if (wilc->vif[i]->mode == AP_MODE)
192 if (ether_addr_equal_unaligned(bssid1,
193 wilc->vif[i]->bssid))
194 return wilc->vif[i]->ndev;
200 int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
202 struct wilc_vif *vif = netdev_priv(wilc_netdev);
204 memcpy(vif->bssid, bssid, 6);
210 int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
213 u8 null_bssid[6] = {0};
216 for (i = 0; i < wilc->vif_num; i++)
217 if (memcmp(wilc->vif[i]->bssid, null_bssid, 6))
223 static int linux_wlan_txq_task(void *vp)
227 struct net_device *dev = vp;
228 struct wilc_vif *vif = netdev_priv(dev);
229 struct wilc *wl = vif->wilc;
231 complete(&wl->txq_thread_started);
233 wait_for_completion(&wl->txq_event);
236 complete(&wl->txq_thread_started);
238 while (!kthread_should_stop())
243 ret = wilc_wlan_handle_txq(dev, &txq_count);
244 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
245 if (netif_queue_stopped(wl->vif[0]->ndev))
246 netif_wake_queue(wl->vif[0]->ndev);
247 if (netif_queue_stopped(wl->vif[1]->ndev))
248 netif_wake_queue(wl->vif[1]->ndev);
250 } while (ret == WILC_TX_ERR_NO_BUF && !wl->close);
255 static int wilc_wlan_get_firmware(struct net_device *dev)
257 struct wilc_vif *vif = netdev_priv(dev);
258 struct wilc *wilc = vif->wilc;
259 int chip_id, ret = 0;
260 const struct firmware *wilc_firmware;
263 chip_id = wilc_get_chipid(wilc, false);
265 if (chip_id < 0x1003a0)
266 firmware = FIRMWARE_1002;
268 firmware = FIRMWARE_1003;
270 netdev_info(dev, "loading firmware %s\n", firmware);
272 if (!(&vif->ndev->dev))
275 if (reject_firmware(&wilc_firmware, firmware, wilc->dev) != 0) {
276 netdev_err(dev, "%s - firmware not available\n", firmware);
280 wilc->firmware = wilc_firmware;
287 static int linux_wlan_start_firmware(struct net_device *dev)
289 struct wilc_vif *vif = netdev_priv(dev);
290 struct wilc *wilc = vif->wilc;
293 ret = wilc_wlan_start(wilc);
297 if (!wait_for_completion_timeout(&wilc->sync_event,
298 msecs_to_jiffies(5000)))
304 static int wilc1000_firmware_download(struct net_device *dev)
306 struct wilc_vif *vif = netdev_priv(dev);
307 struct wilc *wilc = vif->wilc;
310 if (!wilc->firmware) {
311 netdev_err(dev, "Firmware buffer is NULL\n");
315 ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data,
316 wilc->firmware->size);
320 release_firmware(wilc->firmware);
321 wilc->firmware = NULL;
323 netdev_dbg(dev, "Download Succeeded\n");
328 static int linux_wlan_init_test_config(struct net_device *dev,
329 struct wilc_vif *vif)
331 unsigned char c_val[64];
332 struct wilc *wilc = vif->wilc;
333 struct wilc_priv *priv;
334 struct host_if_drv *hif_drv;
336 netdev_dbg(dev, "Start configuring Firmware\n");
337 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
338 hif_drv = (struct host_if_drv *)priv->hif_drv;
339 netdev_dbg(dev, "Host = %p\n", hif_drv);
340 wilc_get_chipid(wilc, false);
344 if (!wilc_wlan_cfg_set(vif, 1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
348 if (!wilc_wlan_cfg_set(vif, 0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
351 c_val[0] = INFRASTRUCTURE;
352 if (!wilc_wlan_cfg_set(vif, 0, WID_BSS_TYPE, c_val, 1, 0, 0))
356 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
359 c_val[0] = G_MIXED_11B_2_MODE;
360 if (!wilc_wlan_cfg_set(vif, 0, WID_11G_OPERATING_MODE, c_val, 1, 0,
365 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
368 c_val[0] = G_SHORT_PREAMBLE;
369 if (!wilc_wlan_cfg_set(vif, 0, WID_PREAMBLE, c_val, 1, 0, 0))
372 c_val[0] = AUTO_PROT;
373 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
376 c_val[0] = ACTIVE_SCAN;
377 if (!wilc_wlan_cfg_set(vif, 0, WID_SCAN_TYPE, c_val, 1, 0, 0))
380 c_val[0] = SITE_SURVEY_OFF;
381 if (!wilc_wlan_cfg_set(vif, 0, WID_SITE_SURVEY, c_val, 1, 0, 0))
384 *((int *)c_val) = 0xffff;
385 if (!wilc_wlan_cfg_set(vif, 0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
388 *((int *)c_val) = 2346;
389 if (!wilc_wlan_cfg_set(vif, 0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
393 if (!wilc_wlan_cfg_set(vif, 0, WID_BCAST_SSID, c_val, 1, 0, 0))
397 if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, c_val, 1, 0, 0))
400 c_val[0] = NO_POWERSAVE;
401 if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
404 c_val[0] = NO_SECURITY; /* NO_ENCRYPT, 0x79 */
405 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_MODE, c_val, 1, 0, 0))
408 c_val[0] = OPEN_SYSTEM;
409 if (!wilc_wlan_cfg_set(vif, 0, WID_AUTH_TYPE, c_val, 1, 0, 0))
412 strcpy(c_val, "123456790abcdef1234567890");
413 if (!wilc_wlan_cfg_set(vif, 0, WID_WEP_KEY_VALUE, c_val,
414 (strlen(c_val) + 1), 0, 0))
417 strcpy(c_val, "12345678");
418 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_PSK, c_val, (strlen(c_val)), 0,
422 strcpy(c_val, "password");
423 if (!wilc_wlan_cfg_set(vif, 0, WID_1X_KEY, c_val, (strlen(c_val) + 1),
431 if (!wilc_wlan_cfg_set(vif, 0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
435 if (!wilc_wlan_cfg_set(vif, 0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
439 if (!wilc_wlan_cfg_set(vif, 0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
442 c_val[0] = NORMAL_ACK;
443 if (!wilc_wlan_cfg_set(vif, 0, WID_ACK_POLICY, c_val, 1, 0, 0))
447 if (!wilc_wlan_cfg_set(vif, 0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1,
452 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0,
457 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0,
461 *((int *)c_val) = 100;
462 if (!wilc_wlan_cfg_set(vif, 0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
465 c_val[0] = REKEY_DISABLE;
466 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_POLICY, c_val, 1, 0, 0))
469 *((int *)c_val) = 84600;
470 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
473 *((int *)c_val) = 500;
474 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PACKET_COUNT, c_val, 4, 0,
479 if (!wilc_wlan_cfg_set(vif, 0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0,
483 c_val[0] = G_SELF_CTS_PROT;
484 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
488 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ENABLE, c_val, 1, 0, 0))
491 c_val[0] = HT_MIXED_MODE;
492 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OPERATING_MODE, c_val, 1, 0,
497 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0,
501 c_val[0] = DETECT_PROTECT_REPORT;
502 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1,
506 c_val[0] = RTS_CTS_NONHT_PROT;
507 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
511 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0,
515 c_val[0] = MIMO_MODE;
516 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
520 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0,
525 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1,
535 static int wlan_deinit_locks(struct net_device *dev)
537 struct wilc_vif *vif = netdev_priv(dev);
538 struct wilc *wilc = vif->wilc;
540 mutex_destroy(&wilc->hif_cs);
541 mutex_destroy(&wilc->rxq_cs);
542 mutex_destroy(&wilc->txq_add_to_head_cs);
547 static void wlan_deinitialize_threads(struct net_device *dev)
549 struct wilc_vif *vif = netdev_priv(dev);
550 struct wilc *wl = vif->wilc;
554 complete(&wl->txq_event);
556 if (wl->txq_thread) {
557 kthread_stop(wl->txq_thread);
558 wl->txq_thread = NULL;
562 static void wilc_wlan_deinitialize(struct net_device *dev)
564 struct wilc_vif *vif = netdev_priv(dev);
565 struct wilc *wl = vif->wilc;
568 netdev_err(dev, "wl is NULL\n");
572 if (wl->initialized) {
573 netdev_info(dev, "Deinitializing wilc1000...\n");
575 if (!wl->dev_irq_num &&
576 wl->hif_func->disable_interrupt) {
577 mutex_lock(&wl->hif_cs);
578 wl->hif_func->disable_interrupt(wl);
579 mutex_unlock(&wl->hif_cs);
581 complete(&wl->txq_event);
583 wlan_deinitialize_threads(dev);
587 wilc_wlan_cleanup(dev);
588 wlan_deinit_locks(dev);
590 wl->initialized = false;
592 netdev_dbg(dev, "wilc1000 deinitialization Done\n");
594 netdev_dbg(dev, "wilc1000 is not initialized\n");
598 static int wlan_init_locks(struct net_device *dev)
600 struct wilc_vif *vif = netdev_priv(dev);
601 struct wilc *wl = vif->wilc;
603 mutex_init(&wl->hif_cs);
604 mutex_init(&wl->rxq_cs);
606 spin_lock_init(&wl->txq_spinlock);
607 mutex_init(&wl->txq_add_to_head_cs);
609 init_completion(&wl->txq_event);
611 init_completion(&wl->cfg_event);
612 init_completion(&wl->sync_event);
613 init_completion(&wl->txq_thread_started);
618 static int wlan_initialize_threads(struct net_device *dev)
620 struct wilc_vif *vif = netdev_priv(dev);
621 struct wilc *wilc = vif->wilc;
623 wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev,
625 if (IS_ERR(wilc->txq_thread)) {
626 netdev_err(dev, "couldn't create TXQ thread\n");
628 return PTR_ERR(wilc->txq_thread);
630 wait_for_completion(&wilc->txq_thread_started);
635 static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
638 struct wilc *wl = vif->wilc;
640 if (!wl->initialized) {
641 wl->mac_status = MAC_STATUS_INIT;
644 wlan_init_locks(dev);
646 ret = wilc_wlan_init(dev);
652 ret = wlan_initialize_threads(dev);
658 if (wl->gpio_irq && init_irq(dev)) {
663 if (!wl->dev_irq_num &&
664 wl->hif_func->enable_interrupt &&
665 wl->hif_func->enable_interrupt(wl)) {
670 if (wilc_wlan_get_firmware(dev)) {
672 goto fail_irq_enable;
675 ret = wilc1000_firmware_download(dev);
678 goto fail_irq_enable;
681 ret = linux_wlan_start_firmware(dev);
684 goto fail_irq_enable;
687 if (wilc_wlan_cfg_get(vif, 1, WID_FIRMWARE_VERSION, 1, 0)) {
689 char firmware_ver[20];
691 size = wilc_wlan_cfg_get_val(WID_FIRMWARE_VERSION,
693 sizeof(firmware_ver));
694 firmware_ver[size] = '\0';
695 netdev_dbg(dev, "Firmware Ver = %s\n", firmware_ver);
697 ret = linux_wlan_init_test_config(dev, vif);
700 netdev_err(dev, "Failed to configure firmware\n");
705 wl->initialized = true;
712 if (!wl->dev_irq_num &&
713 wl->hif_func->disable_interrupt)
714 wl->hif_func->disable_interrupt(wl);
719 wlan_deinitialize_threads(dev);
721 wilc_wlan_cleanup(dev);
723 wlan_deinit_locks(dev);
724 netdev_err(dev, "WLAN initialization FAILED\n");
726 netdev_dbg(dev, "wilc1000 already initialized\n");
731 static int mac_init_fn(struct net_device *ndev)
733 netif_start_queue(ndev);
734 netif_stop_queue(ndev);
739 static int wilc_mac_open(struct net_device *ndev)
741 struct wilc_vif *vif = netdev_priv(ndev);
742 struct wilc *wl = vif->wilc;
743 unsigned char mac_add[ETH_ALEN] = {0};
747 if (!wl || !wl->dev) {
748 netdev_err(ndev, "device not ready\n");
752 netdev_dbg(ndev, "MAC OPEN[%p]\n", ndev);
754 ret = wilc_init_host_int(ndev);
758 ret = wilc_wlan_initialize(ndev, vif);
760 wilc_deinit_host_int(ndev);
764 for (i = 0; i < wl->vif_num; i++) {
765 if (ndev == wl->vif[i]->ndev) {
766 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
767 vif->iftype, vif->ifc_id);
768 wilc_set_operation_mode(vif, vif->iftype);
773 wilc_get_mac_address(vif, mac_add);
774 netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
775 memcpy(wl->vif[i]->src_addr, mac_add, ETH_ALEN);
776 memcpy(ndev->dev_addr, wl->vif[i]->src_addr, ETH_ALEN);
778 if (!is_valid_ether_addr(ndev->dev_addr)) {
779 netdev_err(ndev, "Wrong MAC address\n");
780 wilc_deinit_host_int(ndev);
781 wilc_wlan_deinitialize(ndev);
785 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
786 vif->ndev->ieee80211_ptr,
787 vif->frame_reg[0].type,
788 vif->frame_reg[0].reg);
789 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
790 vif->ndev->ieee80211_ptr,
791 vif->frame_reg[1].type,
792 vif->frame_reg[1].reg);
793 netif_wake_queue(ndev);
799 static struct net_device_stats *mac_stats(struct net_device *dev)
801 struct wilc_vif *vif = netdev_priv(dev);
803 return &vif->netstats;
806 static void wilc_set_multicast_list(struct net_device *dev)
808 struct netdev_hw_addr *ha;
809 struct wilc_vif *vif = netdev_priv(dev);
812 if (dev->flags & IFF_PROMISC)
815 if (dev->flags & IFF_ALLMULTI ||
816 dev->mc.count > WILC_MULTICAST_TABLE_SIZE) {
817 wilc_setup_multicast_filter(vif, false, 0);
821 if (dev->mc.count == 0) {
822 wilc_setup_multicast_filter(vif, true, 0);
826 netdev_for_each_mc_addr(ha, dev) {
827 memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN);
828 netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
829 wilc_multicast_mac_addr_list[i][0],
830 wilc_multicast_mac_addr_list[i][1],
831 wilc_multicast_mac_addr_list[i][2],
832 wilc_multicast_mac_addr_list[i][3],
833 wilc_multicast_mac_addr_list[i][4],
834 wilc_multicast_mac_addr_list[i][5]);
838 wilc_setup_multicast_filter(vif, true, (dev->mc.count));
841 static void linux_wlan_tx_complete(void *priv, int status)
843 struct tx_complete_data *pv_data = priv;
845 dev_kfree_skb(pv_data->skb);
849 netdev_tx_t wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
851 struct wilc_vif *vif = netdev_priv(ndev);
852 struct wilc *wilc = vif->wilc;
853 struct tx_complete_data *tx_data = NULL;
857 struct ethhdr *eth_h;
859 if (skb->dev != ndev) {
860 netdev_err(ndev, "Packet not destined to this device\n");
864 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
867 netif_wake_queue(ndev);
871 tx_data->buff = skb->data;
872 tx_data->size = skb->len;
875 eth_h = (struct ethhdr *)(skb->data);
876 if (eth_h->h_proto == cpu_to_be16(0x8e88))
877 netdev_dbg(ndev, "EAPOL transmitted\n");
879 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
881 udp_buf = (char *)ih + sizeof(struct iphdr);
882 if ((udp_buf[1] == 68 && udp_buf[3] == 67) ||
883 (udp_buf[1] == 67 && udp_buf[3] == 68))
884 netdev_dbg(ndev, "DHCP Message transmitted, type:%x %x %x\n",
885 udp_buf[248], udp_buf[249], udp_buf[250]);
887 vif->netstats.tx_packets++;
888 vif->netstats.tx_bytes += tx_data->size;
889 tx_data->bssid = wilc->vif[vif->idx]->bssid;
890 queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
891 tx_data->buff, tx_data->size,
892 linux_wlan_tx_complete);
894 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
895 netif_stop_queue(wilc->vif[0]->ndev);
896 netif_stop_queue(wilc->vif[1]->ndev);
902 static int wilc_mac_close(struct net_device *ndev)
904 struct wilc_priv *priv;
905 struct wilc_vif *vif = netdev_priv(ndev);
906 struct host_if_drv *hif_drv;
909 if (!vif || !vif->ndev || !vif->ndev->ieee80211_ptr ||
910 !vif->ndev->ieee80211_ptr->wiphy)
913 priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy);
919 hif_drv = (struct host_if_drv *)priv->hif_drv;
921 netdev_dbg(ndev, "Mac close\n");
929 if (wl->open_ifcs > 0)
935 netif_stop_queue(vif->ndev);
937 wilc_deinit_host_int(vif->ndev);
940 if (wl->open_ifcs == 0) {
941 netdev_dbg(ndev, "Deinitializing wilc1000\n");
943 wilc_wlan_deinitialize(ndev);
944 wilc_wfi_deinit_mon_interface();
952 void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset)
954 unsigned int frame_len = 0;
956 unsigned char *buff_to_send = NULL;
958 struct net_device *wilc_netdev;
959 struct wilc_vif *vif;
964 wilc_netdev = get_if_handler(wilc, buff);
969 vif = netdev_priv(wilc_netdev);
975 skb = dev_alloc_skb(frame_len);
979 skb->dev = wilc_netdev;
981 skb_put_data(skb, buff_to_send, frame_len);
983 skb->protocol = eth_type_trans(skb, wilc_netdev);
984 vif->netstats.rx_packets++;
985 vif->netstats.rx_bytes += frame_len;
986 skb->ip_summed = CHECKSUM_UNNECESSARY;
987 stats = netif_rx(skb);
988 netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
992 void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
995 struct wilc_vif *vif;
997 for (i = 0; i < wilc->vif_num; i++) {
998 vif = netdev_priv(wilc->vif[i]->ndev);
999 if (vif->monitor_flag) {
1000 wilc_wfi_monitor_rx(buff, size);
1005 vif = netdev_priv(wilc->vif[1]->ndev);
1006 if ((buff[0] == vif->frame_reg[0].type && vif->frame_reg[0].reg) ||
1007 (buff[0] == vif->frame_reg[1].type && vif->frame_reg[1].reg))
1008 wilc_wfi_p2p_rx(wilc->vif[1]->ndev, buff, size);
1011 static struct notifier_block g_dev_notifier = {
1012 .notifier_call = dev_state_ev_handler
1015 void wilc_netdev_cleanup(struct wilc *wilc)
1019 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev))
1020 unregister_inetaddr_notifier(&g_dev_notifier);
1022 if (wilc && wilc->firmware) {
1023 release_firmware(wilc->firmware);
1024 wilc->firmware = NULL;
1027 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) {
1028 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1029 if (wilc->vif[i]->ndev)
1030 if (wilc->vif[i]->mac_opened)
1031 wilc_mac_close(wilc->vif[i]->ndev);
1033 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1034 unregister_netdev(wilc->vif[i]->ndev);
1035 wilc_free_wiphy(wilc->vif[i]->ndev);
1036 free_netdev(wilc->vif[i]->ndev);
1042 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
1044 static const struct net_device_ops wilc_netdev_ops = {
1045 .ndo_init = mac_init_fn,
1046 .ndo_open = wilc_mac_open,
1047 .ndo_stop = wilc_mac_close,
1048 .ndo_start_xmit = wilc_mac_xmit,
1049 .ndo_get_stats = mac_stats,
1050 .ndo_set_rx_mode = wilc_set_multicast_list,
1053 int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1054 const struct wilc_hif_func *ops)
1057 struct wilc_vif *vif;
1058 struct net_device *ndev;
1061 wl = kzalloc(sizeof(*wl), GFP_KERNEL);
1066 wl->io_type = io_type;
1068 INIT_LIST_HEAD(&wl->txq_head.list);
1069 INIT_LIST_HEAD(&wl->rxq_head.list);
1071 register_inetaddr_notifier(&g_dev_notifier);
1073 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1074 struct wireless_dev *wdev;
1076 ndev = alloc_etherdev(sizeof(struct wilc_vif));
1080 vif = netdev_priv(ndev);
1081 memset(vif, 0, sizeof(struct wilc_vif));
1084 strcpy(ndev->name, "wlan%d");
1087 strcpy(ndev->name, "p2p%d");
1093 wl->vif_num = i + 1;
1096 ndev->netdev_ops = &wilc_netdev_ops;
1098 wdev = wilc_create_wiphy(ndev, dev);
1101 SET_NETDEV_DEV(ndev, dev);
1104 netdev_err(ndev, "Can't register WILC Wiphy\n");
1108 vif->ndev->ieee80211_ptr = wdev;
1109 vif->ndev->ml_priv = vif;
1110 wdev->netdev = vif->ndev;
1111 vif->netstats.rx_packets = 0;
1112 vif->netstats.tx_packets = 0;
1113 vif->netstats.rx_bytes = 0;
1114 vif->netstats.tx_bytes = 0;
1116 ret = register_netdev(ndev);
1120 vif->iftype = STATION_MODE;
1121 vif->mac_opened = 0;
1126 EXPORT_SYMBOL_GPL(wilc_netdev_init);
1128 MODULE_LICENSE("GPL");