Lines Matching +full:num +full:- +full:txq
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2009-2010 Texas Instruments
31 pr_info("%s: id %d\n", __func__, new_proto->chnl_id); in add_channel_to_table()
33 st_gdata->list[new_proto->chnl_id] = new_proto; in add_channel_to_table()
34 st_gdata->is_registered[new_proto->chnl_id] = true; in add_channel_to_table()
40 pr_info("%s: id %d\n", __func__, proto->chnl_id); in remove_channel_from_table()
41 /* st_gdata->list[proto->chnl_id] = NULL; */ in remove_channel_from_table()
42 st_gdata->is_registered[proto->chnl_id] = false; in remove_channel_from_table()
48 * This is a wrapper function to tty->ops->write_room.
54 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { in st_get_uart_wr_room()
56 return -1; in st_get_uart_wr_room()
59 return tty_write_room(st_gdata->tty); in st_get_uart_wr_room()
64 * -- KIM (during fw download)
65 * -- ST Core (during st_write)
67 * This is the internal write function - a wrapper
68 * to tty->ops->write
74 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { in st_int_write()
76 return -EINVAL; in st_int_write()
78 tty = st_gdata->tty; in st_int_write()
83 return tty->ops->write(tty, data, count); in st_int_write()
96 (st_gdata == NULL || st_gdata->rx_skb == NULL in st_send_frame()
97 || st_gdata->is_registered[chnl_id] == false)) { in st_send_frame()
100 kfree_skb(st_gdata->rx_skb); in st_send_frame()
106 * - should be just skb_queue_tail for the in st_send_frame()
109 if (likely(st_gdata->list[chnl_id]->recv != NULL)) { in st_send_frame()
111 (st_gdata->list[chnl_id]->recv in st_send_frame()
112 (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb) in st_send_frame()
114 pr_err(" proto stack %d's ->recv failed", chnl_id); in st_send_frame()
115 kfree_skb(st_gdata->rx_skb); in st_send_frame()
119 pr_err(" proto stack %d's ->recv null", chnl_id); in st_send_frame()
120 kfree_skb(st_gdata->rx_skb); in st_send_frame()
126 * st_reg_complete - to call registration complete callbacks
137 st_gdata->is_registered[i] == true && in st_reg_complete()
138 st_gdata->list[i]->reg_complete_cb != NULL)) { in st_reg_complete()
139 st_gdata->list[i]->reg_complete_cb in st_reg_complete()
140 (st_gdata->list[i]->priv_data, err); in st_reg_complete()
143 st_gdata->is_registered[i] = false; in st_reg_complete()
144 if (st_gdata->protos_registered) in st_reg_complete()
145 st_gdata->protos_registered--; in st_reg_complete()
154 int room = skb_tailroom(st_gdata->rx_skb); in st_check_data_len()
173 kfree_skb(st_gdata->rx_skb); in st_check_data_len()
176 * Packet header has non-zero payload length and in st_check_data_len()
179 st_gdata->rx_state = ST_W4_DATA; in st_check_data_len()
180 st_gdata->rx_count = len; in st_check_data_len()
185 st_gdata->rx_state = ST_W4_PACKET_TYPE; in st_check_data_len()
186 st_gdata->rx_skb = NULL; in st_check_data_len()
187 st_gdata->rx_count = 0; in st_check_data_len()
188 st_gdata->rx_chnl = 0; in st_check_data_len()
194 * st_wakeup_ack - internal function for action when wake-up ack
203 spin_lock_irqsave(&st_gdata->lock, flags); in st_wakeup_ack()
205 * de-Q from waitQ and Q in txQ now that the in st_wakeup_ack()
208 while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq))) in st_wakeup_ack()
209 skb_queue_tail(&st_gdata->txq, waiting_skb); in st_wakeup_ack()
213 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_wakeup_ack()
220 * st_int_recv - ST's internal receive function.
224 * HCI-Events, ACL, SCO, 4 types of HCI-LL PM packets
225 * CH-8 packets from FM, CH-9 packets from GPS cores.
243 "rx_count %ld", count, st_gdata->rx_state, in st_int_recv()
244 st_gdata->rx_count); in st_int_recv()
246 spin_lock_irqsave(&st_gdata->lock, flags); in st_int_recv()
249 if (st_gdata->rx_count) { in st_int_recv()
250 len = min_t(unsigned int, st_gdata->rx_count, count); in st_int_recv()
251 skb_put_data(st_gdata->rx_skb, ptr, len); in st_int_recv()
252 st_gdata->rx_count -= len; in st_int_recv()
253 count -= len; in st_int_recv()
256 if (st_gdata->rx_count) in st_int_recv()
260 switch (st_gdata->rx_state) { in st_int_recv()
268 st_send_frame(st_gdata->rx_chnl, st_gdata); in st_int_recv()
270 st_gdata->rx_state = ST_W4_PACKET_TYPE; in st_int_recv()
271 st_gdata->rx_skb = NULL; in st_int_recv()
275 proto = st_gdata->list[st_gdata->rx_chnl]; in st_int_recv()
277 &st_gdata->rx_skb->data in st_int_recv()
278 [proto->offset_len_in_hdr]; in st_int_recv()
280 if (proto->len_size == 1) /* 1 byte len field */ in st_int_recv()
282 else if (proto->len_size == 2) in st_int_recv()
288 __func__, proto->chnl_id); in st_int_recv()
289 st_check_data_len(st_gdata, proto->chnl_id, in st_int_recv()
292 proto->offset_len_in_hdr, payload_len); in st_int_recv()
310 * sleep state received -- in st_int_recv()
314 * if WAKEUP_IND collides copy from waitq to txq in st_int_recv()
317 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_int_recv()
320 spin_lock_irqsave(&st_gdata->lock, flags); in st_int_recv()
323 count--; in st_int_recv()
328 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_int_recv()
331 spin_lock_irqsave(&st_gdata->lock, flags); in st_int_recv()
334 count--; in st_int_recv()
341 * Default case means non-HCILL packets, in st_int_recv()
343 * (a) valid protocol - Supported Protocols within in st_int_recv()
345 * (b) registered protocol - Checked by in st_int_recv()
346 * "st_gdata->list[type] == NULL)" are supported in st_int_recv()
353 (st_gdata->list[type] == NULL)) { in st_int_recv()
360 st_gdata->rx_skb = alloc_skb( in st_int_recv()
361 st_gdata->list[type]->max_frame_size, in st_int_recv()
363 if (st_gdata->rx_skb == NULL) { in st_int_recv()
368 skb_reserve(st_gdata->rx_skb, in st_int_recv()
369 st_gdata->list[type]->reserve); in st_int_recv()
371 st_gdata->rx_skb->cb[0] = type; /*pkt_type*/ in st_int_recv()
372 st_gdata->rx_skb->cb[1] = 0; /*incoming*/ in st_int_recv()
373 st_gdata->rx_chnl = *ptr; in st_int_recv()
374 st_gdata->rx_state = ST_W4_HEADER; in st_int_recv()
375 st_gdata->rx_count = st_gdata->list[type]->hdr_len; in st_int_recv()
376 pr_debug("rx_count %ld\n", st_gdata->rx_count); in st_int_recv()
379 count--; in st_int_recv()
382 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_int_recv()
388 * st_int_dequeue - internal de-Q function.
391 * In normal cases, return top of txq.
398 if (st_gdata->tx_skb != NULL) { in st_int_dequeue()
399 returning_skb = st_gdata->tx_skb; in st_int_dequeue()
400 st_gdata->tx_skb = NULL; in st_int_dequeue()
403 return skb_dequeue(&st_gdata->txq); in st_int_dequeue()
407 * st_int_enqueue - internal Q-ing function.
408 * Will either Q the skb to txq or the tx_waitq
412 * txq and waitq needs protection since the other contexts
420 spin_lock_irqsave(&st_gdata->lock, flags); in st_int_enqueue()
425 skb_queue_tail(&st_gdata->txq, skb); in st_int_enqueue()
428 skb_queue_tail(&st_gdata->tx_waitq, skb); in st_int_enqueue()
436 skb_queue_tail(&st_gdata->tx_waitq, skb); in st_int_enqueue()
446 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_int_enqueue()
454 * - TTY layer when write's finished
455 * - st_write (in context of the protocol stack)
470 if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) { in st_tx_wakeup()
473 set_bit(ST_TX_WAKEUP, &st_data->tx_state); in st_tx_wakeup()
480 /* woke-up to write */ in st_tx_wakeup()
481 clear_bit(ST_TX_WAKEUP, &st_data->tx_state); in st_tx_wakeup()
484 spin_lock_irqsave(&st_data->lock, flags); in st_tx_wakeup()
485 /* enable wake-up from TTY */ in st_tx_wakeup()
486 set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags); in st_tx_wakeup()
487 len = st_int_write(st_data, skb->data, skb->len); in st_tx_wakeup()
489 /* if skb->len = len as expected, skb->len=0 */ in st_tx_wakeup()
490 if (skb->len) { in st_tx_wakeup()
492 st_data->tx_skb = skb; in st_tx_wakeup()
493 spin_unlock_irqrestore(&st_data->lock, flags); in st_tx_wakeup()
497 spin_unlock_irqrestore(&st_data->lock, flags); in st_tx_wakeup()
499 /* if wake-up is set in another context- restart sending */ in st_tx_wakeup()
500 } while (test_bit(ST_TX_WAKEUP, &st_data->tx_state)); in st_tx_wakeup()
503 clear_bit(ST_TX_SENDING, &st_data->tx_state); in st_tx_wakeup()
512 st_gdata->protos_registered, in kim_st_list_protocols()
513 st_gdata->is_registered[0x04] == true ? 'R' : 'U', in kim_st_list_protocols()
514 st_gdata->is_registered[0x08] == true ? 'R' : 'U', in kim_st_list_protocols()
515 st_gdata->is_registered[0x09] == true ? 'R' : 'U'); in kim_st_list_protocols()
521 * to be EXPORT-ed
530 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL in st_register()
531 || new_proto->reg_complete_cb == NULL) { in st_register()
533 return -EINVAL; in st_register()
536 if (new_proto->chnl_id >= ST_MAX_CHANNELS) { in st_register()
537 pr_err("chnl_id %d not supported", new_proto->chnl_id); in st_register()
538 return -EPROTONOSUPPORT; in st_register()
541 if (st_gdata->is_registered[new_proto->chnl_id] == true) { in st_register()
542 pr_err("chnl_id %d already registered", new_proto->chnl_id); in st_register()
543 return -EALREADY; in st_register()
547 spin_lock_irqsave(&st_gdata->lock, flags); in st_register()
549 if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) { in st_register()
550 pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id); in st_register()
554 st_gdata->protos_registered++; in st_register()
555 new_proto->write = st_write; in st_register()
557 set_bit(ST_REG_PENDING, &st_gdata->st_state); in st_register()
558 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_register()
559 return -EINPROGRESS; in st_register()
560 } else if (st_gdata->protos_registered == ST_EMPTY) { in st_register()
561 pr_info(" chnl_id list empty :%d ", new_proto->chnl_id); in st_register()
562 set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); in st_register()
565 /* enable the ST LL - to set default chip state */ in st_register()
568 /* release lock previously held - re-locked below */ in st_register()
569 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_register()
575 err = st_kim_start(st_gdata->kim_data); in st_register()
577 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); in st_register()
578 if ((st_gdata->protos_registered != ST_EMPTY) && in st_register()
579 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) { in st_register()
581 spin_lock_irqsave(&st_gdata->lock, flags); in st_register()
583 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_register()
584 clear_bit(ST_REG_PENDING, &st_gdata->st_state); in st_register()
586 return -EINVAL; in st_register()
589 spin_lock_irqsave(&st_gdata->lock, flags); in st_register()
591 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); in st_register()
598 if ((st_gdata->protos_registered != ST_EMPTY) && in st_register()
599 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) { in st_register()
603 clear_bit(ST_REG_PENDING, &st_gdata->st_state); in st_register()
609 if (st_gdata->is_registered[new_proto->chnl_id] == true) { in st_register()
611 new_proto->chnl_id); in st_register()
612 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_register()
613 return -EALREADY; in st_register()
617 st_gdata->protos_registered++; in st_register()
618 new_proto->write = st_write; in st_register()
619 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_register()
625 st_gdata->protos_registered++; in st_register()
626 new_proto->write = st_write; in st_register()
629 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_register()
636 * to unregister a protocol -
645 pr_debug("%s: %d ", __func__, proto->chnl_id); in st_unregister()
648 if (!st_gdata || proto->chnl_id >= ST_MAX_CHANNELS) { in st_unregister()
649 pr_err(" chnl_id %d not supported", proto->chnl_id); in st_unregister()
650 return -EPROTONOSUPPORT; in st_unregister()
653 spin_lock_irqsave(&st_gdata->lock, flags); in st_unregister()
655 if (st_gdata->is_registered[proto->chnl_id] == false) { in st_unregister()
656 pr_err(" chnl_id %d not registered", proto->chnl_id); in st_unregister()
657 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_unregister()
658 return -EPROTONOSUPPORT; in st_unregister()
661 if (st_gdata->protos_registered) in st_unregister()
662 st_gdata->protos_registered--; in st_unregister()
665 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_unregister()
667 if ((st_gdata->protos_registered == ST_EMPTY) && in st_unregister()
668 (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) { in st_unregister()
672 if (st_gdata->tty) { in st_unregister()
673 tty_ldisc_flush(st_gdata->tty); in st_unregister()
674 stop_tty(st_gdata->tty); in st_unregister()
678 st_kim_stop(st_gdata->kim_data); in st_unregister()
696 || st_gdata->tty == NULL)) { in st_write()
698 return -EINVAL; in st_write()
701 pr_debug("%d to be written", skb->len); in st_write()
702 len = skb->len; in st_write()
726 st_gdata->tty = tty; in st_tty_open()
727 tty->disc_data = st_gdata; in st_tty_open()
730 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in st_tty_open()
734 tty->receive_room = 65536; in st_tty_open()
739 * signal to UIM via KIM that - in st_tty_open()
742 st_kim_complete(st_gdata->kim_data); in st_tty_open()
752 struct st_data_s *st_gdata = tty->disc_data; in st_tty_close()
759 * un-installed for some reason - what should be done ? in st_tty_close()
761 spin_lock_irqsave(&st_gdata->lock, flags); in st_tty_close()
763 if (st_gdata->is_registered[i] == true) in st_tty_close()
764 pr_err("%d not un-registered", i); in st_tty_close()
765 st_gdata->list[i] = NULL; in st_tty_close()
766 st_gdata->is_registered[i] = false; in st_tty_close()
768 st_gdata->protos_registered = 0; in st_tty_close()
769 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_tty_close()
771 * signal to UIM via KIM that - in st_tty_close()
772 * N_TI_WL ldisc is un-installed in st_tty_close()
774 st_kim_complete(st_gdata->kim_data); in st_tty_close()
775 st_gdata->tty = NULL; in st_tty_close()
780 spin_lock_irqsave(&st_gdata->lock, flags); in st_tty_close()
781 /* empty out txq and tx_waitq */ in st_tty_close()
782 skb_queue_purge(&st_gdata->txq); in st_tty_close()
783 skb_queue_purge(&st_gdata->tx_waitq); in st_tty_close()
785 st_gdata->rx_count = 0; in st_tty_close()
786 st_gdata->rx_state = ST_W4_PACKET_TYPE; in st_tty_close()
787 kfree_skb(st_gdata->rx_skb); in st_tty_close()
788 st_gdata->rx_skb = NULL; in st_tty_close()
789 spin_unlock_irqrestore(&st_gdata->lock, flags); in st_tty_close()
806 st_recv(tty->disc_data, data, count); in st_tty_receive()
811 * wake-up function called in from the TTY layer
816 struct st_data_s *st_gdata = tty->disc_data; in st_tty_wakeup()
819 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in st_tty_wakeup()
823 * avoid lockup (port->lock needed in tty->ops->write is in st_tty_wakeup()
826 schedule_work(&st_gdata->work_write_wakeup); in st_tty_wakeup()
831 struct st_data_s *st_gdata = tty->disc_data; in st_tty_flush_buffer()
834 kfree_skb(st_gdata->tx_skb); in st_tty_flush_buffer()
835 st_gdata->tx_skb = NULL; in st_tty_flush_buffer()
842 .num = N_TI_WL,
869 err = -ENOMEM; in st_core_init()
873 /* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's in st_core_init()
876 skb_queue_head_init(&st_gdata->txq); in st_core_init()
877 skb_queue_head_init(&st_gdata->tx_waitq); in st_core_init()
880 spin_lock_init(&st_gdata->lock); in st_core_init()
888 INIT_WORK(&st_gdata->work_write_wakeup, work_fn_write_wakeup); in st_core_init()
909 skb_queue_purge(&st_gdata->txq); in st_core_exit()
910 skb_queue_purge(&st_gdata->tx_waitq); in st_core_exit()
911 kfree_skb(st_gdata->rx_skb); in st_core_exit()
912 kfree_skb(st_gdata->tx_skb); in st_core_exit()