1 #include "wilc_wfi_cfgoperations.h"
2 #include "wilc_wlan_if.h"
5 #include <linux/slab.h>
6 #include <linux/sched.h>
7 #include <linux/delay.h>
8 #include <linux/workqueue.h>
9 #include <linux/interrupt.h>
10 #include <linux/irq.h>
11 #include <linux/gpio.h>
13 #include <linux/kthread.h>
14 #include <linux/firmware.h>
16 #include <linux/init.h>
17 #include <linux/netdevice.h>
18 #include <linux/inetdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/skbuff.h>
23 #include <linux/mutex.h>
24 #include <linux/completion.h>
26 static int dev_state_ev_handler(struct notifier_block *this,
27 unsigned long event, void *ptr);
29 static struct notifier_block g_dev_notifier = {
30 .notifier_call = dev_state_ev_handler
33 static int wlan_deinit_locks(struct net_device *dev);
34 static void wlan_deinitialize_threads(struct net_device *dev);
36 static void linux_wlan_tx_complete(void *priv, int status);
37 static int mac_init_fn(struct net_device *ndev);
38 static struct net_device_stats *mac_stats(struct net_device *dev);
39 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
40 static int wilc_mac_open(struct net_device *ndev);
41 static int wilc_mac_close(struct net_device *ndev);
42 static void wilc_set_multicast_list(struct net_device *dev);
44 bool wilc_enable_ps = true;
46 static const struct net_device_ops wilc_netdev_ops = {
47 .ndo_init = mac_init_fn,
48 .ndo_open = wilc_mac_open,
49 .ndo_stop = wilc_mac_close,
50 .ndo_start_xmit = wilc_mac_xmit,
51 .ndo_do_ioctl = mac_ioctl,
52 .ndo_get_stats = mac_stats,
53 .ndo_set_rx_mode = wilc_set_multicast_list,
57 static int dev_state_ev_handler(struct notifier_block *this,
58 unsigned long event, void *ptr)
60 struct in_ifaddr *dev_iface = ptr;
61 struct wilc_priv *priv;
62 struct host_if_drv *hif_drv;
63 struct net_device *dev;
67 char wlan_dev_name[5] = "wlan0";
69 if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
72 if (memcmp(dev_iface->ifa_label, "wlan0", 5) &&
73 memcmp(dev_iface->ifa_label, "p2p0", 4))
76 dev = (struct net_device *)dev_iface->ifa_dev->dev;
77 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
80 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
84 hif_drv = (struct host_if_drv *)priv->hif_drv;
85 vif = netdev_priv(dev);
91 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
93 wilc_optaining_ip = false;
94 del_timer(&wilc_during_ip_timer);
98 wilc_set_power_mgmt(vif, 1, 0);
100 netdev_dbg(dev, "[%s] Up IP\n", dev_iface->ifa_label);
102 ip_addr_buf = (char *)&dev_iface->ifa_address;
103 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
104 ip_addr_buf[0], ip_addr_buf[1],
105 ip_addr_buf[2], ip_addr_buf[3]);
106 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
111 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
113 wilc_optaining_ip = false;
116 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
117 wilc_set_power_mgmt(vif, 0, 0);
119 wilc_resolve_disconnect_aberration(vif);
121 netdev_dbg(dev, "[%s] Down IP\n", dev_iface->ifa_label);
123 ip_addr_buf = null_ip;
124 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
125 ip_addr_buf[0], ip_addr_buf[1],
126 ip_addr_buf[2], ip_addr_buf[3]);
128 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
139 static irqreturn_t isr_uh_routine(int irq, void *user_data)
141 struct wilc_vif *vif;
143 struct net_device *dev = user_data;
145 vif = netdev_priv(dev);
149 netdev_err(dev, "Can't handle UH interrupt\n");
152 return IRQ_WAKE_THREAD;
155 static irqreturn_t isr_bh_routine(int irq, void *userdata)
157 struct wilc_vif *vif;
159 struct net_device *dev = userdata;
161 vif = netdev_priv(userdata);
165 netdev_err(dev, "Can't handle BH interrupt\n");
169 wilc_handle_isr(wilc);
174 static int init_irq(struct net_device *dev)
177 struct wilc_vif *vif;
180 vif = netdev_priv(dev);
183 if ((gpio_request(wl->gpio, "WILC_INTR") == 0) &&
184 (gpio_direction_input(wl->gpio) == 0)) {
185 wl->dev_irq_num = gpio_to_irq(wl->gpio);
188 netdev_err(dev, "could not obtain gpio for WILC_INTR\n");
191 if (ret != -1 && request_threaded_irq(wl->dev_irq_num,
194 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
195 "WILC_IRQ", dev) < 0) {
196 netdev_err(dev, "Failed to request IRQ GPIO: %d\n", wl->gpio);
201 "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
202 wl->dev_irq_num, wl->gpio);
208 static void deinit_irq(struct net_device *dev)
210 struct wilc_vif *vif;
213 vif = netdev_priv(dev);
216 /* Deinitialize IRQ */
217 if (wilc->dev_irq_num) {
218 free_irq(wilc->dev_irq_num, wilc);
219 gpio_free(wilc->gpio);
223 void wilc_mac_indicate(struct wilc *wilc, int flag)
227 if (flag == WILC_MAC_INDICATE_STATUS) {
228 wilc_wlan_cfg_get_val(WID_STATUS,
229 (unsigned char *)&status, 4);
230 if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
231 wilc->mac_status = status;
232 complete(&wilc->sync_event);
234 wilc->mac_status = status;
239 static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
244 bssid = mac_header + 10;
245 bssid1 = mac_header + 4;
247 for (i = 0; i < wilc->vif_num; i++) {
248 if (wilc->vif[i]->mode == STATION_MODE)
249 if (ether_addr_equal_unaligned(bssid,
250 wilc->vif[i]->bssid))
251 return wilc->vif[i]->ndev;
252 if (wilc->vif[i]->mode == AP_MODE)
253 if (ether_addr_equal_unaligned(bssid1,
254 wilc->vif[i]->bssid))
255 return wilc->vif[i]->ndev;
261 int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
263 struct wilc_vif *vif = netdev_priv(wilc_netdev);
265 memcpy(vif->bssid, bssid, 6);
271 int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
274 u8 null_bssid[6] = {0};
277 for (i = 0; i < wilc->vif_num; i++)
278 if (memcmp(wilc->vif[i]->bssid, null_bssid, 6))
284 static int linux_wlan_txq_task(void *vp)
288 struct wilc_vif *vif;
290 struct net_device *dev = vp;
292 vif = netdev_priv(dev);
295 complete(&wl->txq_thread_started);
297 wait_for_completion(&wl->txq_event);
300 complete(&wl->txq_thread_started);
302 while (!kthread_should_stop())
307 ret = wilc_wlan_handle_txq(dev, &txq_count);
308 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
309 if (netif_queue_stopped(wl->vif[0]->ndev))
310 netif_wake_queue(wl->vif[0]->ndev);
311 if (netif_queue_stopped(wl->vif[1]->ndev))
312 netif_wake_queue(wl->vif[1]->ndev);
314 } while (ret == WILC_TX_ERR_NO_BUF && !wl->close);
319 int wilc_wlan_get_firmware(struct net_device *dev)
321 struct wilc_vif *vif;
323 int chip_id, ret = 0;
324 const struct firmware *wilc_firmware;
327 vif = netdev_priv(dev);
330 chip_id = wilc_get_chipid(wilc, false);
332 if (chip_id < 0x1003a0)
333 firmware = FIRMWARE_1002;
335 firmware = FIRMWARE_1003;
337 netdev_info(dev, "loading firmware %s\n", firmware);
339 if (!(&vif->ndev->dev))
342 if (reject_firmware(&wilc_firmware, firmware, wilc->dev) != 0) {
343 netdev_err(dev, "%s - firmware not available\n", firmware);
347 wilc->firmware = wilc_firmware;
354 static int linux_wlan_start_firmware(struct net_device *dev)
356 struct wilc_vif *vif;
360 vif = netdev_priv(dev);
363 ret = wilc_wlan_start(wilc);
367 if (!wait_for_completion_timeout(&wilc->sync_event,
368 msecs_to_jiffies(5000)))
374 static int wilc1000_firmware_download(struct net_device *dev)
376 struct wilc_vif *vif;
380 vif = netdev_priv(dev);
383 if (!wilc->firmware) {
384 netdev_err(dev, "Firmware buffer is NULL\n");
388 ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data,
389 wilc->firmware->size);
393 release_firmware(wilc->firmware);
394 wilc->firmware = NULL;
396 netdev_dbg(dev, "Download Succeeded\n");
401 static int linux_wlan_init_test_config(struct net_device *dev,
402 struct wilc_vif *vif)
404 unsigned char c_val[64];
405 struct wilc *wilc = vif->wilc;
406 struct wilc_priv *priv;
407 struct host_if_drv *hif_drv;
409 netdev_dbg(dev, "Start configuring Firmware\n");
410 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
411 hif_drv = (struct host_if_drv *)priv->hif_drv;
412 netdev_dbg(dev, "Host = %p\n", hif_drv);
413 wilc_get_chipid(wilc, false);
417 if (!wilc_wlan_cfg_set(vif, 1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
421 if (!wilc_wlan_cfg_set(vif, 0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
424 c_val[0] = INFRASTRUCTURE;
425 if (!wilc_wlan_cfg_set(vif, 0, WID_BSS_TYPE, c_val, 1, 0, 0))
428 c_val[0] = RATE_AUTO;
429 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
432 c_val[0] = G_MIXED_11B_2_MODE;
433 if (!wilc_wlan_cfg_set(vif, 0, WID_11G_OPERATING_MODE, c_val, 1, 0,
438 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
441 c_val[0] = G_SHORT_PREAMBLE;
442 if (!wilc_wlan_cfg_set(vif, 0, WID_PREAMBLE, c_val, 1, 0, 0))
445 c_val[0] = AUTO_PROT;
446 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
449 c_val[0] = ACTIVE_SCAN;
450 if (!wilc_wlan_cfg_set(vif, 0, WID_SCAN_TYPE, c_val, 1, 0, 0))
453 c_val[0] = SITE_SURVEY_OFF;
454 if (!wilc_wlan_cfg_set(vif, 0, WID_SITE_SURVEY, c_val, 1, 0, 0))
457 *((int *)c_val) = 0xffff;
458 if (!wilc_wlan_cfg_set(vif, 0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
461 *((int *)c_val) = 2346;
462 if (!wilc_wlan_cfg_set(vif, 0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
466 if (!wilc_wlan_cfg_set(vif, 0, WID_BCAST_SSID, c_val, 1, 0, 0))
470 if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, c_val, 1, 0, 0))
473 c_val[0] = NO_POWERSAVE;
474 if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
477 c_val[0] = NO_SECURITY; /* NO_ENCRYPT, 0x79 */
478 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_MODE, c_val, 1, 0, 0))
481 c_val[0] = OPEN_SYSTEM;
482 if (!wilc_wlan_cfg_set(vif, 0, WID_AUTH_TYPE, c_val, 1, 0, 0))
485 strcpy(c_val, "123456790abcdef1234567890");
486 if (!wilc_wlan_cfg_set(vif, 0, WID_WEP_KEY_VALUE, c_val,
487 (strlen(c_val) + 1), 0, 0))
490 strcpy(c_val, "12345678");
491 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_PSK, c_val, (strlen(c_val)), 0,
495 strcpy(c_val, "password");
496 if (!wilc_wlan_cfg_set(vif, 0, WID_1X_KEY, c_val, (strlen(c_val) + 1),
504 if (!wilc_wlan_cfg_set(vif, 0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
508 if (!wilc_wlan_cfg_set(vif, 0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
512 if (!wilc_wlan_cfg_set(vif, 0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
515 c_val[0] = NORMAL_ACK;
516 if (!wilc_wlan_cfg_set(vif, 0, WID_ACK_POLICY, c_val, 1, 0, 0))
520 if (!wilc_wlan_cfg_set(vif, 0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1,
525 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0,
530 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0,
534 *((int *)c_val) = 100;
535 if (!wilc_wlan_cfg_set(vif, 0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
538 c_val[0] = REKEY_DISABLE;
539 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_POLICY, c_val, 1, 0, 0))
542 *((int *)c_val) = 84600;
543 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
546 *((int *)c_val) = 500;
547 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PACKET_COUNT, c_val, 4, 0,
552 if (!wilc_wlan_cfg_set(vif, 0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0,
556 c_val[0] = G_SELF_CTS_PROT;
557 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
561 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ENABLE, c_val, 1, 0, 0))
564 c_val[0] = HT_MIXED_MODE;
565 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OPERATING_MODE, c_val, 1, 0,
570 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0,
574 c_val[0] = DETECT_PROTECT_REPORT;
575 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1,
579 c_val[0] = RTS_CTS_NONHT_PROT;
580 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
584 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0,
588 c_val[0] = MIMO_MODE;
589 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
593 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0,
598 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1,
608 void wilc1000_wlan_deinit(struct net_device *dev)
610 struct wilc_vif *vif;
613 vif = netdev_priv(dev);
617 netdev_err(dev, "wl is NULL\n");
621 if (wl->initialized) {
622 netdev_info(dev, "Deinitializing wilc1000...\n");
624 if (!wl->dev_irq_num &&
625 wl->hif_func->disable_interrupt) {
626 mutex_lock(&wl->hif_cs);
627 wl->hif_func->disable_interrupt(wl);
628 mutex_unlock(&wl->hif_cs);
631 complete(&wl->txq_event);
633 wlan_deinitialize_threads(dev);
637 wilc_wlan_cleanup(dev);
638 wlan_deinit_locks(dev);
640 wl->initialized = false;
642 netdev_dbg(dev, "wilc1000 deinitialization Done\n");
644 netdev_dbg(dev, "wilc1000 is not initialized\n");
648 static int wlan_init_locks(struct net_device *dev)
650 struct wilc_vif *vif;
653 vif = netdev_priv(dev);
656 mutex_init(&wl->hif_cs);
657 mutex_init(&wl->rxq_cs);
659 spin_lock_init(&wl->txq_spinlock);
660 mutex_init(&wl->txq_add_to_head_cs);
662 init_completion(&wl->txq_event);
664 init_completion(&wl->cfg_event);
665 init_completion(&wl->sync_event);
666 init_completion(&wl->txq_thread_started);
671 static int wlan_deinit_locks(struct net_device *dev)
673 struct wilc_vif *vif;
676 vif = netdev_priv(dev);
680 mutex_destroy(&wilc->hif_cs);
683 mutex_destroy(&wilc->rxq_cs);
688 static int wlan_initialize_threads(struct net_device *dev)
690 struct wilc_vif *vif;
693 vif = netdev_priv(dev);
696 wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev,
698 if (IS_ERR(wilc->txq_thread)) {
699 netdev_err(dev, "couldn't create TXQ thread\n");
701 return PTR_ERR(wilc->txq_thread);
703 wait_for_completion(&wilc->txq_thread_started);
708 static void wlan_deinitialize_threads(struct net_device *dev)
710 struct wilc_vif *vif;
713 vif = netdev_priv(dev);
719 complete(&wl->txq_event);
721 if (wl->txq_thread) {
722 kthread_stop(wl->txq_thread);
723 wl->txq_thread = NULL;
727 int wilc1000_wlan_init(struct net_device *dev, struct wilc_vif *vif)
730 struct wilc *wl = vif->wilc;
732 if (!wl->initialized) {
733 wl->mac_status = WILC_MAC_STATUS_INIT;
736 wlan_init_locks(dev);
738 ret = wilc_wlan_init(dev);
744 if (wl->gpio >= 0 && init_irq(dev)) {
749 ret = wlan_initialize_threads(dev);
752 goto _fail_wilc_wlan_;
755 if (!wl->dev_irq_num &&
756 wl->hif_func->enable_interrupt &&
757 wl->hif_func->enable_interrupt(wl)) {
759 goto _fail_irq_init_;
762 if (wilc_wlan_get_firmware(dev)) {
764 goto _fail_irq_enable_;
767 ret = wilc1000_firmware_download(dev);
770 goto _fail_irq_enable_;
773 ret = linux_wlan_start_firmware(dev);
776 goto _fail_irq_enable_;
779 if (wilc_wlan_cfg_get(vif, 1, WID_FIRMWARE_VERSION, 1, 0)) {
781 char firmware_ver[20];
783 size = wilc_wlan_cfg_get_val(WID_FIRMWARE_VERSION,
785 sizeof(firmware_ver));
786 firmware_ver[size] = '\0';
787 netdev_dbg(dev, "Firmware Ver = %s\n", firmware_ver);
789 ret = linux_wlan_init_test_config(dev, vif);
792 netdev_err(dev, "Failed to configure firmware\n");
794 goto _fail_fw_start_;
797 wl->initialized = true;
804 if (!wl->dev_irq_num &&
805 wl->hif_func->disable_interrupt)
806 wl->hif_func->disable_interrupt(wl);
811 wlan_deinitialize_threads(dev);
813 wilc_wlan_cleanup(dev);
815 wlan_deinit_locks(dev);
816 netdev_err(dev, "WLAN initialization FAILED\n");
818 netdev_dbg(dev, "wilc1000 already initialized\n");
823 static int mac_init_fn(struct net_device *ndev)
825 netif_start_queue(ndev);
826 netif_stop_queue(ndev);
831 static int wilc_mac_open(struct net_device *ndev)
833 struct wilc_vif *vif;
835 unsigned char mac_add[ETH_ALEN] = {0};
840 vif = netdev_priv(ndev);
843 if (!wl || !wl->dev) {
844 netdev_err(ndev, "device not ready\n");
848 netdev_dbg(ndev, "MAC OPEN[%p]\n", ndev);
850 ret = wilc_init_host_int(ndev);
854 ret = wilc1000_wlan_init(ndev, vif);
856 wilc_deinit_host_int(ndev);
860 for (i = 0; i < wl->vif_num; i++) {
861 if (ndev == wl->vif[i]->ndev) {
862 wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
863 vif->iftype, vif->ifc_id);
864 wilc_set_operation_mode(vif, vif->iftype);
868 wilc_get_mac_address(vif, mac_add);
869 netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
870 memcpy(wl->vif[i]->src_addr, mac_add, ETH_ALEN);
872 memcpy(ndev->dev_addr, wl->vif[i]->src_addr, ETH_ALEN);
874 if (!is_valid_ether_addr(ndev->dev_addr)) {
875 netdev_err(ndev, "Wrong MAC address\n");
876 wilc_deinit_host_int(ndev);
877 wilc1000_wlan_deinit(ndev);
881 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
882 vif->ndev->ieee80211_ptr,
883 vif->frame_reg[0].type,
884 vif->frame_reg[0].reg);
885 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
886 vif->ndev->ieee80211_ptr,
887 vif->frame_reg[1].type,
888 vif->frame_reg[1].reg);
889 netif_wake_queue(ndev);
895 static struct net_device_stats *mac_stats(struct net_device *dev)
897 struct wilc_vif *vif = netdev_priv(dev);
899 return &vif->netstats;
902 static void wilc_set_multicast_list(struct net_device *dev)
904 struct netdev_hw_addr *ha;
905 struct wilc_vif *vif;
908 vif = netdev_priv(dev);
910 if (dev->flags & IFF_PROMISC)
913 if ((dev->flags & IFF_ALLMULTI) ||
914 (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
915 wilc_setup_multicast_filter(vif, false, 0);
919 if ((dev->mc.count) == 0) {
920 wilc_setup_multicast_filter(vif, true, 0);
924 netdev_for_each_mc_addr(ha, dev) {
925 memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN);
926 netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
927 wilc_multicast_mac_addr_list[i][0],
928 wilc_multicast_mac_addr_list[i][1],
929 wilc_multicast_mac_addr_list[i][2],
930 wilc_multicast_mac_addr_list[i][3],
931 wilc_multicast_mac_addr_list[i][4],
932 wilc_multicast_mac_addr_list[i][5]);
936 wilc_setup_multicast_filter(vif, true, (dev->mc.count));
939 static void linux_wlan_tx_complete(void *priv, int status)
941 struct tx_complete_data *pv_data = priv;
943 dev_kfree_skb(pv_data->skb);
947 int wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
949 struct wilc_vif *vif;
950 struct tx_complete_data *tx_data = NULL;
954 struct ethhdr *eth_h;
957 vif = netdev_priv(ndev);
960 if (skb->dev != ndev) {
961 netdev_err(ndev, "Packet not destined to this device\n");
965 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
968 netif_wake_queue(ndev);
972 tx_data->buff = skb->data;
973 tx_data->size = skb->len;
976 eth_h = (struct ethhdr *)(skb->data);
977 if (eth_h->h_proto == cpu_to_be16(0x8e88))
978 netdev_dbg(ndev, "EAPOL transmitted\n");
980 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
982 udp_buf = (char *)ih + sizeof(struct iphdr);
983 if ((udp_buf[1] == 68 && udp_buf[3] == 67) ||
984 (udp_buf[1] == 67 && udp_buf[3] == 68))
985 netdev_dbg(ndev, "DHCP Message transmitted, type:%x %x %x\n",
986 udp_buf[248], udp_buf[249], udp_buf[250]);
988 vif->netstats.tx_packets++;
989 vif->netstats.tx_bytes += tx_data->size;
990 tx_data->bssid = wilc->vif[vif->idx]->bssid;
991 queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
992 tx_data->buff, tx_data->size,
993 linux_wlan_tx_complete);
995 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
996 netif_stop_queue(wilc->vif[0]->ndev);
997 netif_stop_queue(wilc->vif[1]->ndev);
1003 static int wilc_mac_close(struct net_device *ndev)
1005 struct wilc_priv *priv;
1006 struct wilc_vif *vif;
1007 struct host_if_drv *hif_drv;
1010 vif = netdev_priv(ndev);
1012 if (!vif || !vif->ndev || !vif->ndev->ieee80211_ptr ||
1013 !vif->ndev->ieee80211_ptr->wiphy)
1016 priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy);
1022 hif_drv = (struct host_if_drv *)priv->hif_drv;
1024 netdev_dbg(ndev, "Mac close\n");
1032 if ((wl->open_ifcs) > 0)
1038 netif_stop_queue(vif->ndev);
1040 wilc_deinit_host_int(vif->ndev);
1043 if (wl->open_ifcs == 0) {
1044 netdev_dbg(ndev, "Deinitializing wilc1000\n");
1046 wilc1000_wlan_deinit(ndev);
1047 WILC_WFI_deinit_mon_interface();
1050 vif->mac_opened = 0;
1055 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
1060 struct wilc_vif *vif;
1064 vif = netdev_priv(ndev);
1067 if (!wilc->initialized)
1073 struct iwreq *wrq = (struct iwreq *)req;
1075 size = wrq->u.data.length;
1077 if (size && wrq->u.data.pointer) {
1078 buff = memdup_user(wrq->u.data.pointer,
1079 wrq->u.data.length);
1081 return PTR_ERR(buff);
1083 if (strncasecmp(buff, "RSSI", size) == 0) {
1084 ret = wilc_get_rssi(vif, &rssi);
1085 netdev_info(ndev, "RSSI :%d\n", rssi);
1089 snprintf(buff, size, "rssi %d", rssi);
1091 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
1092 netdev_err(ndev, "failed to copy\n");
1103 netdev_info(ndev, "Command - %d - has been received\n", cmd);
1116 void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset)
1118 unsigned int frame_len = 0;
1120 unsigned char *buff_to_send = NULL;
1121 struct sk_buff *skb;
1122 struct net_device *wilc_netdev;
1123 struct wilc_vif *vif;
1128 wilc_netdev = get_if_handler(wilc, buff);
1133 vif = netdev_priv(wilc_netdev);
1137 buff_to_send = buff;
1139 skb = dev_alloc_skb(frame_len);
1143 skb->dev = wilc_netdev;
1145 skb_put_data(skb, buff_to_send, frame_len);
1147 skb->protocol = eth_type_trans(skb, wilc_netdev);
1148 vif->netstats.rx_packets++;
1149 vif->netstats.rx_bytes += frame_len;
1150 skb->ip_summed = CHECKSUM_UNNECESSARY;
1151 stats = netif_rx(skb);
1152 netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
1156 void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
1159 struct wilc_vif *vif;
1161 for (i = 0; i < wilc->vif_num; i++) {
1162 vif = netdev_priv(wilc->vif[i]->ndev);
1163 if (vif->monitor_flag) {
1164 WILC_WFI_monitor_rx(buff, size);
1169 vif = netdev_priv(wilc->vif[1]->ndev);
1170 if ((buff[0] == vif->frame_reg[0].type && vif->frame_reg[0].reg) ||
1171 (buff[0] == vif->frame_reg[1].type && vif->frame_reg[1].reg))
1172 WILC_WFI_p2p_rx(wilc->vif[1]->ndev, buff, size);
1175 void wilc_netdev_cleanup(struct wilc *wilc)
1179 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev))
1180 unregister_inetaddr_notifier(&g_dev_notifier);
1182 if (wilc && wilc->firmware) {
1183 release_firmware(wilc->firmware);
1184 wilc->firmware = NULL;
1187 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) {
1188 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1189 if (wilc->vif[i]->ndev)
1190 if (wilc->vif[i]->mac_opened)
1191 wilc_mac_close(wilc->vif[i]->ndev);
1193 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1194 unregister_netdev(wilc->vif[i]->ndev);
1195 wilc_free_wiphy(wilc->vif[i]->ndev);
1196 free_netdev(wilc->vif[i]->ndev);
1202 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
1204 int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1205 int gpio, const struct wilc_hif_func *ops)
1208 struct wilc_vif *vif;
1209 struct net_device *ndev;
1212 wl = kzalloc(sizeof(*wl), GFP_KERNEL);
1217 wl->io_type = io_type;
1221 register_inetaddr_notifier(&g_dev_notifier);
1223 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1224 ndev = alloc_etherdev(sizeof(struct wilc_vif));
1228 vif = netdev_priv(ndev);
1229 memset(vif, 0, sizeof(struct wilc_vif));
1232 strcpy(ndev->name, "wlan%d");
1235 strcpy(ndev->name, "p2p%d");
1241 wl->vif_num = i + 1;
1244 ndev->netdev_ops = &wilc_netdev_ops;
1247 struct wireless_dev *wdev;
1249 wdev = wilc_create_wiphy(ndev, dev);
1252 SET_NETDEV_DEV(ndev, dev);
1255 netdev_err(ndev, "Can't register WILC Wiphy\n");
1259 vif->ndev->ieee80211_ptr = wdev;
1260 vif->ndev->ml_priv = vif;
1261 wdev->netdev = vif->ndev;
1262 vif->netstats.rx_packets = 0;
1263 vif->netstats.tx_packets = 0;
1264 vif->netstats.rx_bytes = 0;
1265 vif->netstats.tx_bytes = 0;
1268 ret = register_netdev(ndev);
1272 vif->iftype = STATION_MODE;
1273 vif->mac_opened = 0;
1278 EXPORT_SYMBOL_GPL(wilc_netdev_init);
1280 MODULE_LICENSE("GPL");