Lines Matching refs:wilc

20 static inline void acquire_bus(struct wilc *wilc, enum bus_acquire acquire)
22 mutex_lock(&wilc->hif_cs);
23 if (acquire == WILC_BUS_ACQUIRE_AND_WAKEUP && wilc->power_save_mode)
24 chip_wakeup(wilc);
27 static inline void release_bus(struct wilc *wilc, enum bus_release release)
29 if (release == WILC_BUS_RELEASE_ALLOW_SLEEP && wilc->power_save_mode)
30 chip_allow_sleep(wilc);
31 mutex_unlock(&wilc->hif_cs);
34 static void wilc_wlan_txq_remove(struct wilc *wilc, u8 q_num,
38 wilc->txq_entries -= 1;
39 wilc->txq[q_num].count--;
43 wilc_wlan_txq_remove_from_head(struct wilc *wilc, u8 q_num)
48 spin_lock_irqsave(&wilc->txq_spinlock, flags);
50 if (!list_empty(&wilc->txq[q_num].txq_head.list)) {
51 tqe = list_first_entry(&wilc->txq[q_num].txq_head.list,
54 wilc->txq_entries -= 1;
55 wilc->txq[q_num].count--;
57 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
66 struct wilc *wilc = vif->wilc;
68 spin_lock_irqsave(&wilc->txq_spinlock, flags);
70 list_add_tail(&tqe->list, &wilc->txq[q_num].txq_head.list);
71 wilc->txq_entries += 1;
72 wilc->txq[q_num].count++;
74 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
76 complete(&wilc->txq_event);
83 struct wilc *wilc = vif->wilc;
85 mutex_lock(&wilc->txq_add_to_head_cs);
87 spin_lock_irqsave(&wilc->txq_spinlock, flags);
89 list_add(&tqe->list, &wilc->txq[q_num].txq_head.list);
90 wilc->txq_entries += 1;
91 wilc->txq[q_num].count++;
93 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
94 mutex_unlock(&wilc->txq_add_to_head_cs);
95 complete(&wilc->txq_event);
146 struct wilc *wilc = vif->wilc;
152 spin_lock_irqsave(&wilc->txq_spinlock, flags);
188 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
194 struct wilc *wilc = vif->wilc;
200 spin_lock_irqsave(&wilc->txq_spinlock, flags);
221 wilc_wlan_txq_remove(wilc, tqe->q_num, tqe);
239 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
242 wait_for_completion_timeout(&wilc->txq_event,
257 struct wilc *wilc = vif->wilc;
260 if (wilc->quit) {
262 complete(&wilc->cfg_event);
268 complete(&wilc->cfg_event);
286 static bool is_ac_q_limit(struct wilc *wl, u8 q_num)
333 static inline u8 ac_classify(struct wilc *wilc, struct sk_buff *skb)
372 static inline int ac_balance(struct wilc *wl, u8 *ratio)
389 static inline void ac_update_fw_ac_pkt_info(struct wilc *wl, u32 reg)
402 static inline u8 ac_change(struct wilc *wilc, u8 *ac)
405 if (wilc->txq[*ac].fw.acm == 0)
420 struct wilc *wilc;
423 wilc = vif->wilc;
425 if (wilc->quit) {
430 if (!wilc->initialized) {
448 q_num = ac_classify(wilc, tx_data->skb);
450 if (ac_change(wilc, &q_num)) {
456 if (is_ac_q_limit(wilc, q_num)) {
466 return wilc->txq_entries;
475 struct wilc *wilc;
477 wilc = vif->wilc;
479 if (wilc->quit) {
484 if (!wilc->initialized) {
506 static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc, u8 q_num)
511 spin_lock_irqsave(&wilc->txq_spinlock, flags);
513 if (!list_empty(&wilc->txq[q_num].txq_head.list))
514 tqe = list_first_entry(&wilc->txq[q_num].txq_head.list,
517 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
522 static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
528 spin_lock_irqsave(&wilc->txq_spinlock, flags);
530 if (!list_is_last(&tqe->list, &wilc->txq[q_num].txq_head.list))
534 spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
539 static void wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
541 if (wilc->quit)
544 mutex_lock(&wilc->rxq_cs);
545 list_add_tail(&rqe->list, &wilc->rxq_head.list);
546 mutex_unlock(&wilc->rxq_cs);
549 static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
553 mutex_lock(&wilc->rxq_cs);
554 if (!list_empty(&wilc->rxq_head.list)) {
555 rqe = list_first_entry(&wilc->rxq_head.list, struct rxq_entry_t,
559 mutex_unlock(&wilc->rxq_cs);
563 void chip_allow_sleep(struct wilc *wilc)
566 const struct wilc_hif_func *hif_func = wilc->hif_func;
573 if (wilc->io_type == WILC_HIF_SDIO) {
590 ret = hif_func->hif_read_reg(wilc, to_host_from_fw_reg, &reg);
600 ret = hif_func->hif_read_reg(wilc, wakeup_reg, &reg);
605 ret = hif_func->hif_write_reg(wilc, wakeup_reg, reg);
610 ret = hif_func->hif_read_reg(wilc, from_host_to_fw_reg, &reg);
615 ret = hif_func->hif_write_reg(wilc, from_host_to_fw_reg, reg);
623 void chip_wakeup(struct wilc *wilc)
630 const struct wilc_hif_func *hif_func = wilc->hif_func;
632 if (wilc->io_type == WILC_HIF_SDIO) {
649 ret = hif_func->hif_write_reg(wilc, from_host_to_fw_reg,
655 ret = hif_func->hif_write_reg(wilc, wakeup_reg,
661 ret = hif_func->hif_read_reg(wilc, clk_status_reg,
679 if (wilc->io_type == WILC_HIF_SPI)
680 wilc->hif_func->hif_reset(wilc);
684 void host_wakeup_notify(struct wilc *wilc)
686 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
687 wilc->hif_func->hif_write_reg(wilc, WILC_CORTUS_INTERRUPT_2, 1);
688 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
692 void host_sleep_notify(struct wilc *wilc)
694 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
695 wilc->hif_func->hif_write_reg(wilc, WILC_CORTUS_INTERRUPT_1, 1);
696 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
700 int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
717 u32 *vmm_table = wilc->vmm_table;
721 u8 *txb = wilc->tx_buffer;
724 if (wilc->quit)
727 if (ac_balance(wilc, ac_desired_ratio))
730 mutex_lock(&wilc->txq_add_to_head_cs);
732 srcu_idx = srcu_read_lock(&wilc->srcu);
733 list_for_each_entry_rcu(vif, &wilc->vif_list, list)
735 srcu_read_unlock(&wilc->srcu, srcu_idx);
738 tqe_q[ac] = wilc_wlan_txq_get_first(wilc, ac);
781 tqe_q[ac] = wilc_wlan_txq_get_next(wilc,
793 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
795 func = wilc->hif_func;
797 ret = func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, &reg);
802 ac_update_fw_ac_pkt_info(wilc, reg);
809 ret = func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, 0);
812 } while (!wilc->quit);
819 ret = func->hif_block_tx(wilc,
826 ret = func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x2);
831 ret = func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, &reg);
840 ret = func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x0);
848 ret = func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, &reg);
852 ret = func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg);
868 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
881 tqe = wilc_wlan_txq_remove_from_head(wilc, vmm_entries_ac[i]);
928 wilc->txq[i].fw.count += ac_pkt_num_to_chip[i];
930 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
932 ret = func->hif_clear_int_ext(wilc, ENABLE_TX_VMM);
936 ret = func->hif_block_tx_ext(wilc, 0, txb, offset);
939 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
942 mutex_unlock(&wilc->txq_add_to_head_cs);
945 *txq_count = wilc->txq_entries;
949 static void wilc_wlan_handle_rx_buff(struct wilc *wilc, u8 *buffer, int size)
971 wilc_wfi_mgmt_rx(wilc, buff_ptr, pkt_len,
975 wilc_frmw_to_host(wilc, buff_ptr, pkt_len,
982 wilc_wlan_cfg_indicate_rx(wilc, buff_ptr,
986 if (wilc->cfg_seq_no == rsp.seq_no)
987 complete(&wilc->cfg_event);
989 wilc_mac_indicate(wilc);
997 static void wilc_wlan_handle_rxq(struct wilc *wilc)
1003 while (!wilc->quit) {
1004 rqe = wilc_wlan_rxq_remove(wilc);
1010 wilc_wlan_handle_rx_buff(wilc, buffer, size);
1014 if (wilc->quit)
1015 complete(&wilc->cfg_event);
1018 static void wilc_unknown_isr_ext(struct wilc *wilc)
1020 wilc->hif_func->hif_clear_int_ext(wilc, 0);
1023 static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
1025 u32 offset = wilc->rx_buffer_offset;
1035 wilc->hif_func->hif_read_size(wilc, &size);
1046 buffer = &wilc->rx_buffer[offset];
1048 wilc->hif_func->hif_clear_int_ext(wilc, DATA_INT_CLR | ENABLE_RX_VMM);
1049 ret = wilc->hif_func->hif_block_rx_ext(wilc, 0, buffer, size);
1054 wilc->rx_buffer_offset = offset;
1061 wilc_wlan_rxq_add(wilc, rqe);
1062 wilc_wlan_handle_rxq(wilc);
1065 void wilc_handle_isr(struct wilc *wilc)
1069 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
1070 wilc->hif_func->hif_read_int(wilc, &int_status);
1073 wilc_wlan_handle_isr_ext(wilc, int_status);
1076 wilc_unknown_isr_ext(wilc);
1078 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1082 int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
1100 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
1102 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
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, &reg);
1109 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
1113 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
1122 ret = wilc->hif_func->hif_block_tx(wilc, addr,
1131 release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
1147 int wilc_wlan_start(struct wilc *wilc)
1153 if (wilc->io_type == WILC_HIF_SDIO) {
1156 } else if (wilc->io_type == WILC_HIF_SPI) {
1159 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
1160 ret = wilc->hif_func->hif_write_reg(wilc, WILC_VMM_CORE_CFG, reg);
1165 if (wilc->io_type == WILC_HIF_SDIO && wilc->dev_irq_num)
1168 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_1, reg);
1172 wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT);
1174 ret = wilc->hif_func->hif_read_reg(wilc, WILC_CHIPID, &chipid);
1178 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
1181 wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1182 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
1186 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
1187 wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
1190 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
1194 int wilc_wlan_stop(struct wilc *wilc, struct wilc_vif *vif)
1199 acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
1201 ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, &reg);
1207 ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0,
1214 ret = wilc->hif_func->hif_read_reg(wilc, WILC_FW_HOST_COMM, &reg);
1221 ret = wilc->hif_func->hif_write_reg(wilc, WILC_FW_HOST_COMM, reg);
1230 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
1241 struct wilc *wilc = vif->wilc;
1243 wilc->quit = 1;
1245 while ((tqe = wilc_wlan_txq_remove_from_head(wilc, ac))) {
1252 while ((rqe = wilc_wlan_rxq_remove(wilc)))
1255 kfree(wilc->vmm_table);
1256 wilc->vmm_table = NULL;
1257 kfree(wilc->rx_buffer);
1258 wilc->rx_buffer = NULL;
1259 kfree(wilc->tx_buffer);
1260 wilc->tx_buffer = NULL;
1261 wilc->hif_func->hif_deinit(wilc);
1267 struct wilc *wilc = vif->wilc;
1268 struct wilc_cfg_frame *cfg = &wilc->cfg_frame;
1269 int t_len = wilc->cfg_frame_offset + sizeof(struct wilc_cfg_cmd_hdr);
1276 cfg->hdr.seq_no = wilc->cfg_seq_no % 256;
1279 wilc->cfg_seq_no = cfg->hdr.seq_no;
1292 struct wilc *wilc = vif->wilc;
1294 mutex_lock(&wilc->cfg_cmd_lock);
1297 wilc->cfg_frame_offset = 0;
1299 offset = wilc->cfg_frame_offset;
1300 ret_size = wilc_wlan_cfg_set_wid(wilc->cfg_frame.frame, offset,
1303 wilc->cfg_frame_offset = offset;
1306 mutex_unlock(&wilc->cfg_cmd_lock);
1310 netdev_dbg(vif->ndev, "%s: seqno[%d]\n", __func__, wilc->cfg_seq_no);
1315 if (!wait_for_completion_timeout(&wilc->cfg_event,
1321 wilc->cfg_frame_offset = 0;
1322 wilc->cfg_seq_no += 1;
1323 mutex_unlock(&wilc->cfg_cmd_lock);
1333 struct wilc *wilc = vif->wilc;
1335 mutex_lock(&wilc->cfg_cmd_lock);
1338 wilc->cfg_frame_offset = 0;
1340 offset = wilc->cfg_frame_offset;
1341 ret_size = wilc_wlan_cfg_get_wid(wilc->cfg_frame.frame, offset, wid);
1343 wilc->cfg_frame_offset = offset;
1346 mutex_unlock(&wilc->cfg_cmd_lock);
1353 if (!wait_for_completion_timeout(&wilc->cfg_event,
1358 wilc->cfg_frame_offset = 0;
1359 wilc->cfg_seq_no += 1;
1360 mutex_unlock(&wilc->cfg_cmd_lock);
1383 wids[i].size = wilc_wlan_cfg_get_val(vif->wilc,
1411 struct wilc *wilc = vif->wilc;
1413 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
1415 chipid = wilc_get_chipid(wilc, true);
1418 ret = wilc->hif_func->hif_read_reg(wilc,
1426 ret = wilc->hif_func->hif_write_reg(wilc,
1433 ret = wilc->hif_func->hif_write_reg(wilc,
1443 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
1448 u32 wilc_get_chipid(struct wilc *wilc, bool update)
1453 if (wilc->chipid == 0 || update) {
1454 wilc->hif_func->hif_read_reg(wilc, WILC_CHIPID, &chipid);
1455 wilc->hif_func->hif_read_reg(wilc, WILC_RF_REVISION_ID,
1458 wilc->chipid = 0;
1459 return wilc->chipid;
1471 wilc->chipid = chipid;
1473 return wilc->chipid;
1480 struct wilc *wilc;
1482 wilc = vif->wilc;
1484 wilc->quit = 0;
1486 if (!wilc->hif_func->hif_is_init(wilc)) {
1487 acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
1488 ret = wilc->hif_func->hif_init(wilc, false);
1489 release_bus(wilc, WILC_BUS_RELEASE_ONLY);
1494 if (!wilc->vmm_table)
1495 wilc->vmm_table = kcalloc(WILC_VMM_TBL_SIZE, sizeof(u32), GFP_KERNEL);
1497 if (!wilc->vmm_table) {
1502 if (!wilc->tx_buffer)
1503 wilc->tx_buffer = kmalloc(WILC_TX_BUFF_SIZE, GFP_KERNEL);
1505 if (!wilc->tx_buffer) {
1510 if (!wilc->rx_buffer)
1511 wilc->rx_buffer = kmalloc(WILC_RX_BUFF_SIZE, GFP_KERNEL);
1513 if (!wilc->rx_buffer) {
1526 kfree(wilc->vmm_table);
1527 wilc->vmm_table = NULL;
1528 kfree(wilc->rx_buffer);
1529 wilc->rx_buffer = NULL;
1530 kfree(wilc->tx_buffer);
1531 wilc->tx_buffer = NULL;