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);
29 * input interface functions
31 wilc_wlan_io_func_t io_func;
34 * host interface functions
36 wilc_hif_func_t hif_func;
39 * configuration interface functions
42 wilc_cfg_frame_t cfg_frame;
63 unsigned long txq_spinlock_flags;
65 struct txq_entry_t *txq_head;
66 struct txq_entry_t *txq_tail;
73 struct rxq_entry_t *rxq_head;
74 struct rxq_entry_t *rxq_tail;
81 static wilc_wlan_dev_t g_wlan;
83 static inline void chip_allow_sleep(void);
84 static inline void chip_wakeup(void);
85 /********************************************
89 ********************************************/
91 static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
93 static void wilc_debug(u32 flag, char *fmt, ...)
100 vsprintf(buf, fmt, args);
107 static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
109 /*acquire_bus() and release_bus() are made static inline functions*/
110 /*as a temporary workaround to fix a problem of receiving*/
111 /*unknown interrupt from FW*/
112 static inline void acquire_bus(BUS_ACQUIRE_T acquire)
115 mutex_lock(&g_linux_wlan->hif_cs);
116 #ifndef WILC_OPTIMIZE_SLEEP_INT
117 if (genuChipPSstate != CHIP_WAKEDUP)
120 if (acquire == ACQUIRE_AND_WAKEUP)
125 static inline void release_bus(BUS_RELEASE_T release)
127 #ifdef WILC_OPTIMIZE_SLEEP_INT
128 if (release == RELEASE_ALLOW_SLEEP)
131 mutex_unlock(&g_linux_wlan->hif_cs);
133 /********************************************
137 ********************************************/
139 static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
142 wilc_wlan_dev_t *p = &g_wlan;
143 if (tqe == p->txq_head) {
145 p->txq_head = tqe->next;
147 p->txq_head->prev = NULL;
150 } else if (tqe == p->txq_tail) {
151 p->txq_tail = (tqe->prev);
153 p->txq_tail->next = NULL;
155 tqe->prev->next = tqe->next;
156 tqe->next->prev = tqe->prev;
162 static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
164 struct txq_entry_t *tqe;
165 wilc_wlan_dev_t *p = &g_wlan;
168 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
171 p->txq_head = tqe->next;
173 p->txq_head->prev = NULL;
183 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
187 static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
189 wilc_wlan_dev_t *p = &g_wlan;
191 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
193 if (p->txq_head == NULL) {
200 tqe->prev = p->txq_tail;
201 p->txq_tail->next = tqe;
205 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
207 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
212 PRINT_D(TX_DBG, "Wake the txq_handling\n");
214 up(&g_linux_wlan->txq_event);
217 static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
219 wilc_wlan_dev_t *p = &g_wlan;
221 if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
225 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
227 if (p->txq_head == NULL) {
233 tqe->next = p->txq_head;
235 p->txq_head->prev = tqe;
239 PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
241 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
242 up(&g_linux_wlan->txq_add_to_head_cs);
248 up(&g_linux_wlan->txq_event);
249 PRINT_D(TX_DBG, "Wake up the txq_handler\n");
255 u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
257 #ifdef TCP_ACK_FILTER
258 struct Ack_session_info;
259 struct Ack_session_info {
270 struct txq_entry_t *txqe;
271 } Pending_Acks_info_t /*Ack_info_t*/;
276 struct Ack_session_info *Free_head;
277 struct Ack_session_info *Alloc_head;
279 #define NOT_TCP_ACK (-1)
281 #define MAX_TCP_SESSION 25
282 #define MAX_PENDING_ACKS 256
283 struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
284 Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
286 u32 PendingAcks_arrBase;
287 u32 Opened_TCP_session;
292 static inline int Init_TCP_tracking(void)
298 static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
300 Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
301 Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
302 Acks_keep_track_info[Opened_TCP_session].src_port = src_prt;
303 Acks_keep_track_info[Opened_TCP_session].dst_port = dst_prt;
304 Opened_TCP_session++;
306 PRINT_D(TCP_ENH, "TCP Session %d to Ack %d\n", Opened_TCP_session, seq);
310 static inline int Update_TCP_track_session(u32 index, u32 Ack)
313 if (Ack > Acks_keep_track_info[index].Bigger_Ack_num)
314 Acks_keep_track_info[index].Bigger_Ack_num = Ack;
318 static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t *txqe)
320 Statisitcs_totalAcks++;
321 if (Pending_Acks < MAX_PENDING_ACKS) {
322 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].ack_num = Ack;
323 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].txqe = txqe;
324 Pending_Acks_info[PendingAcks_arrBase + Pending_Acks].Session_index = Session_index;
325 txqe->tcp_PendingAck_index = PendingAcks_arrBase + Pending_Acks;
333 static inline int remove_TCP_related(void)
335 wilc_wlan_dev_t *p = &g_wlan;
338 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
340 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
344 static inline int tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
348 u8 *buffer = tqe->buffer;
349 unsigned short h_proto;
351 wilc_wlan_dev_t *p = &g_wlan;
353 perInterface_wlan_t *nic;
356 nic = netdev_priv(dev);
359 spin_lock_irqsave(&wilc->txq_spinlock, flags);
361 eth_hdr_ptr = &buffer[0];
362 h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
363 if (h_proto == 0x0800) { /* IP */
367 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
368 protocol = ip_hdr_ptr[9];
371 if (protocol == 0x06) {
373 u32 IHL, Total_Length, Data_offset;
375 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
376 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
377 Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
378 Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
379 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*/
382 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]);
384 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]);
387 for (i = 0; i < Opened_TCP_session; i++) {
388 if (Acks_keep_track_info[i].Ack_seq_num == seq_no) {
389 Update_TCP_track_session(i, Ack_no);
393 if (i == Opened_TCP_session)
394 add_TCP_track_session(0, 0, seq_no);
396 add_TCP_Pending_Ack(Ack_no, i, tqe);
407 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
412 static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
414 perInterface_wlan_t *nic;
418 wilc_wlan_dev_t *p = &g_wlan;
420 nic = netdev_priv(dev);
423 spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags);
424 for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
425 if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
426 struct txq_entry_t *tqe;
428 PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
429 tqe = Pending_Acks_info[i].txqe;
431 wilc_wlan_txq_remove(tqe);
432 Statisitcs_DroppedAcks++;
433 tqe->status = 1; /* mark the packet send */
434 if (tqe->tx_complete_func)
435 tqe->tx_complete_func(tqe->priv, tqe->status);
442 Opened_TCP_session = 0;
444 if (PendingAcks_arrBase == 0)
445 PendingAcks_arrBase = MAX_TCP_SESSION;
447 PendingAcks_arrBase = 0;
450 spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags);
452 while (Dropped > 0) {
453 /*consume the semaphore count of the removed packet*/
454 linux_wlan_lock_timeout(&wilc->txq_event, 1);
462 bool EnableTCPAckFilter = false;
464 void Enable_TCP_ACK_Filter(bool value)
466 EnableTCPAckFilter = value;
469 bool is_TCP_ACK_Filter_Enabled(void)
471 return EnableTCPAckFilter;
474 static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
476 wilc_wlan_dev_t *p = &g_wlan;
477 struct txq_entry_t *tqe;
479 PRINT_D(TX_DBG, "Adding config packet ...\n");
481 PRINT_D(TX_DBG, "Return due to clear function\n");
482 up(&g_linux_wlan->cfg_event);
486 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
488 PRINT_ER("Failed to allocate memory\n");
492 tqe->type = WILC_CFG_PKT;
493 tqe->buffer = buffer;
494 tqe->buffer_size = buffer_size;
495 tqe->tx_complete_func = NULL;
497 #ifdef TCP_ACK_FILTER
498 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
501 * Configuration packet always at the front
503 PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
505 if (wilc_wlan_txq_add_to_head(tqe))
510 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
511 u32 buffer_size, wilc_tx_complete_func_t func)
513 wilc_wlan_dev_t *p = &g_wlan;
514 struct txq_entry_t *tqe;
519 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
523 tqe->type = WILC_NET_PKT;
524 tqe->buffer = buffer;
525 tqe->buffer_size = buffer_size;
526 tqe->tx_complete_func = func;
529 PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
530 #ifdef TCP_ACK_FILTER
531 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
532 if (is_TCP_ACK_Filter_Enabled())
533 tcp_process(dev, tqe);
535 wilc_wlan_txq_add_to_tail(tqe);
536 /*return number of itemes in the queue*/
537 return p->txq_entries;
540 int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
543 wilc_wlan_dev_t *p = &g_wlan;
544 struct txq_entry_t *tqe;
549 tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
553 tqe->type = WILC_MGMT_PKT;
554 tqe->buffer = buffer;
555 tqe->buffer_size = buffer_size;
556 tqe->tx_complete_func = func;
558 #ifdef TCP_ACK_FILTER
559 tqe->tcp_PendingAck_index = NOT_TCP_ACK;
561 PRINT_D(TX_DBG, "Adding Network packet at the Queue tail\n");
562 wilc_wlan_txq_add_to_tail(tqe);
566 static struct txq_entry_t *wilc_wlan_txq_get_first(void)
568 wilc_wlan_dev_t *p = &g_wlan;
569 struct txq_entry_t *tqe;
572 spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
576 spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
582 static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
583 struct txq_entry_t *tqe)
586 spin_lock_irqsave(&wilc->txq_spinlock, flags);
589 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
595 static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
597 wilc_wlan_dev_t *p = &g_wlan;
602 mutex_lock(&wilc->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(&wilc->rxq_cs);
617 return p->rxq_entries;
620 static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
622 wilc_wlan_dev_t *p = &g_wlan;
624 PRINT_D(RX_DBG, "Getting rxQ element\n");
626 struct rxq_entry_t *rqe;
628 mutex_lock(&wilc->rxq_cs);
630 p->rxq_head = p->rxq_head->next;
632 PRINT_D(RX_DBG, "RXQ entries decreased\n");
633 mutex_unlock(&wilc->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 & ~BIT(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 | BIT(1));
673 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(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 | BIT(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 &
716 } while ((clk_status_reg & 0x1) == 0);
720 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
721 g_wlan.hif_func.hif_read_reg(0x1C0C, ®);
723 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
725 if (wilc_get_chipid(false) >= 0x1002b0) {
726 /* Enable PALDO back right after wakeup */
729 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
731 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
733 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
735 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
738 genuChipPSstate = CHIP_WAKEDUP;
741 static inline void chip_wakeup(void)
746 if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
747 g_wlan.hif_func.hif_read_reg(1, ®);
748 /* Make sure bit 1 is 0 before we start. */
749 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
751 g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
753 g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
754 } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO) {
755 /* Make sure bit 0 is 0 before we start. */
756 g_wlan.hif_func.hif_read_reg(0xf0, ®);
757 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
759 g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
761 g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
765 /* Wait for the chip to stabilize*/
768 /* Make sure chip is awake. This is an extra step that can be removed */
769 /* later to avoid the bus access overhead */
770 if ((wilc_get_chipid(true) == 0))
771 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
773 } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
775 } while (wilc_get_chipid(true) == 0);
777 if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
778 g_wlan.hif_func.hif_read_reg(0x1C0C, ®);
780 g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
782 if (wilc_get_chipid(false) >= 0x1002b0) {
783 /* Enable PALDO back right after wakeup */
786 g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
788 g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
790 g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
792 g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
795 genuChipPSstate = CHIP_WAKEDUP;
798 void chip_sleep_manually(u32 u32SleepTime)
800 if (genuChipPSstate != CHIP_WAKEDUP) {
801 /* chip is already sleeping. Do nothing */
804 acquire_bus(ACQUIRE_ONLY);
806 #ifdef WILC_OPTIMIZE_SLEEP_INT
810 /* Trigger the manual sleep interrupt */
811 g_wlan.hif_func.hif_write_reg(0x10a8, 1);
813 genuChipPSstate = CHIP_SLEEPING_MANUAL;
814 release_bus(RELEASE_ONLY);
819 /********************************************
821 * Tx, Rx queue handle functions
823 ********************************************/
824 int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount)
826 wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
830 u8 *txb = p->tx_buffer;
833 struct txq_entry_t *tqe;
837 u32 vmm_table[WILC_VMM_TBL_SIZE];
838 perInterface_wlan_t *nic;
841 nic = netdev_priv(dev);
849 linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs,
851 #ifdef TCP_ACK_FILTER
852 wilc_wlan_txq_filter_dup_tcp_ack(dev);
857 PRINT_D(TX_DBG, "Getting the head of the TxQ\n");
858 tqe = wilc_wlan_txq_get_first();
862 if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
864 if (tqe->type == WILC_CFG_PKT)
865 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
867 else if (tqe->type == WILC_NET_PKT)
868 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
871 vmm_sz = HOST_HDR_OFFSET;
873 vmm_sz += tqe->buffer_size;
874 PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
875 if (vmm_sz & 0x3) { /* has to be word aligned */
876 vmm_sz = (vmm_sz + 4) & ~0x3;
878 if ((sum + vmm_sz) > LINUX_TX_SIZE)
881 PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
882 vmm_table[i] = vmm_sz / 4; /* table take the word size */
883 PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
885 if (tqe->type == WILC_CFG_PKT) {
886 vmm_table[i] |= BIT(10);
887 PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
890 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
895 PRINT_D(TX_DBG, "sum = %d\n", sum);
896 tqe = wilc_wlan_txq_get_next(wilc, tqe);
902 if (i == 0) { /* nothing in the queue */
903 PRINT_D(TX_DBG, "Nothing in TX-Q\n");
906 PRINT_D(TX_DBG, "Mark the last entry in VMM table - number of previous entries = %d\n", i);
907 vmm_table[i] = 0x0; /* mark the last element to 0 */
909 acquire_bus(ACQUIRE_AND_WAKEUP);
913 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®);
915 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg vmm_tbl_entry..\n");
919 if ((reg & 0x1) == 0) {
923 PRINT_D(TX_DBG, "Writing VMM table ... with Size = %d\n", ((i + 1) * 4));
929 PRINT_D(TX_DBG, "Looping in tx ctrl , forcce quit\n");
930 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, 0);
934 * wait for vmm table is ready
936 PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
937 release_bus(RELEASE_ALLOW_SLEEP);
938 usleep_range(3000, 3000);
939 acquire_bus(ACQUIRE_AND_WAKEUP);
952 ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
954 wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
962 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x2);
964 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg host_vmm_ctl..\n");
969 * wait for confirm...
973 ret = p->hif_func.hif_read_reg(WILC_HOST_VMM_CTL, ®);
975 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg host_vmm_ctl..\n");
978 if ((reg >> 2) & 0x1) {
982 entries = ((reg >> 3) & 0x3f);
985 release_bus(RELEASE_ALLOW_SLEEP);
986 usleep_range(3000, 3000);
987 acquire_bus(ACQUIRE_AND_WAKEUP);
988 PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
992 ret = p->hif_func.hif_write_reg(WILC_HOST_VMM_CTL, 0x0);
1000 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]);
1002 /* undo the transaction. */
1003 ret = p->hif_func.hif_read_reg(WILC_HOST_TX_CTRL, ®);
1005 wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
1009 ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
1011 wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
1024 ret = WILC_TX_ERR_NO_BUF;
1028 /* since copying data into txb takes some time, then
1029 * allow the bus lock to be released let the RX task go. */
1030 release_bus(RELEASE_ALLOW_SLEEP);
1033 * Copy data to the TX buffer
1038 tqe = wilc_wlan_txq_remove_from_head();
1039 if (tqe != NULL && (vmm_table[i] != 0)) {
1040 u32 header, buffer_offset;
1043 vmm_table[i] = BYTE_SWAP(vmm_table[i]);
1045 vmm_sz = (vmm_table[i] & 0x3ff); /* in word unit */
1047 header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
1048 if (tqe->type == WILC_MGMT_PKT)
1054 header = BYTE_SWAP(header);
1056 memcpy(&txb[offset], &header, 4);
1057 if (tqe->type == WILC_CFG_PKT) {
1058 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
1060 else if (tqe->type == WILC_NET_PKT) {
1061 char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
1063 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
1064 /* copy the bssid at the sart of the buffer */
1065 memcpy(&txb[offset + 4], pBSSID, 6);
1068 buffer_offset = HOST_HDR_OFFSET;
1071 memcpy(&txb[offset + buffer_offset], tqe->buffer, tqe->buffer_size);
1074 tqe->status = 1; /* mark the packet send */
1075 if (tqe->tx_complete_func)
1076 tqe->tx_complete_func(tqe->priv, tqe->status);
1077 #ifdef TCP_ACK_FILTER
1078 if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
1079 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(&wilc->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(struct wilc *wilc)
1124 wilc_wlan_dev_t *p = &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(&wilc->cfg_event);
1140 rqe = wilc_wlan_rxq_remove(wilc);
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 #define IS_MANAGMEMENT 0x100
1177 #define IS_MANAGMEMENT_CALLBACK 0x080
1178 #define IS_MGMT_STATUS_SUCCES 0x040
1181 if (pkt_offset & IS_MANAGMEMENT) {
1182 /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
1183 pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
1185 WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
1190 if (!is_cfg_packet) {
1203 wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
1204 if (rsp.type == WILC_CFG_RSP) {
1206 * wake up the waiting task...
1208 PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
1209 if (p->cfg_seq_no == rsp.seq_no)
1210 up(&wilc->cfg_event);
1211 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
1213 * Call back to indicate status...
1215 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
1217 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
1218 linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
1228 #ifndef MEMORY_STATIC
1234 linux_wlan_rx_complete();
1239 PRINT_D(RX_DBG, "THREAD: Exiting RX thread\n");
1242 /********************************************
1246 ********************************************/
1247 static void wilc_unknown_isr_ext(void)
1249 g_wlan.hif_func.hif_clear_int_ext(0);
1251 static void wilc_pllupdate_isr_ext(u32 int_stats)
1256 g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
1258 /* Waiting for PLL */
1259 mdelay(WILC_PLL_TO);
1261 /* poll till read a valid data */
1262 while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
1263 PRINT_D(TX_DBG, "PLL update retrying\n");
1268 static void wilc_sleeptimer_isr_ext(u32 int_stats1)
1270 g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
1271 #ifndef WILC_OPTIMIZE_SLEEP_INT
1272 genuChipPSstate = CHIP_SLEEPING_AUTO;
1276 static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
1278 wilc_wlan_dev_t *p = &g_wlan;
1279 #ifdef MEMORY_STATIC
1280 u32 offset = p->rx_buffer_offset;
1286 struct rxq_entry_t *rqe;
1293 size = ((int_status & 0x7fff) << 2);
1295 while (!size && retries < 10) {
1297 /*looping more secure*/
1298 /*zero size make a crashe because the dma will not happen and that will block the firmware*/
1299 wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
1300 p->hif_func.hif_read_size(&size);
1301 size = ((size & 0x7fff) << 2);
1307 #ifdef MEMORY_STATIC
1308 if (LINUX_RX_SIZE - offset < size)
1312 buffer = &p->rx_buffer[offset];
1314 wilc_debug(N_ERR, "[wilc isr]: fail Rx Buffer is NULL...drop the packets (%d)\n", size);
1319 buffer = kmalloc(size, GFP_KERNEL);
1320 if (buffer == NULL) {
1321 wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
1322 usleep_range(100 * 1000, 100 * 1000);
1328 * clear the chip's interrupt after getting size some register getting corrupted after clear the interrupt
1330 p->hif_func.hif_clear_int_ext(DATA_INT_CLR | ENABLE_RX_VMM);
1336 ret = p->hif_func.hif_block_rx_ext(0, buffer, size);
1339 wilc_debug(N_ERR, "[wilc isr]: fail block rx...\n");
1346 #ifdef MEMORY_STATIC
1348 p->rx_buffer_offset = offset;
1353 rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
1355 rqe->buffer = buffer;
1356 rqe->buffer_size = size;
1357 PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
1358 wilc_wlan_rxq_add(wilc, rqe);
1361 #ifndef MEMORY_STATIC
1366 wilc_wlan_handle_rxq(wilc);
1369 void wilc_handle_isr(void *wilc)
1373 acquire_bus(ACQUIRE_AND_WAKEUP);
1374 g_wlan.hif_func.hif_read_int(&int_status);
1376 if (int_status & PLL_INT_EXT)
1377 wilc_pllupdate_isr_ext(int_status);
1379 if (int_status & DATA_INT_EXT) {
1380 wilc_wlan_handle_isr_ext(wilc, int_status);
1381 #ifndef WILC_OPTIMIZE_SLEEP_INT
1382 /* Chip is up and talking*/
1383 genuChipPSstate = CHIP_WAKEDUP;
1386 if (int_status & SLEEP_INT_EXT)
1387 wilc_sleeptimer_isr_ext(int_status);
1389 if (!(int_status & (ALL_INT_EXT))) {
1391 PRINT_D(TX_DBG, ">> UNKNOWN_INTERRUPT - 0x%08x\n", int_status);
1393 wilc_unknown_isr_ext();
1395 release_bus(RELEASE_ALLOW_SLEEP);
1398 /********************************************
1402 ********************************************/
1403 int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
1405 wilc_wlan_dev_t *p = &g_wlan;
1407 u32 addr, size, size2, blksz;
1412 /* Allocate a DMA coherent buffer. */
1414 dma_buffer = kmalloc(blksz, GFP_KERNEL);
1415 if (dma_buffer == NULL) {
1418 PRINT_ER("Can't allocate buffer for firmware download IO error\n ");
1422 PRINT_D(INIT_DBG, "Downloading firmware size = %d ...\n", buffer_size);
1428 memcpy(&addr, &buffer[offset], 4);
1429 memcpy(&size, &buffer[offset + 4], 4);
1431 addr = BYTE_SWAP(addr);
1432 size = BYTE_SWAP(size);
1434 acquire_bus(ACQUIRE_ONLY);
1436 while (((int)size) && (offset < buffer_size)) {
1441 /* Copy firmware into a DMA coherent buffer */
1442 memcpy(dma_buffer, &buffer[offset], size2);
1443 ret = p->hif_func.hif_block_tx(addr, dma_buffer, size2);
1451 release_bus(RELEASE_ONLY);
1456 PRINT_ER("Can't download firmware IO error\n ");
1459 PRINT_D(INIT_DBG, "Offset = %d\n", offset);
1460 } while (offset < buffer_size);
1468 return (ret < 0) ? ret : 0;
1471 /********************************************
1475 ********************************************/
1476 int wilc_wlan_start(void)
1478 wilc_wlan_dev_t *p = &g_wlan;
1484 * Set the host interface
1486 if (p->io_func.io_type == HIF_SDIO) {
1488 reg |= BIT(3); /* bug 4456 and 4557 */
1489 } else if (p->io_func.io_type == HIF_SPI) {
1492 acquire_bus(ACQUIRE_ONLY);
1493 ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CFG, reg);
1495 wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_cfg...\n");
1496 release_bus(RELEASE_ONLY);
1502 #ifdef WILC_SDIO_IRQ_GPIO
1503 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1506 #ifdef WILC_DISABLE_PMU
1508 reg |= WILC_HAVE_USE_PMU;
1511 #ifdef WILC_SLEEP_CLK_SRC_XO
1512 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1513 #elif defined WILC_SLEEP_CLK_SRC_RTC
1514 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1517 #ifdef WILC_EXT_PA_INV_TX_RX
1518 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1521 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1524 /*Set oscillator frequency*/
1526 reg |= WILC_HAVE_XTAL_24;
1529 /*Enable/Disable GPIO configuration for FW logs*/
1530 #ifdef DISABLE_WILC_UART
1531 reg |= WILC_HAVE_DISABLE_WILC_UART;
1534 ret = p->hif_func.hif_write_reg(WILC_GP_REG_1, reg);
1536 wilc_debug(N_ERR, "[wilc start]: fail write WILC_GP_REG_1 ...\n");
1537 release_bus(RELEASE_ONLY);
1546 p->hif_func.hif_sync_ext(NUM_INT_EXT);
1548 ret = p->hif_func.hif_read_reg(0x1000, &chipid);
1550 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1000 ...\n");
1551 release_bus(RELEASE_ONLY);
1562 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1563 if ((reg & BIT(10)) == BIT(10)) {
1565 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1566 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1570 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1571 p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1572 release_bus(RELEASE_ONLY);
1574 return (ret < 0) ? ret : 0;
1577 void wilc_wlan_global_reset(void)
1580 wilc_wlan_dev_t *p = &g_wlan;
1582 acquire_bus(ACQUIRE_AND_WAKEUP);
1583 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
1584 release_bus(RELEASE_ONLY);
1586 int wilc_wlan_stop(void)
1588 wilc_wlan_dev_t *p = &g_wlan;
1593 * TODO: stop the firmware, need a re-download
1595 acquire_bus(ACQUIRE_AND_WAKEUP);
1597 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1599 PRINT_ER("Error while reading reg\n");
1600 release_bus(RELEASE_ALLOW_SLEEP);
1607 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1609 PRINT_ER("Error while writing reg\n");
1610 release_bus(RELEASE_ALLOW_SLEEP);
1617 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1619 PRINT_ER("Error while reading reg\n");
1620 release_bus(RELEASE_ALLOW_SLEEP);
1623 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1624 /*Workaround to ensure that the chip is actually reset*/
1625 if ((reg & BIT(10))) {
1626 PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
1628 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1631 PRINT_D(GENERIC_DBG, "Bit 10 reset after : Retry %d\n", timeout);
1632 ret = p->hif_func.hif_read_reg(WILC_GLB_RESET_0, ®);
1634 PRINT_ER("Error while reading reg\n");
1635 release_bus(RELEASE_ALLOW_SLEEP);
1638 PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
1643 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1644 BIT(29) | BIT(30) | BIT(31));
1646 p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1647 reg = (u32)~BIT(10);
1649 ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
1651 release_bus(RELEASE_ALLOW_SLEEP);
1656 void wilc_wlan_cleanup(struct net_device *dev)
1658 wilc_wlan_dev_t *p = &g_wlan;
1659 struct txq_entry_t *tqe;
1660 struct rxq_entry_t *rqe;
1663 perInterface_wlan_t *nic;
1666 nic = netdev_priv(dev);
1671 tqe = wilc_wlan_txq_remove_from_head();
1674 if (tqe->tx_complete_func)
1675 tqe->tx_complete_func(tqe->priv, 0);
1680 rqe = wilc_wlan_rxq_remove(wilc);
1683 #ifndef MEMORY_STATIC
1693 #ifdef MEMORY_STATIC
1694 kfree(p->rx_buffer);
1695 p->rx_buffer = NULL;
1697 kfree(p->tx_buffer);
1699 acquire_bus(ACQUIRE_AND_WAKEUP);
1702 ret = p->hif_func.hif_read_reg(WILC_GP_REG_0, ®);
1704 PRINT_ER("Error while reading reg\n");
1705 release_bus(RELEASE_ALLOW_SLEEP);
1707 PRINT_ER("Writing ABORT reg\n");
1708 ret = p->hif_func.hif_write_reg(WILC_GP_REG_0, (reg | ABORT_INT));
1710 PRINT_ER("Error while writing reg\n");
1711 release_bus(RELEASE_ALLOW_SLEEP);
1713 release_bus(RELEASE_ALLOW_SLEEP);
1717 p->hif_func.hif_deinit(NULL);
1721 static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
1723 wilc_wlan_dev_t *p = &g_wlan;
1724 wilc_cfg_frame_t *cfg = &p->cfg_frame;
1725 int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1726 int seq_no = p->cfg_seq_no % 256;
1727 int driver_handler = (u32)drvHandler;
1733 if (type == WILC_CFG_SET) { /* Set */
1734 cfg->wid_header[0] = 'W';
1735 } else { /* Query */
1736 cfg->wid_header[0] = 'Q';
1738 cfg->wid_header[1] = seq_no; /* sequence number */
1739 cfg->wid_header[2] = (u8)total_len;
1740 cfg->wid_header[3] = (u8)(total_len >> 8);
1741 cfg->wid_header[4] = (u8)driver_handler;
1742 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1743 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1744 cfg->wid_header[7] = (u8)(driver_handler >> 24);
1745 p->cfg_seq_no = seq_no;
1751 if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
1757 int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
1758 int commit, u32 drvHandler)
1760 wilc_wlan_dev_t *p = &g_wlan;
1765 if (p->cfg_frame_in_use)
1769 p->cfg_frame_offset = 0;
1771 offset = p->cfg_frame_offset;
1772 ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
1773 buffer, buffer_size);
1775 p->cfg_frame_offset = offset;
1778 PRINT_D(TX_DBG, "[WILC]PACKET Commit with sequence number %d\n", p->cfg_seq_no);
1779 PRINT_D(RX_DBG, "Processing cfg_set()\n");
1780 p->cfg_frame_in_use = 1;
1782 if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
1785 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1786 CFG_PKTS_TIMEOUT)) {
1787 PRINT_D(TX_DBG, "Set Timed Out\n");
1790 p->cfg_frame_in_use = 0;
1791 p->cfg_frame_offset = 0;
1798 int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
1800 wilc_wlan_dev_t *p = &g_wlan;
1805 if (p->cfg_frame_in_use)
1809 p->cfg_frame_offset = 0;
1811 offset = p->cfg_frame_offset;
1812 ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
1814 p->cfg_frame_offset = offset;
1817 p->cfg_frame_in_use = 1;
1819 if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
1823 if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
1824 CFG_PKTS_TIMEOUT)) {
1825 PRINT_D(TX_DBG, "Get Timed Out\n");
1828 PRINT_D(GENERIC_DBG, "[WILC]Get Response received\n");
1829 p->cfg_frame_in_use = 0;
1830 p->cfg_frame_offset = 0;
1837 int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
1841 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
1846 void wilc_bus_set_max_speed(void)
1849 /* Increase bus speed to max possible. */
1850 g_wlan.hif_func.hif_set_max_bus_speed();
1853 void wilc_bus_set_default_speed(void)
1856 /* Restore bus speed to default. */
1857 g_wlan.hif_func.hif_set_default_bus_speed();
1864 acquire_bus(ACQUIRE_ONLY);
1866 chipid = wilc_get_chipid(true);
1870 if ((chipid & 0xfff) != 0xa0) {
1872 * Avoid booting from boot ROM. Make sure that Drive IRQN [SDIO platform]
1873 * or SD_DAT3 [SPI platform] to ?1?
1875 /* Set cortus reset register to register control. */
1876 ret = g_wlan.hif_func.hif_read_reg(0x1118, ®);
1878 wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
1882 ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
1884 wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
1888 * Write branch intruction to IRAM (0x71 trap) at location 0xFFFF0000
1889 * (Cortus map) or C0000 (AHB map).
1891 ret = g_wlan.hif_func.hif_write_reg(0xc0000, 0x71);
1893 wilc_debug(N_ERR, "[wilc start]: fail write reg 0xc0000 ...\n");
1898 release_bus(RELEASE_ONLY);
1904 u32 wilc_get_chipid(u8 update)
1907 /* SDIO can't read into global variables */
1908 /* Use this variable as a temp, then copy to the global */
1912 if (chipid == 0 || update != 0) {
1913 g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
1914 g_wlan.hif_func.hif_read_reg(0x13f4, &rfrevid);
1915 if (!ISWILC1000(tempchipid)) {
1919 if (tempchipid == 0x1002a0) {
1920 if (rfrevid == 0x1) { /* 1002A0 */
1921 } else { /* if (rfrevid == 0x2) */ /* 1002A1 */
1922 tempchipid = 0x1002a1;
1924 } else if (tempchipid == 0x1002b0) {
1925 if (rfrevid == 3) { /* 1002B0 */
1926 } else if (rfrevid == 4) { /* 1002B1 */
1927 tempchipid = 0x1002b1;
1928 } else { /* if(rfrevid == 5) */ /* 1002B2 */
1929 tempchipid = 0x1002b2;
1934 chipid = tempchipid;
1940 int wilc_wlan_init(wilc_wlan_inp_t *inp)
1945 PRINT_D(INIT_DBG, "Initializing WILC_Wlan ...\n");
1947 memset((void *)&g_wlan, 0, sizeof(wilc_wlan_dev_t));
1952 memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
1954 * host interface init
1956 if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
1957 if (!hif_sdio.hif_init(inp, wilc_debug)) {
1962 memcpy((void *)&g_wlan.hif_func, &hif_sdio, sizeof(wilc_hif_func_t));
1964 if ((inp->io_func.io_type & 0x1) == HIF_SPI) {
1968 if (!hif_spi.hif_init(inp, wilc_debug)) {
1973 memcpy((void *)&g_wlan.hif_func, &hif_spi, sizeof(wilc_hif_func_t));
1982 * mac interface init
1984 if (!wilc_wlan_cfg_init(wilc_debug)) {
1991 * alloc tx, rx buffer
1993 if (g_wlan.tx_buffer == NULL)
1994 g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
1995 PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
1997 if (g_wlan.tx_buffer == NULL) {
2000 PRINT_ER("Can't allocate Tx Buffer");
2004 /* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
2005 #if defined (MEMORY_STATIC)
2006 if (g_wlan.rx_buffer == NULL)
2007 g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
2008 PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
2009 if (g_wlan.rx_buffer == NULL) {
2012 PRINT_ER("Can't allocate Rx Buffer");
2022 #ifdef TCP_ACK_FILTER
2023 Init_TCP_tracking();
2030 #ifdef MEMORY_STATIC
2031 kfree(g_wlan.rx_buffer);
2032 g_wlan.rx_buffer = NULL;
2034 kfree(g_wlan.tx_buffer);
2035 g_wlan.tx_buffer = NULL;
2041 u16 Set_machw_change_vir_if(struct net_device *dev, bool bValue)
2045 perInterface_wlan_t *nic;
2048 nic = netdev_priv(dev);
2051 /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
2052 mutex_lock(&wilc->hif_cs);
2053 ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, ®);
2055 PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
2062 ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
2065 PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
2067 mutex_unlock(&wilc->hif_cs);