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 u32 wilc_get_chipid(u8 update);
22 u16 Set_machw_change_vir_if(bool bValue);
30 * input interface functions
32 wilc_wlan_io_func_t io_func;
35 * host interface functions
37 wilc_hif_func_t hif_func;
40 * configuration interface functions
43 wilc_cfg_frame_t cfg_frame;
64 unsigned long txq_spinlock_flags;
66 struct txq_entry_t *txq_head;
67 struct txq_entry_t *txq_tail;
74 struct rxq_entry_t *rxq_head;
75 struct rxq_entry_t *rxq_tail;
82 static wilc_wlan_dev_t g_wlan;
84 static inline void chip_allow_sleep(void);
85 static inline void chip_wakeup(void);
86 /********************************************
90 ********************************************/
92 static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
94 static void wilc_debug(u32 flag, char *fmt, ...)
101 vsprintf(buf, fmt, args);
108 static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
110 /*acquire_bus() and release_bus() are made static inline functions*/
111 /*as a temporary workaround to fix a problem of receiving*/
112 /*unknown interrupt from FW*/
113 static inline void acquire_bus(BUS_ACQUIRE_T acquire)
116 mutex_lock(&g_linux_wlan->hif_cs);
117 #ifndef WILC_OPTIMIZE_SLEEP_INT
118 if (genuChipPSstate != CHIP_WAKEDUP)
121 if (acquire == ACQUIRE_AND_WAKEUP)
126 static inline void release_bus(BUS_RELEASE_T release)
128 #ifdef WILC_OPTIMIZE_SLEEP_INT
129 if (release == RELEASE_ALLOW_SLEEP)
132 mutex_unlock(&g_linux_wlan->hif_cs);
134 /********************************************
138 ********************************************/
140 static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
143 wilc_wlan_dev_t *p = &g_wlan;
144 if (tqe == p->txq_head) {
146 p->txq_head = tqe->next;
148 p->txq_head->prev = NULL;
151 } else if (tqe == p->txq_tail) {
152 p->txq_tail = (tqe->prev);
154 p->txq_tail->next = NULL;
156 tqe->prev->next = tqe->next;
157 tqe->next->prev = tqe->prev;
163 static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
165 struct txq_entry_t *tqe;
166 wilc_wlan_dev_t *p = &g_wlan;
169 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
172 p->txq_head = tqe->next;
174 p->txq_head->prev = NULL;
184 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
188 static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
190 wilc_wlan_dev_t *p = &g_wlan;
192 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
194 if (p->txq_head == NULL) {
201 tqe->prev = p->txq_tail;
202 p->txq_tail->next = tqe;
206 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
208 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
213 PRINT_D(TX_DBG, "Wake the txq_handling\n");
215 up(&g_linux_wlan->txq_event);
218 static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
220 wilc_wlan_dev_t *p = &g_wlan;
222 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
226 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
228 if (p->txq_head == NULL) {
234 tqe->next = p->txq_head;
236 p->txq_head->prev = tqe;
240 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
242 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
243 up(&g_linux_wlan->txq_add_to_head_cs);
249 up(&g_linux_wlan->txq_event);
250 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
256 u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
258 #ifdef TCP_ACK_FILTER
259 struct Ack_session_info;
260 struct Ack_session_info {
271 struct txq_entry_t *txqe;
272 } Pending_Acks_info_t /*Ack_info_t*/;
277 struct Ack_session_info *Free_head;
278 struct Ack_session_info *Alloc_head;
280 #define NOT_TCP_ACK (-1)
282 #define MAX_TCP_SESSION 25
283 #define MAX_PENDING_ACKS 256
284 struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
285 Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
287 u32 PendingAcks_arrBase;
288 u32 Opened_TCP_session;
293 static inline int Init_TCP_tracking(void)
299 static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
301 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
302 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
303 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
304 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
305 Opened_TCP_session++;
307 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
311 static inline int Update_TCP_track_session(u32 index, u32 Ack)
314 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num)
315 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
319 static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
321 Statisitcs_totalAcks++;
322 if (Pending_Acks < MAX_PENDING_ACKS) {
323 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
324 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
325 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
326 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
334 static inline int remove_TCP_related(void)
336 wilc_wlan_dev_t *p = &g_wlan;
339 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
341 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
345 static inline int tcp_process(struct txq_entry_t *tqe)
349 u8 *buffer = tqe->buffer;
350 unsigned short h_proto;
352 wilc_wlan_dev_t *p = &g_wlan;
355 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
357 eth_hdr_ptr = &buffer[0];
358 h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
359 if (h_proto == 0x0800) { /* IP */
363 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
364 protocol = ip_hdr_ptr[9];
367 if (protocol == 0x06) {
369 u32 IHL, Total_Length, Data_offset;
371 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
372 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
373 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
374 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
375 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*/
378 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]);
380 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]);
383 for (i = 0; i < Opened_TCP_session; i++) {
384 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
385 Update_TCP_track_session(i, Ack_no);
389 if (i == Opened_TCP_session)
390 add_TCP_track_session(0, 0, seq_no);
392 add_TCP_Pending_Ack(Ack_no, i, tqe);
403 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
408 static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
410 perInterface_wlan_t *nic;
414 wilc_wlan_dev_t *p = &g_wlan;
416 nic = netdev_priv(dev);
419 spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags);
420 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
421 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
422 struct txq_entry_t *tqe;
424 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
425 tqe = Pending_Acks_info[i].txqe;
427 wilc_wlan_txq_remove(tqe);
428 Statisitcs_DroppedAcks++;
429 tqe->status = 1; /* mark the packet send */
430 if (tqe->tx_complete_func)
431 tqe->tx_complete_func(tqe->priv, tqe->status);
438 Opened_TCP_session = 0;
440 if (PendingAcks_arrBase == 0)
441 PendingAcks_arrBase = MAX_TCP_SESSION;
443 PendingAcks_arrBase = 0;
446 spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags);
448 while (Dropped > 0) {
449 /*consume the semaphore count of the removed packet*/
450 linux_wlan_lock_timeout(&wilc->txq_event, 1);
458 bool EnableTCPAckFilter = false;
460 void Enable_TCP_ACK_Filter(bool value)
462 EnableTCPAckFilter = value;
465 bool is_TCP_ACK_Filter_Enabled(void)
467 return EnableTCPAckFilter;
470 static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
472 wilc_wlan_dev_t *p = &g_wlan;
473 struct txq_entry_t *tqe;
475 PRINT_D(TX_DBG, "Adding config packet ...\n");
477 PRINT_D(TX_DBG, "Return due to clear function\n");
478 up(&g_linux_wlan->cfg_event);
482 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
484 PRINT_ER("Failed to allocate memory\n");
488 tqe->type = WILC_CFG_PKT;
489 tqe->buffer = buffer;
490 tqe->buffer_size = buffer_size;
491 tqe->tx_complete_func = NULL;
493 #ifdef TCP_ACK_FILTER
494 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
497 * Configuration packet always at the front
499 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
501 if (wilc_wlan_txq_add_to_head(tqe))
506 int wilc_wlan_txq_add_net_pkt(void *priv, u8 *buffer, u32 buffer_size,
507 wilc_tx_complete_func_t func)
509 wilc_wlan_dev_t *p = &g_wlan;
510 struct txq_entry_t *tqe;
515 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
519 tqe->type = WILC_NET_PKT;
520 tqe->buffer = buffer;
521 tqe->buffer_size = buffer_size;
522 tqe->tx_complete_func = func;
525 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
526 #ifdef TCP_ACK_FILTER
527 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
528 if (is_TCP_ACK_Filter_Enabled())
531 wilc_wlan_txq_add_to_tail(tqe);
532 /*return number of itemes in the queue*/
533 return p->txq_entries;
536 int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
539 wilc_wlan_dev_t *p = &g_wlan;
540 struct txq_entry_t *tqe;
545 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
549 tqe->type = WILC_MGMT_PKT;
550 tqe->buffer = buffer;
551 tqe->buffer_size = buffer_size;
552 tqe->tx_complete_func = func;
554 #ifdef TCP_ACK_FILTER
555 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
557 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
558 wilc_wlan_txq_add_to_tail(tqe);
562 static struct txq_entry_t *wilc_wlan_txq_get_first(void)
564 wilc_wlan_dev_t *p = &g_wlan;
565 struct txq_entry_t *tqe;
568 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
572 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
578 static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
581 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
584 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
590 static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
592 wilc_wlan_dev_t *p = &g_wlan;
597 mutex_lock(&g_linux_wlan->rxq_cs);
598 if (p->rxq_head == NULL) {
599 PRINT_D(RX_DBG, "Add to Queue head\n");
604 PRINT_D(RX_DBG, "Add to Queue tail\n");
605 p->rxq_tail->next = rqe;
610 PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
611 mutex_unlock(&g_linux_wlan->rxq_cs);
612 return p->rxq_entries;
615 static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
617 wilc_wlan_dev_t *p = &g_wlan;
619 PRINT_D(RX_DBG, "Getting rxQ element\n");
621 struct rxq_entry_t *rqe;
623 mutex_lock(&wilc->rxq_cs);
625 p->rxq_head = p->rxq_head->next;
627 PRINT_D(RX_DBG, "RXQ entries decreased\n");
628 mutex_unlock(&wilc->rxq_cs);
631 PRINT_D(RX_DBG, "Nothing to get from Q\n");
636 /********************************************
638 * Power Save handle functions
640 ********************************************/
644 #ifdef WILC_OPTIMIZE_SLEEP_INT
646 static inline void chip_allow_sleep(void)
651 g_wlan.hif_func.hif_read_reg(0xf0, ®);
653 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
656 static inline void chip_wakeup(void)
658 u32 reg, clk_status_reg, trials = 0;
661 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
663 g_wlan.hif_func.hif_read_reg(1, ®);
665 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
668 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
671 /* Wait for the chip to stabilize*/
672 usleep_range(2 * 1000, 2 * 1000);
673 /* Make sure chip is awake. This is an extra step that can be removed */
674 /* later to avoid the bus access overhead */
675 if ((wilc_get_chipid(true) == 0))
676 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
678 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
680 } while (wilc_get_chipid(true) == 0);
681 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
682 g_wlan.hif_func.hif_read_reg(0xf0, ®);
685 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
687 /* Check the clock status */
688 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
690 /* in case of clocks off, wait 2ms, and check it again. */
691 /* if still off, wait for another 2ms, for a total wait of 6ms. */
692 /* If still off, redo the wake up sequence */
693 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
694 /* Wait for the chip to stabilize*/
695 usleep_range(2 * 1000, 2 * 1000);
697 /* Make sure chip is awake. This is an extra step that can be removed */
698 /* later to avoid the bus access overhead */
699 g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
701 if ((clk_status_reg & 0x1) == 0)
702 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
705 /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
706 if ((clk_status_reg & 0x1) == 0) {
708 g_wlan.hif_func.hif_write_reg(0xf0, reg &
711 } while ((clk_status_reg & 0x1) == 0);
715 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
716 g_wlan.hif_func.hif_read_reg(0x1C0C, ®);
718 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
720 if (wilc_get_chipid(false) >= 0x1002b0) {
721 /* Enable PALDO back right after wakeup */
724 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
726 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
728 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
730 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
733 genuChipPSstate = CHIP_WAKEDUP;
736 static inline void chip_wakeup(void)
741 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
742 g_wlan.hif_func.hif_read_reg(1, ®);
743 /* Make sure bit 1 is 0 before we start. */
744 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
746 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
748 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
749 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
750 /* Make sure bit 0 is 0 before we start. */
751 g_wlan.hif_func.hif_read_reg(0xf0, ®);
752 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
754 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
756 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
760 /* Wait for the chip to stabilize*/
763 /* Make sure chip is awake. This is an extra step that can be removed */
764 /* later to avoid the bus access overhead */
765 if ((wilc_get_chipid(true) == 0))
766 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
768 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
770 } while (wilc_get_chipid(true) == 0);
772 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
773 g_wlan.hif_func.hif_read_reg(0x1C0C, ®);
775 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
777 if (wilc_get_chipid(false) >= 0x1002b0) {
778 /* Enable PALDO back right after wakeup */
781 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
783 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
785 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
787 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
790 genuChipPSstate = CHIP_WAKEDUP;
793 void chip_sleep_manually(u32 u32SleepTime)
795 if (genuChipPSstate != CHIP_WAKEDUP) {
796 /* chip is already sleeping. Do nothing */
799 acquire_bus(ACQUIRE_ONLY);
801 #ifdef WILC_OPTIMIZE_SLEEP_INT
805 /* Trigger the manual sleep interrupt */
806 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
808 genuChipPSstate = CHIP_SLEEPING_MANUAL;
809 release_bus(RELEASE_ONLY);
814 /********************************************
816 * Tx, Rx queue handle functions
818 ********************************************/
819 int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount)
821 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
825 u8 *txb = p->tx_buffer;
828 struct txq_entry_t *tqe;
832 u32 vmm_table[WILC_VMM_TBL_SIZE];
833 perInterface_wlan_t *nic;
836 nic = netdev_priv(dev);
844 linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs,
846 #ifdef TCP_ACK_FILTER
847 wilc_wlan_txq_filter_dup_tcp_ack(dev);
852 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
853 tqe = wilc_wlan_txq_get_first();
857 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
859 if (tqe->type == WILC_CFG_PKT)
860 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
862 else if (tqe->type == WILC_NET_PKT)
863 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
866 vmm_sz = HOST_HDR_OFFSET;
868 vmm_sz += tqe->buffer_size;
869 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
870 if (vmm_sz & 0x3) { /* has to be word aligned */
871 vmm_sz = (vmm_sz + 4) & ~0x3;
873 if ((sum + vmm_sz) > LINUX_TX_SIZE)
876 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
877 vmm_table[i] = vmm_sz / 4; /* table take the word size */
878 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
880 if (tqe->type == WILC_CFG_PKT) {
881 vmm_table[i] |= BIT(10);
882 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
885 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
890 PRINT_D(TX_DBG, "sum = %d\n", sum);
891 tqe = wilc_wlan_txq_get_next(tqe);
897 if (i == 0) { /* nothing in the queue */
898 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
901 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
902 vmm_table[i] = 0x0; /* mark the last element to 0 */
904 acquire_bus(ACQUIRE_AND_WAKEUP);
908 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®);
910 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
914 if ((reg & 0x1) == 0) {
918 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
924 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
925 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
929 * wait for vmm table is ready
931 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
932 release_bus(RELEASE_ALLOW_SLEEP);
933 usleep_range(3000, 3000);
934 acquire_bus(ACQUIRE_AND_WAKEUP);
947 ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
949 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
957 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
959 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
964 * wait for confirm...
968 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, ®);
970 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
973 if ((reg >> 2) & 0x1) {
977 entries = ((reg >> 3) & 0x3f);
980 release_bus(RELEASE_ALLOW_SLEEP);
981 usleep_range(3000, 3000);
982 acquire_bus(ACQUIRE_AND_WAKEUP);
983 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
987 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
995 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]);
997 /* undo the transaction. */
998 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®);
1000 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1004 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1006 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1019 ret = WILC_TX_ERR_NO_BUF;
1023 /* since copying data into txb takes some time, then
1024 * allow the bus lock to be released let the RX task go. */
1025 release_bus(RELEASE_ALLOW_SLEEP);
1028 * Copy data to the TX buffer
1033 tqe = wilc_wlan_txq_remove_from_head();
1034 if (tqe != NULL && (vmm_table[i] != 0)) {
1035 u32 header, buffer_offset;
1038 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1040 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1042 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
1043 if (tqe->type == WILC_MGMT_PKT)
1049 header = BYTE_SWAP(header);
1051 memcpy(&txb[offset], &header, 4);
1052 if (tqe->type == WILC_CFG_PKT) {
1053 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1055 else if (tqe->type == WILC_NET_PKT) {
1056 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
1058 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1059 /* copy the bssid at the sart of the buffer */
1060 memcpy(&txb[offset + 4], pBSSID, 6);
1063 buffer_offset = HOST_HDR_OFFSET;
1066 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1069 tqe->status = 1; /* mark the packet send */
1070 if (tqe->tx_complete_func)
1071 tqe->tx_complete_func(tqe->priv, tqe->status);
1072 #ifdef TCP_ACK_FILTER
1073 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
1074 Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
1080 } while (--entries);
1085 acquire_bus(ACQUIRE_AND_WAKEUP);
1087 ret = p->hif_func.hif_clear_int_ext(ENABLE_TX_VMM);
1089 wilc_debug(N_ERR, "[wilc txq]: fail can't start tx VMM ...\n");
1096 ret = p->hif_func.hif_block_tx_ext(0, txb, offset);
1098 wilc_debug(N_ERR, "[wilc txq]: fail can't block tx ext...\n");
1104 release_bus(RELEASE_ALLOW_SLEEP);
1108 up(&wilc->txq_add_to_head_cs);
1111 PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
1112 /* return tx[]q count */
1113 *pu32TxqCount = p->txq_entries;
1117 static void wilc_wlan_handle_rxq(struct wilc *wilc)
1119 wilc_wlan_dev_t *p = &g_wlan;
1120 int offset = 0, size, has_packet = 0;
1122 struct rxq_entry_t *rqe;
1131 PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
1132 up(&wilc->cfg_event);
1135 rqe = wilc_wlan_rxq_remove(wilc);
1137 PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
1140 buffer = rqe->buffer;
1141 size = rqe->buffer_size;
1142 PRINT_D(RX_DBG, "rxQ entery Size = %d - Address = %p\n", size, buffer);
1149 u32 pkt_len, pkt_offset, tp_len;
1152 PRINT_D(RX_DBG, "In the 2nd do-while\n");
1153 memcpy(&header, &buffer[offset], 4);
1155 header = BYTE_SWAP(header);
1157 PRINT_D(RX_DBG, "Header = %04x - Offset = %d\n", header, offset);
1161 is_cfg_packet = (header >> 31) & 0x1;
1162 pkt_offset = (header >> 22) & 0x1ff;
1163 tp_len = (header >> 11) & 0x7ff;
1164 pkt_len = header & 0x7ff;
1166 if (pkt_len == 0 || tp_len == 0) {
1167 wilc_debug(N_RXQ, "[wilc rxq]: data corrupt, packet len or tp_len is 0 [%d][%d]\n", pkt_len, tp_len);
1171 #define IS_MANAGMEMENT 0x100
1172 #define IS_MANAGMEMENT_CALLBACK 0x080
1173 #define IS_MGMT_STATUS_SUCCES 0x040
1176 if (pkt_offset & IS_MANAGMEMENT) {
1177 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1178 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1180 WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
1185 if (!is_cfg_packet) {
1187 frmw_to_linux(&buffer[offset],
1197 wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
1198 if (rsp.type == WILC_CFG_RSP) {
1200 * wake up the waiting task...
1202 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1203 if (p->cfg_seq_no == rsp.seq_no)
1204 up(&wilc->cfg_event);
1205 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1207 * Call back to indicate status...
1209 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
1211 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
1212 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
1222 #ifndef MEMORY_STATIC
1228 linux_wlan_rx_complete();
1233 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
1236 /********************************************
1240 ********************************************/
1241 static void wilc_unknown_isr_ext(void)
1243 g_wlan.hif_func.hif_clear_int_ext(0);
1245 static void wilc_pllupdate_isr_ext(u32 int_stats)
1250 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1252 /* Waiting for PLL */
1253 mdelay(WILC_PLL_TO);
1255 /* poll till read a valid data */
1256 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
1257 PRINT_D(TX_DBG, "PLL update retrying\n");
1262 static void wilc_sleeptimer_isr_ext(u32 int_stats1)
1264 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1265 #ifndef WILC_OPTIMIZE_SLEEP_INT
1266 genuChipPSstate = CHIP_SLEEPING_AUTO;
1270 static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
1272 wilc_wlan_dev_t *p = &g_wlan;
1273 #ifdef MEMORY_STATIC
1274 u32 offset = p->rx_buffer_offset;
1280 struct rxq_entry_t *rqe;
1287 size = ((int_status & 0x7fff) << 2);
1289 while (!size && retries < 10) {
1291 /*looping more secure*/
1292 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1293 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1294 p->hif_func.hif_read_size(&size);
1295 size = ((size & 0x7fff) << 2);
1301 #ifdef MEMORY_STATIC
1302 if (LINUX_RX_SIZE - offset < size)
1306 buffer = &p->rx_buffer[offset];
1308 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1313 buffer = kmalloc(size, GFP_KERNEL);
1314 if (buffer == NULL) {
1315 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
1316 usleep_range(100 * 1000, 100 * 1000);
1322 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1324 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1330 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1333 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1340 #ifdef MEMORY_STATIC
1342 p->rx_buffer_offset = offset;
1347 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
1349 rqe->buffer = buffer;
1350 rqe->buffer_size = size;
1351 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1352 wilc_wlan_rxq_add(rqe);
1355 #ifndef MEMORY_STATIC
1360 wilc_wlan_handle_rxq(wilc);
1363 void wilc_handle_isr(void *wilc)
1367 acquire_bus(ACQUIRE_AND_WAKEUP);
1368 g_wlan.hif_func.hif_read_int(&int_status);
1370 if (int_status & PLL_INT_EXT)
1371 wilc_pllupdate_isr_ext(int_status);
1373 if (int_status & DATA_INT_EXT) {
1374 wilc_wlan_handle_isr_ext(wilc, int_status);
1375 #ifndef WILC_OPTIMIZE_SLEEP_INT
1376 /* Chip is up and talking*/
1377 genuChipPSstate = CHIP_WAKEDUP;
1380 if (int_status & SLEEP_INT_EXT)
1381 wilc_sleeptimer_isr_ext(int_status);
1383 if (!(int_status & (ALL_INT_EXT))) {
1385 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1387 wilc_unknown_isr_ext();
1389 release_bus(RELEASE_ALLOW_SLEEP);
1392 /********************************************
1396 ********************************************/
1397 int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
1399 wilc_wlan_dev_t *p = &g_wlan;
1401 u32 addr, size, size2, blksz;
1406 /* Allocate a DMA coherent buffer. */
1408 dma_buffer = kmalloc(blksz, GFP_KERNEL);
1409 if (dma_buffer == NULL) {
1412 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1416 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1422 memcpy(&addr, &buffer[offset], 4);
1423 memcpy(&size, &buffer[offset + 4], 4);
1425 addr = BYTE_SWAP(addr);
1426 size = BYTE_SWAP(size);
1428 acquire_bus(ACQUIRE_ONLY);
1430 while (((int)size) && (offset < buffer_size)) {
1435 /* Copy firmware into a DMA coherent buffer */
1436 memcpy(dma_buffer, &buffer[offset], size2);
1437 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1445 release_bus(RELEASE_ONLY);
1450 PRINT_ER("Can't download firmware IO error\n ");
1453 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1454 } while (offset < buffer_size);
1462 return (ret < 0) ? ret : 0;
1465 /********************************************
1469 ********************************************/
1470 int wilc_wlan_start(void)
1472 wilc_wlan_dev_t *p = &g_wlan;
1478 * Set the host interface
1480 if (p->io_func.io_type == HIF_SDIO) {
1482 reg |= BIT(3); /* bug 4456 and 4557 */
1483 } else if (p->io_func.io_type == HIF_SPI) {
1486 acquire_bus(ACQUIRE_ONLY);
1487 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1489 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1490 release_bus(RELEASE_ONLY);
1496 #ifdef WILC_SDIO_IRQ_GPIO
1497 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1500 #ifdef WILC_DISABLE_PMU
1502 reg |= WILC_HAVE_USE_PMU;
1505 #ifdef WILC_SLEEP_CLK_SRC_XO
1506 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1507 #elif defined WILC_SLEEP_CLK_SRC_RTC
1508 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1511 #ifdef WILC_EXT_PA_INV_TX_RX
1512 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1515 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1518 /*Set oscillator frequency*/
1520 reg |= WILC_HAVE_XTAL_24;
1523 /*Enable/Disable GPIO configuration for FW logs*/
1524 #ifdef DISABLE_WILC_UART
1525 reg |= WILC_HAVE_DISABLE_WILC_UART;
1528 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1530 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1531 release_bus(RELEASE_ONLY);
1540 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1542 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1544 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1545 release_bus(RELEASE_ONLY);
1556 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1557 if ((reg & BIT(10)) == BIT(10)) {
1559 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1560 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1564 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1565 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1566 release_bus(RELEASE_ONLY);
1568 return (ret < 0) ? ret : 0;
1571 void wilc_wlan_global_reset(void)
1574 wilc_wlan_dev_t *p = &g_wlan;
1576 acquire_bus(ACQUIRE_AND_WAKEUP);
1577 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1578 release_bus(RELEASE_ONLY);
1580 int wilc_wlan_stop(void)
1582 wilc_wlan_dev_t *p = &g_wlan;
1587 * TODO: stop the firmware, need a re-download
1589 acquire_bus(ACQUIRE_AND_WAKEUP);
1591 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1593 PRINT_ER("Error while reading reg\n");
1594 release_bus(RELEASE_ALLOW_SLEEP);
1601 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1603 PRINT_ER("Error while writing reg\n");
1604 release_bus(RELEASE_ALLOW_SLEEP);
1611 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1613 PRINT_ER("Error while reading reg\n");
1614 release_bus(RELEASE_ALLOW_SLEEP);
1617 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1618 /*Workaround to ensure that the chip is actually reset*/
1619 if ((reg & BIT(10))) {
1620 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1622 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1625 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1626 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1628 PRINT_ER("Error while reading reg\n");
1629 release_bus(RELEASE_ALLOW_SLEEP);
1632 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1637 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1638 BIT(29) | BIT(30) | BIT(31));
1640 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1641 reg = (u32)~BIT(10);
1643 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1645 release_bus(RELEASE_ALLOW_SLEEP);
1650 void wilc_wlan_cleanup(struct net_device *dev)
1652 wilc_wlan_dev_t *p = &g_wlan;
1653 struct txq_entry_t *tqe;
1654 struct rxq_entry_t *rqe;
1657 perInterface_wlan_t *nic;
1660 nic = netdev_priv(dev);
1665 tqe = wilc_wlan_txq_remove_from_head();
1668 if (tqe->tx_complete_func)
1669 tqe->tx_complete_func(tqe->priv, 0);
1674 rqe = wilc_wlan_rxq_remove(wilc);
1677 #ifndef MEMORY_STATIC
1687 #ifdef MEMORY_STATIC
1688 kfree(p->rx_buffer);
1689 p->rx_buffer = NULL;
1691 kfree(p->tx_buffer);
1693 acquire_bus(ACQUIRE_AND_WAKEUP);
1696 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, ®);
1698 PRINT_ER("Error while reading reg\n");
1699 release_bus(RELEASE_ALLOW_SLEEP);
1701 PRINT_ER("Writing ABORT reg\n");
1702 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1704 PRINT_ER("Error while writing reg\n");
1705 release_bus(RELEASE_ALLOW_SLEEP);
1707 release_bus(RELEASE_ALLOW_SLEEP);
1711 p->hif_func.hif_deinit(NULL);
1715 static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
1717 wilc_wlan_dev_t *p = &g_wlan;
1718 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1719 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1720 int seq_no = p->cfg_seq_no % 256;
1721 int driver_handler = (u32)drvHandler;
1727 if (type == WILC_CFG_SET) { /* Set */
1728 cfg->wid_header[0] = 'W';
1729 } else { /* Query */
1730 cfg->wid_header[0] = 'Q';
1732 cfg->wid_header[1] = seq_no; /* sequence number */
1733 cfg->wid_header[2] = (u8)total_len;
1734 cfg->wid_header[3] = (u8)(total_len >> 8);
1735 cfg->wid_header[4] = (u8)driver_handler;
1736 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1737 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1738 cfg->wid_header[7] = (u8)(driver_handler >> 24);
1739 p->cfg_seq_no = seq_no;
1745 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1751 int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1752 int commit, u32 drvHandler)
1754 wilc_wlan_dev_t *p = &g_wlan;
1759 if (p->cfg_frame_in_use)
1763 p->cfg_frame_offset = 0;
1765 offset = p->cfg_frame_offset;
1766 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1767 buffer, buffer_size);
1769 p->cfg_frame_offset = offset;
1772 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1773 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1774 p->cfg_frame_in_use = 1;
1776 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
1779 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1780 CFG_PKTS_TIMEOUT)) {
1781 PRINT_D(TX_DBG, "Set Timed Out\n");
1784 p->cfg_frame_in_use = 0;
1785 p->cfg_frame_offset = 0;
1792 int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
1794 wilc_wlan_dev_t *p = &g_wlan;
1799 if (p->cfg_frame_in_use)
1803 p->cfg_frame_offset = 0;
1805 offset = p->cfg_frame_offset;
1806 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
1808 p->cfg_frame_offset = offset;
1811 p->cfg_frame_in_use = 1;
1813 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
1817 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1818 CFG_PKTS_TIMEOUT)) {
1819 PRINT_D(TX_DBG, "Get Timed Out\n");
1822 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1823 p->cfg_frame_in_use = 0;
1824 p->cfg_frame_offset = 0;
1831 int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
1835 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
1840 void wilc_bus_set_max_speed(void)
1843 /* Increase bus speed to max possible. */
1844 g_wlan.hif_func.hif_set_max_bus_speed();
1847 void wilc_bus_set_default_speed(void)
1850 /* Restore bus speed to default. */
1851 g_wlan.hif_func.hif_set_default_bus_speed();
1858 acquire_bus(ACQUIRE_ONLY);
1860 chipid = wilc_get_chipid(true);
1864 if ((chipid & 0xfff) != 0xa0) {
1866 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1867 * or SD_DAT3 [SPI platform] to ?1?
1869 /* Set cortus reset register to register control. */
1870 ret = g_wlan.hif_func.hif_read_reg(0x1118, ®);
1872 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1876 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1878 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1882 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1883 * (Cortus map) or C0000 (AHB map).
1885 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1887 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1892 release_bus(RELEASE_ONLY);
1898 u32 wilc_get_chipid(u8 update)
1901 /* SDIO can't read into global variables */
1902 /* Use this variable as a temp, then copy to the global */
1906 if (chipid == 0 || update != 0) {
1907 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1908 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1909 if (!ISWILC1000(tempchipid)) {
1913 if (tempchipid == 0x1002a0) {
1914 if (rfrevid == 0x1) { /* 1002A0 */
1915 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1916 tempchipid = 0x1002a1;
1918 } else if (tempchipid == 0x1002b0) {
1919 if (rfrevid == 3) { /* 1002B0 */
1920 } else if (rfrevid == 4) { /* 1002B1 */
1921 tempchipid = 0x1002b1;
1922 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1923 tempchipid = 0x1002b2;
1928 chipid = tempchipid;
1934 int wilc_wlan_init(wilc_wlan_inp_t *inp)
1939 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1941 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1946 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
1948 * host interface init
1950 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1951 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1956 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1958 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1962 if (!hif_spi.hif_init(inp, wilc_debug)) {
1967 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1976 * mac interface init
1978 if (!wilc_wlan_cfg_init(wilc_debug)) {
1985 * alloc tx, rx buffer
1987 if (g_wlan.tx_buffer == NULL)
1988 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
1989 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
1991 if (g_wlan.tx_buffer == NULL) {
1994 PRINT_ER("Can't allocate Tx Buffer");
1998 /* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
1999 #if defined (MEMORY_STATIC)
2000 if (g_wlan.rx_buffer == NULL)
2001 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
2002 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
2003 if (g_wlan.rx_buffer == NULL) {
2006 PRINT_ER("Can't allocate Rx Buffer");
2016 #ifdef TCP_ACK_FILTER
2017 Init_TCP_tracking();
2024 #ifdef MEMORY_STATIC
2025 kfree(g_wlan.rx_buffer);
2026 g_wlan.rx_buffer = NULL;
2028 kfree(g_wlan.tx_buffer);
2029 g_wlan.tx_buffer = NULL;
2035 u16 Set_machw_change_vir_if(bool bValue)
2040 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
2041 mutex_lock(&g_linux_wlan->hif_cs);
2042 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, ®);
2044 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2051 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2054 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2056 mutex_unlock(&g_linux_wlan->hif_cs);