1 #include "wilc_wlan_if.h"
3 #include "wilc_wfi_netdevice.h"
4 #include "wilc_wlan_cfg.h"
6 static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
8 /* FIXME: replace with dev_debug() */
9 static void wilc_debug(u32 flag, char *fmt, ...)
16 vsprintf(buf, fmt, args);
21 static CHIP_PS_STATE_T chip_ps_state = CHIP_WAKEDUP;
23 static inline void acquire_bus(struct wilc *wilc, BUS_ACQUIRE_T acquire)
25 mutex_lock(&wilc->hif_cs);
26 if (acquire == ACQUIRE_AND_WAKEUP)
30 static inline void release_bus(struct wilc *wilc, BUS_RELEASE_T release)
32 if (release == RELEASE_ALLOW_SLEEP)
33 chip_allow_sleep(wilc);
34 mutex_unlock(&wilc->hif_cs);
37 static void wilc_wlan_txq_remove(struct wilc *wilc, struct txq_entry_t *tqe)
40 if (tqe == wilc->txq_head) {
41 wilc->txq_head = tqe->next;
43 wilc->txq_head->prev = NULL;
44 } else if (tqe == wilc->txq_tail) {
45 wilc->txq_tail = (tqe->prev);
47 wilc->txq_tail->next = NULL;
49 tqe->prev->next = tqe->next;
50 tqe->next->prev = tqe->prev;
52 wilc->txq_entries -= 1;
55 static struct txq_entry_t *
56 wilc_wlan_txq_remove_from_head(struct net_device *dev)
58 struct txq_entry_t *tqe;
63 vif = netdev_priv(dev);
66 spin_lock_irqsave(&wilc->txq_spinlock, flags);
69 wilc->txq_head = tqe->next;
71 wilc->txq_head->prev = NULL;
73 wilc->txq_entries -= 1;
77 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
81 static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
82 struct txq_entry_t *tqe)
88 vif = netdev_priv(dev);
91 spin_lock_irqsave(&wilc->txq_spinlock, flags);
93 if (!wilc->txq_head) {
100 tqe->prev = wilc->txq_tail;
101 wilc->txq_tail->next = tqe;
102 wilc->txq_tail = tqe;
104 wilc->txq_entries += 1;
106 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
108 up(&wilc->txq_event);
111 static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
112 struct txq_entry_t *tqe)
115 struct wilc *wilc = vif->wilc;
117 if (wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs,
121 spin_lock_irqsave(&wilc->txq_spinlock, flags);
123 if (!wilc->txq_head) {
126 wilc->txq_head = tqe;
127 wilc->txq_tail = tqe;
129 tqe->next = wilc->txq_head;
131 wilc->txq_head->prev = tqe;
132 wilc->txq_head = tqe;
134 wilc->txq_entries += 1;
136 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
137 up(&wilc->txq_add_to_head_cs);
138 up(&wilc->txq_event);
143 struct ack_session_info;
144 struct ack_session_info {
152 struct pending_acks_info {
155 struct txq_entry_t *txqe;
159 #define NOT_TCP_ACK (-1)
161 #define MAX_TCP_SESSION 25
162 #define MAX_PENDING_ACKS 256
163 static struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
164 static struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS];
166 static u32 pending_base;
167 static u32 tcp_session;
168 static u32 pending_acks;
170 static inline int init_tcp_tracking(void)
175 static inline int add_tcp_session(u32 src_prt, u32 dst_prt, u32 seq)
177 if (tcp_session < 2 * MAX_TCP_SESSION) {
178 ack_session_info[tcp_session].seq_num = seq;
179 ack_session_info[tcp_session].bigger_ack_num = 0;
180 ack_session_info[tcp_session].src_port = src_prt;
181 ack_session_info[tcp_session].dst_port = dst_prt;
187 static inline int update_tcp_session(u32 index, u32 ack)
189 if (index < 2 * MAX_TCP_SESSION &&
190 ack > ack_session_info[index].bigger_ack_num)
191 ack_session_info[index].bigger_ack_num = ack;
195 static inline int add_tcp_pending_ack(u32 ack, u32 session_index,
196 struct txq_entry_t *txqe)
198 if (pending_base + pending_acks < MAX_PENDING_ACKS) {
199 pending_acks_info[pending_base + pending_acks].ack_num = ack;
200 pending_acks_info[pending_base + pending_acks].txqe = txqe;
201 pending_acks_info[pending_base + pending_acks].session_index = session_index;
202 txqe->tcp_pending_ack_idx = pending_base + pending_acks;
208 static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
211 u8 *buffer = tqe->buffer;
212 unsigned short h_proto;
215 struct wilc_vif *vif;
218 vif = netdev_priv(dev);
221 spin_lock_irqsave(&wilc->txq_spinlock, flags);
223 eth_hdr_ptr = &buffer[0];
224 h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
225 if (h_proto == ETH_P_IP) {
229 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
230 protocol = ip_hdr_ptr[9];
232 if (protocol == 0x06) {
234 u32 IHL, total_length, data_offset;
236 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
237 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
238 total_length = ((u32)ip_hdr_ptr[2] << 8) +
240 data_offset = ((u32)tcp_hdr_ptr[12] & 0xf0) >> 2;
241 if (total_length == (IHL + data_offset)) {
244 seq_no = ((u32)tcp_hdr_ptr[4] << 24) +
245 ((u32)tcp_hdr_ptr[5] << 16) +
246 ((u32)tcp_hdr_ptr[6] << 8) +
249 ack_no = ((u32)tcp_hdr_ptr[8] << 24) +
250 ((u32)tcp_hdr_ptr[9] << 16) +
251 ((u32)tcp_hdr_ptr[10] << 8) +
252 (u32)tcp_hdr_ptr[11];
254 for (i = 0; i < tcp_session; i++) {
255 if (i < 2 * MAX_TCP_SESSION &&
256 ack_session_info[i].seq_num == seq_no) {
257 update_tcp_session(i, ack_no);
261 if (i == tcp_session)
262 add_tcp_session(0, 0, seq_no);
264 add_tcp_pending_ack(ack_no, i, tqe);
269 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
272 static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
274 struct wilc_vif *vif;
279 vif = netdev_priv(dev);
282 spin_lock_irqsave(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
283 for (i = pending_base; i < (pending_base + pending_acks); i++) {
284 if (i >= MAX_PENDING_ACKS ||
285 pending_acks_info[i].session_index >= 2 * MAX_TCP_SESSION)
287 if (pending_acks_info[i].ack_num < ack_session_info[pending_acks_info[i].session_index].bigger_ack_num) {
288 struct txq_entry_t *tqe;
290 tqe = pending_acks_info[i].txqe;
292 wilc_wlan_txq_remove(wilc, tqe);
294 if (tqe->tx_complete_func)
295 tqe->tx_complete_func(tqe->priv,
305 if (pending_base == 0)
306 pending_base = MAX_TCP_SESSION;
310 spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
312 while (dropped > 0) {
313 wilc_lock_timeout(wilc, &wilc->txq_event, 1);
322 void wilc_enable_tcp_ack_filter(bool value)
327 static bool is_tcp_ack_filter_enabled(void)
332 static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
335 struct txq_entry_t *tqe;
336 struct wilc *wilc = vif->wilc;
338 netdev_dbg(vif->ndev, "Adding config packet ...\n");
340 netdev_dbg(vif->ndev, "Return due to clear function\n");
341 up(&wilc->cfg_event);
345 tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
347 netdev_err(vif->ndev, "Failed to allocate memory\n");
351 tqe->type = WILC_CFG_PKT;
352 tqe->buffer = buffer;
353 tqe->buffer_size = buffer_size;
354 tqe->tx_complete_func = NULL;
356 tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
358 if (wilc_wlan_txq_add_to_head(vif, tqe))
363 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
364 u32 buffer_size, wilc_tx_complete_func_t func)
366 struct txq_entry_t *tqe;
367 struct wilc_vif *vif = netdev_priv(dev);
375 tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
379 tqe->type = WILC_NET_PKT;
380 tqe->buffer = buffer;
381 tqe->buffer_size = buffer_size;
382 tqe->tx_complete_func = func;
385 tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
386 if (is_tcp_ack_filter_enabled())
387 tcp_process(dev, tqe);
388 wilc_wlan_txq_add_to_tail(dev, tqe);
389 return wilc->txq_entries;
392 int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
393 u32 buffer_size, wilc_tx_complete_func_t func)
395 struct txq_entry_t *tqe;
396 struct wilc_vif *vif = netdev_priv(dev);
404 tqe = kmalloc(sizeof(*tqe), GFP_KERNEL);
408 tqe->type = WILC_MGMT_PKT;
409 tqe->buffer = buffer;
410 tqe->buffer_size = buffer_size;
411 tqe->tx_complete_func = func;
413 tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
414 wilc_wlan_txq_add_to_tail(dev, tqe);
418 static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc)
420 struct txq_entry_t *tqe;
423 spin_lock_irqsave(&wilc->txq_spinlock, flags);
425 tqe = wilc->txq_head;
427 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
432 static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
433 struct txq_entry_t *tqe)
437 spin_lock_irqsave(&wilc->txq_spinlock, flags);
440 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
445 static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
451 mutex_lock(&wilc->rxq_cs);
452 if (!wilc->rxq_head) {
454 wilc->rxq_head = rqe;
455 wilc->rxq_tail = rqe;
457 wilc->rxq_tail->next = rqe;
459 wilc->rxq_tail = rqe;
461 wilc->rxq_entries += 1;
462 mutex_unlock(&wilc->rxq_cs);
463 return wilc->rxq_entries;
466 static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
469 if (wilc->rxq_head) {
470 struct rxq_entry_t *rqe;
472 mutex_lock(&wilc->rxq_cs);
473 rqe = wilc->rxq_head;
474 wilc->rxq_head = wilc->rxq_head->next;
475 wilc->rxq_entries -= 1;
476 mutex_unlock(&wilc->rxq_cs);
482 void chip_allow_sleep(struct wilc *wilc)
486 wilc->hif_func->hif_read_reg(wilc, 0xf0, ®);
488 wilc->hif_func->hif_write_reg(wilc, 0xf0, reg & ~BIT(0));
489 wilc->hif_func->hif_write_reg(wilc, 0xfa, 0);
491 EXPORT_SYMBOL_GPL(chip_allow_sleep);
493 void chip_wakeup(struct wilc *wilc)
495 u32 reg, clk_status_reg, trials = 0;
497 if ((wilc->io_type & 0x1) == HIF_SPI) {
499 wilc->hif_func->hif_read_reg(wilc, 1, ®);
500 wilc->hif_func->hif_write_reg(wilc, 1, reg | BIT(1));
501 wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1));
504 usleep_range(2 * 1000, 2 * 1000);
505 if ((wilc_get_chipid(wilc, true) == 0))
506 wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
508 } while ((wilc_get_chipid(wilc, true) == 0) && ((++trials % 3) == 0));
510 } while (wilc_get_chipid(wilc, true) == 0);
511 } else if ((wilc->io_type & 0x1) == HIF_SDIO) {
512 wilc->hif_func->hif_write_reg(wilc, 0xfa, 1);
514 wilc->hif_func->hif_read_reg(wilc, 0xf0, ®);
516 wilc->hif_func->hif_write_reg(wilc, 0xf0,
518 wilc->hif_func->hif_read_reg(wilc, 0xf1,
521 while (((clk_status_reg & 0x1) == 0) && (((++trials) % 3) == 0)) {
522 usleep_range(2 * 1000, 2 * 1000);
524 wilc->hif_func->hif_read_reg(wilc, 0xf1,
527 if ((clk_status_reg & 0x1) == 0)
528 wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
530 if ((clk_status_reg & 0x1) == 0) {
531 wilc->hif_func->hif_write_reg(wilc, 0xf0,
534 } while ((clk_status_reg & 0x1) == 0);
537 if (chip_ps_state == CHIP_SLEEPING_MANUAL) {
538 if (wilc_get_chipid(wilc, false) < 0x1002b0) {
541 wilc->hif_func->hif_read_reg(wilc, 0x1e1c, &val32);
543 wilc->hif_func->hif_write_reg(wilc, 0x1e1c, val32);
545 wilc->hif_func->hif_read_reg(wilc, 0x1e9c, &val32);
547 wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32);
550 chip_ps_state = CHIP_WAKEDUP;
552 EXPORT_SYMBOL_GPL(chip_wakeup);
554 void wilc_chip_sleep_manually(struct wilc *wilc)
556 if (chip_ps_state != CHIP_WAKEDUP)
558 acquire_bus(wilc, ACQUIRE_ONLY);
560 chip_allow_sleep(wilc);
561 wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1);
563 chip_ps_state = CHIP_SLEEPING_MANUAL;
564 release_bus(wilc, RELEASE_ONLY);
566 EXPORT_SYMBOL_GPL(wilc_chip_sleep_manually);
568 void host_wakeup_notify(struct wilc *wilc)
570 acquire_bus(wilc, ACQUIRE_ONLY);
571 wilc->hif_func->hif_write_reg(wilc, 0x10b0, 1);
572 release_bus(wilc, RELEASE_ONLY);
574 EXPORT_SYMBOL_GPL(host_wakeup_notify);
576 void host_sleep_notify(struct wilc *wilc)
578 acquire_bus(wilc, ACQUIRE_ONLY);
579 wilc->hif_func->hif_write_reg(wilc, 0x10ac, 1);
580 release_bus(wilc, RELEASE_ONLY);
582 EXPORT_SYMBOL_GPL(host_sleep_notify);
584 int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
592 struct txq_entry_t *tqe;
596 u32 vmm_table[WILC_VMM_TBL_SIZE];
597 struct wilc_vif *vif;
600 vif = netdev_priv(dev);
603 txb = wilc->tx_buffer;
609 wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs,
611 wilc_wlan_txq_filter_dup_tcp_ack(dev);
612 tqe = wilc_wlan_txq_get_first(wilc);
616 if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) {
617 if (tqe->type == WILC_CFG_PKT)
618 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
620 else if (tqe->type == WILC_NET_PKT)
621 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
624 vmm_sz = HOST_HDR_OFFSET;
626 vmm_sz += tqe->buffer_size;
629 vmm_sz = (vmm_sz + 4) & ~0x3;
631 if ((sum + vmm_sz) > LINUX_TX_SIZE)
634 vmm_table[i] = vmm_sz / 4;
635 if (tqe->type == WILC_CFG_PKT)
636 vmm_table[i] |= BIT(10);
637 vmm_table[i] = cpu_to_le32(vmm_table[i]);
641 tqe = wilc_wlan_txq_get_next(wilc, tqe);
652 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
655 ret = wilc->hif_func->hif_read_reg(wilc,
661 if ((reg & 0x1) == 0) {
667 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, 0);
671 } while (!wilc->quit);
678 ret = wilc->hif_func->hif_block_tx(wilc, WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
682 ret = wilc->hif_func->hif_write_reg(wilc,
689 ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, ®);
692 if ((reg >> 2) & 0x1) {
693 entries = ((reg >> 3) & 0x3f);
696 release_bus(wilc, RELEASE_ALLOW_SLEEP);
700 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x0);
708 ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, ®);
712 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg);
725 ret = WILC_TX_ERR_NO_BUF;
729 release_bus(wilc, RELEASE_ALLOW_SLEEP);
734 tqe = wilc_wlan_txq_remove_from_head(dev);
735 if (tqe && (vmm_table[i] != 0)) {
736 u32 header, buffer_offset;
738 vmm_table[i] = cpu_to_le32(vmm_table[i]);
739 vmm_sz = (vmm_table[i] & 0x3ff);
741 header = (tqe->type << 31) |
742 (tqe->buffer_size << 15) |
744 if (tqe->type == WILC_MGMT_PKT)
749 header = cpu_to_le32(header);
750 memcpy(&txb[offset], &header, 4);
751 if (tqe->type == WILC_CFG_PKT) {
752 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
753 } else if (tqe->type == WILC_NET_PKT) {
754 char *bssid = ((struct tx_complete_data *)(tqe->priv))->bssid;
756 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
757 memcpy(&txb[offset + 4], bssid, 6);
759 buffer_offset = HOST_HDR_OFFSET;
762 memcpy(&txb[offset + buffer_offset],
763 tqe->buffer, tqe->buffer_size);
767 if (tqe->tx_complete_func)
768 tqe->tx_complete_func(tqe->priv,
770 if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK &&
771 tqe->tcp_pending_ack_idx < MAX_PENDING_ACKS)
772 pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL;
779 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
781 ret = wilc->hif_func->hif_clear_int_ext(wilc, ENABLE_TX_VMM);
785 ret = wilc->hif_func->hif_block_tx_ext(wilc, 0, txb, offset);
791 release_bus(wilc, RELEASE_ALLOW_SLEEP);
795 up(&wilc->txq_add_to_head_cs);
798 *txq_count = wilc->txq_entries;
802 static void wilc_wlan_handle_rxq(struct wilc *wilc)
804 int offset = 0, size;
806 struct rxq_entry_t *rqe;
812 up(&wilc->cfg_event);
815 rqe = wilc_wlan_rxq_remove(wilc);
819 buffer = rqe->buffer;
820 size = rqe->buffer_size;
825 u32 pkt_len, pkt_offset, tp_len;
828 memcpy(&header, &buffer[offset], 4);
829 header = cpu_to_le32(header);
831 is_cfg_packet = (header >> 31) & 0x1;
832 pkt_offset = (header >> 22) & 0x1ff;
833 tp_len = (header >> 11) & 0x7ff;
834 pkt_len = header & 0x7ff;
836 if (pkt_len == 0 || tp_len == 0)
839 #define IS_MANAGMEMENT 0x100
840 #define IS_MANAGMEMENT_CALLBACK 0x080
841 #define IS_MGMT_STATUS_SUCCES 0x040
843 if (pkt_offset & IS_MANAGMEMENT) {
844 pkt_offset &= ~(IS_MANAGMEMENT |
845 IS_MANAGMEMENT_CALLBACK |
846 IS_MGMT_STATUS_SUCCES);
848 WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
850 if (!is_cfg_packet) {
852 wilc_frmw_to_linux(wilc,
858 struct wilc_cfg_rsp rsp;
860 wilc_wlan_cfg_indicate_rx(wilc, &buffer[pkt_offset + offset], pkt_len, &rsp);
861 if (rsp.type == WILC_CFG_RSP) {
862 if (wilc->cfg_seq_no == rsp.seq_no)
863 up(&wilc->cfg_event);
864 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
865 wilc_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
867 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
868 wilc_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
882 static void wilc_unknown_isr_ext(struct wilc *wilc)
884 wilc->hif_func->hif_clear_int_ext(wilc, 0);
887 static void wilc_pllupdate_isr_ext(struct wilc *wilc, u32 int_stats)
891 wilc->hif_func->hif_clear_int_ext(wilc, PLL_INT_CLR);
893 if (wilc->io_type == HIF_SDIO)
894 mdelay(WILC_PLL_TO_SDIO);
896 mdelay(WILC_PLL_TO_SPI);
898 while (!(ISWILC1000(wilc_get_chipid(wilc, true)) && --trials))
902 static void wilc_sleeptimer_isr_ext(struct wilc *wilc, u32 int_stats1)
904 wilc->hif_func->hif_clear_int_ext(wilc, SLEEP_INT_CLR);
907 static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
909 u32 offset = wilc->rx_buffer_offset;
914 struct rxq_entry_t *rqe;
916 size = (int_status & 0x7fff) << 2;
918 while (!size && retries < 10) {
919 wilc->hif_func->hif_read_size(wilc, &size);
920 size = (size & 0x7fff) << 2;
925 if (LINUX_RX_SIZE - offset < size)
929 buffer = &wilc->rx_buffer[offset];
933 wilc->hif_func->hif_clear_int_ext(wilc,
934 DATA_INT_CLR | ENABLE_RX_VMM);
935 ret = wilc->hif_func->hif_block_rx_ext(wilc, 0, buffer, size);
942 wilc->rx_buffer_offset = offset;
943 rqe = kmalloc(sizeof(*rqe), GFP_KERNEL);
945 rqe->buffer = buffer;
946 rqe->buffer_size = size;
947 wilc_wlan_rxq_add(wilc, rqe);
951 wilc_wlan_handle_rxq(wilc);
954 void wilc_handle_isr(struct wilc *wilc)
958 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
959 wilc->hif_func->hif_read_int(wilc, &int_status);
961 if (int_status & PLL_INT_EXT)
962 wilc_pllupdate_isr_ext(wilc, int_status);
964 if (int_status & DATA_INT_EXT)
965 wilc_wlan_handle_isr_ext(wilc, int_status);
967 if (int_status & SLEEP_INT_EXT)
968 wilc_sleeptimer_isr_ext(wilc, int_status);
970 if (!(int_status & (ALL_INT_EXT)))
971 wilc_unknown_isr_ext(wilc);
973 release_bus(wilc, RELEASE_ALLOW_SLEEP);
975 EXPORT_SYMBOL_GPL(wilc_handle_isr);
977 int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
981 u32 addr, size, size2, blksz;
987 dma_buffer = kmalloc(blksz, GFP_KERNEL);
995 memcpy(&addr, &buffer[offset], 4);
996 memcpy(&size, &buffer[offset + 4], 4);
997 addr = cpu_to_le32(addr);
998 size = cpu_to_le32(size);
999 acquire_bus(wilc, ACQUIRE_ONLY);
1001 while (((int)size) && (offset < buffer_size)) {
1007 memcpy(dma_buffer, &buffer[offset], size2);
1008 ret = wilc->hif_func->hif_block_tx(wilc, addr,
1017 release_bus(wilc, RELEASE_ONLY);
1023 } while (offset < buffer_size);
1031 return (ret < 0) ? ret : 0;
1034 int wilc_wlan_start(struct wilc *wilc)
1040 if (wilc->io_type == HIF_SDIO) {
1043 } else if (wilc->io_type == HIF_SPI) {
1046 acquire_bus(wilc, ACQUIRE_ONLY);
1047 ret = wilc->hif_func->hif_write_reg(wilc, WILC_VMM_CORE_CFG, reg);
1049 release_bus(wilc, RELEASE_ONLY);
1054 if (wilc->io_type == HIF_SDIO && wilc->dev_irq_num)
1055 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1057 #ifdef WILC_DISABLE_PMU
1059 reg |= WILC_HAVE_USE_PMU;
1062 #ifdef WILC_SLEEP_CLK_SRC_XO
1063 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1064 #elif defined WILC_SLEEP_CLK_SRC_RTC
1065 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1068 #ifdef WILC_EXT_PA_INV_TX_RX
1069 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1071 reg |= WILC_HAVE_USE_IRQ_AS_HOST_WAKE;
1072 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1074 reg |= WILC_HAVE_XTAL_24;
1076 #ifdef DISABLE_WILC_UART
1077 reg |= WILC_HAVE_DISABLE_WILC_UART;
1080 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_1, reg);
1082 release_bus(wilc, RELEASE_ONLY);
1087 wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT);
1089 ret = wilc->hif_func->hif_read_reg(wilc, 0x1000, &chipid);
1091 release_bus(wilc, RELEASE_ONLY);
1096 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1097 if ((reg & BIT(10)) == BIT(10)) {
1099 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1100 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1104 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1105 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1106 release_bus(wilc, RELEASE_ONLY);
1108 return (ret < 0) ? ret : 0;
1111 int wilc_wlan_stop(struct wilc *wilc)
1117 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
1119 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1121 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1126 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1128 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1133 ret = wilc->hif_func->hif_read_reg(wilc,
1134 WILC_GLB_RESET_0, ®);
1136 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1140 if ((reg & BIT(10))) {
1142 ret = wilc->hif_func->hif_write_reg(wilc,
1147 ret = wilc->hif_func->hif_read_reg(wilc,
1151 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1158 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1159 BIT(29) | BIT(30) | BIT(31));
1161 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1162 reg = (u32)~BIT(10);
1164 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1166 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1171 void wilc_wlan_cleanup(struct net_device *dev)
1173 struct txq_entry_t *tqe;
1174 struct rxq_entry_t *rqe;
1177 struct wilc_vif *vif;
1180 vif = netdev_priv(dev);
1185 tqe = wilc_wlan_txq_remove_from_head(dev);
1188 if (tqe->tx_complete_func)
1189 tqe->tx_complete_func(tqe->priv, 0);
1194 rqe = wilc_wlan_rxq_remove(wilc);
1200 kfree(wilc->rx_buffer);
1201 wilc->rx_buffer = NULL;
1202 kfree(wilc->tx_buffer);
1203 wilc->tx_buffer = NULL;
1205 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
1207 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, ®);
1209 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1211 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0,
1214 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1216 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1217 wilc->hif_func->hif_deinit(NULL);
1220 static int wilc_wlan_cfg_commit(struct wilc_vif *vif, int type,
1223 struct wilc *wilc = vif->wilc;
1224 struct wilc_cfg_frame *cfg = &wilc->cfg_frame;
1225 int total_len = wilc->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1226 int seq_no = wilc->cfg_seq_no % 256;
1227 int driver_handler = (u32)drv_handler;
1229 if (type == WILC_CFG_SET)
1230 cfg->wid_header[0] = 'W';
1232 cfg->wid_header[0] = 'Q';
1233 cfg->wid_header[1] = seq_no;
1234 cfg->wid_header[2] = (u8)total_len;
1235 cfg->wid_header[3] = (u8)(total_len >> 8);
1236 cfg->wid_header[4] = (u8)driver_handler;
1237 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1238 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1239 cfg->wid_header[7] = (u8)(driver_handler >> 24);
1240 wilc->cfg_seq_no = seq_no;
1242 if (!wilc_wlan_txq_add_cfg_pkt(vif, &cfg->wid_header[0], total_len))
1248 int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u32 wid, u8 *buffer,
1249 u32 buffer_size, int commit, u32 drv_handler)
1253 struct wilc *wilc = vif->wilc;
1255 if (wilc->cfg_frame_in_use)
1259 wilc->cfg_frame_offset = 0;
1261 offset = wilc->cfg_frame_offset;
1262 ret_size = wilc_wlan_cfg_set_wid(wilc->cfg_frame.frame, offset,
1263 (u16)wid, buffer, buffer_size);
1265 wilc->cfg_frame_offset = offset;
1268 netdev_dbg(vif->ndev,
1269 "[WILC]PACKET Commit with sequence number %d\n",
1271 netdev_dbg(vif->ndev, "Processing cfg_set()\n");
1272 wilc->cfg_frame_in_use = 1;
1274 if (wilc_wlan_cfg_commit(vif, WILC_CFG_SET, drv_handler))
1277 if (wilc_lock_timeout(wilc, &wilc->cfg_event,
1278 CFG_PKTS_TIMEOUT)) {
1279 netdev_dbg(vif->ndev, "Set Timed Out\n");
1282 wilc->cfg_frame_in_use = 0;
1283 wilc->cfg_frame_offset = 0;
1284 wilc->cfg_seq_no += 1;
1290 int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u32 wid, int commit,
1295 struct wilc *wilc = vif->wilc;
1297 if (wilc->cfg_frame_in_use)
1301 wilc->cfg_frame_offset = 0;
1303 offset = wilc->cfg_frame_offset;
1304 ret_size = wilc_wlan_cfg_get_wid(wilc->cfg_frame.frame, offset,
1307 wilc->cfg_frame_offset = offset;
1310 wilc->cfg_frame_in_use = 1;
1312 if (wilc_wlan_cfg_commit(vif, WILC_CFG_QUERY, drv_handler))
1315 if (wilc_lock_timeout(wilc, &wilc->cfg_event,
1316 CFG_PKTS_TIMEOUT)) {
1317 netdev_dbg(vif->ndev, "Get Timed Out\n");
1320 wilc->cfg_frame_in_use = 0;
1321 wilc->cfg_frame_offset = 0;
1322 wilc->cfg_seq_no += 1;
1328 int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
1332 ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
1337 int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
1343 if (mode == GET_CFG) {
1344 for (i = 0; i < count; i++) {
1345 if (!wilc_wlan_cfg_get(vif, !i,
1353 for (i = 0; i < count; i++) {
1354 wids[i].size = wilc_wlan_cfg_get_val(wids[i].id,
1358 } else if (mode == SET_CFG) {
1359 for (i = 0; i < count; i++) {
1360 if (!wilc_wlan_cfg_set(vif, !i,
1375 static u32 init_chip(struct net_device *dev)
1379 struct wilc_vif *vif;
1382 vif = netdev_priv(dev);
1385 acquire_bus(wilc, ACQUIRE_ONLY);
1387 chipid = wilc_get_chipid(wilc, true);
1389 if ((chipid & 0xfff) != 0xa0) {
1390 ret = wilc->hif_func->hif_read_reg(wilc, 0x1118, ®);
1392 netdev_err(dev, "fail read reg 0x1118\n");
1396 ret = wilc->hif_func->hif_write_reg(wilc, 0x1118, reg);
1398 netdev_err(dev, "fail write reg 0x1118\n");
1401 ret = wilc->hif_func->hif_write_reg(wilc, 0xc0000, 0x71);
1403 netdev_err(dev, "fail write reg 0xc0000\n");
1408 release_bus(wilc, RELEASE_ONLY);
1413 u32 wilc_get_chipid(struct wilc *wilc, bool update)
1419 if (chipid == 0 || update) {
1420 wilc->hif_func->hif_read_reg(wilc, 0x1000, &tempchipid);
1421 wilc->hif_func->hif_read_reg(wilc, 0x13f4, &rfrevid);
1422 if (!ISWILC1000(tempchipid)) {
1426 if (tempchipid == 0x1002a0) {
1428 tempchipid = 0x1002a1;
1429 } else if (tempchipid == 0x1002b0) {
1431 tempchipid = 0x1002b1;
1432 else if (rfrevid != 0x3)
1433 tempchipid = 0x1002b2;
1436 chipid = tempchipid;
1441 int wilc_wlan_init(struct net_device *dev)
1444 struct wilc_vif *vif = netdev_priv(dev);
1451 if (!wilc->hif_func->hif_init(wilc, false)) {
1456 if (!wilc_wlan_cfg_init(wilc_debug)) {
1461 if (!wilc->tx_buffer)
1462 wilc->tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
1464 if (!wilc->tx_buffer) {
1469 if (!wilc->rx_buffer)
1470 wilc->rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
1472 if (!wilc->rx_buffer) {
1477 if (!init_chip(dev)) {
1481 init_tcp_tracking();
1487 kfree(wilc->rx_buffer);
1488 wilc->rx_buffer = NULL;
1489 kfree(wilc->tx_buffer);
1490 wilc->tx_buffer = NULL;