Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2018 Redpine Signals Inc.
0003  *
0004  * Permission to use, copy, modify, and/or distribute this software for any
0005  * purpose with or without fee is hereby granted, provided that the above
0006  * copyright notice and this permission notice appear in all copies.
0007  *
0008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0011  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0013  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0014  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0015  */
0016 
0017 #include "rsi_main.h"
0018 #include "rsi_coex.h"
0019 #include "rsi_mgmt.h"
0020 #include "rsi_hal.h"
0021 
0022 static enum rsi_coex_queues rsi_coex_determine_coex_q
0023             (struct rsi_coex_ctrl_block *coex_cb)
0024 {
0025     enum rsi_coex_queues q_num = RSI_COEX_Q_INVALID;
0026 
0027     if (skb_queue_len(&coex_cb->coex_tx_qs[RSI_COEX_Q_COMMON]) > 0)
0028         q_num = RSI_COEX_Q_COMMON;
0029     if (skb_queue_len(&coex_cb->coex_tx_qs[RSI_COEX_Q_BT]) > 0)
0030         q_num = RSI_COEX_Q_BT;
0031     if (skb_queue_len(&coex_cb->coex_tx_qs[RSI_COEX_Q_WLAN]) > 0)
0032         q_num = RSI_COEX_Q_WLAN;
0033 
0034     return q_num;
0035 }
0036 
0037 static void rsi_coex_sched_tx_pkts(struct rsi_coex_ctrl_block *coex_cb)
0038 {
0039     enum rsi_coex_queues coex_q = RSI_COEX_Q_INVALID;
0040     struct sk_buff *skb;
0041 
0042     do {
0043         coex_q = rsi_coex_determine_coex_q(coex_cb);
0044         rsi_dbg(INFO_ZONE, "queue = %d\n", coex_q);
0045 
0046         if (coex_q == RSI_COEX_Q_BT) {
0047             skb = skb_dequeue(&coex_cb->coex_tx_qs[RSI_COEX_Q_BT]);
0048             rsi_send_bt_pkt(coex_cb->priv, skb);
0049         }
0050     } while (coex_q != RSI_COEX_Q_INVALID);
0051 }
0052 
0053 static void rsi_coex_scheduler_thread(struct rsi_common *common)
0054 {
0055     struct rsi_coex_ctrl_block *coex_cb =
0056         (struct rsi_coex_ctrl_block *)common->coex_cb;
0057     u32 timeout = EVENT_WAIT_FOREVER;
0058 
0059     do {
0060         rsi_wait_event(&coex_cb->coex_tx_thread.event, timeout);
0061         rsi_reset_event(&coex_cb->coex_tx_thread.event);
0062 
0063         rsi_coex_sched_tx_pkts(coex_cb);
0064     } while (atomic_read(&coex_cb->coex_tx_thread.thread_done) == 0);
0065 
0066     kthread_complete_and_exit(&coex_cb->coex_tx_thread.completion, 0);
0067 }
0068 
0069 int rsi_coex_recv_pkt(struct rsi_common *common, u8 *msg)
0070 {
0071     u8 msg_type = msg[RSI_RX_DESC_MSG_TYPE_OFFSET];
0072 
0073     switch (msg_type) {
0074     case COMMON_CARD_READY_IND:
0075         rsi_dbg(INFO_ZONE, "common card ready received\n");
0076         common->hibernate_resume = false;
0077         rsi_handle_card_ready(common, msg);
0078         break;
0079     case SLEEP_NOTIFY_IND:
0080         rsi_dbg(INFO_ZONE, "sleep notify received\n");
0081         rsi_mgmt_pkt_recv(common, msg);
0082         break;
0083     }
0084 
0085     return 0;
0086 }
0087 
0088 static inline int rsi_map_coex_q(u8 hal_queue)
0089 {
0090     switch (hal_queue) {
0091     case RSI_COEX_Q:
0092         return RSI_COEX_Q_COMMON;
0093     case RSI_WLAN_Q:
0094         return RSI_COEX_Q_WLAN;
0095     case RSI_BT_Q:
0096         return RSI_COEX_Q_BT;
0097     }
0098     return RSI_COEX_Q_INVALID;
0099 }
0100 
0101 int rsi_coex_send_pkt(void *priv, struct sk_buff *skb, u8 hal_queue)
0102 {
0103     struct rsi_common *common = (struct rsi_common *)priv;
0104     struct rsi_coex_ctrl_block *coex_cb =
0105         (struct rsi_coex_ctrl_block *)common->coex_cb;
0106     struct skb_info *tx_params = NULL;
0107     enum rsi_coex_queues coex_q;
0108     int status;
0109 
0110     coex_q = rsi_map_coex_q(hal_queue);
0111     if (coex_q == RSI_COEX_Q_INVALID) {
0112         rsi_dbg(ERR_ZONE, "Invalid coex queue\n");
0113         return -EINVAL;
0114     }
0115     if (coex_q != RSI_COEX_Q_COMMON &&
0116         coex_q != RSI_COEX_Q_WLAN) {
0117         skb_queue_tail(&coex_cb->coex_tx_qs[coex_q], skb);
0118         rsi_set_event(&coex_cb->coex_tx_thread.event);
0119         return 0;
0120     }
0121     if (common->iface_down) {
0122         tx_params =
0123             (struct skb_info *)&IEEE80211_SKB_CB(skb)->driver_data;
0124 
0125         if (!(tx_params->flags & INTERNAL_MGMT_PKT)) {
0126             rsi_indicate_tx_status(common->priv, skb, -EINVAL);
0127             return 0;
0128         }
0129     }
0130 
0131     /* Send packet to hal */
0132     if (skb->priority == MGMT_SOFT_Q)
0133         status = rsi_send_mgmt_pkt(common, skb);
0134     else
0135         status = rsi_send_data_pkt(common, skb);
0136 
0137     return status;
0138 }
0139 
0140 int rsi_coex_attach(struct rsi_common *common)
0141 {
0142     struct rsi_coex_ctrl_block *coex_cb;
0143     int cnt;
0144 
0145     coex_cb = kzalloc(sizeof(*coex_cb), GFP_KERNEL);
0146     if (!coex_cb)
0147         return -ENOMEM;
0148 
0149     common->coex_cb = (void *)coex_cb;
0150     coex_cb->priv = common;
0151 
0152     /* Initialize co-ex queues */
0153     for (cnt = 0; cnt < NUM_COEX_TX_QUEUES; cnt++)
0154         skb_queue_head_init(&coex_cb->coex_tx_qs[cnt]);
0155     rsi_init_event(&coex_cb->coex_tx_thread.event);
0156 
0157     /* Initialize co-ex thread */
0158     if (rsi_create_kthread(common,
0159                    &coex_cb->coex_tx_thread,
0160                    rsi_coex_scheduler_thread,
0161                    "Coex-Tx-Thread")) {
0162         rsi_dbg(ERR_ZONE, "%s: Unable to init tx thrd\n", __func__);
0163         return -EINVAL;
0164     }
0165     return 0;
0166 }
0167 
0168 void rsi_coex_detach(struct rsi_common *common)
0169 {
0170     struct rsi_coex_ctrl_block *coex_cb =
0171         (struct rsi_coex_ctrl_block *)common->coex_cb;
0172     int cnt;
0173 
0174     rsi_kill_thread(&coex_cb->coex_tx_thread);
0175 
0176     for (cnt = 0; cnt < NUM_COEX_TX_QUEUES; cnt++)
0177         skb_queue_purge(&coex_cb->coex_tx_qs[cnt]);
0178 
0179     kfree(coex_cb);
0180 }