2 * Shared Transport Line discipline driver Core
3 * This hooks up ST KIM driver and ST LL driver
4 * Copyright (C) 2009-2010 Texas Instruments
5 * Author: Pavan Savoy <pavan_savoy@ti.com>
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.
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.
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
22 #define pr_fmt(fmt) "(stc): " fmt
23 #include <linux/module.h>
24 #include <linux/kernel.h>
25 #include <linux/init.h>
26 #include <linux/tty.h>
28 #include <linux/seq_file.h>
29 #include <linux/skbuff.h>
31 #include <linux/ti_wilink_st.h>
33 extern void st_kim_recv(void *, const unsigned char *, long);
34 void st_int_recv(void *, const unsigned char *, long);
35 /* function pointer pointing to either,
36 * st_kim_recv during registration to receive fw download responses
37 * st_int_recv after registration to receive proto stack responses
39 static void (*st_recv) (void *, const unsigned char *, long);
41 /********************************************************************/
42 static void add_channel_to_table(struct st_data_s *st_gdata,
43 struct st_proto_s *new_proto)
45 pr_info("%s: id %d\n", __func__, new_proto->chnl_id);
46 /* list now has the channel id as index itself */
47 st_gdata->list[new_proto->chnl_id] = new_proto;
48 st_gdata->is_registered[new_proto->chnl_id] = true;
51 static void remove_channel_from_table(struct st_data_s *st_gdata,
52 struct st_proto_s *proto)
54 pr_info("%s: id %d\n", __func__, proto->chnl_id);
55 /* st_gdata->list[proto->chnl_id] = NULL; */
56 st_gdata->is_registered[proto->chnl_id] = false;
60 * called from KIM during firmware download.
62 * This is a wrapper function to tty->ops->write_room.
63 * It returns number of free space available in
66 int st_get_uart_wr_room(struct st_data_s *st_gdata)
68 struct tty_struct *tty;
69 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
70 pr_err("tty unavailable to perform write");
74 return tty->ops->write_room(tty);
77 /* can be called in from
78 * -- KIM (during fw download)
79 * -- ST Core (during st_write)
81 * This is the internal write function - a wrapper
84 int st_int_write(struct st_data_s *st_gdata,
85 const unsigned char *data, int count)
87 struct tty_struct *tty;
88 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
89 pr_err("tty unavailable to perform write");
94 print_hex_dump(KERN_DEBUG, "<out<", DUMP_PREFIX_NONE,
95 16, 1, data, count, 0);
97 return tty->ops->write(tty, data, count);
102 * push the skb received to relevant
105 static void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata)
107 pr_debug(" %s(prot:%d) ", __func__, chnl_id);
110 (st_gdata == NULL || st_gdata->rx_skb == NULL
111 || st_gdata->is_registered[chnl_id] == false)) {
112 pr_err("chnl_id %d not registered, no data to send?",
114 kfree_skb(st_gdata->rx_skb);
118 * this shouldn't take long
119 * - should be just skb_queue_tail for the
120 * protocol stack driver
122 if (likely(st_gdata->list[chnl_id]->recv != NULL)) {
124 (st_gdata->list[chnl_id]->recv
125 (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb)
127 pr_err(" proto stack %d's ->recv failed", chnl_id);
128 kfree_skb(st_gdata->rx_skb);
132 pr_err(" proto stack %d's ->recv null", chnl_id);
133 kfree_skb(st_gdata->rx_skb);
140 * to call registration complete callbacks
141 * of all protocol stack drivers
142 * This function is being called with spin lock held, protocol drivers are
143 * only expected to complete their waits and do nothing more than that.
145 static void st_reg_complete(struct st_data_s *st_gdata, char err)
148 pr_info(" %s ", __func__);
149 for (i = 0; i < ST_MAX_CHANNELS; i++) {
150 if (likely(st_gdata != NULL &&
151 st_gdata->is_registered[i] == true &&
152 st_gdata->list[i]->reg_complete_cb != NULL)) {
153 st_gdata->list[i]->reg_complete_cb
154 (st_gdata->list[i]->priv_data, err);
155 pr_info("protocol %d's cb sent %d\n", i, err);
156 if (err) { /* cleanup registered protocol */
157 st_gdata->protos_registered--;
158 st_gdata->is_registered[i] = false;
164 static inline int st_check_data_len(struct st_data_s *st_gdata,
165 unsigned char chnl_id, int len)
167 int room = skb_tailroom(st_gdata->rx_skb);
169 pr_debug("len %d room %d", len, room);
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)
176 st_send_frame(chnl_id, st_gdata);
178 } else if (len > room) {
179 /* Received packet's payload length is larger.
180 * We can't accommodate it in created skb.
182 pr_err("Data length is too large len %d room %d", len,
184 kfree_skb(st_gdata->rx_skb);
186 /* Packet header has non-zero payload length and
187 * we have enough space in created skb. Lets read
189 st_gdata->rx_state = ST_W4_DATA;
190 st_gdata->rx_count = len;
194 /* Change ST state to continue to process next
196 st_gdata->rx_state = ST_W4_PACKET_TYPE;
197 st_gdata->rx_skb = NULL;
198 st_gdata->rx_count = 0;
199 st_gdata->rx_chnl = 0;
205 * st_wakeup_ack - internal function for action when wake-up ack
208 static inline void st_wakeup_ack(struct st_data_s *st_gdata,
211 struct sk_buff *waiting_skb;
212 unsigned long flags = 0;
214 spin_lock_irqsave(&st_gdata->lock, flags);
215 /* de-Q from waitQ and Q in txQ now that the
218 while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq)))
219 skb_queue_tail(&st_gdata->txq, waiting_skb);
221 /* state forwarded to ST LL */
222 st_ll_sleep_state(st_gdata, (unsigned long)cmd);
223 spin_unlock_irqrestore(&st_gdata->lock, flags);
225 /* wake up to send the recently copied skbs from waitQ */
226 st_tx_wakeup(st_gdata);
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.
237 void st_int_recv(void *disc_data,
238 const unsigned char *data, long count)
241 struct st_proto_s *proto;
242 unsigned short payload_len = 0;
243 int len = 0, type = 0;
245 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
249 /* tty_receive sent null ? */
250 if (unlikely(ptr == NULL) || (st_gdata == NULL)) {
251 pr_err(" received null from TTY ");
255 pr_debug("count %ld rx_state %ld"
256 "rx_count %ld", count, st_gdata->rx_state,
259 spin_lock_irqsave(&st_gdata->lock, flags);
260 /* Decode received bytes here */
262 if (st_gdata->rx_count) {
263 len = min_t(unsigned int, st_gdata->rx_count, count);
264 memcpy(skb_put(st_gdata->rx_skb, len), ptr, len);
265 st_gdata->rx_count -= len;
269 if (st_gdata->rx_count)
272 /* Check ST RX state machine , where are we? */
273 switch (st_gdata->rx_state) {
274 /* Waiting for complete packet ? */
276 pr_debug("Complete pkt received");
277 /* Ask ST CORE to forward
278 * the packet to protocol driver */
279 st_send_frame(st_gdata->rx_chnl, st_gdata);
281 st_gdata->rx_state = ST_W4_PACKET_TYPE;
282 st_gdata->rx_skb = NULL;
284 /* parse the header to know details */
286 proto = st_gdata->list[st_gdata->rx_chnl];
288 &st_gdata->rx_skb->data
289 [proto->offset_len_in_hdr];
290 pr_debug("plen pointing to %x\n", *plen);
291 if (proto->len_size == 1)/* 1 byte len field */
292 payload_len = *(unsigned char *)plen;
293 else if (proto->len_size == 2)
295 __le16_to_cpu(*(unsigned short *)plen);
297 pr_info("%s: invalid length "
299 __func__, proto->chnl_id);
300 st_check_data_len(st_gdata, proto->chnl_id,
302 pr_debug("off %d, pay len %d\n",
303 proto->offset_len_in_hdr, payload_len);
305 } /* end of switch rx_state */
308 /* end of if rx_count */
309 /* Check first byte of packet and identify module
310 * owner (BT/FM/GPS) */
315 pr_debug("PM packet");
316 /* this takes appropriate action based on
317 * sleep state received --
319 st_ll_sleep_state(st_gdata, *ptr);
320 /* if WAKEUP_IND collides copy from waitq to txq
321 * and assume chip awake
323 spin_unlock_irqrestore(&st_gdata->lock, flags);
324 if (st_ll_getstate(st_gdata) == ST_LL_AWAKE)
325 st_wakeup_ack(st_gdata, LL_WAKE_UP_ACK);
326 spin_lock_irqsave(&st_gdata->lock, flags);
332 pr_debug("PM packet");
334 spin_unlock_irqrestore(&st_gdata->lock, flags);
335 /* wake up ack received */
336 st_wakeup_ack(st_gdata, *ptr);
337 spin_lock_irqsave(&st_gdata->lock, flags);
345 if (st_gdata->list[type] == NULL) {
346 pr_err("chip/interface misbehavior dropping"
347 " frame starting with 0x%02x", type);
351 st_gdata->rx_skb = alloc_skb(
352 st_gdata->list[type]->max_frame_size,
354 if (st_gdata->rx_skb == NULL) {
355 pr_err("out of memory: dropping\n");
359 skb_reserve(st_gdata->rx_skb,
360 st_gdata->list[type]->reserve);
361 /* next 2 required for BT only */
362 st_gdata->rx_skb->cb[0] = type; /*pkt_type*/
363 st_gdata->rx_skb->cb[1] = 0; /*incoming*/
364 st_gdata->rx_chnl = *ptr;
365 st_gdata->rx_state = ST_W4_HEADER;
366 st_gdata->rx_count = st_gdata->list[type]->hdr_len;
367 pr_debug("rx_count %ld\n", st_gdata->rx_count);
373 spin_unlock_irqrestore(&st_gdata->lock, flags);
374 pr_debug("done %s", __func__);
379 * st_int_dequeue - internal de-Q function.
380 * If the previous data set was not written
381 * completely, return that skb which has the pending data.
382 * In normal cases, return top of txq.
384 static struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata)
386 struct sk_buff *returning_skb;
388 pr_debug("%s", __func__);
389 if (st_gdata->tx_skb != NULL) {
390 returning_skb = st_gdata->tx_skb;
391 st_gdata->tx_skb = NULL;
392 return returning_skb;
394 return skb_dequeue(&st_gdata->txq);
398 * st_int_enqueue - internal Q-ing function.
399 * Will either Q the skb to txq or the tx_waitq
400 * depending on the ST LL state.
401 * If the chip is asleep, then Q it onto waitq and
403 * txq and waitq needs protection since the other contexts
404 * may be sending data, waking up chip.
406 static void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb)
408 unsigned long flags = 0;
410 pr_debug("%s", __func__);
411 spin_lock_irqsave(&st_gdata->lock, flags);
413 switch (st_ll_getstate(st_gdata)) {
415 pr_debug("ST LL is AWAKE, sending normally");
416 skb_queue_tail(&st_gdata->txq, skb);
418 case ST_LL_ASLEEP_TO_AWAKE:
419 skb_queue_tail(&st_gdata->tx_waitq, skb);
421 case ST_LL_AWAKE_TO_ASLEEP:
422 pr_err("ST LL is illegal state(%ld),"
423 "purging received skb.", st_ll_getstate(st_gdata));
427 skb_queue_tail(&st_gdata->tx_waitq, skb);
428 st_ll_wakeup(st_gdata);
431 pr_err("ST LL is illegal state(%ld),"
432 "purging received skb.", st_ll_getstate(st_gdata));
437 spin_unlock_irqrestore(&st_gdata->lock, flags);
438 pr_debug("done %s", __func__);
443 * internal wakeup function
445 * - TTY layer when write's finished
446 * - st_write (in context of the protocol stack)
448 void st_tx_wakeup(struct st_data_s *st_data)
451 unsigned long flags; /* for irq save flags */
452 pr_debug("%s", __func__);
453 /* check for sending & set flag sending here */
454 if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) {
455 pr_debug("ST already sending");
457 set_bit(ST_TX_WAKEUP, &st_data->tx_state);
459 /* TX_WAKEUP will be checked in another
463 do { /* come back if st_tx_wakeup is set */
464 /* woke-up to write */
465 clear_bit(ST_TX_WAKEUP, &st_data->tx_state);
466 while ((skb = st_int_dequeue(st_data))) {
468 spin_lock_irqsave(&st_data->lock, flags);
469 /* enable wake-up from TTY */
470 set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags);
471 len = st_int_write(st_data, skb->data, skb->len);
473 /* if skb->len = len as expected, skb->len=0 */
475 /* would be the next skb to be sent */
476 st_data->tx_skb = skb;
477 spin_unlock_irqrestore(&st_data->lock, flags);
481 spin_unlock_irqrestore(&st_data->lock, flags);
483 /* if wake-up is set in another context- restart sending */
484 } while (test_bit(ST_TX_WAKEUP, &st_data->tx_state));
486 /* clear flag sending */
487 clear_bit(ST_TX_SENDING, &st_data->tx_state);
490 /********************************************************************/
491 /* functions called from ST KIM
493 void kim_st_list_protocols(struct st_data_s *st_gdata, void *buf)
495 seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n",
496 st_gdata->protos_registered,
497 st_gdata->is_registered[0x04] == true ? 'R' : 'U',
498 st_gdata->is_registered[0x08] == true ? 'R' : 'U',
499 st_gdata->is_registered[0x09] == true ? 'R' : 'U');
502 /********************************************************************/
504 * functions called from protocol stack drivers
507 long st_register(struct st_proto_s *new_proto)
509 struct st_data_s *st_gdata;
511 unsigned long flags = 0;
513 st_kim_ref(&st_gdata, 0);
514 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
515 || new_proto->reg_complete_cb == NULL) {
516 pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
520 if (new_proto->chnl_id >= ST_MAX_CHANNELS) {
521 pr_err("chnl_id %d not supported", new_proto->chnl_id);
522 return -EPROTONOSUPPORT;
525 if (st_gdata->is_registered[new_proto->chnl_id] == true) {
526 pr_err("chnl_id %d already registered", new_proto->chnl_id);
530 /* can be from process context only */
531 spin_lock_irqsave(&st_gdata->lock, flags);
533 if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
534 pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id);
535 /* fw download in progress */
537 add_channel_to_table(st_gdata, new_proto);
538 st_gdata->protos_registered++;
539 new_proto->write = st_write;
541 set_bit(ST_REG_PENDING, &st_gdata->st_state);
542 spin_unlock_irqrestore(&st_gdata->lock, flags);
544 } else if (st_gdata->protos_registered == ST_EMPTY) {
545 pr_info(" chnl_id list empty :%d ", new_proto->chnl_id);
546 set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
547 st_recv = st_kim_recv;
549 /* enable the ST LL - to set default chip state */
550 st_ll_enable(st_gdata);
552 /* release lock previously held - re-locked below */
553 spin_unlock_irqrestore(&st_gdata->lock, flags);
555 /* this may take a while to complete
556 * since it involves BT fw download
558 err = st_kim_start(st_gdata->kim_data);
560 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
561 if ((st_gdata->protos_registered != ST_EMPTY) &&
562 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
563 pr_err(" KIM failure complete callback ");
564 st_reg_complete(st_gdata, err);
565 clear_bit(ST_REG_PENDING, &st_gdata->st_state);
570 spin_lock_irqsave(&st_gdata->lock, flags);
572 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
573 st_recv = st_int_recv;
575 /* this is where all pending registration
576 * are signalled to be complete by calling callback functions
578 if ((st_gdata->protos_registered != ST_EMPTY) &&
579 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
580 pr_debug(" call reg complete callback ");
581 st_reg_complete(st_gdata, 0);
583 clear_bit(ST_REG_PENDING, &st_gdata->st_state);
585 /* check for already registered once more,
586 * since the above check is old
588 if (st_gdata->is_registered[new_proto->chnl_id] == true) {
589 pr_err(" proto %d already registered ",
591 spin_unlock_irqrestore(&st_gdata->lock, flags);
595 add_channel_to_table(st_gdata, new_proto);
596 st_gdata->protos_registered++;
597 new_proto->write = st_write;
598 spin_unlock_irqrestore(&st_gdata->lock, flags);
601 /* if fw is already downloaded & new stack registers protocol */
603 add_channel_to_table(st_gdata, new_proto);
604 st_gdata->protos_registered++;
605 new_proto->write = st_write;
607 /* lock already held before entering else */
608 spin_unlock_irqrestore(&st_gdata->lock, flags);
611 pr_debug("done %s(%d) ", __func__, new_proto->chnl_id);
613 EXPORT_SYMBOL_GPL(st_register);
615 /* to unregister a protocol -
616 * to be called from protocol stack driver
618 long st_unregister(struct st_proto_s *proto)
621 unsigned long flags = 0;
622 struct st_data_s *st_gdata;
624 pr_debug("%s: %d ", __func__, proto->chnl_id);
626 st_kim_ref(&st_gdata, 0);
627 if (!st_gdata || proto->chnl_id >= ST_MAX_CHANNELS) {
628 pr_err(" chnl_id %d not supported", proto->chnl_id);
629 return -EPROTONOSUPPORT;
632 spin_lock_irqsave(&st_gdata->lock, flags);
634 if (st_gdata->is_registered[proto->chnl_id] == false) {
635 pr_err(" chnl_id %d not registered", proto->chnl_id);
636 spin_unlock_irqrestore(&st_gdata->lock, flags);
637 return -EPROTONOSUPPORT;
640 st_gdata->protos_registered--;
641 remove_channel_from_table(st_gdata, proto);
642 spin_unlock_irqrestore(&st_gdata->lock, flags);
645 if (st_gdata->protos_registered < ST_EMPTY)
646 st_gdata->protos_registered = ST_EMPTY;
648 if ((st_gdata->protos_registered == ST_EMPTY) &&
649 (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
650 pr_info(" all chnl_ids unregistered ");
652 /* stop traffic on tty */
654 tty_ldisc_flush(st_gdata->tty);
655 stop_tty(st_gdata->tty);
658 /* all chnl_ids now unregistered */
659 st_kim_stop(st_gdata->kim_data);
661 st_ll_disable(st_gdata);
667 * called in protocol stack drivers
668 * via the write function pointer
670 long st_write(struct sk_buff *skb)
672 struct st_data_s *st_gdata;
675 st_kim_ref(&st_gdata, 0);
676 if (unlikely(skb == NULL || st_gdata == NULL
677 || st_gdata->tty == NULL)) {
678 pr_err("data/tty unavailable to perform write");
682 pr_debug("%d to be written", skb->len);
685 /* st_ll to decide where to enqueue the skb */
686 st_int_enqueue(st_gdata, skb);
688 st_tx_wakeup(st_gdata);
690 /* return number of bytes written */
694 /* for protocols making use of shared transport */
695 EXPORT_SYMBOL_GPL(st_unregister);
697 /********************************************************************/
699 * functions called from TTY layer
701 static int st_tty_open(struct tty_struct *tty)
704 struct st_data_s *st_gdata;
705 pr_info("%s ", __func__);
707 st_kim_ref(&st_gdata, 0);
709 tty->disc_data = st_gdata;
711 /* don't do an wakeup for now */
712 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
714 /* mem already allocated
716 tty->receive_room = 65536;
717 /* Flush any pending characters in the driver and discipline. */
718 tty_ldisc_flush(tty);
719 tty_driver_flush_buffer(tty);
721 * signal to UIM via KIM that -
722 * installation of N_TI_WL ldisc is complete
724 st_kim_complete(st_gdata->kim_data);
725 pr_debug("done %s", __func__);
729 static void st_tty_close(struct tty_struct *tty)
731 unsigned char i = ST_MAX_CHANNELS;
732 unsigned long flags = 0;
733 struct st_data_s *st_gdata = tty->disc_data;
735 pr_info("%s ", __func__);
738 * if a protocol has been registered & line discipline
739 * un-installed for some reason - what should be done ?
741 spin_lock_irqsave(&st_gdata->lock, flags);
742 for (i = ST_BT; i < ST_MAX_CHANNELS; i++) {
743 if (st_gdata->is_registered[i] == true)
744 pr_err("%d not un-registered", i);
745 st_gdata->list[i] = NULL;
746 st_gdata->is_registered[i] = false;
748 st_gdata->protos_registered = 0;
749 spin_unlock_irqrestore(&st_gdata->lock, flags);
751 * signal to UIM via KIM that -
752 * N_TI_WL ldisc is un-installed
754 st_kim_complete(st_gdata->kim_data);
755 st_gdata->tty = NULL;
756 /* Flush any pending characters in the driver and discipline. */
757 tty_ldisc_flush(tty);
758 tty_driver_flush_buffer(tty);
760 spin_lock_irqsave(&st_gdata->lock, flags);
761 /* empty out txq and tx_waitq */
762 skb_queue_purge(&st_gdata->txq);
763 skb_queue_purge(&st_gdata->tx_waitq);
764 /* reset the TTY Rx states of ST */
765 st_gdata->rx_count = 0;
766 st_gdata->rx_state = ST_W4_PACKET_TYPE;
767 kfree_skb(st_gdata->rx_skb);
768 st_gdata->rx_skb = NULL;
769 spin_unlock_irqrestore(&st_gdata->lock, flags);
771 pr_debug("%s: done ", __func__);
774 static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
775 char *tty_flags, int count)
778 print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
779 16, 1, data, count, 0);
783 * if fw download is in progress then route incoming data
784 * to KIM for validation
786 st_recv(tty->disc_data, data, count);
787 pr_debug("done %s", __func__);
790 /* wake-up function called in from the TTY layer
791 * inside the internal wakeup function will be called
793 static void st_tty_wakeup(struct tty_struct *tty)
795 struct st_data_s *st_gdata = tty->disc_data;
796 pr_debug("%s ", __func__);
797 /* don't do an wakeup for now */
798 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
800 /* call our internal wakeup */
801 st_tx_wakeup((void *)st_gdata);
804 static void st_tty_flush_buffer(struct tty_struct *tty)
806 struct st_data_s *st_gdata = tty->disc_data;
807 pr_debug("%s ", __func__);
809 kfree_skb(st_gdata->tx_skb);
810 st_gdata->tx_skb = NULL;
812 tty->ops->flush_buffer(tty);
816 static struct tty_ldisc_ops st_ldisc_ops = {
817 .magic = TTY_LDISC_MAGIC,
820 .close = st_tty_close,
821 .receive_buf = st_tty_receive,
822 .write_wakeup = st_tty_wakeup,
823 .flush_buffer = st_tty_flush_buffer,
827 /********************************************************************/
828 int st_core_init(struct st_data_s **core_data)
830 struct st_data_s *st_gdata;
833 err = tty_register_ldisc(N_TI_WL, &st_ldisc_ops);
835 pr_err("error registering %d line discipline %ld",
839 pr_debug("registered n_shared line discipline");
841 st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
843 pr_err("memory allocation failed");
844 err = tty_unregister_ldisc(N_TI_WL);
846 pr_err("unable to un-register ldisc %ld", err);
851 /* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's
852 * will be pushed in this queue for actual transmission.
854 skb_queue_head_init(&st_gdata->txq);
855 skb_queue_head_init(&st_gdata->tx_waitq);
857 /* Locking used in st_int_enqueue() to avoid multiple execution */
858 spin_lock_init(&st_gdata->lock);
860 err = st_ll_init(st_gdata);
862 pr_err("error during st_ll initialization(%ld)", err);
864 err = tty_unregister_ldisc(N_TI_WL);
866 pr_err("unable to un-register ldisc");
869 *core_data = st_gdata;
873 void st_core_exit(struct st_data_s *st_gdata)
876 /* internal module cleanup */
877 err = st_ll_deinit(st_gdata);
879 pr_err("error during deinit of ST LL %ld", err);
881 if (st_gdata != NULL) {
882 /* Free ST Tx Qs and skbs */
883 skb_queue_purge(&st_gdata->txq);
884 skb_queue_purge(&st_gdata->tx_waitq);
885 kfree_skb(st_gdata->rx_skb);
886 kfree_skb(st_gdata->tx_skb);
887 /* TTY ldisc cleanup */
888 err = tty_unregister_ldisc(N_TI_WL);
890 pr_err("unable to un-register ldisc %ld", err);
891 /* free the global data pointer */