1 #include "wilc_wlan_if.h"
3 #include "wilc_wfi_netdevice.h"
4 #include "wilc_wlan_cfg.h"
6 static CHIP_PS_STATE_T chip_ps_state = CHIP_WAKEDUP;
8 static inline void acquire_bus(struct wilc *wilc, BUS_ACQUIRE_T acquire)
10 mutex_lock(&wilc->hif_cs);
11 if (acquire == ACQUIRE_AND_WAKEUP)
15 static inline void release_bus(struct wilc *wilc, BUS_RELEASE_T release)
17 if (release == RELEASE_ALLOW_SLEEP)
18 chip_allow_sleep(wilc);
19 mutex_unlock(&wilc->hif_cs);
22 static void wilc_wlan_txq_remove(struct wilc *wilc, struct txq_entry_t *tqe)
24 if (tqe == wilc->txq_head) {
25 wilc->txq_head = tqe->next;
27 wilc->txq_head->prev = NULL;
28 } else if (tqe == wilc->txq_tail) {
29 wilc->txq_tail = (tqe->prev);
31 wilc->txq_tail->next = NULL;
33 tqe->prev->next = tqe->next;
34 tqe->next->prev = tqe->prev;
36 wilc->txq_entries -= 1;
39 static struct txq_entry_t *
40 wilc_wlan_txq_remove_from_head(struct net_device *dev)
42 struct txq_entry_t *tqe;
47 vif = netdev_priv(dev);
50 spin_lock_irqsave(&wilc->txq_spinlock, flags);
53 wilc->txq_head = tqe->next;
55 wilc->txq_head->prev = NULL;
57 wilc->txq_entries -= 1;
61 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
65 static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
66 struct txq_entry_t *tqe)
72 vif = netdev_priv(dev);
75 spin_lock_irqsave(&wilc->txq_spinlock, flags);
77 if (!wilc->txq_head) {
84 tqe->prev = wilc->txq_tail;
85 wilc->txq_tail->next = tqe;
88 wilc->txq_entries += 1;
90 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
95 static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
96 struct txq_entry_t *tqe)
99 struct wilc *wilc = vif->wilc;
101 if (wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs,
105 spin_lock_irqsave(&wilc->txq_spinlock, flags);
107 if (!wilc->txq_head) {
110 wilc->txq_head = tqe;
111 wilc->txq_tail = tqe;
113 tqe->next = wilc->txq_head;
115 wilc->txq_head->prev = tqe;
116 wilc->txq_head = tqe;
118 wilc->txq_entries += 1;
120 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
121 up(&wilc->txq_add_to_head_cs);
122 up(&wilc->txq_event);
127 struct ack_session_info;
128 struct ack_session_info {
136 struct pending_acks_info {
139 struct txq_entry_t *txqe;
142 #define NOT_TCP_ACK (-1)
144 #define MAX_TCP_SESSION 25
145 #define MAX_PENDING_ACKS 256
146 static struct ack_session_info ack_session_info[2 * MAX_TCP_SESSION];
147 static struct pending_acks_info pending_acks_info[MAX_PENDING_ACKS];
149 static u32 pending_base;
150 static u32 tcp_session;
151 static u32 pending_acks;
153 static inline int add_tcp_session(u32 src_prt, u32 dst_prt, u32 seq)
155 if (tcp_session < 2 * MAX_TCP_SESSION) {
156 ack_session_info[tcp_session].seq_num = seq;
157 ack_session_info[tcp_session].bigger_ack_num = 0;
158 ack_session_info[tcp_session].src_port = src_prt;
159 ack_session_info[tcp_session].dst_port = dst_prt;
165 static inline int update_tcp_session(u32 index, u32 ack)
167 if (index < 2 * MAX_TCP_SESSION &&
168 ack > ack_session_info[index].bigger_ack_num)
169 ack_session_info[index].bigger_ack_num = ack;
173 static inline int add_tcp_pending_ack(u32 ack, u32 session_index,
174 struct txq_entry_t *txqe)
176 if (pending_base + pending_acks < MAX_PENDING_ACKS) {
177 pending_acks_info[pending_base + pending_acks].ack_num = ack;
178 pending_acks_info[pending_base + pending_acks].txqe = txqe;
179 pending_acks_info[pending_base + pending_acks].session_index = session_index;
180 txqe->tcp_pending_ack_idx = pending_base + pending_acks;
186 static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
189 u8 *buffer = tqe->buffer;
190 unsigned short h_proto;
193 struct wilc_vif *vif;
196 vif = netdev_priv(dev);
199 spin_lock_irqsave(&wilc->txq_spinlock, flags);
201 eth_hdr_ptr = &buffer[0];
202 h_proto = ntohs(*((unsigned short *)ð_hdr_ptr[12]));
203 if (h_proto == ETH_P_IP) {
207 ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
208 protocol = ip_hdr_ptr[9];
210 if (protocol == 0x06) {
212 u32 IHL, total_length, data_offset;
214 tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
215 IHL = (ip_hdr_ptr[0] & 0xf) << 2;
216 total_length = ((u32)ip_hdr_ptr[2] << 8) +
218 data_offset = ((u32)tcp_hdr_ptr[12] & 0xf0) >> 2;
219 if (total_length == (IHL + data_offset)) {
222 seq_no = ((u32)tcp_hdr_ptr[4] << 24) +
223 ((u32)tcp_hdr_ptr[5] << 16) +
224 ((u32)tcp_hdr_ptr[6] << 8) +
227 ack_no = ((u32)tcp_hdr_ptr[8] << 24) +
228 ((u32)tcp_hdr_ptr[9] << 16) +
229 ((u32)tcp_hdr_ptr[10] << 8) +
230 (u32)tcp_hdr_ptr[11];
232 for (i = 0; i < tcp_session; i++) {
233 if (i < 2 * MAX_TCP_SESSION &&
234 ack_session_info[i].seq_num == seq_no) {
235 update_tcp_session(i, ack_no);
239 if (i == tcp_session)
240 add_tcp_session(0, 0, seq_no);
242 add_tcp_pending_ack(ack_no, i, tqe);
246 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
249 static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
251 struct wilc_vif *vif;
256 vif = netdev_priv(dev);
259 spin_lock_irqsave(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
260 for (i = pending_base; i < (pending_base + pending_acks); i++) {
261 if (i >= MAX_PENDING_ACKS ||
262 pending_acks_info[i].session_index >= 2 * MAX_TCP_SESSION)
264 if (pending_acks_info[i].ack_num < ack_session_info[pending_acks_info[i].session_index].bigger_ack_num) {
265 struct txq_entry_t *tqe;
267 tqe = pending_acks_info[i].txqe;
269 wilc_wlan_txq_remove(wilc, tqe);
271 if (tqe->tx_complete_func)
272 tqe->tx_complete_func(tqe->priv,
282 if (pending_base == 0)
283 pending_base = MAX_TCP_SESSION;
287 spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
289 while (dropped > 0) {
290 wilc_lock_timeout(wilc, &wilc->txq_event, 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 up(&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 wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs,
576 wilc_wlan_txq_filter_dup_tcp_ack(dev);
577 tqe = wilc_wlan_txq_get_first(wilc);
581 if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) {
582 if (tqe->type == WILC_CFG_PKT)
583 vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
585 else if (tqe->type == WILC_NET_PKT)
586 vmm_sz = ETH_ETHERNET_HDR_OFFSET;
589 vmm_sz = HOST_HDR_OFFSET;
591 vmm_sz += tqe->buffer_size;
594 vmm_sz = (vmm_sz + 4) & ~0x3;
596 if ((sum + vmm_sz) > LINUX_TX_SIZE)
599 vmm_table[i] = vmm_sz / 4;
600 if (tqe->type == WILC_CFG_PKT)
601 vmm_table[i] |= BIT(10);
602 vmm_table[i] = cpu_to_le32(vmm_table[i]);
606 tqe = wilc_wlan_txq_get_next(wilc, tqe);
616 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
619 ret = wilc->hif_func->hif_read_reg(wilc,
625 if ((reg & 0x1) == 0) {
631 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, 0);
634 } while (!wilc->quit);
641 ret = wilc->hif_func->hif_block_tx(wilc, WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
645 ret = wilc->hif_func->hif_write_reg(wilc,
652 ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, ®);
655 if ((reg >> 2) & 0x1) {
656 entries = ((reg >> 3) & 0x3f);
659 release_bus(wilc, RELEASE_ALLOW_SLEEP);
662 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x0);
670 ret = wilc->hif_func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, ®);
674 ret = wilc->hif_func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg);
686 ret = WILC_TX_ERR_NO_BUF;
690 release_bus(wilc, RELEASE_ALLOW_SLEEP);
695 tqe = wilc_wlan_txq_remove_from_head(dev);
696 if (tqe && (vmm_table[i] != 0)) {
697 u32 header, buffer_offset;
699 vmm_table[i] = cpu_to_le32(vmm_table[i]);
700 vmm_sz = (vmm_table[i] & 0x3ff);
702 header = (tqe->type << 31) |
703 (tqe->buffer_size << 15) |
705 if (tqe->type == WILC_MGMT_PKT)
710 header = cpu_to_le32(header);
711 memcpy(&txb[offset], &header, 4);
712 if (tqe->type == WILC_CFG_PKT) {
713 buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
714 } else if (tqe->type == WILC_NET_PKT) {
715 char *bssid = ((struct tx_complete_data *)(tqe->priv))->bssid;
717 buffer_offset = ETH_ETHERNET_HDR_OFFSET;
718 memcpy(&txb[offset + 4], bssid, 6);
720 buffer_offset = HOST_HDR_OFFSET;
723 memcpy(&txb[offset + buffer_offset],
724 tqe->buffer, tqe->buffer_size);
728 if (tqe->tx_complete_func)
729 tqe->tx_complete_func(tqe->priv,
731 if (tqe->tcp_pending_ack_idx != NOT_TCP_ACK &&
732 tqe->tcp_pending_ack_idx < MAX_PENDING_ACKS)
733 pending_acks_info[tqe->tcp_pending_ack_idx].txqe = NULL;
740 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
742 ret = wilc->hif_func->hif_clear_int_ext(wilc, ENABLE_TX_VMM);
746 ret = wilc->hif_func->hif_block_tx_ext(wilc, 0, txb, offset);
752 release_bus(wilc, RELEASE_ALLOW_SLEEP);
756 up(&wilc->txq_add_to_head_cs);
759 *txq_count = wilc->txq_entries;
763 static void wilc_wlan_handle_rxq(struct wilc *wilc)
765 int offset = 0, size;
767 struct rxq_entry_t *rqe;
773 up(&wilc->cfg_event);
776 rqe = wilc_wlan_rxq_remove(wilc);
780 buffer = rqe->buffer;
781 size = rqe->buffer_size;
786 u32 pkt_len, pkt_offset, tp_len;
789 memcpy(&header, &buffer[offset], 4);
790 header = cpu_to_le32(header);
792 is_cfg_packet = (header >> 31) & 0x1;
793 pkt_offset = (header >> 22) & 0x1ff;
794 tp_len = (header >> 11) & 0x7ff;
795 pkt_len = header & 0x7ff;
797 if (pkt_len == 0 || tp_len == 0)
800 #define IS_MANAGMEMENT 0x100
801 #define IS_MANAGMEMENT_CALLBACK 0x080
802 #define IS_MGMT_STATUS_SUCCES 0x040
804 if (pkt_offset & IS_MANAGMEMENT) {
805 pkt_offset &= ~(IS_MANAGMEMENT |
806 IS_MANAGMEMENT_CALLBACK |
807 IS_MGMT_STATUS_SUCCES);
809 WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
811 if (!is_cfg_packet) {
813 wilc_frmw_to_linux(wilc,
819 struct wilc_cfg_rsp rsp;
821 wilc_wlan_cfg_indicate_rx(wilc, &buffer[pkt_offset + offset], pkt_len, &rsp);
822 if (rsp.type == WILC_CFG_RSP) {
823 if (wilc->cfg_seq_no == rsp.seq_no)
824 up(&wilc->cfg_event);
825 } else if (rsp.type == WILC_CFG_RSP_STATUS) {
826 wilc_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
828 } else if (rsp.type == WILC_CFG_RSP_SCAN) {
829 wilc_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
843 static void wilc_unknown_isr_ext(struct wilc *wilc)
845 wilc->hif_func->hif_clear_int_ext(wilc, 0);
848 static void wilc_pllupdate_isr_ext(struct wilc *wilc, u32 int_stats)
852 wilc->hif_func->hif_clear_int_ext(wilc, PLL_INT_CLR);
854 if (wilc->io_type == HIF_SDIO)
855 mdelay(WILC_PLL_TO_SDIO);
857 mdelay(WILC_PLL_TO_SPI);
859 while (!(ISWILC1000(wilc_get_chipid(wilc, true)) && --trials))
863 static void wilc_sleeptimer_isr_ext(struct wilc *wilc, u32 int_stats1)
865 wilc->hif_func->hif_clear_int_ext(wilc, SLEEP_INT_CLR);
868 static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
870 u32 offset = wilc->rx_buffer_offset;
875 struct rxq_entry_t *rqe;
877 size = (int_status & 0x7fff) << 2;
879 while (!size && retries < 10) {
880 wilc->hif_func->hif_read_size(wilc, &size);
881 size = (size & 0x7fff) << 2;
886 if (LINUX_RX_SIZE - offset < size)
890 buffer = &wilc->rx_buffer[offset];
894 wilc->hif_func->hif_clear_int_ext(wilc,
895 DATA_INT_CLR | ENABLE_RX_VMM);
896 ret = wilc->hif_func->hif_block_rx_ext(wilc, 0, buffer, size);
901 wilc->rx_buffer_offset = offset;
902 rqe = kmalloc(sizeof(*rqe), GFP_KERNEL);
904 rqe->buffer = buffer;
905 rqe->buffer_size = size;
906 wilc_wlan_rxq_add(wilc, rqe);
910 wilc_wlan_handle_rxq(wilc);
913 void wilc_handle_isr(struct wilc *wilc)
917 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
918 wilc->hif_func->hif_read_int(wilc, &int_status);
920 if (int_status & PLL_INT_EXT)
921 wilc_pllupdate_isr_ext(wilc, int_status);
923 if (int_status & DATA_INT_EXT)
924 wilc_wlan_handle_isr_ext(wilc, int_status);
926 if (int_status & SLEEP_INT_EXT)
927 wilc_sleeptimer_isr_ext(wilc, int_status);
929 if (!(int_status & (ALL_INT_EXT)))
930 wilc_unknown_isr_ext(wilc);
932 release_bus(wilc, RELEASE_ALLOW_SLEEP);
934 EXPORT_SYMBOL_GPL(wilc_handle_isr);
936 int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
940 u32 addr, size, size2, blksz;
946 dma_buffer = kmalloc(blksz, GFP_KERNEL);
952 memcpy(&addr, &buffer[offset], 4);
953 memcpy(&size, &buffer[offset + 4], 4);
954 addr = cpu_to_le32(addr);
955 size = cpu_to_le32(size);
956 acquire_bus(wilc, ACQUIRE_ONLY);
958 while (((int)size) && (offset < buffer_size)) {
964 memcpy(dma_buffer, &buffer[offset], size2);
965 ret = wilc->hif_func->hif_block_tx(wilc, addr,
974 release_bus(wilc, RELEASE_ONLY);
980 } while (offset < buffer_size);
986 return (ret < 0) ? ret : 0;
989 int wilc_wlan_start(struct wilc *wilc)
995 if (wilc->io_type == HIF_SDIO) {
998 } else if (wilc->io_type == HIF_SPI) {
1001 acquire_bus(wilc, ACQUIRE_ONLY);
1002 ret = wilc->hif_func->hif_write_reg(wilc, WILC_VMM_CORE_CFG, reg);
1004 release_bus(wilc, RELEASE_ONLY);
1009 if (wilc->io_type == HIF_SDIO && wilc->dev_irq_num)
1010 reg |= WILC_HAVE_SDIO_IRQ_GPIO;
1012 #ifdef WILC_DISABLE_PMU
1014 reg |= WILC_HAVE_USE_PMU;
1017 #ifdef WILC_SLEEP_CLK_SRC_XO
1018 reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
1019 #elif defined WILC_SLEEP_CLK_SRC_RTC
1020 reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
1023 #ifdef WILC_EXT_PA_INV_TX_RX
1024 reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
1026 reg |= WILC_HAVE_USE_IRQ_AS_HOST_WAKE;
1027 reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
1029 reg |= WILC_HAVE_XTAL_24;
1031 #ifdef DISABLE_WILC_UART
1032 reg |= WILC_HAVE_DISABLE_WILC_UART;
1035 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_1, reg);
1037 release_bus(wilc, RELEASE_ONLY);
1042 wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT);
1044 ret = wilc->hif_func->hif_read_reg(wilc, 0x1000, &chipid);
1046 release_bus(wilc, RELEASE_ONLY);
1051 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1052 if ((reg & BIT(10)) == BIT(10)) {
1054 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1055 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1059 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1060 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1061 release_bus(wilc, RELEASE_ONLY);
1063 return (ret < 0) ? ret : 0;
1066 int wilc_wlan_stop(struct wilc *wilc)
1072 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
1074 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
1076 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1081 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1083 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1088 ret = wilc->hif_func->hif_read_reg(wilc,
1089 WILC_GLB_RESET_0, ®);
1091 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1095 if ((reg & BIT(10))) {
1097 ret = wilc->hif_func->hif_write_reg(wilc,
1102 ret = wilc->hif_func->hif_read_reg(wilc,
1106 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1113 reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
1114 BIT(29) | BIT(30) | BIT(31));
1116 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1117 reg = (u32)~BIT(10);
1119 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1121 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1126 void wilc_wlan_cleanup(struct net_device *dev)
1128 struct txq_entry_t *tqe;
1129 struct rxq_entry_t *rqe;
1132 struct wilc_vif *vif;
1135 vif = netdev_priv(dev);
1140 tqe = wilc_wlan_txq_remove_from_head(dev);
1143 if (tqe->tx_complete_func)
1144 tqe->tx_complete_func(tqe->priv, 0);
1149 rqe = wilc_wlan_rxq_remove(wilc);
1155 kfree(wilc->rx_buffer);
1156 wilc->rx_buffer = NULL;
1157 kfree(wilc->tx_buffer);
1158 wilc->tx_buffer = NULL;
1160 acquire_bus(wilc, ACQUIRE_AND_WAKEUP);
1162 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, ®);
1164 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1166 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0,
1169 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1171 release_bus(wilc, RELEASE_ALLOW_SLEEP);
1172 wilc->hif_func->hif_deinit(NULL);
1175 static int wilc_wlan_cfg_commit(struct wilc_vif *vif, int type,
1178 struct wilc *wilc = vif->wilc;
1179 struct wilc_cfg_frame *cfg = &wilc->cfg_frame;
1180 int total_len = wilc->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
1181 int seq_no = wilc->cfg_seq_no % 256;
1182 int driver_handler = (u32)drv_handler;
1184 if (type == WILC_CFG_SET)
1185 cfg->wid_header[0] = 'W';
1187 cfg->wid_header[0] = 'Q';
1188 cfg->wid_header[1] = seq_no;
1189 cfg->wid_header[2] = (u8)total_len;
1190 cfg->wid_header[3] = (u8)(total_len >> 8);
1191 cfg->wid_header[4] = (u8)driver_handler;
1192 cfg->wid_header[5] = (u8)(driver_handler >> 8);
1193 cfg->wid_header[6] = (u8)(driver_handler >> 16);
1194 cfg->wid_header[7] = (u8)(driver_handler >> 24);
1195 wilc->cfg_seq_no = seq_no;
1197 if (!wilc_wlan_txq_add_cfg_pkt(vif, &cfg->wid_header[0], total_len))
1203 int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
1204 u32 buffer_size, int commit, u32 drv_handler)
1208 struct wilc *wilc = vif->wilc;
1210 if (wilc->cfg_frame_in_use)
1214 wilc->cfg_frame_offset = 0;
1216 offset = wilc->cfg_frame_offset;
1217 ret_size = wilc_wlan_cfg_set_wid(wilc->cfg_frame.frame, offset,
1218 wid, buffer, buffer_size);
1220 wilc->cfg_frame_offset = offset;
1223 netdev_dbg(vif->ndev,
1224 "[WILC]PACKET Commit with sequence number %d\n",
1226 netdev_dbg(vif->ndev, "Processing cfg_set()\n");
1227 wilc->cfg_frame_in_use = 1;
1229 if (wilc_wlan_cfg_commit(vif, WILC_CFG_SET, drv_handler))
1232 if (wilc_lock_timeout(wilc, &wilc->cfg_event,
1233 CFG_PKTS_TIMEOUT)) {
1234 netdev_dbg(vif->ndev, "Set Timed Out\n");
1237 wilc->cfg_frame_in_use = 0;
1238 wilc->cfg_frame_offset = 0;
1239 wilc->cfg_seq_no += 1;
1245 int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
1250 struct wilc *wilc = vif->wilc;
1252 if (wilc->cfg_frame_in_use)
1256 wilc->cfg_frame_offset = 0;
1258 offset = wilc->cfg_frame_offset;
1259 ret_size = wilc_wlan_cfg_get_wid(wilc->cfg_frame.frame, offset, wid);
1261 wilc->cfg_frame_offset = offset;
1264 wilc->cfg_frame_in_use = 1;
1266 if (wilc_wlan_cfg_commit(vif, WILC_CFG_QUERY, drv_handler))
1269 if (wilc_lock_timeout(wilc, &wilc->cfg_event,
1270 CFG_PKTS_TIMEOUT)) {
1271 netdev_dbg(vif->ndev, "Get Timed Out\n");
1274 wilc->cfg_frame_in_use = 0;
1275 wilc->cfg_frame_offset = 0;
1276 wilc->cfg_seq_no += 1;
1282 int wilc_wlan_cfg_get_val(u16 wid, u8 *buffer, u32 buffer_size)
1284 return wilc_wlan_cfg_get_wid_value(wid, buffer, buffer_size);
1287 int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
1293 if (mode == GET_CFG) {
1294 for (i = 0; i < count; i++) {
1295 if (!wilc_wlan_cfg_get(vif, !i,
1303 for (i = 0; i < count; i++) {
1304 wids[i].size = wilc_wlan_cfg_get_val(wids[i].id,
1308 } else if (mode == SET_CFG) {
1309 for (i = 0; i < count; i++) {
1310 if (!wilc_wlan_cfg_set(vif, !i,
1325 static u32 init_chip(struct net_device *dev)
1329 struct wilc_vif *vif;
1332 vif = netdev_priv(dev);
1335 acquire_bus(wilc, ACQUIRE_ONLY);
1337 chipid = wilc_get_chipid(wilc, true);
1339 if ((chipid & 0xfff) != 0xa0) {
1340 ret = wilc->hif_func->hif_read_reg(wilc, 0x1118, ®);
1342 netdev_err(dev, "fail read reg 0x1118\n");
1346 ret = wilc->hif_func->hif_write_reg(wilc, 0x1118, reg);
1348 netdev_err(dev, "fail write reg 0x1118\n");
1351 ret = wilc->hif_func->hif_write_reg(wilc, 0xc0000, 0x71);
1353 netdev_err(dev, "fail write reg 0xc0000\n");
1358 release_bus(wilc, RELEASE_ONLY);
1363 u32 wilc_get_chipid(struct wilc *wilc, bool update)
1369 if (chipid == 0 || update) {
1370 wilc->hif_func->hif_read_reg(wilc, 0x1000, &tempchipid);
1371 wilc->hif_func->hif_read_reg(wilc, 0x13f4, &rfrevid);
1372 if (!ISWILC1000(tempchipid)) {
1376 if (tempchipid == 0x1002a0) {
1378 tempchipid = 0x1002a1;
1379 } else if (tempchipid == 0x1002b0) {
1381 tempchipid = 0x1002b1;
1382 else if (rfrevid != 0x3)
1383 tempchipid = 0x1002b2;
1386 chipid = tempchipid;
1391 int wilc_wlan_init(struct net_device *dev)
1394 struct wilc_vif *vif = netdev_priv(dev);
1401 if (!wilc->hif_func->hif_init(wilc, false)) {
1406 if (!wilc_wlan_cfg_init()) {
1411 if (!wilc->tx_buffer)
1412 wilc->tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
1414 if (!wilc->tx_buffer) {
1419 if (!wilc->rx_buffer)
1420 wilc->rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
1422 if (!wilc->rx_buffer) {
1427 if (!init_chip(dev)) {
1436 kfree(wilc->rx_buffer);
1437 wilc->rx_buffer = NULL;
1438 kfree(wilc->tx_buffer);
1439 wilc->tx_buffer = NULL;