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