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()
157 clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); in hci_uart_write_work()
159 while ((skb = hci_uart_dequeue(hu))) { in hci_uart_write_work()
168 hu->tx_skb = skb; in hci_uart_write_work()
172 hci_uart_tx_complete(hu, hci_skb_pkt_type(skb)); in hci_uart_write_work()
176 clear_bit(HCI_UART_SENDING, &hu->tx_state); in hci_uart_write_work()
177 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state)) in hci_uart_write_work()
180 wake_up_bit(&hu->tx_state, HCI_UART_SENDING); in hci_uart_write_work()
185 struct hci_uart *hu = container_of(work, struct hci_uart, init_ready); in hci_uart_init_work() local
189 if (!test_and_clear_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_init_work()
192 err = hci_register_dev(hu->hdev); in hci_uart_init_work()
195 clear_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_init_work()
196 hu->proto->close(hu); in hci_uart_init_work()
197 hdev = hu->hdev; in hci_uart_init_work()
198 hu->hdev = NULL; in hci_uart_init_work()
203 set_bit(HCI_UART_REGISTERED, &hu->flags); in hci_uart_init_work()
206 int hci_uart_init_ready(struct hci_uart *hu) in hci_uart_init_ready() argument
208 if (!test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_init_ready()
211 schedule_work(&hu->init_ready); in hci_uart_init_ready()
216 int hci_uart_wait_until_sent(struct hci_uart *hu) in hci_uart_wait_until_sent() argument
218 return wait_on_bit_timeout(&hu->tx_state, HCI_UART_SENDING, in hci_uart_wait_until_sent()
227 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_flush() local
228 struct tty_struct *tty = hu->tty; in hci_uart_flush()
232 if (hu->tx_skb) { in hci_uart_flush()
233 kfree_skb(hu->tx_skb); hu->tx_skb = NULL; in hci_uart_flush()
240 percpu_down_read(&hu->proto_lock); in hci_uart_flush()
242 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) in hci_uart_flush()
243 hu->proto->flush(hu); in hci_uart_flush()
245 percpu_up_read(&hu->proto_lock); in hci_uart_flush()
274 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_send_frame() local
279 percpu_down_read(&hu->proto_lock); in hci_uart_send_frame()
281 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_send_frame()
282 percpu_up_read(&hu->proto_lock); in hci_uart_send_frame()
286 hu->proto->enqueue(hu, skb); in hci_uart_send_frame()
287 percpu_up_read(&hu->proto_lock); in hci_uart_send_frame()
289 hci_uart_tx_wakeup(hu); in hci_uart_send_frame()
295 bool hci_uart_has_flow_control(struct hci_uart *hu) in hci_uart_has_flow_control() argument
298 if (hu->serdev) in hci_uart_has_flow_control()
301 if (hu->tty->driver->ops->tiocmget && hu->tty->driver->ops->tiocmset) in hci_uart_has_flow_control()
308 void hci_uart_set_flow_control(struct hci_uart *hu, bool enable) in hci_uart_set_flow_control() argument
310 struct tty_struct *tty = hu->tty; in hci_uart_set_flow_control()
316 if (hu->serdev) { in hci_uart_set_flow_control()
317 serdev_device_set_flow_control(hu->serdev, !enable); in hci_uart_set_flow_control()
318 serdev_device_set_rts(hu->serdev, !enable); in hci_uart_set_flow_control()
366 void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, in hci_uart_set_speeds() argument
369 hu->init_speed = init_speed; in hci_uart_set_speeds()
370 hu->oper_speed = oper_speed; in hci_uart_set_speeds()
373 void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed) in hci_uart_set_baudrate() argument
375 struct tty_struct *tty = hu->tty; in hci_uart_set_baudrate()
385 BT_DBG("%s: New tty speeds: %d/%d", hu->hdev->name, in hci_uart_set_baudrate()
391 struct hci_uart *hu = hci_get_drvdata(hdev); in hci_uart_setup() local
398 if (hu->init_speed) in hci_uart_setup()
399 speed = hu->init_speed; in hci_uart_setup()
400 else if (hu->proto->init_speed) in hci_uart_setup()
401 speed = hu->proto->init_speed; in hci_uart_setup()
406 hci_uart_set_baudrate(hu, speed); in hci_uart_setup()
409 if (hu->oper_speed) in hci_uart_setup()
410 speed = hu->oper_speed; in hci_uart_setup()
411 else if (hu->proto->oper_speed) in hci_uart_setup()
412 speed = hu->proto->oper_speed; in hci_uart_setup()
416 if (hu->proto->set_baudrate && speed) { in hci_uart_setup()
417 err = hu->proto->set_baudrate(hu, speed); in hci_uart_setup()
419 hci_uart_set_baudrate(hu, speed); in hci_uart_setup()
422 if (hu->proto->setup) in hci_uart_setup()
423 return hu->proto->setup(hu); in hci_uart_setup()
425 if (!test_bit(HCI_UART_VND_DETECT, &hu->hdev_flags)) in hci_uart_setup()
478 struct hci_uart *hu; in hci_uart_tty_open() local
491 hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL); in hci_uart_tty_open()
492 if (!hu) { in hci_uart_tty_open()
496 if (percpu_init_rwsem(&hu->proto_lock)) { in hci_uart_tty_open()
498 kfree(hu); in hci_uart_tty_open()
502 tty->disc_data = hu; in hci_uart_tty_open()
503 hu->tty = tty; in hci_uart_tty_open()
507 hu->alignment = 1; in hci_uart_tty_open()
508 hu->padding = 0; in hci_uart_tty_open()
510 INIT_WORK(&hu->init_ready, hci_uart_init_work); in hci_uart_tty_open()
511 INIT_WORK(&hu->write_work, hci_uart_write_work); in hci_uart_tty_open()
526 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_close() local
534 if (!hu) in hci_uart_tty_close()
537 hdev = hu->hdev; in hci_uart_tty_close()
541 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_tty_close()
542 percpu_down_write(&hu->proto_lock); in hci_uart_tty_close()
543 clear_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_tty_close()
544 percpu_up_write(&hu->proto_lock); in hci_uart_tty_close()
546 cancel_work_sync(&hu->init_ready); in hci_uart_tty_close()
547 cancel_work_sync(&hu->write_work); in hci_uart_tty_close()
550 if (test_bit(HCI_UART_REGISTERED, &hu->flags)) in hci_uart_tty_close()
554 hu->proto->close(hu); in hci_uart_tty_close()
556 clear_bit(HCI_UART_PROTO_SET, &hu->flags); in hci_uart_tty_close()
558 percpu_free_rwsem(&hu->proto_lock); in hci_uart_tty_close()
560 kfree(hu); in hci_uart_tty_close()
573 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_wakeup() local
577 if (!hu) in hci_uart_tty_wakeup()
582 if (tty != hu->tty) in hci_uart_tty_wakeup()
585 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) in hci_uart_tty_wakeup()
586 hci_uart_tx_wakeup(hu); in hci_uart_tty_wakeup()
604 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_receive() local
606 if (!hu || tty != hu->tty) in hci_uart_tty_receive()
609 percpu_down_read(&hu->proto_lock); in hci_uart_tty_receive()
611 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) { in hci_uart_tty_receive()
612 percpu_up_read(&hu->proto_lock); in hci_uart_tty_receive()
619 hu->proto->recv(hu, data, count); in hci_uart_tty_receive()
620 percpu_up_read(&hu->proto_lock); in hci_uart_tty_receive()
622 if (hu->hdev) in hci_uart_tty_receive()
623 hu->hdev->stat.byte_rx += count; in hci_uart_tty_receive()
628 static int hci_uart_register_dev(struct hci_uart *hu) in hci_uart_register_dev() argument
642 hu->hdev = hdev; in hci_uart_register_dev()
645 hci_set_drvdata(hdev, hu); in hci_uart_register_dev()
651 if (hu->proto->setup) in hci_uart_register_dev()
652 hdev->manufacturer = hu->proto->manufacturer; in hci_uart_register_dev()
659 SET_HCIDEV_DEV(hdev, hu->tty->dev); in hci_uart_register_dev()
661 if (test_bit(HCI_UART_RAW_DEVICE, &hu->hdev_flags)) in hci_uart_register_dev()
664 if (test_bit(HCI_UART_EXT_CONFIG, &hu->hdev_flags)) in hci_uart_register_dev()
667 if (!test_bit(HCI_UART_RESET_ON_INIT, &hu->hdev_flags)) in hci_uart_register_dev()
670 if (test_bit(HCI_UART_CREATE_AMP, &hu->hdev_flags)) in hci_uart_register_dev()
678 err = hu->proto->open(hu); in hci_uart_register_dev()
680 hu->hdev = NULL; in hci_uart_register_dev()
685 if (test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags)) in hci_uart_register_dev()
690 hu->proto->close(hu); in hci_uart_register_dev()
691 hu->hdev = NULL; in hci_uart_register_dev()
696 set_bit(HCI_UART_REGISTERED, &hu->flags); in hci_uart_register_dev()
701 static int hci_uart_set_proto(struct hci_uart *hu, int id) in hci_uart_set_proto() argument
710 hu->proto = p; in hci_uart_set_proto()
712 err = hci_uart_register_dev(hu); in hci_uart_set_proto()
717 set_bit(HCI_UART_PROTO_READY, &hu->flags); in hci_uart_set_proto()
721 static int hci_uart_set_flags(struct hci_uart *hu, unsigned long flags) in hci_uart_set_flags() argument
733 hu->hdev_flags = flags; in hci_uart_set_flags()
753 struct hci_uart *hu = tty->disc_data; in hci_uart_tty_ioctl() local
759 if (!hu) in hci_uart_tty_ioctl()
764 if (!test_and_set_bit(HCI_UART_PROTO_SET, &hu->flags)) { in hci_uart_tty_ioctl()
765 err = hci_uart_set_proto(hu, arg); in hci_uart_tty_ioctl()
767 clear_bit(HCI_UART_PROTO_SET, &hu->flags); in hci_uart_tty_ioctl()
773 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) in hci_uart_tty_ioctl()
774 err = hu->proto->id; in hci_uart_tty_ioctl()
780 if (test_bit(HCI_UART_REGISTERED, &hu->flags)) in hci_uart_tty_ioctl()
781 err = hu->hdev->id; in hci_uart_tty_ioctl()
787 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) in hci_uart_tty_ioctl()
790 err = hci_uart_set_flags(hu, arg); in hci_uart_tty_ioctl()
794 err = hu->hdev_flags; in hci_uart_tty_ioctl()