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/semaphore.h>
25 #include <linux/completion.h>
27 static int dev_state_ev_handler(struct notifier_block *this,
28 unsigned long event, void *ptr);
30 static struct notifier_block g_dev_notifier = {
31 .notifier_call = dev_state_ev_handler
34 static int wlan_deinit_locks(struct net_device *dev);
35 static void wlan_deinitialize_threads(struct net_device *dev);
37 static void linux_wlan_tx_complete(void *priv, int status);
38 static int mac_init_fn(struct net_device *ndev);
39 static struct net_device_stats *mac_stats(struct net_device *dev);
40 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
41 static void wilc_set_multicast_list(struct net_device *dev);
43 bool wilc_enable_ps = true;
45 static const struct net_device_ops wilc_netdev_ops = {
46 .ndo_init = mac_init_fn,
47 .ndo_open = wilc_mac_open,
48 .ndo_stop = wilc_mac_close,
49 .ndo_start_xmit = wilc_mac_xmit,
50 .ndo_do_ioctl = mac_ioctl,
51 .ndo_get_stats = mac_stats,
52 .ndo_set_rx_mode = wilc_set_multicast_list,
56 static int dev_state_ev_handler(struct notifier_block *this,
57 unsigned long event, void *ptr)
59 struct in_ifaddr *dev_iface = ptr;
60 struct wilc_priv *priv;
61 struct host_if_drv *hif_drv;
62 struct net_device *dev;
66 char wlan_dev_name[5] = "wlan0";
68 if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
71 if (memcmp(dev_iface->ifa_label, "wlan0", 5) &&
72 memcmp(dev_iface->ifa_label, "p2p0", 4))
75 dev = (struct net_device *)dev_iface->ifa_dev->dev;
76 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
79 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
83 hif_drv = (struct host_if_drv *)priv->hif_drv;
84 vif = netdev_priv(dev);
90 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
92 wilc_optaining_ip = false;
93 del_timer(&wilc_during_ip_timer);
97 wilc_set_power_mgmt(vif, 1, 0);
99 netdev_dbg(dev, "[%s] Up IP\n", dev_iface->ifa_label);
101 ip_addr_buf = (char *)&dev_iface->ifa_address;
102 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
103 ip_addr_buf[0], ip_addr_buf[1],
104 ip_addr_buf[2], ip_addr_buf[3]);
105 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
110 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
112 wilc_optaining_ip = false;
115 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
116 wilc_set_power_mgmt(vif, 0, 0);
118 wilc_resolve_disconnect_aberration(vif);
120 netdev_dbg(dev, "[%s] Down IP\n", dev_iface->ifa_label);
122 ip_addr_buf = null_ip;
123 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
124 ip_addr_buf[0], ip_addr_buf[1],
125 ip_addr_buf[2], ip_addr_buf[3]);
127 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
138 static irqreturn_t isr_uh_routine(int irq, void *user_data)
140 struct wilc_vif *vif;
142 struct net_device *dev = user_data;
144 vif = netdev_priv(dev);
148 netdev_err(dev, "Can't handle UH interrupt\n");
151 return IRQ_WAKE_THREAD;
154 static irqreturn_t isr_bh_routine(int irq, void *userdata)
156 struct wilc_vif *vif;
158 struct net_device *dev = userdata;
160 vif = netdev_priv(userdata);
164 netdev_err(dev, "Can't handle BH interrupt\n");
168 wilc_handle_isr(wilc);
173 static int init_irq(struct net_device *dev)
176 struct wilc_vif *vif;
179 vif = netdev_priv(dev);
182 if ((gpio_request(wl->gpio, "WILC_INTR") == 0) &&
183 (gpio_direction_input(wl->gpio) == 0)) {
184 wl->dev_irq_num = gpio_to_irq(wl->gpio);
187 netdev_err(dev, "could not obtain gpio for WILC_INTR\n");
190 if (ret != -1 && request_threaded_irq(wl->dev_irq_num,
193 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
194 "WILC_IRQ", dev) < 0) {
195 netdev_err(dev, "Failed to request IRQ GPIO: %d\n", wl->gpio);
200 "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
201 wl->dev_irq_num, wl->gpio);
207 static void deinit_irq(struct net_device *dev)
209 struct wilc_vif *vif;
212 vif = netdev_priv(dev);
215 /* Deintialize IRQ */
216 if (wilc->dev_irq_num) {
217 free_irq(wilc->dev_irq_num, wilc);
218 gpio_free(wilc->gpio);
222 int wilc_lock_timeout(struct wilc *nic, void *vp, u32 timeout)
224 /* FIXME: replace with mutex_lock or wait_for_completion */
228 error = down_timeout(vp,
229 msecs_to_jiffies(timeout));
233 void wilc_mac_indicate(struct wilc *wilc, int flag)
237 if (flag == WILC_MAC_INDICATE_STATUS) {
238 wilc_wlan_cfg_get_val(WID_STATUS,
239 (unsigned char *)&status, 4);
240 if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
241 wilc->mac_status = status;
242 complete(&wilc->sync_event);
244 wilc->mac_status = status;
249 static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
254 bssid = mac_header + 10;
255 bssid1 = mac_header + 4;
257 for (i = 0; i < wilc->vif_num; i++) {
258 if (wilc->vif[i]->mode == STATION_MODE)
259 if (ether_addr_equal_unaligned(bssid,
260 wilc->vif[i]->bssid))
261 return wilc->vif[i]->ndev;
262 if (wilc->vif[i]->mode == AP_MODE)
263 if (ether_addr_equal_unaligned(bssid1,
264 wilc->vif[i]->bssid))
265 return wilc->vif[i]->ndev;
271 int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
275 struct wilc_vif *vif;
278 vif = netdev_priv(wilc_netdev);
281 for (i = 0; i < wilc->vif_num; i++)
282 if (wilc->vif[i]->ndev == wilc_netdev) {
283 memcpy(wilc->vif[i]->bssid, bssid, 6);
284 wilc->vif[i]->mode = mode;
292 int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
295 u8 null_bssid[6] = {0};
298 for (i = 0; i < wilc->vif_num; i++)
299 if (memcmp(wilc->vif[i]->bssid, null_bssid, 6))
305 static int linux_wlan_txq_task(void *vp)
308 struct wilc_vif *vif;
310 struct net_device *dev = vp;
312 vif = netdev_priv(dev);
315 complete(&wl->txq_thread_started);
317 wait_for_completion(&wl->txq_event);
320 complete(&wl->txq_thread_started);
322 while (!kthread_should_stop())
327 ret = wilc_wlan_handle_txq(dev, &txq_count);
328 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
329 if (netif_queue_stopped(wl->vif[0]->ndev))
330 netif_wake_queue(wl->vif[0]->ndev);
331 if (netif_queue_stopped(wl->vif[1]->ndev))
332 netif_wake_queue(wl->vif[1]->ndev);
334 } while (ret == WILC_TX_ERR_NO_BUF && !wl->close);
339 int wilc_wlan_get_firmware(struct net_device *dev)
341 struct wilc_vif *vif;
343 int chip_id, ret = 0;
344 const struct firmware *wilc_firmware;
347 vif = netdev_priv(dev);
350 chip_id = wilc_get_chipid(wilc, false);
352 if (chip_id < 0x1003a0)
353 firmware = FIRMWARE_1002;
355 firmware = FIRMWARE_1003;
357 netdev_info(dev, "loading firmware %s\n", firmware);
359 if (!(&vif->ndev->dev))
362 if (request_firmware(&wilc_firmware, firmware, wilc->dev) != 0) {
363 netdev_err(dev, "%s - firmware not available\n", firmware);
367 wilc->firmware = wilc_firmware;
374 static int linux_wlan_start_firmware(struct net_device *dev)
376 struct wilc_vif *vif;
380 vif = netdev_priv(dev);
383 ret = wilc_wlan_start(wilc);
387 if (!wait_for_completion_timeout(&wilc->sync_event,
388 msecs_to_jiffies(5000)))
394 static int wilc1000_firmware_download(struct net_device *dev)
396 struct wilc_vif *vif;
400 vif = netdev_priv(dev);
403 if (!wilc->firmware) {
404 netdev_err(dev, "Firmware buffer is NULL\n");
408 ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data,
409 wilc->firmware->size);
413 release_firmware(wilc->firmware);
414 wilc->firmware = NULL;
416 netdev_dbg(dev, "Download Succeeded\n");
421 static int linux_wlan_init_test_config(struct net_device *dev,
422 struct wilc_vif *vif)
424 unsigned char c_val[64];
425 struct wilc *wilc = vif->wilc;
426 struct wilc_priv *priv;
427 struct host_if_drv *hif_drv;
429 netdev_dbg(dev, "Start configuring Firmware\n");
430 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
431 hif_drv = (struct host_if_drv *)priv->hif_drv;
432 netdev_dbg(dev, "Host = %p\n", hif_drv);
433 wilc_get_chipid(wilc, false);
437 if (!wilc_wlan_cfg_set(vif, 1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
441 if (!wilc_wlan_cfg_set(vif, 0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
444 c_val[0] = INFRASTRUCTURE;
445 if (!wilc_wlan_cfg_set(vif, 0, WID_BSS_TYPE, c_val, 1, 0, 0))
448 c_val[0] = RATE_AUTO;
449 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
452 c_val[0] = G_MIXED_11B_2_MODE;
453 if (!wilc_wlan_cfg_set(vif, 0, WID_11G_OPERATING_MODE, c_val, 1, 0,
458 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
461 c_val[0] = G_SHORT_PREAMBLE;
462 if (!wilc_wlan_cfg_set(vif, 0, WID_PREAMBLE, c_val, 1, 0, 0))
465 c_val[0] = AUTO_PROT;
466 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
469 c_val[0] = ACTIVE_SCAN;
470 if (!wilc_wlan_cfg_set(vif, 0, WID_SCAN_TYPE, c_val, 1, 0, 0))
473 c_val[0] = SITE_SURVEY_OFF;
474 if (!wilc_wlan_cfg_set(vif, 0, WID_SITE_SURVEY, c_val, 1, 0, 0))
477 *((int *)c_val) = 0xffff;
478 if (!wilc_wlan_cfg_set(vif, 0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
481 *((int *)c_val) = 2346;
482 if (!wilc_wlan_cfg_set(vif, 0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
486 if (!wilc_wlan_cfg_set(vif, 0, WID_BCAST_SSID, c_val, 1, 0, 0))
490 if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, c_val, 1, 0, 0))
493 c_val[0] = NO_POWERSAVE;
494 if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
497 c_val[0] = NO_SECURITY; /* NO_ENCRYPT, 0x79 */
498 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_MODE, c_val, 1, 0, 0))
501 c_val[0] = OPEN_SYSTEM;
502 if (!wilc_wlan_cfg_set(vif, 0, WID_AUTH_TYPE, c_val, 1, 0, 0))
505 strcpy(c_val, "123456790abcdef1234567890");
506 if (!wilc_wlan_cfg_set(vif, 0, WID_WEP_KEY_VALUE, c_val,
507 (strlen(c_val) + 1), 0, 0))
510 strcpy(c_val, "12345678");
511 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_PSK, c_val, (strlen(c_val)), 0,
515 strcpy(c_val, "password");
516 if (!wilc_wlan_cfg_set(vif, 0, WID_1X_KEY, c_val, (strlen(c_val) + 1),
524 if (!wilc_wlan_cfg_set(vif, 0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
528 if (!wilc_wlan_cfg_set(vif, 0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
532 if (!wilc_wlan_cfg_set(vif, 0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
535 c_val[0] = NORMAL_ACK;
536 if (!wilc_wlan_cfg_set(vif, 0, WID_ACK_POLICY, c_val, 1, 0, 0))
540 if (!wilc_wlan_cfg_set(vif, 0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1,
545 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0,
550 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0,
554 *((int *)c_val) = 100;
555 if (!wilc_wlan_cfg_set(vif, 0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
558 c_val[0] = REKEY_DISABLE;
559 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_POLICY, c_val, 1, 0, 0))
562 *((int *)c_val) = 84600;
563 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
566 *((int *)c_val) = 500;
567 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PACKET_COUNT, c_val, 4, 0,
572 if (!wilc_wlan_cfg_set(vif, 0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0,
576 c_val[0] = G_SELF_CTS_PROT;
577 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
581 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ENABLE, c_val, 1, 0, 0))
584 c_val[0] = HT_MIXED_MODE;
585 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OPERATING_MODE, c_val, 1, 0,
590 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0,
594 c_val[0] = DETECT_PROTECT_REPORT;
595 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1,
599 c_val[0] = RTS_CTS_NONHT_PROT;
600 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
604 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0,
608 c_val[0] = MIMO_MODE;
609 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
613 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0,
618 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1,
628 void wilc1000_wlan_deinit(struct net_device *dev)
630 struct wilc_vif *vif;
633 vif = netdev_priv(dev);
637 netdev_err(dev, "wl is NULL\n");
641 if (wl->initialized) {
642 netdev_info(dev, "Deinitializing wilc1000...\n");
644 if (!wl->dev_irq_num &&
645 wl->hif_func->disable_interrupt) {
646 mutex_lock(&wl->hif_cs);
647 wl->hif_func->disable_interrupt(wl);
648 mutex_unlock(&wl->hif_cs);
651 wait_for_completion(&wl->txq_event);
653 wlan_deinitialize_threads(dev);
657 wilc_wlan_cleanup(dev);
658 wlan_deinit_locks(dev);
660 wl->initialized = false;
662 netdev_dbg(dev, "wilc1000 deinitialization Done\n");
664 netdev_dbg(dev, "wilc1000 is not initialized\n");
668 static int wlan_init_locks(struct net_device *dev)
670 struct wilc_vif *vif;
673 vif = netdev_priv(dev);
676 mutex_init(&wl->hif_cs);
677 mutex_init(&wl->rxq_cs);
679 spin_lock_init(&wl->txq_spinlock);
680 mutex_init(&wl->txq_add_to_head_cs);
682 init_completion(&wl->txq_event);
684 init_completion(&wl->cfg_event);
685 init_completion(&wl->sync_event);
686 init_completion(&wl->txq_thread_started);
691 static int wlan_deinit_locks(struct net_device *dev)
693 struct wilc_vif *vif;
696 vif = netdev_priv(dev);
700 mutex_destroy(&wilc->hif_cs);
703 mutex_destroy(&wilc->rxq_cs);
708 static int wlan_initialize_threads(struct net_device *dev)
710 struct wilc_vif *vif;
713 vif = netdev_priv(dev);
716 wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev,
718 if (IS_ERR(wilc->txq_thread)) {
719 netdev_err(dev, "couldn't create TXQ thread\n");
721 return PTR_ERR(wilc->txq_thread);
723 wait_for_completion(&wilc->txq_thread_started);
728 static void wlan_deinitialize_threads(struct net_device *dev)
730 struct wilc_vif *vif;
733 vif = netdev_priv(dev);
739 complete(&wl->txq_event);
741 if (wl->txq_thread) {
742 kthread_stop(wl->txq_thread);
743 wl->txq_thread = NULL;
747 int wilc1000_wlan_init(struct net_device *dev, struct wilc_vif *vif)
750 struct wilc *wl = vif->wilc;
752 if (!wl->initialized) {
753 wl->mac_status = WILC_MAC_STATUS_INIT;
756 wlan_init_locks(dev);
758 ret = wilc_wlan_init(dev);
764 if (wl->gpio >= 0 && init_irq(dev)) {
769 ret = wlan_initialize_threads(dev);
772 goto _fail_wilc_wlan_;
775 if (!wl->dev_irq_num &&
776 wl->hif_func->enable_interrupt &&
777 wl->hif_func->enable_interrupt(wl)) {
779 goto _fail_irq_init_;
782 if (wilc_wlan_get_firmware(dev)) {
784 goto _fail_irq_enable_;
787 ret = wilc1000_firmware_download(dev);
790 goto _fail_irq_enable_;
793 ret = linux_wlan_start_firmware(dev);
796 goto _fail_irq_enable_;
799 if (wilc_wlan_cfg_get(vif, 1, WID_FIRMWARE_VERSION, 1, 0)) {
801 char firmware_ver[20];
803 size = wilc_wlan_cfg_get_val(WID_FIRMWARE_VERSION,
805 sizeof(firmware_ver));
806 firmware_ver[size] = '\0';
807 netdev_dbg(dev, "Firmware Ver = %s\n", firmware_ver);
809 ret = linux_wlan_init_test_config(dev, vif);
812 netdev_err(dev, "Failed to configure firmware\n");
814 goto _fail_fw_start_;
817 wl->initialized = true;
824 if (!wl->dev_irq_num &&
825 wl->hif_func->disable_interrupt)
826 wl->hif_func->disable_interrupt(wl);
831 wlan_deinitialize_threads(dev);
833 wilc_wlan_cleanup(dev);
835 wlan_deinit_locks(dev);
836 netdev_err(dev, "WLAN Iinitialization FAILED\n");
838 netdev_dbg(dev, "wilc1000 already initialized\n");
843 static int mac_init_fn(struct net_device *ndev)
845 netif_start_queue(ndev);
846 netif_stop_queue(ndev);
851 int wilc_mac_open(struct net_device *ndev)
853 struct wilc_vif *vif;
855 unsigned char mac_add[ETH_ALEN] = {0};
860 vif = netdev_priv(ndev);
863 if (!wl || !wl->dev) {
864 netdev_err(ndev, "device not ready\n");
868 netdev_dbg(ndev, "MAC OPEN[%p]\n", ndev);
870 ret = wilc_init_host_int(ndev);
874 ret = wilc1000_wlan_init(ndev, vif);
876 wilc_deinit_host_int(ndev);
880 for (i = 0; i < wl->vif_num; i++) {
881 if (ndev == wl->vif[i]->ndev) {
882 if (vif->iftype == AP_MODE) {
883 wilc_set_wfi_drv_handler(vif,
884 wilc_get_vif_idx(vif),
886 } else if (!wilc_wlan_get_num_conn_ifcs(wl)) {
887 wilc_set_wfi_drv_handler(vif,
888 wilc_get_vif_idx(vif),
891 if (memcmp(wl->vif[i ^ 1]->bssid,
892 wl->vif[i ^ 1]->src_addr, 6))
893 wilc_set_wfi_drv_handler(vif,
894 wilc_get_vif_idx(vif),
897 wilc_set_wfi_drv_handler(vif,
898 wilc_get_vif_idx(vif),
901 wilc_set_operation_mode(vif, vif->iftype);
903 wilc_get_mac_address(vif, mac_add);
904 netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
905 memcpy(wl->vif[i]->src_addr, mac_add, ETH_ALEN);
911 memcpy(ndev->dev_addr, wl->vif[i]->src_addr, ETH_ALEN);
913 if (!is_valid_ether_addr(ndev->dev_addr)) {
914 netdev_err(ndev, "Wrong MAC address\n");
915 wilc_deinit_host_int(ndev);
916 wilc1000_wlan_deinit(ndev);
920 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
921 vif->ndev->ieee80211_ptr,
922 vif->frame_reg[0].type,
923 vif->frame_reg[0].reg);
924 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
925 vif->ndev->ieee80211_ptr,
926 vif->frame_reg[1].type,
927 vif->frame_reg[1].reg);
928 netif_wake_queue(ndev);
934 static struct net_device_stats *mac_stats(struct net_device *dev)
936 struct wilc_vif *vif = netdev_priv(dev);
938 return &vif->netstats;
941 static void wilc_set_multicast_list(struct net_device *dev)
943 struct netdev_hw_addr *ha;
944 struct wilc_vif *vif;
947 vif = netdev_priv(dev);
949 if (dev->flags & IFF_PROMISC)
952 if ((dev->flags & IFF_ALLMULTI) ||
953 (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
954 wilc_setup_multicast_filter(vif, false, 0);
958 if ((dev->mc.count) == 0) {
959 wilc_setup_multicast_filter(vif, true, 0);
963 netdev_for_each_mc_addr(ha, dev) {
964 memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN);
965 netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
966 wilc_multicast_mac_addr_list[i][0],
967 wilc_multicast_mac_addr_list[i][1],
968 wilc_multicast_mac_addr_list[i][2],
969 wilc_multicast_mac_addr_list[i][3],
970 wilc_multicast_mac_addr_list[i][4],
971 wilc_multicast_mac_addr_list[i][5]);
975 wilc_setup_multicast_filter(vif, true, (dev->mc.count));
978 static void linux_wlan_tx_complete(void *priv, int status)
980 struct tx_complete_data *pv_data = priv;
982 dev_kfree_skb(pv_data->skb);
986 int wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
988 struct wilc_vif *vif;
989 struct tx_complete_data *tx_data = NULL;
993 struct ethhdr *eth_h;
996 vif = netdev_priv(ndev);
999 if (skb->dev != ndev) {
1000 netdev_err(ndev, "Packet not destined to this device\n");
1004 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
1007 netif_wake_queue(ndev);
1011 tx_data->buff = skb->data;
1012 tx_data->size = skb->len;
1015 eth_h = (struct ethhdr *)(skb->data);
1016 if (eth_h->h_proto == 0x8e88)
1017 netdev_dbg(ndev, "EAPOL transmitted\n");
1019 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
1021 udp_buf = (char *)ih + sizeof(struct iphdr);
1022 if ((udp_buf[1] == 68 && udp_buf[3] == 67) ||
1023 (udp_buf[1] == 67 && udp_buf[3] == 68))
1024 netdev_dbg(ndev, "DHCP Message transmitted, type:%x %x %x\n",
1025 udp_buf[248], udp_buf[249], udp_buf[250]);
1027 vif->netstats.tx_packets++;
1028 vif->netstats.tx_bytes += tx_data->size;
1029 tx_data->bssid = wilc->vif[vif->idx]->bssid;
1030 queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
1031 tx_data->buff, tx_data->size,
1032 linux_wlan_tx_complete);
1034 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
1035 netif_stop_queue(wilc->vif[0]->ndev);
1036 netif_stop_queue(wilc->vif[1]->ndev);
1042 int wilc_mac_close(struct net_device *ndev)
1044 struct wilc_priv *priv;
1045 struct wilc_vif *vif;
1046 struct host_if_drv *hif_drv;
1049 vif = netdev_priv(ndev);
1051 if (!vif || !vif->ndev || !vif->ndev->ieee80211_ptr ||
1052 !vif->ndev->ieee80211_ptr->wiphy)
1055 priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy);
1061 hif_drv = (struct host_if_drv *)priv->hif_drv;
1063 netdev_dbg(ndev, "Mac close\n");
1071 if ((wl->open_ifcs) > 0)
1077 netif_stop_queue(vif->ndev);
1079 wilc_deinit_host_int(vif->ndev);
1082 if (wl->open_ifcs == 0) {
1083 netdev_dbg(ndev, "Deinitializing wilc1000\n");
1085 wilc1000_wlan_deinit(ndev);
1086 WILC_WFI_deinit_mon_interface();
1089 vif->mac_opened = 0;
1094 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
1098 u32 size = 0, length = 0;
1099 struct wilc_vif *vif;
1103 vif = netdev_priv(ndev);
1106 if (!wilc->initialized)
1112 struct iwreq *wrq = (struct iwreq *)req;
1114 size = wrq->u.data.length;
1116 if (size && wrq->u.data.pointer) {
1117 buff = memdup_user(wrq->u.data.pointer,
1118 wrq->u.data.length);
1120 return PTR_ERR(buff);
1122 if (strncasecmp(buff, "RSSI", length) == 0) {
1123 ret = wilc_get_rssi(vif, &rssi);
1124 netdev_info(ndev, "RSSI :%d\n", rssi);
1128 snprintf(buff, size, "rssi %d", rssi);
1130 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
1131 netdev_err(ndev, "failed to copy\n");
1142 netdev_info(ndev, "Command - %d - has been received\n", cmd);
1155 void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset)
1157 unsigned int frame_len = 0;
1159 unsigned char *buff_to_send = NULL;
1160 struct sk_buff *skb;
1161 struct net_device *wilc_netdev;
1162 struct wilc_vif *vif;
1167 wilc_netdev = get_if_handler(wilc, buff);
1172 vif = netdev_priv(wilc_netdev);
1176 buff_to_send = buff;
1178 skb = dev_alloc_skb(frame_len);
1182 skb->dev = wilc_netdev;
1184 memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
1186 skb->protocol = eth_type_trans(skb, wilc_netdev);
1187 vif->netstats.rx_packets++;
1188 vif->netstats.rx_bytes += frame_len;
1189 skb->ip_summed = CHECKSUM_UNNECESSARY;
1190 stats = netif_rx(skb);
1191 netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
1195 void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
1198 struct wilc_vif *vif;
1200 for (i = 0; i < wilc->vif_num; i++) {
1201 vif = netdev_priv(wilc->vif[i]->ndev);
1202 if (vif->monitor_flag) {
1203 WILC_WFI_monitor_rx(buff, size);
1208 vif = netdev_priv(wilc->vif[1]->ndev);
1209 if ((buff[0] == vif->frame_reg[0].type && vif->frame_reg[0].reg) ||
1210 (buff[0] == vif->frame_reg[1].type && vif->frame_reg[1].reg))
1211 WILC_WFI_p2p_rx(wilc->vif[1]->ndev, buff, size);
1214 void wilc_netdev_cleanup(struct wilc *wilc)
1217 struct wilc_vif *vif[NUM_CONCURRENT_IFC];
1219 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) {
1220 unregister_inetaddr_notifier(&g_dev_notifier);
1222 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1223 vif[i] = netdev_priv(wilc->vif[i]->ndev);
1226 if (wilc && wilc->firmware) {
1227 release_firmware(wilc->firmware);
1228 wilc->firmware = NULL;
1231 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) {
1232 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1233 if (wilc->vif[i]->ndev)
1234 if (vif[i]->mac_opened)
1235 wilc_mac_close(wilc->vif[i]->ndev);
1237 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1238 unregister_netdev(wilc->vif[i]->ndev);
1239 wilc_free_wiphy(wilc->vif[i]->ndev);
1240 free_netdev(wilc->vif[i]->ndev);
1246 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
1248 int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1249 int gpio, const struct wilc_hif_func *ops)
1252 struct wilc_vif *vif;
1253 struct net_device *ndev;
1256 wl = kzalloc(sizeof(*wl), GFP_KERNEL);
1261 wl->io_type = io_type;
1265 register_inetaddr_notifier(&g_dev_notifier);
1267 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1268 ndev = alloc_etherdev(sizeof(struct wilc_vif));
1272 vif = netdev_priv(ndev);
1273 memset(vif, 0, sizeof(struct wilc_vif));
1276 strcpy(ndev->name, "wlan%d");
1278 strcpy(ndev->name, "p2p%d");
1280 vif->idx = wl->vif_num;
1283 wl->vif[wl->vif_num]->ndev = ndev;
1285 ndev->netdev_ops = &wilc_netdev_ops;
1288 struct wireless_dev *wdev;
1290 wdev = wilc_create_wiphy(ndev, dev);
1293 SET_NETDEV_DEV(ndev, dev);
1296 netdev_err(ndev, "Can't register WILC Wiphy\n");
1300 vif->ndev->ieee80211_ptr = wdev;
1301 vif->ndev->ml_priv = vif;
1302 wdev->netdev = vif->ndev;
1303 vif->netstats.rx_packets = 0;
1304 vif->netstats.tx_packets = 0;
1305 vif->netstats.rx_bytes = 0;
1306 vif->netstats.tx_bytes = 0;
1309 ret = register_netdev(ndev);
1313 vif->iftype = STATION_MODE;
1314 vif->mac_opened = 0;
1319 EXPORT_SYMBOL_GPL(wilc_netdev_init);
1321 MODULE_LICENSE("GPL");