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_wlan.h"
13 /********************************************
17 ********************************************/
18 extern wilc_hif_func_t hif_sdio;
19 extern wilc_hif_func_t hif_spi;
20 extern wilc_cfg_func_t mac_cfg;
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_os_func_t os_func;
34 wilc_wlan_io_func_t io_func;
37 * host interface functions
39 wilc_hif_func_t hif_func;
42 * configuration interface functions
44 wilc_cfg_func_t cif_func;
46 wilc_cfg_frame_t cfg_frame;
68 unsigned long txq_spinlock_flags;
70 struct txq_entry_t *txq_head;
71 struct txq_entry_t *txq_tail;
78 struct rxq_entry_t *rxq_head;
79 struct rxq_entry_t *rxq_tail;
86 static wilc_wlan_dev_t g_wlan;
88 static inline void chip_allow_sleep(void);
89 static inline void chip_wakeup(void);
90 /********************************************
94 ********************************************/
96 static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
98 static void wilc_debug(u32 flag, char *fmt, ...)
103 if (flag & dbgflag) {
105 vsprintf(buf, fmt, args);
112 static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
114 /*acquire_bus() and release_bus() are made static inline functions*/
115 /*as a temporary workaround to fix a problem of receiving*/
116 /*unknown interrupt from FW*/
117 static inline void acquire_bus(BUS_ACQUIRE_T acquire)
120 mutex_lock(&g_linux_wlan->hif_cs);
121 #ifndef WILC_OPTIMIZE_SLEEP_INT
122 if (genuChipPSstate != CHIP_WAKEDUP)
125 if (acquire == ACQUIRE_AND_WAKEUP)
130 static inline void release_bus(BUS_RELEASE_T release)
132 #ifdef WILC_OPTIMIZE_SLEEP_INT
133 if (release == RELEASE_ALLOW_SLEEP)
136 mutex_unlock(&g_linux_wlan->hif_cs);
138 /********************************************
142 ********************************************/
144 static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
147 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
148 /* unsigned long flags; */
149 if (tqe == p->txq_head) {
151 p->txq_head = tqe->next;
153 p->txq_head->prev = NULL;
156 } else if (tqe == p->txq_tail) {
157 p->txq_tail = (tqe->prev);
159 p->txq_tail->next = NULL;
161 tqe->prev->next = tqe->next;
162 tqe->next->prev = tqe->prev;
168 static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
170 struct txq_entry_t *tqe;
171 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
174 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
177 p->txq_head = tqe->next;
179 p->txq_head->prev = NULL;
189 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
193 static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
195 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
197 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
199 if (p->txq_head == NULL) {
206 tqe->prev = p->txq_tail;
207 p->txq_tail->next = tqe;
211 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
213 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
218 PRINT_D(TX_DBG, "Wake the txq_handling\n");
220 up(&g_linux_wlan->txq_event);
223 static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
225 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
227 if (p->os_func.os_wait(&g_linux_wlan->txq_add_to_head_cs,
231 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
233 if (p->txq_head == NULL) {
239 tqe->next = p->txq_head;
241 p->txq_head->prev = tqe;
245 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
247 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
248 up(&g_linux_wlan->txq_add_to_head_cs);
254 up(&g_linux_wlan->txq_event);
255 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
261 u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
263 #ifdef TCP_ACK_FILTER
264 struct Ack_session_info;
265 struct Ack_session_info {
276 struct txq_entry_t *txqe;
277 } Pending_Acks_info_t /*Ack_info_t*/;
282 struct Ack_session_info *Free_head;
283 struct Ack_session_info *Alloc_head;
285 #define TCP_FIN_MASK (1 << 0)
286 #define TCP_SYN_MASK (1 << 1)
287 #define TCP_Ack_MASK (1 << 4)
288 #define NOT_TCP_ACK (-1)
290 #define MAX_TCP_SESSION 25
291 #define MAX_PENDING_ACKS 256
292 struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
293 Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
295 u32 PendingAcks_arrBase;
296 u32 Opened_TCP_session;
301 static inline int Init_TCP_tracking(void)
307 static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
309 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
310 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
311 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
312 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
313 Opened_TCP_session++;
315 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
319 static inline int Update_TCP_track_session(u32 index, u32 Ack)
322 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
323 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
328 static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
330 Statisitcs_totalAcks++;
331 if (Pending_Acks < MAX_PENDING_ACKS) {
332 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
333 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
334 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
335 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
343 static inline int remove_TCP_related(void)
345 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
348 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
350 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
354 static inline int tcp_process(struct txq_entry_t *tqe)
358 u8 *buffer = tqe->buffer;
359 unsigned short h_proto;
361 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
364 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
366 eth_hdr_ptr = &buffer[0];
367 h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
368 if (h_proto == 0x0800) { /* IP */
372 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
373 protocol = ip_hdr_ptr[9];
376 if (protocol == 0x06) {
378 u32 IHL, Total_Length, Data_offset;
380 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
381 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
382 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
383 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
384 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*/
387 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]);
389 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]);
392 for (i = 0; i < Opened_TCP_session; i++) {
393 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
394 Update_TCP_track_session(i, Ack_no);
398 if (i == Opened_TCP_session) {
399 add_TCP_track_session(0, 0, seq_no);
401 add_TCP_Pending_Ack(Ack_no, i, tqe);
412 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
417 static int wilc_wlan_txq_filter_dup_tcp_ack(void)
422 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
424 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, p->txq_spinlock_flags);
425 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
426 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
427 struct txq_entry_t *tqe;
429 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
430 tqe = Pending_Acks_info[i].txqe;
432 wilc_wlan_txq_remove(tqe);
433 Statisitcs_DroppedAcks++;
434 tqe->status = 1; /* mark the packet send */
435 if (tqe->tx_complete_func)
436 tqe->tx_complete_func(tqe->priv, tqe->status);
443 Opened_TCP_session = 0;
445 if (PendingAcks_arrBase == 0)
446 PendingAcks_arrBase = MAX_TCP_SESSION;
448 PendingAcks_arrBase = 0;
451 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock,
452 p->txq_spinlock_flags);
454 while (Dropped > 0) {
455 /*consume the semaphore count of the removed packet*/
456 p->os_func.os_wait(&g_linux_wlan->txq_event, 1);
464 bool EnableTCPAckFilter = false;
466 void Enable_TCP_ACK_Filter(bool value)
468 EnableTCPAckFilter = value;
471 bool is_TCP_ACK_Filter_Enabled(void)
473 return EnableTCPAckFilter;
476 static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
478 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
479 struct txq_entry_t *tqe;
481 PRINT_D(TX_DBG, "Adding config packet ...\n");
483 PRINT_D(TX_DBG, "Return due to clear function\n");
484 up(&g_linux_wlan->cfg_event);
488 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
490 PRINT_ER("Failed to allocate memory\n");
494 tqe->type = WILC_CFG_PKT;
495 tqe->buffer = buffer;
496 tqe->buffer_size = buffer_size;
497 tqe->tx_complete_func = NULL;
499 #ifdef TCP_ACK_FILTER
500 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
503 * Configuration packet always at the front
505 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
507 if (wilc_wlan_txq_add_to_head(tqe))
512 static int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
514 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
515 struct txq_entry_t *tqe;
520 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
524 tqe->type = WILC_NET_PKT;
525 tqe->buffer = buffer;
526 tqe->buffer_size = buffer_size;
527 tqe->tx_complete_func = func;
530 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
531 #ifdef TCP_ACK_FILTER
532 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
533 if (is_TCP_ACK_Filter_Enabled())
536 wilc_wlan_txq_add_to_tail(tqe);
537 /*return number of itemes in the queue*/
538 return p->txq_entries;
541 int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
544 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
545 struct txq_entry_t *tqe;
550 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
554 tqe->type = WILC_MGMT_PKT;
555 tqe->buffer = buffer;
556 tqe->buffer_size = buffer_size;
557 tqe->tx_complete_func = func;
559 #ifdef TCP_ACK_FILTER
560 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
562 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
563 wilc_wlan_txq_add_to_tail(tqe);
567 static struct txq_entry_t *wilc_wlan_txq_get_first(void)
569 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
570 struct txq_entry_t *tqe;
573 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
577 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
583 static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
586 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
589 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
595 static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
597 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
602 mutex_lock(&g_linux_wlan->rxq_cs);
603 if (p->rxq_head == NULL) {
604 PRINT_D(RX_DBG, "Add to Queue head\n");
609 PRINT_D(RX_DBG, "Add to Queue tail\n");
610 p->rxq_tail->next = rqe;
615 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
616 mutex_unlock(&g_linux_wlan->rxq_cs);
617 return p->rxq_entries;
620 static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
622 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
624 PRINT_D(RX_DBG, "Getting rxQ element\n");
626 struct rxq_entry_t *rqe;
628 mutex_lock(&g_linux_wlan->rxq_cs);
630 p->rxq_head = p->rxq_head->next;
632 PRINT_D(RX_DBG, "RXQ entries decreased\n");
633 mutex_unlock(&g_linux_wlan->rxq_cs);
636 PRINT_D(RX_DBG, "Nothing to get from Q\n");
641 /********************************************
643 * Power Save handle functions
645 ********************************************/
649 #ifdef WILC_OPTIMIZE_SLEEP_INT
651 static inline void chip_allow_sleep(void)
656 g_wlan.hif_func.hif_read_reg(0xf0, ®);
658 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
661 static inline void chip_wakeup(void)
663 u32 reg, clk_status_reg, trials = 0;
666 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
668 g_wlan.hif_func.hif_read_reg(1, ®);
670 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
673 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
676 /* Wait for the chip to stabilize*/
677 usleep_range(2 * 1000, 2 * 1000);
678 /* Make sure chip is awake. This is an extra step that can be removed */
679 /* later to avoid the bus access overhead */
680 if ((wilc_get_chipid(true) == 0)) {
681 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
683 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
685 } while (wilc_get_chipid(true) == 0);
686 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
687 g_wlan.hif_func.hif_read_reg(0xf0, ®);
690 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
692 /* Check the clock status */
693 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
695 /* in case of clocks off, wait 2ms, and check it again. */
696 /* if still off, wait for another 2ms, for a total wait of 6ms. */
697 /* If still off, redo the wake up sequence */
698 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
699 /* Wait for the chip to stabilize*/
700 usleep_range(2 * 1000, 2 * 1000);
702 /* Make sure chip is awake. This is an extra step that can be removed */
703 /* later to avoid the bus access overhead */
704 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
706 if ((clk_status_reg & 0x1) == 0) {
707 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
710 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
711 if ((clk_status_reg & 0x1) == 0) {
713 g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
715 } while ((clk_status_reg & 0x1) == 0);
719 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
720 g_wlan.hif_func.hif_read_reg(0x1C0C, ®);
722 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
724 if (wilc_get_chipid(false) >= 0x1002b0) {
725 /* Enable PALDO back right after wakeup */
728 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
730 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
732 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
734 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
737 genuChipPSstate = CHIP_WAKEDUP;
740 static inline void chip_wakeup(void)
745 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
746 g_wlan.hif_func.hif_read_reg(1, ®);
747 /* Make sure bit 1 is 0 before we start. */
748 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
750 g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
752 g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
753 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
754 /* Make sure bit 0 is 0 before we start. */
755 g_wlan.hif_func.hif_read_reg(0xf0, ®);
756 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
758 g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
760 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
764 /* Wait for the chip to stabilize*/
767 /* Make sure chip is awake. This is an extra step that can be removed */
768 /* later to avoid the bus access overhead */
769 if ((wilc_get_chipid(true) == 0)) {
770 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
772 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
774 } while (wilc_get_chipid(true) == 0);
776 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
777 g_wlan.hif_func.hif_read_reg(0x1C0C, ®);
779 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
781 if (wilc_get_chipid(false) >= 0x1002b0) {
782 /* Enable PALDO back right after wakeup */
785 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
787 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
789 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
791 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
794 genuChipPSstate = CHIP_WAKEDUP;
797 void chip_sleep_manually(u32 u32SleepTime)
799 if (genuChipPSstate != CHIP_WAKEDUP) {
800 /* chip is already sleeping. Do nothing */
803 acquire_bus(ACQUIRE_ONLY);
805 #ifdef WILC_OPTIMIZE_SLEEP_INT
809 /* Trigger the manual sleep interrupt */
810 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
812 genuChipPSstate = CHIP_SLEEPING_MANUAL;
813 release_bus(RELEASE_ONLY);
818 /********************************************
820 * Tx, Rx queue handle functions
822 ********************************************/
823 static int wilc_wlan_handle_txq(u32 *pu32TxqCount)
825 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
829 u8 *txb = p->tx_buffer;
832 struct txq_entry_t *tqe;
836 u32 vmm_table[WILC_VMM_TBL_SIZE];
843 p->os_func.os_wait(&g_linux_wlan->txq_add_to_head_cs,
845 #ifdef TCP_ACK_FILTER
846 wilc_wlan_txq_filter_dup_tcp_ack();
851 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
852 tqe = wilc_wlan_txq_get_first();
856 /* if ((tqe != NULL) && (i < (8)) && */
857 /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
858 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
860 if (tqe->type == WILC_CFG_PKT) {
861 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
863 else if (tqe->type == WILC_NET_PKT) {
864 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
867 vmm_sz = HOST_HDR_OFFSET;
869 vmm_sz += tqe->buffer_size;
870 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
871 if (vmm_sz & 0x3) { /* has to be word aligned */
872 vmm_sz = (vmm_sz + 4) & ~0x3;
874 if ((sum + vmm_sz) > LINUX_TX_SIZE) {
877 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
878 vmm_table[i] = vmm_sz / 4; /* table take the word size */
879 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
881 if (tqe->type == WILC_CFG_PKT) {
882 vmm_table[i] |= (1 << 10);
883 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
886 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
891 PRINT_D(TX_DBG, "sum = %d\n", sum);
892 tqe = wilc_wlan_txq_get_next(tqe);
898 if (i == 0) { /* nothing in the queue */
899 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
902 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
903 vmm_table[i] = 0x0; /* mark the last element to 0 */
905 acquire_bus(ACQUIRE_AND_WAKEUP);
909 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®);
911 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
915 if ((reg & 0x1) == 0) {
919 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
925 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
926 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
930 * wait for vmm table is ready
932 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
933 release_bus(RELEASE_ALLOW_SLEEP);
934 usleep_range(3000, 3000);
935 acquire_bus(ACQUIRE_AND_WAKEUP);
949 ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
951 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
959 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
961 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
966 * wait for confirm...
970 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, ®);
972 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
975 if ((reg >> 2) & 0x1) {
979 entries = ((reg >> 3) & 0x3f);
980 /* entries = ((reg>>3)&0x2f); */
983 release_bus(RELEASE_ALLOW_SLEEP);
984 usleep_range(3000, 3000);
985 acquire_bus(ACQUIRE_AND_WAKEUP);
986 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
990 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
999 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]);
1001 /* undo the transaction. */
1002 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®);
1004 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1008 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1010 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1023 ret = WILC_TX_ERR_NO_BUF;
1027 /* since copying data into txb takes some time, then
1028 * allow the bus lock to be released let the RX task go. */
1029 release_bus(RELEASE_ALLOW_SLEEP);
1032 * Copy data to the TX buffer
1037 tqe = wilc_wlan_txq_remove_from_head();
1038 if (tqe != NULL && (vmm_table[i] != 0)) {
1039 u32 header, buffer_offset;
1042 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1044 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1046 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
1047 if (tqe->type == WILC_MGMT_PKT)
1048 header |= (1 << 30);
1050 header &= ~(1 << 30);
1053 header = BYTE_SWAP(header);
1055 memcpy(&txb[offset], &header, 4);
1056 if (tqe->type == WILC_CFG_PKT) {
1057 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1059 else if (tqe->type == WILC_NET_PKT) {
1060 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
1062 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1063 /* copy the bssid at the sart of the buffer */
1064 memcpy(&txb[offset + 4], pBSSID, 6);
1067 buffer_offset = HOST_HDR_OFFSET;
1070 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1073 tqe->status = 1; /* mark the packet send */
1074 if (tqe->tx_complete_func)
1075 tqe->tx_complete_func(tqe->priv, tqe->status);
1076 #ifdef TCP_ACK_FILTER
1077 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
1078 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1085 } while (--entries);
1090 acquire_bus(ACQUIRE_AND_WAKEUP);
1092 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1094 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1101 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1103 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1109 release_bus(RELEASE_ALLOW_SLEEP);
1113 up(&g_linux_wlan->txq_add_to_head_cs);
1116 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1117 /* return tx[]q count */
1118 *pu32TxqCount = p->txq_entries;
1122 static void wilc_wlan_handle_rxq(void)
1124 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1125 int offset = 0, size, has_packet = 0;
1127 struct rxq_entry_t *rqe;
1136 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
1137 up(&g_linux_wlan->cfg_event);
1140 rqe = wilc_wlan_rxq_remove();
1142 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1145 buffer = rqe->buffer;
1146 size = rqe->buffer_size;
1147 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1154 u32 pkt_len, pkt_offset, tp_len;
1157 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1158 memcpy(&header, &buffer[offset], 4);
1160 header = BYTE_SWAP(header);
1162 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1166 is_cfg_packet = (header >> 31) & 0x1;
1167 pkt_offset = (header >> 22) & 0x1ff;
1168 tp_len = (header >> 11) & 0x7ff;
1169 pkt_len = header & 0x7ff;
1171 if (pkt_len == 0 || tp_len == 0) {
1172 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1176 /*bug 3887: [AP] Allow Management frames to be passed to the host*/
1177 #define IS_MANAGMEMENT 0x100
1178 #define IS_MANAGMEMENT_CALLBACK 0x080
1179 #define IS_MGMT_STATUS_SUCCES 0x040
1182 if (pkt_offset & IS_MANAGMEMENT) {
1183 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1184 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1186 WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
1192 if (!is_cfg_packet) {
1194 frmw_to_linux(&buffer[offset],
1204 p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
1205 if (rsp.type == WILC_CFG_RSP) {
1207 * wake up the waiting task...
1209 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1210 if (p->cfg_seq_no == rsp.seq_no) {
1211 up(&g_linux_wlan->cfg_event);
1213 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1215 * Call back to indicate status...
1217 linux_wlan_mac_indicate(WILC_MAC_INDICATE_STATUS);
1219 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
1220 linux_wlan_mac_indicate(WILC_MAC_INDICATE_SCAN);
1230 #ifndef MEMORY_STATIC
1236 linux_wlan_rx_complete();
1241 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
1244 /********************************************
1248 ********************************************/
1249 static void wilc_unknown_isr_ext(void)
1251 g_wlan.hif_func.hif_clear_int_ext(0);
1253 static void wilc_pllupdate_isr_ext(u32 int_stats)
1258 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1260 /* Waiting for PLL */
1261 mdelay(WILC_PLL_TO);
1263 /* poll till read a valid data */
1264 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
1265 PRINT_D(TX_DBG, "PLL update retrying\n");
1270 static void wilc_sleeptimer_isr_ext(u32 int_stats1)
1272 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1273 #ifndef WILC_OPTIMIZE_SLEEP_INT
1274 genuChipPSstate = CHIP_SLEEPING_AUTO;
1278 static void wilc_wlan_handle_isr_ext(u32 int_status)
1280 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1281 #ifdef MEMORY_STATIC
1282 u32 offset = p->rx_buffer_offset;
1288 struct rxq_entry_t *rqe;
1295 size = ((int_status & 0x7fff) << 2);
1297 while (!size && retries < 10) {
1299 /*looping more secure*/
1300 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1301 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1302 p->hif_func.hif_read_size(&size);
1303 size = ((size & 0x7fff) << 2);
1309 #ifdef MEMORY_STATIC
1310 if (LINUX_RX_SIZE - offset < size)
1314 buffer = &p->rx_buffer[offset];
1316 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1321 buffer = kmalloc(size, GFP_KERNEL);
1322 if (buffer == NULL) {
1323 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
1324 usleep_range(100 * 1000, 100 * 1000);
1330 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1332 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1338 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1341 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1348 #ifdef MEMORY_STATIC
1350 p->rx_buffer_offset = offset;
1355 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
1357 rqe->buffer = buffer;
1358 rqe->buffer_size = size;
1359 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1360 wilc_wlan_rxq_add(rqe);
1363 #ifndef MEMORY_STATIC
1368 wilc_wlan_handle_rxq();
1371 void wilc_handle_isr(void)
1375 acquire_bus(ACQUIRE_AND_WAKEUP);
1376 g_wlan.hif_func.hif_read_int(&int_status);
1378 if (int_status & PLL_INT_EXT) {
1379 wilc_pllupdate_isr_ext(int_status);
1381 if (int_status & DATA_INT_EXT) {
1382 wilc_wlan_handle_isr_ext(int_status);
1383 #ifndef WILC_OPTIMIZE_SLEEP_INT
1384 /* Chip is up and talking*/
1385 genuChipPSstate = CHIP_WAKEDUP;
1388 if (int_status & SLEEP_INT_EXT) {
1389 wilc_sleeptimer_isr_ext(int_status);
1392 if (!(int_status & (ALL_INT_EXT))) {
1394 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1396 wilc_unknown_isr_ext();
1398 release_bus(RELEASE_ALLOW_SLEEP);
1401 /********************************************
1405 ********************************************/
1406 static int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
1408 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1410 u32 addr, size, size2, blksz;
1414 blksz = (1ul << 12);
1415 /* Allocate a DMA coherent buffer. */
1417 dma_buffer = kmalloc(blksz, GFP_KERNEL);
1418 if (dma_buffer == NULL) {
1421 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1425 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1431 memcpy(&addr, &buffer[offset], 4);
1432 memcpy(&size, &buffer[offset + 4], 4);
1434 addr = BYTE_SWAP(addr);
1435 size = BYTE_SWAP(size);
1437 acquire_bus(ACQUIRE_ONLY);
1439 while (((int)size) && (offset < buffer_size)) {
1444 /* Copy firmware into a DMA coherent buffer */
1445 memcpy(dma_buffer, &buffer[offset], size2);
1446 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1454 release_bus(RELEASE_ONLY);
1459 PRINT_ER("Can't download firmware IO error\n ");
1462 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1463 } while (offset < buffer_size);
1471 return (ret < 0) ? ret : 0;
1474 /********************************************
1478 ********************************************/
1479 static int wilc_wlan_start(void)
1481 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1487 * Set the host interface
1489 if (p->io_func.io_type == HIF_SDIO) {
1491 reg |= (1 << 3); /* bug 4456 and 4557 */
1492 } else if (p->io_func.io_type == HIF_SPI) {
1495 acquire_bus(ACQUIRE_ONLY);
1496 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1498 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1499 release_bus(RELEASE_ONLY);
1505 #ifdef WILC_SDIO_IRQ_GPIO
1506 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1509 #ifdef WILC_DISABLE_PMU
1511 reg |= WILC_HAVE_USE_PMU;
1514 #ifdef WILC_SLEEP_CLK_SRC_XO
1515 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1516 #elif defined WILC_SLEEP_CLK_SRC_RTC
1517 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1520 #ifdef WILC_EXT_PA_INV_TX_RX
1521 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1524 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1527 /*Set oscillator frequency*/
1529 reg |= WILC_HAVE_XTAL_24;
1532 /*Enable/Disable GPIO configuration for FW logs*/
1533 #ifdef DISABLE_WILC_UART
1534 reg |= WILC_HAVE_DISABLE_WILC_UART;
1537 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1539 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1540 release_bus(RELEASE_ONLY);
1549 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1551 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1553 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1554 release_bus(RELEASE_ONLY);
1565 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1566 if ((reg & (1ul << 10)) == (1ul << 10)) {
1567 reg &= ~(1ul << 10);
1568 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1569 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1573 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1574 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1575 release_bus(RELEASE_ONLY);
1577 return (ret < 0) ? ret : 0;
1580 void wilc_wlan_global_reset(void)
1583 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1585 acquire_bus(ACQUIRE_AND_WAKEUP);
1586 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1587 release_bus(RELEASE_ONLY);
1589 static int wilc_wlan_stop(void)
1591 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1596 * TODO: stop the firmware, need a re-download
1598 acquire_bus(ACQUIRE_AND_WAKEUP);
1600 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1602 PRINT_ER("Error while reading reg\n");
1603 release_bus(RELEASE_ALLOW_SLEEP);
1610 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1612 PRINT_ER("Error while writing reg\n");
1613 release_bus(RELEASE_ALLOW_SLEEP);
1620 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1622 PRINT_ER("Error while reading reg\n");
1623 release_bus(RELEASE_ALLOW_SLEEP);
1626 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1627 /*Workaround to ensure that the chip is actually reset*/
1628 if ((reg & (1 << 10))) {
1629 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1631 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1634 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1635 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1637 PRINT_ER("Error while reading reg\n");
1638 release_bus(RELEASE_ALLOW_SLEEP);
1641 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1646 reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
1648 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1649 reg = ~(1 << 10); /**/
1651 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg); /**/
1652 /******************************************************************************/
1654 release_bus(RELEASE_ALLOW_SLEEP);
1659 static void wilc_wlan_cleanup(void)
1661 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1662 struct txq_entry_t *tqe;
1663 struct rxq_entry_t *rqe;
1669 tqe = wilc_wlan_txq_remove_from_head();
1672 if (tqe->tx_complete_func)
1673 tqe->tx_complete_func(tqe->priv, 0);
1678 rqe = wilc_wlan_rxq_remove();
1681 #ifndef MEMORY_STATIC
1691 #ifdef MEMORY_STATIC
1692 kfree(p->rx_buffer);
1693 p->rx_buffer = NULL;
1695 kfree(p->tx_buffer);
1697 acquire_bus(ACQUIRE_AND_WAKEUP);
1700 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, ®);
1702 PRINT_ER("Error while reading reg\n");
1703 release_bus(RELEASE_ALLOW_SLEEP);
1705 PRINT_ER("Writing ABORT reg\n");
1706 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1708 PRINT_ER("Error while writing reg\n");
1709 release_bus(RELEASE_ALLOW_SLEEP);
1711 release_bus(RELEASE_ALLOW_SLEEP);
1715 p->hif_func.hif_deinit(NULL);
1719 static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
1721 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1722 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1723 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1724 int seq_no = p->cfg_seq_no % 256;
1725 int driver_handler = (u32)drvHandler;
1731 if (type == WILC_CFG_SET) { /* Set */
1732 cfg->wid_header[0] = 'W';
1733 } else { /* Query */
1734 cfg->wid_header[0] = 'Q';
1736 cfg->wid_header[1] = seq_no; /* sequence number */
1737 cfg->wid_header[2] = (u8)total_len;
1738 cfg->wid_header[3] = (u8)(total_len >> 8);
1739 cfg->wid_header[4] = (u8)driver_handler;
1740 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1741 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1742 cfg->wid_header[7] = (u8)(driver_handler >> 24);
1743 p->cfg_seq_no = seq_no;
1749 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1755 static int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size, int commit, u32 drvHandler)
1757 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1762 if (p->cfg_frame_in_use)
1766 p->cfg_frame_offset = 0;
1768 offset = p->cfg_frame_offset;
1769 ret_size = p->cif_func.cfg_wid_set(p->cfg_frame.frame, offset, (u16)wid, buffer, buffer_size);
1771 p->cfg_frame_offset = offset;
1774 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1775 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1776 p->cfg_frame_in_use = 1;
1778 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
1781 if (p->os_func.os_wait(&g_linux_wlan->cfg_event,
1782 CFG_PKTS_TIMEOUT)) {
1783 PRINT_D(TX_DBG, "Set Timed Out\n");
1786 p->cfg_frame_in_use = 0;
1787 p->cfg_frame_offset = 0;
1794 static int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
1796 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1801 if (p->cfg_frame_in_use)
1805 p->cfg_frame_offset = 0;
1807 offset = p->cfg_frame_offset;
1808 ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (u16)wid);
1810 p->cfg_frame_offset = offset;
1813 p->cfg_frame_in_use = 1;
1815 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
1819 if (p->os_func.os_wait(&g_linux_wlan->cfg_event,
1820 CFG_PKTS_TIMEOUT)) {
1821 PRINT_D(TX_DBG, "Get Timed Out\n");
1824 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1825 p->cfg_frame_in_use = 0;
1826 p->cfg_frame_offset = 0;
1833 static int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
1835 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
1838 ret = p->cif_func.cfg_wid_get_val((u16)wid, buffer, buffer_size);
1843 void wilc_bus_set_max_speed(void)
1846 /* Increase bus speed to max possible. */
1847 g_wlan.hif_func.hif_set_max_bus_speed();
1850 void wilc_bus_set_default_speed(void)
1853 /* Restore bus speed to default. */
1854 g_wlan.hif_func.hif_set_default_bus_speed();
1861 acquire_bus(ACQUIRE_ONLY);
1863 chipid = wilc_get_chipid(true);
1867 if ((chipid & 0xfff) != 0xa0) {
1869 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1870 * or SD_DAT3 [SPI platform] to ?1?
1872 /* Set cortus reset register to register control. */
1873 ret = g_wlan.hif_func.hif_read_reg(0x1118, ®);
1875 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1879 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1881 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1885 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1886 * (Cortus map) or C0000 (AHB map).
1888 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1890 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1895 release_bus(RELEASE_ONLY);
1901 u32 wilc_get_chipid(u8 update)
1904 /* SDIO can't read into global variables */
1905 /* Use this variable as a temp, then copy to the global */
1909 if (chipid == 0 || update != 0) {
1910 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1911 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1912 if (!ISWILC1000(tempchipid)) {
1916 if (tempchipid == 0x1002a0) {
1917 if (rfrevid == 0x1) { /* 1002A0 */
1918 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1919 tempchipid = 0x1002a1;
1921 } else if (tempchipid == 0x1002b0) {
1922 if (rfrevid == 3) { /* 1002B0 */
1923 } else if (rfrevid == 4) { /* 1002B1 */
1924 tempchipid = 0x1002b1;
1925 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1926 tempchipid = 0x1002b2;
1931 chipid = tempchipid;
1937 #ifdef COMPLEMENT_BOOT
1938 u8 core_11b_ready(void)
1942 acquire_bus(ACQUIRE_ONLY);
1943 g_wlan.hif_func.hif_write_reg(0x16082c, 1);
1944 g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
1945 g_wlan.hif_func.hif_read_reg(0x161600, ®_val);
1946 release_bus(RELEASE_ONLY);
1948 if (reg_val == 0x90)
1955 int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
1960 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1962 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1967 memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
1968 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
1969 g_wlan.txq_lock = inp->os_context.txq_critical_section;
1971 * host interface init
1973 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1974 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1979 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1981 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1985 if (!hif_spi.hif_init(inp, wilc_debug)) {
1990 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1999 * mac interface init
2001 if (!mac_cfg.cfg_init(wilc_debug)) {
2006 memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
2010 * alloc tx, rx buffer
2012 if (g_wlan.tx_buffer == NULL)
2013 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
2014 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
2016 if (g_wlan.tx_buffer == NULL) {
2019 PRINT_ER("Can't allocate Tx Buffer");
2023 /* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2024 #if defined (MEMORY_STATIC)
2025 if (g_wlan.rx_buffer == NULL)
2026 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
2027 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
2028 if (g_wlan.rx_buffer == NULL) {
2031 PRINT_ER("Can't allocate Rx Buffer");
2039 oup->wlan_firmware_download = wilc_wlan_firmware_download;
2040 oup->wlan_start = wilc_wlan_start;
2041 oup->wlan_stop = wilc_wlan_stop;
2042 oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
2043 oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
2044 oup->wlan_handle_rx_isr = wilc_handle_isr;
2045 oup->wlan_cleanup = wilc_wlan_cleanup;
2046 oup->wlan_cfg_set = wilc_wlan_cfg_set;
2047 oup->wlan_cfg_get = wilc_wlan_cfg_get;
2048 oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
2050 oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
2057 #ifdef TCP_ACK_FILTER
2058 Init_TCP_tracking();
2065 #ifdef MEMORY_STATIC
2066 kfree(g_wlan.rx_buffer);
2067 g_wlan.rx_buffer = NULL;
2069 kfree(g_wlan.tx_buffer);
2070 g_wlan.tx_buffer = NULL;
2076 u16 Set_machw_change_vir_if(bool bValue)
2081 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
2082 mutex_lock(&g_linux_wlan->hif_cs);
2083 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, ®);
2085 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2093 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2096 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2098 mutex_unlock(&g_linux_wlan->hif_cs);