1470d48c1SLee Jones /*
2dad0d04fSFariya Fatima * Copyright (c) 2014 Redpine Signals Inc.
3dad0d04fSFariya Fatima *
4dad0d04fSFariya Fatima * Permission to use, copy, modify, and/or distribute this software for any
5dad0d04fSFariya Fatima * purpose with or without fee is hereby granted, provided that the above
6dad0d04fSFariya Fatima * copyright notice and this permission notice appear in all copies.
7dad0d04fSFariya Fatima *
8dad0d04fSFariya Fatima * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9dad0d04fSFariya Fatima * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10dad0d04fSFariya Fatima * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11dad0d04fSFariya Fatima * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12dad0d04fSFariya Fatima * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13dad0d04fSFariya Fatima * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14dad0d04fSFariya Fatima * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15dad0d04fSFariya Fatima */
16dad0d04fSFariya Fatima
175fe1b76aSJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
185fe1b76aSJoe Perches
19dad0d04fSFariya Fatima #include <linux/module.h>
20dad0d04fSFariya Fatima #include <linux/firmware.h>
21716b840cSSiva Rebbagondla #include <net/rsi_91x.h>
22dad0d04fSFariya Fatima #include "rsi_mgmt.h"
23dad0d04fSFariya Fatima #include "rsi_common.h"
242108df3cSPrameela Rani Garnepudi #include "rsi_coex.h"
25192524a4SPavani Muthyala #include "rsi_hal.h"
26f1cb3476SZekun Shen #include "rsi_usb.h"
27dad0d04fSFariya Fatima
28dad0d04fSFariya Fatima u32 rsi_zone_enabled = /* INFO_ZONE |
29dad0d04fSFariya Fatima INIT_ZONE |
30dad0d04fSFariya Fatima MGMT_TX_ZONE |
31dad0d04fSFariya Fatima MGMT_RX_ZONE |
32dad0d04fSFariya Fatima DATA_TX_ZONE |
33dad0d04fSFariya Fatima DATA_RX_ZONE |
34dad0d04fSFariya Fatima FSM_ZONE |
35dad0d04fSFariya Fatima ISR_ZONE | */
36dad0d04fSFariya Fatima ERR_ZONE |
37dad0d04fSFariya Fatima 0;
38dad0d04fSFariya Fatima EXPORT_SYMBOL_GPL(rsi_zone_enabled);
39dad0d04fSFariya Fatima
40716b840cSSiva Rebbagondla #ifdef CONFIG_RSI_COEX
41716b840cSSiva Rebbagondla static struct rsi_proto_ops g_proto_ops = {
42716b840cSSiva Rebbagondla .coex_send_pkt = rsi_coex_send_pkt,
43716b840cSSiva Rebbagondla .get_host_intf = rsi_get_host_intf,
44716b840cSSiva Rebbagondla .set_bt_context = rsi_set_bt_context,
45716b840cSSiva Rebbagondla };
46716b840cSSiva Rebbagondla #endif
47716b840cSSiva Rebbagondla
48dad0d04fSFariya Fatima /**
492df3b0b7SJohn W. Linville * rsi_dbg() - This function outputs informational messages.
502df3b0b7SJohn W. Linville * @zone: Zone of interest for output message.
512df3b0b7SJohn W. Linville * @fmt: printf-style format for output message.
522df3b0b7SJohn W. Linville *
532df3b0b7SJohn W. Linville * Return: none
542df3b0b7SJohn W. Linville */
rsi_dbg(u32 zone,const char * fmt,...)552df3b0b7SJohn W. Linville void rsi_dbg(u32 zone, const char *fmt, ...)
562df3b0b7SJohn W. Linville {
572df3b0b7SJohn W. Linville struct va_format vaf;
582df3b0b7SJohn W. Linville va_list args;
592df3b0b7SJohn W. Linville
602df3b0b7SJohn W. Linville va_start(args, fmt);
612df3b0b7SJohn W. Linville
622df3b0b7SJohn W. Linville vaf.fmt = fmt;
632df3b0b7SJohn W. Linville vaf.va = &args;
642df3b0b7SJohn W. Linville
652df3b0b7SJohn W. Linville if (zone & rsi_zone_enabled)
662df3b0b7SJohn W. Linville pr_info("%pV", &vaf);
672df3b0b7SJohn W. Linville va_end(args);
682df3b0b7SJohn W. Linville }
692df3b0b7SJohn W. Linville EXPORT_SYMBOL_GPL(rsi_dbg);
702df3b0b7SJohn W. Linville
opmode_str(int oper_mode)71192524a4SPavani Muthyala static char *opmode_str(int oper_mode)
72192524a4SPavani Muthyala {
73192524a4SPavani Muthyala switch (oper_mode) {
74898b2553SPrameela Rani Garnepudi case DEV_OPMODE_WIFI_ALONE:
75192524a4SPavani Muthyala return "Wi-Fi alone";
76898b2553SPrameela Rani Garnepudi case DEV_OPMODE_BT_ALONE:
77898b2553SPrameela Rani Garnepudi return "BT EDR alone";
78898b2553SPrameela Rani Garnepudi case DEV_OPMODE_BT_LE_ALONE:
79898b2553SPrameela Rani Garnepudi return "BT LE alone";
80898b2553SPrameela Rani Garnepudi case DEV_OPMODE_BT_DUAL:
81898b2553SPrameela Rani Garnepudi return "BT Dual";
82898b2553SPrameela Rani Garnepudi case DEV_OPMODE_STA_BT:
83898b2553SPrameela Rani Garnepudi return "Wi-Fi STA + BT EDR";
84898b2553SPrameela Rani Garnepudi case DEV_OPMODE_STA_BT_LE:
85898b2553SPrameela Rani Garnepudi return "Wi-Fi STA + BT LE";
86898b2553SPrameela Rani Garnepudi case DEV_OPMODE_STA_BT_DUAL:
87898b2553SPrameela Rani Garnepudi return "Wi-Fi STA + BT DUAL";
88898b2553SPrameela Rani Garnepudi case DEV_OPMODE_AP_BT:
89898b2553SPrameela Rani Garnepudi return "Wi-Fi AP + BT EDR";
90898b2553SPrameela Rani Garnepudi case DEV_OPMODE_AP_BT_DUAL:
91898b2553SPrameela Rani Garnepudi return "Wi-Fi AP + BT DUAL";
92192524a4SPavani Muthyala }
93192524a4SPavani Muthyala
94192524a4SPavani Muthyala return "Unknown";
95192524a4SPavani Muthyala }
96192524a4SPavani Muthyala
rsi_print_version(struct rsi_common * common)97192524a4SPavani Muthyala void rsi_print_version(struct rsi_common *common)
98192524a4SPavani Muthyala {
99192524a4SPavani Muthyala rsi_dbg(ERR_ZONE, "================================================\n");
100192524a4SPavani Muthyala rsi_dbg(ERR_ZONE, "================ RSI Version Info ==============\n");
101192524a4SPavani Muthyala rsi_dbg(ERR_ZONE, "================================================\n");
102192524a4SPavani Muthyala rsi_dbg(ERR_ZONE, "FW Version\t: %d.%d.%d\n",
103192524a4SPavani Muthyala common->lmac_ver.major, common->lmac_ver.minor,
104192524a4SPavani Muthyala common->lmac_ver.release_num);
105192524a4SPavani Muthyala rsi_dbg(ERR_ZONE, "Operating mode\t: %d [%s]",
106192524a4SPavani Muthyala common->oper_mode, opmode_str(common->oper_mode));
107192524a4SPavani Muthyala rsi_dbg(ERR_ZONE, "Firmware file\t: %s", common->priv->fw_file_name);
108192524a4SPavani Muthyala rsi_dbg(ERR_ZONE, "================================================\n");
109192524a4SPavani Muthyala }
110192524a4SPavani Muthyala
1112df3b0b7SJohn W. Linville /**
112dad0d04fSFariya Fatima * rsi_prepare_skb() - This function prepares the skb.
113dad0d04fSFariya Fatima * @common: Pointer to the driver private structure.
114dad0d04fSFariya Fatima * @buffer: Pointer to the packet data.
115dad0d04fSFariya Fatima * @pkt_len: Length of the packet.
116dad0d04fSFariya Fatima * @extended_desc: Extended descriptor.
117dad0d04fSFariya Fatima *
118dad0d04fSFariya Fatima * Return: Successfully skb.
119dad0d04fSFariya Fatima */
rsi_prepare_skb(struct rsi_common * common,u8 * buffer,u32 pkt_len,u8 extended_desc)120dad0d04fSFariya Fatima static struct sk_buff *rsi_prepare_skb(struct rsi_common *common,
121dad0d04fSFariya Fatima u8 *buffer,
122dad0d04fSFariya Fatima u32 pkt_len,
123dad0d04fSFariya Fatima u8 extended_desc)
124dad0d04fSFariya Fatima {
125dad0d04fSFariya Fatima struct sk_buff *skb = NULL;
126dad0d04fSFariya Fatima u8 payload_offset;
127dad0d04fSFariya Fatima
128dad0d04fSFariya Fatima if (WARN(!pkt_len, "%s: Dummy pkt received", __func__))
129dad0d04fSFariya Fatima return NULL;
130dad0d04fSFariya Fatima
131dad0d04fSFariya Fatima if (pkt_len > (RSI_RCV_BUFFER_LEN * 4)) {
132dad0d04fSFariya Fatima rsi_dbg(ERR_ZONE, "%s: Pkt size > max rx buf size %d\n",
133dad0d04fSFariya Fatima __func__, pkt_len);
134dad0d04fSFariya Fatima pkt_len = RSI_RCV_BUFFER_LEN * 4;
135dad0d04fSFariya Fatima }
136dad0d04fSFariya Fatima
137dad0d04fSFariya Fatima pkt_len -= extended_desc;
138dad0d04fSFariya Fatima skb = dev_alloc_skb(pkt_len + FRAME_DESC_SZ);
139dad0d04fSFariya Fatima if (skb == NULL)
140dad0d04fSFariya Fatima return NULL;
141dad0d04fSFariya Fatima
142dad0d04fSFariya Fatima payload_offset = (extended_desc + FRAME_DESC_SZ);
143dad0d04fSFariya Fatima skb_put(skb, pkt_len);
144dad0d04fSFariya Fatima memcpy((skb->data), (buffer + payload_offset), skb->len);
145dad0d04fSFariya Fatima
146dad0d04fSFariya Fatima return skb;
147dad0d04fSFariya Fatima }
148dad0d04fSFariya Fatima
149dad0d04fSFariya Fatima /**
150dad0d04fSFariya Fatima * rsi_read_pkt() - This function reads frames from the card.
151dad0d04fSFariya Fatima * @common: Pointer to the driver private structure.
152a8433a92SLee Jones * @rx_pkt: Received pkt.
153dad0d04fSFariya Fatima * @rcv_pkt_len: Received pkt length. In case of USB it is 0.
154dad0d04fSFariya Fatima *
155dad0d04fSFariya Fatima * Return: 0 on success, -1 on failure.
156dad0d04fSFariya Fatima */
rsi_read_pkt(struct rsi_common * common,u8 * rx_pkt,s32 rcv_pkt_len)1571100f81bSPrameela Rani Garnepudi int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len)
158dad0d04fSFariya Fatima {
159dad0d04fSFariya Fatima u8 *frame_desc = NULL, extended_desc = 0;
160dad0d04fSFariya Fatima u32 index, length = 0, queueno = 0;
161dad0d04fSFariya Fatima u16 actual_length = 0, offset;
162dad0d04fSFariya Fatima struct sk_buff *skb = NULL;
163716b840cSSiva Rebbagondla #ifdef CONFIG_RSI_COEX
164716b840cSSiva Rebbagondla u8 bt_pkt_type;
165716b840cSSiva Rebbagondla #endif
166dad0d04fSFariya Fatima
167dad0d04fSFariya Fatima index = 0;
168dad0d04fSFariya Fatima do {
1691100f81bSPrameela Rani Garnepudi frame_desc = &rx_pkt[index];
170dad0d04fSFariya Fatima actual_length = *(u16 *)&frame_desc[0];
171dad0d04fSFariya Fatima offset = *(u16 *)&frame_desc[2];
172f1cb3476SZekun Shen if (!rcv_pkt_len && offset >
173f1cb3476SZekun Shen RSI_MAX_RX_USB_PKT_SIZE - FRAME_DESC_SZ)
174f1cb3476SZekun Shen goto fail;
175dad0d04fSFariya Fatima
176dad0d04fSFariya Fatima queueno = rsi_get_queueno(frame_desc, offset);
177dad0d04fSFariya Fatima length = rsi_get_length(frame_desc, offset);
17861f2a6fcSPrameela Rani Garnepudi
17961f2a6fcSPrameela Rani Garnepudi /* Extended descriptor is valid for WLAN queues only */
18061f2a6fcSPrameela Rani Garnepudi if (queueno == RSI_WIFI_DATA_Q || queueno == RSI_WIFI_MGMT_Q)
18161f2a6fcSPrameela Rani Garnepudi extended_desc = rsi_get_extended_desc(frame_desc,
18261f2a6fcSPrameela Rani Garnepudi offset);
183dad0d04fSFariya Fatima
184dad0d04fSFariya Fatima switch (queueno) {
18561f2a6fcSPrameela Rani Garnepudi case RSI_COEX_Q:
1862108df3cSPrameela Rani Garnepudi #ifdef CONFIG_RSI_COEX
1872108df3cSPrameela Rani Garnepudi if (common->coex_mode > 1)
1882108df3cSPrameela Rani Garnepudi rsi_coex_recv_pkt(common, frame_desc + offset);
1892108df3cSPrameela Rani Garnepudi else
1902108df3cSPrameela Rani Garnepudi #endif
1912108df3cSPrameela Rani Garnepudi rsi_mgmt_pkt_recv(common,
1922108df3cSPrameela Rani Garnepudi (frame_desc + offset));
19361f2a6fcSPrameela Rani Garnepudi break;
1942108df3cSPrameela Rani Garnepudi
195dad0d04fSFariya Fatima case RSI_WIFI_DATA_Q:
196dad0d04fSFariya Fatima skb = rsi_prepare_skb(common,
197dad0d04fSFariya Fatima (frame_desc + offset),
198dad0d04fSFariya Fatima length,
199dad0d04fSFariya Fatima extended_desc);
200dad0d04fSFariya Fatima if (skb == NULL)
201dad0d04fSFariya Fatima goto fail;
202dad0d04fSFariya Fatima
203dad0d04fSFariya Fatima rsi_indicate_pkt_to_os(common, skb);
204dad0d04fSFariya Fatima break;
205dad0d04fSFariya Fatima
206dad0d04fSFariya Fatima case RSI_WIFI_MGMT_Q:
207dad0d04fSFariya Fatima rsi_mgmt_pkt_recv(common, (frame_desc + offset));
208dad0d04fSFariya Fatima break;
209dad0d04fSFariya Fatima
210716b840cSSiva Rebbagondla #ifdef CONFIG_RSI_COEX
211716b840cSSiva Rebbagondla case RSI_BT_MGMT_Q:
212716b840cSSiva Rebbagondla case RSI_BT_DATA_Q:
213716b840cSSiva Rebbagondla #define BT_RX_PKT_TYPE_OFST 14
214716b840cSSiva Rebbagondla #define BT_CARD_READY_IND 0x89
215716b840cSSiva Rebbagondla bt_pkt_type = frame_desc[offset + BT_RX_PKT_TYPE_OFST];
216716b840cSSiva Rebbagondla if (bt_pkt_type == BT_CARD_READY_IND) {
217716b840cSSiva Rebbagondla rsi_dbg(INFO_ZONE, "BT Card ready recvd\n");
2189b14ed6eSMartin Fuzzey if (common->fsm_state == FSM_MAC_INIT_DONE)
2199b14ed6eSMartin Fuzzey rsi_attach_bt(common);
2209b14ed6eSMartin Fuzzey else
2219b14ed6eSMartin Fuzzey common->bt_defer_attach = true;
222716b840cSSiva Rebbagondla } else {
223716b840cSSiva Rebbagondla if (common->bt_adapter)
224716b840cSSiva Rebbagondla rsi_bt_ops.recv_pkt(common->bt_adapter,
225716b840cSSiva Rebbagondla frame_desc + offset);
226716b840cSSiva Rebbagondla }
227716b840cSSiva Rebbagondla break;
228716b840cSSiva Rebbagondla #endif
229716b840cSSiva Rebbagondla
230dad0d04fSFariya Fatima default:
231dad0d04fSFariya Fatima rsi_dbg(ERR_ZONE, "%s: pkt from invalid queue: %d\n",
232dad0d04fSFariya Fatima __func__, queueno);
233dad0d04fSFariya Fatima goto fail;
234dad0d04fSFariya Fatima }
235dad0d04fSFariya Fatima
236dad0d04fSFariya Fatima index += actual_length;
237dad0d04fSFariya Fatima rcv_pkt_len -= actual_length;
238dad0d04fSFariya Fatima } while (rcv_pkt_len > 0);
239dad0d04fSFariya Fatima
240dad0d04fSFariya Fatima return 0;
241dad0d04fSFariya Fatima fail:
242dad0d04fSFariya Fatima return -EINVAL;
243dad0d04fSFariya Fatima }
244dad0d04fSFariya Fatima EXPORT_SYMBOL_GPL(rsi_read_pkt);
245dad0d04fSFariya Fatima
246dad0d04fSFariya Fatima /**
247dad0d04fSFariya Fatima * rsi_tx_scheduler_thread() - This function is a kernel thread to send the
248dad0d04fSFariya Fatima * packets to the device.
249dad0d04fSFariya Fatima * @common: Pointer to the driver private structure.
250dad0d04fSFariya Fatima *
251dad0d04fSFariya Fatima * Return: None.
252dad0d04fSFariya Fatima */
rsi_tx_scheduler_thread(struct rsi_common * common)253dad0d04fSFariya Fatima static void rsi_tx_scheduler_thread(struct rsi_common *common)
254dad0d04fSFariya Fatima {
255dad0d04fSFariya Fatima struct rsi_hw *adapter = common->priv;
256dad0d04fSFariya Fatima u32 timeout = EVENT_WAIT_FOREVER;
257dad0d04fSFariya Fatima
258dad0d04fSFariya Fatima do {
259dad0d04fSFariya Fatima if (adapter->determine_event_timeout)
260dad0d04fSFariya Fatima timeout = adapter->determine_event_timeout(adapter);
261dad0d04fSFariya Fatima rsi_wait_event(&common->tx_thread.event, timeout);
262dad0d04fSFariya Fatima rsi_reset_event(&common->tx_thread.event);
263dad0d04fSFariya Fatima
264dad0d04fSFariya Fatima if (common->init_done)
265dad0d04fSFariya Fatima rsi_core_qos_processor(common);
266dad0d04fSFariya Fatima } while (atomic_read(&common->tx_thread.thread_done) == 0);
267cead1855SEric W. Biederman kthread_complete_and_exit(&common->tx_thread.completion, 0);
268dad0d04fSFariya Fatima }
269dad0d04fSFariya Fatima
2702108df3cSPrameela Rani Garnepudi #ifdef CONFIG_RSI_COEX
rsi_get_host_intf(void * priv)2712108df3cSPrameela Rani Garnepudi enum rsi_host_intf rsi_get_host_intf(void *priv)
2722108df3cSPrameela Rani Garnepudi {
273*db2be1a0SWu Yunchuan struct rsi_common *common = priv;
2742108df3cSPrameela Rani Garnepudi
2752108df3cSPrameela Rani Garnepudi return common->priv->rsi_host_intf;
2762108df3cSPrameela Rani Garnepudi }
277716b840cSSiva Rebbagondla
rsi_set_bt_context(void * priv,void * bt_context)278716b840cSSiva Rebbagondla void rsi_set_bt_context(void *priv, void *bt_context)
279716b840cSSiva Rebbagondla {
280*db2be1a0SWu Yunchuan struct rsi_common *common = priv;
281716b840cSSiva Rebbagondla
282716b840cSSiva Rebbagondla common->bt_adapter = bt_context;
283716b840cSSiva Rebbagondla }
2842108df3cSPrameela Rani Garnepudi #endif
2852108df3cSPrameela Rani Garnepudi
rsi_attach_bt(struct rsi_common * common)2869b14ed6eSMartin Fuzzey void rsi_attach_bt(struct rsi_common *common)
2879b14ed6eSMartin Fuzzey {
2889b14ed6eSMartin Fuzzey #ifdef CONFIG_RSI_COEX
2899b14ed6eSMartin Fuzzey if (rsi_bt_ops.attach(common, &g_proto_ops))
2909b14ed6eSMartin Fuzzey rsi_dbg(ERR_ZONE,
2919b14ed6eSMartin Fuzzey "Failed to attach BT module\n");
2929b14ed6eSMartin Fuzzey #endif
2939b14ed6eSMartin Fuzzey }
2949b14ed6eSMartin Fuzzey
295dad0d04fSFariya Fatima /**
296dad0d04fSFariya Fatima * rsi_91x_init() - This function initializes os interface operations.
297470d48c1SLee Jones * @oper_mode: One of DEV_OPMODE_*.
298dad0d04fSFariya Fatima *
299dad0d04fSFariya Fatima * Return: Pointer to the adapter structure on success, NULL on failure .
300dad0d04fSFariya Fatima */
rsi_91x_init(u16 oper_mode)301898b2553SPrameela Rani Garnepudi struct rsi_hw *rsi_91x_init(u16 oper_mode)
302dad0d04fSFariya Fatima {
303dad0d04fSFariya Fatima struct rsi_hw *adapter = NULL;
304dad0d04fSFariya Fatima struct rsi_common *common = NULL;
305dad0d04fSFariya Fatima u8 ii = 0;
306dad0d04fSFariya Fatima
307dad0d04fSFariya Fatima adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
308dad0d04fSFariya Fatima if (!adapter)
309dad0d04fSFariya Fatima return NULL;
310dad0d04fSFariya Fatima
311dad0d04fSFariya Fatima adapter->priv = kzalloc(sizeof(*common), GFP_KERNEL);
312dad0d04fSFariya Fatima if (adapter->priv == NULL) {
313dad0d04fSFariya Fatima rsi_dbg(ERR_ZONE, "%s: Failed in allocation of memory\n",
314dad0d04fSFariya Fatima __func__);
315dad0d04fSFariya Fatima kfree(adapter);
316dad0d04fSFariya Fatima return NULL;
317dad0d04fSFariya Fatima } else {
318dad0d04fSFariya Fatima common = adapter->priv;
319dad0d04fSFariya Fatima common->priv = adapter;
320dad0d04fSFariya Fatima }
321dad0d04fSFariya Fatima
322dad0d04fSFariya Fatima for (ii = 0; ii < NUM_SOFT_QUEUES; ii++)
323dad0d04fSFariya Fatima skb_queue_head_init(&common->tx_queue[ii]);
324dad0d04fSFariya Fatima
325dad0d04fSFariya Fatima rsi_init_event(&common->tx_thread.event);
326dad0d04fSFariya Fatima mutex_init(&common->mutex);
327cb164535SKarun Eagalapati mutex_init(&common->tx_lock);
3286c409cadSKarun Eagalapati mutex_init(&common->rx_lock);
3292108df3cSPrameela Rani Garnepudi mutex_init(&common->tx_bus_mutex);
330dad0d04fSFariya Fatima
331dad0d04fSFariya Fatima if (rsi_create_kthread(common,
332dad0d04fSFariya Fatima &common->tx_thread,
333dad0d04fSFariya Fatima rsi_tx_scheduler_thread,
334dad0d04fSFariya Fatima "Tx-Thread")) {
335dad0d04fSFariya Fatima rsi_dbg(ERR_ZONE, "%s: Unable to init tx thrd\n", __func__);
336dad0d04fSFariya Fatima goto err;
337dad0d04fSFariya Fatima }
338dad0d04fSFariya Fatima
339ce86893fSKarun Eagalapati rsi_default_ps_params(adapter);
3407fdcb8e1SPrameela Rani Garnepudi init_bgscan_params(common);
341ce86893fSKarun Eagalapati spin_lock_init(&adapter->ps_lock);
342dfefb9f8SKees Cook timer_setup(&common->roc_timer, rsi_roc_timeout, 0);
343b6c8d06cSKarun Eagalapati init_completion(&common->wlan_init_completion);
344898b2553SPrameela Rani Garnepudi adapter->device_model = RSI_DEV_9113;
345898b2553SPrameela Rani Garnepudi common->oper_mode = oper_mode;
3462108df3cSPrameela Rani Garnepudi
347898b2553SPrameela Rani Garnepudi /* Determine coex mode */
348898b2553SPrameela Rani Garnepudi switch (common->oper_mode) {
349898b2553SPrameela Rani Garnepudi case DEV_OPMODE_STA_BT_DUAL:
350898b2553SPrameela Rani Garnepudi case DEV_OPMODE_STA_BT:
351898b2553SPrameela Rani Garnepudi case DEV_OPMODE_STA_BT_LE:
352898b2553SPrameela Rani Garnepudi case DEV_OPMODE_BT_ALONE:
353898b2553SPrameela Rani Garnepudi case DEV_OPMODE_BT_LE_ALONE:
354898b2553SPrameela Rani Garnepudi case DEV_OPMODE_BT_DUAL:
355898b2553SPrameela Rani Garnepudi common->coex_mode = 2;
356898b2553SPrameela Rani Garnepudi break;
357898b2553SPrameela Rani Garnepudi case DEV_OPMODE_AP_BT_DUAL:
358898b2553SPrameela Rani Garnepudi case DEV_OPMODE_AP_BT:
359898b2553SPrameela Rani Garnepudi common->coex_mode = 4;
360898b2553SPrameela Rani Garnepudi break;
361898b2553SPrameela Rani Garnepudi case DEV_OPMODE_WIFI_ALONE:
362898b2553SPrameela Rani Garnepudi common->coex_mode = 1;
363898b2553SPrameela Rani Garnepudi break;
364898b2553SPrameela Rani Garnepudi default:
365898b2553SPrameela Rani Garnepudi common->oper_mode = 1;
366898b2553SPrameela Rani Garnepudi common->coex_mode = 1;
367898b2553SPrameela Rani Garnepudi }
368898b2553SPrameela Rani Garnepudi rsi_dbg(INFO_ZONE, "%s: oper_mode = %d, coex_mode = %d\n",
369898b2553SPrameela Rani Garnepudi __func__, common->oper_mode, common->coex_mode);
370898b2553SPrameela Rani Garnepudi
3712108df3cSPrameela Rani Garnepudi adapter->device_model = RSI_DEV_9113;
3722108df3cSPrameela Rani Garnepudi #ifdef CONFIG_RSI_COEX
3732108df3cSPrameela Rani Garnepudi if (common->coex_mode > 1) {
3742108df3cSPrameela Rani Garnepudi if (rsi_coex_attach(common)) {
3752108df3cSPrameela Rani Garnepudi rsi_dbg(ERR_ZONE, "Failed to init coex module\n");
376515e7184SZiyang Xuan rsi_kill_thread(&common->tx_thread);
3772108df3cSPrameela Rani Garnepudi goto err;
3782108df3cSPrameela Rani Garnepudi }
3792108df3cSPrameela Rani Garnepudi }
3802108df3cSPrameela Rani Garnepudi #endif
3812108df3cSPrameela Rani Garnepudi
3822ddd82eeSAmol Hanwate common->init_done = true;
383dad0d04fSFariya Fatima return adapter;
384dad0d04fSFariya Fatima
385dad0d04fSFariya Fatima err:
386dad0d04fSFariya Fatima kfree(common);
387dad0d04fSFariya Fatima kfree(adapter);
388dad0d04fSFariya Fatima return NULL;
389dad0d04fSFariya Fatima }
390dad0d04fSFariya Fatima EXPORT_SYMBOL_GPL(rsi_91x_init);
391dad0d04fSFariya Fatima
392dad0d04fSFariya Fatima /**
393dad0d04fSFariya Fatima * rsi_91x_deinit() - This function de-intializes os intf operations.
394dad0d04fSFariya Fatima * @adapter: Pointer to the adapter structure.
395dad0d04fSFariya Fatima *
396dad0d04fSFariya Fatima * Return: None.
397dad0d04fSFariya Fatima */
rsi_91x_deinit(struct rsi_hw * adapter)398dad0d04fSFariya Fatima void rsi_91x_deinit(struct rsi_hw *adapter)
399dad0d04fSFariya Fatima {
400dad0d04fSFariya Fatima struct rsi_common *common = adapter->priv;
401dad0d04fSFariya Fatima u8 ii;
402dad0d04fSFariya Fatima
403dad0d04fSFariya Fatima rsi_dbg(INFO_ZONE, "%s: Performing deinit os ops\n", __func__);
404dad0d04fSFariya Fatima
405dad0d04fSFariya Fatima rsi_kill_thread(&common->tx_thread);
406dad0d04fSFariya Fatima
407dad0d04fSFariya Fatima for (ii = 0; ii < NUM_SOFT_QUEUES; ii++)
408dad0d04fSFariya Fatima skb_queue_purge(&common->tx_queue[ii]);
409dad0d04fSFariya Fatima
4102108df3cSPrameela Rani Garnepudi #ifdef CONFIG_RSI_COEX
411716b840cSSiva Rebbagondla if (common->coex_mode > 1) {
412716b840cSSiva Rebbagondla if (common->bt_adapter) {
413716b840cSSiva Rebbagondla rsi_bt_ops.detach(common->bt_adapter);
414716b840cSSiva Rebbagondla common->bt_adapter = NULL;
415716b840cSSiva Rebbagondla }
4162108df3cSPrameela Rani Garnepudi rsi_coex_detach(common);
417716b840cSSiva Rebbagondla }
4182108df3cSPrameela Rani Garnepudi #endif
4192108df3cSPrameela Rani Garnepudi
420716b840cSSiva Rebbagondla common->init_done = false;
421716b840cSSiva Rebbagondla
422dad0d04fSFariya Fatima kfree(common);
423dad0d04fSFariya Fatima kfree(adapter->rsi_dev);
424dad0d04fSFariya Fatima kfree(adapter);
425dad0d04fSFariya Fatima }
426dad0d04fSFariya Fatima EXPORT_SYMBOL_GPL(rsi_91x_deinit);
427dad0d04fSFariya Fatima
428dad0d04fSFariya Fatima /**
429dad0d04fSFariya Fatima * rsi_91x_hal_module_init() - This function is invoked when the module is
430dad0d04fSFariya Fatima * loaded into the kernel.
431dad0d04fSFariya Fatima * It registers the client driver.
432dad0d04fSFariya Fatima * @void: Void.
433dad0d04fSFariya Fatima *
434dad0d04fSFariya Fatima * Return: 0 on success, -1 on failure.
435dad0d04fSFariya Fatima */
rsi_91x_hal_module_init(void)436dad0d04fSFariya Fatima static int rsi_91x_hal_module_init(void)
437dad0d04fSFariya Fatima {
438dad0d04fSFariya Fatima rsi_dbg(INIT_ZONE, "%s: Module init called\n", __func__);
439dad0d04fSFariya Fatima return 0;
440dad0d04fSFariya Fatima }
441dad0d04fSFariya Fatima
442dad0d04fSFariya Fatima /**
443dad0d04fSFariya Fatima * rsi_91x_hal_module_exit() - This function is called at the time of
444dad0d04fSFariya Fatima * removing/unloading the module.
445dad0d04fSFariya Fatima * It unregisters the client driver.
446dad0d04fSFariya Fatima * @void: Void.
447dad0d04fSFariya Fatima *
448dad0d04fSFariya Fatima * Return: None.
449dad0d04fSFariya Fatima */
rsi_91x_hal_module_exit(void)450dad0d04fSFariya Fatima static void rsi_91x_hal_module_exit(void)
451dad0d04fSFariya Fatima {
452dad0d04fSFariya Fatima rsi_dbg(INIT_ZONE, "%s: Module exit called\n", __func__);
453dad0d04fSFariya Fatima }
454dad0d04fSFariya Fatima
455dad0d04fSFariya Fatima module_init(rsi_91x_hal_module_init);
456dad0d04fSFariya Fatima module_exit(rsi_91x_hal_module_exit);
457dad0d04fSFariya Fatima MODULE_AUTHOR("Redpine Signals Inc");
458dad0d04fSFariya Fatima MODULE_DESCRIPTION("Station driver for RSI 91x devices");
459dad0d04fSFariya Fatima MODULE_VERSION("0.1");
460dad0d04fSFariya Fatima MODULE_LICENSE("Dual BSD/GPL");
461