Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1 | #include "wilc_wfi_cfgoperations.h" |
| 2 | #include "linux_wlan_common.h" |
| 3 | #include "wilc_wlan_if.h" |
| 4 | #include "wilc_wlan.h" |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 5 | |
| 6 | #include <linux/slab.h> |
| 7 | #include <linux/sched.h> |
| 8 | #include <linux/delay.h> |
| 9 | #include <linux/workqueue.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/irq.h> |
Guenter Roeck | f1a9983 | 2015-05-27 13:02:16 -0700 | [diff] [blame] | 12 | #include <linux/gpio.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 13 | |
| 14 | #include <linux/kthread.h> |
| 15 | #include <linux/firmware.h> |
| 16 | #include <linux/delay.h> |
| 17 | |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/netdevice.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 20 | #include <linux/inetdevice.h> |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 21 | #include <linux/etherdevice.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 26 | #include <linux/semaphore.h> |
| 27 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 28 | static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr); |
| 29 | |
| 30 | static struct notifier_block g_dev_notifier = { |
| 31 | .notifier_call = dev_state_ev_handler |
| 32 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 33 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 34 | #define IRQ_WAIT 1 |
| 35 | #define IRQ_NO_WAIT 0 |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 36 | static struct semaphore close_exit_sync; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 37 | |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 38 | static int wlan_deinit_locks(struct net_device *dev); |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 39 | static void wlan_deinitialize_threads(struct net_device *dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 40 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 41 | static void linux_wlan_tx_complete(void *priv, int status); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 42 | static int mac_init_fn(struct net_device *ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 43 | static struct net_device_stats *mac_stats(struct net_device *dev); |
| 44 | static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd); |
| 45 | static void wilc_set_multicast_list(struct net_device *dev); |
Arnd Bergmann | 750ffe9 | 2015-11-16 15:05:08 +0100 | [diff] [blame] | 46 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 47 | bool wilc_enable_ps = true; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 48 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 49 | static const struct net_device_ops wilc_netdev_ops = { |
| 50 | .ndo_init = mac_init_fn, |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 51 | .ndo_open = wilc_mac_open, |
| 52 | .ndo_stop = wilc_mac_close, |
| 53 | .ndo_start_xmit = wilc_mac_xmit, |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 54 | .ndo_do_ioctl = mac_ioctl, |
| 55 | .ndo_get_stats = mac_stats, |
| 56 | .ndo_set_rx_mode = wilc_set_multicast_list, |
| 57 | |
| 58 | }; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 59 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 60 | static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr) |
| 61 | { |
| 62 | struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr; |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 63 | struct wilc_priv *priv; |
Leo Kim | f24374a | 2015-11-05 14:36:12 +0900 | [diff] [blame] | 64 | struct host_if_drv *hif_drv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 65 | struct net_device *dev; |
Leo Kim | eac3e8f | 2015-11-05 14:36:16 +0900 | [diff] [blame] | 66 | u8 *ip_addr_buf; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 67 | struct wilc_vif *vif; |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 68 | u8 null_ip[4] = {0}; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 69 | char wlan_dev_name[5] = "wlan0"; |
| 70 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 71 | if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 72 | PRINT_D(GENERIC_DBG, "dev_iface = NULL\n"); |
| 73 | return NOTIFY_DONE; |
| 74 | } |
| 75 | |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 76 | if (memcmp(dev_iface->ifa_label, "wlan0", 5) && |
| 77 | memcmp(dev_iface->ifa_label, "p2p0", 4)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 78 | PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n"); |
| 79 | return NOTIFY_DONE; |
| 80 | } |
| 81 | |
| 82 | dev = (struct net_device *)dev_iface->ifa_dev->dev; |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 83 | if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 84 | PRINT_D(GENERIC_DBG, "No Wireless registerd\n"); |
| 85 | return NOTIFY_DONE; |
| 86 | } |
| 87 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 88 | if (!priv) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 89 | PRINT_D(GENERIC_DBG, "No Wireless Priv\n"); |
| 90 | return NOTIFY_DONE; |
| 91 | } |
Leo Kim | f24374a | 2015-11-05 14:36:12 +0900 | [diff] [blame] | 92 | hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 93 | vif = netdev_priv(dev); |
| 94 | if (!vif || !hif_drv) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 95 | PRINT_D(GENERIC_DBG, "No Wireless Priv\n"); |
| 96 | return NOTIFY_DONE; |
| 97 | } |
| 98 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 99 | PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 100 | |
| 101 | switch (event) { |
| 102 | case NETDEV_UP: |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 103 | PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 104 | |
| 105 | PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n"); |
| 106 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 107 | if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) { |
Leo Kim | f24374a | 2015-11-05 14:36:12 +0900 | [diff] [blame] | 108 | hif_drv->IFC_UP = 1; |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 109 | wilc_optaining_ip = false; |
| 110 | del_timer(&wilc_during_ip_timer); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 111 | PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n"); |
| 112 | } |
| 113 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 114 | if (wilc_enable_ps) |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 115 | wilc_set_power_mgmt(vif, 1, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 116 | |
| 117 | PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label); |
| 118 | |
Leo Kim | eac3e8f | 2015-11-05 14:36:16 +0900 | [diff] [blame] | 119 | ip_addr_buf = (char *)&dev_iface->ifa_address; |
| 120 | PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", |
| 121 | ip_addr_buf[0], ip_addr_buf[1], |
| 122 | ip_addr_buf[2], ip_addr_buf[3]); |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 123 | wilc_setup_ipaddress(vif, ip_addr_buf, vif->u8IfIdx); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 124 | |
| 125 | break; |
| 126 | |
| 127 | case NETDEV_DOWN: |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 128 | PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 129 | |
| 130 | PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n"); |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 131 | if (vif->iftype == STATION_MODE || vif->iftype == CLIENT_MODE) { |
Leo Kim | f24374a | 2015-11-05 14:36:12 +0900 | [diff] [blame] | 132 | hif_drv->IFC_UP = 0; |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 133 | wilc_optaining_ip = false; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0) |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 137 | wilc_set_power_mgmt(vif, 0, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 138 | |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 139 | wilc_resolve_disconnect_aberration(vif); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 140 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 141 | PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label); |
| 142 | |
Leo Kim | eac3e8f | 2015-11-05 14:36:16 +0900 | [diff] [blame] | 143 | ip_addr_buf = null_ip; |
| 144 | PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n", |
| 145 | ip_addr_buf[0], ip_addr_buf[1], |
| 146 | ip_addr_buf[2], ip_addr_buf[3]); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 147 | |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 148 | wilc_setup_ipaddress(vif, ip_addr_buf, vif->u8IfIdx); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 149 | |
| 150 | break; |
| 151 | |
| 152 | default: |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 153 | PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 154 | PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event); |
| 155 | |
| 156 | break; |
| 157 | } |
| 158 | |
| 159 | return NOTIFY_DONE; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 160 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 161 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 162 | static irqreturn_t isr_uh_routine(int irq, void *user_data) |
| 163 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 164 | struct wilc_vif *vif; |
Glen Lee | 3948362 | 2015-10-27 18:27:37 +0900 | [diff] [blame] | 165 | struct wilc *wilc; |
| 166 | struct net_device *dev = (struct net_device *)user_data; |
| 167 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 168 | vif = netdev_priv(dev); |
| 169 | wilc = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 170 | PRINT_D(INT_DBG, "Interrupt received UH\n"); |
| 171 | |
Glen Lee | 3948362 | 2015-10-27 18:27:37 +0900 | [diff] [blame] | 172 | if (wilc->close) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 173 | PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 174 | return IRQ_HANDLED; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 175 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 176 | return IRQ_WAKE_THREAD; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 177 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 178 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 179 | static irqreturn_t isr_bh_routine(int irq, void *userdata) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 180 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 181 | struct wilc_vif *vif; |
Glen Lee | 2e7933d | 2015-10-27 18:27:38 +0900 | [diff] [blame] | 182 | struct wilc *wilc; |
| 183 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 184 | vif = netdev_priv(userdata); |
| 185 | wilc = vif->wilc; |
Glen Lee | 2e7933d | 2015-10-27 18:27:38 +0900 | [diff] [blame] | 186 | |
Glen Lee | 2e7933d | 2015-10-27 18:27:38 +0900 | [diff] [blame] | 187 | if (wilc->close) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 188 | PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 189 | return IRQ_HANDLED; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 190 | } |
| 191 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 192 | PRINT_D(INT_DBG, "Interrupt received BH\n"); |
Glen Lee | 50b929e | 2015-10-27 18:27:40 +0900 | [diff] [blame] | 193 | wilc_handle_isr(wilc); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 194 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 195 | return IRQ_HANDLED; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 196 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 197 | |
Glen Lee | 2c1d05d | 2015-10-20 17:14:03 +0900 | [diff] [blame] | 198 | static int init_irq(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 199 | { |
| 200 | int ret = 0; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 201 | struct wilc_vif *vif; |
Glen Lee | 2c1d05d | 2015-10-20 17:14:03 +0900 | [diff] [blame] | 202 | struct wilc *wl; |
| 203 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 204 | vif = netdev_priv(dev); |
| 205 | wl = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 206 | |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 207 | if ((gpio_request(wl->gpio, "WILC_INTR") == 0) && |
| 208 | (gpio_direction_input(wl->gpio) == 0)) { |
| 209 | wl->dev_irq_num = gpio_to_irq(wl->gpio); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 210 | } else { |
| 211 | ret = -1; |
| 212 | PRINT_ER("could not obtain gpio for WILC_INTR\n"); |
| 213 | } |
| 214 | |
Leo Kim | 83231b7 | 2015-11-06 11:12:22 +0900 | [diff] [blame] | 215 | if (ret != -1 && request_threaded_irq(wl->dev_irq_num, |
| 216 | isr_uh_routine, |
| 217 | isr_bh_routine, |
| 218 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, |
| 219 | "WILC_IRQ", dev) < 0) { |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 220 | PRINT_ER("Failed to request IRQ for GPIO: %d\n", wl->gpio); |
| 221 | gpio_free(wl->gpio); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 222 | ret = -1; |
| 223 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 224 | PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n", |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 225 | wl->dev_irq_num, wl->gpio); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | return ret; |
| 229 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 230 | |
Glen Lee | ec5cc75 | 2015-10-27 18:27:39 +0900 | [diff] [blame] | 231 | static void deinit_irq(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 232 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 233 | struct wilc_vif *vif; |
Glen Lee | ec5cc75 | 2015-10-27 18:27:39 +0900 | [diff] [blame] | 234 | struct wilc *wilc; |
| 235 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 236 | vif = netdev_priv(dev); |
| 237 | wilc = vif->wilc; |
Glen Lee | ec5cc75 | 2015-10-27 18:27:39 +0900 | [diff] [blame] | 238 | |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 239 | /* Deintialize IRQ */ |
| 240 | if (wilc->dev_irq_num) { |
Glen Lee | ec5cc75 | 2015-10-27 18:27:39 +0900 | [diff] [blame] | 241 | free_irq(wilc->dev_irq_num, wilc); |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 242 | gpio_free(wilc->gpio); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 243 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 244 | } |
| 245 | |
Glen Lee | d36ec22 | 2015-11-18 15:11:36 +0900 | [diff] [blame] | 246 | void wilc_dbg(u8 *buff) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 247 | { |
| 248 | PRINT_D(INIT_DBG, "%d\n", *buff); |
| 249 | } |
| 250 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 251 | int wilc_lock_timeout(struct wilc *nic, void *vp, u32 timeout) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 252 | { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 253 | /* FIXME: replace with mutex_lock or wait_for_completion */ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 254 | int error = -1; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 255 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 256 | PRINT_D(LOCK_DBG, "Locking %p\n", vp); |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 257 | if (vp) |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 258 | error = down_timeout((struct semaphore *)vp, |
| 259 | msecs_to_jiffies(timeout)); |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 260 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 261 | PRINT_ER("Failed, mutex is NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 262 | return error; |
| 263 | } |
| 264 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 265 | void wilc_mac_indicate(struct wilc *wilc, int flag) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 266 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 267 | int status; |
| 268 | |
| 269 | if (flag == WILC_MAC_INDICATE_STATUS) { |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 270 | wilc_wlan_cfg_get_val(WID_STATUS, |
| 271 | (unsigned char *)&status, 4); |
Glen Lee | 64f2b71 | 2015-10-27 18:27:43 +0900 | [diff] [blame] | 272 | if (wilc->mac_status == WILC_MAC_STATUS_INIT) { |
| 273 | wilc->mac_status = status; |
| 274 | up(&wilc->sync_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 275 | } else { |
Glen Lee | 64f2b71 | 2015-10-27 18:27:43 +0900 | [diff] [blame] | 276 | wilc->mac_status = status; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 277 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 278 | } else if (flag == WILC_MAC_INDICATE_SCAN) { |
| 279 | PRINT_D(GENERIC_DBG, "Scanning ...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 280 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 281 | } |
| 282 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 283 | static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 284 | { |
Leo Kim | 660786e | 2015-11-05 14:36:27 +0900 | [diff] [blame] | 285 | u8 *bssid, *bssid1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 286 | int i = 0; |
| 287 | |
Leo Kim | d239222 | 2015-11-05 14:36:26 +0900 | [diff] [blame] | 288 | bssid = mac_header + 10; |
Leo Kim | 660786e | 2015-11-05 14:36:27 +0900 | [diff] [blame] | 289 | bssid1 = mac_header + 4; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 290 | |
Glen Lee | 4ad81fd | 2015-10-27 18:27:57 +0900 | [diff] [blame] | 291 | for (i = 0; i < wilc->vif_num; i++) |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 292 | if (!memcmp(bssid1, wilc->vif[i]->bssid, ETH_ALEN) || |
| 293 | !memcmp(bssid, wilc->vif[i]->bssid, ETH_ALEN)) |
| 294 | return wilc->vif[i]->ndev; |
Tony Cho | 8259a53 | 2015-10-20 14:26:47 +0900 | [diff] [blame] | 295 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 296 | PRINT_INFO(INIT_DBG, "Invalide handle\n"); |
Kim, Leo | fc4b95d | 2015-07-28 17:47:37 +0900 | [diff] [blame] | 297 | for (i = 0; i < 25; i++) |
Leo Kim | 51456c2 | 2015-11-05 14:36:25 +0900 | [diff] [blame] | 298 | PRINT_D(INIT_DBG, "%02x ", mac_header[i]); |
Leo Kim | d239222 | 2015-11-05 14:36:26 +0900 | [diff] [blame] | 299 | bssid = mac_header + 18; |
Leo Kim | 660786e | 2015-11-05 14:36:27 +0900 | [diff] [blame] | 300 | bssid1 = mac_header + 12; |
Glen Lee | 4ad81fd | 2015-10-27 18:27:57 +0900 | [diff] [blame] | 301 | for (i = 0; i < wilc->vif_num; i++) |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 302 | if (!memcmp(bssid1, wilc->vif[i]->bssid, ETH_ALEN) || |
| 303 | !memcmp(bssid, wilc->vif[i]->bssid, ETH_ALEN)) |
| 304 | return wilc->vif[i]->ndev; |
Tony Cho | 8259a53 | 2015-10-20 14:26:47 +0900 | [diff] [blame] | 305 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 306 | PRINT_INFO(INIT_DBG, "\n"); |
| 307 | return NULL; |
| 308 | } |
| 309 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 310 | int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 311 | { |
| 312 | int i = 0; |
| 313 | int ret = -1; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 314 | struct wilc_vif *vif; |
Glen Lee | 472791a | 2015-10-27 18:27:44 +0900 | [diff] [blame] | 315 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 316 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 317 | vif = netdev_priv(wilc_netdev); |
| 318 | wilc = vif->wilc; |
Glen Lee | 472791a | 2015-10-27 18:27:44 +0900 | [diff] [blame] | 319 | |
| 320 | for (i = 0; i < wilc->vif_num; i++) |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 321 | if (wilc->vif[i]->ndev == wilc_netdev) { |
| 322 | memcpy(wilc->vif[i]->bssid, bssid, 6); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 323 | ret = 0; |
| 324 | break; |
| 325 | } |
Tony Cho | 8259a53 | 2015-10-20 14:26:47 +0900 | [diff] [blame] | 326 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 327 | return ret; |
| 328 | } |
| 329 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 330 | int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 331 | { |
Chaehyun Lim | 51e825f | 2015-09-15 14:06:14 +0900 | [diff] [blame] | 332 | u8 i = 0; |
| 333 | u8 null_bssid[6] = {0}; |
| 334 | u8 ret_val = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 335 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 336 | for (i = 0; i < wilc->vif_num; i++) |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 337 | if (memcmp(wilc->vif[i]->bssid, null_bssid, 6)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 338 | ret_val++; |
Tony Cho | 8259a53 | 2015-10-20 14:26:47 +0900 | [diff] [blame] | 339 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 340 | return ret_val; |
| 341 | } |
| 342 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 343 | #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS |
| 344 | |
| 345 | static int linux_wlan_txq_task(void *vp) |
| 346 | { |
| 347 | int ret, txq_count; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 348 | struct wilc_vif *vif; |
Glen Lee | 8868758 | 2015-10-27 18:27:46 +0900 | [diff] [blame] | 349 | struct wilc *wl; |
| 350 | struct net_device *dev = vp; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 351 | #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS |
| 352 | #define TX_BACKOFF_WEIGHT_INCR_STEP (1) |
| 353 | #define TX_BACKOFF_WEIGHT_DECR_STEP (1) |
| 354 | #define TX_BACKOFF_WEIGHT_MAX (7) |
| 355 | #define TX_BACKOFF_WEIGHT_MIN (0) |
| 356 | #define TX_BACKOFF_WEIGHT_UNIT_MS (10) |
| 357 | int backoff_weight = TX_BACKOFF_WEIGHT_MIN; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 358 | #endif |
| 359 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 360 | vif = netdev_priv(dev); |
| 361 | wl = vif->wilc; |
Glen Lee | 8868758 | 2015-10-27 18:27:46 +0900 | [diff] [blame] | 362 | |
Glen Lee | 8868758 | 2015-10-27 18:27:46 +0900 | [diff] [blame] | 363 | up(&wl->txq_thread_started); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 364 | while (1) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 365 | PRINT_D(TX_DBG, "txq_task Taking a nap :)\n"); |
Glen Lee | 8868758 | 2015-10-27 18:27:46 +0900 | [diff] [blame] | 366 | down(&wl->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 367 | PRINT_D(TX_DBG, "txq_task Who waked me up :$\n"); |
| 368 | |
Glen Lee | 8868758 | 2015-10-27 18:27:46 +0900 | [diff] [blame] | 369 | if (wl->close) { |
Glen Lee | 8868758 | 2015-10-27 18:27:46 +0900 | [diff] [blame] | 370 | up(&wl->txq_thread_started); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 371 | |
| 372 | while (!kthread_should_stop()) |
| 373 | schedule(); |
| 374 | |
| 375 | PRINT_D(TX_DBG, "TX thread stopped\n"); |
| 376 | break; |
| 377 | } |
| 378 | PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n"); |
| 379 | #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS |
Glen Lee | a1332ca | 2015-10-27 18:27:47 +0900 | [diff] [blame] | 380 | ret = wilc_wlan_handle_txq(dev, &txq_count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 381 | #else |
| 382 | do { |
Glen Lee | a1332ca | 2015-10-27 18:27:47 +0900 | [diff] [blame] | 383 | ret = wilc_wlan_handle_txq(dev, &txq_count); |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 384 | if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 385 | PRINT_D(TX_DBG, "Waking up queue\n"); |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 386 | |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 387 | if (netif_queue_stopped(wl->vif[0]->ndev)) |
| 388 | netif_wake_queue(wl->vif[0]->ndev); |
| 389 | if (netif_queue_stopped(wl->vif[1]->ndev)) |
| 390 | netif_wake_queue(wl->vif[1]->ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 391 | } |
| 392 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 393 | if (ret == WILC_TX_ERR_NO_BUF) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 394 | do { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 395 | msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight); |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 396 | } while (0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 397 | backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP; |
Kim, Leo | fc4b95d | 2015-07-28 17:47:37 +0900 | [diff] [blame] | 398 | if (backoff_weight > TX_BACKOFF_WEIGHT_MAX) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 399 | backoff_weight = TX_BACKOFF_WEIGHT_MAX; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 400 | } else { |
| 401 | if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) { |
| 402 | backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP; |
Kim, Leo | fc4b95d | 2015-07-28 17:47:37 +0900 | [diff] [blame] | 403 | if (backoff_weight < TX_BACKOFF_WEIGHT_MIN) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 404 | backoff_weight = TX_BACKOFF_WEIGHT_MIN; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 405 | } |
| 406 | } |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 407 | } while (ret == WILC_TX_ERR_NO_BUF && !wl->close); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 408 | #endif |
| 409 | } |
| 410 | return 0; |
| 411 | } |
| 412 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 413 | void wilc_rx_complete(struct wilc *nic) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 414 | { |
| 415 | PRINT_D(RX_DBG, "RX completed\n"); |
| 416 | } |
| 417 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 418 | int wilc_wlan_get_firmware(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 419 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 420 | struct wilc_vif *vif; |
Glen Lee | 65c8adc | 2015-10-29 12:18:49 +0900 | [diff] [blame] | 421 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 422 | int ret = 0; |
| 423 | const struct firmware *wilc_firmware; |
| 424 | char *firmware; |
| 425 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 426 | vif = netdev_priv(dev); |
| 427 | wilc = vif->wilc; |
Glen Lee | 65c8adc | 2015-10-29 12:18:49 +0900 | [diff] [blame] | 428 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 429 | if (vif->iftype == AP_MODE) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 430 | firmware = AP_FIRMWARE; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 431 | } else if (vif->iftype == STATION_MODE) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 432 | firmware = STA_FIRMWARE; |
Leo Kim | 1b7a93a | 2015-11-05 14:36:29 +0900 | [diff] [blame] | 433 | } else { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 434 | PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n"); |
| 435 | firmware = P2P_CONCURRENCY_FIRMWARE; |
| 436 | } |
| 437 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 438 | if (!vif) { |
| 439 | PRINT_ER("vif is NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 440 | goto _fail_; |
| 441 | } |
| 442 | |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 443 | if (!(&vif->ndev->dev)) { |
| 444 | PRINT_ER("&vif->ndev->dev is NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 445 | goto _fail_; |
| 446 | } |
| 447 | |
Arnd Bergmann | b03314e | 2015-11-16 15:05:01 +0100 | [diff] [blame] | 448 | if (request_firmware(&wilc_firmware, firmware, wilc->dev) != 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 449 | PRINT_ER("%s - firmare not available\n", firmware); |
| 450 | ret = -1; |
| 451 | goto _fail_; |
| 452 | } |
Glen Lee | 65c8adc | 2015-10-29 12:18:49 +0900 | [diff] [blame] | 453 | wilc->firmware = wilc_firmware; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 454 | |
| 455 | _fail_: |
| 456 | |
| 457 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 458 | } |
| 459 | |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 460 | static int linux_wlan_start_firmware(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 461 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 462 | struct wilc_vif *vif; |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 463 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 464 | int ret = 0; |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 465 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 466 | vif = netdev_priv(dev); |
| 467 | wilc = vif->wilc; |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 468 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 469 | PRINT_D(INIT_DBG, "Starting Firmware ...\n"); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 470 | ret = wilc_wlan_start(wilc); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 471 | if (ret < 0) { |
| 472 | PRINT_ER("Failed to start Firmware\n"); |
Leo Kim | 0aeea1a | 2015-11-05 14:36:30 +0900 | [diff] [blame] | 473 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 474 | } |
| 475 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 476 | PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n"); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 477 | ret = wilc_lock_timeout(wilc, &wilc->sync_event, 5000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 478 | if (ret) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 479 | PRINT_D(INIT_DBG, "Firmware start timed out"); |
Leo Kim | 0aeea1a | 2015-11-05 14:36:30 +0900 | [diff] [blame] | 480 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 481 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 482 | PRINT_D(INIT_DBG, "Firmware successfully started\n"); |
| 483 | |
Leo Kim | 0aeea1a | 2015-11-05 14:36:30 +0900 | [diff] [blame] | 484 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 485 | } |
Leo Kim | a40b22c | 2015-11-05 14:36:32 +0900 | [diff] [blame] | 486 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 487 | static int wilc1000_firmware_download(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 488 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 489 | struct wilc_vif *vif; |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 490 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 491 | int ret = 0; |
| 492 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 493 | vif = netdev_priv(dev); |
| 494 | wilc = vif->wilc; |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 495 | |
| 496 | if (!wilc->firmware) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 497 | PRINT_ER("Firmware buffer is NULL\n"); |
Leo Kim | 14b1821 | 2015-11-05 14:36:31 +0900 | [diff] [blame] | 498 | return -ENOBUFS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 499 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 500 | PRINT_D(INIT_DBG, "Downloading Firmware ...\n"); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 501 | ret = wilc_wlan_firmware_download(wilc, wilc->firmware->data, |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 502 | wilc->firmware->size); |
Kim, Leo | fc4b95d | 2015-07-28 17:47:37 +0900 | [diff] [blame] | 503 | if (ret < 0) |
Leo Kim | 14b1821 | 2015-11-05 14:36:31 +0900 | [diff] [blame] | 504 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 505 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 506 | PRINT_D(INIT_DBG, "Freeing FW buffer ...\n"); |
| 507 | PRINT_D(INIT_DBG, "Releasing firmware\n"); |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 508 | release_firmware(wilc->firmware); |
Glen Lee | 6f72ed7 | 2015-11-25 11:59:40 +0900 | [diff] [blame] | 509 | wilc->firmware = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 510 | |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 511 | PRINT_D(INIT_DBG, "Download Succeeded\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 512 | |
Leo Kim | 14b1821 | 2015-11-05 14:36:31 +0900 | [diff] [blame] | 513 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 514 | } |
| 515 | |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 516 | static int linux_wlan_init_test_config(struct net_device *dev, |
| 517 | struct wilc *wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 518 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 519 | unsigned char c_val[64]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 520 | unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff}; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 521 | |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 522 | struct wilc_priv *priv; |
Leo Kim | 0fa66c7 | 2015-11-05 14:36:13 +0900 | [diff] [blame] | 523 | struct host_if_drv *hif_drv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 524 | |
| 525 | PRINT_D(TX_DBG, "Start configuring Firmware\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 526 | get_random_bytes(&mac_add[5], 1); |
| 527 | get_random_bytes(&mac_add[4], 1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 528 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); |
Leo Kim | 0fa66c7 | 2015-11-05 14:36:13 +0900 | [diff] [blame] | 529 | hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; |
| 530 | PRINT_D(INIT_DBG, "Host = %p\n", hif_drv); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 531 | |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 532 | PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", |
| 533 | mac_add[0], mac_add[1], mac_add[2], |
| 534 | mac_add[3], mac_add[4], mac_add[5]); |
Glen Lee | 00215dd | 2015-11-18 15:11:25 +0900 | [diff] [blame] | 535 | wilc_get_chipid(wilc, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 536 | |
Johnny Kim | e5d57e9 | 2015-08-20 16:32:53 +0900 | [diff] [blame] | 537 | *(int *)c_val = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 538 | |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 539 | if (!wilc_wlan_cfg_set(wilc, 1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 540 | goto _fail_; |
| 541 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 542 | c_val[0] = 0; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 543 | if (!wilc_wlan_cfg_set(wilc, 0, WID_PC_TEST_MODE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 544 | goto _fail_; |
| 545 | |
| 546 | c_val[0] = INFRASTRUCTURE; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 547 | if (!wilc_wlan_cfg_set(wilc, 0, WID_BSS_TYPE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 548 | goto _fail_; |
| 549 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 550 | c_val[0] = RATE_AUTO; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 551 | if (!wilc_wlan_cfg_set(wilc, 0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 552 | goto _fail_; |
| 553 | |
| 554 | c_val[0] = G_MIXED_11B_2_MODE; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 555 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11G_OPERATING_MODE, c_val, 1, 0, |
| 556 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 557 | goto _fail_; |
| 558 | |
| 559 | c_val[0] = 1; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 560 | if (!wilc_wlan_cfg_set(wilc, 0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 561 | goto _fail_; |
| 562 | |
| 563 | c_val[0] = G_SHORT_PREAMBLE; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 564 | if (!wilc_wlan_cfg_set(wilc, 0, WID_PREAMBLE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 565 | goto _fail_; |
| 566 | |
| 567 | c_val[0] = AUTO_PROT; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 568 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_PROT_MECH, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 569 | goto _fail_; |
| 570 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 571 | c_val[0] = ACTIVE_SCAN; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 572 | if (!wilc_wlan_cfg_set(wilc, 0, WID_SCAN_TYPE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 573 | goto _fail_; |
| 574 | |
| 575 | c_val[0] = SITE_SURVEY_OFF; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 576 | if (!wilc_wlan_cfg_set(wilc, 0, WID_SITE_SURVEY, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 577 | goto _fail_; |
| 578 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 579 | *((int *)c_val) = 0xffff; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 580 | if (!wilc_wlan_cfg_set(wilc, 0, WID_RTS_THRESHOLD, c_val, 2, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 581 | goto _fail_; |
| 582 | |
| 583 | *((int *)c_val) = 2346; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 584 | if (!wilc_wlan_cfg_set(wilc, 0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 585 | goto _fail_; |
| 586 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 587 | c_val[0] = 0; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 588 | if (!wilc_wlan_cfg_set(wilc, 0, WID_BCAST_SSID, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 589 | goto _fail_; |
| 590 | |
| 591 | c_val[0] = 1; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 592 | if (!wilc_wlan_cfg_set(wilc, 0, WID_QOS_ENABLE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 593 | goto _fail_; |
| 594 | |
| 595 | c_val[0] = NO_POWERSAVE; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 596 | if (!wilc_wlan_cfg_set(wilc, 0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 597 | goto _fail_; |
| 598 | |
Arnd Bergmann | b4d04c1 | 2015-11-16 15:04:56 +0100 | [diff] [blame] | 599 | c_val[0] = NO_SECURITY; /* NO_ENCRYPT, 0x79 */ |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 600 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11I_MODE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 601 | goto _fail_; |
| 602 | |
| 603 | c_val[0] = OPEN_SYSTEM; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 604 | if (!wilc_wlan_cfg_set(wilc, 0, WID_AUTH_TYPE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 605 | goto _fail_; |
| 606 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 607 | strcpy(c_val, "123456790abcdef1234567890"); |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 608 | if (!wilc_wlan_cfg_set(wilc, 0, WID_WEP_KEY_VALUE, c_val, |
| 609 | (strlen(c_val) + 1), 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 610 | goto _fail_; |
| 611 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 612 | strcpy(c_val, "12345678"); |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 613 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11I_PSK, c_val, (strlen(c_val)), 0, |
| 614 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 615 | goto _fail_; |
| 616 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 617 | strcpy(c_val, "password"); |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 618 | if (!wilc_wlan_cfg_set(wilc, 0, WID_1X_KEY, c_val, (strlen(c_val) + 1), |
| 619 | 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 620 | goto _fail_; |
| 621 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 622 | c_val[0] = 192; |
| 623 | c_val[1] = 168; |
| 624 | c_val[2] = 1; |
| 625 | c_val[3] = 112; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 626 | if (!wilc_wlan_cfg_set(wilc, 0, WID_1X_SERV_ADDR, c_val, 4, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 627 | goto _fail_; |
| 628 | |
| 629 | c_val[0] = 3; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 630 | if (!wilc_wlan_cfg_set(wilc, 0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 631 | goto _fail_; |
| 632 | |
| 633 | c_val[0] = 3; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 634 | if (!wilc_wlan_cfg_set(wilc, 0, WID_DTIM_PERIOD, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 635 | goto _fail_; |
| 636 | |
| 637 | c_val[0] = NORMAL_ACK; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 638 | if (!wilc_wlan_cfg_set(wilc, 0, WID_ACK_POLICY, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 639 | goto _fail_; |
| 640 | |
| 641 | c_val[0] = 0; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 642 | if (!wilc_wlan_cfg_set(wilc, 0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, |
| 643 | 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 644 | goto _fail_; |
| 645 | |
| 646 | c_val[0] = 48; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 647 | if (!wilc_wlan_cfg_set(wilc, 0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, |
| 648 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 649 | goto _fail_; |
| 650 | |
| 651 | c_val[0] = 28; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 652 | if (!wilc_wlan_cfg_set(wilc, 0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, |
| 653 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 654 | goto _fail_; |
| 655 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 656 | *((int *)c_val) = 100; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 657 | if (!wilc_wlan_cfg_set(wilc, 0, WID_BEACON_INTERVAL, c_val, 2, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 658 | goto _fail_; |
| 659 | |
| 660 | c_val[0] = REKEY_DISABLE; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 661 | if (!wilc_wlan_cfg_set(wilc, 0, WID_REKEY_POLICY, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 662 | goto _fail_; |
| 663 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 664 | *((int *)c_val) = 84600; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 665 | if (!wilc_wlan_cfg_set(wilc, 0, WID_REKEY_PERIOD, c_val, 4, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 666 | goto _fail_; |
| 667 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 668 | *((int *)c_val) = 500; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 669 | if (!wilc_wlan_cfg_set(wilc, 0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, |
| 670 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 671 | goto _fail_; |
| 672 | |
| 673 | c_val[0] = 1; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 674 | if (!wilc_wlan_cfg_set(wilc, 0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, |
| 675 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 676 | goto _fail_; |
| 677 | |
| 678 | c_val[0] = G_SELF_CTS_PROT; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 679 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 680 | goto _fail_; |
| 681 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 682 | c_val[0] = 1; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 683 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_ENABLE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 684 | goto _fail_; |
| 685 | |
| 686 | c_val[0] = HT_MIXED_MODE; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 687 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_OPERATING_MODE, c_val, 1, 0, |
| 688 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 689 | goto _fail_; |
| 690 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 691 | c_val[0] = 1; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 692 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, |
| 693 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 694 | goto _fail_; |
| 695 | |
| 696 | memcpy(c_val, mac_add, 6); |
| 697 | |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 698 | if (!wilc_wlan_cfg_set(wilc, 0, WID_MAC_ADDR, c_val, 6, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 699 | goto _fail_; |
| 700 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 701 | c_val[0] = DETECT_PROTECT_REPORT; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 702 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, |
| 703 | 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 704 | goto _fail_; |
| 705 | |
| 706 | c_val[0] = RTS_CTS_NONHT_PROT; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 707 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 708 | goto _fail_; |
| 709 | |
| 710 | c_val[0] = 0; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 711 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, |
| 712 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 713 | goto _fail_; |
| 714 | |
| 715 | c_val[0] = MIMO_MODE; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 716 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_SMPS_MODE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 717 | goto _fail_; |
| 718 | |
| 719 | c_val[0] = 7; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 720 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, |
| 721 | 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 722 | goto _fail_; |
| 723 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 724 | c_val[0] = 1; |
Glen Lee | 89758e1 | 2015-11-18 15:11:34 +0900 | [diff] [blame] | 725 | if (!wilc_wlan_cfg_set(wilc, 0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, |
| 726 | 1, 1)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 727 | goto _fail_; |
| 728 | |
| 729 | return 0; |
| 730 | |
| 731 | _fail_: |
| 732 | return -1; |
| 733 | } |
| 734 | |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 735 | void wilc1000_wlan_deinit(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 736 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 737 | struct wilc_vif *vif; |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 738 | struct wilc *wl; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 739 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 740 | vif = netdev_priv(dev); |
| 741 | wl = vif->wilc; |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 742 | |
| 743 | if (!wl) { |
| 744 | netdev_err(dev, "wl is NULL\n"); |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | if (wl->initialized) { |
| 749 | netdev_info(dev, "Deinitializing wilc1000...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 750 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 751 | PRINT_D(INIT_DBG, "Disabling IRQ\n"); |
Arnd Bergmann | 5547c1f | 2015-11-16 15:05:06 +0100 | [diff] [blame] | 752 | if (!wl->dev_irq_num && |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 753 | wl->hif_func->disable_interrupt) { |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 754 | mutex_lock(&wl->hif_cs); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 755 | wl->hif_func->disable_interrupt(wl); |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 756 | mutex_unlock(&wl->hif_cs); |
| 757 | } |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 758 | if (&wl->txq_event) |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 759 | up(&wl->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 760 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 761 | PRINT_D(INIT_DBG, "Deinitializing Threads\n"); |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 762 | wlan_deinitialize_threads(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 763 | |
| 764 | PRINT_D(INIT_DBG, "Deinitializing IRQ\n"); |
Glen Lee | ec5cc75 | 2015-10-27 18:27:39 +0900 | [diff] [blame] | 765 | deinit_irq(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 766 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 767 | wilc_wlan_stop(wl); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 768 | |
| 769 | PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n"); |
Glen Lee | 2de7cbe | 2015-10-27 18:27:54 +0900 | [diff] [blame] | 770 | wilc_wlan_cleanup(dev); |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 771 | #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) |
Arnd Bergmann | 5547c1f | 2015-11-16 15:05:06 +0100 | [diff] [blame] | 772 | if (!wl->dev_irq_num && |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 773 | wl->hif_func->disable_interrupt) { |
Arnd Bergmann | 5547c1f | 2015-11-16 15:05:06 +0100 | [diff] [blame] | 774 | |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 775 | PRINT_D(INIT_DBG, "Disabling IRQ 2\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 776 | |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 777 | mutex_lock(&wl->hif_cs); |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 778 | wl->hif_func->disable_interrupt(wl); |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 779 | mutex_unlock(&wl->hif_cs); |
| 780 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 781 | #endif |
| 782 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 783 | PRINT_D(INIT_DBG, "Deinitializing Locks\n"); |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 784 | wlan_deinit_locks(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 785 | |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 786 | wl->initialized = false; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 787 | |
| 788 | PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n"); |
| 789 | |
| 790 | } else { |
| 791 | PRINT_D(INIT_DBG, "wilc1000 is not initialized\n"); |
| 792 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 793 | } |
| 794 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 795 | static int wlan_init_locks(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 796 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 797 | struct wilc_vif *vif; |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 798 | struct wilc *wl; |
| 799 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 800 | vif = netdev_priv(dev); |
| 801 | wl = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 802 | |
| 803 | PRINT_D(INIT_DBG, "Initializing Locks ...\n"); |
| 804 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 805 | mutex_init(&wl->hif_cs); |
| 806 | mutex_init(&wl->rxq_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 807 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 808 | spin_lock_init(&wl->txq_spinlock); |
| 809 | sema_init(&wl->txq_add_to_head_cs, 1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 810 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 811 | sema_init(&wl->txq_event, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 812 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 813 | sema_init(&wl->cfg_event, 0); |
| 814 | sema_init(&wl->sync_event, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 815 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 816 | sema_init(&wl->txq_thread_started, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 817 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 818 | return 0; |
| 819 | } |
| 820 | |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 821 | static int wlan_deinit_locks(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 822 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 823 | struct wilc_vif *vif; |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 824 | struct wilc *wilc; |
| 825 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 826 | vif = netdev_priv(dev); |
| 827 | wilc = vif->wilc; |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 828 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 829 | PRINT_D(INIT_DBG, "De-Initializing Locks\n"); |
| 830 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 831 | if (&wilc->hif_cs) |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 832 | mutex_destroy(&wilc->hif_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 833 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 834 | if (&wilc->rxq_cs) |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 835 | mutex_destroy(&wilc->rxq_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 836 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 837 | return 0; |
| 838 | } |
Leo Kim | a40b22c | 2015-11-05 14:36:32 +0900 | [diff] [blame] | 839 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 840 | static int wlan_initialize_threads(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 841 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 842 | struct wilc_vif *vif; |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 843 | struct wilc *wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 844 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 845 | vif = netdev_priv(dev); |
| 846 | wilc = vif->wilc; |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 847 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 848 | PRINT_D(INIT_DBG, "Initializing Threads ...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 849 | PRINT_D(INIT_DBG, "Creating kthread for transmission\n"); |
Glen Lee | 8868758 | 2015-10-27 18:27:46 +0900 | [diff] [blame] | 850 | wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev, |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 851 | "K_TXQ_TASK"); |
| 852 | if (!wilc->txq_thread) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 853 | PRINT_ER("couldn't create TXQ thread\n"); |
Leo Kim | 6bc72c5 | 2015-11-05 14:36:33 +0900 | [diff] [blame] | 854 | wilc->close = 0; |
| 855 | return -ENOBUFS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 856 | } |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 857 | down(&wilc->txq_thread_started); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 858 | |
| 859 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 860 | } |
| 861 | |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 862 | static void wlan_deinitialize_threads(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 863 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 864 | struct wilc_vif *vif; |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 865 | struct wilc *wl; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 866 | vif = netdev_priv(dev); |
| 867 | wl = vif->wilc; |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 868 | |
| 869 | wl->close = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 870 | PRINT_D(INIT_DBG, "Deinitializing Threads\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 871 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 872 | if (&wl->txq_event) |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 873 | up(&wl->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 874 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 875 | if (wl->txq_thread) { |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 876 | kthread_stop(wl->txq_thread); |
| 877 | wl->txq_thread = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 878 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 879 | } |
| 880 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 881 | int wilc1000_wlan_init(struct net_device *dev, struct wilc_vif *vif) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 882 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 883 | int ret = 0; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 884 | struct wilc *wl = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 885 | |
Glen Lee | 0fa683b | 2015-10-20 17:13:52 +0900 | [diff] [blame] | 886 | if (!wl->initialized) { |
| 887 | wl->mac_status = WILC_MAC_STATUS_INIT; |
| 888 | wl->close = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 889 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 890 | wlan_init_locks(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 891 | |
Arnd Bergmann | 4bd7baf | 2015-11-16 15:04:59 +0100 | [diff] [blame] | 892 | ret = wilc_wlan_init(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 893 | if (ret < 0) { |
| 894 | PRINT_ER("Initializing WILC_Wlan FAILED\n"); |
| 895 | ret = -EIO; |
| 896 | goto _fail_locks_; |
| 897 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 898 | |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 899 | if (wl->gpio >= 0 && init_irq(dev)) { |
Tony Cho | b46d688 | 2015-10-20 14:26:54 +0900 | [diff] [blame] | 900 | PRINT_ER("couldn't initialize IRQ\n"); |
| 901 | ret = -EIO; |
| 902 | goto _fail_locks_; |
| 903 | } |
Tony Cho | b46d688 | 2015-10-20 14:26:54 +0900 | [diff] [blame] | 904 | |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 905 | ret = wlan_initialize_threads(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 906 | if (ret < 0) { |
| 907 | PRINT_ER("Initializing Threads FAILED\n"); |
| 908 | ret = -EIO; |
| 909 | goto _fail_wilc_wlan_; |
| 910 | } |
| 911 | |
Arnd Bergmann | 5547c1f | 2015-11-16 15:05:06 +0100 | [diff] [blame] | 912 | if (!wl->dev_irq_num && |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 913 | wl->hif_func->enable_interrupt && |
| 914 | wl->hif_func->enable_interrupt(wl)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 915 | PRINT_ER("couldn't initialize IRQ\n"); |
| 916 | ret = -EIO; |
| 917 | goto _fail_irq_init_; |
| 918 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 919 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 920 | if (wilc_wlan_get_firmware(dev)) { |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 921 | PRINT_ER("Can't get firmware\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 922 | ret = -EIO; |
| 923 | goto _fail_irq_enable_; |
| 924 | } |
| 925 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 926 | ret = wilc1000_firmware_download(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 927 | if (ret < 0) { |
| 928 | PRINT_ER("Failed to download firmware\n"); |
| 929 | ret = -EIO; |
| 930 | goto _fail_irq_enable_; |
| 931 | } |
| 932 | |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 933 | ret = linux_wlan_start_firmware(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 934 | if (ret < 0) { |
| 935 | PRINT_ER("Failed to start firmware\n"); |
| 936 | ret = -EIO; |
| 937 | goto _fail_irq_enable_; |
| 938 | } |
| 939 | |
Glen Lee | d40c99c | 2015-11-18 15:11:35 +0900 | [diff] [blame] | 940 | if (wilc_wlan_cfg_get(wl, 1, WID_FIRMWARE_VERSION, 1, 0)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 941 | int size; |
| 942 | char Firmware_ver[20]; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 943 | |
Glen Lee | 894de36b | 2015-10-01 16:03:42 +0900 | [diff] [blame] | 944 | size = wilc_wlan_cfg_get_val( |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 945 | WID_FIRMWARE_VERSION, |
| 946 | Firmware_ver, sizeof(Firmware_ver)); |
| 947 | Firmware_ver[size] = '\0'; |
| 948 | PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver); |
| 949 | } |
Glen Lee | 0fa683b | 2015-10-20 17:13:52 +0900 | [diff] [blame] | 950 | ret = linux_wlan_init_test_config(dev, wl); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 951 | |
| 952 | if (ret < 0) { |
| 953 | PRINT_ER("Failed to configure firmware\n"); |
| 954 | ret = -EIO; |
| 955 | goto _fail_fw_start_; |
| 956 | } |
| 957 | |
Glen Lee | 0fa683b | 2015-10-20 17:13:52 +0900 | [diff] [blame] | 958 | wl->initialized = true; |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 959 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 960 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 961 | _fail_fw_start_: |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 962 | wilc_wlan_stop(wl); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 963 | |
| 964 | _fail_irq_enable_: |
Arnd Bergmann | 5547c1f | 2015-11-16 15:05:06 +0100 | [diff] [blame] | 965 | if (!wl->dev_irq_num && |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 966 | wl->hif_func->disable_interrupt) |
| 967 | wl->hif_func->disable_interrupt(wl); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 968 | _fail_irq_init_: |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 969 | if (wl->dev_irq_num) |
| 970 | deinit_irq(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 971 | |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 972 | wlan_deinitialize_threads(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 973 | _fail_wilc_wlan_: |
Glen Lee | 2de7cbe | 2015-10-27 18:27:54 +0900 | [diff] [blame] | 974 | wilc_wlan_cleanup(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 975 | _fail_locks_: |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 976 | wlan_deinit_locks(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 977 | PRINT_ER("WLAN Iinitialization FAILED\n"); |
| 978 | } else { |
| 979 | PRINT_D(INIT_DBG, "wilc1000 already initialized\n"); |
| 980 | } |
| 981 | return ret; |
| 982 | } |
| 983 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 984 | static int mac_init_fn(struct net_device *ndev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 985 | { |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 986 | netif_start_queue(ndev); |
| 987 | netif_stop_queue(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 988 | |
| 989 | return 0; |
| 990 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 991 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 992 | int wilc_mac_open(struct net_device *ndev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 993 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 994 | struct wilc_vif *vif; |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 995 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 996 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 997 | unsigned char mac_add[ETH_ALEN] = {0}; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 998 | int ret = 0; |
| 999 | int i = 0; |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 1000 | struct wilc_priv *priv; |
Glen Lee | f3c1366 | 2015-10-20 17:13:54 +0900 | [diff] [blame] | 1001 | struct wilc *wl; |
| 1002 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1003 | vif = netdev_priv(ndev); |
| 1004 | wl = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1005 | |
Arnd Bergmann | b03314e | 2015-11-16 15:05:01 +0100 | [diff] [blame] | 1006 | if (!wl|| !wl->dev) { |
Chandra S Gorentla | 7d05652 | 2015-09-15 18:09:51 +0530 | [diff] [blame] | 1007 | netdev_err(ndev, "wilc1000: SPI device not ready\n"); |
| 1008 | return -ENODEV; |
| 1009 | } |
Arnd Bergmann | b03314e | 2015-11-16 15:05:01 +0100 | [diff] [blame] | 1010 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1011 | vif = netdev_priv(ndev); |
| 1012 | wilc = vif->wilc; |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1013 | priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1014 | PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev); |
| 1015 | |
Chaehyun Lim | dd4b6a8 | 2015-09-20 15:51:25 +0900 | [diff] [blame] | 1016 | ret = wilc_init_host_int(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1017 | if (ret < 0) { |
| 1018 | PRINT_ER("Failed to initialize host interface\n"); |
| 1019 | |
| 1020 | return ret; |
| 1021 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1022 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1023 | PRINT_D(INIT_DBG, "*** re-init ***\n"); |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1024 | ret = wilc1000_wlan_init(ndev, vif); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1025 | if (ret < 0) { |
| 1026 | PRINT_ER("Failed to initialize wilc1000\n"); |
Chaehyun Lim | a9a1682 | 2015-09-20 15:51:24 +0900 | [diff] [blame] | 1027 | wilc_deinit_host_int(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1028 | return ret; |
| 1029 | } |
| 1030 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1031 | wilc_set_machw_change_vir_if(ndev, false); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1032 | |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 1033 | wilc_get_mac_address(vif, mac_add); |
Alexander Kuleshov | 310a28f | 2015-09-04 00:48:14 +0600 | [diff] [blame] | 1034 | PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1035 | |
Glen Lee | f3c1366 | 2015-10-20 17:13:54 +0900 | [diff] [blame] | 1036 | for (i = 0; i < wl->vif_num; i++) { |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1037 | if (ndev == wl->vif[i]->ndev) { |
| 1038 | memcpy(wl->vif[i]->src_addr, mac_add, ETH_ALEN); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1039 | break; |
| 1040 | } |
| 1041 | } |
| 1042 | |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1043 | memcpy(ndev->dev_addr, wl->vif[i]->src_addr, ETH_ALEN); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1044 | |
| 1045 | if (!is_valid_ether_addr(ndev->dev_addr)) { |
| 1046 | PRINT_ER("Error: Wrong MAC address\n"); |
Leo Kim | 339d244 | 2015-11-05 14:36:34 +0900 | [diff] [blame] | 1047 | wilc_deinit_host_int(ndev); |
| 1048 | wilc1000_wlan_deinit(ndev); |
| 1049 | return -EINVAL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1050 | } |
| 1051 | |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1052 | wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy, |
| 1053 | vif->ndev->ieee80211_ptr, |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1054 | vif->g_struct_frame_reg[0].frame_type, |
| 1055 | vif->g_struct_frame_reg[0].reg); |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1056 | wilc_mgmt_frame_register(vif->ndev->ieee80211_ptr->wiphy, |
| 1057 | vif->ndev->ieee80211_ptr, |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1058 | vif->g_struct_frame_reg[1].frame_type, |
| 1059 | vif->g_struct_frame_reg[1].reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1060 | netif_wake_queue(ndev); |
Glen Lee | f3c1366 | 2015-10-20 17:13:54 +0900 | [diff] [blame] | 1061 | wl->open_ifcs++; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1062 | vif->mac_opened = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1063 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1064 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1065 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 1066 | static struct net_device_stats *mac_stats(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1067 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1068 | struct wilc_vif *vif= netdev_priv(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1069 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1070 | return &vif->netstats; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1071 | } |
| 1072 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1073 | static void wilc_set_multicast_list(struct net_device *dev) |
| 1074 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1075 | struct netdev_hw_addr *ha; |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 1076 | struct wilc_priv *priv; |
Leo Kim | ef7606c | 2015-11-05 14:36:14 +0900 | [diff] [blame] | 1077 | struct host_if_drv *hif_drv; |
Glen Lee | cf60106 | 2015-12-21 14:18:39 +0900 | [diff] [blame] | 1078 | struct wilc_vif *vif; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1079 | int i = 0; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1080 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1081 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); |
Glen Lee | cf60106 | 2015-12-21 14:18:39 +0900 | [diff] [blame] | 1082 | vif = netdev_priv(dev); |
Leo Kim | ef7606c | 2015-11-05 14:36:14 +0900 | [diff] [blame] | 1083 | hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1084 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1085 | if (!dev) |
| 1086 | return; |
| 1087 | |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1088 | PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", |
| 1089 | dev->mc.count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1090 | |
| 1091 | if (dev->flags & IFF_PROMISC) { |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 1092 | PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1093 | return; |
| 1094 | } |
| 1095 | |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1096 | if ((dev->flags & IFF_ALLMULTI) || |
| 1097 | (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1098 | PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n"); |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 1099 | wilc_setup_multicast_filter(vif, false, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1100 | return; |
| 1101 | } |
| 1102 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1103 | if ((dev->mc.count) == 0) { |
| 1104 | PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n"); |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 1105 | wilc_setup_multicast_filter(vif, true, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1106 | return; |
| 1107 | } |
| 1108 | |
Leo Kim | c8537e6 | 2015-11-06 11:12:24 +0900 | [diff] [blame] | 1109 | netdev_for_each_mc_addr(ha, dev) { |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1110 | memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1111 | PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i, |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1112 | wilc_multicast_mac_addr_list[i][0], |
| 1113 | wilc_multicast_mac_addr_list[i][1], |
| 1114 | wilc_multicast_mac_addr_list[i][2], |
| 1115 | wilc_multicast_mac_addr_list[i][3], |
| 1116 | wilc_multicast_mac_addr_list[i][4], |
| 1117 | wilc_multicast_mac_addr_list[i][5]); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1118 | i++; |
| 1119 | } |
| 1120 | |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 1121 | wilc_setup_multicast_filter(vif, true, (dev->mc.count)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1122 | |
| 1123 | return; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1124 | } |
| 1125 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1126 | static void linux_wlan_tx_complete(void *priv, int status) |
| 1127 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1128 | struct tx_complete_data *pv_data = (struct tx_complete_data *)priv; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1129 | |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1130 | if (status == 1) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1131 | PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1132 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1133 | PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1134 | dev_kfree_skb(pv_data->skb); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1135 | kfree(pv_data); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1136 | } |
| 1137 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1138 | int wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1139 | { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1140 | struct wilc_vif *vif; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1141 | struct tx_complete_data *tx_data = NULL; |
Leo Kim | 44ec3b7 | 2015-11-05 14:36:38 +0900 | [diff] [blame] | 1142 | int queue_count; |
Leo Kim | fd8f036 | 2015-11-05 14:36:39 +0900 | [diff] [blame] | 1143 | char *udp_buf; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1144 | struct iphdr *ih; |
| 1145 | struct ethhdr *eth_h; |
Glen Lee | b7495be | 2015-10-27 18:28:01 +0900 | [diff] [blame] | 1146 | struct wilc *wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1147 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1148 | vif = netdev_priv(ndev); |
| 1149 | wilc = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1150 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1151 | PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n"); |
| 1152 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1153 | if (skb->dev != ndev) { |
| 1154 | PRINT_ER("Packet not destined to this device\n"); |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
Leo Kim | b38e903 | 2015-11-06 11:12:23 +0900 | [diff] [blame] | 1158 | tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC); |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1159 | if (!tx_data) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1160 | PRINT_ER("Failed to allocate memory for tx_data structure\n"); |
| 1161 | dev_kfree_skb(skb); |
| 1162 | netif_wake_queue(ndev); |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | tx_data->buff = skb->data; |
| 1167 | tx_data->size = skb->len; |
| 1168 | tx_data->skb = skb; |
| 1169 | |
| 1170 | eth_h = (struct ethhdr *)(skb->data); |
Kim, Leo | fc4b95d | 2015-07-28 17:47:37 +0900 | [diff] [blame] | 1171 | if (eth_h->h_proto == 0x8e88) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1172 | PRINT_D(INIT_DBG, "EAPOL transmitted\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1173 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1174 | ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); |
| 1175 | |
Leo Kim | fd8f036 | 2015-11-05 14:36:39 +0900 | [diff] [blame] | 1176 | udp_buf = (char *)ih + sizeof(struct iphdr); |
| 1177 | if ((udp_buf[1] == 68 && udp_buf[3] == 67) || |
| 1178 | (udp_buf[1] == 67 && udp_buf[3] == 68)) |
| 1179 | PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", |
| 1180 | udp_buf[248], udp_buf[249], udp_buf[250]); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1181 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1182 | PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1183 | PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n"); |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1184 | vif->netstats.tx_packets++; |
| 1185 | vif->netstats.tx_bytes += tx_data->size; |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1186 | tx_data->pBssid = wilc->vif[vif->u8IfIdx]->bssid; |
Leo Kim | 44ec3b7 | 2015-11-05 14:36:38 +0900 | [diff] [blame] | 1187 | queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data, |
| 1188 | tx_data->buff, tx_data->size, |
| 1189 | linux_wlan_tx_complete); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1190 | |
Leo Kim | 44ec3b7 | 2015-11-05 14:36:38 +0900 | [diff] [blame] | 1191 | if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) { |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1192 | netif_stop_queue(wilc->vif[0]->ndev); |
| 1193 | netif_stop_queue(wilc->vif[1]->ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1199 | int wilc_mac_close(struct net_device *ndev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1200 | { |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 1201 | struct wilc_priv *priv; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1202 | struct wilc_vif *vif; |
Leo Kim | 2db2c8a | 2015-11-05 14:36:15 +0900 | [diff] [blame] | 1203 | struct host_if_drv *hif_drv; |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1204 | struct wilc *wl; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1205 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1206 | vif = netdev_priv(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1207 | |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1208 | if (!vif || !vif->ndev || !vif->ndev->ieee80211_ptr || |
| 1209 | !vif->ndev->ieee80211_ptr->wiphy) { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1210 | PRINT_ER("vif = NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1211 | return 0; |
| 1212 | } |
| 1213 | |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1214 | priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy); |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1215 | wl = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1216 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1217 | if (!priv) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1218 | PRINT_ER("priv = NULL\n"); |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
Leo Kim | 2db2c8a | 2015-11-05 14:36:15 +0900 | [diff] [blame] | 1222 | hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1223 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1224 | PRINT_D(GENERIC_DBG, "Mac close\n"); |
| 1225 | |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1226 | if (!wl) { |
| 1227 | PRINT_ER("wl = NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1228 | return 0; |
| 1229 | } |
| 1230 | |
Leo Kim | 2db2c8a | 2015-11-05 14:36:15 +0900 | [diff] [blame] | 1231 | if (!hif_drv) { |
| 1232 | PRINT_ER("hif_drv = NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1233 | return 0; |
| 1234 | } |
| 1235 | |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1236 | if ((wl->open_ifcs) > 0) { |
| 1237 | wl->open_ifcs--; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1238 | } else { |
| 1239 | PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n"); |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1243 | if (vif->ndev) { |
| 1244 | netif_stop_queue(vif->ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1245 | |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1246 | wilc_deinit_host_int(vif->ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1247 | } |
| 1248 | |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1249 | if (wl->open_ifcs == 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1250 | PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n"); |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1251 | wl->close = 1; |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 1252 | wilc1000_wlan_deinit(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1253 | WILC_WFI_deinit_mon_interface(); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1254 | } |
| 1255 | |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 1256 | up(&close_exit_sync); |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1257 | vif->mac_opened = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1258 | |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 1262 | static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1263 | { |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 1264 | u8 *buff = NULL; |
Chaehyun Lim | ca356ad | 2015-06-11 14:35:57 +0900 | [diff] [blame] | 1265 | s8 rssi; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 1266 | u32 size = 0, length = 0; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1267 | struct wilc_vif *vif; |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 1268 | struct wilc_priv *priv; |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1269 | s32 ret = 0; |
Glen Lee | 07320b6 | 2015-10-27 18:27:53 +0900 | [diff] [blame] | 1270 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1271 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1272 | vif = netdev_priv(ndev); |
| 1273 | wilc = vif->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1274 | |
Glen Lee | 07320b6 | 2015-10-27 18:27:53 +0900 | [diff] [blame] | 1275 | if (!wilc->initialized) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1276 | return 0; |
| 1277 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1278 | switch (cmd) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1279 | case SIOCSIWPRIV: |
| 1280 | { |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 1281 | struct iwreq *wrq = (struct iwreq *) req; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1282 | |
| 1283 | size = wrq->u.data.length; |
| 1284 | |
| 1285 | if (size && wrq->u.data.pointer) { |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1286 | buff = memdup_user(wrq->u.data.pointer, |
| 1287 | wrq->u.data.length); |
Sudip Mukherjee | 360e27a | 2015-09-04 15:34:15 +0530 | [diff] [blame] | 1288 | if (IS_ERR(buff)) |
| 1289 | return PTR_ERR(buff); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1290 | |
| 1291 | if (strncasecmp(buff, "RSSI", length) == 0) { |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1292 | priv = wiphy_priv(vif->ndev->ieee80211_ptr->wiphy); |
Glen Lee | fbf5379 | 2015-12-21 14:18:40 +0900 | [diff] [blame] | 1293 | ret = wilc_get_rssi(vif, &rssi); |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1294 | if (ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1295 | PRINT_ER("Failed to send get rssi param's message queue "); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1296 | PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi); |
| 1297 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1298 | rssi += 5; |
| 1299 | |
| 1300 | snprintf(buff, size, "rssi %d", rssi); |
| 1301 | |
| 1302 | if (copy_to_user(wrq->u.data.pointer, buff, size)) { |
Chaehyun Lim | 60cb1e2 | 2015-06-19 09:06:28 +0900 | [diff] [blame] | 1303 | PRINT_ER("%s: failed to copy data to user buffer\n", __func__); |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1304 | ret = -EFAULT; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1305 | goto done; |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | break; |
| 1311 | |
| 1312 | default: |
| 1313 | { |
| 1314 | PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd); |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1315 | ret = -EOPNOTSUPP; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1316 | goto done; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | done: |
| 1321 | |
Shraddha Barke | 642ac6c | 2015-08-10 13:30:33 +0530 | [diff] [blame] | 1322 | kfree(buff); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1323 | |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1324 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1325 | } |
| 1326 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1327 | void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1328 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1329 | unsigned int frame_len = 0; |
| 1330 | int stats; |
| 1331 | unsigned char *buff_to_send = NULL; |
| 1332 | struct sk_buff *skb; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1333 | struct net_device *wilc_netdev; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1334 | struct wilc_vif *vif; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1335 | |
Leo Kim | 7e725b4 | 2015-11-05 14:36:24 +0900 | [diff] [blame] | 1336 | wilc_netdev = get_if_handler(wilc, buff); |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1337 | if (!wilc_netdev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1338 | return; |
| 1339 | |
| 1340 | buff += pkt_offset; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1341 | vif = netdev_priv(wilc_netdev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1342 | |
| 1343 | if (size > 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1344 | frame_len = size; |
| 1345 | buff_to_send = buff; |
| 1346 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1347 | skb = dev_alloc_skb(frame_len); |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1348 | if (!skb) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1349 | PRINT_ER("Low memory - packet droped\n"); |
| 1350 | return; |
| 1351 | } |
| 1352 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1353 | if (!wilc || !wilc_netdev) |
Glen Lee | cb1991a | 2015-10-27 18:27:56 +0900 | [diff] [blame] | 1354 | PRINT_ER("wilc_netdev in wilc is NULL"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1355 | skb->dev = wilc_netdev; |
| 1356 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1357 | if (!skb->dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1358 | PRINT_ER("skb->dev is NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1359 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1360 | memcpy(skb_put(skb, frame_len), buff_to_send, frame_len); |
| 1361 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1362 | skb->protocol = eth_type_trans(skb, wilc_netdev); |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1363 | vif->netstats.rx_packets++; |
| 1364 | vif->netstats.rx_bytes += frame_len; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1365 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1366 | stats = netif_rx(skb); |
| 1367 | PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats); |
| 1368 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1369 | } |
| 1370 | |
Glen Lee | 11f4b2e | 2015-10-27 18:27:51 +0900 | [diff] [blame] | 1371 | void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1372 | { |
| 1373 | int i = 0; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1374 | struct wilc_vif *vif; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1375 | |
Glen Lee | 11f4b2e | 2015-10-27 18:27:51 +0900 | [diff] [blame] | 1376 | for (i = 0; i < wilc->vif_num; i++) { |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1377 | vif = netdev_priv(wilc->vif[i]->ndev); |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1378 | if (vif->monitor_flag) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1379 | WILC_WFI_monitor_rx(buff, size); |
| 1380 | return; |
| 1381 | } |
| 1382 | } |
| 1383 | |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1384 | vif = netdev_priv(wilc->vif[1]->ndev); |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1385 | if ((buff[0] == vif->g_struct_frame_reg[0].frame_type && vif->g_struct_frame_reg[0].reg) || |
| 1386 | (buff[0] == vif->g_struct_frame_reg[1].frame_type && vif->g_struct_frame_reg[1].reg)) |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1387 | WILC_WFI_p2p_rx(wilc->vif[1]->ndev, buff, size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1388 | } |
| 1389 | |
Arnd Bergmann | 857c7b0 | 2015-11-16 15:05:00 +0100 | [diff] [blame] | 1390 | void wilc_netdev_cleanup(struct wilc *wilc) |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1391 | { |
| 1392 | int i = 0; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1393 | struct wilc_vif *vif[NUM_CONCURRENT_IFC]; |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1394 | |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1395 | if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) { |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1396 | unregister_inetaddr_notifier(&g_dev_notifier); |
| 1397 | |
| 1398 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1399 | vif[i] = netdev_priv(wilc->vif[i]->ndev); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1400 | } |
| 1401 | |
Glen Lee | 90b984c | 2015-10-29 12:18:50 +0900 | [diff] [blame] | 1402 | if (wilc && wilc->firmware) |
| 1403 | release_firmware(wilc->firmware); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1404 | |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1405 | if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) { |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1406 | wilc_lock_timeout(wilc, &close_exit_sync, 12 * 1000); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1407 | |
| 1408 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1409 | if (wilc->vif[i]->ndev) |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1410 | if (vif[i]->mac_opened) |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1411 | wilc_mac_close(wilc->vif[i]->ndev); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1412 | |
| 1413 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1414 | unregister_netdev(wilc->vif[i]->ndev); |
| 1415 | wilc_free_wiphy(wilc->vif[i]->ndev); |
| 1416 | free_netdev(wilc->vif[i]->ndev); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | |
Glen Lee | 90b984c | 2015-10-29 12:18:50 +0900 | [diff] [blame] | 1420 | kfree(wilc); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1421 | } |
Arnd Bergmann | 750ffe9 | 2015-11-16 15:05:08 +0100 | [diff] [blame] | 1422 | EXPORT_SYMBOL_GPL(wilc_netdev_cleanup); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1423 | |
Arnd Bergmann | 7d37a4a | 2015-11-16 15:05:05 +0100 | [diff] [blame] | 1424 | int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type, |
| 1425 | int gpio, const struct wilc_hif_func *ops) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1426 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1427 | int i; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1428 | struct wilc_vif *vif; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1429 | struct net_device *ndev; |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1430 | struct wilc *wl; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1431 | |
Greg Kroah-Hartman | 642768e | 2015-09-03 19:56:21 -0700 | [diff] [blame] | 1432 | sema_init(&close_exit_sync, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1433 | |
Glen Lee | 825b966 | 2015-11-18 15:11:37 +0900 | [diff] [blame] | 1434 | wl = kzalloc(sizeof(*wl), GFP_KERNEL); |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1435 | if (!wl) |
Chaehyun Lim | ac61ef8 | 2015-09-08 00:36:36 +0900 | [diff] [blame] | 1436 | return -ENOMEM; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1437 | |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1438 | *wilc = wl; |
| 1439 | wl->io_type = io_type; |
| 1440 | wl->gpio = gpio; |
Glen Lee | af9ae09 | 2015-12-21 14:18:09 +0900 | [diff] [blame] | 1441 | wl->hif_func = ops; |
Arnd Bergmann | c4d139c | 2015-11-16 15:05:04 +0100 | [diff] [blame] | 1442 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1443 | register_inetaddr_notifier(&g_dev_notifier); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1444 | |
| 1445 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1446 | ndev = alloc_etherdev(sizeof(struct wilc_vif)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1447 | if (!ndev) { |
| 1448 | PRINT_ER("Failed to allocate ethernet dev\n"); |
| 1449 | return -1; |
| 1450 | } |
| 1451 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1452 | vif = netdev_priv(ndev); |
| 1453 | memset(vif, 0, sizeof(struct wilc_vif)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1454 | |
Leo Kim | 84d3b87 | 2015-11-05 14:36:19 +0900 | [diff] [blame] | 1455 | if (i == 0) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1456 | strcpy(ndev->name, "wlan%d"); |
Leo Kim | 84d3b87 | 2015-11-05 14:36:19 +0900 | [diff] [blame] | 1457 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1458 | strcpy(ndev->name, "p2p%d"); |
| 1459 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1460 | vif->u8IfIdx = wl->vif_num; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1461 | vif->wilc = *wilc; |
Glen Lee | 1f435d2 | 2015-12-21 14:18:37 +0900 | [diff] [blame] | 1462 | wl->vif[i] = vif; |
| 1463 | wl->vif[wl->vif_num]->ndev = ndev; |
Arnd Bergmann | 562ed3f | 2015-11-16 15:05:10 +0100 | [diff] [blame] | 1464 | wl->vif_num++; |
Arnd Bergmann | e5af056 | 2015-05-29 22:52:12 +0200 | [diff] [blame] | 1465 | ndev->netdev_ops = &wilc_netdev_ops; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1466 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1467 | { |
| 1468 | struct wireless_dev *wdev; |
Arnd Bergmann | 2e7d537 | 2015-11-16 15:05:03 +0100 | [diff] [blame] | 1469 | wdev = wilc_create_wiphy(ndev, dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1470 | |
Arnd Bergmann | 6703992 | 2015-11-16 15:05:02 +0100 | [diff] [blame] | 1471 | if (dev) |
| 1472 | SET_NETDEV_DEV(ndev, dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1473 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1474 | if (!wdev) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1475 | PRINT_ER("Can't register WILC Wiphy\n"); |
| 1476 | return -1; |
| 1477 | } |
| 1478 | |
Glen Lee | 1006b5c | 2015-12-21 14:18:38 +0900 | [diff] [blame] | 1479 | vif->ndev->ieee80211_ptr = wdev; |
| 1480 | vif->ndev->ml_priv = vif; |
| 1481 | wdev->netdev = vif->ndev; |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1482 | vif->netstats.rx_packets = 0; |
| 1483 | vif->netstats.tx_packets = 0; |
| 1484 | vif->netstats.rx_bytes = 0; |
| 1485 | vif->netstats.tx_bytes = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1486 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1487 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1488 | if (register_netdev(ndev)) { |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1489 | PRINT_ER("Device couldn't be registered - %s\n", |
| 1490 | ndev->name); |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 1491 | return -1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1492 | } |
| 1493 | |
Glen Lee | a4cac48 | 2015-12-21 14:18:36 +0900 | [diff] [blame] | 1494 | vif->iftype = STATION_MODE; |
| 1495 | vif->mac_opened = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1496 | } |
| 1497 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1498 | return 0; |
| 1499 | } |
Arnd Bergmann | 750ffe9 | 2015-11-16 15:05:08 +0100 | [diff] [blame] | 1500 | EXPORT_SYMBOL_GPL(wilc_netdev_init); |
Arnd Bergmann | c94f05e | 2015-11-16 15:05:09 +0100 | [diff] [blame] | 1501 | |
| 1502 | MODULE_LICENSE("GPL"); |