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 | |
Arnd Bergmann | b03314e | 2015-11-16 15:05:01 +0100 | [diff] [blame^] | 456 | if (request_firmware(&wilc_firmware, firmware, wilc->dev) != 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 457 | PRINT_ER("%s - firmare not available\n", firmware); |
| 458 | ret = -1; |
| 459 | goto _fail_; |
| 460 | } |
Glen Lee | 65c8adc | 2015-10-29 12:18:49 +0900 | [diff] [blame] | 461 | wilc->firmware = wilc_firmware; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 462 | |
| 463 | _fail_: |
| 464 | |
| 465 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 466 | } |
| 467 | |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 468 | static int linux_wlan_start_firmware(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 469 | { |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 470 | perInterface_wlan_t *nic; |
| 471 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 472 | int ret = 0; |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 473 | |
| 474 | nic = netdev_priv(dev); |
| 475 | wilc = nic->wilc; |
| 476 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 477 | PRINT_D(INIT_DBG, "Starting Firmware ...\n"); |
Glen Lee | e42563b | 2015-10-01 16:03:33 +0900 | [diff] [blame] | 478 | ret = wilc_wlan_start(); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 479 | if (ret < 0) { |
| 480 | PRINT_ER("Failed to start Firmware\n"); |
Leo Kim | 0aeea1a | 2015-11-05 14:36:30 +0900 | [diff] [blame] | 481 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 482 | } |
| 483 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 484 | PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n"); |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 485 | ret = linux_wlan_lock_timeout(&wilc->sync_event, 5000); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 486 | if (ret) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 487 | PRINT_D(INIT_DBG, "Firmware start timed out"); |
Leo Kim | 0aeea1a | 2015-11-05 14:36:30 +0900 | [diff] [blame] | 488 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 489 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 490 | PRINT_D(INIT_DBG, "Firmware successfully started\n"); |
| 491 | |
Leo Kim | 0aeea1a | 2015-11-05 14:36:30 +0900 | [diff] [blame] | 492 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 493 | } |
Leo Kim | a40b22c | 2015-11-05 14:36:32 +0900 | [diff] [blame] | 494 | |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 495 | static int linux_wlan_firmware_download(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 496 | { |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 497 | perInterface_wlan_t *nic; |
| 498 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 499 | int ret = 0; |
| 500 | |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 501 | nic = netdev_priv(dev); |
| 502 | wilc = nic->wilc; |
| 503 | |
| 504 | if (!wilc->firmware) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 505 | PRINT_ER("Firmware buffer is NULL\n"); |
Leo Kim | 14b1821 | 2015-11-05 14:36:31 +0900 | [diff] [blame] | 506 | return -ENOBUFS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 507 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 508 | PRINT_D(INIT_DBG, "Downloading Firmware ...\n"); |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 509 | ret = wilc_wlan_firmware_download(wilc->firmware->data, |
| 510 | wilc->firmware->size); |
Kim, Leo | fc4b95d | 2015-07-28 17:47:37 +0900 | [diff] [blame] | 511 | if (ret < 0) |
Leo Kim | 14b1821 | 2015-11-05 14:36:31 +0900 | [diff] [blame] | 512 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 513 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 514 | PRINT_D(INIT_DBG, "Freeing FW buffer ...\n"); |
| 515 | PRINT_D(INIT_DBG, "Releasing firmware\n"); |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 516 | release_firmware(wilc->firmware); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 517 | |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 518 | PRINT_D(INIT_DBG, "Download Succeeded\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 519 | |
Leo Kim | 14b1821 | 2015-11-05 14:36:31 +0900 | [diff] [blame] | 520 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 521 | } |
| 522 | |
Tony Cho | f61c5af | 2015-10-14 20:46:30 +0900 | [diff] [blame] | 523 | 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] | 524 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 525 | unsigned char c_val[64]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 526 | unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff}; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 527 | |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 528 | struct wilc_priv *priv; |
Leo Kim | 0fa66c7 | 2015-11-05 14:36:13 +0900 | [diff] [blame] | 529 | struct host_if_drv *hif_drv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 530 | |
| 531 | PRINT_D(TX_DBG, "Start configuring Firmware\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 532 | get_random_bytes(&mac_add[5], 1); |
| 533 | get_random_bytes(&mac_add[4], 1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 534 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); |
Leo Kim | 0fa66c7 | 2015-11-05 14:36:13 +0900 | [diff] [blame] | 535 | hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; |
| 536 | PRINT_D(INIT_DBG, "Host = %p\n", hif_drv); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 537 | |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 538 | PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", |
| 539 | mac_add[0], mac_add[1], mac_add[2], |
| 540 | mac_add[3], mac_add[4], mac_add[5]); |
Madhusudhanan Ravindran | 21175ef | 2015-06-09 11:19:06 +0000 | [diff] [blame] | 541 | wilc_get_chipid(0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 542 | |
Johnny Kim | e5d57e9 | 2015-08-20 16:32:53 +0900 | [diff] [blame] | 543 | *(int *)c_val = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 544 | |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 545 | 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] | 546 | goto _fail_; |
| 547 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 548 | c_val[0] = 0; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 549 | 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] | 550 | goto _fail_; |
| 551 | |
| 552 | c_val[0] = INFRASTRUCTURE; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 553 | 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] | 554 | goto _fail_; |
| 555 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 556 | c_val[0] = RATE_AUTO; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 557 | 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] | 558 | goto _fail_; |
| 559 | |
| 560 | c_val[0] = G_MIXED_11B_2_MODE; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 561 | 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] | 562 | goto _fail_; |
| 563 | |
| 564 | c_val[0] = 1; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 565 | 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] | 566 | goto _fail_; |
| 567 | |
| 568 | c_val[0] = G_SHORT_PREAMBLE; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 569 | 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] | 570 | goto _fail_; |
| 571 | |
| 572 | c_val[0] = AUTO_PROT; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 573 | 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] | 574 | goto _fail_; |
| 575 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 576 | c_val[0] = ACTIVE_SCAN; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 577 | 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] | 578 | goto _fail_; |
| 579 | |
| 580 | c_val[0] = SITE_SURVEY_OFF; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 581 | 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] | 582 | goto _fail_; |
| 583 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 584 | *((int *)c_val) = 0xffff; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 585 | 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] | 586 | goto _fail_; |
| 587 | |
| 588 | *((int *)c_val) = 2346; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 589 | 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] | 590 | goto _fail_; |
| 591 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 592 | c_val[0] = 0; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 593 | 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] | 594 | goto _fail_; |
| 595 | |
| 596 | c_val[0] = 1; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 597 | 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] | 598 | goto _fail_; |
| 599 | |
| 600 | c_val[0] = NO_POWERSAVE; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 601 | 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] | 602 | goto _fail_; |
| 603 | |
Arnd Bergmann | b4d04c1 | 2015-11-16 15:04:56 +0100 | [diff] [blame] | 604 | c_val[0] = NO_SECURITY; /* NO_ENCRYPT, 0x79 */ |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 605 | 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] | 606 | goto _fail_; |
| 607 | |
| 608 | c_val[0] = OPEN_SYSTEM; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 609 | 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] | 610 | goto _fail_; |
| 611 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 612 | strcpy(c_val, "123456790abcdef1234567890"); |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 613 | 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] | 614 | goto _fail_; |
| 615 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 616 | strcpy(c_val, "12345678"); |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 617 | 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] | 618 | goto _fail_; |
| 619 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 620 | strcpy(c_val, "password"); |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 621 | 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] | 622 | goto _fail_; |
| 623 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 624 | c_val[0] = 192; |
| 625 | c_val[1] = 168; |
| 626 | c_val[2] = 1; |
| 627 | c_val[3] = 112; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 628 | 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] | 629 | goto _fail_; |
| 630 | |
| 631 | c_val[0] = 3; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 632 | 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] | 633 | goto _fail_; |
| 634 | |
| 635 | c_val[0] = 3; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 636 | 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] | 637 | goto _fail_; |
| 638 | |
| 639 | c_val[0] = NORMAL_ACK; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 640 | 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] | 641 | goto _fail_; |
| 642 | |
| 643 | c_val[0] = 0; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 644 | 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] | 645 | goto _fail_; |
| 646 | |
| 647 | c_val[0] = 48; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 648 | 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] | 649 | goto _fail_; |
| 650 | |
| 651 | c_val[0] = 28; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 652 | 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] | 653 | goto _fail_; |
| 654 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 655 | *((int *)c_val) = 100; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 656 | 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] | 657 | goto _fail_; |
| 658 | |
| 659 | c_val[0] = REKEY_DISABLE; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 660 | 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] | 661 | goto _fail_; |
| 662 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 663 | *((int *)c_val) = 84600; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 664 | 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] | 665 | goto _fail_; |
| 666 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 667 | *((int *)c_val) = 500; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 668 | 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] | 669 | goto _fail_; |
| 670 | |
| 671 | c_val[0] = 1; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 672 | 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] | 673 | goto _fail_; |
| 674 | |
| 675 | c_val[0] = G_SELF_CTS_PROT; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 676 | 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] | 677 | goto _fail_; |
| 678 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 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_11N_ENABLE, 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] = HT_MIXED_MODE; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 684 | 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] | 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_TXOP_PROT_DISABLE, c_val, 1, 0, 0)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 689 | goto _fail_; |
| 690 | |
| 691 | memcpy(c_val, mac_add, 6); |
| 692 | |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 693 | 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] | 694 | goto _fail_; |
| 695 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 696 | c_val[0] = DETECT_PROTECT_REPORT; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 697 | 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] | 698 | goto _fail_; |
| 699 | |
| 700 | c_val[0] = RTS_CTS_NONHT_PROT; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 701 | 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] | 702 | goto _fail_; |
| 703 | |
| 704 | c_val[0] = 0; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 705 | 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] | 706 | goto _fail_; |
| 707 | |
| 708 | c_val[0] = MIMO_MODE; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 709 | 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] | 710 | goto _fail_; |
| 711 | |
| 712 | c_val[0] = 7; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 713 | 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] | 714 | goto _fail_; |
| 715 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 716 | c_val[0] = 1; |
Glen Lee | 1028e5a | 2015-10-01 16:03:40 +0900 | [diff] [blame] | 717 | 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] | 718 | goto _fail_; |
| 719 | |
| 720 | return 0; |
| 721 | |
| 722 | _fail_: |
| 723 | return -1; |
| 724 | } |
| 725 | |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 726 | void wilc1000_wlan_deinit(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 727 | { |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 728 | perInterface_wlan_t *nic; |
| 729 | struct wilc *wl; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 730 | |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 731 | nic = netdev_priv(dev); |
| 732 | wl = nic->wilc; |
| 733 | |
| 734 | if (!wl) { |
| 735 | netdev_err(dev, "wl is NULL\n"); |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | if (wl->initialized) { |
| 740 | netdev_info(dev, "Deinitializing wilc1000...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 741 | |
| 742 | #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] | 743 | PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n"); |
| 744 | #else |
| 745 | wilc_bus_set_default_speed(); |
| 746 | #endif |
| 747 | |
| 748 | PRINT_D(INIT_DBG, "Disabling IRQ\n"); |
Glen Lee | d59177c | 2015-09-17 17:47:25 +0900 | [diff] [blame] | 749 | #ifdef WILC_SDIO |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 750 | mutex_lock(&wl->hif_cs); |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 751 | wilc_sdio_disable_interrupt(); |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 752 | mutex_unlock(&wl->hif_cs); |
Glen Lee | d59177c | 2015-09-17 17:47:25 +0900 | [diff] [blame] | 753 | #endif |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 754 | if (&wl->txq_event) |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 755 | up(&wl->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 756 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 757 | PRINT_D(INIT_DBG, "Deinitializing Threads\n"); |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 758 | wlan_deinitialize_threads(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 759 | |
| 760 | PRINT_D(INIT_DBG, "Deinitializing IRQ\n"); |
Glen Lee | ec5cc75 | 2015-10-27 18:27:39 +0900 | [diff] [blame] | 761 | deinit_irq(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 762 | |
Glen Lee | 8cec741 | 2015-10-01 16:03:34 +0900 | [diff] [blame] | 763 | wilc_wlan_stop(); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 764 | |
| 765 | PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n"); |
Glen Lee | 2de7cbe | 2015-10-27 18:27:54 +0900 | [diff] [blame] | 766 | wilc_wlan_cleanup(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 767 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) |
| 768 | #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31) |
| 769 | PRINT_D(INIT_DBG, "Disabling IRQ 2\n"); |
| 770 | |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 771 | mutex_lock(&wl->hif_cs); |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 772 | wilc_sdio_disable_interrupt(); |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 773 | mutex_unlock(&wl->hif_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 774 | #endif |
| 775 | #endif |
| 776 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 777 | PRINT_D(INIT_DBG, "Deinitializing Locks\n"); |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 778 | wlan_deinit_locks(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 779 | |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 780 | wl->initialized = false; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 781 | |
| 782 | PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n"); |
| 783 | |
| 784 | } else { |
| 785 | PRINT_D(INIT_DBG, "wilc1000 is not initialized\n"); |
| 786 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 787 | } |
| 788 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 789 | static int wlan_init_locks(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 790 | { |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 791 | perInterface_wlan_t *nic; |
| 792 | struct wilc *wl; |
| 793 | |
| 794 | nic = netdev_priv(dev); |
| 795 | wl = nic->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 796 | |
| 797 | PRINT_D(INIT_DBG, "Initializing Locks ...\n"); |
| 798 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 799 | mutex_init(&wl->hif_cs); |
| 800 | mutex_init(&wl->rxq_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 801 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 802 | spin_lock_init(&wl->txq_spinlock); |
| 803 | sema_init(&wl->txq_add_to_head_cs, 1); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 804 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 805 | sema_init(&wl->txq_event, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 806 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 807 | sema_init(&wl->cfg_event, 0); |
| 808 | sema_init(&wl->sync_event, 0); |
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 | sema_init(&wl->txq_thread_started, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 811 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 812 | return 0; |
| 813 | } |
| 814 | |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 815 | static int wlan_deinit_locks(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 816 | { |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 817 | perInterface_wlan_t *nic; |
| 818 | struct wilc *wilc; |
| 819 | |
| 820 | nic = netdev_priv(dev); |
| 821 | wilc = nic->wilc; |
| 822 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 823 | PRINT_D(INIT_DBG, "De-Initializing Locks\n"); |
| 824 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 825 | if (&wilc->hif_cs) |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 826 | mutex_destroy(&wilc->hif_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 827 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 828 | if (&wilc->rxq_cs) |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 829 | mutex_destroy(&wilc->rxq_cs); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 830 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 831 | return 0; |
| 832 | } |
Leo Kim | a40b22c | 2015-11-05 14:36:32 +0900 | [diff] [blame] | 833 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 834 | static int wlan_initialize_threads(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 835 | { |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 836 | perInterface_wlan_t *nic; |
| 837 | struct wilc *wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 838 | |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 839 | nic = netdev_priv(dev); |
| 840 | wilc = nic->wilc; |
| 841 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 842 | PRINT_D(INIT_DBG, "Initializing Threads ...\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 843 | PRINT_D(INIT_DBG, "Creating kthread for transmission\n"); |
Glen Lee | 8868758 | 2015-10-27 18:27:46 +0900 | [diff] [blame] | 844 | wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev, |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 845 | "K_TXQ_TASK"); |
| 846 | if (!wilc->txq_thread) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 847 | PRINT_ER("couldn't create TXQ thread\n"); |
Leo Kim | 6bc72c5 | 2015-11-05 14:36:33 +0900 | [diff] [blame] | 848 | wilc->close = 0; |
| 849 | return -ENOBUFS; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 850 | } |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 851 | down(&wilc->txq_thread_started); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 852 | |
| 853 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 854 | } |
| 855 | |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 856 | static void wlan_deinitialize_threads(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 857 | { |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 858 | perInterface_wlan_t *nic; |
| 859 | struct wilc *wl; |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 860 | nic = netdev_priv(dev); |
| 861 | wl = nic->wilc; |
| 862 | |
| 863 | wl->close = 1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 864 | PRINT_D(INIT_DBG, "Deinitializing Threads\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 865 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 866 | if (&wl->txq_event) |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 867 | up(&wl->txq_event); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 868 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 869 | if (wl->txq_thread) { |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 870 | kthread_stop(wl->txq_thread); |
| 871 | wl->txq_thread = NULL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 872 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 873 | } |
| 874 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 875 | int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic) |
| 876 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 877 | perInterface_wlan_t *nic = p_nic; |
| 878 | int ret = 0; |
Glen Lee | 0fa683b | 2015-10-20 17:13:52 +0900 | [diff] [blame] | 879 | struct wilc *wl = nic->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 880 | |
Glen Lee | 0fa683b | 2015-10-20 17:13:52 +0900 | [diff] [blame] | 881 | if (!wl->initialized) { |
| 882 | wl->mac_status = WILC_MAC_STATUS_INIT; |
| 883 | wl->close = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 884 | |
Glen Lee | 38afb39 | 2015-10-20 17:13:53 +0900 | [diff] [blame] | 885 | wlan_init_locks(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 886 | |
Arnd Bergmann | 4bd7baf | 2015-11-16 15:04:59 +0100 | [diff] [blame] | 887 | #ifdef WILC_SDIO |
| 888 | wl->io_type = HIF_SDIO; |
| 889 | #else |
| 890 | wl->io_type = HIF_SPI; |
| 891 | #endif |
| 892 | ret = wilc_wlan_init(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 893 | if (ret < 0) { |
| 894 | PRINT_ER("Initializing WILC_Wlan FAILED\n"); |
| 895 | ret = -EIO; |
| 896 | goto _fail_locks_; |
| 897 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 898 | |
Tony Cho | b46d688 | 2015-10-20 14:26:54 +0900 | [diff] [blame] | 899 | #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) |
Glen Lee | 2c1d05d | 2015-10-20 17:14:03 +0900 | [diff] [blame] | 900 | if (init_irq(dev)) { |
Tony Cho | b46d688 | 2015-10-20 14:26:54 +0900 | [diff] [blame] | 901 | PRINT_ER("couldn't initialize IRQ\n"); |
| 902 | ret = -EIO; |
| 903 | goto _fail_locks_; |
| 904 | } |
| 905 | #endif |
| 906 | |
Glen Lee | 75a9466 | 2015-10-27 18:27:45 +0900 | [diff] [blame] | 907 | ret = wlan_initialize_threads(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 908 | if (ret < 0) { |
| 909 | PRINT_ER("Initializing Threads FAILED\n"); |
| 910 | ret = -EIO; |
| 911 | goto _fail_wilc_wlan_; |
| 912 | } |
| 913 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 914 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 915 | if (wilc_sdio_enable_interrupt()) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 916 | PRINT_ER("couldn't initialize IRQ\n"); |
| 917 | ret = -EIO; |
| 918 | goto _fail_irq_init_; |
| 919 | } |
| 920 | #endif |
| 921 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 922 | if (wilc_wlan_get_firmware(dev)) { |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 923 | PRINT_ER("Can't get firmware\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 924 | ret = -EIO; |
| 925 | goto _fail_irq_enable_; |
| 926 | } |
| 927 | |
Glen Lee | ed760b6 | 2015-10-29 12:18:42 +0900 | [diff] [blame] | 928 | ret = linux_wlan_firmware_download(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 929 | if (ret < 0) { |
| 930 | PRINT_ER("Failed to download firmware\n"); |
| 931 | ret = -EIO; |
| 932 | goto _fail_irq_enable_; |
| 933 | } |
| 934 | |
Glen Lee | 9bf3d72 | 2015-10-29 12:18:46 +0900 | [diff] [blame] | 935 | ret = linux_wlan_start_firmware(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 936 | if (ret < 0) { |
| 937 | PRINT_ER("Failed to start firmware\n"); |
| 938 | ret = -EIO; |
| 939 | goto _fail_irq_enable_; |
| 940 | } |
| 941 | |
| 942 | wilc_bus_set_max_speed(); |
| 943 | |
Glen Lee | 07056a8 | 2015-10-01 16:03:41 +0900 | [diff] [blame] | 944 | if (wilc_wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 945 | int size; |
| 946 | char Firmware_ver[20]; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 947 | |
Glen Lee | 894de36b | 2015-10-01 16:03:42 +0900 | [diff] [blame] | 948 | size = wilc_wlan_cfg_get_val( |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 949 | WID_FIRMWARE_VERSION, |
| 950 | Firmware_ver, sizeof(Firmware_ver)); |
| 951 | Firmware_ver[size] = '\0'; |
| 952 | PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver); |
| 953 | } |
Glen Lee | 0fa683b | 2015-10-20 17:13:52 +0900 | [diff] [blame] | 954 | ret = linux_wlan_init_test_config(dev, wl); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 955 | |
| 956 | if (ret < 0) { |
| 957 | PRINT_ER("Failed to configure firmware\n"); |
| 958 | ret = -EIO; |
| 959 | goto _fail_fw_start_; |
| 960 | } |
| 961 | |
Glen Lee | 0fa683b | 2015-10-20 17:13:52 +0900 | [diff] [blame] | 962 | wl->initialized = true; |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 963 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 964 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 965 | _fail_fw_start_: |
Glen Lee | 8cec741 | 2015-10-01 16:03:34 +0900 | [diff] [blame] | 966 | wilc_wlan_stop(); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 967 | |
| 968 | _fail_irq_enable_: |
| 969 | #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO) |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 970 | wilc_sdio_disable_interrupt(); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 971 | _fail_irq_init_: |
Arnd Bergmann | 7a8fd84 | 2015-06-01 21:06:45 +0200 | [diff] [blame] | 972 | #endif |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 973 | #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO) |
Glen Lee | ec5cc75 | 2015-10-27 18:27:39 +0900 | [diff] [blame] | 974 | deinit_irq(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 975 | |
| 976 | #endif |
Glen Lee | 32dd51b | 2015-10-27 18:27:52 +0900 | [diff] [blame] | 977 | wlan_deinitialize_threads(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 978 | _fail_wilc_wlan_: |
Glen Lee | 2de7cbe | 2015-10-27 18:27:54 +0900 | [diff] [blame] | 979 | wilc_wlan_cleanup(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 980 | _fail_locks_: |
Glen Lee | 7c67c05 | 2015-10-27 18:27:50 +0900 | [diff] [blame] | 981 | wlan_deinit_locks(dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 982 | PRINT_ER("WLAN Iinitialization FAILED\n"); |
| 983 | } else { |
| 984 | PRINT_D(INIT_DBG, "wilc1000 already initialized\n"); |
| 985 | } |
| 986 | return ret; |
| 987 | } |
| 988 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 989 | static int mac_init_fn(struct net_device *ndev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 990 | { |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 991 | netif_start_queue(ndev); |
| 992 | netif_stop_queue(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 993 | |
| 994 | return 0; |
| 995 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 996 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 997 | int wilc_mac_open(struct net_device *ndev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 998 | { |
| 999 | perInterface_wlan_t *nic; |
| 1000 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1001 | unsigned char mac_add[ETH_ALEN] = {0}; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1002 | int ret = 0; |
| 1003 | int i = 0; |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 1004 | struct wilc_priv *priv; |
Glen Lee | f3c1366 | 2015-10-20 17:13:54 +0900 | [diff] [blame] | 1005 | struct wilc *wl; |
| 1006 | |
| 1007 | nic = netdev_priv(ndev); |
| 1008 | wl = nic->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1009 | |
Arnd Bergmann | b03314e | 2015-11-16 15:05:01 +0100 | [diff] [blame^] | 1010 | if (!wl|| !wl->dev) { |
Chandra S Gorentla | 7d05652 | 2015-09-15 18:09:51 +0530 | [diff] [blame] | 1011 | netdev_err(ndev, "wilc1000: SPI device not ready\n"); |
| 1012 | return -ENODEV; |
| 1013 | } |
Arnd Bergmann | b03314e | 2015-11-16 15:05:01 +0100 | [diff] [blame^] | 1014 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1015 | nic = netdev_priv(ndev); |
| 1016 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); |
| 1017 | PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev); |
| 1018 | |
Chaehyun Lim | dd4b6a8 | 2015-09-20 15:51:25 +0900 | [diff] [blame] | 1019 | ret = wilc_init_host_int(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1020 | if (ret < 0) { |
| 1021 | PRINT_ER("Failed to initialize host interface\n"); |
| 1022 | |
| 1023 | return ret; |
| 1024 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1025 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1026 | PRINT_D(INIT_DBG, "*** re-init ***\n"); |
| 1027 | ret = wilc1000_wlan_init(ndev, nic); |
| 1028 | if (ret < 0) { |
| 1029 | PRINT_ER("Failed to initialize wilc1000\n"); |
Chaehyun Lim | a9a1682 | 2015-09-20 15:51:24 +0900 | [diff] [blame] | 1030 | wilc_deinit_host_int(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1031 | return ret; |
| 1032 | } |
| 1033 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1034 | wilc_set_machw_change_vir_if(ndev, false); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1035 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1036 | wilc_get_mac_address(priv->hWILCWFIDrv, mac_add); |
Alexander Kuleshov | 310a28f | 2015-09-04 00:48:14 +0600 | [diff] [blame] | 1037 | PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1038 | |
Glen Lee | f3c1366 | 2015-10-20 17:13:54 +0900 | [diff] [blame] | 1039 | for (i = 0; i < wl->vif_num; i++) { |
| 1040 | if (ndev == wl->vif[i].ndev) { |
| 1041 | memcpy(wl->vif[i].src_addr, mac_add, ETH_ALEN); |
| 1042 | wl->vif[i].hif_drv = priv->hWILCWFIDrv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1043 | break; |
| 1044 | } |
| 1045 | } |
| 1046 | |
Glen Lee | f3c1366 | 2015-10-20 17:13:54 +0900 | [diff] [blame] | 1047 | memcpy(ndev->dev_addr, wl->vif[i].src_addr, ETH_ALEN); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1048 | |
| 1049 | if (!is_valid_ether_addr(ndev->dev_addr)) { |
| 1050 | PRINT_ER("Error: Wrong MAC address\n"); |
Leo Kim | 339d244 | 2015-11-05 14:36:34 +0900 | [diff] [blame] | 1051 | wilc_deinit_host_int(ndev); |
| 1052 | wilc1000_wlan_deinit(ndev); |
| 1053 | return -EINVAL; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1054 | } |
| 1055 | |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1056 | wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, |
| 1057 | nic->wilc_netdev->ieee80211_ptr, |
| 1058 | nic->g_struct_frame_reg[0].frame_type, |
| 1059 | nic->g_struct_frame_reg[0].reg); |
| 1060 | wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, |
| 1061 | nic->wilc_netdev->ieee80211_ptr, |
| 1062 | nic->g_struct_frame_reg[1].frame_type, |
| 1063 | nic->g_struct_frame_reg[1].reg); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1064 | netif_wake_queue(ndev); |
Glen Lee | f3c1366 | 2015-10-20 17:13:54 +0900 | [diff] [blame] | 1065 | wl->open_ifcs++; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1066 | nic->mac_opened = 1; |
| 1067 | return 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1068 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1069 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 1070 | static struct net_device_stats *mac_stats(struct net_device *dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1071 | { |
| 1072 | perInterface_wlan_t *nic = netdev_priv(dev); |
| 1073 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1074 | return &nic->netstats; |
| 1075 | } |
| 1076 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1077 | static void wilc_set_multicast_list(struct net_device *dev) |
| 1078 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1079 | struct netdev_hw_addr *ha; |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 1080 | struct wilc_priv *priv; |
Leo Kim | ef7606c | 2015-11-05 14:36:14 +0900 | [diff] [blame] | 1081 | struct host_if_drv *hif_drv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1082 | int i = 0; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1083 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1084 | priv = wiphy_priv(dev->ieee80211_ptr->wiphy); |
Leo Kim | ef7606c | 2015-11-05 14:36:14 +0900 | [diff] [blame] | 1085 | hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; |
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 | if (!dev) |
| 1088 | return; |
| 1089 | |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1090 | PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", |
| 1091 | dev->mc.count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1092 | |
| 1093 | if (dev->flags & IFF_PROMISC) { |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 1094 | PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1095 | return; |
| 1096 | } |
| 1097 | |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1098 | if ((dev->flags & IFF_ALLMULTI) || |
| 1099 | (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1100 | PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n"); |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1101 | wilc_setup_multicast_filter(hif_drv, false, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1102 | return; |
| 1103 | } |
| 1104 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1105 | if ((dev->mc.count) == 0) { |
| 1106 | PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n"); |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1107 | wilc_setup_multicast_filter(hif_drv, true, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1108 | return; |
| 1109 | } |
| 1110 | |
Leo Kim | c8537e6 | 2015-11-06 11:12:24 +0900 | [diff] [blame] | 1111 | netdev_for_each_mc_addr(ha, dev) { |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1112 | memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1113 | 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] | 1114 | wilc_multicast_mac_addr_list[i][0], |
| 1115 | wilc_multicast_mac_addr_list[i][1], |
| 1116 | wilc_multicast_mac_addr_list[i][2], |
| 1117 | wilc_multicast_mac_addr_list[i][3], |
| 1118 | wilc_multicast_mac_addr_list[i][4], |
| 1119 | wilc_multicast_mac_addr_list[i][5]); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1120 | i++; |
| 1121 | } |
| 1122 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1123 | wilc_setup_multicast_filter(hif_drv, true, (dev->mc.count)); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1124 | |
| 1125 | return; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1126 | } |
| 1127 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1128 | static void linux_wlan_tx_complete(void *priv, int status) |
| 1129 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1130 | struct tx_complete_data *pv_data = (struct tx_complete_data *)priv; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1131 | |
Chandra S Gorentla | 78174ad | 2015-08-08 17:41:36 +0530 | [diff] [blame] | 1132 | if (status == 1) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1133 | 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] | 1134 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1135 | 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] | 1136 | dev_kfree_skb(pv_data->skb); |
Greg Kroah-Hartman | a18dd63 | 2015-09-03 19:04:19 -0700 | [diff] [blame] | 1137 | kfree(pv_data); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1138 | } |
| 1139 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1140 | int wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1141 | { |
| 1142 | perInterface_wlan_t *nic; |
| 1143 | struct tx_complete_data *tx_data = NULL; |
Leo Kim | 44ec3b7 | 2015-11-05 14:36:38 +0900 | [diff] [blame] | 1144 | int queue_count; |
Leo Kim | fd8f036 | 2015-11-05 14:36:39 +0900 | [diff] [blame] | 1145 | char *udp_buf; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1146 | struct iphdr *ih; |
| 1147 | struct ethhdr *eth_h; |
Glen Lee | b7495be | 2015-10-27 18:28:01 +0900 | [diff] [blame] | 1148 | struct wilc *wilc; |
Chaehyun Lim | 8dfaafd | 2015-08-18 23:18:11 +0900 | [diff] [blame] | 1149 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1150 | nic = netdev_priv(ndev); |
Glen Lee | b7495be | 2015-10-27 18:28:01 +0900 | [diff] [blame] | 1151 | wilc = nic->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1152 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1153 | PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n"); |
| 1154 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1155 | if (skb->dev != ndev) { |
| 1156 | PRINT_ER("Packet not destined to this device\n"); |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Leo Kim | b38e903 | 2015-11-06 11:12:23 +0900 | [diff] [blame] | 1160 | tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC); |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1161 | if (!tx_data) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1162 | PRINT_ER("Failed to allocate memory for tx_data structure\n"); |
| 1163 | dev_kfree_skb(skb); |
| 1164 | netif_wake_queue(ndev); |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | tx_data->buff = skb->data; |
| 1169 | tx_data->size = skb->len; |
| 1170 | tx_data->skb = skb; |
| 1171 | |
| 1172 | eth_h = (struct ethhdr *)(skb->data); |
Kim, Leo | fc4b95d | 2015-07-28 17:47:37 +0900 | [diff] [blame] | 1173 | if (eth_h->h_proto == 0x8e88) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1174 | PRINT_D(INIT_DBG, "EAPOL transmitted\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1175 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1176 | ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); |
| 1177 | |
Leo Kim | fd8f036 | 2015-11-05 14:36:39 +0900 | [diff] [blame] | 1178 | udp_buf = (char *)ih + sizeof(struct iphdr); |
| 1179 | if ((udp_buf[1] == 68 && udp_buf[3] == 67) || |
| 1180 | (udp_buf[1] == 67 && udp_buf[3] == 68)) |
| 1181 | PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", |
| 1182 | udp_buf[248], udp_buf[249], udp_buf[250]); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1183 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1184 | 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] | 1185 | PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n"); |
| 1186 | nic->netstats.tx_packets++; |
| 1187 | nic->netstats.tx_bytes += tx_data->size; |
Glen Lee | b7495be | 2015-10-27 18:28:01 +0900 | [diff] [blame] | 1188 | tx_data->pBssid = wilc->vif[nic->u8IfIdx].bssid; |
Leo Kim | 44ec3b7 | 2015-11-05 14:36:38 +0900 | [diff] [blame] | 1189 | queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data, |
| 1190 | tx_data->buff, tx_data->size, |
| 1191 | linux_wlan_tx_complete); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1192 | |
Leo Kim | 44ec3b7 | 2015-11-05 14:36:38 +0900 | [diff] [blame] | 1193 | if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) { |
Glen Lee | b7495be | 2015-10-27 18:28:01 +0900 | [diff] [blame] | 1194 | netif_stop_queue(wilc->vif[0].ndev); |
| 1195 | netif_stop_queue(wilc->vif[1].ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1201 | int wilc_mac_close(struct net_device *ndev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1202 | { |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 1203 | struct wilc_priv *priv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1204 | perInterface_wlan_t *nic; |
Leo Kim | 2db2c8a | 2015-11-05 14:36:15 +0900 | [diff] [blame] | 1205 | struct host_if_drv *hif_drv; |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1206 | struct wilc *wl; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1207 | |
| 1208 | nic = netdev_priv(ndev); |
| 1209 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1210 | if (!nic || !nic->wilc_netdev || !nic->wilc_netdev->ieee80211_ptr || |
| 1211 | !nic->wilc_netdev->ieee80211_ptr->wiphy) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1212 | PRINT_ER("nic = NULL\n"); |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1217 | wl = nic->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1218 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1219 | if (!priv) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1220 | PRINT_ER("priv = NULL\n"); |
| 1221 | return 0; |
| 1222 | } |
| 1223 | |
Leo Kim | 2db2c8a | 2015-11-05 14:36:15 +0900 | [diff] [blame] | 1224 | hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1225 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1226 | PRINT_D(GENERIC_DBG, "Mac close\n"); |
| 1227 | |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1228 | if (!wl) { |
| 1229 | PRINT_ER("wl = NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1230 | return 0; |
| 1231 | } |
| 1232 | |
Leo Kim | 2db2c8a | 2015-11-05 14:36:15 +0900 | [diff] [blame] | 1233 | if (!hif_drv) { |
| 1234 | PRINT_ER("hif_drv = NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1235 | return 0; |
| 1236 | } |
| 1237 | |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1238 | if ((wl->open_ifcs) > 0) { |
| 1239 | wl->open_ifcs--; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1240 | } else { |
| 1241 | PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n"); |
| 1242 | return 0; |
| 1243 | } |
| 1244 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1245 | if (nic->wilc_netdev) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1246 | netif_stop_queue(nic->wilc_netdev); |
| 1247 | |
Chaehyun Lim | a9a1682 | 2015-09-20 15:51:24 +0900 | [diff] [blame] | 1248 | wilc_deinit_host_int(nic->wilc_netdev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1249 | } |
| 1250 | |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1251 | if (wl->open_ifcs == 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1252 | PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n"); |
Glen Lee | ca64ad6 | 2015-10-20 17:13:55 +0900 | [diff] [blame] | 1253 | wl->close = 1; |
Glen Lee | 53dc0cf | 2015-10-20 17:13:57 +0900 | [diff] [blame] | 1254 | wilc1000_wlan_deinit(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1255 | WILC_WFI_deinit_mon_interface(); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1256 | } |
| 1257 | |
Greg Kroah-Hartman | 8990d85 | 2015-09-03 20:07:58 -0700 | [diff] [blame] | 1258 | up(&close_exit_sync); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1259 | nic->mac_opened = 0; |
| 1260 | |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
Arnd Bergmann | 1608c40 | 2015-11-16 15:04:53 +0100 | [diff] [blame] | 1264 | 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] | 1265 | { |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 1266 | u8 *buff = NULL; |
Chaehyun Lim | ca356ad | 2015-06-11 14:35:57 +0900 | [diff] [blame] | 1267 | s8 rssi; |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 1268 | u32 size = 0, length = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1269 | perInterface_wlan_t *nic; |
Chaehyun Lim | 2726887 | 2015-09-15 14:06:13 +0900 | [diff] [blame] | 1270 | struct wilc_priv *priv; |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1271 | s32 ret = 0; |
Glen Lee | 07320b6 | 2015-10-27 18:27:53 +0900 | [diff] [blame] | 1272 | struct wilc *wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1273 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1274 | nic = netdev_priv(ndev); |
Glen Lee | 07320b6 | 2015-10-27 18:27:53 +0900 | [diff] [blame] | 1275 | wilc = nic->wilc; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1276 | |
Glen Lee | 07320b6 | 2015-10-27 18:27:53 +0900 | [diff] [blame] | 1277 | if (!wilc->initialized) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1278 | return 0; |
| 1279 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1280 | switch (cmd) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1281 | case SIOCSIWPRIV: |
| 1282 | { |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 1283 | struct iwreq *wrq = (struct iwreq *) req; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1284 | |
| 1285 | size = wrq->u.data.length; |
| 1286 | |
| 1287 | if (size && wrq->u.data.pointer) { |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1288 | buff = memdup_user(wrq->u.data.pointer, |
| 1289 | wrq->u.data.length); |
Sudip Mukherjee | 360e27a | 2015-09-04 15:34:15 +0530 | [diff] [blame] | 1290 | if (IS_ERR(buff)) |
| 1291 | return PTR_ERR(buff); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1292 | |
| 1293 | if (strncasecmp(buff, "RSSI", length) == 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1294 | priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy); |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1295 | ret = wilc_get_rssi(priv->hWILCWFIDrv, &rssi); |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1296 | if (ret) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1297 | PRINT_ER("Failed to send get rssi param's message queue "); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1298 | PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi); |
| 1299 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1300 | rssi += 5; |
| 1301 | |
| 1302 | snprintf(buff, size, "rssi %d", rssi); |
| 1303 | |
| 1304 | if (copy_to_user(wrq->u.data.pointer, buff, size)) { |
Chaehyun Lim | 60cb1e2 | 2015-06-19 09:06:28 +0900 | [diff] [blame] | 1305 | PRINT_ER("%s: failed to copy data to user buffer\n", __func__); |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1306 | ret = -EFAULT; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1307 | goto done; |
| 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | break; |
| 1313 | |
| 1314 | default: |
| 1315 | { |
| 1316 | PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd); |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1317 | ret = -EOPNOTSUPP; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1318 | goto done; |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | done: |
| 1323 | |
Shraddha Barke | 642ac6c | 2015-08-10 13:30:33 +0530 | [diff] [blame] | 1324 | kfree(buff); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1325 | |
Leo Kim | 9457b05 | 2015-11-05 14:36:37 +0900 | [diff] [blame] | 1326 | return ret; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1327 | } |
| 1328 | |
Glen Lee | cb1991a | 2015-10-27 18:27:56 +0900 | [diff] [blame] | 1329 | 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] | 1330 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1331 | unsigned int frame_len = 0; |
| 1332 | int stats; |
| 1333 | unsigned char *buff_to_send = NULL; |
| 1334 | struct sk_buff *skb; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1335 | struct net_device *wilc_netdev; |
| 1336 | perInterface_wlan_t *nic; |
| 1337 | |
Leo Kim | 7e725b4 | 2015-11-05 14:36:24 +0900 | [diff] [blame] | 1338 | wilc_netdev = get_if_handler(wilc, buff); |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1339 | if (!wilc_netdev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1340 | return; |
| 1341 | |
| 1342 | buff += pkt_offset; |
| 1343 | nic = netdev_priv(wilc_netdev); |
| 1344 | |
| 1345 | if (size > 0) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1346 | frame_len = size; |
| 1347 | buff_to_send = buff; |
| 1348 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1349 | skb = dev_alloc_skb(frame_len); |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1350 | if (!skb) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1351 | PRINT_ER("Low memory - packet droped\n"); |
| 1352 | return; |
| 1353 | } |
| 1354 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1355 | if (!wilc || !wilc_netdev) |
Glen Lee | cb1991a | 2015-10-27 18:27:56 +0900 | [diff] [blame] | 1356 | PRINT_ER("wilc_netdev in wilc is NULL"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1357 | skb->dev = wilc_netdev; |
| 1358 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1359 | if (!skb->dev) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1360 | PRINT_ER("skb->dev is NULL\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1361 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1362 | memcpy(skb_put(skb, frame_len), buff_to_send, frame_len); |
| 1363 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1364 | skb->protocol = eth_type_trans(skb, wilc_netdev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1365 | nic->netstats.rx_packets++; |
| 1366 | nic->netstats.rx_bytes += frame_len; |
| 1367 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1368 | stats = netif_rx(skb); |
| 1369 | PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats); |
| 1370 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1371 | } |
| 1372 | |
Glen Lee | 11f4b2e | 2015-10-27 18:27:51 +0900 | [diff] [blame] | 1373 | void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1374 | { |
| 1375 | int i = 0; |
| 1376 | perInterface_wlan_t *nic; |
| 1377 | |
Glen Lee | 11f4b2e | 2015-10-27 18:27:51 +0900 | [diff] [blame] | 1378 | for (i = 0; i < wilc->vif_num; i++) { |
| 1379 | nic = netdev_priv(wilc->vif[i].ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1380 | if (nic->monitor_flag) { |
| 1381 | WILC_WFI_monitor_rx(buff, size); |
| 1382 | return; |
| 1383 | } |
| 1384 | } |
| 1385 | |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 1386 | nic = netdev_priv(wilc->vif[1].ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1387 | 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] | 1388 | (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] | 1389 | WILC_WFI_p2p_rx(wilc->vif[1].ndev, buff, size); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1390 | } |
| 1391 | |
Arnd Bergmann | 857c7b0 | 2015-11-16 15:05:00 +0100 | [diff] [blame] | 1392 | void wilc_netdev_cleanup(struct wilc *wilc) |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1393 | { |
| 1394 | int i = 0; |
| 1395 | perInterface_wlan_t *nic[NUM_CONCURRENT_IFC]; |
| 1396 | |
Leo Kim | 83231b7 | 2015-11-06 11:12:22 +0900 | [diff] [blame] | 1397 | if (wilc && (wilc->vif[0].ndev || wilc->vif[1].ndev)) { |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1398 | unregister_inetaddr_notifier(&g_dev_notifier); |
| 1399 | |
| 1400 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) |
Glen Lee | 90b984c | 2015-10-29 12:18:50 +0900 | [diff] [blame] | 1401 | nic[i] = netdev_priv(wilc->vif[i].ndev); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1402 | } |
| 1403 | |
Glen Lee | 90b984c | 2015-10-29 12:18:50 +0900 | [diff] [blame] | 1404 | if (wilc && wilc->firmware) |
| 1405 | release_firmware(wilc->firmware); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1406 | |
Leo Kim | 5191d77 | 2015-11-05 14:36:22 +0900 | [diff] [blame] | 1407 | if (wilc && (wilc->vif[0].ndev || wilc->vif[1].ndev)) { |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1408 | linux_wlan_lock_timeout(&close_exit_sync, 12 * 1000); |
| 1409 | |
| 1410 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) |
Glen Lee | 90b984c | 2015-10-29 12:18:50 +0900 | [diff] [blame] | 1411 | if (wilc->vif[i].ndev) |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1412 | if (nic[i]->mac_opened) |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1413 | wilc_mac_close(wilc->vif[i].ndev); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1414 | |
| 1415 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { |
Glen Lee | 90b984c | 2015-10-29 12:18:50 +0900 | [diff] [blame] | 1416 | unregister_netdev(wilc->vif[i].ndev); |
| 1417 | wilc_free_wiphy(wilc->vif[i].ndev); |
| 1418 | free_netdev(wilc->vif[i].ndev); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | |
Glen Lee | 90b984c | 2015-10-29 12:18:50 +0900 | [diff] [blame] | 1422 | kfree(wilc); |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1423 | |
| 1424 | #if defined(WILC_DEBUGFS) |
| 1425 | wilc_debugfs_remove(); |
| 1426 | #endif |
Tony Cho | 4875c49 | 2015-10-20 14:26:52 +0900 | [diff] [blame] | 1427 | } |
| 1428 | |
Tony Cho | 12ba541 | 2015-10-20 14:26:56 +0900 | [diff] [blame] | 1429 | int wilc_netdev_init(struct wilc **wilc) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1430 | { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1431 | int i; |
| 1432 | perInterface_wlan_t *nic; |
| 1433 | struct net_device *ndev; |
| 1434 | |
Greg Kroah-Hartman | 642768e | 2015-09-03 19:56:21 -0700 | [diff] [blame] | 1435 | sema_init(&close_exit_sync, 0); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1436 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1437 | wilc_dev = kzalloc(sizeof(*wilc_dev), GFP_KERNEL); |
| 1438 | if (!wilc_dev) |
Chaehyun Lim | ac61ef8 | 2015-09-08 00:36:36 +0900 | [diff] [blame] | 1439 | return -ENOMEM; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1440 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1441 | *wilc = wilc_dev; |
Tony Cho | 12ba541 | 2015-10-20 14:26:56 +0900 | [diff] [blame] | 1442 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1443 | register_inetaddr_notifier(&g_dev_notifier); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1444 | |
| 1445 | for (i = 0; i < NUM_CONCURRENT_IFC; i++) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1446 | ndev = alloc_etherdev(sizeof(perInterface_wlan_t)); |
| 1447 | if (!ndev) { |
| 1448 | PRINT_ER("Failed to allocate ethernet dev\n"); |
| 1449 | return -1; |
| 1450 | } |
| 1451 | |
| 1452 | nic = netdev_priv(ndev); |
| 1453 | memset(nic, 0, sizeof(perInterface_wlan_t)); |
| 1454 | |
Leo Kim | 84d3b87 | 2015-11-05 14:36:19 +0900 | [diff] [blame] | 1455 | if (i == 0) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1456 | strcpy(ndev->name, "wlan%d"); |
Leo Kim | 84d3b87 | 2015-11-05 14:36:19 +0900 | [diff] [blame] | 1457 | else |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1458 | strcpy(ndev->name, "p2p%d"); |
| 1459 | |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1460 | nic->u8IfIdx = wilc_dev->vif_num; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1461 | nic->wilc_netdev = ndev; |
Glen Lee | 38b3001d | 2015-10-20 17:13:51 +0900 | [diff] [blame] | 1462 | nic->wilc = *wilc; |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1463 | wilc_dev->vif[wilc_dev->vif_num].ndev = ndev; |
| 1464 | wilc_dev->vif_num++; |
Arnd Bergmann | e5af056 | 2015-05-29 22:52:12 +0200 | [diff] [blame] | 1465 | ndev->netdev_ops = &wilc_netdev_ops; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1466 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1467 | { |
| 1468 | struct wireless_dev *wdev; |
Chaehyun Lim | 8459fd5 | 2015-09-20 15:51:09 +0900 | [diff] [blame] | 1469 | wdev = wilc_create_wiphy(ndev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1470 | |
| 1471 | #ifdef WILC_SDIO |
Arnd Bergmann | 0e1af73 | 2015-11-16 15:04:54 +0100 | [diff] [blame] | 1472 | SET_NETDEV_DEV(ndev, &wilc_sdio_func->dev); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1473 | #endif |
| 1474 | |
Leo Kim | 3a147c0 | 2015-11-05 14:36:10 +0900 | [diff] [blame] | 1475 | if (!wdev) { |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1476 | PRINT_ER("Can't register WILC Wiphy\n"); |
| 1477 | return -1; |
| 1478 | } |
| 1479 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1480 | nic->wilc_netdev->ieee80211_ptr = wdev; |
| 1481 | nic->wilc_netdev->ml_priv = nic; |
| 1482 | wdev->netdev = nic->wilc_netdev; |
| 1483 | nic->netstats.rx_packets = 0; |
| 1484 | nic->netstats.tx_packets = 0; |
| 1485 | nic->netstats.rx_bytes = 0; |
| 1486 | nic->netstats.tx_bytes = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1487 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1488 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1489 | if (register_netdev(ndev)) { |
Leo Kim | 582f8a2 | 2015-11-05 14:36:21 +0900 | [diff] [blame] | 1490 | PRINT_ER("Device couldn't be registered - %s\n", |
| 1491 | ndev->name); |
Leo Kim | 98b8984 | 2015-11-05 14:36:18 +0900 | [diff] [blame] | 1492 | return -1; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | nic->iftype = STATION_MODE; |
| 1496 | nic->mac_opened = 0; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1497 | } |
| 1498 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1499 | return 0; |
| 1500 | } |