1 #include <linux/completion.h>
2 #include "wilc_wlan_if.h"
4 #include "wilc_wfi_netdevice.h"
5 #include "wilc_wlan_cfg.h"
7 static CHIP_PS_STATE_T chip_ps_state = CHIP_WAKEDUP;
9 static inline void acquire_bus(struct wilc *wilc, BUS_ACQUIRE_T acquire)
11 mutex_lock(&wilc->hif_cs);
12 if (acquire == ACQUIRE_AND_WAKEUP)
16 static inline void release_bus(struct wilc *wilc, BUS_RELEASE_T release)
18 if (release == RELEASE_ALLOW_SLEEP)
19 chip_allow_sleep(wilc);
20 mutex_unlock(&wilc->hif_cs);
23 static void wilc_wlan_txq_remove(struct wilc *wilc, struct txq_entry_t *tqe)
25 if (tqe == wilc->txq_head) {
26 wilc->txq_head = tqe->next;
28 wilc->txq_head->prev = NULL;
29 } else if (tqe == wilc->txq_tail) {
30 wilc->txq_tail = (tqe->prev);
32 wilc->txq_tail->next = NULL;
34 tqe->prev->next = tqe->next;
35 tqe->next->prev = tqe->prev;
37 wilc->txq_entries -= 1;
40 static struct txq_entry_t *
41 wilc_wlan_txq_remove_from_head(struct net_device *dev)
43 struct txq_entry_t *tqe;
48 vif = netdev_priv(dev);
51 spin_lock_irqsave(&wilc->txq_spinlock, flags);
54 wilc->txq_head = tqe->next;
56 wilc->txq_head->prev = NULL;
58 wilc->txq_entries -= 1;
62 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
66 static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
67 struct txq_entry_t *tqe)
73 vif = netdev_priv(dev);
76 spin_lock_irqsave(&wilc->txq_spinlock, flags);
78 if (!wilc->txq_head) {
85 tqe->prev = wilc->txq_tail;
86 wilc->txq_tail->next = tqe;
89 wilc->txq_entries += 1;
91 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
93 complete(&wilc->txq_event);
96 static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
97 struct txq_entry_t *tqe)
100 struct wilc *wilc = vif->wilc;
102 mutex_lock(&wilc->txq_add_to_head_cs);
104 spin_lock_irqsave(&wilc->txq_spinlock, flags);
106 if (!wilc->txq_head) {
109 wilc->txq_head = tqe;
110 wilc->txq_tail = tqe;
112 tqe->next = wilc->txq_head;
114 wilc->txq_head->prev = tqe;
115 wilc->txq_head = tqe;
117 wilc->txq_entries += 1;
119 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
120 mutex_unlock(&wilc->txq_add_to_head_cs);
121 complete(&wilc->txq_event);
126 struct ack_session_info;
127 struct ack_session_info {
135 struct pending_acks_info {
138 struct txq_entry_t *txqe;
141 #define NOT_TCP_ACK (-1)
143 #define MAX_TCP_SESSION 25
144 #define MAX_PENDING_ACKS 256
145 static struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
146 static struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS];
148 static u32 pending_base;
149 static u32 tcp_session;
150 static u32 pending_acks;
152 static inline int add_tcp_session(u32 src_prt, u32 dst_prt, u32 seq)
154 if (tcp_session < 2 * MAX_TCP_SESSION) {
155 ack_session_info[tcp_session].seq_num = seq;
156 ack_session_info[tcp_session].bigger_ack_num = 0;
157 ack_session_info[tcp_session].src_port = src_prt;
158 ack_session_info[tcp_session].dst_port = dst_prt;
164 static inline int update_tcp_session(u32 index, u32 ack)
166 if (index < 2 * MAX_TCP_SESSION &&
167 ack > ack_session_info[index].bigger_ack_num)
168 ack_session_info[index].bigger_ack_num = ack;
172 static inline int add_tcp_pending_ack(u32 ack, u32 session_index,
173 struct txq_entry_t *txqe)
175 if (pending_base + pending_acks < MAX_PENDING_ACKS) {
176 pending_acks_info[pending_base + pending_acks].ack_num = ack;
177 pending_acks_info[pending_base + pending_acks].txqe = txqe;
178 pending_acks_info[pending_base + pending_acks].session_index = session_index;
179 txqe->tcp_pending_ack_idx = pending_base + pending_acks;
185 static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
188 u8 *buffer = tqe->buffer;
189 unsigned short h_proto;
192 struct wilc_vif *vif;
195 vif = netdev_priv(dev);
198 spin_lock_irqsave(&wilc->txq_spinlock, flags);
200 eth_hdr_ptr = &buffer[0];
201 h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
202 if (h_proto == ETH_P_IP) {
206 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
207 protocol = ip_hdr_ptr[9];
209 if (protocol == 0x06) {
211 u32 IHL, total_length, data_offset;
213 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
214 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
215 total_length = ((u32)ip_hdr_ptr[2] << 8) +
217 data_offset = ((u32)tcp_hdr_ptr[12] & 0xf0) >> 2;
218 if (total_length == (IHL + data_offset)) {
221 seq_no = ((u32)tcp_hdr_ptr[4] << 24) +
222 ((u32)tcp_hdr_ptr[5] << 16) +
223 ((u32)tcp_hdr_ptr[6] << 8) +
226 ack_no = ((u32)tcp_hdr_ptr[8] << 24) +
227 ((u32)tcp_hdr_ptr[9] << 16) +
228 ((u32)tcp_hdr_ptr[10] << 8) +
229 (u32)tcp_hdr_ptr[11];
231 for (i = 0; i < tcp_session; i++) {
232 if (i < 2 * MAX_TCP_SESSION &&
233 ack_session_info[i].seq_num == seq_no) {
234 update_tcp_session(i, ack_no);
238 if (i == tcp_session)
239 add_tcp_session(0, 0, seq_no);
241 add_tcp_pending_ack(ack_no, i, tqe);
245 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
248 static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
250 struct wilc_vif *vif;
255 vif = netdev_priv(dev);
258 spin_lock_irqsave(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
259 for (i = pending_base; i < (pending_base + pending_acks); i++) {
260 if (i >= MAX_PENDING_ACKS ||
261 pending_acks_info[i].session_index >= 2 * MAX_TCP_SESSION)
263 if (pending_acks_info[i].ack_num < ack_session_info[pending_acks_info[i].session_index].bigger_ack_num) {
264 struct txq_entry_t *tqe;
266 tqe = pending_acks_info[i].txqe;
268 wilc_wlan_txq_remove(wilc, tqe);
270 if (tqe->tx_complete_func)
271 tqe->tx_complete_func(tqe->priv,
281 if (pending_base == 0)
282 pending_base = MAX_TCP_SESSION;
286 spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
288 while (dropped > 0) {
289 wait_for_completion_timeout(&wilc->txq_event,
290 msecs_to_jiffies(1));
299 void wilc_enable_tcp_ack_filter(bool value)
304 static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
307 struct txq_entry_t *tqe;
308 struct wilc *wilc = vif->wilc;
310 netdev_dbg(vif->ndev, "Adding config packet ...\n");
312 netdev_dbg(vif->ndev, "Return due to clear function\n");
313 complete(&wilc->cfg_event);
317 tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
321 tqe->type = WILC_CFG_PKT;
322 tqe->buffer = buffer;
323 tqe->buffer_size = buffer_size;
324 tqe->tx_complete_func = NULL;
326 tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
328 if (wilc_wlan_txq_add_to_head(vif, tqe)) {
336 int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
337 u32 buffer_size, wilc_tx_complete_func_t func)
339 struct txq_entry_t *tqe;
340 struct wilc_vif *vif = netdev_priv(dev);
348 tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
352 tqe->type = WILC_NET_PKT;
353 tqe->buffer = buffer;
354 tqe->buffer_size = buffer_size;
355 tqe->tx_complete_func = func;
358 tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
360 tcp_process(dev, tqe);
361 wilc_wlan_txq_add_to_tail(dev, tqe);
362 return wilc->txq_entries;
365 int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
366 u32 buffer_size, wilc_tx_complete_func_t func)
368 struct txq_entry_t *tqe;
369 struct wilc_vif *vif = netdev_priv(dev);
377 tqe = kmalloc(sizeof(*tqe), GFP_KERNEL);
381 tqe->type = WILC_MGMT_PKT;
382 tqe->buffer = buffer;
383 tqe->buffer_size = buffer_size;
384 tqe->tx_complete_func = func;
386 tqe->tcp_pending_ack_idx = NOT_TCP_ACK;
387 wilc_wlan_txq_add_to_tail(dev, tqe);
391 static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc)
393 struct txq_entry_t *tqe;
396 spin_lock_irqsave(&wilc->txq_spinlock, flags);
398 tqe = wilc->txq_head;
400 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
405 static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
406 struct txq_entry_t *tqe)
410 spin_lock_irqsave(&wilc->txq_spinlock, flags);
413 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
418 static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
423 mutex_lock(&wilc->rxq_cs);
424 if (!wilc->rxq_head) {
426 wilc->rxq_head = rqe;
427 wilc->rxq_tail = rqe;
429 wilc->rxq_tail->next = rqe;
431 wilc->rxq_tail = rqe;
433 wilc->rxq_entries += 1;
434 mutex_unlock(&wilc->rxq_cs);
435 return wilc->rxq_entries;
438 static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
440 if (wilc->rxq_head) {
441 struct rxq_entry_t *rqe;
443 mutex_lock(&wilc->rxq_cs);
444 rqe = wilc->rxq_head;
445 wilc->rxq_head = wilc->rxq_head->next;
446 wilc->rxq_entries -= 1;
447 mutex_unlock(&wilc->rxq_cs);
453 void chip_allow_sleep(struct wilc *wilc)
457 wilc->hif_func->hif_read_reg(wilc, 0xf0, ®);
459 wilc->hif_func->hif_write_reg(wilc, 0xf0, reg & ~BIT(0));
460 wilc->hif_func->hif_write_reg(wilc, 0xfa, 0);
462 EXPORT_SYMBOL_GPL(chip_allow_sleep);
464 void chip_wakeup(struct wilc *wilc)
466 u32 reg, clk_status_reg;
468 if ((wilc->io_type & 0x1) == HIF_SPI) {
470 wilc->hif_func->hif_read_reg(wilc, 1, ®);
471 wilc->hif_func->hif_write_reg(wilc, 1, reg | BIT(1));
472 wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1));
475 usleep_range(2 * 1000, 2 * 1000);
476 wilc_get_chipid(wilc, true);
477 } while (wilc_get_chipid(wilc, true) == 0);
478 } while (wilc_get_chipid(wilc, true) == 0);
479 } else if ((wilc->io_type & 0x1) == HIF_SDIO) {
480 wilc->hif_func->hif_write_reg(wilc, 0xfa, 1);
482 wilc->hif_func->hif_read_reg(wilc, 0xf0, ®);
484 wilc->hif_func->hif_write_reg(wilc, 0xf0,
486 wilc->hif_func->hif_read_reg(wilc, 0xf1,
489 while ((clk_status_reg & 0x1) == 0) {
490 usleep_range(2 * 1000, 2 * 1000);
492 wilc->hif_func->hif_read_reg(wilc, 0xf1,
495 if ((clk_status_reg & 0x1) == 0) {
496 wilc->hif_func->hif_write_reg(wilc, 0xf0,
499 } while ((clk_status_reg & 0x1) == 0);
502 if (chip_ps_state == CHIP_SLEEPING_MANUAL) {
503 if (wilc_get_chipid(wilc, false) < 0x1002b0) {
506 wilc->hif_func->hif_read_reg(wilc, 0x1e1c, &val32);
508 wilc->hif_func->hif_write_reg(wilc, 0x1e1c, val32);
510 wilc->hif_func->hif_read_reg(wilc, 0x1e9c, &val32);
512 wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32);
515 chip_ps_state = CHIP_WAKEDUP;
517 EXPORT_SYMBOL_GPL(chip_wakeup);
519 void wilc_chip_sleep_manually(struct wilc *wilc)
521 if (chip_ps_state != CHIP_WAKEDUP)
523 acquire_bus(wilc, ACQUIRE_ONLY);
525 chip_allow_sleep(wilc);
526 wilc->hif_func->hif_write_reg(wilc, 0x10a8, 1);
528 chip_ps_state = CHIP_SLEEPING_MANUAL;
529 release_bus(wilc, RELEASE_ONLY);
531 EXPORT_SYMBOL_GPL(wilc_chip_sleep_manually);
533 void host_wakeup_notify(struct wilc *wilc)
535 acquire_bus(wilc, ACQUIRE_ONLY);
536 wilc->hif_func->hif_write_reg(wilc, 0x10b0, 1);
537 release_bus(wilc, RELEASE_ONLY);
539 EXPORT_SYMBOL_GPL(host_wakeup_notify);
541 void host_sleep_notify(struct wilc *wilc)
543 acquire_bus(wilc, ACQUIRE_ONLY);
544 wilc->hif_func->hif_write_reg(wilc, 0x10ac, 1);
545 release_bus(wilc, RELEASE_ONLY);
547 EXPORT_SYMBOL_GPL(host_sleep_notify);
549 int wilc_wlan_handle_txq(struct net_device *dev, u32 *txq_count)
557 struct txq_entry_t *tqe;
561 u32 vmm_table[WILC_VMM_TBL_SIZE];
562 struct wilc_vif *vif;
565 vif = netdev_priv(dev);
568 txb = wilc->tx_buffer;
574 mutex_lock(&wilc->txq_add_to_head_cs);
575 wilc_wlan_txq_filter_dup_tcp_ack(dev);
576 tqe = wilc_wlan_txq_get_first(wilc);
580 if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) {
581 if (tqe->type == WILC_CFG_PKT)
582 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
584 else if (tqe->type == WILC_NET_PKT)
585 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
588 vmm_sz = HOST_HDR_OFFSET;
590 vmm_sz += tqe->buffer_size;
593 vmm_sz = (vmm_sz + 4) & ~0x3;
595 if ((sum + vmm_sz) > LINUX_TX_SIZE)
598 vmm_table[i] = vmm_sz / 4;
599 if (tqe->type == WILC_CFG_PKT)
600 vmm_table[i] |= BIT(10);
601 vmm_table[i] = cpu_to_le32(vmm_table[i]);
605 tqe = wilc_wlan_txq_get_next(wilc, tqe);
615 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
618 ret = wilc->hif_func->hif_read_reg(wilc,
624 if ((reg & 0x1) == 0)
630 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, 0);
633 } while (!wilc->quit);
640 ret = wilc->hif_func->hif_block_tx(wilc, WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
644 ret = wilc->hif_func->hif_write_reg(wilc,
651 ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, ®);
654 if ((reg >> 2) & 0x1) {
655 entries = ((reg >> 3) & 0x3f);
658 release_bus(wilc, RELEASE_ALLOW_SLEEP);
661 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x0);
669 ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, ®);
673 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg);
685 ret = WILC_TX_ERR_NO_BUF;
689 release_bus(wilc, RELEASE_ALLOW_SLEEP);
694 tqe = wilc_wlan_txq_remove_from_head(dev);
695 if (tqe && (vmm_table[i] != 0)) {
696 u32 header, buffer_offset;
698 vmm_table[i] = cpu_to_le32(vmm_table[i]);
699 vmm_sz = (vmm_table[i] & 0x3ff);
701 header = (tqe->type << 31) |
702 (tqe->buffer_size << 15) |
704 if (tqe->type == WILC_MGMT_PKT)
709 header = cpu_to_le32(header);
710 memcpy(&txb[offset], &header, 4);
711 if (tqe->type == WILC_CFG_PKT) {
712 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
713 } else if (tqe->type == WILC_NET_PKT) {
714 char *bssid = ((struct tx_complete_data *)(tqe->priv))->bssid;
716 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
717 memcpy(&txb[offset + 8], bssid, 6);
719 buffer_offset = HOST_HDR_OFFSET;
722 memcpy(&txb[offset + buffer_offset],
723 tqe->buffer, tqe->buffer_size);
727 if (tqe->tx_complete_func)
728 tqe->tx_complete_func(tqe->priv,
730 if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK &&
731 tqe->tcp_pending_ack_idx < MAX_PENDING_ACKS)
732 pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL;
739 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
741 ret = wilc->hif_func->hif_clear_int_ext(wilc, ENABLE_TX_VMM);
745 ret = wilc->hif_func->hif_block_tx_ext(wilc, 0, txb, offset);
751 release_bus(wilc, RELEASE_ALLOW_SLEEP);
755 mutex_unlock(&wilc->txq_add_to_head_cs);
758 *txq_count = wilc->txq_entries;
762 static void wilc_wlan_handle_rxq(struct wilc *wilc)
764 int offset = 0, size;
766 struct rxq_entry_t *rqe;
772 complete(&wilc->cfg_event);
775 rqe = wilc_wlan_rxq_remove(wilc);
779 buffer = rqe->buffer;
780 size = rqe->buffer_size;
785 u32 pkt_len, pkt_offset, tp_len;
788 memcpy(&header, &buffer[offset], 4);
789 header = cpu_to_le32(header);
791 is_cfg_packet = (header >> 31) & 0x1;
792 pkt_offset = (header >> 22) & 0x1ff;
793 tp_len = (header >> 11) & 0x7ff;
794 pkt_len = header & 0x7ff;
796 if (pkt_len == 0 || tp_len == 0)
799 #define IS_MANAGMEMENT 0x100
800 #define IS_MANAGMEMENT_CALLBACK 0x080
801 #define IS_MGMT_STATUS_SUCCES 0x040
803 if (pkt_offset & IS_MANAGMEMENT) {
804 pkt_offset &= ~(IS_MANAGMEMENT |
805 IS_MANAGMEMENT_CALLBACK |
806 IS_MGMT_STATUS_SUCCES);
808 WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
810 if (!is_cfg_packet) {
812 wilc_frmw_to_linux(wilc,
818 struct wilc_cfg_rsp rsp;
820 wilc_wlan_cfg_indicate_rx(wilc, &buffer[pkt_offset + offset], pkt_len, &rsp);
821 if (rsp.type == WILC_CFG_RSP) {
822 if (wilc->cfg_seq_no == rsp.seq_no)
823 complete(&wilc->cfg_event);
824 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
825 wilc_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
827 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
828 wilc_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
842 static void wilc_unknown_isr_ext(struct wilc *wilc)
844 wilc->hif_func->hif_clear_int_ext(wilc, 0);
847 static void wilc_pllupdate_isr_ext(struct wilc *wilc, u32 int_stats)
851 wilc->hif_func->hif_clear_int_ext(wilc, PLL_INT_CLR);
853 if (wilc->io_type == HIF_SDIO)
854 mdelay(WILC_PLL_TO_SDIO);
856 mdelay(WILC_PLL_TO_SPI);
858 while (!(ISWILC1000(wilc_get_chipid(wilc, true)) && --trials))
862 static void wilc_sleeptimer_isr_ext(struct wilc *wilc, u32 int_stats1)
864 wilc->hif_func->hif_clear_int_ext(wilc, SLEEP_INT_CLR);
867 static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
869 u32 offset = wilc->rx_buffer_offset;
874 struct rxq_entry_t *rqe;
876 size = (int_status & 0x7fff) << 2;
878 while (!size && retries < 10) {
879 wilc->hif_func->hif_read_size(wilc, &size);
880 size = (size & 0x7fff) << 2;
885 if (LINUX_RX_SIZE - offset < size)
889 buffer = &wilc->rx_buffer[offset];
893 wilc->hif_func->hif_clear_int_ext(wilc,
894 DATA_INT_CLR | ENABLE_RX_VMM);
895 ret = wilc->hif_func->hif_block_rx_ext(wilc, 0, buffer, size);
900 wilc->rx_buffer_offset = offset;
901 rqe = kmalloc(sizeof(*rqe), GFP_KERNEL);
903 rqe->buffer = buffer;
904 rqe->buffer_size = size;
905 wilc_wlan_rxq_add(wilc, rqe);
909 wilc_wlan_handle_rxq(wilc);
912 void wilc_handle_isr(struct wilc *wilc)
916 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
917 wilc->hif_func->hif_read_int(wilc, &int_status);
919 if (int_status & PLL_INT_EXT)
920 wilc_pllupdate_isr_ext(wilc, int_status);
922 if (int_status & DATA_INT_EXT)
923 wilc_wlan_handle_isr_ext(wilc, int_status);
925 if (int_status & SLEEP_INT_EXT)
926 wilc_sleeptimer_isr_ext(wilc, int_status);
928 if (!(int_status & (ALL_INT_EXT)))
929 wilc_unknown_isr_ext(wilc);
931 release_bus(wilc, RELEASE_ALLOW_SLEEP);
933 EXPORT_SYMBOL_GPL(wilc_handle_isr);
935 int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
939 u32 addr, size, size2, blksz;
945 dma_buffer = kmalloc(blksz, GFP_KERNEL);
951 memcpy(&addr, &buffer[offset], 4);
952 memcpy(&size, &buffer[offset + 4], 4);
953 addr = cpu_to_le32(addr);
954 size = cpu_to_le32(size);
955 acquire_bus(wilc, ACQUIRE_ONLY);
957 while (((int)size) && (offset < buffer_size)) {
963 memcpy(dma_buffer, &buffer[offset], size2);
964 ret = wilc->hif_func->hif_block_tx(wilc, addr,
973 release_bus(wilc, RELEASE_ONLY);
979 } while (offset < buffer_size);
985 return (ret < 0) ? ret : 0;
988 int wilc_wlan_start(struct wilc *wilc)
994 if (wilc->io_type == HIF_SDIO) {
997 } else if (wilc->io_type == HIF_SPI) {
1000 acquire_bus(wilc, ACQUIRE_ONLY);
1001 ret = wilc->hif_func->hif_write_reg(wilc, WILC_VMM_CORE_CFG, reg);
1003 release_bus(wilc, RELEASE_ONLY);
1007 if (wilc->io_type == HIF_SDIO && wilc->dev_irq_num)
1008 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1010 #ifdef WILC_DISABLE_PMU
1012 reg |= WILC_HAVE_USE_PMU;
1015 #ifdef WILC_SLEEP_CLK_SRC_XO
1016 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1017 #elif defined WILC_SLEEP_CLK_SRC_RTC
1018 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1021 #ifdef WILC_EXT_PA_INV_TX_RX
1022 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1024 reg |= WILC_HAVE_USE_IRQ_AS_HOST_WAKE;
1025 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1027 reg |= WILC_HAVE_XTAL_24;
1029 #ifdef DISABLE_WILC_UART
1030 reg |= WILC_HAVE_DISABLE_WILC_UART;
1033 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_1, reg);
1035 release_bus(wilc, RELEASE_ONLY);
1039 wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT);
1041 ret = wilc->hif_func->hif_read_reg(wilc, 0x1000, &chipid);
1043 release_bus(wilc, RELEASE_ONLY);
1047 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1048 if ((reg & BIT(10)) == BIT(10)) {
1050 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1051 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1055 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1056 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1057 release_bus(wilc, RELEASE_ONLY);
1059 return (ret < 0) ? ret : 0;
1062 int wilc_wlan_stop(struct wilc *wilc)
1068 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
1070 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1072 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1077 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1079 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1084 ret = wilc->hif_func->hif_read_reg(wilc,
1085 WILC_GLB_RESET_0, ®);
1087 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1091 if ((reg & BIT(10))) {
1093 ret = wilc->hif_func->hif_write_reg(wilc,
1098 ret = wilc->hif_func->hif_read_reg(wilc,
1102 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1109 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1110 BIT(29) | BIT(30) | BIT(31));
1112 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1113 reg = (u32)~BIT(10);
1115 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1117 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1122 void wilc_wlan_cleanup(struct net_device *dev)
1124 struct txq_entry_t *tqe;
1125 struct rxq_entry_t *rqe;
1128 struct wilc_vif *vif;
1131 vif = netdev_priv(dev);
1136 tqe = wilc_wlan_txq_remove_from_head(dev);
1139 if (tqe->tx_complete_func)
1140 tqe->tx_complete_func(tqe->priv, 0);
1145 rqe = wilc_wlan_rxq_remove(wilc);
1151 kfree(wilc->rx_buffer);
1152 wilc->rx_buffer = NULL;
1153 kfree(wilc->tx_buffer);
1154 wilc->tx_buffer = NULL;
1156 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
1158 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, ®);
1160 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1162 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0,
1165 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1167 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1168 wilc->hif_func->hif_deinit(NULL);
1171 static int wilc_wlan_cfg_commit(struct wilc_vif *vif, int type,
1174 struct wilc *wilc = vif->wilc;
1175 struct wilc_cfg_frame *cfg = &wilc->cfg_frame;
1176 int total_len = wilc->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1177 int seq_no = wilc->cfg_seq_no % 256;
1178 int driver_handler = (u32)drv_handler;
1180 if (type == WILC_CFG_SET)
1181 cfg->wid_header[0] = 'W';
1183 cfg->wid_header[0] = 'Q';
1184 cfg->wid_header[1] = seq_no;
1185 cfg->wid_header[2] = (u8)total_len;
1186 cfg->wid_header[3] = (u8)(total_len >> 8);
1187 cfg->wid_header[4] = (u8)driver_handler;
1188 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1189 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1190 cfg->wid_header[7] = (u8)(driver_handler >> 24);
1191 wilc->cfg_seq_no = seq_no;
1193 if (!wilc_wlan_txq_add_cfg_pkt(vif, &cfg->wid_header[0], total_len))
1199 int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
1200 u32 buffer_size, int commit, u32 drv_handler)
1204 struct wilc *wilc = vif->wilc;
1206 if (wilc->cfg_frame_in_use)
1210 wilc->cfg_frame_offset = 0;
1212 offset = wilc->cfg_frame_offset;
1213 ret_size = wilc_wlan_cfg_set_wid(wilc->cfg_frame.frame, offset,
1214 wid, buffer, buffer_size);
1216 wilc->cfg_frame_offset = offset;
1219 netdev_dbg(vif->ndev,
1220 "[WILC]PACKET Commit with sequence number %d\n",
1222 netdev_dbg(vif->ndev, "Processing cfg_set()\n");
1223 wilc->cfg_frame_in_use = 1;
1225 if (wilc_wlan_cfg_commit(vif, WILC_CFG_SET, drv_handler))
1228 if (!wait_for_completion_timeout(&wilc->cfg_event,
1229 msecs_to_jiffies(CFG_PKTS_TIMEOUT))) {
1230 netdev_dbg(vif->ndev, "Set Timed Out\n");
1234 wilc->cfg_frame_in_use = 0;
1235 wilc->cfg_frame_offset = 0;
1236 wilc->cfg_seq_no += 1;
1242 int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
1247 struct wilc *wilc = vif->wilc;
1249 if (wilc->cfg_frame_in_use)
1253 wilc->cfg_frame_offset = 0;
1255 offset = wilc->cfg_frame_offset;
1256 ret_size = wilc_wlan_cfg_get_wid(wilc->cfg_frame.frame, offset, wid);
1258 wilc->cfg_frame_offset = offset;
1261 wilc->cfg_frame_in_use = 1;
1263 if (wilc_wlan_cfg_commit(vif, WILC_CFG_QUERY, drv_handler))
1266 if (!wait_for_completion_timeout(&wilc->cfg_event,
1267 msecs_to_jiffies(CFG_PKTS_TIMEOUT))) {
1268 netdev_dbg(vif->ndev, "Get Timed Out\n");
1271 wilc->cfg_frame_in_use = 0;
1272 wilc->cfg_frame_offset = 0;
1273 wilc->cfg_seq_no += 1;
1279 int wilc_wlan_cfg_get_val(u16 wid, u8 *buffer, u32 buffer_size)
1281 return wilc_wlan_cfg_get_wid_value(wid, buffer, buffer_size);
1284 int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
1290 if (mode == GET_CFG) {
1291 for (i = 0; i < count; i++) {
1292 if (!wilc_wlan_cfg_get(vif, !i,
1300 for (i = 0; i < count; i++) {
1301 wids[i].size = wilc_wlan_cfg_get_val(wids[i].id,
1305 } else if (mode == SET_CFG) {
1306 for (i = 0; i < count; i++) {
1307 if (!wilc_wlan_cfg_set(vif, !i,
1322 static u32 init_chip(struct net_device *dev)
1326 struct wilc_vif *vif;
1329 vif = netdev_priv(dev);
1332 acquire_bus(wilc, ACQUIRE_ONLY);
1334 chipid = wilc_get_chipid(wilc, true);
1336 if ((chipid & 0xfff) != 0xa0) {
1337 ret = wilc->hif_func->hif_read_reg(wilc, 0x1118, ®);
1339 netdev_err(dev, "fail read reg 0x1118\n");
1343 ret = wilc->hif_func->hif_write_reg(wilc, 0x1118, reg);
1345 netdev_err(dev, "fail write reg 0x1118\n");
1348 ret = wilc->hif_func->hif_write_reg(wilc, 0xc0000, 0x71);
1350 netdev_err(dev, "fail write reg 0xc0000\n");
1355 release_bus(wilc, RELEASE_ONLY);
1360 u32 wilc_get_chipid(struct wilc *wilc, bool update)
1366 if (chipid == 0 || update) {
1367 wilc->hif_func->hif_read_reg(wilc, 0x1000, &tempchipid);
1368 wilc->hif_func->hif_read_reg(wilc, 0x13f4, &rfrevid);
1369 if (!ISWILC1000(tempchipid)) {
1373 if (tempchipid == 0x1002a0) {
1375 tempchipid = 0x1002a1;
1376 } else if (tempchipid == 0x1002b0) {
1378 tempchipid = 0x1002b1;
1379 else if (rfrevid != 0x3)
1380 tempchipid = 0x1002b2;
1383 chipid = tempchipid;
1388 int wilc_wlan_init(struct net_device *dev)
1391 struct wilc_vif *vif = netdev_priv(dev);
1398 if (!wilc->hif_func->hif_init(wilc, false)) {
1403 if (!wilc_wlan_cfg_init()) {
1408 if (!wilc->tx_buffer)
1409 wilc->tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
1411 if (!wilc->tx_buffer) {
1416 if (!wilc->rx_buffer)
1417 wilc->rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
1419 if (!wilc->rx_buffer) {
1424 if (!init_chip(dev)) {
1433 kfree(wilc->rx_buffer);
1434 wilc->rx_buffer = NULL;
1435 kfree(wilc->tx_buffer);
1436 wilc->tx_buffer = NULL;