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>
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 struct semaphore close_exit_sync;
36 static int wlan_deinit_locks(struct net_device *dev);
37 static void wlan_deinitialize_threads(struct net_device *dev);
39 static void linux_wlan_tx_complete(void *priv, int status);
40 static int mac_init_fn(struct net_device *ndev);
41 static struct net_device_stats *mac_stats(struct net_device *dev);
42 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
43 static void wilc_set_multicast_list(struct net_device *dev);
45 bool wilc_enable_ps = true;
47 static const struct net_device_ops wilc_netdev_ops = {
48 .ndo_init = mac_init_fn,
49 .ndo_open = wilc_mac_open,
50 .ndo_stop = wilc_mac_close,
51 .ndo_start_xmit = wilc_mac_xmit,
52 .ndo_do_ioctl = mac_ioctl,
53 .ndo_get_stats = mac_stats,
54 .ndo_set_rx_mode = wilc_set_multicast_list,
58 static int dev_state_ev_handler(struct notifier_block *this,
59 unsigned long event, void *ptr)
61 struct in_ifaddr *dev_iface = ptr;
62 struct wilc_priv *priv;
63 struct host_if_drv *hif_drv;
64 struct net_device *dev;
68 char wlan_dev_name[5] = "wlan0";
70 if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev)
73 if (memcmp(dev_iface->ifa_label, "wlan0", 5) &&
74 memcmp(dev_iface->ifa_label, "p2p0", 4))
77 dev = (struct net_device *)dev_iface->ifa_dev->dev;
78 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
81 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
85 hif_drv = (struct host_if_drv *)priv->hif_drv;
86 vif = netdev_priv(dev);
92 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
94 wilc_optaining_ip = false;
95 del_timer(&wilc_during_ip_timer);
99 wilc_set_power_mgmt(vif, 1, 0);
101 netdev_dbg(dev, "[%s] Up IP\n", dev_iface->ifa_label);
103 ip_addr_buf = (char *)&dev_iface->ifa_address;
104 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
105 ip_addr_buf[0], ip_addr_buf[1],
106 ip_addr_buf[2], ip_addr_buf[3]);
107 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
112 if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) {
114 wilc_optaining_ip = false;
117 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
118 wilc_set_power_mgmt(vif, 0, 0);
120 wilc_resolve_disconnect_aberration(vif);
122 netdev_dbg(dev, "[%s] Down IP\n", dev_iface->ifa_label);
124 ip_addr_buf = null_ip;
125 netdev_dbg(dev, "IP add=%d:%d:%d:%d\n",
126 ip_addr_buf[0], ip_addr_buf[1],
127 ip_addr_buf[2], ip_addr_buf[3]);
129 wilc_setup_ipaddress(vif, ip_addr_buf, vif->idx);
140 static irqreturn_t isr_uh_routine(int irq, void *user_data)
142 struct wilc_vif *vif;
144 struct net_device *dev = user_data;
146 vif = netdev_priv(dev);
150 netdev_err(dev, "Can't handle UH interrupt\n");
153 return IRQ_WAKE_THREAD;
156 static irqreturn_t isr_bh_routine(int irq, void *userdata)
158 struct wilc_vif *vif;
160 struct net_device *dev = userdata;
162 vif = netdev_priv(userdata);
166 netdev_err(dev, "Can't handle BH interrupt\n");
170 wilc_handle_isr(wilc);
175 static int init_irq(struct net_device *dev)
178 struct wilc_vif *vif;
181 vif = netdev_priv(dev);
184 if ((gpio_request(wl->gpio, "WILC_INTR") == 0) &&
185 (gpio_direction_input(wl->gpio) == 0)) {
186 wl->dev_irq_num = gpio_to_irq(wl->gpio);
189 netdev_err(dev, "could not obtain gpio for WILC_INTR\n");
192 if (ret != -1 && request_threaded_irq(wl->dev_irq_num,
195 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
196 "WILC_IRQ", dev) < 0) {
197 netdev_err(dev, "Failed to request IRQ GPIO: %d\n", wl->gpio);
202 "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
203 wl->dev_irq_num, wl->gpio);
209 static void deinit_irq(struct net_device *dev)
211 struct wilc_vif *vif;
214 vif = netdev_priv(dev);
217 /* Deintialize IRQ */
218 if (wilc->dev_irq_num) {
219 free_irq(wilc->dev_irq_num, wilc);
220 gpio_free(wilc->gpio);
224 int wilc_lock_timeout(struct wilc *nic, void *vp, u32 timeout)
226 /* FIXME: replace with mutex_lock or wait_for_completion */
230 error = down_timeout(vp,
231 msecs_to_jiffies(timeout));
235 void wilc_mac_indicate(struct wilc *wilc, int flag)
239 if (flag == WILC_MAC_INDICATE_STATUS) {
240 wilc_wlan_cfg_get_val(WID_STATUS,
241 (unsigned char *)&status, 4);
242 if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
243 wilc->mac_status = status;
244 up(&wilc->sync_event);
246 wilc->mac_status = status;
251 static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
256 bssid = mac_header + 10;
257 bssid1 = mac_header + 4;
259 for (i = 0; i < wilc->vif_num; i++) {
260 if (wilc->vif[i]->mode == STATION_MODE)
261 if (ether_addr_equal_unaligned(bssid,
262 wilc->vif[i]->bssid))
263 return wilc->vif[i]->ndev;
264 if (wilc->vif[i]->mode == AP_MODE)
265 if (ether_addr_equal_unaligned(bssid1,
266 wilc->vif[i]->bssid))
267 return wilc->vif[i]->ndev;
273 int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
277 struct wilc_vif *vif;
280 vif = netdev_priv(wilc_netdev);
283 for (i = 0; i < wilc->vif_num; i++)
284 if (wilc->vif[i]->ndev == wilc_netdev) {
285 memcpy(wilc->vif[i]->bssid, bssid, 6);
286 wilc->vif[i]->mode = mode;
294 int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
297 u8 null_bssid[6] = {0};
300 for (i = 0; i < wilc->vif_num; i++)
301 if (memcmp(wilc->vif[i]->bssid, null_bssid, 6))
307 static int linux_wlan_txq_task(void *vp)
310 struct wilc_vif *vif;
312 struct net_device *dev = vp;
314 vif = netdev_priv(dev);
317 complete(&wl->txq_thread_started);
319 down(&wl->txq_event);
322 complete(&wl->txq_thread_started);
324 while (!kthread_should_stop())
329 ret = wilc_wlan_handle_txq(dev, &txq_count);
330 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
331 if (netif_queue_stopped(wl->vif[0]->ndev))
332 netif_wake_queue(wl->vif[0]->ndev);
333 if (netif_queue_stopped(wl->vif[1]->ndev))
334 netif_wake_queue(wl->vif[1]->ndev);
336 } while (ret == WILC_TX_ERR_NO_BUF && !wl->close);
341 int wilc_wlan_get_firmware(struct net_device *dev)
343 struct wilc_vif *vif;
345 int chip_id, ret = 0;
346 const struct firmware *wilc_firmware;
349 vif = netdev_priv(dev);
352 chip_id = wilc_get_chipid(wilc, false);
354 if (chip_id < 0x1003a0)
355 firmware = FIRMWARE_1002;
357 firmware = FIRMWARE_1003;
359 netdev_info(dev, "loading firmware %s\n", firmware);
361 if (!(&vif->ndev->dev))
364 if (request_firmware(&wilc_firmware, firmware, wilc->dev) != 0) {
365 netdev_err(dev, "%s - firmare not available\n", firmware);
369 wilc->firmware = wilc_firmware;
376 static int linux_wlan_start_firmware(struct net_device *dev)
378 struct wilc_vif *vif;
382 vif = netdev_priv(dev);
385 ret = wilc_wlan_start(wilc);
389 ret = wilc_lock_timeout(wilc, &wilc->sync_event, 5000);
396 static int wilc1000_firmware_download(struct net_device *dev)
398 struct wilc_vif *vif;
402 vif = netdev_priv(dev);
405 if (!wilc->firmware) {
406 netdev_err(dev, "Firmware buffer is NULL\n");
410 ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data,
411 wilc->firmware->size);
415 release_firmware(wilc->firmware);
416 wilc->firmware = NULL;
418 netdev_dbg(dev, "Download Succeeded\n");
423 static int linux_wlan_init_test_config(struct net_device *dev,
424 struct wilc_vif *vif)
426 unsigned char c_val[64];
427 struct wilc *wilc = vif->wilc;
428 struct wilc_priv *priv;
429 struct host_if_drv *hif_drv;
431 netdev_dbg(dev, "Start configuring Firmware\n");
432 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
433 hif_drv = (struct host_if_drv *)priv->hif_drv;
434 netdev_dbg(dev, "Host = %p\n", hif_drv);
435 wilc_get_chipid(wilc, false);
439 if (!wilc_wlan_cfg_set(vif, 1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
443 if (!wilc_wlan_cfg_set(vif, 0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
446 c_val[0] = INFRASTRUCTURE;
447 if (!wilc_wlan_cfg_set(vif, 0, WID_BSS_TYPE, c_val, 1, 0, 0))
450 c_val[0] = RATE_AUTO;
451 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
454 c_val[0] = G_MIXED_11B_2_MODE;
455 if (!wilc_wlan_cfg_set(vif, 0, WID_11G_OPERATING_MODE, c_val, 1, 0,
460 if (!wilc_wlan_cfg_set(vif, 0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
463 c_val[0] = G_SHORT_PREAMBLE;
464 if (!wilc_wlan_cfg_set(vif, 0, WID_PREAMBLE, c_val, 1, 0, 0))
467 c_val[0] = AUTO_PROT;
468 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
471 c_val[0] = ACTIVE_SCAN;
472 if (!wilc_wlan_cfg_set(vif, 0, WID_SCAN_TYPE, c_val, 1, 0, 0))
475 c_val[0] = SITE_SURVEY_OFF;
476 if (!wilc_wlan_cfg_set(vif, 0, WID_SITE_SURVEY, c_val, 1, 0, 0))
479 *((int *)c_val) = 0xffff;
480 if (!wilc_wlan_cfg_set(vif, 0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
483 *((int *)c_val) = 2346;
484 if (!wilc_wlan_cfg_set(vif, 0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
488 if (!wilc_wlan_cfg_set(vif, 0, WID_BCAST_SSID, c_val, 1, 0, 0))
492 if (!wilc_wlan_cfg_set(vif, 0, WID_QOS_ENABLE, c_val, 1, 0, 0))
495 c_val[0] = NO_POWERSAVE;
496 if (!wilc_wlan_cfg_set(vif, 0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
499 c_val[0] = NO_SECURITY; /* NO_ENCRYPT, 0x79 */
500 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_MODE, c_val, 1, 0, 0))
503 c_val[0] = OPEN_SYSTEM;
504 if (!wilc_wlan_cfg_set(vif, 0, WID_AUTH_TYPE, c_val, 1, 0, 0))
507 strcpy(c_val, "123456790abcdef1234567890");
508 if (!wilc_wlan_cfg_set(vif, 0, WID_WEP_KEY_VALUE, c_val,
509 (strlen(c_val) + 1), 0, 0))
512 strcpy(c_val, "12345678");
513 if (!wilc_wlan_cfg_set(vif, 0, WID_11I_PSK, c_val, (strlen(c_val)), 0,
517 strcpy(c_val, "password");
518 if (!wilc_wlan_cfg_set(vif, 0, WID_1X_KEY, c_val, (strlen(c_val) + 1),
526 if (!wilc_wlan_cfg_set(vif, 0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
530 if (!wilc_wlan_cfg_set(vif, 0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
534 if (!wilc_wlan_cfg_set(vif, 0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
537 c_val[0] = NORMAL_ACK;
538 if (!wilc_wlan_cfg_set(vif, 0, WID_ACK_POLICY, c_val, 1, 0, 0))
542 if (!wilc_wlan_cfg_set(vif, 0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1,
547 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0,
552 if (!wilc_wlan_cfg_set(vif, 0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0,
556 *((int *)c_val) = 100;
557 if (!wilc_wlan_cfg_set(vif, 0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
560 c_val[0] = REKEY_DISABLE;
561 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_POLICY, c_val, 1, 0, 0))
564 *((int *)c_val) = 84600;
565 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
568 *((int *)c_val) = 500;
569 if (!wilc_wlan_cfg_set(vif, 0, WID_REKEY_PACKET_COUNT, c_val, 4, 0,
574 if (!wilc_wlan_cfg_set(vif, 0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0,
578 c_val[0] = G_SELF_CTS_PROT;
579 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
583 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_ENABLE, c_val, 1, 0, 0))
586 c_val[0] = HT_MIXED_MODE;
587 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OPERATING_MODE, c_val, 1, 0,
592 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0,
596 c_val[0] = DETECT_PROTECT_REPORT;
597 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1,
601 c_val[0] = RTS_CTS_NONHT_PROT;
602 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
606 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0,
610 c_val[0] = MIMO_MODE;
611 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
615 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0,
620 if (!wilc_wlan_cfg_set(vif, 0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1,
630 void wilc1000_wlan_deinit(struct net_device *dev)
632 struct wilc_vif *vif;
635 vif = netdev_priv(dev);
639 netdev_err(dev, "wl is NULL\n");
643 if (wl->initialized) {
644 netdev_info(dev, "Deinitializing wilc1000...\n");
646 if (!wl->dev_irq_num &&
647 wl->hif_func->disable_interrupt) {
648 mutex_lock(&wl->hif_cs);
649 wl->hif_func->disable_interrupt(wl);
650 mutex_unlock(&wl->hif_cs);
655 wlan_deinitialize_threads(dev);
659 wilc_wlan_cleanup(dev);
660 wlan_deinit_locks(dev);
662 wl->initialized = false;
664 netdev_dbg(dev, "wilc1000 deinitialization Done\n");
666 netdev_dbg(dev, "wilc1000 is not initialized\n");
670 static int wlan_init_locks(struct net_device *dev)
672 struct wilc_vif *vif;
675 vif = netdev_priv(dev);
678 mutex_init(&wl->hif_cs);
679 mutex_init(&wl->rxq_cs);
681 spin_lock_init(&wl->txq_spinlock);
682 sema_init(&wl->txq_add_to_head_cs, 1);
684 sema_init(&wl->txq_event, 0);
686 sema_init(&wl->cfg_event, 0);
687 sema_init(&wl->sync_event, 0);
688 init_completion(&wl->txq_thread_started);
693 static int wlan_deinit_locks(struct net_device *dev)
695 struct wilc_vif *vif;
698 vif = netdev_priv(dev);
702 mutex_destroy(&wilc->hif_cs);
705 mutex_destroy(&wilc->rxq_cs);
710 static int wlan_initialize_threads(struct net_device *dev)
712 struct wilc_vif *vif;
715 vif = netdev_priv(dev);
718 wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev,
720 if (!wilc->txq_thread) {
721 netdev_err(dev, "couldn't create TXQ thread\n");
725 wait_for_completion(&wilc->txq_thread_started);
730 static void wlan_deinitialize_threads(struct net_device *dev)
732 struct wilc_vif *vif;
735 vif = netdev_priv(dev);
743 if (wl->txq_thread) {
744 kthread_stop(wl->txq_thread);
745 wl->txq_thread = NULL;
749 int wilc1000_wlan_init(struct net_device *dev, struct wilc_vif *vif)
752 struct wilc *wl = vif->wilc;
754 if (!wl->initialized) {
755 wl->mac_status = WILC_MAC_STATUS_INIT;
758 wlan_init_locks(dev);
760 ret = wilc_wlan_init(dev);
766 if (wl->gpio >= 0 && init_irq(dev)) {
771 ret = wlan_initialize_threads(dev);
774 goto _fail_wilc_wlan_;
777 if (!wl->dev_irq_num &&
778 wl->hif_func->enable_interrupt &&
779 wl->hif_func->enable_interrupt(wl)) {
781 goto _fail_irq_init_;
784 if (wilc_wlan_get_firmware(dev)) {
786 goto _fail_irq_enable_;
789 ret = wilc1000_firmware_download(dev);
792 goto _fail_irq_enable_;
795 ret = linux_wlan_start_firmware(dev);
798 goto _fail_irq_enable_;
801 if (wilc_wlan_cfg_get(vif, 1, WID_FIRMWARE_VERSION, 1, 0)) {
803 char firmware_ver[20];
805 size = wilc_wlan_cfg_get_val(WID_FIRMWARE_VERSION,
807 sizeof(firmware_ver));
808 firmware_ver[size] = '\0';
809 netdev_dbg(dev, "Firmware Ver = %s\n", firmware_ver);
811 ret = linux_wlan_init_test_config(dev, vif);
814 netdev_err(dev, "Failed to configure firmware\n");
816 goto _fail_fw_start_;
819 wl->initialized = true;
826 if (!wl->dev_irq_num &&
827 wl->hif_func->disable_interrupt)
828 wl->hif_func->disable_interrupt(wl);
833 wlan_deinitialize_threads(dev);
835 wilc_wlan_cleanup(dev);
837 wlan_deinit_locks(dev);
838 netdev_err(dev, "WLAN Iinitialization FAILED\n");
840 netdev_dbg(dev, "wilc1000 already initialized\n");
845 static int mac_init_fn(struct net_device *ndev)
847 netif_start_queue(ndev);
848 netif_stop_queue(ndev);
853 int wilc_mac_open(struct net_device *ndev)
855 struct wilc_vif *vif;
857 unsigned char mac_add[ETH_ALEN] = {0};
862 vif = netdev_priv(ndev);
865 if (!wl || !wl->dev) {
866 netdev_err(ndev, "device not ready\n");
870 netdev_dbg(ndev, "MAC OPEN[%p]\n", ndev);
872 ret = wilc_init_host_int(ndev);
876 ret = wilc1000_wlan_init(ndev, vif);
878 wilc_deinit_host_int(ndev);
882 for (i = 0; i < wl->vif_num; i++) {
883 if (ndev == wl->vif[i]->ndev) {
884 if (vif->iftype == AP_MODE) {
885 wilc_set_wfi_drv_handler(vif,
886 wilc_get_vif_idx(vif),
888 } else if (!wilc_wlan_get_num_conn_ifcs(wl)) {
889 wilc_set_wfi_drv_handler(vif,
890 wilc_get_vif_idx(vif),
893 if (memcmp(wl->vif[i ^ 1]->bssid,
894 wl->vif[i ^ 1]->src_addr, 6))
895 wilc_set_wfi_drv_handler(vif,
896 wilc_get_vif_idx(vif),
899 wilc_set_wfi_drv_handler(vif,
900 wilc_get_vif_idx(vif),
903 wilc_set_operation_mode(vif, vif->iftype);
905 wilc_get_mac_address(vif, mac_add);
906 netdev_dbg(ndev, "Mac address: %pM\n", mac_add);
907 memcpy(wl->vif[i]->src_addr, mac_add, ETH_ALEN);
913 memcpy(ndev->dev_addr, wl->vif[i]->src_addr, ETH_ALEN);
915 if (!is_valid_ether_addr(ndev->dev_addr)) {
916 netdev_err(ndev, "Wrong MAC address\n");
917 wilc_deinit_host_int(ndev);
918 wilc1000_wlan_deinit(ndev);
922 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
923 vif->ndev->ieee80211_ptr,
924 vif->frame_reg[0].type,
925 vif->frame_reg[0].reg);
926 wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy,
927 vif->ndev->ieee80211_ptr,
928 vif->frame_reg[1].type,
929 vif->frame_reg[1].reg);
930 netif_wake_queue(ndev);
936 static struct net_device_stats *mac_stats(struct net_device *dev)
938 struct wilc_vif *vif = netdev_priv(dev);
940 return &vif->netstats;
943 static void wilc_set_multicast_list(struct net_device *dev)
945 struct netdev_hw_addr *ha;
946 struct wilc_vif *vif;
949 vif = netdev_priv(dev);
951 if (dev->flags & IFF_PROMISC)
954 if ((dev->flags & IFF_ALLMULTI) ||
955 (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
956 wilc_setup_multicast_filter(vif, false, 0);
960 if ((dev->mc.count) == 0) {
961 wilc_setup_multicast_filter(vif, true, 0);
965 netdev_for_each_mc_addr(ha, dev) {
966 memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN);
967 netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
968 wilc_multicast_mac_addr_list[i][0],
969 wilc_multicast_mac_addr_list[i][1],
970 wilc_multicast_mac_addr_list[i][2],
971 wilc_multicast_mac_addr_list[i][3],
972 wilc_multicast_mac_addr_list[i][4],
973 wilc_multicast_mac_addr_list[i][5]);
977 wilc_setup_multicast_filter(vif, true, (dev->mc.count));
980 static void linux_wlan_tx_complete(void *priv, int status)
982 struct tx_complete_data *pv_data = priv;
984 dev_kfree_skb(pv_data->skb);
988 int wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
990 struct wilc_vif *vif;
991 struct tx_complete_data *tx_data = NULL;
995 struct ethhdr *eth_h;
998 vif = netdev_priv(ndev);
1001 if (skb->dev != ndev) {
1002 netdev_err(ndev, "Packet not destined to this device\n");
1006 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
1009 netif_wake_queue(ndev);
1013 tx_data->buff = skb->data;
1014 tx_data->size = skb->len;
1017 eth_h = (struct ethhdr *)(skb->data);
1018 if (eth_h->h_proto == 0x8e88)
1019 netdev_dbg(ndev, "EAPOL transmitted\n");
1021 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
1023 udp_buf = (char *)ih + sizeof(struct iphdr);
1024 if ((udp_buf[1] == 68 && udp_buf[3] == 67) ||
1025 (udp_buf[1] == 67 && udp_buf[3] == 68))
1026 netdev_dbg(ndev, "DHCP Message transmitted, type:%x %x %x\n",
1027 udp_buf[248], udp_buf[249], udp_buf[250]);
1029 vif->netstats.tx_packets++;
1030 vif->netstats.tx_bytes += tx_data->size;
1031 tx_data->bssid = wilc->vif[vif->idx]->bssid;
1032 queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
1033 tx_data->buff, tx_data->size,
1034 linux_wlan_tx_complete);
1036 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
1037 netif_stop_queue(wilc->vif[0]->ndev);
1038 netif_stop_queue(wilc->vif[1]->ndev);
1044 int wilc_mac_close(struct net_device *ndev)
1046 struct wilc_priv *priv;
1047 struct wilc_vif *vif;
1048 struct host_if_drv *hif_drv;
1051 vif = netdev_priv(ndev);
1053 if (!vif || !vif->ndev || !vif->ndev->ieee80211_ptr ||
1054 !vif->ndev->ieee80211_ptr->wiphy)
1057 priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy);
1063 hif_drv = (struct host_if_drv *)priv->hif_drv;
1065 netdev_dbg(ndev, "Mac close\n");
1073 if ((wl->open_ifcs) > 0)
1079 netif_stop_queue(vif->ndev);
1081 wilc_deinit_host_int(vif->ndev);
1084 if (wl->open_ifcs == 0) {
1085 netdev_dbg(ndev, "Deinitializing wilc1000\n");
1087 wilc1000_wlan_deinit(ndev);
1088 WILC_WFI_deinit_mon_interface();
1091 up(&close_exit_sync);
1092 vif->mac_opened = 0;
1097 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
1101 u32 size = 0, length = 0;
1102 struct wilc_vif *vif;
1106 vif = netdev_priv(ndev);
1109 if (!wilc->initialized)
1115 struct iwreq *wrq = (struct iwreq *)req;
1117 size = wrq->u.data.length;
1119 if (size && wrq->u.data.pointer) {
1120 buff = memdup_user(wrq->u.data.pointer,
1121 wrq->u.data.length);
1123 return PTR_ERR(buff);
1125 if (strncasecmp(buff, "RSSI", length) == 0) {
1126 ret = wilc_get_rssi(vif, &rssi);
1127 netdev_info(ndev, "RSSI :%d\n", rssi);
1131 snprintf(buff, size, "rssi %d", rssi);
1133 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
1134 netdev_err(ndev, "failed to copy\n");
1145 netdev_info(ndev, "Command - %d - has been received\n", cmd);
1158 void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset)
1160 unsigned int frame_len = 0;
1162 unsigned char *buff_to_send = NULL;
1163 struct sk_buff *skb;
1164 struct net_device *wilc_netdev;
1165 struct wilc_vif *vif;
1170 wilc_netdev = get_if_handler(wilc, buff);
1175 vif = netdev_priv(wilc_netdev);
1179 buff_to_send = buff;
1181 skb = dev_alloc_skb(frame_len);
1185 skb->dev = wilc_netdev;
1187 memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
1189 skb->protocol = eth_type_trans(skb, wilc_netdev);
1190 vif->netstats.rx_packets++;
1191 vif->netstats.rx_bytes += frame_len;
1192 skb->ip_summed = CHECKSUM_UNNECESSARY;
1193 stats = netif_rx(skb);
1194 netdev_dbg(wilc_netdev, "netif_rx ret value is: %d\n", stats);
1198 void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
1201 struct wilc_vif *vif;
1203 for (i = 0; i < wilc->vif_num; i++) {
1204 vif = netdev_priv(wilc->vif[i]->ndev);
1205 if (vif->monitor_flag) {
1206 WILC_WFI_monitor_rx(buff, size);
1211 vif = netdev_priv(wilc->vif[1]->ndev);
1212 if ((buff[0] == vif->frame_reg[0].type && vif->frame_reg[0].reg) ||
1213 (buff[0] == vif->frame_reg[1].type && vif->frame_reg[1].reg))
1214 WILC_WFI_p2p_rx(wilc->vif[1]->ndev, buff, size);
1217 void wilc_netdev_cleanup(struct wilc *wilc)
1220 struct wilc_vif *vif[NUM_CONCURRENT_IFC];
1222 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) {
1223 unregister_inetaddr_notifier(&g_dev_notifier);
1225 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1226 vif[i] = netdev_priv(wilc->vif[i]->ndev);
1229 if (wilc && wilc->firmware) {
1230 release_firmware(wilc->firmware);
1231 wilc->firmware = NULL;
1234 if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) {
1235 wilc_lock_timeout(wilc, &close_exit_sync, 5 * 1000);
1237 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1238 if (wilc->vif[i]->ndev)
1239 if (vif[i]->mac_opened)
1240 wilc_mac_close(wilc->vif[i]->ndev);
1242 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1243 unregister_netdev(wilc->vif[i]->ndev);
1244 wilc_free_wiphy(wilc->vif[i]->ndev);
1245 free_netdev(wilc->vif[i]->ndev);
1251 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
1253 int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1254 int gpio, const struct wilc_hif_func *ops)
1257 struct wilc_vif *vif;
1258 struct net_device *ndev;
1261 sema_init(&close_exit_sync, 0);
1263 wl = kzalloc(sizeof(*wl), GFP_KERNEL);
1268 wl->io_type = io_type;
1272 register_inetaddr_notifier(&g_dev_notifier);
1274 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1275 ndev = alloc_etherdev(sizeof(struct wilc_vif));
1279 vif = netdev_priv(ndev);
1280 memset(vif, 0, sizeof(struct wilc_vif));
1283 strcpy(ndev->name, "wlan%d");
1285 strcpy(ndev->name, "p2p%d");
1287 vif->idx = wl->vif_num;
1290 wl->vif[wl->vif_num]->ndev = ndev;
1292 ndev->netdev_ops = &wilc_netdev_ops;
1295 struct wireless_dev *wdev;
1297 wdev = wilc_create_wiphy(ndev, dev);
1300 SET_NETDEV_DEV(ndev, dev);
1303 netdev_err(ndev, "Can't register WILC Wiphy\n");
1307 vif->ndev->ieee80211_ptr = wdev;
1308 vif->ndev->ml_priv = vif;
1309 wdev->netdev = vif->ndev;
1310 vif->netstats.rx_packets = 0;
1311 vif->netstats.tx_packets = 0;
1312 vif->netstats.rx_bytes = 0;
1313 vif->netstats.tx_bytes = 0;
1316 ret = register_netdev(ndev);
1320 vif->iftype = STATION_MODE;
1321 vif->mac_opened = 0;
1326 EXPORT_SYMBOL_GPL(wilc_netdev_init);
1328 MODULE_LICENSE("GPL");