blob: 54be83d3efdd682e8025577c5464f2c3807739c0 [file] [log] [blame]
Pavan Savoy53618cc2010-04-08 13:16:53 -05001/*
2 * Shared Transport Line discipline driver Core
3 * This hooks up ST KIM driver and ST LL driver
Pavan Savoya0cc2f32010-10-06 12:18:14 -04004 * Copyright (C) 2009-2010 Texas Instruments
5 * Author: Pavan Savoy <pavan_savoy@ti.com>
Pavan Savoy53618cc2010-04-08 13:16:53 -05006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#define pr_fmt(fmt) "(stc): " fmt
23#include <linux/module.h>
24#include <linux/kernel.h>
Pavan Savoy53618cc2010-04-08 13:16:53 -050025#include <linux/tty.h>
26
Pavan Savoy5c88b022011-02-04 02:23:09 -060027#include <linux/seq_file.h>
28#include <linux/skbuff.h>
29
Pavan Savoye5558672010-09-30 16:13:30 -040030#include <linux/ti_wilink_st.h>
Pavan Savoy53618cc2010-04-08 13:16:53 -050031
Pavan Savoy27712b32012-08-03 14:49:40 -050032extern void st_kim_recv(void *, const unsigned char *, long);
33void st_int_recv(void *, const unsigned char *, long);
Pavan Savoy53618cc2010-04-08 13:16:53 -050034/* function pointer pointing to either,
35 * st_kim_recv during registration to receive fw download responses
36 * st_int_recv after registration to receive proto stack responses
37 */
Pavan Savoy27712b32012-08-03 14:49:40 -050038static void (*st_recv) (void *, const unsigned char *, long);
Pavan Savoy53618cc2010-04-08 13:16:53 -050039
40/********************************************************************/
Pavan Savoy5c88b022011-02-04 02:23:09 -060041static void add_channel_to_table(struct st_data_s *st_gdata,
42 struct st_proto_s *new_proto)
Pavan Savoy53618cc2010-04-08 13:16:53 -050043{
Pavan Savoy5c88b022011-02-04 02:23:09 -060044 pr_info("%s: id %d\n", __func__, new_proto->chnl_id);
45 /* list now has the channel id as index itself */
46 st_gdata->list[new_proto->chnl_id] = new_proto;
Pavan Savoy764b0c42011-04-08 04:57:42 -050047 st_gdata->is_registered[new_proto->chnl_id] = true;
Pavan Savoy53618cc2010-04-08 13:16:53 -050048}
Pavan Savoy5c88b022011-02-04 02:23:09 -060049
50static void remove_channel_from_table(struct st_data_s *st_gdata,
51 struct st_proto_s *proto)
52{
53 pr_info("%s: id %d\n", __func__, proto->chnl_id);
Pavan Savoy764b0c42011-04-08 04:57:42 -050054/* st_gdata->list[proto->chnl_id] = NULL; */
55 st_gdata->is_registered[proto->chnl_id] = false;
Pavan Savoy5c88b022011-02-04 02:23:09 -060056}
Pavan Savoy36b5aee2010-07-22 05:32:06 -050057
Pavan Savoyef04d122011-02-04 02:23:13 -060058/*
59 * called from KIM during firmware download.
60 *
61 * This is a wrapper function to tty->ops->write_room.
62 * It returns number of free space available in
63 * uart tx buffer.
64 */
65int st_get_uart_wr_room(struct st_data_s *st_gdata)
66{
67 struct tty_struct *tty;
68 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
69 pr_err("tty unavailable to perform write");
70 return -1;
71 }
72 tty = st_gdata->tty;
73 return tty->ops->write_room(tty);
74}
75
Pavan Savoy53618cc2010-04-08 13:16:53 -050076/* can be called in from
77 * -- KIM (during fw download)
78 * -- ST Core (during st_write)
79 *
80 * This is the internal write function - a wrapper
81 * to tty->ops->write
82 */
83int st_int_write(struct st_data_s *st_gdata,
84 const unsigned char *data, int count)
85{
Pavan Savoy53618cc2010-04-08 13:16:53 -050086 struct tty_struct *tty;
87 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
88 pr_err("tty unavailable to perform write");
Pavan Savoy70442662011-02-04 02:23:11 -060089 return -EINVAL;
Pavan Savoy53618cc2010-04-08 13:16:53 -050090 }
91 tty = st_gdata->tty;
92#ifdef VERBOSE
Pavan Savoye6d9e642010-07-22 05:32:05 -050093 print_hex_dump(KERN_DEBUG, "<out<", DUMP_PREFIX_NONE,
94 16, 1, data, count, 0);
Pavan Savoy53618cc2010-04-08 13:16:53 -050095#endif
96 return tty->ops->write(tty, data, count);
97
98}
99
100/*
101 * push the skb received to relevant
102 * protocol stacks
103 */
Pavan Savoy27712b32012-08-03 14:49:40 -0500104static void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500105{
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600106 pr_debug(" %s(prot:%d) ", __func__, chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500107
108 if (unlikely
109 (st_gdata == NULL || st_gdata->rx_skb == NULL
Pavan Savoy764b0c42011-04-08 04:57:42 -0500110 || st_gdata->is_registered[chnl_id] == false)) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600111 pr_err("chnl_id %d not registered, no data to send?",
112 chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500113 kfree_skb(st_gdata->rx_skb);
114 return;
115 }
116 /* this cannot fail
117 * this shouldn't take long
118 * - should be just skb_queue_tail for the
119 * protocol stack driver
120 */
Pavan Savoy5c88b022011-02-04 02:23:09 -0600121 if (likely(st_gdata->list[chnl_id]->recv != NULL)) {
Pavan Savoybb8f3c02010-07-22 05:32:07 -0500122 if (unlikely
Pavan Savoy5c88b022011-02-04 02:23:09 -0600123 (st_gdata->list[chnl_id]->recv
124 (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb)
Pavan Savoy320920c2010-07-14 08:21:12 -0500125 != 0)) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600126 pr_err(" proto stack %d's ->recv failed", chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500127 kfree_skb(st_gdata->rx_skb);
128 return;
129 }
130 } else {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600131 pr_err(" proto stack %d's ->recv null", chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500132 kfree_skb(st_gdata->rx_skb);
133 }
Pavan Savoy53618cc2010-04-08 13:16:53 -0500134 return;
135}
136
Pavan Savoy36b5aee2010-07-22 05:32:06 -0500137/**
138 * st_reg_complete -
Pavan Savoy53618cc2010-04-08 13:16:53 -0500139 * to call registration complete callbacks
140 * of all protocol stack drivers
Pavan Savoybfb88d62011-12-15 10:38:20 -0600141 * This function is being called with spin lock held, protocol drivers are
142 * only expected to complete their waits and do nothing more than that.
Pavan Savoy53618cc2010-04-08 13:16:53 -0500143 */
Pavan Savoy27712b32012-08-03 14:49:40 -0500144static void st_reg_complete(struct st_data_s *st_gdata, char err)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500145{
146 unsigned char i = 0;
147 pr_info(" %s ", __func__);
Pavan Savoy5c88b022011-02-04 02:23:09 -0600148 for (i = 0; i < ST_MAX_CHANNELS; i++) {
Pavan Savoy764b0c42011-04-08 04:57:42 -0500149 if (likely(st_gdata != NULL &&
150 st_gdata->is_registered[i] == true &&
151 st_gdata->list[i]->reg_complete_cb != NULL)) {
Pavan Savoybb8f3c02010-07-22 05:32:07 -0500152 st_gdata->list[i]->reg_complete_cb
153 (st_gdata->list[i]->priv_data, err);
Pavan Savoy70442662011-02-04 02:23:11 -0600154 pr_info("protocol %d's cb sent %d\n", i, err);
155 if (err) { /* cleanup registered protocol */
Pavan Savoy764b0c42011-04-08 04:57:42 -0500156 st_gdata->is_registered[i] = false;
Lee Jonese4ebe5f2014-08-28 14:14:08 +0100157 if (st_gdata->protos_registered)
158 st_gdata->protos_registered--;
Pavan Savoy70442662011-02-04 02:23:11 -0600159 }
160 }
Pavan Savoy53618cc2010-04-08 13:16:53 -0500161 }
162}
163
164static inline int st_check_data_len(struct st_data_s *st_gdata,
Pavan Savoy5c88b022011-02-04 02:23:09 -0600165 unsigned char chnl_id, int len)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500166{
Pavan Savoy73f12e82010-10-12 16:27:38 -0400167 int room = skb_tailroom(st_gdata->rx_skb);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500168
Pavan Savoye6d9e642010-07-22 05:32:05 -0500169 pr_debug("len %d room %d", len, room);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500170
171 if (!len) {
172 /* Received packet has only packet header and
173 * has zero length payload. So, ask ST CORE to
174 * forward the packet to protocol driver (BT/FM/GPS)
175 */
Pavan Savoy5c88b022011-02-04 02:23:09 -0600176 st_send_frame(chnl_id, st_gdata);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500177
178 } else if (len > room) {
179 /* Received packet's payload length is larger.
180 * We can't accommodate it in created skb.
181 */
182 pr_err("Data length is too large len %d room %d", len,
183 room);
184 kfree_skb(st_gdata->rx_skb);
185 } else {
186 /* Packet header has non-zero payload length and
187 * we have enough space in created skb. Lets read
188 * payload data */
Pavan Savoy5c88b022011-02-04 02:23:09 -0600189 st_gdata->rx_state = ST_W4_DATA;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500190 st_gdata->rx_count = len;
191 return len;
192 }
193
194 /* Change ST state to continue to process next
195 * packet */
196 st_gdata->rx_state = ST_W4_PACKET_TYPE;
197 st_gdata->rx_skb = NULL;
198 st_gdata->rx_count = 0;
Pavan Savoy5c88b022011-02-04 02:23:09 -0600199 st_gdata->rx_chnl = 0;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500200
201 return 0;
202}
203
Pavan Savoy36b5aee2010-07-22 05:32:06 -0500204/**
205 * st_wakeup_ack - internal function for action when wake-up ack
206 * received
Pavan Savoy53618cc2010-04-08 13:16:53 -0500207 */
208static inline void st_wakeup_ack(struct st_data_s *st_gdata,
209 unsigned char cmd)
210{
Pavan Savoy73f12e82010-10-12 16:27:38 -0400211 struct sk_buff *waiting_skb;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500212 unsigned long flags = 0;
213
214 spin_lock_irqsave(&st_gdata->lock, flags);
215 /* de-Q from waitQ and Q in txQ now that the
216 * chip is awake
217 */
218 while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq)))
219 skb_queue_tail(&st_gdata->txq, waiting_skb);
220
221 /* state forwarded to ST LL */
222 st_ll_sleep_state(st_gdata, (unsigned long)cmd);
223 spin_unlock_irqrestore(&st_gdata->lock, flags);
224
225 /* wake up to send the recently copied skbs from waitQ */
226 st_tx_wakeup(st_gdata);
227}
228
Pavan Savoy36b5aee2010-07-22 05:32:06 -0500229/**
230 * st_int_recv - ST's internal receive function.
231 * Decodes received RAW data and forwards to corresponding
232 * client drivers (Bluetooth,FM,GPS..etc).
233 * This can receive various types of packets,
234 * HCI-Events, ACL, SCO, 4 types of HCI-LL PM packets
235 * CH-8 packets from FM, CH-9 packets from GPS cores.
Pavan Savoy53618cc2010-04-08 13:16:53 -0500236 */
237void st_int_recv(void *disc_data,
238 const unsigned char *data, long count)
239{
Pavan Savoy73f12e82010-10-12 16:27:38 -0400240 char *ptr;
Pavan Savoy5c88b022011-02-04 02:23:09 -0600241 struct st_proto_s *proto;
242 unsigned short payload_len = 0;
channing25c22d52013-01-10 16:27:29 +0800243 int len = 0;
244 unsigned char type = 0;
Pavan Savoy5c88b022011-02-04 02:23:09 -0600245 unsigned char *plen;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500246 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
Pavan Savoy6d71ba22011-02-04 02:23:14 -0600247 unsigned long flags;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500248
249 ptr = (char *)data;
250 /* tty_receive sent null ? */
251 if (unlikely(ptr == NULL) || (st_gdata == NULL)) {
252 pr_err(" received null from TTY ");
253 return;
254 }
255
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600256 pr_debug("count %ld rx_state %ld"
Pavan Savoy53618cc2010-04-08 13:16:53 -0500257 "rx_count %ld", count, st_gdata->rx_state,
258 st_gdata->rx_count);
259
Pavan Savoy6d71ba22011-02-04 02:23:14 -0600260 spin_lock_irqsave(&st_gdata->lock, flags);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500261 /* Decode received bytes here */
262 while (count) {
263 if (st_gdata->rx_count) {
264 len = min_t(unsigned int, st_gdata->rx_count, count);
265 memcpy(skb_put(st_gdata->rx_skb, len), ptr, len);
266 st_gdata->rx_count -= len;
267 count -= len;
268 ptr += len;
269
270 if (st_gdata->rx_count)
271 continue;
272
273 /* Check ST RX state machine , where are we? */
274 switch (st_gdata->rx_state) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600275 /* Waiting for complete packet ? */
276 case ST_W4_DATA:
Pavan Savoye6d9e642010-07-22 05:32:05 -0500277 pr_debug("Complete pkt received");
Pavan Savoy53618cc2010-04-08 13:16:53 -0500278 /* Ask ST CORE to forward
279 * the packet to protocol driver */
Pavan Savoy5c88b022011-02-04 02:23:09 -0600280 st_send_frame(st_gdata->rx_chnl, st_gdata);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500281
282 st_gdata->rx_state = ST_W4_PACKET_TYPE;
283 st_gdata->rx_skb = NULL;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500284 continue;
Pavan Savoy5c88b022011-02-04 02:23:09 -0600285 /* parse the header to know details */
286 case ST_W4_HEADER:
287 proto = st_gdata->list[st_gdata->rx_chnl];
288 plen =
289 &st_gdata->rx_skb->data
290 [proto->offset_len_in_hdr];
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600291 pr_debug("plen pointing to %x\n", *plen);
Pavan Savoy5c88b022011-02-04 02:23:09 -0600292 if (proto->len_size == 1)/* 1 byte len field */
293 payload_len = *(unsigned char *)plen;
294 else if (proto->len_size == 2)
295 payload_len =
296 __le16_to_cpu(*(unsigned short *)plen);
297 else
298 pr_info("%s: invalid length "
299 "for id %d\n",
300 __func__, proto->chnl_id);
301 st_check_data_len(st_gdata, proto->chnl_id,
302 payload_len);
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600303 pr_debug("off %d, pay len %d\n",
Pavan Savoy5c88b022011-02-04 02:23:09 -0600304 proto->offset_len_in_hdr, payload_len);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500305 continue;
306 } /* end of switch rx_state */
307 }
308
309 /* end of if rx_count */
310 /* Check first byte of packet and identify module
311 * owner (BT/FM/GPS) */
312 switch (*ptr) {
Pavan Savoy53618cc2010-04-08 13:16:53 -0500313 case LL_SLEEP_IND:
314 case LL_SLEEP_ACK:
315 case LL_WAKE_UP_IND:
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600316 pr_debug("PM packet");
Pavan Savoy53618cc2010-04-08 13:16:53 -0500317 /* this takes appropriate action based on
318 * sleep state received --
319 */
320 st_ll_sleep_state(st_gdata, *ptr);
Pavan Savoy6d71ba22011-02-04 02:23:14 -0600321 /* if WAKEUP_IND collides copy from waitq to txq
322 * and assume chip awake
323 */
324 spin_unlock_irqrestore(&st_gdata->lock, flags);
325 if (st_ll_getstate(st_gdata) == ST_LL_AWAKE)
326 st_wakeup_ack(st_gdata, LL_WAKE_UP_ACK);
327 spin_lock_irqsave(&st_gdata->lock, flags);
328
Pavan Savoy53618cc2010-04-08 13:16:53 -0500329 ptr++;
330 count--;
331 continue;
332 case LL_WAKE_UP_ACK:
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600333 pr_debug("PM packet");
Pavan Savoy6d71ba22011-02-04 02:23:14 -0600334
335 spin_unlock_irqrestore(&st_gdata->lock, flags);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500336 /* wake up ack received */
337 st_wakeup_ack(st_gdata, *ptr);
Pavan Savoy6d71ba22011-02-04 02:23:14 -0600338 spin_lock_irqsave(&st_gdata->lock, flags);
339
Pavan Savoy53618cc2010-04-08 13:16:53 -0500340 ptr++;
341 count--;
342 continue;
343 /* Unknow packet? */
344 default:
Pavan Savoy5c88b022011-02-04 02:23:09 -0600345 type = *ptr;
Vijay Badawadagi78bb9692011-08-10 10:18:33 -0500346 if (st_gdata->list[type] == NULL) {
347 pr_err("chip/interface misbehavior dropping"
348 " frame starting with 0x%02x", type);
349 goto done;
350
351 }
Pavan Savoy5c88b022011-02-04 02:23:09 -0600352 st_gdata->rx_skb = alloc_skb(
353 st_gdata->list[type]->max_frame_size,
354 GFP_ATOMIC);
Alan Cox5353cf02012-07-30 14:40:06 -0700355 if (st_gdata->rx_skb == NULL) {
356 pr_err("out of memory: dropping\n");
357 goto done;
358 }
359
Pavan Savoy5c88b022011-02-04 02:23:09 -0600360 skb_reserve(st_gdata->rx_skb,
361 st_gdata->list[type]->reserve);
362 /* next 2 required for BT only */
363 st_gdata->rx_skb->cb[0] = type; /*pkt_type*/
364 st_gdata->rx_skb->cb[1] = 0; /*incoming*/
365 st_gdata->rx_chnl = *ptr;
366 st_gdata->rx_state = ST_W4_HEADER;
367 st_gdata->rx_count = st_gdata->list[type]->hdr_len;
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600368 pr_debug("rx_count %ld\n", st_gdata->rx_count);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500369 };
370 ptr++;
371 count--;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500372 }
Vijay Badawadagi78bb9692011-08-10 10:18:33 -0500373done:
Pavan Savoy6d71ba22011-02-04 02:23:14 -0600374 spin_unlock_irqrestore(&st_gdata->lock, flags);
Pavan Savoye6d9e642010-07-22 05:32:05 -0500375 pr_debug("done %s", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500376 return;
377}
378
Pavan Savoy36b5aee2010-07-22 05:32:06 -0500379/**
380 * st_int_dequeue - internal de-Q function.
381 * If the previous data set was not written
382 * completely, return that skb which has the pending data.
383 * In normal cases, return top of txq.
Pavan Savoy53618cc2010-04-08 13:16:53 -0500384 */
Pavan Savoy27712b32012-08-03 14:49:40 -0500385static struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500386{
387 struct sk_buff *returning_skb;
388
Pavan Savoye6d9e642010-07-22 05:32:05 -0500389 pr_debug("%s", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500390 if (st_gdata->tx_skb != NULL) {
391 returning_skb = st_gdata->tx_skb;
392 st_gdata->tx_skb = NULL;
393 return returning_skb;
394 }
Pavan Savoy53618cc2010-04-08 13:16:53 -0500395 return skb_dequeue(&st_gdata->txq);
396}
397
Pavan Savoy36b5aee2010-07-22 05:32:06 -0500398/**
399 * st_int_enqueue - internal Q-ing function.
400 * Will either Q the skb to txq or the tx_waitq
401 * depending on the ST LL state.
402 * If the chip is asleep, then Q it onto waitq and
403 * wakeup the chip.
404 * txq and waitq needs protection since the other contexts
405 * may be sending data, waking up chip.
Pavan Savoy53618cc2010-04-08 13:16:53 -0500406 */
Pavan Savoy27712b32012-08-03 14:49:40 -0500407static void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500408{
409 unsigned long flags = 0;
410
Pavan Savoye6d9e642010-07-22 05:32:05 -0500411 pr_debug("%s", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500412 spin_lock_irqsave(&st_gdata->lock, flags);
413
414 switch (st_ll_getstate(st_gdata)) {
415 case ST_LL_AWAKE:
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600416 pr_debug("ST LL is AWAKE, sending normally");
Pavan Savoy53618cc2010-04-08 13:16:53 -0500417 skb_queue_tail(&st_gdata->txq, skb);
418 break;
419 case ST_LL_ASLEEP_TO_AWAKE:
420 skb_queue_tail(&st_gdata->tx_waitq, skb);
421 break;
Pavan Savoy36b5aee2010-07-22 05:32:06 -0500422 case ST_LL_AWAKE_TO_ASLEEP:
Pavan Savoy53618cc2010-04-08 13:16:53 -0500423 pr_err("ST LL is illegal state(%ld),"
424 "purging received skb.", st_ll_getstate(st_gdata));
425 kfree_skb(skb);
426 break;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500427 case ST_LL_ASLEEP:
Pavan Savoy53618cc2010-04-08 13:16:53 -0500428 skb_queue_tail(&st_gdata->tx_waitq, skb);
429 st_ll_wakeup(st_gdata);
430 break;
431 default:
432 pr_err("ST LL is illegal state(%ld),"
433 "purging received skb.", st_ll_getstate(st_gdata));
434 kfree_skb(skb);
435 break;
436 }
Pavan Savoy36b5aee2010-07-22 05:32:06 -0500437
Pavan Savoy53618cc2010-04-08 13:16:53 -0500438 spin_unlock_irqrestore(&st_gdata->lock, flags);
Pavan Savoye6d9e642010-07-22 05:32:05 -0500439 pr_debug("done %s", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500440 return;
441}
442
443/*
444 * internal wakeup function
445 * called from either
446 * - TTY layer when write's finished
447 * - st_write (in context of the protocol stack)
448 */
449void st_tx_wakeup(struct st_data_s *st_data)
450{
451 struct sk_buff *skb;
452 unsigned long flags; /* for irq save flags */
Pavan Savoye6d9e642010-07-22 05:32:05 -0500453 pr_debug("%s", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500454 /* check for sending & set flag sending here */
455 if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) {
Pavan Savoy6710fcf2011-02-04 02:23:12 -0600456 pr_debug("ST already sending");
Pavan Savoy53618cc2010-04-08 13:16:53 -0500457 /* keep sending */
458 set_bit(ST_TX_WAKEUP, &st_data->tx_state);
459 return;
460 /* TX_WAKEUP will be checked in another
461 * context
462 */
463 }
464 do { /* come back if st_tx_wakeup is set */
465 /* woke-up to write */
466 clear_bit(ST_TX_WAKEUP, &st_data->tx_state);
467 while ((skb = st_int_dequeue(st_data))) {
468 int len;
469 spin_lock_irqsave(&st_data->lock, flags);
470 /* enable wake-up from TTY */
471 set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags);
472 len = st_int_write(st_data, skb->data, skb->len);
473 skb_pull(skb, len);
474 /* if skb->len = len as expected, skb->len=0 */
475 if (skb->len) {
476 /* would be the next skb to be sent */
477 st_data->tx_skb = skb;
478 spin_unlock_irqrestore(&st_data->lock, flags);
479 break;
480 }
481 kfree_skb(skb);
482 spin_unlock_irqrestore(&st_data->lock, flags);
483 }
484 /* if wake-up is set in another context- restart sending */
485 } while (test_bit(ST_TX_WAKEUP, &st_data->tx_state));
486
487 /* clear flag sending */
488 clear_bit(ST_TX_SENDING, &st_data->tx_state);
489}
490
491/********************************************************************/
492/* functions called from ST KIM
493*/
Pavan Savoyc1afac12010-07-28 02:25:59 -0500494void kim_st_list_protocols(struct st_data_s *st_gdata, void *buf)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500495{
Pavan Savoyc1afac12010-07-28 02:25:59 -0500496 seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n",
Naveen Jain36e574f2010-06-09 07:20:40 -0500497 st_gdata->protos_registered,
Pavan Savoy764b0c42011-04-08 04:57:42 -0500498 st_gdata->is_registered[0x04] == true ? 'R' : 'U',
499 st_gdata->is_registered[0x08] == true ? 'R' : 'U',
500 st_gdata->is_registered[0x09] == true ? 'R' : 'U');
Pavan Savoy53618cc2010-04-08 13:16:53 -0500501}
502
503/********************************************************************/
504/*
505 * functions called from protocol stack drivers
506 * to be EXPORT-ed
507 */
508long st_register(struct st_proto_s *new_proto)
509{
510 struct st_data_s *st_gdata;
Pavan Savoy320920c2010-07-14 08:21:12 -0500511 long err = 0;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500512 unsigned long flags = 0;
513
Pavan Savoydbd3a872010-08-19 14:08:51 -0400514 st_kim_ref(&st_gdata, 0);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500515 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
516 || new_proto->reg_complete_cb == NULL) {
517 pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
Pavan Savoy70442662011-02-04 02:23:11 -0600518 return -EINVAL;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500519 }
520
Pavan Savoy5c88b022011-02-04 02:23:09 -0600521 if (new_proto->chnl_id >= ST_MAX_CHANNELS) {
522 pr_err("chnl_id %d not supported", new_proto->chnl_id);
Pavan Savoy320920c2010-07-14 08:21:12 -0500523 return -EPROTONOSUPPORT;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500524 }
525
Pavan Savoy764b0c42011-04-08 04:57:42 -0500526 if (st_gdata->is_registered[new_proto->chnl_id] == true) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600527 pr_err("chnl_id %d already registered", new_proto->chnl_id);
Pavan Savoy320920c2010-07-14 08:21:12 -0500528 return -EALREADY;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500529 }
530
531 /* can be from process context only */
532 spin_lock_irqsave(&st_gdata->lock, flags);
533
534 if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600535 pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500536 /* fw download in progress */
Pavan Savoy53618cc2010-04-08 13:16:53 -0500537
Pavan Savoy5c88b022011-02-04 02:23:09 -0600538 add_channel_to_table(st_gdata, new_proto);
Naveen Jain36e574f2010-06-09 07:20:40 -0500539 st_gdata->protos_registered++;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500540 new_proto->write = st_write;
541
542 set_bit(ST_REG_PENDING, &st_gdata->st_state);
543 spin_unlock_irqrestore(&st_gdata->lock, flags);
Pavan Savoy320920c2010-07-14 08:21:12 -0500544 return -EINPROGRESS;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500545 } else if (st_gdata->protos_registered == ST_EMPTY) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600546 pr_info(" chnl_id list empty :%d ", new_proto->chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500547 set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
548 st_recv = st_kim_recv;
549
Pavan Savoybfb88d62011-12-15 10:38:20 -0600550 /* enable the ST LL - to set default chip state */
551 st_ll_enable(st_gdata);
552
Pavan Savoy53618cc2010-04-08 13:16:53 -0500553 /* release lock previously held - re-locked below */
554 spin_unlock_irqrestore(&st_gdata->lock, flags);
555
Pavan Savoy53618cc2010-04-08 13:16:53 -0500556 /* this may take a while to complete
557 * since it involves BT fw download
558 */
Pavan Savoy38d9df42010-07-08 08:55:17 -0500559 err = st_kim_start(st_gdata->kim_data);
Pavan Savoy320920c2010-07-14 08:21:12 -0500560 if (err != 0) {
Pavan Savoy53618cc2010-04-08 13:16:53 -0500561 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
562 if ((st_gdata->protos_registered != ST_EMPTY) &&
563 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
564 pr_err(" KIM failure complete callback ");
Oleksandr Kozaruk3a2d3d22013-08-29 10:55:48 +0300565 spin_lock_irqsave(&st_gdata->lock, flags);
Pavan Savoy70442662011-02-04 02:23:11 -0600566 st_reg_complete(st_gdata, err);
Oleksandr Kozaruk3a2d3d22013-08-29 10:55:48 +0300567 spin_unlock_irqrestore(&st_gdata->lock, flags);
Pavan Savoybfb88d62011-12-15 10:38:20 -0600568 clear_bit(ST_REG_PENDING, &st_gdata->st_state);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500569 }
Pavan Savoy70442662011-02-04 02:23:11 -0600570 return -EINVAL;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500571 }
572
Pavan Savoybfb88d62011-12-15 10:38:20 -0600573 spin_lock_irqsave(&st_gdata->lock, flags);
574
Pavan Savoy53618cc2010-04-08 13:16:53 -0500575 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
576 st_recv = st_int_recv;
577
578 /* this is where all pending registration
579 * are signalled to be complete by calling callback functions
580 */
581 if ((st_gdata->protos_registered != ST_EMPTY) &&
582 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
Pavan Savoye6d9e642010-07-22 05:32:05 -0500583 pr_debug(" call reg complete callback ");
Pavan Savoy320920c2010-07-14 08:21:12 -0500584 st_reg_complete(st_gdata, 0);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500585 }
586 clear_bit(ST_REG_PENDING, &st_gdata->st_state);
587
588 /* check for already registered once more,
589 * since the above check is old
590 */
Pavan Savoy764b0c42011-04-08 04:57:42 -0500591 if (st_gdata->is_registered[new_proto->chnl_id] == true) {
Pavan Savoy53618cc2010-04-08 13:16:53 -0500592 pr_err(" proto %d already registered ",
Pavan Savoy5c88b022011-02-04 02:23:09 -0600593 new_proto->chnl_id);
Pavan Savoybfb88d62011-12-15 10:38:20 -0600594 spin_unlock_irqrestore(&st_gdata->lock, flags);
Pavan Savoy320920c2010-07-14 08:21:12 -0500595 return -EALREADY;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500596 }
597
Pavan Savoy5c88b022011-02-04 02:23:09 -0600598 add_channel_to_table(st_gdata, new_proto);
Naveen Jain36e574f2010-06-09 07:20:40 -0500599 st_gdata->protos_registered++;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500600 new_proto->write = st_write;
601 spin_unlock_irqrestore(&st_gdata->lock, flags);
602 return err;
603 }
604 /* if fw is already downloaded & new stack registers protocol */
605 else {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600606 add_channel_to_table(st_gdata, new_proto);
Naveen Jain36e574f2010-06-09 07:20:40 -0500607 st_gdata->protos_registered++;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500608 new_proto->write = st_write;
609
610 /* lock already held before entering else */
611 spin_unlock_irqrestore(&st_gdata->lock, flags);
612 return err;
613 }
Pavan Savoy5c88b022011-02-04 02:23:09 -0600614 pr_debug("done %s(%d) ", __func__, new_proto->chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500615}
616EXPORT_SYMBOL_GPL(st_register);
617
618/* to unregister a protocol -
619 * to be called from protocol stack driver
620 */
Pavan Savoy5c88b022011-02-04 02:23:09 -0600621long st_unregister(struct st_proto_s *proto)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500622{
Pavan Savoy320920c2010-07-14 08:21:12 -0500623 long err = 0;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500624 unsigned long flags = 0;
625 struct st_data_s *st_gdata;
626
Pavan Savoy5c88b022011-02-04 02:23:09 -0600627 pr_debug("%s: %d ", __func__, proto->chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500628
Pavan Savoydbd3a872010-08-19 14:08:51 -0400629 st_kim_ref(&st_gdata, 0);
Steven Rostedt7316a9f2011-05-23 16:45:32 -0400630 if (!st_gdata || proto->chnl_id >= ST_MAX_CHANNELS) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600631 pr_err(" chnl_id %d not supported", proto->chnl_id);
Pavan Savoy320920c2010-07-14 08:21:12 -0500632 return -EPROTONOSUPPORT;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500633 }
634
635 spin_lock_irqsave(&st_gdata->lock, flags);
636
Pavan Savoybfb88d62011-12-15 10:38:20 -0600637 if (st_gdata->is_registered[proto->chnl_id] == false) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600638 pr_err(" chnl_id %d not registered", proto->chnl_id);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500639 spin_unlock_irqrestore(&st_gdata->lock, flags);
Pavan Savoy320920c2010-07-14 08:21:12 -0500640 return -EPROTONOSUPPORT;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500641 }
642
Lee Jonese4ebe5f2014-08-28 14:14:08 +0100643 if (st_gdata->protos_registered)
644 st_gdata->protos_registered--;
645
Pavan Savoy5c88b022011-02-04 02:23:09 -0600646 remove_channel_from_table(st_gdata, proto);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500647 spin_unlock_irqrestore(&st_gdata->lock, flags);
648
649 if ((st_gdata->protos_registered == ST_EMPTY) &&
650 (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
Pavan Savoy5c88b022011-02-04 02:23:09 -0600651 pr_info(" all chnl_ids unregistered ");
Pavan Savoy53618cc2010-04-08 13:16:53 -0500652
653 /* stop traffic on tty */
654 if (st_gdata->tty) {
655 tty_ldisc_flush(st_gdata->tty);
656 stop_tty(st_gdata->tty);
657 }
658
Pavan Savoy5c88b022011-02-04 02:23:09 -0600659 /* all chnl_ids now unregistered */
Pavan Savoy38d9df42010-07-08 08:55:17 -0500660 st_kim_stop(st_gdata->kim_data);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500661 /* disable ST LL */
662 st_ll_disable(st_gdata);
663 }
664 return err;
665}
666
667/*
668 * called in protocol stack drivers
669 * via the write function pointer
670 */
671long st_write(struct sk_buff *skb)
672{
673 struct st_data_s *st_gdata;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500674 long len;
675
Pavan Savoydbd3a872010-08-19 14:08:51 -0400676 st_kim_ref(&st_gdata, 0);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500677 if (unlikely(skb == NULL || st_gdata == NULL
678 || st_gdata->tty == NULL)) {
679 pr_err("data/tty unavailable to perform write");
Pavan Savoy70442662011-02-04 02:23:11 -0600680 return -EINVAL;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500681 }
Pavan Savoyc1605f22011-03-02 03:59:56 -0600682
Pavan Savoye6d9e642010-07-22 05:32:05 -0500683 pr_debug("%d to be written", skb->len);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500684 len = skb->len;
685
686 /* st_ll to decide where to enqueue the skb */
687 st_int_enqueue(st_gdata, skb);
688 /* wake up */
689 st_tx_wakeup(st_gdata);
690
691 /* return number of bytes written */
692 return len;
693}
694
695/* for protocols making use of shared transport */
696EXPORT_SYMBOL_GPL(st_unregister);
697
698/********************************************************************/
699/*
700 * functions called from TTY layer
701 */
702static int st_tty_open(struct tty_struct *tty)
703{
Pavan Savoy320920c2010-07-14 08:21:12 -0500704 int err = 0;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500705 struct st_data_s *st_gdata;
706 pr_info("%s ", __func__);
707
Pavan Savoydbd3a872010-08-19 14:08:51 -0400708 st_kim_ref(&st_gdata, 0);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500709 st_gdata->tty = tty;
710 tty->disc_data = st_gdata;
711
712 /* don't do an wakeup for now */
713 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
714
715 /* mem already allocated
716 */
717 tty->receive_room = 65536;
718 /* Flush any pending characters in the driver and discipline. */
719 tty_ldisc_flush(tty);
720 tty_driver_flush_buffer(tty);
721 /*
722 * signal to UIM via KIM that -
723 * installation of N_TI_WL ldisc is complete
724 */
Pavan Savoy38d9df42010-07-08 08:55:17 -0500725 st_kim_complete(st_gdata->kim_data);
Pavan Savoye6d9e642010-07-22 05:32:05 -0500726 pr_debug("done %s", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500727 return err;
728}
729
730static void st_tty_close(struct tty_struct *tty)
731{
Pavan Savoy5c88b022011-02-04 02:23:09 -0600732 unsigned char i = ST_MAX_CHANNELS;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500733 unsigned long flags = 0;
734 struct st_data_s *st_gdata = tty->disc_data;
735
736 pr_info("%s ", __func__);
737
738 /* TODO:
739 * if a protocol has been registered & line discipline
740 * un-installed for some reason - what should be done ?
741 */
742 spin_lock_irqsave(&st_gdata->lock, flags);
Pavan Savoy5c88b022011-02-04 02:23:09 -0600743 for (i = ST_BT; i < ST_MAX_CHANNELS; i++) {
Pavan Savoy5926cef2011-08-10 10:18:30 -0500744 if (st_gdata->is_registered[i] == true)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500745 pr_err("%d not un-registered", i);
746 st_gdata->list[i] = NULL;
Pavan Savoy651d62a2011-08-10 10:18:37 -0500747 st_gdata->is_registered[i] = false;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500748 }
Pavan Savoybb8f3c02010-07-22 05:32:07 -0500749 st_gdata->protos_registered = 0;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500750 spin_unlock_irqrestore(&st_gdata->lock, flags);
751 /*
752 * signal to UIM via KIM that -
753 * N_TI_WL ldisc is un-installed
754 */
Pavan Savoy38d9df42010-07-08 08:55:17 -0500755 st_kim_complete(st_gdata->kim_data);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500756 st_gdata->tty = NULL;
757 /* Flush any pending characters in the driver and discipline. */
758 tty_ldisc_flush(tty);
759 tty_driver_flush_buffer(tty);
760
761 spin_lock_irqsave(&st_gdata->lock, flags);
762 /* empty out txq and tx_waitq */
763 skb_queue_purge(&st_gdata->txq);
764 skb_queue_purge(&st_gdata->tx_waitq);
765 /* reset the TTY Rx states of ST */
766 st_gdata->rx_count = 0;
767 st_gdata->rx_state = ST_W4_PACKET_TYPE;
768 kfree_skb(st_gdata->rx_skb);
769 st_gdata->rx_skb = NULL;
770 spin_unlock_irqrestore(&st_gdata->lock, flags);
771
Pavan Savoye6d9e642010-07-22 05:32:05 -0500772 pr_debug("%s: done ", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500773}
774
Linus Torvalds55db4c62011-06-04 06:33:24 +0900775static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
776 char *tty_flags, int count)
Pavan Savoy53618cc2010-04-08 13:16:53 -0500777{
Pavan Savoy53618cc2010-04-08 13:16:53 -0500778#ifdef VERBOSE
Pavan Savoye6d9e642010-07-22 05:32:05 -0500779 print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
780 16, 1, data, count, 0);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500781#endif
782
783 /*
784 * if fw download is in progress then route incoming data
785 * to KIM for validation
786 */
787 st_recv(tty->disc_data, data, count);
Pavan Savoye6d9e642010-07-22 05:32:05 -0500788 pr_debug("done %s", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500789}
790
791/* wake-up function called in from the TTY layer
792 * inside the internal wakeup function will be called
793 */
794static void st_tty_wakeup(struct tty_struct *tty)
795{
796 struct st_data_s *st_gdata = tty->disc_data;
Pavan Savoye6d9e642010-07-22 05:32:05 -0500797 pr_debug("%s ", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500798 /* don't do an wakeup for now */
799 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
800
801 /* call our internal wakeup */
802 st_tx_wakeup((void *)st_gdata);
803}
804
805static void st_tty_flush_buffer(struct tty_struct *tty)
806{
807 struct st_data_s *st_gdata = tty->disc_data;
Pavan Savoye6d9e642010-07-22 05:32:05 -0500808 pr_debug("%s ", __func__);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500809
810 kfree_skb(st_gdata->tx_skb);
811 st_gdata->tx_skb = NULL;
812
Peter Hurley94459a92013-11-29 18:00:35 -0500813 tty_driver_flush_buffer(tty);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500814 return;
815}
816
Pavan Savoy73f12e82010-10-12 16:27:38 -0400817static struct tty_ldisc_ops st_ldisc_ops = {
818 .magic = TTY_LDISC_MAGIC,
819 .name = "n_st",
820 .open = st_tty_open,
821 .close = st_tty_close,
822 .receive_buf = st_tty_receive,
823 .write_wakeup = st_tty_wakeup,
824 .flush_buffer = st_tty_flush_buffer,
825 .owner = THIS_MODULE
826};
827
Pavan Savoy53618cc2010-04-08 13:16:53 -0500828/********************************************************************/
829int st_core_init(struct st_data_s **core_data)
830{
831 struct st_data_s *st_gdata;
832 long err;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500833
Pavan Savoy73f12e82010-10-12 16:27:38 -0400834 err = tty_register_ldisc(N_TI_WL, &st_ldisc_ops);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500835 if (err) {
836 pr_err("error registering %d line discipline %ld",
837 N_TI_WL, err);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500838 return err;
839 }
Pavan Savoye6d9e642010-07-22 05:32:05 -0500840 pr_debug("registered n_shared line discipline");
Pavan Savoy53618cc2010-04-08 13:16:53 -0500841
842 st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
843 if (!st_gdata) {
844 pr_err("memory allocation failed");
845 err = tty_unregister_ldisc(N_TI_WL);
846 if (err)
847 pr_err("unable to un-register ldisc %ld", err);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500848 err = -ENOMEM;
849 return err;
850 }
851
852 /* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's
853 * will be pushed in this queue for actual transmission.
854 */
855 skb_queue_head_init(&st_gdata->txq);
856 skb_queue_head_init(&st_gdata->tx_waitq);
857
858 /* Locking used in st_int_enqueue() to avoid multiple execution */
859 spin_lock_init(&st_gdata->lock);
860
Pavan Savoy53618cc2010-04-08 13:16:53 -0500861 err = st_ll_init(st_gdata);
862 if (err) {
863 pr_err("error during st_ll initialization(%ld)", err);
864 kfree(st_gdata);
865 err = tty_unregister_ldisc(N_TI_WL);
866 if (err)
867 pr_err("unable to un-register ldisc");
Pavan Savoy70442662011-02-04 02:23:11 -0600868 return err;
Pavan Savoy53618cc2010-04-08 13:16:53 -0500869 }
870 *core_data = st_gdata;
871 return 0;
872}
873
874void st_core_exit(struct st_data_s *st_gdata)
875{
876 long err;
877 /* internal module cleanup */
878 err = st_ll_deinit(st_gdata);
879 if (err)
880 pr_err("error during deinit of ST LL %ld", err);
Pavan Savoy73f12e82010-10-12 16:27:38 -0400881
Pavan Savoy53618cc2010-04-08 13:16:53 -0500882 if (st_gdata != NULL) {
883 /* Free ST Tx Qs and skbs */
884 skb_queue_purge(&st_gdata->txq);
885 skb_queue_purge(&st_gdata->tx_waitq);
886 kfree_skb(st_gdata->rx_skb);
887 kfree_skb(st_gdata->tx_skb);
888 /* TTY ldisc cleanup */
889 err = tty_unregister_ldisc(N_TI_WL);
890 if (err)
891 pr_err("unable to un-register ldisc %ld", err);
Pavan Savoy53618cc2010-04-08 13:16:53 -0500892 /* free the global data pointer */
893 kfree(st_gdata);
894 }
895}
896
897