Lines Matching refs:hu

78 static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)  in hci_uart_tx_complete()  argument
80 struct hci_dev *hdev = hu->hdev; in hci_uart_tx_complete()
98 static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu) in hci_uart_dequeue() argument
100 struct sk_buff *skb = hu->tx_skb; in hci_uart_dequeue()
103 percpu_down_read(&hu->proto_lock); in hci_uart_dequeue()
105 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) in hci_uart_dequeue()
106 skb = hu->proto->dequeue(hu); in hci_uart_dequeue()
108 percpu_up_read(&hu->proto_lock); in hci_uart_dequeue()
110 hu->tx_skb = NULL; in hci_uart_dequeue()
116 int hci_uart_tx_wakeup(struct hci_uart *hu) in hci_uart_tx_wakeup() argument
124 if (!percpu_down_read_trylock(&hu->proto_lock)) in hci_uart_tx_wakeup()
127 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) in hci_uart_tx_wakeup()
130 if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) { in hci_uart_tx_wakeup()
131 set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); in hci_uart_tx_wakeup()
137 schedule_work(&hu->write_work); in hci_uart_tx_wakeup()
140 percpu_up_read(&hu->proto_lock); in hci_uart_tx_wakeup()
148 struct hci_uart *hu = container_of(work, struct hci_uart, write_work); in hci_uart_write_work() local
149 struct tty_struct *tty = hu->tty; in hci_uart_write_work()
150 struct hci_dev *hdev = hu->hdev; in hci_uart_write_work()
158 clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); in hci_uart_write_work()
160 while ((skb = hci_uart_dequeue(hu))) { in hci_uart_write_work()
169 hu->tx_skb = skb; in hci_uart_write_work()
173 hci_uart_tx_complete(hu, hci_skb_pkt_type(skb)); in hci_uart_write_work()
177 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) in hci_uart_write_work()
180 clear_bit(HCI_UART_SENDING, &hu->tx_state); in hci_uart_write_work()
181 wake_up_bit(&hu->tx_state, HCI_UART_SENDING); in hci_uart_write_work()
186 struct hci_uart *hu = container_of(work, struct hci_uart, init_ready); in hci_uart_init_work() local
190 if (!test_and_clear_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_init_work()
193 err = hci_register_dev(hu->hdev); in hci_uart_init_work()
196 clear_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_init_work()
197 hu->proto->close(hu); in hci_uart_init_work()
198 hdev = hu->hdev; in hci_uart_init_work()
199 hu->hdev = NULL; in hci_uart_init_work()
204 set_bit(HCI_UART_REGISTERED, &hu->flags); in hci_uart_init_work()
207 int hci_uart_init_ready(struct hci_uart *hu) in hci_uart_init_ready() argument
209 if (!test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_init_ready()
212 schedule_work(&hu->init_ready); in hci_uart_init_ready()
217 int hci_uart_wait_until_sent(struct hci_uart *hu) in hci_uart_wait_until_sent() argument
219 return wait_on_bit_timeout(&hu->tx_state, HCI_UART_SENDING, in hci_uart_wait_until_sent()
228 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_flush() local
229 struct tty_struct *tty = hu->tty; in hci_uart_flush()
233 if (hu->tx_skb) { in hci_uart_flush()
234 kfree_skb(hu->tx_skb); hu->tx_skb = NULL; in hci_uart_flush()
241 percpu_down_read(&hu->proto_lock); in hci_uart_flush()
243 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) in hci_uart_flush()
244 hu->proto->flush(hu); in hci_uart_flush()
246 percpu_up_read(&hu->proto_lock); in hci_uart_flush()
275 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_send_frame() local
280 percpu_down_read(&hu->proto_lock); in hci_uart_send_frame()
282 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_send_frame()
283 percpu_up_read(&hu->proto_lock); in hci_uart_send_frame()
287 hu->proto->enqueue(hu, skb); in hci_uart_send_frame()
288 percpu_up_read(&hu->proto_lock); in hci_uart_send_frame()
290 hci_uart_tx_wakeup(hu); in hci_uart_send_frame()
296 bool hci_uart_has_flow_control(struct hci_uart *hu) in hci_uart_has_flow_control() argument
299 if (hu->serdev) in hci_uart_has_flow_control()
302 if (hu->tty->driver->ops->tiocmget && hu->tty->driver->ops->tiocmset) in hci_uart_has_flow_control()
309 void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) in hci_uart_set_flow_control() argument
311 struct tty_struct *tty = hu->tty; in hci_uart_set_flow_control()
317 if (hu->serdev) { in hci_uart_set_flow_control()
318 serdev_device_set_flow_control(hu->serdev, !enable); in hci_uart_set_flow_control()
319 serdev_device_set_rts(hu->serdev, !enable); in hci_uart_set_flow_control()
367 void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, in hci_uart_set_speeds() argument
370 hu->init_speed = init_speed; in hci_uart_set_speeds()
371 hu->oper_speed = oper_speed; in hci_uart_set_speeds()
374 void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed) in hci_uart_set_baudrate() argument
376 struct tty_struct *tty = hu->tty; in hci_uart_set_baudrate()
386 BT_DBG("%s: New tty speeds: %d/%d", hu->hdev->name, in hci_uart_set_baudrate()
392 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_setup() local
399 if (hu->init_speed) in hci_uart_setup()
400 speed = hu->init_speed; in hci_uart_setup()
401 else if (hu->proto->init_speed) in hci_uart_setup()
402 speed = hu->proto->init_speed; in hci_uart_setup()
407 hci_uart_set_baudrate(hu, speed); in hci_uart_setup()
410 if (hu->oper_speed) in hci_uart_setup()
411 speed = hu->oper_speed; in hci_uart_setup()
412 else if (hu->proto->oper_speed) in hci_uart_setup()
413 speed = hu->proto->oper_speed; in hci_uart_setup()
417 if (hu->proto->set_baudrate && speed) { in hci_uart_setup()
418 err = hu->proto->set_baudrate(hu, speed); in hci_uart_setup()
420 hci_uart_set_baudrate(hu, speed); in hci_uart_setup()
423 if (hu->proto->setup) in hci_uart_setup()
424 return hu->proto->setup(hu); in hci_uart_setup()
426 if (!test_bit(HCI_UART_VND_DETECT, &hu->hdev_flags)) in hci_uart_setup()
479 struct hci_uart *hu; in hci_uart_tty_open() local
489 hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL); in hci_uart_tty_open()
490 if (!hu) { in hci_uart_tty_open()
495 tty->disc_data = hu; in hci_uart_tty_open()
496 hu->tty = tty; in hci_uart_tty_open()
500 hu->alignment = 1; in hci_uart_tty_open()
501 hu->padding = 0; in hci_uart_tty_open()
503 INIT_WORK(&hu->init_ready, hci_uart_init_work); in hci_uart_tty_open()
504 INIT_WORK(&hu->write_work, hci_uart_write_work); in hci_uart_tty_open()
506 percpu_init_rwsem(&hu->proto_lock); in hci_uart_tty_open()
521 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_close() local
529 if (!hu) in hci_uart_tty_close()
532 hdev = hu->hdev; in hci_uart_tty_close()
536 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_tty_close()
537 percpu_down_write(&hu->proto_lock); in hci_uart_tty_close()
538 clear_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_tty_close()
539 percpu_up_write(&hu->proto_lock); in hci_uart_tty_close()
541 cancel_work_sync(&hu->init_ready); in hci_uart_tty_close()
542 cancel_work_sync(&hu->write_work); in hci_uart_tty_close()
545 if (test_bit(HCI_UART_REGISTERED, &hu->flags)) in hci_uart_tty_close()
549 hu->proto->close(hu); in hci_uart_tty_close()
551 clear_bit(HCI_UART_PROTO_SET, &hu->flags); in hci_uart_tty_close()
553 percpu_free_rwsem(&hu->proto_lock); in hci_uart_tty_close()
555 kfree(hu); in hci_uart_tty_close()
568 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_wakeup() local
572 if (!hu) in hci_uart_tty_wakeup()
577 if (tty != hu->tty) in hci_uart_tty_wakeup()
580 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) in hci_uart_tty_wakeup()
581 hci_uart_tx_wakeup(hu); in hci_uart_tty_wakeup()
599 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_receive() local
601 if (!hu || tty != hu->tty) in hci_uart_tty_receive()
604 percpu_down_read(&hu->proto_lock); in hci_uart_tty_receive()
606 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_tty_receive()
607 percpu_up_read(&hu->proto_lock); in hci_uart_tty_receive()
614 hu->proto->recv(hu, data, count); in hci_uart_tty_receive()
615 percpu_up_read(&hu->proto_lock); in hci_uart_tty_receive()
617 if (hu->hdev) in hci_uart_tty_receive()
618 hu->hdev->stat.byte_rx += count; in hci_uart_tty_receive()
623 static int hci_uart_register_dev(struct hci_uart *hu) in hci_uart_register_dev() argument
637 hu->hdev = hdev; in hci_uart_register_dev()
640 hci_set_drvdata(hdev, hu); in hci_uart_register_dev()
646 if (hu->proto->setup) in hci_uart_register_dev()
647 hdev->manufacturer = hu->proto->manufacturer; in hci_uart_register_dev()
654 SET_HCIDEV_DEV(hdev, hu->tty->dev); in hci_uart_register_dev()
656 if (test_bit(HCI_UART_RAW_DEVICE, &hu->hdev_flags)) in hci_uart_register_dev()
659 if (test_bit(HCI_UART_EXT_CONFIG, &hu->hdev_flags)) in hci_uart_register_dev()
662 if (!test_bit(HCI_UART_RESET_ON_INIT, &hu->hdev_flags)) in hci_uart_register_dev()
665 if (test_bit(HCI_UART_CREATE_AMP, &hu->hdev_flags)) in hci_uart_register_dev()
673 err = hu->proto->open(hu); in hci_uart_register_dev()
675 hu->hdev = NULL; in hci_uart_register_dev()
680 if (test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_register_dev()
685 hu->proto->close(hu); in hci_uart_register_dev()
686 hu->hdev = NULL; in hci_uart_register_dev()
691 set_bit(HCI_UART_REGISTERED, &hu->flags); in hci_uart_register_dev()
696 static int hci_uart_set_proto(struct hci_uart *hu, int id) in hci_uart_set_proto() argument
705 hu->proto = p; in hci_uart_set_proto()
707 err = hci_uart_register_dev(hu); in hci_uart_set_proto()
712 set_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_set_proto()
716 static int hci_uart_set_flags(struct hci_uart *hu, unsigned long flags) in hci_uart_set_flags() argument
728 hu->hdev_flags = flags; in hci_uart_set_flags()
749 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_ioctl() local
755 if (!hu) in hci_uart_tty_ioctl()
760 if (!test_and_set_bit(HCI_UART_PROTO_SET, &hu->flags)) { in hci_uart_tty_ioctl()
761 err = hci_uart_set_proto(hu, arg); in hci_uart_tty_ioctl()
763 clear_bit(HCI_UART_PROTO_SET, &hu->flags); in hci_uart_tty_ioctl()
769 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) in hci_uart_tty_ioctl()
770 err = hu->proto->id; in hci_uart_tty_ioctl()
776 if (test_bit(HCI_UART_REGISTERED, &hu->flags)) in hci_uart_tty_ioctl()
777 err = hu->hdev->id; in hci_uart_tty_ioctl()
783 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) in hci_uart_tty_ioctl()
786 err = hci_uart_set_flags(hu, arg); in hci_uart_tty_ioctl()
790 err = hu->hdev_flags; in hci_uart_tty_ioctl()