|
| 1 | +/** |
| 2 | + * Copyright (c) 2018 Redpine Signals Inc. |
| 3 | + * |
| 4 | + * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | + * purpose with or without fee is hereby granted, provided that the above |
| 6 | + * copyright notice and this permission notice appear in all copies. |
| 7 | + * |
| 8 | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "rsi_main.h" |
| 18 | +#include "rsi_coex.h" |
| 19 | +#include "rsi_mgmt.h" |
| 20 | +#include "rsi_hal.h" |
| 21 | + |
| 22 | +static enum rsi_coex_queues rsi_coex_determine_coex_q |
| 23 | + (struct rsi_coex_ctrl_block *coex_cb) |
| 24 | +{ |
| 25 | + enum rsi_coex_queues q_num = RSI_COEX_Q_INVALID; |
| 26 | + |
| 27 | + if (skb_queue_len(&coex_cb->coex_tx_qs[RSI_COEX_Q_COMMON]) > 0) |
| 28 | + q_num = RSI_COEX_Q_COMMON; |
| 29 | + if (skb_queue_len(&coex_cb->coex_tx_qs[RSI_COEX_Q_BT]) > 0) |
| 30 | + q_num = RSI_COEX_Q_BT; |
| 31 | + if (skb_queue_len(&coex_cb->coex_tx_qs[RSI_COEX_Q_WLAN]) > 0) |
| 32 | + q_num = RSI_COEX_Q_WLAN; |
| 33 | + |
| 34 | + return q_num; |
| 35 | +} |
| 36 | + |
| 37 | +static void rsi_coex_sched_tx_pkts(struct rsi_coex_ctrl_block *coex_cb) |
| 38 | +{ |
| 39 | + enum rsi_coex_queues coex_q = RSI_COEX_Q_INVALID; |
| 40 | + struct sk_buff *skb; |
| 41 | + |
| 42 | + do { |
| 43 | + coex_q = rsi_coex_determine_coex_q(coex_cb); |
| 44 | + rsi_dbg(INFO_ZONE, "queue = %d\n", coex_q); |
| 45 | + |
| 46 | + if (coex_q == RSI_COEX_Q_BT) |
| 47 | + skb = skb_dequeue(&coex_cb->coex_tx_qs[RSI_COEX_Q_BT]); |
| 48 | + } while (coex_q != RSI_COEX_Q_INVALID); |
| 49 | +} |
| 50 | + |
| 51 | +static void rsi_coex_scheduler_thread(struct rsi_common *common) |
| 52 | +{ |
| 53 | + struct rsi_coex_ctrl_block *coex_cb = |
| 54 | + (struct rsi_coex_ctrl_block *)common->coex_cb; |
| 55 | + u32 timeout = EVENT_WAIT_FOREVER; |
| 56 | + |
| 57 | + do { |
| 58 | + rsi_wait_event(&coex_cb->coex_tx_thread.event, timeout); |
| 59 | + rsi_reset_event(&coex_cb->coex_tx_thread.event); |
| 60 | + |
| 61 | + rsi_coex_sched_tx_pkts(coex_cb); |
| 62 | + } while (atomic_read(&coex_cb->coex_tx_thread.thread_done) == 0); |
| 63 | + |
| 64 | + complete_and_exit(&coex_cb->coex_tx_thread.completion, 0); |
| 65 | +} |
| 66 | + |
| 67 | +int rsi_coex_recv_pkt(struct rsi_common *common, u8 *msg) |
| 68 | +{ |
| 69 | + u8 msg_type = msg[RSI_RX_DESC_MSG_TYPE_OFFSET]; |
| 70 | + |
| 71 | + switch (msg_type) { |
| 72 | + case COMMON_CARD_READY_IND: |
| 73 | + rsi_dbg(INFO_ZONE, "common card ready received\n"); |
| 74 | + rsi_handle_card_ready(common, msg); |
| 75 | + break; |
| 76 | + case SLEEP_NOTIFY_IND: |
| 77 | + rsi_dbg(INFO_ZONE, "sleep notify received\n"); |
| 78 | + rsi_mgmt_pkt_recv(common, msg); |
| 79 | + break; |
| 80 | + } |
| 81 | + |
| 82 | + return 0; |
| 83 | +} |
| 84 | + |
| 85 | +static inline int rsi_map_coex_q(u8 hal_queue) |
| 86 | +{ |
| 87 | + switch (hal_queue) { |
| 88 | + case RSI_COEX_Q: |
| 89 | + return RSI_COEX_Q_COMMON; |
| 90 | + case RSI_WLAN_Q: |
| 91 | + return RSI_COEX_Q_WLAN; |
| 92 | + case RSI_BT_Q: |
| 93 | + return RSI_COEX_Q_BT; |
| 94 | + } |
| 95 | + return RSI_COEX_Q_INVALID; |
| 96 | +} |
| 97 | + |
| 98 | +int rsi_coex_send_pkt(void *priv, struct sk_buff *skb, u8 hal_queue) |
| 99 | +{ |
| 100 | + struct rsi_common *common = (struct rsi_common *)priv; |
| 101 | + struct rsi_coex_ctrl_block *coex_cb = |
| 102 | + (struct rsi_coex_ctrl_block *)common->coex_cb; |
| 103 | + struct skb_info *tx_params = NULL; |
| 104 | + enum rsi_coex_queues coex_q; |
| 105 | + int status; |
| 106 | + |
| 107 | + coex_q = rsi_map_coex_q(hal_queue); |
| 108 | + if (coex_q == RSI_COEX_Q_INVALID) { |
| 109 | + rsi_dbg(ERR_ZONE, "Invalid coex queue\n"); |
| 110 | + return -EINVAL; |
| 111 | + } |
| 112 | + if (coex_q != RSI_COEX_Q_COMMON && |
| 113 | + coex_q != RSI_COEX_Q_WLAN) { |
| 114 | + skb_queue_tail(&coex_cb->coex_tx_qs[coex_q], skb); |
| 115 | + rsi_set_event(&coex_cb->coex_tx_thread.event); |
| 116 | + return 0; |
| 117 | + } |
| 118 | + if (common->iface_down) { |
| 119 | + tx_params = |
| 120 | + (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data; |
| 121 | + |
| 122 | + if (!(tx_params->flags & INTERNAL_MGMT_PKT)) { |
| 123 | + rsi_indicate_tx_status(common->priv, skb, -EINVAL); |
| 124 | + return 0; |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + /* Send packet to hal */ |
| 129 | + if (skb->priority == MGMT_SOFT_Q) |
| 130 | + status = rsi_send_mgmt_pkt(common, skb); |
| 131 | + else |
| 132 | + status = rsi_send_data_pkt(common, skb); |
| 133 | + |
| 134 | + return status; |
| 135 | +} |
| 136 | + |
| 137 | +int rsi_coex_attach(struct rsi_common *common) |
| 138 | +{ |
| 139 | + struct rsi_coex_ctrl_block *coex_cb; |
| 140 | + int cnt; |
| 141 | + |
| 142 | + coex_cb = kzalloc(sizeof(*coex_cb), GFP_KERNEL); |
| 143 | + if (!coex_cb) |
| 144 | + return -ENOMEM; |
| 145 | + |
| 146 | + common->coex_cb = (void *)coex_cb; |
| 147 | + coex_cb->priv = common; |
| 148 | + |
| 149 | + /* Initialize co-ex queues */ |
| 150 | + for (cnt = 0; cnt < NUM_COEX_TX_QUEUES; cnt++) |
| 151 | + skb_queue_head_init(&coex_cb->coex_tx_qs[cnt]); |
| 152 | + rsi_init_event(&coex_cb->coex_tx_thread.event); |
| 153 | + |
| 154 | + /* Initialize co-ex thread */ |
| 155 | + if (rsi_create_kthread(common, |
| 156 | + &coex_cb->coex_tx_thread, |
| 157 | + rsi_coex_scheduler_thread, |
| 158 | + "Coex-Tx-Thread")) { |
| 159 | + rsi_dbg(ERR_ZONE, "%s: Unable to init tx thrd\n", __func__); |
| 160 | + return -EINVAL; |
| 161 | + } |
| 162 | + return 0; |
| 163 | +} |
| 164 | + |
| 165 | +void rsi_coex_detach(struct rsi_common *common) |
| 166 | +{ |
| 167 | + struct rsi_coex_ctrl_block *coex_cb = |
| 168 | + (struct rsi_coex_ctrl_block *)common->coex_cb; |
| 169 | + int cnt; |
| 170 | + |
| 171 | + rsi_kill_thread(&coex_cb->coex_tx_thread); |
| 172 | + |
| 173 | + for (cnt = 0; cnt < NUM_COEX_TX_QUEUES; cnt++) |
| 174 | + skb_queue_purge(&coex_cb->coex_tx_qs[cnt]); |
| 175 | + |
| 176 | + kfree(coex_cb); |
| 177 | +} |
0 commit comments