root/drivers/staging/wilc1000/wilc_wlan.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. is_wilc1000
  2. acquire_bus
  3. release_bus
  4. wilc_wlan_txq_remove
  5. wilc_wlan_txq_remove_from_head
  6. wilc_wlan_txq_add_to_tail
  7. wilc_wlan_txq_add_to_head
  8. add_tcp_session
  9. update_tcp_session
  10. add_tcp_pending_ack
  11. tcp_process
  12. wilc_wlan_txq_filter_dup_tcp_ack
  13. wilc_enable_tcp_ack_filter
  14. wilc_wlan_txq_add_cfg_pkt
  15. wilc_wlan_txq_add_net_pkt
  16. wilc_wlan_txq_add_mgmt_pkt
  17. wilc_wlan_txq_get_first
  18. wilc_wlan_txq_get_next
  19. wilc_wlan_rxq_add
  20. wilc_wlan_rxq_remove
  21. chip_allow_sleep
  22. chip_wakeup
  23. host_wakeup_notify
  24. host_sleep_notify
  25. wilc_wlan_handle_txq
  26. wilc_wlan_handle_rx_buff
  27. wilc_wlan_handle_rxq
  28. wilc_unknown_isr_ext
  29. wilc_wlan_handle_isr_ext
  30. wilc_handle_isr
  31. wilc_wlan_firmware_download
  32. wilc_wlan_start
  33. wilc_wlan_stop
  34. wilc_wlan_cleanup
  35. wilc_wlan_cfg_commit
  36. wilc_wlan_cfg_set
  37. wilc_wlan_cfg_get
  38. wilc_send_config_pkt
  39. init_chip
  40. wilc_get_chipid
  41. wilc_wlan_init

   1 // SPDX-License-Identifier: GPL-2.0
   2 /*
   3  * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
   4  * All rights reserved.
   5  */
   6 
   7 #include <linux/if_ether.h>
   8 #include <linux/ip.h>
   9 #include "wilc_wfi_cfgoperations.h"
  10 #include "wilc_wlan_cfg.h"
  11 
  12 static inline bool is_wilc1000(u32 id)
  13 {
  14         return (id & 0xfffff000) == 0x100000;
  15 }
  16 
  17 static inline void acquire_bus(struct wilc *wilc, enum bus_acquire acquire)
  18 {
  19         mutex_lock(&wilc->hif_cs);
  20         if (acquire == WILC_BUS_ACQUIRE_AND_WAKEUP)
  21                 chip_wakeup(wilc);
  22 }
  23 
  24 static inline void release_bus(struct wilc *wilc, enum bus_release release)
  25 {
  26         if (release == WILC_BUS_RELEASE_ALLOW_SLEEP)
  27                 chip_allow_sleep(wilc);
  28         mutex_unlock(&wilc->hif_cs);
  29 }
  30 
  31 static void wilc_wlan_txq_remove(struct wilc *wilc, struct txq_entry_t *tqe)
  32 {
  33         list_del(&tqe->list);
  34         wilc->txq_entries -= 1;
  35 }
  36 
  37 static struct txq_entry_t *
  38 wilc_wlan_txq_remove_from_head(struct net_device *dev)
  39 {
  40         struct txq_entry_t *tqe = NULL;
  41         unsigned long flags;
  42         struct wilc_vif *vif = netdev_priv(dev);
  43         struct wilc *wilc = vif->wilc;
  44 
  45         spin_lock_irqsave(&wilc->txq_spinlock, flags);
  46 
  47         if (!list_empty(&wilc->txq_head.list)) {
  48                 tqe = list_first_entry(&wilc->txq_head.list, struct txq_entry_t,
  49                                        list);
  50                 list_del(&tqe->list);
  51                 wilc->txq_entries -= 1;
  52         }
  53         spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
  54         return tqe;
  55 }
  56 
  57 static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
  58                                       struct txq_entry_t *tqe)
  59 {
  60         unsigned long flags;
  61         struct wilc_vif *vif = netdev_priv(dev);
  62         struct wilc *wilc = vif->wilc;
  63 
  64         spin_lock_irqsave(&wilc->txq_spinlock, flags);
  65 
  66         list_add_tail(&tqe->list, &wilc->txq_head.list);
  67         wilc->txq_entries += 1;
  68 
  69         spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
  70 
  71         complete(&wilc->txq_event);
  72 }
  73 
  74 static void wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
  75                                       struct txq_entry_t *tqe)
  76 {
  77         unsigned long flags;
  78         struct wilc *wilc = vif->wilc;
  79 
  80         mutex_lock(&wilc->txq_add_to_head_cs);
  81 
  82         spin_lock_irqsave(&wilc->txq_spinlock, flags);
  83 
  84         list_add(&tqe->list, &wilc->txq_head.list);
  85         wilc->txq_entries += 1;
  86 
  87         spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
  88         mutex_unlock(&wilc->txq_add_to_head_cs);
  89         complete(&wilc->txq_event);
  90 }
  91 
  92 #define NOT_TCP_ACK                     (-1)
  93 
  94 static inline void add_tcp_session(struct wilc_vif *vif, u32 src_prt,
  95                                    u32 dst_prt, u32 seq)
  96 {
  97         struct tcp_ack_filter *f = &vif->ack_filter;
  98 
  99         if (f->tcp_session < 2 * MAX_TCP_SESSION) {
 100                 f->ack_session_info[f->tcp_session].seq_num = seq;
 101                 f->ack_session_info[f->tcp_session].bigger_ack_num = 0;
 102                 f->ack_session_info[f->tcp_session].src_port = src_prt;
 103                 f->ack_session_info[f->tcp_session].dst_port = dst_prt;
 104                 f->tcp_session++;
 105         }
 106 }
 107 
 108 static inline void update_tcp_session(struct wilc_vif *vif, u32 index, u32 ack)
 109 {
 110         struct tcp_ack_filter *f = &vif->ack_filter;
 111 
 112         if (index < 2 * MAX_TCP_SESSION &&
 113             ack > f->ack_session_info[index].bigger_ack_num)
 114                 f->ack_session_info[index].bigger_ack_num = ack;
 115 }
 116 
 117 static inline void add_tcp_pending_ack(struct wilc_vif *vif, u32 ack,
 118                                        u32 session_index,
 119                                        struct txq_entry_t *txqe)
 120 {
 121         struct tcp_ack_filter *f = &vif->ack_filter;
 122         u32 i = f->pending_base + f->pending_acks_idx;
 123 
 124         if (i < MAX_PENDING_ACKS) {
 125                 f->pending_acks[i].ack_num = ack;
 126                 f->pending_acks[i].txqe = txqe;
 127                 f->pending_acks[i].session_index = session_index;
 128                 txqe->ack_idx = i;
 129                 f->pending_acks_idx++;
 130         }
 131 }
 132 
 133 static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
 134 {
 135         void *buffer = tqe->buffer;
 136         const struct ethhdr *eth_hdr_ptr = buffer;
 137         int i;
 138         unsigned long flags;
 139         struct wilc_vif *vif = netdev_priv(dev);
 140         struct wilc *wilc = vif->wilc;
 141         struct tcp_ack_filter *f = &vif->ack_filter;
 142         const struct iphdr *ip_hdr_ptr;
 143         const struct tcphdr *tcp_hdr_ptr;
 144         u32 ihl, total_length, data_offset;
 145 
 146         spin_lock_irqsave(&wilc->txq_spinlock, flags);
 147 
 148         if (eth_hdr_ptr->h_proto != htons(ETH_P_IP))
 149                 goto out;
 150 
 151         ip_hdr_ptr = buffer + ETH_HLEN;
 152 
 153         if (ip_hdr_ptr->protocol != IPPROTO_TCP)
 154                 goto out;
 155 
 156         ihl = ip_hdr_ptr->ihl << 2;
 157         tcp_hdr_ptr = buffer + ETH_HLEN + ihl;
 158         total_length = ntohs(ip_hdr_ptr->tot_len);
 159 
 160         data_offset = tcp_hdr_ptr->doff << 2;
 161         if (total_length == (ihl + data_offset)) {
 162                 u32 seq_no, ack_no;
 163 
 164                 seq_no = ntohl(tcp_hdr_ptr->seq);
 165                 ack_no = ntohl(tcp_hdr_ptr->ack_seq);
 166                 for (i = 0; i < f->tcp_session; i++) {
 167                         u32 j = f->ack_session_info[i].seq_num;
 168 
 169                         if (i < 2 * MAX_TCP_SESSION &&
 170                             j == seq_no) {
 171                                 update_tcp_session(vif, i, ack_no);
 172                                 break;
 173                         }
 174                 }
 175                 if (i == f->tcp_session)
 176                         add_tcp_session(vif, 0, 0, seq_no);
 177 
 178                 add_tcp_pending_ack(vif, ack_no, i, tqe);
 179         }
 180 
 181 out:
 182         spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 183 }
 184 
 185 static void wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
 186 {
 187         struct wilc_vif *vif = netdev_priv(dev);
 188         struct wilc *wilc = vif->wilc;
 189         struct tcp_ack_filter *f = &vif->ack_filter;
 190         u32 i = 0;
 191         u32 dropped = 0;
 192         unsigned long flags;
 193 
 194         spin_lock_irqsave(&wilc->txq_spinlock, flags);
 195         for (i = f->pending_base;
 196              i < (f->pending_base + f->pending_acks_idx); i++) {
 197                 u32 index;
 198                 u32 bigger_ack_num;
 199 
 200                 if (i >= MAX_PENDING_ACKS)
 201                         break;
 202 
 203                 index = f->pending_acks[i].session_index;
 204 
 205                 if (index >= 2 * MAX_TCP_SESSION)
 206                         break;
 207 
 208                 bigger_ack_num = f->ack_session_info[index].bigger_ack_num;
 209 
 210                 if (f->pending_acks[i].ack_num < bigger_ack_num) {
 211                         struct txq_entry_t *tqe;
 212 
 213                         tqe = f->pending_acks[i].txqe;
 214                         if (tqe) {
 215                                 wilc_wlan_txq_remove(wilc, tqe);
 216                                 tqe->status = 1;
 217                                 if (tqe->tx_complete_func)
 218                                         tqe->tx_complete_func(tqe->priv,
 219                                                               tqe->status);
 220                                 kfree(tqe);
 221                                 dropped++;
 222                         }
 223                 }
 224         }
 225         f->pending_acks_idx = 0;
 226         f->tcp_session = 0;
 227 
 228         if (f->pending_base == 0)
 229                 f->pending_base = MAX_TCP_SESSION;
 230         else
 231                 f->pending_base = 0;
 232 
 233         spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 234 
 235         while (dropped > 0) {
 236                 wait_for_completion_timeout(&wilc->txq_event,
 237                                             msecs_to_jiffies(1));
 238                 dropped--;
 239         }
 240 }
 241 
 242 void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value)
 243 {
 244         vif->ack_filter.enabled = value;
 245 }
 246 
 247 static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
 248                                      u32 buffer_size)
 249 {
 250         struct txq_entry_t *tqe;
 251         struct wilc *wilc = vif->wilc;
 252 
 253         netdev_dbg(vif->ndev, "Adding config packet ...\n");
 254         if (wilc->quit) {
 255                 netdev_dbg(vif->ndev, "Return due to clear function\n");
 256                 complete(&wilc->cfg_event);
 257                 return 0;
 258         }
 259 
 260         tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
 261         if (!tqe)
 262                 return 0;
 263 
 264         tqe->type = WILC_CFG_PKT;
 265         tqe->buffer = buffer;
 266         tqe->buffer_size = buffer_size;
 267         tqe->tx_complete_func = NULL;
 268         tqe->priv = NULL;
 269         tqe->ack_idx = NOT_TCP_ACK;
 270         tqe->vif = vif;
 271 
 272         wilc_wlan_txq_add_to_head(vif, tqe);
 273 
 274         return 1;
 275 }
 276 
 277 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
 278                               u32 buffer_size,
 279                               void (*tx_complete_fn)(void *, int))
 280 {
 281         struct txq_entry_t *tqe;
 282         struct wilc_vif *vif = netdev_priv(dev);
 283         struct wilc *wilc;
 284 
 285         wilc = vif->wilc;
 286 
 287         if (wilc->quit)
 288                 return 0;
 289 
 290         tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
 291 
 292         if (!tqe)
 293                 return 0;
 294         tqe->type = WILC_NET_PKT;
 295         tqe->buffer = buffer;
 296         tqe->buffer_size = buffer_size;
 297         tqe->tx_complete_func = tx_complete_fn;
 298         tqe->priv = priv;
 299         tqe->vif = vif;
 300 
 301         tqe->ack_idx = NOT_TCP_ACK;
 302         if (vif->ack_filter.enabled)
 303                 tcp_process(dev, tqe);
 304         wilc_wlan_txq_add_to_tail(dev, tqe);
 305         return wilc->txq_entries;
 306 }
 307 
 308 int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
 309                                u32 buffer_size,
 310                                void (*tx_complete_fn)(void *, int))
 311 {
 312         struct txq_entry_t *tqe;
 313         struct wilc_vif *vif = netdev_priv(dev);
 314         struct wilc *wilc;
 315 
 316         wilc = vif->wilc;
 317 
 318         if (wilc->quit)
 319                 return 0;
 320 
 321         tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
 322 
 323         if (!tqe)
 324                 return 0;
 325         tqe->type = WILC_MGMT_PKT;
 326         tqe->buffer = buffer;
 327         tqe->buffer_size = buffer_size;
 328         tqe->tx_complete_func = tx_complete_fn;
 329         tqe->priv = priv;
 330         tqe->ack_idx = NOT_TCP_ACK;
 331         tqe->vif = vif;
 332         wilc_wlan_txq_add_to_tail(dev, tqe);
 333         return 1;
 334 }
 335 
 336 static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc)
 337 {
 338         struct txq_entry_t *tqe = NULL;
 339         unsigned long flags;
 340 
 341         spin_lock_irqsave(&wilc->txq_spinlock, flags);
 342 
 343         if (!list_empty(&wilc->txq_head.list))
 344                 tqe = list_first_entry(&wilc->txq_head.list, struct txq_entry_t,
 345                                        list);
 346 
 347         spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 348 
 349         return tqe;
 350 }
 351 
 352 static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
 353                                                   struct txq_entry_t *tqe)
 354 {
 355         unsigned long flags;
 356 
 357         spin_lock_irqsave(&wilc->txq_spinlock, flags);
 358 
 359         if (!list_is_last(&tqe->list, &wilc->txq_head.list))
 360                 tqe = list_next_entry(tqe, list);
 361         else
 362                 tqe = NULL;
 363         spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 364 
 365         return tqe;
 366 }
 367 
 368 static void wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
 369 {
 370         if (wilc->quit)
 371                 return;
 372 
 373         mutex_lock(&wilc->rxq_cs);
 374         list_add_tail(&rqe->list, &wilc->rxq_head.list);
 375         mutex_unlock(&wilc->rxq_cs);
 376 }
 377 
 378 static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
 379 {
 380         struct rxq_entry_t *rqe = NULL;
 381 
 382         mutex_lock(&wilc->rxq_cs);
 383         if (!list_empty(&wilc->rxq_head.list)) {
 384                 rqe = list_first_entry(&wilc->rxq_head.list, struct rxq_entry_t,
 385                                        list);
 386                 list_del(&rqe->list);
 387         }
 388         mutex_unlock(&wilc->rxq_cs);
 389         return rqe;
 390 }
 391 
 392 void chip_allow_sleep(struct wilc *wilc)
 393 {
 394         u32 reg = 0;
 395 
 396         wilc->hif_func->hif_read_reg(wilc, 0xf0, &reg);
 397 
 398         wilc->hif_func->hif_write_reg(wilc, 0xf0, reg & ~BIT(0));
 399         wilc->hif_func->hif_write_reg(wilc, 0xfa, 0);
 400 }
 401 EXPORT_SYMBOL_GPL(chip_allow_sleep);
 402 
 403 void chip_wakeup(struct wilc *wilc)
 404 {
 405         u32 reg, clk_status_reg;
 406 
 407         if ((wilc->io_type & 0x1) == WILC_HIF_SPI) {
 408                 do {
 409                         wilc->hif_func->hif_read_reg(wilc, 1, &reg);
 410                         wilc->hif_func->hif_write_reg(wilc, 1, reg | BIT(1));
 411                         wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1));
 412 
 413                         do {
 414                                 usleep_range(2000, 2500);
 415                                 wilc_get_chipid(wilc, true);
 416                         } while (wilc_get_chipid(wilc, true) == 0);
 417                 } while (wilc_get_chipid(wilc, true) == 0);
 418         } else if ((wilc->io_type & 0x1) == WILC_HIF_SDIO) {
 419                 wilc->hif_func->hif_write_reg(wilc, 0xfa, 1);
 420                 usleep_range(200, 400);
 421                 wilc->hif_func->hif_read_reg(wilc, 0xf0, &reg);
 422                 do {
 423                         wilc->hif_func->hif_write_reg(wilc, 0xf0,
 424                                                       reg | BIT(0));
 425                         wilc->hif_func->hif_read_reg(wilc, 0xf1,
 426                                                      &clk_status_reg);
 427 
 428                         while ((clk_status_reg & 0x1) == 0) {
 429                                 usleep_range(2000, 2500);
 430 
 431                                 wilc->hif_func->hif_read_reg(wilc, 0xf1,
 432                                                              &clk_status_reg);
 433                         }
 434                         if ((clk_status_reg & 0x1) == 0) {
 435                                 wilc->hif_func->hif_write_reg(wilc, 0xf0,
 436                                                               reg & (~BIT(0)));
 437                         }
 438                 } while ((clk_status_reg & 0x1) == 0);
 439         }
 440 
 441         if (wilc->chip_ps_state == WILC_CHIP_SLEEPING_MANUAL) {
 442                 if (wilc_get_chipid(wilc, false) < 0x1002b0) {
 443                         u32 val32;
 444 
 445                         wilc->hif_func->hif_read_reg(wilc, 0x1e1c, &val32);
 446                         val32 |= BIT(6);
 447                         wilc->hif_func->hif_write_reg(wilc, 0x1e1c, val32);
 448 
 449                         wilc->hif_func->hif_read_reg(wilc, 0x1e9c, &val32);
 450                         val32 |= BIT(6);
 451                         wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32);
 452                 }
 453         }
 454         wilc->chip_ps_state = WILC_CHIP_WAKEDUP;
 455 }
 456 EXPORT_SYMBOL_GPL(chip_wakeup);
 457 
 458 void host_wakeup_notify(struct wilc *wilc)
 459 {
 460         acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
 461         wilc->hif_func->hif_write_reg(wilc, 0x10b0, 1);
 462         release_bus(wilc, WILC_BUS_RELEASE_ONLY);
 463 }
 464 EXPORT_SYMBOL_GPL(host_wakeup_notify);
 465 
 466 void host_sleep_notify(struct wilc *wilc)
 467 {
 468         acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
 469         wilc->hif_func->hif_write_reg(wilc, 0x10ac, 1);
 470         release_bus(wilc, WILC_BUS_RELEASE_ONLY);
 471 }
 472 EXPORT_SYMBOL_GPL(host_sleep_notify);
 473 
 474 int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
 475 {
 476         int i, entries = 0;
 477         u32 sum;
 478         u32 reg;
 479         u32 offset = 0;
 480         int vmm_sz = 0;
 481         struct txq_entry_t *tqe;
 482         int ret = 0;
 483         int counter;
 484         int timeout;
 485         u32 vmm_table[WILC_VMM_TBL_SIZE];
 486         const struct wilc_hif_func *func;
 487         u8 *txb = wilc->tx_buffer;
 488         struct net_device *dev;
 489         struct wilc_vif *vif;
 490 
 491         if (wilc->quit)
 492                 goto out;
 493 
 494         mutex_lock(&wilc->txq_add_to_head_cs);
 495         tqe = wilc_wlan_txq_get_first(wilc);
 496         if (!tqe)
 497                 goto out;
 498         dev = tqe->vif->ndev;
 499         wilc_wlan_txq_filter_dup_tcp_ack(dev);
 500         i = 0;
 501         sum = 0;
 502         do {
 503                 if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) {
 504                         if (tqe->type == WILC_CFG_PKT)
 505                                 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
 506 
 507                         else if (tqe->type == WILC_NET_PKT)
 508                                 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
 509 
 510                         else
 511                                 vmm_sz = HOST_HDR_OFFSET;
 512 
 513                         vmm_sz += tqe->buffer_size;
 514 
 515                         if (vmm_sz & 0x3)
 516                                 vmm_sz = (vmm_sz + 4) & ~0x3;
 517 
 518                         if ((sum + vmm_sz) > WILC_TX_BUFF_SIZE)
 519                                 break;
 520 
 521                         vmm_table[i] = vmm_sz / 4;
 522                         if (tqe->type == WILC_CFG_PKT)
 523                                 vmm_table[i] |= BIT(10);
 524                         cpu_to_le32s(&vmm_table[i]);
 525 
 526                         i++;
 527                         sum += vmm_sz;
 528                         tqe = wilc_wlan_txq_get_next(wilc, tqe);
 529                 } else {
 530                         break;
 531                 }
 532         } while (1);
 533 
 534         if (i == 0)
 535                 goto out;
 536         vmm_table[i] = 0x0;
 537 
 538         acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
 539         counter = 0;
 540         func = wilc->hif_func;
 541         do {
 542                 ret = func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, &reg);
 543                 if (!ret)
 544                         break;
 545 
 546                 if ((reg & 0x1) == 0)
 547                         break;
 548 
 549                 counter++;
 550                 if (counter > 200) {
 551                         counter = 0;
 552                         ret = func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, 0);
 553                         break;
 554                 }
 555         } while (!wilc->quit);
 556 
 557         if (!ret)
 558                 goto out_release_bus;
 559 
 560         timeout = 200;
 561         do {
 562                 ret = func->hif_block_tx(wilc,
 563                                          WILC_VMM_TBL_RX_SHADOW_BASE,
 564                                          (u8 *)vmm_table,
 565                                          ((i + 1) * 4));
 566                 if (!ret)
 567                         break;
 568 
 569                 ret = func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x2);
 570                 if (!ret)
 571                         break;
 572 
 573                 do {
 574                         ret = func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, &reg);
 575                         if (!ret)
 576                                 break;
 577                         if ((reg >> 2) & 0x1) {
 578                                 entries = ((reg >> 3) & 0x3f);
 579                                 break;
 580                         }
 581                 } while (--timeout);
 582                 if (timeout <= 0) {
 583                         ret = func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x0);
 584                         break;
 585                 }
 586 
 587                 if (!ret)
 588                         break;
 589 
 590                 if (entries == 0) {
 591                         ret = func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, &reg);
 592                         if (!ret)
 593                                 break;
 594                         reg &= ~BIT(0);
 595                         ret = func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg);
 596                         if (!ret)
 597                                 break;
 598                         break;
 599                 }
 600                 break;
 601         } while (1);
 602 
 603         if (!ret)
 604                 goto out_release_bus;
 605 
 606         if (entries == 0) {
 607                 ret = -ENOBUFS;
 608                 goto out_release_bus;
 609         }
 610 
 611         release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 612 
 613         offset = 0;
 614         i = 0;
 615         do {
 616                 u32 header, buffer_offset;
 617                 char *bssid;
 618 
 619                 tqe = wilc_wlan_txq_remove_from_head(dev);
 620                 if (!tqe)
 621                         break;
 622 
 623                 vif = tqe->vif;
 624                 if (vmm_table[i] == 0)
 625                         break;
 626 
 627                 le32_to_cpus(&vmm_table[i]);
 628                 vmm_sz = (vmm_table[i] & 0x3ff);
 629                 vmm_sz *= 4;
 630                 header = (tqe->type << 31) |
 631                          (tqe->buffer_size << 15) |
 632                          vmm_sz;
 633                 if (tqe->type == WILC_MGMT_PKT)
 634                         header |= BIT(30);
 635                 else
 636                         header &= ~BIT(30);
 637 
 638                 cpu_to_le32s(&header);
 639                 memcpy(&txb[offset], &header, 4);
 640                 if (tqe->type == WILC_CFG_PKT) {
 641                         buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
 642                 } else if (tqe->type == WILC_NET_PKT) {
 643                         bssid = tqe->vif->bssid;
 644                         buffer_offset = ETH_ETHERNET_HDR_OFFSET;
 645                         memcpy(&txb[offset + 8], bssid, 6);
 646                 } else {
 647                         buffer_offset = HOST_HDR_OFFSET;
 648                 }
 649 
 650                 memcpy(&txb[offset + buffer_offset],
 651                        tqe->buffer, tqe->buffer_size);
 652                 offset += vmm_sz;
 653                 i++;
 654                 tqe->status = 1;
 655                 if (tqe->tx_complete_func)
 656                         tqe->tx_complete_func(tqe->priv, tqe->status);
 657                 if (tqe->ack_idx != NOT_TCP_ACK &&
 658                     tqe->ack_idx < MAX_PENDING_ACKS)
 659                         vif->ack_filter.pending_acks[tqe->ack_idx].txqe = NULL;
 660                 kfree(tqe);
 661         } while (--entries);
 662 
 663         acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
 664 
 665         ret = func->hif_clear_int_ext(wilc, ENABLE_TX_VMM);
 666         if (!ret)
 667                 goto out_release_bus;
 668 
 669         ret = func->hif_block_tx_ext(wilc, 0, txb, offset);
 670 
 671 out_release_bus:
 672         release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 673 
 674 out:
 675         mutex_unlock(&wilc->txq_add_to_head_cs);
 676 
 677         *txq_count = wilc->txq_entries;
 678         return ret;
 679 }
 680 
 681 static void wilc_wlan_handle_rx_buff(struct wilc *wilc, u8 *buffer, int size)
 682 {
 683         int offset = 0;
 684         u32 header;
 685         u32 pkt_len, pkt_offset, tp_len;
 686         int is_cfg_packet;
 687         u8 *buff_ptr;
 688 
 689         do {
 690                 buff_ptr = buffer + offset;
 691                 header = get_unaligned_le32(buff_ptr);
 692 
 693                 is_cfg_packet = (header >> 31) & 0x1;
 694                 pkt_offset = (header >> 22) & 0x1ff;
 695                 tp_len = (header >> 11) & 0x7ff;
 696                 pkt_len = header & 0x7ff;
 697 
 698                 if (pkt_len == 0 || tp_len == 0)
 699                         break;
 700 
 701                 if (pkt_offset & IS_MANAGMEMENT) {
 702                         buff_ptr += HOST_HDR_OFFSET;
 703                         wilc_wfi_mgmt_rx(wilc, buff_ptr, pkt_len);
 704                 } else {
 705                         if (!is_cfg_packet) {
 706                                 if (pkt_len > 0) {
 707                                         wilc_frmw_to_host(wilc, buff_ptr,
 708                                                           pkt_len, pkt_offset);
 709                                 }
 710                         } else {
 711                                 struct wilc_cfg_rsp rsp;
 712 
 713                                 buff_ptr += pkt_offset;
 714 
 715                                 wilc_wlan_cfg_indicate_rx(wilc, buff_ptr,
 716                                                           pkt_len,
 717                                                           &rsp);
 718                                 if (rsp.type == WILC_CFG_RSP) {
 719                                         if (wilc->cfg_seq_no == rsp.seq_no)
 720                                                 complete(&wilc->cfg_event);
 721                                 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
 722                                         wilc_mac_indicate(wilc);
 723                                 }
 724                         }
 725                 }
 726                 offset += tp_len;
 727                 if (offset >= size)
 728                         break;
 729         } while (1);
 730 }
 731 
 732 static void wilc_wlan_handle_rxq(struct wilc *wilc)
 733 {
 734         int size;
 735         u8 *buffer;
 736         struct rxq_entry_t *rqe;
 737 
 738         do {
 739                 if (wilc->quit) {
 740                         complete(&wilc->cfg_event);
 741                         break;
 742                 }
 743                 rqe = wilc_wlan_rxq_remove(wilc);
 744                 if (!rqe)
 745                         break;
 746 
 747                 buffer = rqe->buffer;
 748                 size = rqe->buffer_size;
 749                 wilc_wlan_handle_rx_buff(wilc, buffer, size);
 750 
 751                 kfree(rqe);
 752         } while (1);
 753 }
 754 
 755 static void wilc_unknown_isr_ext(struct wilc *wilc)
 756 {
 757         wilc->hif_func->hif_clear_int_ext(wilc, 0);
 758 }
 759 
 760 static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
 761 {
 762         u32 offset = wilc->rx_buffer_offset;
 763         u8 *buffer = NULL;
 764         u32 size;
 765         u32 retries = 0;
 766         int ret = 0;
 767         struct rxq_entry_t *rqe;
 768 
 769         size = (int_status & 0x7fff) << 2;
 770 
 771         while (!size && retries < 10) {
 772                 wilc->hif_func->hif_read_size(wilc, &size);
 773                 size = (size & 0x7fff) << 2;
 774                 retries++;
 775         }
 776 
 777         if (size <= 0)
 778                 return;
 779 
 780         if (WILC_RX_BUFF_SIZE - offset < size)
 781                 offset = 0;
 782 
 783         buffer = &wilc->rx_buffer[offset];
 784 
 785         wilc->hif_func->hif_clear_int_ext(wilc, DATA_INT_CLR | ENABLE_RX_VMM);
 786         ret = wilc->hif_func->hif_block_rx_ext(wilc, 0, buffer, size);
 787         if (!ret)
 788                 return;
 789 
 790         offset += size;
 791         wilc->rx_buffer_offset = offset;
 792         rqe = kmalloc(sizeof(*rqe), GFP_KERNEL);
 793         if (!rqe)
 794                 return;
 795 
 796         rqe->buffer = buffer;
 797         rqe->buffer_size = size;
 798         wilc_wlan_rxq_add(wilc, rqe);
 799         wilc_wlan_handle_rxq(wilc);
 800 }
 801 
 802 void wilc_handle_isr(struct wilc *wilc)
 803 {
 804         u32 int_status;
 805 
 806         acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
 807         wilc->hif_func->hif_read_int(wilc, &int_status);
 808 
 809         if (int_status & DATA_INT_EXT)
 810                 wilc_wlan_handle_isr_ext(wilc, int_status);
 811 
 812         if (!(int_status & (ALL_INT_EXT)))
 813                 wilc_unknown_isr_ext(wilc);
 814 
 815         release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 816 }
 817 EXPORT_SYMBOL_GPL(wilc_handle_isr);
 818 
 819 int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
 820                                 u32 buffer_size)
 821 {
 822         u32 offset;
 823         u32 addr, size, size2, blksz;
 824         u8 *dma_buffer;
 825         int ret = 0;
 826 
 827         blksz = BIT(12);
 828 
 829         dma_buffer = kmalloc(blksz, GFP_KERNEL);
 830         if (!dma_buffer)
 831                 return -EIO;
 832 
 833         offset = 0;
 834         do {
 835                 addr = get_unaligned_le32(&buffer[offset]);
 836                 size = get_unaligned_le32(&buffer[offset + 4]);
 837                 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
 838                 offset += 8;
 839                 while (((int)size) && (offset < buffer_size)) {
 840                         if (size <= blksz)
 841                                 size2 = size;
 842                         else
 843                                 size2 = blksz;
 844 
 845                         memcpy(dma_buffer, &buffer[offset], size2);
 846                         ret = wilc->hif_func->hif_block_tx(wilc, addr,
 847                                                            dma_buffer, size2);
 848                         if (!ret)
 849                                 break;
 850 
 851                         addr += size2;
 852                         offset += size2;
 853                         size -= size2;
 854                 }
 855                 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
 856 
 857                 if (!ret) {
 858                         ret = -EIO;
 859                         goto fail;
 860                 }
 861         } while (offset < buffer_size);
 862 
 863 fail:
 864 
 865         kfree(dma_buffer);
 866 
 867         return (ret < 0) ? ret : 0;
 868 }
 869 
 870 int wilc_wlan_start(struct wilc *wilc)
 871 {
 872         u32 reg = 0;
 873         int ret;
 874         u32 chipid;
 875 
 876         if (wilc->io_type == WILC_HIF_SDIO) {
 877                 reg = 0;
 878                 reg |= BIT(3);
 879         } else if (wilc->io_type == WILC_HIF_SPI) {
 880                 reg = 1;
 881         }
 882         acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
 883         ret = wilc->hif_func->hif_write_reg(wilc, WILC_VMM_CORE_CFG, reg);
 884         if (!ret) {
 885                 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
 886                 return -EIO;
 887         }
 888         reg = 0;
 889         if (wilc->io_type == WILC_HIF_SDIO && wilc->dev_irq_num)
 890                 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
 891 
 892 #ifdef WILC_DISABLE_PMU
 893 #else
 894         reg |= WILC_HAVE_USE_PMU;
 895 #endif
 896 
 897 #ifdef WILC_SLEEP_CLK_SRC_XO
 898         reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
 899 #elif defined WILC_SLEEP_CLK_SRC_RTC
 900         reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
 901 #endif
 902 
 903 #ifdef WILC_EXT_PA_INV_TX_RX
 904         reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
 905 #endif
 906         reg |= WILC_HAVE_USE_IRQ_AS_HOST_WAKE;
 907         reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
 908 #ifdef XTAL_24
 909         reg |= WILC_HAVE_XTAL_24;
 910 #endif
 911 #ifdef DISABLE_WILC_UART
 912         reg |= WILC_HAVE_DISABLE_WILC_UART;
 913 #endif
 914 
 915         ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_1, reg);
 916         if (!ret) {
 917                 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
 918                 return -EIO;
 919         }
 920 
 921         wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT);
 922 
 923         ret = wilc->hif_func->hif_read_reg(wilc, 0x1000, &chipid);
 924         if (!ret) {
 925                 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
 926                 return -EIO;
 927         }
 928 
 929         wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
 930         if ((reg & BIT(10)) == BIT(10)) {
 931                 reg &= ~BIT(10);
 932                 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
 933                 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
 934         }
 935 
 936         reg |= BIT(10);
 937         ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
 938         wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
 939         release_bus(wilc, WILC_BUS_RELEASE_ONLY);
 940 
 941         return (ret < 0) ? ret : 0;
 942 }
 943 
 944 int wilc_wlan_stop(struct wilc *wilc, struct wilc_vif *vif)
 945 {
 946         u32 reg = 0;
 947         int ret;
 948 
 949         acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
 950 
 951         ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, &reg);
 952         if (!ret) {
 953                 netdev_err(vif->ndev, "Error while reading reg\n");
 954                 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 955                 return -EIO;
 956         }
 957 
 958         ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0,
 959                                         (reg | WILC_ABORT_REQ_BIT));
 960         if (!ret) {
 961                 netdev_err(vif->ndev, "Error while writing reg\n");
 962                 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 963                 return -EIO;
 964         }
 965 
 966         ret = wilc->hif_func->hif_read_reg(wilc, WILC_FW_HOST_COMM, &reg);
 967         if (!ret) {
 968                 netdev_err(vif->ndev, "Error while reading reg\n");
 969                 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 970                 return -EIO;
 971         }
 972         reg = BIT(0);
 973 
 974         ret = wilc->hif_func->hif_write_reg(wilc, WILC_FW_HOST_COMM, reg);
 975         if (!ret) {
 976                 netdev_err(vif->ndev, "Error while writing reg\n");
 977                 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 978                 return -EIO;
 979         }
 980 
 981         release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 982 
 983         return 0;
 984 }
 985 
 986 void wilc_wlan_cleanup(struct net_device *dev)
 987 {
 988         struct txq_entry_t *tqe;
 989         struct rxq_entry_t *rqe;
 990         struct wilc_vif *vif = netdev_priv(dev);
 991         struct wilc *wilc = vif->wilc;
 992 
 993         wilc->quit = 1;
 994         do {
 995                 tqe = wilc_wlan_txq_remove_from_head(dev);
 996                 if (!tqe)
 997                         break;
 998                 if (tqe->tx_complete_func)
 999                         tqe->tx_complete_func(tqe->priv, 0);
1000                 kfree(tqe);
1001         } while (1);
1002 
1003         do {
1004                 rqe = wilc_wlan_rxq_remove(wilc);
1005                 if (!rqe)
1006                         break;
1007                 kfree(rqe);
1008         } while (1);
1009 
1010         kfree(wilc->rx_buffer);
1011         wilc->rx_buffer = NULL;
1012         kfree(wilc->tx_buffer);
1013         wilc->tx_buffer = NULL;
1014         wilc->hif_func->hif_deinit(NULL);
1015 }
1016 
1017 static int wilc_wlan_cfg_commit(struct wilc_vif *vif, int type,
1018                                 u32 drv_handler)
1019 {
1020         struct wilc *wilc = vif->wilc;
1021         struct wilc_cfg_frame *cfg = &wilc->cfg_frame;
1022         int t_len = wilc->cfg_frame_offset + sizeof(struct wilc_cfg_cmd_hdr);
1023 
1024         if (type == WILC_CFG_SET)
1025                 cfg->hdr.cmd_type = 'W';
1026         else
1027                 cfg->hdr.cmd_type = 'Q';
1028 
1029         cfg->hdr.seq_no = wilc->cfg_seq_no % 256;
1030         cfg->hdr.total_len = cpu_to_le16(t_len);
1031         cfg->hdr.driver_handler = cpu_to_le32(drv_handler);
1032         wilc->cfg_seq_no = cfg->hdr.seq_no;
1033 
1034         if (!wilc_wlan_txq_add_cfg_pkt(vif, (u8 *)&cfg->hdr, t_len))
1035                 return -1;
1036 
1037         return 0;
1038 }
1039 
1040 int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
1041                       u32 buffer_size, int commit, u32 drv_handler)
1042 {
1043         u32 offset;
1044         int ret_size;
1045         struct wilc *wilc = vif->wilc;
1046 
1047         mutex_lock(&wilc->cfg_cmd_lock);
1048 
1049         if (start)
1050                 wilc->cfg_frame_offset = 0;
1051 
1052         offset = wilc->cfg_frame_offset;
1053         ret_size = wilc_wlan_cfg_set_wid(wilc->cfg_frame.frame, offset,
1054                                          wid, buffer, buffer_size);
1055         offset += ret_size;
1056         wilc->cfg_frame_offset = offset;
1057 
1058         if (!commit) {
1059                 mutex_unlock(&wilc->cfg_cmd_lock);
1060                 return ret_size;
1061         }
1062 
1063         netdev_dbg(vif->ndev, "%s: seqno[%d]\n", __func__, wilc->cfg_seq_no);
1064 
1065         if (wilc_wlan_cfg_commit(vif, WILC_CFG_SET, drv_handler))
1066                 ret_size = 0;
1067 
1068         if (!wait_for_completion_timeout(&wilc->cfg_event,
1069                                          WILC_CFG_PKTS_TIMEOUT)) {
1070                 netdev_dbg(vif->ndev, "%s: Timed Out\n", __func__);
1071                 ret_size = 0;
1072         }
1073 
1074         wilc->cfg_frame_offset = 0;
1075         wilc->cfg_seq_no += 1;
1076         mutex_unlock(&wilc->cfg_cmd_lock);
1077 
1078         return ret_size;
1079 }
1080 
1081 int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
1082                       u32 drv_handler)
1083 {
1084         u32 offset;
1085         int ret_size;
1086         struct wilc *wilc = vif->wilc;
1087 
1088         mutex_lock(&wilc->cfg_cmd_lock);
1089 
1090         if (start)
1091                 wilc->cfg_frame_offset = 0;
1092 
1093         offset = wilc->cfg_frame_offset;
1094         ret_size = wilc_wlan_cfg_get_wid(wilc->cfg_frame.frame, offset, wid);
1095         offset += ret_size;
1096         wilc->cfg_frame_offset = offset;
1097 
1098         if (!commit) {
1099                 mutex_unlock(&wilc->cfg_cmd_lock);
1100                 return ret_size;
1101         }
1102 
1103         if (wilc_wlan_cfg_commit(vif, WILC_CFG_QUERY, drv_handler))
1104                 ret_size = 0;
1105 
1106         if (!wait_for_completion_timeout(&wilc->cfg_event,
1107                                          WILC_CFG_PKTS_TIMEOUT)) {
1108                 netdev_dbg(vif->ndev, "%s: Timed Out\n", __func__);
1109                 ret_size = 0;
1110         }
1111         wilc->cfg_frame_offset = 0;
1112         wilc->cfg_seq_no += 1;
1113         mutex_unlock(&wilc->cfg_cmd_lock);
1114 
1115         return ret_size;
1116 }
1117 
1118 int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
1119                          u32 count)
1120 {
1121         int i;
1122         int ret = 0;
1123         u32 drv = wilc_get_vif_idx(vif);
1124 
1125         if (mode == WILC_GET_CFG) {
1126                 for (i = 0; i < count; i++) {
1127                         if (!wilc_wlan_cfg_get(vif, !i,
1128                                                wids[i].id,
1129                                                (i == count - 1),
1130                                                drv)) {
1131                                 ret = -ETIMEDOUT;
1132                                 break;
1133                         }
1134                 }
1135                 for (i = 0; i < count; i++) {
1136                         wids[i].size = wilc_wlan_cfg_get_val(vif->wilc,
1137                                                              wids[i].id,
1138                                                              wids[i].val,
1139                                                              wids[i].size);
1140                 }
1141         } else if (mode == WILC_SET_CFG) {
1142                 for (i = 0; i < count; i++) {
1143                         if (!wilc_wlan_cfg_set(vif, !i,
1144                                                wids[i].id,
1145                                                wids[i].val,
1146                                                wids[i].size,
1147                                                (i == count - 1),
1148                                                drv)) {
1149                                 ret = -ETIMEDOUT;
1150                                 break;
1151                         }
1152                 }
1153         }
1154 
1155         return ret;
1156 }
1157 
1158 static u32 init_chip(struct net_device *dev)
1159 {
1160         u32 chipid;
1161         u32 reg, ret = 0;
1162         struct wilc_vif *vif = netdev_priv(dev);
1163         struct wilc *wilc = vif->wilc;
1164 
1165         acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
1166 
1167         chipid = wilc_get_chipid(wilc, true);
1168 
1169         if ((chipid & 0xfff) != 0xa0) {
1170                 ret = wilc->hif_func->hif_read_reg(wilc, 0x1118, &reg);
1171                 if (!ret) {
1172                         netdev_err(dev, "fail read reg 0x1118\n");
1173                         goto release;
1174                 }
1175                 reg |= BIT(0);
1176                 ret = wilc->hif_func->hif_write_reg(wilc, 0x1118, reg);
1177                 if (!ret) {
1178                         netdev_err(dev, "fail write reg 0x1118\n");
1179                         goto release;
1180                 }
1181                 ret = wilc->hif_func->hif_write_reg(wilc, 0xc0000, 0x71);
1182                 if (!ret) {
1183                         netdev_err(dev, "fail write reg 0xc0000\n");
1184                         goto release;
1185                 }
1186         }
1187 
1188 release:
1189         release_bus(wilc, WILC_BUS_RELEASE_ONLY);
1190 
1191         return ret;
1192 }
1193 
1194 u32 wilc_get_chipid(struct wilc *wilc, bool update)
1195 {
1196         static u32 chipid;
1197         u32 tempchipid = 0;
1198         u32 rfrevid = 0;
1199 
1200         if (chipid == 0 || update) {
1201                 wilc->hif_func->hif_read_reg(wilc, 0x1000, &tempchipid);
1202                 wilc->hif_func->hif_read_reg(wilc, 0x13f4, &rfrevid);
1203                 if (!is_wilc1000(tempchipid)) {
1204                         chipid = 0;
1205                         return chipid;
1206                 }
1207                 if (tempchipid == 0x1002a0) {
1208                         if (rfrevid != 0x1)
1209                                 tempchipid = 0x1002a1;
1210                 } else if (tempchipid == 0x1002b0) {
1211                         if (rfrevid == 0x4)
1212                                 tempchipid = 0x1002b1;
1213                         else if (rfrevid != 0x3)
1214                                 tempchipid = 0x1002b2;
1215                 }
1216 
1217                 chipid = tempchipid;
1218         }
1219         return chipid;
1220 }
1221 
1222 int wilc_wlan_init(struct net_device *dev)
1223 {
1224         int ret = 0;
1225         struct wilc_vif *vif = netdev_priv(dev);
1226         struct wilc *wilc;
1227 
1228         wilc = vif->wilc;
1229 
1230         wilc->quit = 0;
1231 
1232         if (!wilc->hif_func->hif_init(wilc, false)) {
1233                 ret = -EIO;
1234                 goto fail;
1235         }
1236 
1237         if (!wilc->tx_buffer)
1238                 wilc->tx_buffer = kmalloc(WILC_TX_BUFF_SIZE, GFP_KERNEL);
1239 
1240         if (!wilc->tx_buffer) {
1241                 ret = -ENOBUFS;
1242                 goto fail;
1243         }
1244 
1245         if (!wilc->rx_buffer)
1246                 wilc->rx_buffer = kmalloc(WILC_RX_BUFF_SIZE, GFP_KERNEL);
1247 
1248         if (!wilc->rx_buffer) {
1249                 ret = -ENOBUFS;
1250                 goto fail;
1251         }
1252 
1253         if (!init_chip(dev)) {
1254                 ret = -EIO;
1255                 goto fail;
1256         }
1257 
1258         return 1;
1259 
1260 fail:
1261 
1262         kfree(wilc->rx_buffer);
1263         wilc->rx_buffer = NULL;
1264         kfree(wilc->tx_buffer);
1265         wilc->tx_buffer = NULL;
1266 
1267         return ret;
1268 }

/* [<][>][^][v][top][bottom][index][help] */