Linux Audio

Check our new training course

Loading...
v6.8
  1/*
  2 * Copyright (c) 2014 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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 18
 19#include <linux/module.h>
 20#include <linux/firmware.h>
 21#include <net/rsi_91x.h>
 22#include "rsi_mgmt.h"
 23#include "rsi_common.h"
 24#include "rsi_coex.h"
 25#include "rsi_hal.h"
 26#include "rsi_usb.h"
 27
 28u32 rsi_zone_enabled = /* INFO_ZONE |
 29			INIT_ZONE |
 30			MGMT_TX_ZONE |
 31			MGMT_RX_ZONE |
 32			DATA_TX_ZONE |
 33			DATA_RX_ZONE |
 34			FSM_ZONE |
 35			ISR_ZONE | */
 36			ERR_ZONE |
 37			0;
 38EXPORT_SYMBOL_GPL(rsi_zone_enabled);
 39
 40#ifdef CONFIG_RSI_COEX
 41static struct rsi_proto_ops g_proto_ops = {
 42	.coex_send_pkt = rsi_coex_send_pkt,
 43	.get_host_intf = rsi_get_host_intf,
 44	.set_bt_context = rsi_set_bt_context,
 45};
 46#endif
 47
 48/**
 49 * rsi_dbg() - This function outputs informational messages.
 50 * @zone: Zone of interest for output message.
 51 * @fmt: printf-style format for output message.
 52 *
 53 * Return: none
 54 */
 55void rsi_dbg(u32 zone, const char *fmt, ...)
 56{
 57	struct va_format vaf;
 58	va_list args;
 59
 60	va_start(args, fmt);
 61
 62	vaf.fmt = fmt;
 63	vaf.va = &args;
 64
 65	if (zone & rsi_zone_enabled)
 66		pr_info("%pV", &vaf);
 67	va_end(args);
 68}
 69EXPORT_SYMBOL_GPL(rsi_dbg);
 70
 71static char *opmode_str(int oper_mode)
 72{
 73	switch (oper_mode) {
 74	case DEV_OPMODE_WIFI_ALONE:
 75		return "Wi-Fi alone";
 76	case DEV_OPMODE_BT_ALONE:
 77		return "BT EDR alone";
 78	case DEV_OPMODE_BT_LE_ALONE:
 79		return "BT LE alone";
 80	case DEV_OPMODE_BT_DUAL:
 81		return "BT Dual";
 82	case DEV_OPMODE_STA_BT:
 83		return "Wi-Fi STA + BT EDR";
 84	case DEV_OPMODE_STA_BT_LE:
 85		return "Wi-Fi STA + BT LE";
 86	case DEV_OPMODE_STA_BT_DUAL:
 87		return "Wi-Fi STA + BT DUAL";
 88	case DEV_OPMODE_AP_BT:
 89		return "Wi-Fi AP + BT EDR";
 90	case DEV_OPMODE_AP_BT_DUAL:
 91		return "Wi-Fi AP + BT DUAL";
 92	}
 93
 94	return "Unknown";
 95}
 96
 97void rsi_print_version(struct rsi_common *common)
 98{
 99	rsi_dbg(ERR_ZONE, "================================================\n");
100	rsi_dbg(ERR_ZONE, "================ RSI Version Info ==============\n");
101	rsi_dbg(ERR_ZONE, "================================================\n");
102	rsi_dbg(ERR_ZONE, "FW Version\t: %d.%d.%d\n",
103		common->lmac_ver.major, common->lmac_ver.minor,
104		common->lmac_ver.release_num);
105	rsi_dbg(ERR_ZONE, "Operating mode\t: %d [%s]",
106		common->oper_mode, opmode_str(common->oper_mode));
107	rsi_dbg(ERR_ZONE, "Firmware file\t: %s", common->priv->fw_file_name);
108	rsi_dbg(ERR_ZONE, "================================================\n");
109}
110
111/**
112 * rsi_prepare_skb() - This function prepares the skb.
113 * @common: Pointer to the driver private structure.
114 * @buffer: Pointer to the packet data.
115 * @pkt_len: Length of the packet.
116 * @extended_desc: Extended descriptor.
117 *
118 * Return: Successfully skb.
119 */
120static struct sk_buff *rsi_prepare_skb(struct rsi_common *common,
121				       u8 *buffer,
122				       u32 pkt_len,
123				       u8 extended_desc)
124{
125	struct sk_buff *skb = NULL;
126	u8 payload_offset;
127
128	if (WARN(!pkt_len, "%s: Dummy pkt received", __func__))
129		return NULL;
130
131	if (pkt_len > (RSI_RCV_BUFFER_LEN * 4)) {
132		rsi_dbg(ERR_ZONE, "%s: Pkt size > max rx buf size %d\n",
133			__func__, pkt_len);
134		pkt_len = RSI_RCV_BUFFER_LEN * 4;
135	}
136
137	pkt_len -= extended_desc;
138	skb = dev_alloc_skb(pkt_len + FRAME_DESC_SZ);
139	if (skb == NULL)
140		return NULL;
141
142	payload_offset = (extended_desc + FRAME_DESC_SZ);
143	skb_put(skb, pkt_len);
144	memcpy((skb->data), (buffer + payload_offset), skb->len);
145
146	return skb;
147}
148
149/**
150 * rsi_read_pkt() - This function reads frames from the card.
151 * @common: Pointer to the driver private structure.
152 * @rx_pkt: Received pkt.
153 * @rcv_pkt_len: Received pkt length. In case of USB it is 0.
154 *
155 * Return: 0 on success, -1 on failure.
156 */
157int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len)
158{
159	u8 *frame_desc = NULL, extended_desc = 0;
160	u32 index, length = 0, queueno = 0;
161	u16 actual_length = 0, offset;
162	struct sk_buff *skb = NULL;
163#ifdef CONFIG_RSI_COEX
164	u8 bt_pkt_type;
165#endif
166
167	index = 0;
168	do {
169		frame_desc = &rx_pkt[index];
170		actual_length = *(u16 *)&frame_desc[0];
171		offset = *(u16 *)&frame_desc[2];
172		if (!rcv_pkt_len && offset >
173			RSI_MAX_RX_USB_PKT_SIZE - FRAME_DESC_SZ)
174			goto fail;
175
176		queueno = rsi_get_queueno(frame_desc, offset);
177		length = rsi_get_length(frame_desc, offset);
178
179		/* Extended descriptor is valid for WLAN queues only */
180		if (queueno == RSI_WIFI_DATA_Q || queueno == RSI_WIFI_MGMT_Q)
181			extended_desc = rsi_get_extended_desc(frame_desc,
182							      offset);
183
184		switch (queueno) {
185		case RSI_COEX_Q:
186#ifdef CONFIG_RSI_COEX
187			if (common->coex_mode > 1)
188				rsi_coex_recv_pkt(common, frame_desc + offset);
189			else
190#endif
191				rsi_mgmt_pkt_recv(common,
192						  (frame_desc + offset));
193			break;
194
195		case RSI_WIFI_DATA_Q:
196			skb = rsi_prepare_skb(common,
197					      (frame_desc + offset),
198					      length,
199					      extended_desc);
200			if (skb == NULL)
201				goto fail;
202
203			rsi_indicate_pkt_to_os(common, skb);
204			break;
205
206		case RSI_WIFI_MGMT_Q:
207			rsi_mgmt_pkt_recv(common, (frame_desc + offset));
208			break;
209
210#ifdef CONFIG_RSI_COEX
211		case RSI_BT_MGMT_Q:
212		case RSI_BT_DATA_Q:
213#define BT_RX_PKT_TYPE_OFST	14
214#define BT_CARD_READY_IND	0x89
215			bt_pkt_type = frame_desc[offset + BT_RX_PKT_TYPE_OFST];
216			if (bt_pkt_type == BT_CARD_READY_IND) {
217				rsi_dbg(INFO_ZONE, "BT Card ready recvd\n");
218				if (common->fsm_state == FSM_MAC_INIT_DONE)
219					rsi_attach_bt(common);
220				else
221					common->bt_defer_attach = true;
222			} else {
223				if (common->bt_adapter)
224					rsi_bt_ops.recv_pkt(common->bt_adapter,
225							frame_desc + offset);
226			}
227			break;
228#endif
229
230		default:
231			rsi_dbg(ERR_ZONE, "%s: pkt from invalid queue: %d\n",
232				__func__,   queueno);
233			goto fail;
234		}
235
236		index  += actual_length;
237		rcv_pkt_len -= actual_length;
238	} while (rcv_pkt_len > 0);
239
240	return 0;
241fail:
242	return -EINVAL;
243}
244EXPORT_SYMBOL_GPL(rsi_read_pkt);
245
246/**
247 * rsi_tx_scheduler_thread() - This function is a kernel thread to send the
248 *			       packets to the device.
249 * @common: Pointer to the driver private structure.
250 *
251 * Return: None.
252 */
253static void rsi_tx_scheduler_thread(struct rsi_common *common)
254{
255	struct rsi_hw *adapter = common->priv;
256	u32 timeout = EVENT_WAIT_FOREVER;
257
258	do {
259		if (adapter->determine_event_timeout)
260			timeout = adapter->determine_event_timeout(adapter);
261		rsi_wait_event(&common->tx_thread.event, timeout);
262		rsi_reset_event(&common->tx_thread.event);
263
264		if (common->init_done)
265			rsi_core_qos_processor(common);
266	} while (atomic_read(&common->tx_thread.thread_done) == 0);
267	kthread_complete_and_exit(&common->tx_thread.completion, 0);
268}
269
270#ifdef CONFIG_RSI_COEX
271enum rsi_host_intf rsi_get_host_intf(void *priv)
272{
273	struct rsi_common *common = priv;
274
275	return common->priv->rsi_host_intf;
276}
277
278void rsi_set_bt_context(void *priv, void *bt_context)
279{
280	struct rsi_common *common = priv;
281
282	common->bt_adapter = bt_context;
283}
284#endif
285
286void rsi_attach_bt(struct rsi_common *common)
287{
288#ifdef CONFIG_RSI_COEX
289	if (rsi_bt_ops.attach(common, &g_proto_ops))
290		rsi_dbg(ERR_ZONE,
291			"Failed to attach BT module\n");
292#endif
293}
294
295/**
296 * rsi_91x_init() - This function initializes os interface operations.
297 * @oper_mode: One of DEV_OPMODE_*.
298 *
299 * Return: Pointer to the adapter structure on success, NULL on failure .
300 */
301struct rsi_hw *rsi_91x_init(u16 oper_mode)
302{
303	struct rsi_hw *adapter = NULL;
304	struct rsi_common *common = NULL;
305	u8 ii = 0;
306
307	adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
308	if (!adapter)
309		return NULL;
310
311	adapter->priv = kzalloc(sizeof(*common), GFP_KERNEL);
312	if (adapter->priv == NULL) {
313		rsi_dbg(ERR_ZONE, "%s: Failed in allocation of memory\n",
314			__func__);
315		kfree(adapter);
316		return NULL;
317	} else {
318		common = adapter->priv;
319		common->priv = adapter;
320	}
321
322	for (ii = 0; ii < NUM_SOFT_QUEUES; ii++)
323		skb_queue_head_init(&common->tx_queue[ii]);
324
325	rsi_init_event(&common->tx_thread.event);
326	mutex_init(&common->mutex);
327	mutex_init(&common->tx_lock);
328	mutex_init(&common->rx_lock);
329	mutex_init(&common->tx_bus_mutex);
330
331	if (rsi_create_kthread(common,
332			       &common->tx_thread,
333			       rsi_tx_scheduler_thread,
334			       "Tx-Thread")) {
335		rsi_dbg(ERR_ZONE, "%s: Unable to init tx thrd\n", __func__);
336		goto err;
337	}
338
339	rsi_default_ps_params(adapter);
340	init_bgscan_params(common);
341	spin_lock_init(&adapter->ps_lock);
342	timer_setup(&common->roc_timer, rsi_roc_timeout, 0);
343	init_completion(&common->wlan_init_completion);
344	adapter->device_model = RSI_DEV_9113;
345	common->oper_mode = oper_mode;
346
347	/* Determine coex mode */
348	switch (common->oper_mode) {
349	case DEV_OPMODE_STA_BT_DUAL:
350	case DEV_OPMODE_STA_BT:
351	case DEV_OPMODE_STA_BT_LE:
352	case DEV_OPMODE_BT_ALONE:
353	case DEV_OPMODE_BT_LE_ALONE:
354	case DEV_OPMODE_BT_DUAL:
355		common->coex_mode = 2;
356		break;
357	case DEV_OPMODE_AP_BT_DUAL:
358	case DEV_OPMODE_AP_BT:
359		common->coex_mode = 4;
360		break;
361	case DEV_OPMODE_WIFI_ALONE:
362		common->coex_mode = 1;
363		break;
364	default:
365		common->oper_mode = 1;
366		common->coex_mode = 1;
367	}
368	rsi_dbg(INFO_ZONE, "%s: oper_mode = %d, coex_mode = %d\n",
369		__func__, common->oper_mode, common->coex_mode);
370
371	adapter->device_model = RSI_DEV_9113;
372#ifdef CONFIG_RSI_COEX
373	if (common->coex_mode > 1) {
374		if (rsi_coex_attach(common)) {
375			rsi_dbg(ERR_ZONE, "Failed to init coex module\n");
376			rsi_kill_thread(&common->tx_thread);
377			goto err;
378		}
379	}
380#endif
381
382	common->init_done = true;
383	return adapter;
384
385err:
386	kfree(common);
387	kfree(adapter);
388	return NULL;
389}
390EXPORT_SYMBOL_GPL(rsi_91x_init);
391
392/**
393 * rsi_91x_deinit() - This function de-intializes os intf operations.
394 * @adapter: Pointer to the adapter structure.
395 *
396 * Return: None.
397 */
398void rsi_91x_deinit(struct rsi_hw *adapter)
399{
400	struct rsi_common *common = adapter->priv;
401	u8 ii;
402
403	rsi_dbg(INFO_ZONE, "%s: Performing deinit os ops\n", __func__);
404
405	rsi_kill_thread(&common->tx_thread);
406
407	for (ii = 0; ii < NUM_SOFT_QUEUES; ii++)
408		skb_queue_purge(&common->tx_queue[ii]);
409
410#ifdef CONFIG_RSI_COEX
411	if (common->coex_mode > 1) {
412		if (common->bt_adapter) {
413			rsi_bt_ops.detach(common->bt_adapter);
414			common->bt_adapter = NULL;
415		}
416		rsi_coex_detach(common);
417	}
418#endif
419
420	common->init_done = false;
421
422	kfree(common);
423	kfree(adapter->rsi_dev);
424	kfree(adapter);
425}
426EXPORT_SYMBOL_GPL(rsi_91x_deinit);
427
428/**
429 * rsi_91x_hal_module_init() - This function is invoked when the module is
430 *			       loaded into the kernel.
431 *			       It registers the client driver.
432 * @void: Void.
433 *
434 * Return: 0 on success, -1 on failure.
435 */
436static int rsi_91x_hal_module_init(void)
437{
438	rsi_dbg(INIT_ZONE, "%s: Module init called\n", __func__);
439	return 0;
440}
441
442/**
443 * rsi_91x_hal_module_exit() - This function is called at the time of
444 *			       removing/unloading the module.
445 *			       It unregisters the client driver.
446 * @void: Void.
447 *
448 * Return: None.
449 */
450static void rsi_91x_hal_module_exit(void)
451{
452	rsi_dbg(INIT_ZONE, "%s: Module exit called\n", __func__);
453}
454
455module_init(rsi_91x_hal_module_init);
456module_exit(rsi_91x_hal_module_exit);
457MODULE_AUTHOR("Redpine Signals Inc");
458MODULE_DESCRIPTION("Station driver for RSI 91x devices");
459MODULE_VERSION("0.1");
460MODULE_LICENSE("Dual BSD/GPL");
v5.14.15
  1/*
  2 * Copyright (c) 2014 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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 18
 19#include <linux/module.h>
 20#include <linux/firmware.h>
 21#include <net/rsi_91x.h>
 22#include "rsi_mgmt.h"
 23#include "rsi_common.h"
 24#include "rsi_coex.h"
 25#include "rsi_hal.h"
 
 26
 27u32 rsi_zone_enabled = /* INFO_ZONE |
 28			INIT_ZONE |
 29			MGMT_TX_ZONE |
 30			MGMT_RX_ZONE |
 31			DATA_TX_ZONE |
 32			DATA_RX_ZONE |
 33			FSM_ZONE |
 34			ISR_ZONE | */
 35			ERR_ZONE |
 36			0;
 37EXPORT_SYMBOL_GPL(rsi_zone_enabled);
 38
 39#ifdef CONFIG_RSI_COEX
 40static struct rsi_proto_ops g_proto_ops = {
 41	.coex_send_pkt = rsi_coex_send_pkt,
 42	.get_host_intf = rsi_get_host_intf,
 43	.set_bt_context = rsi_set_bt_context,
 44};
 45#endif
 46
 47/**
 48 * rsi_dbg() - This function outputs informational messages.
 49 * @zone: Zone of interest for output message.
 50 * @fmt: printf-style format for output message.
 51 *
 52 * Return: none
 53 */
 54void rsi_dbg(u32 zone, const char *fmt, ...)
 55{
 56	struct va_format vaf;
 57	va_list args;
 58
 59	va_start(args, fmt);
 60
 61	vaf.fmt = fmt;
 62	vaf.va = &args;
 63
 64	if (zone & rsi_zone_enabled)
 65		pr_info("%pV", &vaf);
 66	va_end(args);
 67}
 68EXPORT_SYMBOL_GPL(rsi_dbg);
 69
 70static char *opmode_str(int oper_mode)
 71{
 72	switch (oper_mode) {
 73	case DEV_OPMODE_WIFI_ALONE:
 74		return "Wi-Fi alone";
 75	case DEV_OPMODE_BT_ALONE:
 76		return "BT EDR alone";
 77	case DEV_OPMODE_BT_LE_ALONE:
 78		return "BT LE alone";
 79	case DEV_OPMODE_BT_DUAL:
 80		return "BT Dual";
 81	case DEV_OPMODE_STA_BT:
 82		return "Wi-Fi STA + BT EDR";
 83	case DEV_OPMODE_STA_BT_LE:
 84		return "Wi-Fi STA + BT LE";
 85	case DEV_OPMODE_STA_BT_DUAL:
 86		return "Wi-Fi STA + BT DUAL";
 87	case DEV_OPMODE_AP_BT:
 88		return "Wi-Fi AP + BT EDR";
 89	case DEV_OPMODE_AP_BT_DUAL:
 90		return "Wi-Fi AP + BT DUAL";
 91	}
 92
 93	return "Unknown";
 94}
 95
 96void rsi_print_version(struct rsi_common *common)
 97{
 98	rsi_dbg(ERR_ZONE, "================================================\n");
 99	rsi_dbg(ERR_ZONE, "================ RSI Version Info ==============\n");
100	rsi_dbg(ERR_ZONE, "================================================\n");
101	rsi_dbg(ERR_ZONE, "FW Version\t: %d.%d.%d\n",
102		common->lmac_ver.major, common->lmac_ver.minor,
103		common->lmac_ver.release_num);
104	rsi_dbg(ERR_ZONE, "Operating mode\t: %d [%s]",
105		common->oper_mode, opmode_str(common->oper_mode));
106	rsi_dbg(ERR_ZONE, "Firmware file\t: %s", common->priv->fw_file_name);
107	rsi_dbg(ERR_ZONE, "================================================\n");
108}
109
110/**
111 * rsi_prepare_skb() - This function prepares the skb.
112 * @common: Pointer to the driver private structure.
113 * @buffer: Pointer to the packet data.
114 * @pkt_len: Length of the packet.
115 * @extended_desc: Extended descriptor.
116 *
117 * Return: Successfully skb.
118 */
119static struct sk_buff *rsi_prepare_skb(struct rsi_common *common,
120				       u8 *buffer,
121				       u32 pkt_len,
122				       u8 extended_desc)
123{
124	struct sk_buff *skb = NULL;
125	u8 payload_offset;
126
127	if (WARN(!pkt_len, "%s: Dummy pkt received", __func__))
128		return NULL;
129
130	if (pkt_len > (RSI_RCV_BUFFER_LEN * 4)) {
131		rsi_dbg(ERR_ZONE, "%s: Pkt size > max rx buf size %d\n",
132			__func__, pkt_len);
133		pkt_len = RSI_RCV_BUFFER_LEN * 4;
134	}
135
136	pkt_len -= extended_desc;
137	skb = dev_alloc_skb(pkt_len + FRAME_DESC_SZ);
138	if (skb == NULL)
139		return NULL;
140
141	payload_offset = (extended_desc + FRAME_DESC_SZ);
142	skb_put(skb, pkt_len);
143	memcpy((skb->data), (buffer + payload_offset), skb->len);
144
145	return skb;
146}
147
148/**
149 * rsi_read_pkt() - This function reads frames from the card.
150 * @common: Pointer to the driver private structure.
151 * @rx_pkt: Received pkt.
152 * @rcv_pkt_len: Received pkt length. In case of USB it is 0.
153 *
154 * Return: 0 on success, -1 on failure.
155 */
156int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len)
157{
158	u8 *frame_desc = NULL, extended_desc = 0;
159	u32 index, length = 0, queueno = 0;
160	u16 actual_length = 0, offset;
161	struct sk_buff *skb = NULL;
162#ifdef CONFIG_RSI_COEX
163	u8 bt_pkt_type;
164#endif
165
166	index = 0;
167	do {
168		frame_desc = &rx_pkt[index];
169		actual_length = *(u16 *)&frame_desc[0];
170		offset = *(u16 *)&frame_desc[2];
 
 
 
171
172		queueno = rsi_get_queueno(frame_desc, offset);
173		length = rsi_get_length(frame_desc, offset);
174
175		/* Extended descriptor is valid for WLAN queues only */
176		if (queueno == RSI_WIFI_DATA_Q || queueno == RSI_WIFI_MGMT_Q)
177			extended_desc = rsi_get_extended_desc(frame_desc,
178							      offset);
179
180		switch (queueno) {
181		case RSI_COEX_Q:
182#ifdef CONFIG_RSI_COEX
183			if (common->coex_mode > 1)
184				rsi_coex_recv_pkt(common, frame_desc + offset);
185			else
186#endif
187				rsi_mgmt_pkt_recv(common,
188						  (frame_desc + offset));
189			break;
190
191		case RSI_WIFI_DATA_Q:
192			skb = rsi_prepare_skb(common,
193					      (frame_desc + offset),
194					      length,
195					      extended_desc);
196			if (skb == NULL)
197				goto fail;
198
199			rsi_indicate_pkt_to_os(common, skb);
200			break;
201
202		case RSI_WIFI_MGMT_Q:
203			rsi_mgmt_pkt_recv(common, (frame_desc + offset));
204			break;
205
206#ifdef CONFIG_RSI_COEX
207		case RSI_BT_MGMT_Q:
208		case RSI_BT_DATA_Q:
209#define BT_RX_PKT_TYPE_OFST	14
210#define BT_CARD_READY_IND	0x89
211			bt_pkt_type = frame_desc[offset + BT_RX_PKT_TYPE_OFST];
212			if (bt_pkt_type == BT_CARD_READY_IND) {
213				rsi_dbg(INFO_ZONE, "BT Card ready recvd\n");
214				if (rsi_bt_ops.attach(common, &g_proto_ops))
215					rsi_dbg(ERR_ZONE,
216						"Failed to attach BT module\n");
 
217			} else {
218				if (common->bt_adapter)
219					rsi_bt_ops.recv_pkt(common->bt_adapter,
220							frame_desc + offset);
221			}
222			break;
223#endif
224
225		default:
226			rsi_dbg(ERR_ZONE, "%s: pkt from invalid queue: %d\n",
227				__func__,   queueno);
228			goto fail;
229		}
230
231		index  += actual_length;
232		rcv_pkt_len -= actual_length;
233	} while (rcv_pkt_len > 0);
234
235	return 0;
236fail:
237	return -EINVAL;
238}
239EXPORT_SYMBOL_GPL(rsi_read_pkt);
240
241/**
242 * rsi_tx_scheduler_thread() - This function is a kernel thread to send the
243 *			       packets to the device.
244 * @common: Pointer to the driver private structure.
245 *
246 * Return: None.
247 */
248static void rsi_tx_scheduler_thread(struct rsi_common *common)
249{
250	struct rsi_hw *adapter = common->priv;
251	u32 timeout = EVENT_WAIT_FOREVER;
252
253	do {
254		if (adapter->determine_event_timeout)
255			timeout = adapter->determine_event_timeout(adapter);
256		rsi_wait_event(&common->tx_thread.event, timeout);
257		rsi_reset_event(&common->tx_thread.event);
258
259		if (common->init_done)
260			rsi_core_qos_processor(common);
261	} while (atomic_read(&common->tx_thread.thread_done) == 0);
262	complete_and_exit(&common->tx_thread.completion, 0);
263}
264
265#ifdef CONFIG_RSI_COEX
266enum rsi_host_intf rsi_get_host_intf(void *priv)
267{
268	struct rsi_common *common = (struct rsi_common *)priv;
269
270	return common->priv->rsi_host_intf;
271}
272
273void rsi_set_bt_context(void *priv, void *bt_context)
274{
275	struct rsi_common *common = (struct rsi_common *)priv;
276
277	common->bt_adapter = bt_context;
278}
279#endif
280
 
 
 
 
 
 
 
 
 
281/**
282 * rsi_91x_init() - This function initializes os interface operations.
283 * @oper_mode: One of DEV_OPMODE_*.
284 *
285 * Return: Pointer to the adapter structure on success, NULL on failure .
286 */
287struct rsi_hw *rsi_91x_init(u16 oper_mode)
288{
289	struct rsi_hw *adapter = NULL;
290	struct rsi_common *common = NULL;
291	u8 ii = 0;
292
293	adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
294	if (!adapter)
295		return NULL;
296
297	adapter->priv = kzalloc(sizeof(*common), GFP_KERNEL);
298	if (adapter->priv == NULL) {
299		rsi_dbg(ERR_ZONE, "%s: Failed in allocation of memory\n",
300			__func__);
301		kfree(adapter);
302		return NULL;
303	} else {
304		common = adapter->priv;
305		common->priv = adapter;
306	}
307
308	for (ii = 0; ii < NUM_SOFT_QUEUES; ii++)
309		skb_queue_head_init(&common->tx_queue[ii]);
310
311	rsi_init_event(&common->tx_thread.event);
312	mutex_init(&common->mutex);
313	mutex_init(&common->tx_lock);
314	mutex_init(&common->rx_lock);
315	mutex_init(&common->tx_bus_mutex);
316
317	if (rsi_create_kthread(common,
318			       &common->tx_thread,
319			       rsi_tx_scheduler_thread,
320			       "Tx-Thread")) {
321		rsi_dbg(ERR_ZONE, "%s: Unable to init tx thrd\n", __func__);
322		goto err;
323	}
324
325	rsi_default_ps_params(adapter);
326	init_bgscan_params(common);
327	spin_lock_init(&adapter->ps_lock);
328	timer_setup(&common->roc_timer, rsi_roc_timeout, 0);
329	init_completion(&common->wlan_init_completion);
330	adapter->device_model = RSI_DEV_9113;
331	common->oper_mode = oper_mode;
332
333	/* Determine coex mode */
334	switch (common->oper_mode) {
335	case DEV_OPMODE_STA_BT_DUAL:
336	case DEV_OPMODE_STA_BT:
337	case DEV_OPMODE_STA_BT_LE:
338	case DEV_OPMODE_BT_ALONE:
339	case DEV_OPMODE_BT_LE_ALONE:
340	case DEV_OPMODE_BT_DUAL:
341		common->coex_mode = 2;
342		break;
343	case DEV_OPMODE_AP_BT_DUAL:
344	case DEV_OPMODE_AP_BT:
345		common->coex_mode = 4;
346		break;
347	case DEV_OPMODE_WIFI_ALONE:
348		common->coex_mode = 1;
349		break;
350	default:
351		common->oper_mode = 1;
352		common->coex_mode = 1;
353	}
354	rsi_dbg(INFO_ZONE, "%s: oper_mode = %d, coex_mode = %d\n",
355		__func__, common->oper_mode, common->coex_mode);
356
357	adapter->device_model = RSI_DEV_9113;
358#ifdef CONFIG_RSI_COEX
359	if (common->coex_mode > 1) {
360		if (rsi_coex_attach(common)) {
361			rsi_dbg(ERR_ZONE, "Failed to init coex module\n");
 
362			goto err;
363		}
364	}
365#endif
366
367	common->init_done = true;
368	return adapter;
369
370err:
371	kfree(common);
372	kfree(adapter);
373	return NULL;
374}
375EXPORT_SYMBOL_GPL(rsi_91x_init);
376
377/**
378 * rsi_91x_deinit() - This function de-intializes os intf operations.
379 * @adapter: Pointer to the adapter structure.
380 *
381 * Return: None.
382 */
383void rsi_91x_deinit(struct rsi_hw *adapter)
384{
385	struct rsi_common *common = adapter->priv;
386	u8 ii;
387
388	rsi_dbg(INFO_ZONE, "%s: Performing deinit os ops\n", __func__);
389
390	rsi_kill_thread(&common->tx_thread);
391
392	for (ii = 0; ii < NUM_SOFT_QUEUES; ii++)
393		skb_queue_purge(&common->tx_queue[ii]);
394
395#ifdef CONFIG_RSI_COEX
396	if (common->coex_mode > 1) {
397		if (common->bt_adapter) {
398			rsi_bt_ops.detach(common->bt_adapter);
399			common->bt_adapter = NULL;
400		}
401		rsi_coex_detach(common);
402	}
403#endif
404
405	common->init_done = false;
406
407	kfree(common);
408	kfree(adapter->rsi_dev);
409	kfree(adapter);
410}
411EXPORT_SYMBOL_GPL(rsi_91x_deinit);
412
413/**
414 * rsi_91x_hal_module_init() - This function is invoked when the module is
415 *			       loaded into the kernel.
416 *			       It registers the client driver.
417 * @void: Void.
418 *
419 * Return: 0 on success, -1 on failure.
420 */
421static int rsi_91x_hal_module_init(void)
422{
423	rsi_dbg(INIT_ZONE, "%s: Module init called\n", __func__);
424	return 0;
425}
426
427/**
428 * rsi_91x_hal_module_exit() - This function is called at the time of
429 *			       removing/unloading the module.
430 *			       It unregisters the client driver.
431 * @void: Void.
432 *
433 * Return: None.
434 */
435static void rsi_91x_hal_module_exit(void)
436{
437	rsi_dbg(INIT_ZONE, "%s: Module exit called\n", __func__);
438}
439
440module_init(rsi_91x_hal_module_init);
441module_exit(rsi_91x_hal_module_exit);
442MODULE_AUTHOR("Redpine Signals Inc");
443MODULE_DESCRIPTION("Station driver for RSI 91x devices");
444MODULE_VERSION("0.1");
445MODULE_LICENSE("Dual BSD/GPL");