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 set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); in hci_uart_tx_wakeup()
131 if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) in hci_uart_tx_wakeup()
136 schedule_work(&hu->write_work); in hci_uart_tx_wakeup()
139 percpu_up_read(&hu->proto_lock); in hci_uart_tx_wakeup()
147 struct hci_uart *hu = container_of(work, struct hci_uart, write_work); in hci_uart_write_work() local
148 struct tty_struct *tty = hu->tty; in hci_uart_write_work()
149 struct hci_dev *hdev = hu->hdev; in hci_uart_write_work()
152 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_write_work()
153 clear_bit(HCI_UART_SENDING, &hu->tx_state); in hci_uart_write_work()
162 clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); in hci_uart_write_work()
164 while ((skb = hci_uart_dequeue(hu))) { in hci_uart_write_work()
173 hu->tx_skb = skb; in hci_uart_write_work()
177 hci_uart_tx_complete(hu, hci_skb_pkt_type(skb)); in hci_uart_write_work()
181 clear_bit(HCI_UART_SENDING, &hu->tx_state); in hci_uart_write_work()
182 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) in hci_uart_write_work()
185 wake_up_bit(&hu->tx_state, HCI_UART_SENDING); in hci_uart_write_work()
190 struct hci_uart *hu = container_of(work, struct hci_uart, init_ready); in hci_uart_init_work() local
194 if (!test_and_clear_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_init_work()
197 err = hci_register_dev(hu->hdev); in hci_uart_init_work()
200 clear_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_init_work()
201 hu->proto->close(hu); in hci_uart_init_work()
202 hdev = hu->hdev; in hci_uart_init_work()
203 hu->hdev = NULL; in hci_uart_init_work()
208 set_bit(HCI_UART_REGISTERED, &hu->flags); in hci_uart_init_work()
211 int hci_uart_init_ready(struct hci_uart *hu) in hci_uart_init_ready() argument
213 if (!test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_init_ready()
216 schedule_work(&hu->init_ready); in hci_uart_init_ready()
221 int hci_uart_wait_until_sent(struct hci_uart *hu) in hci_uart_wait_until_sent() argument
223 return wait_on_bit_timeout(&hu->tx_state, HCI_UART_SENDING, in hci_uart_wait_until_sent()
232 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_flush() local
233 struct tty_struct *tty = hu->tty; in hci_uart_flush()
237 if (hu->tx_skb) { in hci_uart_flush()
238 kfree_skb(hu->tx_skb); hu->tx_skb = NULL; in hci_uart_flush()
245 percpu_down_read(&hu->proto_lock); in hci_uart_flush()
247 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) in hci_uart_flush()
248 hu->proto->flush(hu); in hci_uart_flush()
250 percpu_up_read(&hu->proto_lock); in hci_uart_flush()
279 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_send_frame() local
284 percpu_down_read(&hu->proto_lock); in hci_uart_send_frame()
286 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_send_frame()
287 percpu_up_read(&hu->proto_lock); in hci_uart_send_frame()
291 hu->proto->enqueue(hu, skb); in hci_uart_send_frame()
292 percpu_up_read(&hu->proto_lock); in hci_uart_send_frame()
294 hci_uart_tx_wakeup(hu); in hci_uart_send_frame()
300 bool hci_uart_has_flow_control(struct hci_uart *hu) in hci_uart_has_flow_control() argument
303 if (hu->serdev) in hci_uart_has_flow_control()
306 if (hu->tty->driver->ops->tiocmget && hu->tty->driver->ops->tiocmset) in hci_uart_has_flow_control()
313 void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) in hci_uart_set_flow_control() argument
315 struct tty_struct *tty = hu->tty; in hci_uart_set_flow_control()
321 if (hu->serdev) { in hci_uart_set_flow_control()
322 serdev_device_set_flow_control(hu->serdev, !enable); in hci_uart_set_flow_control()
323 serdev_device_set_rts(hu->serdev, !enable); in hci_uart_set_flow_control()
371 void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, in hci_uart_set_speeds() argument
374 hu->init_speed = init_speed; in hci_uart_set_speeds()
375 hu->oper_speed = oper_speed; in hci_uart_set_speeds()
378 void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed) in hci_uart_set_baudrate() argument
380 struct tty_struct *tty = hu->tty; in hci_uart_set_baudrate()
390 BT_DBG("%s: New tty speeds: %d/%d", hu->hdev->name, in hci_uart_set_baudrate()
396 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_setup() local
403 if (hu->init_speed) in hci_uart_setup()
404 speed = hu->init_speed; in hci_uart_setup()
405 else if (hu->proto->init_speed) in hci_uart_setup()
406 speed = hu->proto->init_speed; in hci_uart_setup()
411 hci_uart_set_baudrate(hu, speed); in hci_uart_setup()
414 if (hu->oper_speed) in hci_uart_setup()
415 speed = hu->oper_speed; in hci_uart_setup()
416 else if (hu->proto->oper_speed) in hci_uart_setup()
417 speed = hu->proto->oper_speed; in hci_uart_setup()
421 if (hu->proto->set_baudrate && speed) { in hci_uart_setup()
422 err = hu->proto->set_baudrate(hu, speed); in hci_uart_setup()
424 hci_uart_set_baudrate(hu, speed); in hci_uart_setup()
427 if (hu->proto->setup) in hci_uart_setup()
428 return hu->proto->setup(hu); in hci_uart_setup()
430 if (!test_bit(HCI_UART_VND_DETECT, &hu->hdev_flags)) in hci_uart_setup()
483 struct hci_uart *hu; in hci_uart_tty_open() local
493 hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL); in hci_uart_tty_open()
494 if (!hu) { in hci_uart_tty_open()
498 if (percpu_init_rwsem(&hu->proto_lock)) { in hci_uart_tty_open()
500 kfree(hu); in hci_uart_tty_open()
504 tty->disc_data = hu; in hci_uart_tty_open()
505 hu->tty = tty; in hci_uart_tty_open()
509 hu->alignment = 1; in hci_uart_tty_open()
510 hu->padding = 0; in hci_uart_tty_open()
512 INIT_WORK(&hu->init_ready, hci_uart_init_work); in hci_uart_tty_open()
513 INIT_WORK(&hu->write_work, hci_uart_write_work); in hci_uart_tty_open()
528 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_close() local
536 if (!hu) in hci_uart_tty_close()
539 hdev = hu->hdev; in hci_uart_tty_close()
543 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_tty_close()
544 percpu_down_write(&hu->proto_lock); in hci_uart_tty_close()
545 clear_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_tty_close()
546 percpu_up_write(&hu->proto_lock); in hci_uart_tty_close()
548 cancel_work_sync(&hu->init_ready); in hci_uart_tty_close()
549 cancel_work_sync(&hu->write_work); in hci_uart_tty_close()
552 if (test_bit(HCI_UART_REGISTERED, &hu->flags)) in hci_uart_tty_close()
556 hu->proto->close(hu); in hci_uart_tty_close()
558 clear_bit(HCI_UART_PROTO_SET, &hu->flags); in hci_uart_tty_close()
560 percpu_free_rwsem(&hu->proto_lock); in hci_uart_tty_close()
562 kfree(hu); in hci_uart_tty_close()
575 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_wakeup() local
579 if (!hu) in hci_uart_tty_wakeup()
584 if (tty != hu->tty) in hci_uart_tty_wakeup()
587 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) in hci_uart_tty_wakeup()
588 hci_uart_tx_wakeup(hu); in hci_uart_tty_wakeup()
606 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_receive() local
608 if (!hu || tty != hu->tty) in hci_uart_tty_receive()
611 percpu_down_read(&hu->proto_lock); in hci_uart_tty_receive()
613 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_tty_receive()
614 percpu_up_read(&hu->proto_lock); in hci_uart_tty_receive()
621 hu->proto->recv(hu, data, count); in hci_uart_tty_receive()
622 percpu_up_read(&hu->proto_lock); in hci_uart_tty_receive()
624 if (hu->hdev) in hci_uart_tty_receive()
625 hu->hdev->stat.byte_rx += count; in hci_uart_tty_receive()
630 static int hci_uart_register_dev(struct hci_uart *hu) in hci_uart_register_dev() argument
644 hu->hdev = hdev; in hci_uart_register_dev()
647 hci_set_drvdata(hdev, hu); in hci_uart_register_dev()
653 if (hu->proto->setup) in hci_uart_register_dev()
654 hdev->manufacturer = hu->proto->manufacturer; in hci_uart_register_dev()
661 SET_HCIDEV_DEV(hdev, hu->tty->dev); in hci_uart_register_dev()
663 if (test_bit(HCI_UART_RAW_DEVICE, &hu->hdev_flags)) in hci_uart_register_dev()
666 if (test_bit(HCI_UART_EXT_CONFIG, &hu->hdev_flags)) in hci_uart_register_dev()
669 if (!test_bit(HCI_UART_RESET_ON_INIT, &hu->hdev_flags)) in hci_uart_register_dev()
672 if (test_bit(HCI_UART_CREATE_AMP, &hu->hdev_flags)) in hci_uart_register_dev()
680 err = hu->proto->open(hu); in hci_uart_register_dev()
682 hu->hdev = NULL; in hci_uart_register_dev()
687 if (test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_register_dev()
692 hu->proto->close(hu); in hci_uart_register_dev()
693 hu->hdev = NULL; in hci_uart_register_dev()
698 set_bit(HCI_UART_REGISTERED, &hu->flags); in hci_uart_register_dev()
703 static int hci_uart_set_proto(struct hci_uart *hu, int id) in hci_uart_set_proto() argument
712 hu->proto = p; in hci_uart_set_proto()
714 err = hci_uart_register_dev(hu); in hci_uart_set_proto()
719 set_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_set_proto()
723 static int hci_uart_set_flags(struct hci_uart *hu, unsigned long flags) in hci_uart_set_flags() argument
735 hu->hdev_flags = flags; in hci_uart_set_flags()
756 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_ioctl() local
762 if (!hu) in hci_uart_tty_ioctl()
767 if (!test_and_set_bit(HCI_UART_PROTO_SET, &hu->flags)) { in hci_uart_tty_ioctl()
768 err = hci_uart_set_proto(hu, arg); in hci_uart_tty_ioctl()
770 clear_bit(HCI_UART_PROTO_SET, &hu->flags); in hci_uart_tty_ioctl()
776 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) in hci_uart_tty_ioctl()
777 err = hu->proto->id; in hci_uart_tty_ioctl()
783 if (test_bit(HCI_UART_REGISTERED, &hu->flags)) in hci_uart_tty_ioctl()
784 err = hu->hdev->id; in hci_uart_tty_ioctl()
790 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) in hci_uart_tty_ioctl()
793 err = hci_uart_set_flags(hu, arg); in hci_uart_tty_ioctl()
797 err = hu->hdev_flags; in hci_uart_tty_ioctl()