Fariya Fatima | dad0d04 | 2014-03-16 03:47:02 +0530 | [diff] [blame^] | 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 | #include <linux/module.h> |
| 18 | #include <linux/firmware.h> |
| 19 | #include "rsi_mgmt.h" |
| 20 | #include "rsi_common.h" |
| 21 | |
| 22 | u32 rsi_zone_enabled = /* INFO_ZONE | |
| 23 | INIT_ZONE | |
| 24 | MGMT_TX_ZONE | |
| 25 | MGMT_RX_ZONE | |
| 26 | DATA_TX_ZONE | |
| 27 | DATA_RX_ZONE | |
| 28 | FSM_ZONE | |
| 29 | ISR_ZONE | */ |
| 30 | ERR_ZONE | |
| 31 | 0; |
| 32 | EXPORT_SYMBOL_GPL(rsi_zone_enabled); |
| 33 | |
| 34 | /** |
| 35 | * rsi_prepare_skb() - This function prepares the skb. |
| 36 | * @common: Pointer to the driver private structure. |
| 37 | * @buffer: Pointer to the packet data. |
| 38 | * @pkt_len: Length of the packet. |
| 39 | * @extended_desc: Extended descriptor. |
| 40 | * |
| 41 | * Return: Successfully skb. |
| 42 | */ |
| 43 | static struct sk_buff *rsi_prepare_skb(struct rsi_common *common, |
| 44 | u8 *buffer, |
| 45 | u32 pkt_len, |
| 46 | u8 extended_desc) |
| 47 | { |
| 48 | struct ieee80211_tx_info *info; |
| 49 | struct skb_info *rx_params; |
| 50 | struct sk_buff *skb = NULL; |
| 51 | u8 payload_offset; |
| 52 | |
| 53 | if (WARN(!pkt_len, "%s: Dummy pkt received", __func__)) |
| 54 | return NULL; |
| 55 | |
| 56 | if (pkt_len > (RSI_RCV_BUFFER_LEN * 4)) { |
| 57 | rsi_dbg(ERR_ZONE, "%s: Pkt size > max rx buf size %d\n", |
| 58 | __func__, pkt_len); |
| 59 | pkt_len = RSI_RCV_BUFFER_LEN * 4; |
| 60 | } |
| 61 | |
| 62 | pkt_len -= extended_desc; |
| 63 | skb = dev_alloc_skb(pkt_len + FRAME_DESC_SZ); |
| 64 | if (skb == NULL) |
| 65 | return NULL; |
| 66 | |
| 67 | payload_offset = (extended_desc + FRAME_DESC_SZ); |
| 68 | skb_put(skb, pkt_len); |
| 69 | memcpy((skb->data), (buffer + payload_offset), skb->len); |
| 70 | |
| 71 | info = IEEE80211_SKB_CB(skb); |
| 72 | rx_params = (struct skb_info *)info->driver_data; |
| 73 | rx_params->rssi = rsi_get_rssi(buffer); |
| 74 | rx_params->channel = rsi_get_connected_channel(common->priv); |
| 75 | |
| 76 | return skb; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * rsi_read_pkt() - This function reads frames from the card. |
| 81 | * @common: Pointer to the driver private structure. |
| 82 | * @rcv_pkt_len: Received pkt length. In case of USB it is 0. |
| 83 | * |
| 84 | * Return: 0 on success, -1 on failure. |
| 85 | */ |
| 86 | int rsi_read_pkt(struct rsi_common *common, s32 rcv_pkt_len) |
| 87 | { |
| 88 | u8 *frame_desc = NULL, extended_desc = 0; |
| 89 | u32 index, length = 0, queueno = 0; |
| 90 | u16 actual_length = 0, offset; |
| 91 | struct sk_buff *skb = NULL; |
| 92 | |
| 93 | index = 0; |
| 94 | do { |
| 95 | frame_desc = &common->rx_data_pkt[index]; |
| 96 | actual_length = *(u16 *)&frame_desc[0]; |
| 97 | offset = *(u16 *)&frame_desc[2]; |
| 98 | |
| 99 | queueno = rsi_get_queueno(frame_desc, offset); |
| 100 | length = rsi_get_length(frame_desc, offset); |
| 101 | extended_desc = rsi_get_extended_desc(frame_desc, offset); |
| 102 | |
| 103 | switch (queueno) { |
| 104 | case RSI_WIFI_DATA_Q: |
| 105 | skb = rsi_prepare_skb(common, |
| 106 | (frame_desc + offset), |
| 107 | length, |
| 108 | extended_desc); |
| 109 | if (skb == NULL) |
| 110 | goto fail; |
| 111 | |
| 112 | rsi_indicate_pkt_to_os(common, skb); |
| 113 | break; |
| 114 | |
| 115 | case RSI_WIFI_MGMT_Q: |
| 116 | rsi_mgmt_pkt_recv(common, (frame_desc + offset)); |
| 117 | break; |
| 118 | |
| 119 | default: |
| 120 | rsi_dbg(ERR_ZONE, "%s: pkt from invalid queue: %d\n", |
| 121 | __func__, queueno); |
| 122 | goto fail; |
| 123 | } |
| 124 | |
| 125 | index += actual_length; |
| 126 | rcv_pkt_len -= actual_length; |
| 127 | } while (rcv_pkt_len > 0); |
| 128 | |
| 129 | return 0; |
| 130 | fail: |
| 131 | return -EINVAL; |
| 132 | } |
| 133 | EXPORT_SYMBOL_GPL(rsi_read_pkt); |
| 134 | |
| 135 | /** |
| 136 | * rsi_tx_scheduler_thread() - This function is a kernel thread to send the |
| 137 | * packets to the device. |
| 138 | * @common: Pointer to the driver private structure. |
| 139 | * |
| 140 | * Return: None. |
| 141 | */ |
| 142 | static void rsi_tx_scheduler_thread(struct rsi_common *common) |
| 143 | { |
| 144 | struct rsi_hw *adapter = common->priv; |
| 145 | u32 timeout = EVENT_WAIT_FOREVER; |
| 146 | |
| 147 | do { |
| 148 | if (adapter->determine_event_timeout) |
| 149 | timeout = adapter->determine_event_timeout(adapter); |
| 150 | rsi_wait_event(&common->tx_thread.event, timeout); |
| 151 | rsi_reset_event(&common->tx_thread.event); |
| 152 | |
| 153 | if (common->init_done) |
| 154 | rsi_core_qos_processor(common); |
| 155 | } while (atomic_read(&common->tx_thread.thread_done) == 0); |
| 156 | complete_and_exit(&common->tx_thread.completion, 0); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * rsi_91x_init() - This function initializes os interface operations. |
| 161 | * @void: Void. |
| 162 | * |
| 163 | * Return: Pointer to the adapter structure on success, NULL on failure . |
| 164 | */ |
| 165 | struct rsi_hw *rsi_91x_init(void) |
| 166 | { |
| 167 | struct rsi_hw *adapter = NULL; |
| 168 | struct rsi_common *common = NULL; |
| 169 | u8 ii = 0; |
| 170 | |
| 171 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); |
| 172 | if (!adapter) |
| 173 | return NULL; |
| 174 | |
| 175 | adapter->priv = kzalloc(sizeof(*common), GFP_KERNEL); |
| 176 | if (adapter->priv == NULL) { |
| 177 | rsi_dbg(ERR_ZONE, "%s: Failed in allocation of memory\n", |
| 178 | __func__); |
| 179 | kfree(adapter); |
| 180 | return NULL; |
| 181 | } else { |
| 182 | common = adapter->priv; |
| 183 | common->priv = adapter; |
| 184 | } |
| 185 | |
| 186 | for (ii = 0; ii < NUM_SOFT_QUEUES; ii++) |
| 187 | skb_queue_head_init(&common->tx_queue[ii]); |
| 188 | |
| 189 | rsi_init_event(&common->tx_thread.event); |
| 190 | mutex_init(&common->mutex); |
| 191 | mutex_init(&common->tx_rxlock); |
| 192 | |
| 193 | if (rsi_create_kthread(common, |
| 194 | &common->tx_thread, |
| 195 | rsi_tx_scheduler_thread, |
| 196 | "Tx-Thread")) { |
| 197 | rsi_dbg(ERR_ZONE, "%s: Unable to init tx thrd\n", __func__); |
| 198 | goto err; |
| 199 | } |
| 200 | |
| 201 | common->init_done = true; |
| 202 | return adapter; |
| 203 | |
| 204 | err: |
| 205 | kfree(common); |
| 206 | kfree(adapter); |
| 207 | return NULL; |
| 208 | } |
| 209 | EXPORT_SYMBOL_GPL(rsi_91x_init); |
| 210 | |
| 211 | /** |
| 212 | * rsi_91x_deinit() - This function de-intializes os intf operations. |
| 213 | * @adapter: Pointer to the adapter structure. |
| 214 | * |
| 215 | * Return: None. |
| 216 | */ |
| 217 | void rsi_91x_deinit(struct rsi_hw *adapter) |
| 218 | { |
| 219 | struct rsi_common *common = adapter->priv; |
| 220 | u8 ii; |
| 221 | |
| 222 | rsi_dbg(INFO_ZONE, "%s: Performing deinit os ops\n", __func__); |
| 223 | |
| 224 | rsi_kill_thread(&common->tx_thread); |
| 225 | |
| 226 | for (ii = 0; ii < NUM_SOFT_QUEUES; ii++) |
| 227 | skb_queue_purge(&common->tx_queue[ii]); |
| 228 | |
| 229 | common->init_done = false; |
| 230 | |
| 231 | kfree(common); |
| 232 | kfree(adapter->rsi_dev); |
| 233 | kfree(adapter); |
| 234 | } |
| 235 | EXPORT_SYMBOL_GPL(rsi_91x_deinit); |
| 236 | |
| 237 | /** |
| 238 | * rsi_91x_hal_module_init() - This function is invoked when the module is |
| 239 | * loaded into the kernel. |
| 240 | * It registers the client driver. |
| 241 | * @void: Void. |
| 242 | * |
| 243 | * Return: 0 on success, -1 on failure. |
| 244 | */ |
| 245 | static int rsi_91x_hal_module_init(void) |
| 246 | { |
| 247 | rsi_dbg(INIT_ZONE, "%s: Module init called\n", __func__); |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * rsi_91x_hal_module_exit() - This function is called at the time of |
| 253 | * removing/unloading the module. |
| 254 | * It unregisters the client driver. |
| 255 | * @void: Void. |
| 256 | * |
| 257 | * Return: None. |
| 258 | */ |
| 259 | static void rsi_91x_hal_module_exit(void) |
| 260 | { |
| 261 | rsi_dbg(INIT_ZONE, "%s: Module exit called\n", __func__); |
| 262 | } |
| 263 | |
| 264 | module_init(rsi_91x_hal_module_init); |
| 265 | module_exit(rsi_91x_hal_module_exit); |
| 266 | MODULE_AUTHOR("Redpine Signals Inc"); |
| 267 | MODULE_DESCRIPTION("Station driver for RSI 91x devices"); |
| 268 | MODULE_SUPPORTED_DEVICE("RSI-91x"); |
| 269 | MODULE_VERSION("0.1"); |
| 270 | MODULE_LICENSE("Dual BSD/GPL"); |