2 * Copyright (c) 2014 Redpine Signals Inc.
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.
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.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/module.h>
20 #include <linux/firmware.h>
21 #include <net/rsi_91x.h>
23 #include "rsi_common.h"
27 u32 rsi_zone_enabled
= /* INFO_ZONE |
37 EXPORT_SYMBOL_GPL(rsi_zone_enabled
);
39 #ifdef CONFIG_RSI_COEX
40 static 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
,
48 * rsi_dbg() - This function outputs informational messages.
49 * @zone: Zone of interest for output message.
50 * @fmt: printf-style format for output message.
54 void rsi_dbg(u32 zone
, const char *fmt
, ...)
64 if (zone
& rsi_zone_enabled
)
68 EXPORT_SYMBOL_GPL(rsi_dbg
);
70 static char *opmode_str(int oper_mode
)
73 case DEV_OPMODE_WIFI_ALONE
:
75 case DEV_OPMODE_BT_ALONE
:
76 return "BT EDR alone";
77 case DEV_OPMODE_BT_LE_ALONE
:
79 case DEV_OPMODE_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";
96 void rsi_print_version(struct rsi_common
*common
)
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");
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.
117 * Return: Successfully skb.
119 static struct sk_buff
*rsi_prepare_skb(struct rsi_common
*common
,
124 struct ieee80211_tx_info
*info
;
125 struct sk_buff
*skb
= NULL
;
127 struct ieee80211_vif
*vif
;
128 struct ieee80211_hdr
*wh
;
130 if (WARN(!pkt_len
, "%s: Dummy pkt received", __func__
))
133 if (pkt_len
> (RSI_RCV_BUFFER_LEN
* 4)) {
134 rsi_dbg(ERR_ZONE
, "%s: Pkt size > max rx buf size %d\n",
136 pkt_len
= RSI_RCV_BUFFER_LEN
* 4;
139 pkt_len
-= extended_desc
;
140 skb
= dev_alloc_skb(pkt_len
+ FRAME_DESC_SZ
);
144 payload_offset
= (extended_desc
+ FRAME_DESC_SZ
);
145 skb_put(skb
, pkt_len
);
146 memcpy((skb
->data
), (buffer
+ payload_offset
), skb
->len
);
147 wh
= (struct ieee80211_hdr
*)skb
->data
;
148 vif
= rsi_get_vif(common
->priv
, wh
->addr1
);
150 info
= IEEE80211_SKB_CB(skb
);
155 * rsi_read_pkt() - This function reads frames from the card.
156 * @common: Pointer to the driver private structure.
157 * @rcv_pkt_len: Received pkt length. In case of USB it is 0.
159 * Return: 0 on success, -1 on failure.
161 int rsi_read_pkt(struct rsi_common
*common
, u8
*rx_pkt
, s32 rcv_pkt_len
)
163 u8
*frame_desc
= NULL
, extended_desc
= 0;
164 u32 index
, length
= 0, queueno
= 0;
165 u16 actual_length
= 0, offset
;
166 struct sk_buff
*skb
= NULL
;
167 #ifdef CONFIG_RSI_COEX
173 frame_desc
= &rx_pkt
[index
];
174 actual_length
= *(u16
*)&frame_desc
[0];
175 offset
= *(u16
*)&frame_desc
[2];
177 queueno
= rsi_get_queueno(frame_desc
, offset
);
178 length
= rsi_get_length(frame_desc
, offset
);
180 /* Extended descriptor is valid for WLAN queues only */
181 if (queueno
== RSI_WIFI_DATA_Q
|| queueno
== RSI_WIFI_MGMT_Q
)
182 extended_desc
= rsi_get_extended_desc(frame_desc
,
187 #ifdef CONFIG_RSI_COEX
188 if (common
->coex_mode
> 1)
189 rsi_coex_recv_pkt(common
, frame_desc
+ offset
);
192 rsi_mgmt_pkt_recv(common
,
193 (frame_desc
+ offset
));
196 case RSI_WIFI_DATA_Q
:
197 skb
= rsi_prepare_skb(common
,
198 (frame_desc
+ offset
),
204 rsi_indicate_pkt_to_os(common
, skb
);
207 case RSI_WIFI_MGMT_Q
:
208 rsi_mgmt_pkt_recv(common
, (frame_desc
+ offset
));
211 #ifdef CONFIG_RSI_COEX
214 #define BT_RX_PKT_TYPE_OFST 14
215 #define BT_CARD_READY_IND 0x89
216 bt_pkt_type
= frame_desc
[offset
+ BT_RX_PKT_TYPE_OFST
];
217 if (bt_pkt_type
== BT_CARD_READY_IND
) {
218 rsi_dbg(INFO_ZONE
, "BT Card ready recvd\n");
219 if (rsi_bt_ops
.attach(common
, &g_proto_ops
))
221 "Failed to attach BT module\n");
223 if (common
->bt_adapter
)
224 rsi_bt_ops
.recv_pkt(common
->bt_adapter
,
225 frame_desc
+ offset
);
231 rsi_dbg(ERR_ZONE
, "%s: pkt from invalid queue: %d\n",
236 index
+= actual_length
;
237 rcv_pkt_len
-= actual_length
;
238 } while (rcv_pkt_len
> 0);
244 EXPORT_SYMBOL_GPL(rsi_read_pkt
);
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.
253 static void rsi_tx_scheduler_thread(struct rsi_common
*common
)
255 struct rsi_hw
*adapter
= common
->priv
;
256 u32 timeout
= EVENT_WAIT_FOREVER
;
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
);
264 if (common
->init_done
)
265 rsi_core_qos_processor(common
);
266 } while (atomic_read(&common
->tx_thread
.thread_done
) == 0);
267 complete_and_exit(&common
->tx_thread
.completion
, 0);
270 #ifdef CONFIG_RSI_COEX
271 enum rsi_host_intf
rsi_get_host_intf(void *priv
)
273 struct rsi_common
*common
= (struct rsi_common
*)priv
;
275 return common
->priv
->rsi_host_intf
;
278 void rsi_set_bt_context(void *priv
, void *bt_context
)
280 struct rsi_common
*common
= (struct rsi_common
*)priv
;
282 common
->bt_adapter
= bt_context
;
287 * rsi_91x_init() - This function initializes os interface operations.
290 * Return: Pointer to the adapter structure on success, NULL on failure .
292 struct rsi_hw
*rsi_91x_init(u16 oper_mode
)
294 struct rsi_hw
*adapter
= NULL
;
295 struct rsi_common
*common
= NULL
;
298 adapter
= kzalloc(sizeof(*adapter
), GFP_KERNEL
);
302 adapter
->priv
= kzalloc(sizeof(*common
), GFP_KERNEL
);
303 if (adapter
->priv
== NULL
) {
304 rsi_dbg(ERR_ZONE
, "%s: Failed in allocation of memory\n",
309 common
= adapter
->priv
;
310 common
->priv
= adapter
;
313 for (ii
= 0; ii
< NUM_SOFT_QUEUES
; ii
++)
314 skb_queue_head_init(&common
->tx_queue
[ii
]);
316 rsi_init_event(&common
->tx_thread
.event
);
317 mutex_init(&common
->mutex
);
318 mutex_init(&common
->tx_lock
);
319 mutex_init(&common
->rx_lock
);
320 mutex_init(&common
->tx_bus_mutex
);
322 if (rsi_create_kthread(common
,
324 rsi_tx_scheduler_thread
,
326 rsi_dbg(ERR_ZONE
, "%s: Unable to init tx thrd\n", __func__
);
330 rsi_default_ps_params(adapter
);
331 spin_lock_init(&adapter
->ps_lock
);
332 timer_setup(&common
->roc_timer
, rsi_roc_timeout
, 0);
333 init_completion(&common
->wlan_init_completion
);
334 adapter
->device_model
= RSI_DEV_9113
;
335 common
->oper_mode
= oper_mode
;
337 /* Determine coex mode */
338 switch (common
->oper_mode
) {
339 case DEV_OPMODE_STA_BT_DUAL
:
340 case DEV_OPMODE_STA_BT
:
341 case DEV_OPMODE_STA_BT_LE
:
342 case DEV_OPMODE_BT_ALONE
:
343 case DEV_OPMODE_BT_LE_ALONE
:
344 case DEV_OPMODE_BT_DUAL
:
345 common
->coex_mode
= 2;
347 case DEV_OPMODE_AP_BT_DUAL
:
348 case DEV_OPMODE_AP_BT
:
349 common
->coex_mode
= 4;
351 case DEV_OPMODE_WIFI_ALONE
:
352 common
->coex_mode
= 1;
355 common
->oper_mode
= 1;
356 common
->coex_mode
= 1;
358 rsi_dbg(INFO_ZONE
, "%s: oper_mode = %d, coex_mode = %d\n",
359 __func__
, common
->oper_mode
, common
->coex_mode
);
361 adapter
->device_model
= RSI_DEV_9113
;
362 #ifdef CONFIG_RSI_COEX
363 if (common
->coex_mode
> 1) {
364 if (rsi_coex_attach(common
)) {
365 rsi_dbg(ERR_ZONE
, "Failed to init coex module\n");
371 common
->init_done
= true;
379 EXPORT_SYMBOL_GPL(rsi_91x_init
);
382 * rsi_91x_deinit() - This function de-intializes os intf operations.
383 * @adapter: Pointer to the adapter structure.
387 void rsi_91x_deinit(struct rsi_hw
*adapter
)
389 struct rsi_common
*common
= adapter
->priv
;
392 rsi_dbg(INFO_ZONE
, "%s: Performing deinit os ops\n", __func__
);
394 rsi_kill_thread(&common
->tx_thread
);
396 for (ii
= 0; ii
< NUM_SOFT_QUEUES
; ii
++)
397 skb_queue_purge(&common
->tx_queue
[ii
]);
399 #ifdef CONFIG_RSI_COEX
400 if (common
->coex_mode
> 1) {
401 if (common
->bt_adapter
) {
402 rsi_bt_ops
.detach(common
->bt_adapter
);
403 common
->bt_adapter
= NULL
;
405 rsi_coex_detach(common
);
409 common
->init_done
= false;
412 kfree(adapter
->rsi_dev
);
415 EXPORT_SYMBOL_GPL(rsi_91x_deinit
);
418 * rsi_91x_hal_module_init() - This function is invoked when the module is
419 * loaded into the kernel.
420 * It registers the client driver.
423 * Return: 0 on success, -1 on failure.
425 static int rsi_91x_hal_module_init(void)
427 rsi_dbg(INIT_ZONE
, "%s: Module init called\n", __func__
);
432 * rsi_91x_hal_module_exit() - This function is called at the time of
433 * removing/unloading the module.
434 * It unregisters the client driver.
439 static void rsi_91x_hal_module_exit(void)
441 rsi_dbg(INIT_ZONE
, "%s: Module exit called\n", __func__
);
444 module_init(rsi_91x_hal_module_init
);
445 module_exit(rsi_91x_hal_module_exit
);
446 MODULE_AUTHOR("Redpine Signals Inc");
447 MODULE_DESCRIPTION("Station driver for RSI 91x devices");
448 MODULE_SUPPORTED_DEVICE("RSI-91x");
449 MODULE_VERSION("0.1");
450 MODULE_LICENSE("Dual BSD/GPL");