1 /* ////////////////////////////////////////////////////////////////////////// */
3 /* Copyright (c) Atmel Corporation. All rights reserved. */
5 /* Module Name: wilc_wlan.c */
8 /* //////////////////////////////////////////////////////////////////////////// */
10 #include "wilc_wlan_if.h"
11 #include "wilc_wfi_netdevice.h"
12 #include "wilc_wlan_cfg.h"
14 /********************************************
18 ********************************************/
19 extern wilc_hif_func_t hif_sdio;
20 extern wilc_hif_func_t hif_spi;
21 extern void WILC_WFI_mgmt_rx(u8 *buff, u32 size);
22 u32 wilc_get_chipid(u8 update);
23 u16 Set_machw_change_vir_if(bool bValue);
31 * input interface functions
33 wilc_wlan_io_func_t io_func;
36 * host interface functions
38 wilc_hif_func_t hif_func;
41 * configuration interface functions
44 wilc_cfg_frame_t cfg_frame;
65 unsigned long txq_spinlock_flags;
67 struct txq_entry_t *txq_head;
68 struct txq_entry_t *txq_tail;
75 struct rxq_entry_t *rxq_head;
76 struct rxq_entry_t *rxq_tail;
83 static wilc_wlan_dev_t g_wlan;
85 static inline void chip_allow_sleep(void);
86 static inline void chip_wakeup(void);
87 /********************************************
91 ********************************************/
93 static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
95 static void wilc_debug(u32 flag, char *fmt, ...)
100 if (flag & dbgflag) {
102 vsprintf(buf, fmt, args);
109 static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
111 /*acquire_bus() and release_bus() are made static inline functions*/
112 /*as a temporary workaround to fix a problem of receiving*/
113 /*unknown interrupt from FW*/
114 static inline void acquire_bus(BUS_ACQUIRE_T acquire)
117 mutex_lock(&g_linux_wlan->hif_cs);
118 #ifndef WILC_OPTIMIZE_SLEEP_INT
119 if (genuChipPSstate != CHIP_WAKEDUP)
122 if (acquire == ACQUIRE_AND_WAKEUP)
127 static inline void release_bus(BUS_RELEASE_T release)
129 #ifdef WILC_OPTIMIZE_SLEEP_INT
130 if (release == RELEASE_ALLOW_SLEEP)
133 mutex_unlock(&g_linux_wlan->hif_cs);
135 /********************************************
139 ********************************************/
141 static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
144 wilc_wlan_dev_t *p = &g_wlan;
145 if (tqe == p->txq_head) {
147 p->txq_head = tqe->next;
149 p->txq_head->prev = NULL;
152 } else if (tqe == p->txq_tail) {
153 p->txq_tail = (tqe->prev);
155 p->txq_tail->next = NULL;
157 tqe->prev->next = tqe->next;
158 tqe->next->prev = tqe->prev;
164 static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
166 struct txq_entry_t *tqe;
167 wilc_wlan_dev_t *p = &g_wlan;
170 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
173 p->txq_head = tqe->next;
175 p->txq_head->prev = NULL;
185 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
189 static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
191 wilc_wlan_dev_t *p = &g_wlan;
193 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
195 if (p->txq_head == NULL) {
202 tqe->prev = p->txq_tail;
203 p->txq_tail->next = tqe;
207 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
209 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
214 PRINT_D(TX_DBG, "Wake the txq_handling\n");
216 up(&g_linux_wlan->txq_event);
219 static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
221 wilc_wlan_dev_t *p = &g_wlan;
223 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
227 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
229 if (p->txq_head == NULL) {
235 tqe->next = p->txq_head;
237 p->txq_head->prev = tqe;
241 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
243 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
244 up(&g_linux_wlan->txq_add_to_head_cs);
250 up(&g_linux_wlan->txq_event);
251 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
257 u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
259 #ifdef TCP_ACK_FILTER
260 struct Ack_session_info;
261 struct Ack_session_info {
272 struct txq_entry_t *txqe;
273 } Pending_Acks_info_t /*Ack_info_t*/;
278 struct Ack_session_info *Free_head;
279 struct Ack_session_info *Alloc_head;
281 #define NOT_TCP_ACK (-1)
283 #define MAX_TCP_SESSION 25
284 #define MAX_PENDING_ACKS 256
285 struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
286 Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
288 u32 PendingAcks_arrBase;
289 u32 Opened_TCP_session;
294 static inline int Init_TCP_tracking(void)
300 static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
302 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
303 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
304 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
305 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
306 Opened_TCP_session++;
308 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
312 static inline int Update_TCP_track_session(u32 index, u32 Ack)
315 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num)
316 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
320 static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
322 Statisitcs_totalAcks++;
323 if (Pending_Acks < MAX_PENDING_ACKS) {
324 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
325 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
326 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
327 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
335 static inline int remove_TCP_related(void)
337 wilc_wlan_dev_t *p = &g_wlan;
340 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
342 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
346 static inline int tcp_process(struct txq_entry_t *tqe)
350 u8 *buffer = tqe->buffer;
351 unsigned short h_proto;
353 wilc_wlan_dev_t *p = &g_wlan;
356 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
358 eth_hdr_ptr = &buffer[0];
359 h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
360 if (h_proto == 0x0800) { /* IP */
364 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
365 protocol = ip_hdr_ptr[9];
368 if (protocol == 0x06) {
370 u32 IHL, Total_Length, Data_offset;
372 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
373 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
374 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
375 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
376 if (Total_Length == (IHL + Data_offset)) { /*we want to recognize the clear Acks(packet only carry Ack infos not with data) so data size must be equal zero*/
379 seq_no = (((u32)tcp_hdr_ptr[4]) << 24) + (((u32)tcp_hdr_ptr[5]) << 16) + (((u32)tcp_hdr_ptr[6]) << 8) + ((u32)tcp_hdr_ptr[7]);
381 Ack_no = (((u32)tcp_hdr_ptr[8]) << 24) + (((u32)tcp_hdr_ptr[9]) << 16) + (((u32)tcp_hdr_ptr[10]) << 8) + ((u32)tcp_hdr_ptr[11]);
384 for (i = 0; i < Opened_TCP_session; i++) {
385 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
386 Update_TCP_track_session(i, Ack_no);
390 if (i == Opened_TCP_session)
391 add_TCP_track_session(0, 0, seq_no);
393 add_TCP_Pending_Ack(Ack_no, i, tqe);
404 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
409 static int wilc_wlan_txq_filter_dup_tcp_ack(void)
414 wilc_wlan_dev_t *p = &g_wlan;
416 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, p->txq_spinlock_flags);
417 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
418 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
419 struct txq_entry_t *tqe;
421 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
422 tqe = Pending_Acks_info[i].txqe;
424 wilc_wlan_txq_remove(tqe);
425 Statisitcs_DroppedAcks++;
426 tqe->status = 1; /* mark the packet send */
427 if (tqe->tx_complete_func)
428 tqe->tx_complete_func(tqe->priv, tqe->status);
435 Opened_TCP_session = 0;
437 if (PendingAcks_arrBase == 0)
438 PendingAcks_arrBase = MAX_TCP_SESSION;
440 PendingAcks_arrBase = 0;
443 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock,
444 p->txq_spinlock_flags);
446 while (Dropped > 0) {
447 /*consume the semaphore count of the removed packet*/
448 linux_wlan_lock_timeout(&g_linux_wlan->txq_event, 1);
456 bool EnableTCPAckFilter = false;
458 void Enable_TCP_ACK_Filter(bool value)
460 EnableTCPAckFilter = value;
463 bool is_TCP_ACK_Filter_Enabled(void)
465 return EnableTCPAckFilter;
468 static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
470 wilc_wlan_dev_t *p = &g_wlan;
471 struct txq_entry_t *tqe;
473 PRINT_D(TX_DBG, "Adding config packet ...\n");
475 PRINT_D(TX_DBG, "Return due to clear function\n");
476 up(&g_linux_wlan->cfg_event);
480 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
482 PRINT_ER("Failed to allocate memory\n");
486 tqe->type = WILC_CFG_PKT;
487 tqe->buffer = buffer;
488 tqe->buffer_size = buffer_size;
489 tqe->tx_complete_func = NULL;
491 #ifdef TCP_ACK_FILTER
492 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
495 * Configuration packet always at the front
497 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
499 if (wilc_wlan_txq_add_to_head(tqe))
504 int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size,
505 wilc_tx_complete_func_t func)
507 wilc_wlan_dev_t *p = &g_wlan;
508 struct txq_entry_t *tqe;
513 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
517 tqe->type = WILC_NET_PKT;
518 tqe->buffer = buffer;
519 tqe->buffer_size = buffer_size;
520 tqe->tx_complete_func = func;
523 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
524 #ifdef TCP_ACK_FILTER
525 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
526 if (is_TCP_ACK_Filter_Enabled())
529 wilc_wlan_txq_add_to_tail(tqe);
530 /*return number of itemes in the queue*/
531 return p->txq_entries;
534 int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
537 wilc_wlan_dev_t *p = &g_wlan;
538 struct txq_entry_t *tqe;
543 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
547 tqe->type = WILC_MGMT_PKT;
548 tqe->buffer = buffer;
549 tqe->buffer_size = buffer_size;
550 tqe->tx_complete_func = func;
552 #ifdef TCP_ACK_FILTER
553 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
555 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
556 wilc_wlan_txq_add_to_tail(tqe);
560 static struct txq_entry_t *wilc_wlan_txq_get_first(void)
562 wilc_wlan_dev_t *p = &g_wlan;
563 struct txq_entry_t *tqe;
566 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
570 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
576 static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
579 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
582 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
588 static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
590 wilc_wlan_dev_t *p = &g_wlan;
595 mutex_lock(&g_linux_wlan->rxq_cs);
596 if (p->rxq_head == NULL) {
597 PRINT_D(RX_DBG, "Add to Queue head\n");
602 PRINT_D(RX_DBG, "Add to Queue tail\n");
603 p->rxq_tail->next = rqe;
608 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
609 mutex_unlock(&g_linux_wlan->rxq_cs);
610 return p->rxq_entries;
613 static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
615 wilc_wlan_dev_t *p = &g_wlan;
617 PRINT_D(RX_DBG, "Getting rxQ element\n");
619 struct rxq_entry_t *rqe;
621 mutex_lock(&g_linux_wlan->rxq_cs);
623 p->rxq_head = p->rxq_head->next;
625 PRINT_D(RX_DBG, "RXQ entries decreased\n");
626 mutex_unlock(&g_linux_wlan->rxq_cs);
629 PRINT_D(RX_DBG, "Nothing to get from Q\n");
634 /********************************************
636 * Power Save handle functions
638 ********************************************/
642 #ifdef WILC_OPTIMIZE_SLEEP_INT
644 static inline void chip_allow_sleep(void)
649 g_wlan.hif_func.hif_read_reg(0xf0, ®);
651 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
654 static inline void chip_wakeup(void)
656 u32 reg, clk_status_reg, trials = 0;
659 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
661 g_wlan.hif_func.hif_read_reg(1, ®);
663 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
666 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
669 /* Wait for the chip to stabilize*/
670 usleep_range(2 * 1000, 2 * 1000);
671 /* Make sure chip is awake. This is an extra step that can be removed */
672 /* later to avoid the bus access overhead */
673 if ((wilc_get_chipid(true) == 0))
674 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
676 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
678 } while (wilc_get_chipid(true) == 0);
679 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
680 g_wlan.hif_func.hif_read_reg(0xf0, ®);
683 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
685 /* Check the clock status */
686 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
688 /* in case of clocks off, wait 2ms, and check it again. */
689 /* if still off, wait for another 2ms, for a total wait of 6ms. */
690 /* If still off, redo the wake up sequence */
691 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
692 /* Wait for the chip to stabilize*/
693 usleep_range(2 * 1000, 2 * 1000);
695 /* Make sure chip is awake. This is an extra step that can be removed */
696 /* later to avoid the bus access overhead */
697 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
699 if ((clk_status_reg & 0x1) == 0)
700 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
703 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
704 if ((clk_status_reg & 0x1) == 0) {
706 g_wlan.hif_func.hif_write_reg(0xf0, reg &
709 } while ((clk_status_reg & 0x1) == 0);
713 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
714 g_wlan.hif_func.hif_read_reg(0x1C0C, ®);
716 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
718 if (wilc_get_chipid(false) >= 0x1002b0) {
719 /* Enable PALDO back right after wakeup */
722 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
724 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
726 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
728 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
731 genuChipPSstate = CHIP_WAKEDUP;
734 static inline void chip_wakeup(void)
739 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
740 g_wlan.hif_func.hif_read_reg(1, ®);
741 /* Make sure bit 1 is 0 before we start. */
742 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
744 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
746 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
747 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
748 /* Make sure bit 0 is 0 before we start. */
749 g_wlan.hif_func.hif_read_reg(0xf0, ®);
750 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
752 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
754 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
758 /* Wait for the chip to stabilize*/
761 /* Make sure chip is awake. This is an extra step that can be removed */
762 /* later to avoid the bus access overhead */
763 if ((wilc_get_chipid(true) == 0))
764 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
766 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
768 } while (wilc_get_chipid(true) == 0);
770 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
771 g_wlan.hif_func.hif_read_reg(0x1C0C, ®);
773 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
775 if (wilc_get_chipid(false) >= 0x1002b0) {
776 /* Enable PALDO back right after wakeup */
779 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
781 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
783 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
785 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
788 genuChipPSstate = CHIP_WAKEDUP;
791 void chip_sleep_manually(u32 u32SleepTime)
793 if (genuChipPSstate != CHIP_WAKEDUP) {
794 /* chip is already sleeping. Do nothing */
797 acquire_bus(ACQUIRE_ONLY);
799 #ifdef WILC_OPTIMIZE_SLEEP_INT
803 /* Trigger the manual sleep interrupt */
804 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
806 genuChipPSstate = CHIP_SLEEPING_MANUAL;
807 release_bus(RELEASE_ONLY);
812 /********************************************
814 * Tx, Rx queue handle functions
816 ********************************************/
817 int wilc_wlan_handle_txq(u32 *pu32TxqCount)
819 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
823 u8 *txb = p->tx_buffer;
826 struct txq_entry_t *tqe;
830 u32 vmm_table[WILC_VMM_TBL_SIZE];
837 linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
839 #ifdef TCP_ACK_FILTER
840 wilc_wlan_txq_filter_dup_tcp_ack();
845 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
846 tqe = wilc_wlan_txq_get_first();
850 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
852 if (tqe->type == WILC_CFG_PKT)
853 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
855 else if (tqe->type == WILC_NET_PKT)
856 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
859 vmm_sz = HOST_HDR_OFFSET;
861 vmm_sz += tqe->buffer_size;
862 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
863 if (vmm_sz & 0x3) { /* has to be word aligned */
864 vmm_sz = (vmm_sz + 4) & ~0x3;
866 if ((sum + vmm_sz) > LINUX_TX_SIZE)
869 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
870 vmm_table[i] = vmm_sz / 4; /* table take the word size */
871 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
873 if (tqe->type == WILC_CFG_PKT) {
874 vmm_table[i] |= BIT(10);
875 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
878 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
883 PRINT_D(TX_DBG, "sum = %d\n", sum);
884 tqe = wilc_wlan_txq_get_next(tqe);
890 if (i == 0) { /* nothing in the queue */
891 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
894 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
895 vmm_table[i] = 0x0; /* mark the last element to 0 */
897 acquire_bus(ACQUIRE_AND_WAKEUP);
901 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®);
903 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
907 if ((reg & 0x1) == 0) {
911 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
917 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
918 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
922 * wait for vmm table is ready
924 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
925 release_bus(RELEASE_ALLOW_SLEEP);
926 usleep_range(3000, 3000);
927 acquire_bus(ACQUIRE_AND_WAKEUP);
940 ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
942 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
950 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
952 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
957 * wait for confirm...
961 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, ®);
963 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
966 if ((reg >> 2) & 0x1) {
970 entries = ((reg >> 3) & 0x3f);
973 release_bus(RELEASE_ALLOW_SLEEP);
974 usleep_range(3000, 3000);
975 acquire_bus(ACQUIRE_AND_WAKEUP);
976 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
980 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
988 PRINT_WRN(GENERIC_DBG, "[wilc txq]: no more buffer in the chip (reg: %08x), retry later [[ %d, %x ]]\n", reg, i, vmm_table[i - 1]);
990 /* undo the transaction. */
991 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®);
993 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
997 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
999 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1012 ret = WILC_TX_ERR_NO_BUF;
1016 /* since copying data into txb takes some time, then
1017 * allow the bus lock to be released let the RX task go. */
1018 release_bus(RELEASE_ALLOW_SLEEP);
1021 * Copy data to the TX buffer
1026 tqe = wilc_wlan_txq_remove_from_head();
1027 if (tqe != NULL && (vmm_table[i] != 0)) {
1028 u32 header, buffer_offset;
1031 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1033 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1035 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
1036 if (tqe->type == WILC_MGMT_PKT)
1042 header = BYTE_SWAP(header);
1044 memcpy(&txb[offset], &header, 4);
1045 if (tqe->type == WILC_CFG_PKT) {
1046 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1048 else if (tqe->type == WILC_NET_PKT) {
1049 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
1051 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1052 /* copy the bssid at the sart of the buffer */
1053 memcpy(&txb[offset + 4], pBSSID, 6);
1056 buffer_offset = HOST_HDR_OFFSET;
1059 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1062 tqe->status = 1; /* mark the packet send */
1063 if (tqe->tx_complete_func)
1064 tqe->tx_complete_func(tqe->priv, tqe->status);
1065 #ifdef TCP_ACK_FILTER
1066 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
1067 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1073 } while (--entries);
1078 acquire_bus(ACQUIRE_AND_WAKEUP);
1080 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1082 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1089 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1091 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1097 release_bus(RELEASE_ALLOW_SLEEP);
1101 up(&g_linux_wlan->txq_add_to_head_cs);
1104 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1105 /* return tx[]q count */
1106 *pu32TxqCount = p->txq_entries;
1110 static void wilc_wlan_handle_rxq(struct wilc *wilc)
1112 wilc_wlan_dev_t *p = &g_wlan;
1113 int offset = 0, size, has_packet = 0;
1115 struct rxq_entry_t *rqe;
1124 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
1125 up(&wilc->cfg_event);
1128 rqe = wilc_wlan_rxq_remove();
1130 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1133 buffer = rqe->buffer;
1134 size = rqe->buffer_size;
1135 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1142 u32 pkt_len, pkt_offset, tp_len;
1145 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1146 memcpy(&header, &buffer[offset], 4);
1148 header = BYTE_SWAP(header);
1150 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1154 is_cfg_packet = (header >> 31) & 0x1;
1155 pkt_offset = (header >> 22) & 0x1ff;
1156 tp_len = (header >> 11) & 0x7ff;
1157 pkt_len = header & 0x7ff;
1159 if (pkt_len == 0 || tp_len == 0) {
1160 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1164 #define IS_MANAGMEMENT 0x100
1165 #define IS_MANAGMEMENT_CALLBACK 0x080
1166 #define IS_MGMT_STATUS_SUCCES 0x040
1169 if (pkt_offset & IS_MANAGMEMENT) {
1170 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1171 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1173 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
1178 if (!is_cfg_packet) {
1180 frmw_to_linux(&buffer[offset],
1190 wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
1191 if (rsp.type == WILC_CFG_RSP) {
1193 * wake up the waiting task...
1195 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1196 if (p->cfg_seq_no == rsp.seq_no)
1197 up(&wilc->cfg_event);
1198 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1200 * Call back to indicate status...
1202 linux_wlan_mac_indicate(WILC_MAC_INDICATE_STATUS);
1204 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
1205 linux_wlan_mac_indicate(WILC_MAC_INDICATE_SCAN);
1215 #ifndef MEMORY_STATIC
1221 linux_wlan_rx_complete();
1226 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
1229 /********************************************
1233 ********************************************/
1234 static void wilc_unknown_isr_ext(void)
1236 g_wlan.hif_func.hif_clear_int_ext(0);
1238 static void wilc_pllupdate_isr_ext(u32 int_stats)
1243 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1245 /* Waiting for PLL */
1246 mdelay(WILC_PLL_TO);
1248 /* poll till read a valid data */
1249 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
1250 PRINT_D(TX_DBG, "PLL update retrying\n");
1255 static void wilc_sleeptimer_isr_ext(u32 int_stats1)
1257 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1258 #ifndef WILC_OPTIMIZE_SLEEP_INT
1259 genuChipPSstate = CHIP_SLEEPING_AUTO;
1263 static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
1265 wilc_wlan_dev_t *p = &g_wlan;
1266 #ifdef MEMORY_STATIC
1267 u32 offset = p->rx_buffer_offset;
1273 struct rxq_entry_t *rqe;
1280 size = ((int_status & 0x7fff) << 2);
1282 while (!size && retries < 10) {
1284 /*looping more secure*/
1285 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1286 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1287 p->hif_func.hif_read_size(&size);
1288 size = ((size & 0x7fff) << 2);
1294 #ifdef MEMORY_STATIC
1295 if (LINUX_RX_SIZE - offset < size)
1299 buffer = &p->rx_buffer[offset];
1301 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1306 buffer = kmalloc(size, GFP_KERNEL);
1307 if (buffer == NULL) {
1308 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
1309 usleep_range(100 * 1000, 100 * 1000);
1315 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1317 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1323 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1326 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1333 #ifdef MEMORY_STATIC
1335 p->rx_buffer_offset = offset;
1340 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
1342 rqe->buffer = buffer;
1343 rqe->buffer_size = size;
1344 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1345 wilc_wlan_rxq_add(rqe);
1348 #ifndef MEMORY_STATIC
1353 wilc_wlan_handle_rxq(wilc);
1356 void wilc_handle_isr(void *wilc)
1360 acquire_bus(ACQUIRE_AND_WAKEUP);
1361 g_wlan.hif_func.hif_read_int(&int_status);
1363 if (int_status & PLL_INT_EXT)
1364 wilc_pllupdate_isr_ext(int_status);
1366 if (int_status & DATA_INT_EXT) {
1367 wilc_wlan_handle_isr_ext(wilc, int_status);
1368 #ifndef WILC_OPTIMIZE_SLEEP_INT
1369 /* Chip is up and talking*/
1370 genuChipPSstate = CHIP_WAKEDUP;
1373 if (int_status & SLEEP_INT_EXT)
1374 wilc_sleeptimer_isr_ext(int_status);
1376 if (!(int_status & (ALL_INT_EXT))) {
1378 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1380 wilc_unknown_isr_ext();
1382 release_bus(RELEASE_ALLOW_SLEEP);
1385 /********************************************
1389 ********************************************/
1390 int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
1392 wilc_wlan_dev_t *p = &g_wlan;
1394 u32 addr, size, size2, blksz;
1399 /* Allocate a DMA coherent buffer. */
1401 dma_buffer = kmalloc(blksz, GFP_KERNEL);
1402 if (dma_buffer == NULL) {
1405 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1409 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1415 memcpy(&addr, &buffer[offset], 4);
1416 memcpy(&size, &buffer[offset + 4], 4);
1418 addr = BYTE_SWAP(addr);
1419 size = BYTE_SWAP(size);
1421 acquire_bus(ACQUIRE_ONLY);
1423 while (((int)size) && (offset < buffer_size)) {
1428 /* Copy firmware into a DMA coherent buffer */
1429 memcpy(dma_buffer, &buffer[offset], size2);
1430 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1438 release_bus(RELEASE_ONLY);
1443 PRINT_ER("Can't download firmware IO error\n ");
1446 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1447 } while (offset < buffer_size);
1455 return (ret < 0) ? ret : 0;
1458 /********************************************
1462 ********************************************/
1463 int wilc_wlan_start(void)
1465 wilc_wlan_dev_t *p = &g_wlan;
1471 * Set the host interface
1473 if (p->io_func.io_type == HIF_SDIO) {
1475 reg |= BIT(3); /* bug 4456 and 4557 */
1476 } else if (p->io_func.io_type == HIF_SPI) {
1479 acquire_bus(ACQUIRE_ONLY);
1480 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1482 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1483 release_bus(RELEASE_ONLY);
1489 #ifdef WILC_SDIO_IRQ_GPIO
1490 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1493 #ifdef WILC_DISABLE_PMU
1495 reg |= WILC_HAVE_USE_PMU;
1498 #ifdef WILC_SLEEP_CLK_SRC_XO
1499 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1500 #elif defined WILC_SLEEP_CLK_SRC_RTC
1501 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1504 #ifdef WILC_EXT_PA_INV_TX_RX
1505 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1508 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1511 /*Set oscillator frequency*/
1513 reg |= WILC_HAVE_XTAL_24;
1516 /*Enable/Disable GPIO configuration for FW logs*/
1517 #ifdef DISABLE_WILC_UART
1518 reg |= WILC_HAVE_DISABLE_WILC_UART;
1521 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1523 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1524 release_bus(RELEASE_ONLY);
1533 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1535 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1537 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1538 release_bus(RELEASE_ONLY);
1549 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1550 if ((reg & BIT(10)) == BIT(10)) {
1552 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1553 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1557 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1558 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1559 release_bus(RELEASE_ONLY);
1561 return (ret < 0) ? ret : 0;
1564 void wilc_wlan_global_reset(void)
1567 wilc_wlan_dev_t *p = &g_wlan;
1569 acquire_bus(ACQUIRE_AND_WAKEUP);
1570 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1571 release_bus(RELEASE_ONLY);
1573 int wilc_wlan_stop(void)
1575 wilc_wlan_dev_t *p = &g_wlan;
1580 * TODO: stop the firmware, need a re-download
1582 acquire_bus(ACQUIRE_AND_WAKEUP);
1584 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1586 PRINT_ER("Error while reading reg\n");
1587 release_bus(RELEASE_ALLOW_SLEEP);
1594 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1596 PRINT_ER("Error while writing reg\n");
1597 release_bus(RELEASE_ALLOW_SLEEP);
1604 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1606 PRINT_ER("Error while reading reg\n");
1607 release_bus(RELEASE_ALLOW_SLEEP);
1610 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1611 /*Workaround to ensure that the chip is actually reset*/
1612 if ((reg & BIT(10))) {
1613 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1615 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1618 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1619 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1621 PRINT_ER("Error while reading reg\n");
1622 release_bus(RELEASE_ALLOW_SLEEP);
1625 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1630 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1631 BIT(29) | BIT(30) | BIT(31));
1633 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1634 reg = (u32)~BIT(10);
1636 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1638 release_bus(RELEASE_ALLOW_SLEEP);
1643 void wilc_wlan_cleanup(void)
1645 wilc_wlan_dev_t *p = &g_wlan;
1646 struct txq_entry_t *tqe;
1647 struct rxq_entry_t *rqe;
1653 tqe = wilc_wlan_txq_remove_from_head();
1656 if (tqe->tx_complete_func)
1657 tqe->tx_complete_func(tqe->priv, 0);
1662 rqe = wilc_wlan_rxq_remove();
1665 #ifndef MEMORY_STATIC
1675 #ifdef MEMORY_STATIC
1676 kfree(p->rx_buffer);
1677 p->rx_buffer = NULL;
1679 kfree(p->tx_buffer);
1681 acquire_bus(ACQUIRE_AND_WAKEUP);
1684 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, ®);
1686 PRINT_ER("Error while reading reg\n");
1687 release_bus(RELEASE_ALLOW_SLEEP);
1689 PRINT_ER("Writing ABORT reg\n");
1690 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1692 PRINT_ER("Error while writing reg\n");
1693 release_bus(RELEASE_ALLOW_SLEEP);
1695 release_bus(RELEASE_ALLOW_SLEEP);
1699 p->hif_func.hif_deinit(NULL);
1703 static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
1705 wilc_wlan_dev_t *p = &g_wlan;
1706 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1707 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1708 int seq_no = p->cfg_seq_no % 256;
1709 int driver_handler = (u32)drvHandler;
1715 if (type == WILC_CFG_SET) { /* Set */
1716 cfg->wid_header[0] = 'W';
1717 } else { /* Query */
1718 cfg->wid_header[0] = 'Q';
1720 cfg->wid_header[1] = seq_no; /* sequence number */
1721 cfg->wid_header[2] = (u8)total_len;
1722 cfg->wid_header[3] = (u8)(total_len >> 8);
1723 cfg->wid_header[4] = (u8)driver_handler;
1724 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1725 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1726 cfg->wid_header[7] = (u8)(driver_handler >> 24);
1727 p->cfg_seq_no = seq_no;
1733 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1739 int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1740 int commit, u32 drvHandler)
1742 wilc_wlan_dev_t *p = &g_wlan;
1747 if (p->cfg_frame_in_use)
1751 p->cfg_frame_offset = 0;
1753 offset = p->cfg_frame_offset;
1754 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1755 buffer, buffer_size);
1757 p->cfg_frame_offset = offset;
1760 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1761 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1762 p->cfg_frame_in_use = 1;
1764 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
1767 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1768 CFG_PKTS_TIMEOUT)) {
1769 PRINT_D(TX_DBG, "Set Timed Out\n");
1772 p->cfg_frame_in_use = 0;
1773 p->cfg_frame_offset = 0;
1780 int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
1782 wilc_wlan_dev_t *p = &g_wlan;
1787 if (p->cfg_frame_in_use)
1791 p->cfg_frame_offset = 0;
1793 offset = p->cfg_frame_offset;
1794 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
1796 p->cfg_frame_offset = offset;
1799 p->cfg_frame_in_use = 1;
1801 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
1805 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1806 CFG_PKTS_TIMEOUT)) {
1807 PRINT_D(TX_DBG, "Get Timed Out\n");
1810 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1811 p->cfg_frame_in_use = 0;
1812 p->cfg_frame_offset = 0;
1819 int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
1823 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
1828 void wilc_bus_set_max_speed(void)
1831 /* Increase bus speed to max possible. */
1832 g_wlan.hif_func.hif_set_max_bus_speed();
1835 void wilc_bus_set_default_speed(void)
1838 /* Restore bus speed to default. */
1839 g_wlan.hif_func.hif_set_default_bus_speed();
1846 acquire_bus(ACQUIRE_ONLY);
1848 chipid = wilc_get_chipid(true);
1852 if ((chipid & 0xfff) != 0xa0) {
1854 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1855 * or SD_DAT3 [SPI platform] to ?1?
1857 /* Set cortus reset register to register control. */
1858 ret = g_wlan.hif_func.hif_read_reg(0x1118, ®);
1860 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1864 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1866 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1870 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1871 * (Cortus map) or C0000 (AHB map).
1873 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1875 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1880 release_bus(RELEASE_ONLY);
1886 u32 wilc_get_chipid(u8 update)
1889 /* SDIO can't read into global variables */
1890 /* Use this variable as a temp, then copy to the global */
1894 if (chipid == 0 || update != 0) {
1895 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1896 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1897 if (!ISWILC1000(tempchipid)) {
1901 if (tempchipid == 0x1002a0) {
1902 if (rfrevid == 0x1) { /* 1002A0 */
1903 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1904 tempchipid = 0x1002a1;
1906 } else if (tempchipid == 0x1002b0) {
1907 if (rfrevid == 3) { /* 1002B0 */
1908 } else if (rfrevid == 4) { /* 1002B1 */
1909 tempchipid = 0x1002b1;
1910 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1911 tempchipid = 0x1002b2;
1916 chipid = tempchipid;
1922 int wilc_wlan_init(wilc_wlan_inp_t *inp)
1927 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1929 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1934 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
1936 * host interface init
1938 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1939 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1944 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1946 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1950 if (!hif_spi.hif_init(inp, wilc_debug)) {
1955 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1964 * mac interface init
1966 if (!wilc_wlan_cfg_init(wilc_debug)) {
1973 * alloc tx, rx buffer
1975 if (g_wlan.tx_buffer == NULL)
1976 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
1977 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
1979 if (g_wlan.tx_buffer == NULL) {
1982 PRINT_ER("Can't allocate Tx Buffer");
1986 /* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
1987 #if defined (MEMORY_STATIC)
1988 if (g_wlan.rx_buffer == NULL)
1989 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
1990 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
1991 if (g_wlan.rx_buffer == NULL) {
1994 PRINT_ER("Can't allocate Rx Buffer");
2004 #ifdef TCP_ACK_FILTER
2005 Init_TCP_tracking();
2012 #ifdef MEMORY_STATIC
2013 kfree(g_wlan.rx_buffer);
2014 g_wlan.rx_buffer = NULL;
2016 kfree(g_wlan.tx_buffer);
2017 g_wlan.tx_buffer = NULL;
2023 u16 Set_machw_change_vir_if(bool bValue)
2028 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
2029 mutex_lock(&g_linux_wlan->hif_cs);
2030 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, ®);
2032 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2039 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2042 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2044 mutex_unlock(&g_linux_wlan->hif_cs);