Lines Matching refs:hu
78 static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
80 struct hci_dev *hdev = hu->hdev;
98 static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu)
100 struct sk_buff *skb = hu->tx_skb;
103 percpu_down_read(&hu->proto_lock);
105 if (test_bit(HCI_UART_PROTO_READY, &hu->flags))
106 skb = hu->proto->dequeue(hu);
108 percpu_up_read(&hu->proto_lock);
110 hu->tx_skb = NULL;
116 int hci_uart_tx_wakeup(struct hci_uart *hu)
124 if (!percpu_down_read_trylock(&hu->proto_lock))
127 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags))
130 set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
131 if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state))
136 schedule_work(&hu->write_work);
139 percpu_up_read(&hu->proto_lock);
147 struct hci_uart *hu = container_of(work, struct hci_uart, write_work);
148 struct tty_struct *tty = hu->tty;
149 struct hci_dev *hdev = hu->hdev;
157 clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
159 while ((skb = hci_uart_dequeue(hu))) {
168 hu->tx_skb = skb;
172 hci_uart_tx_complete(hu, hci_skb_pkt_type(skb));
176 clear_bit(HCI_UART_SENDING, &hu->tx_state);
177 if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state))
180 wake_up_bit(&hu->tx_state, HCI_UART_SENDING);
185 struct hci_uart *hu = container_of(work, struct hci_uart, init_ready);
189 if (!test_and_clear_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags))
192 err = hci_register_dev(hu->hdev);
195 clear_bit(HCI_UART_PROTO_READY, &hu->flags);
196 hu->proto->close(hu);
197 hdev = hu->hdev;
198 hu->hdev = NULL;
203 set_bit(HCI_UART_REGISTERED, &hu->flags);
206 int hci_uart_init_ready(struct hci_uart *hu)
208 if (!test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags))
211 schedule_work(&hu->init_ready);
216 int hci_uart_wait_until_sent(struct hci_uart *hu)
218 return wait_on_bit_timeout(&hu->tx_state, HCI_UART_SENDING,
227 struct hci_uart *hu = hci_get_drvdata(hdev);
228 struct tty_struct *tty = hu->tty;
232 if (hu->tx_skb) {
233 kfree_skb(hu->tx_skb); hu->tx_skb = NULL;
240 percpu_down_read(&hu->proto_lock);
242 if (test_bit(HCI_UART_PROTO_READY, &hu->flags))
243 hu->proto->flush(hu);
245 percpu_up_read(&hu->proto_lock);
274 struct hci_uart *hu = hci_get_drvdata(hdev);
279 percpu_down_read(&hu->proto_lock);
281 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
282 percpu_up_read(&hu->proto_lock);
286 hu->proto->enqueue(hu, skb);
287 percpu_up_read(&hu->proto_lock);
289 hci_uart_tx_wakeup(hu);
295 bool hci_uart_has_flow_control(struct hci_uart *hu)
298 if (hu->serdev)
301 if (hu->tty->driver->ops->tiocmget && hu->tty->driver->ops->tiocmset)
308 void hci_uart_set_flow_control(struct hci_uart *hu, bool enable)
310 struct tty_struct *tty = hu->tty;
316 if (hu->serdev) {
317 serdev_device_set_flow_control(hu->serdev, !enable);
318 serdev_device_set_rts(hu->serdev, !enable);
366 void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed,
369 hu->init_speed = init_speed;
370 hu->oper_speed = oper_speed;
373 void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed)
375 struct tty_struct *tty = hu->tty;
385 BT_DBG("%s: New tty speeds: %d/%d", hu->hdev->name,
391 struct hci_uart *hu = hci_get_drvdata(hdev);
398 if (hu->init_speed)
399 speed = hu->init_speed;
400 else if (hu->proto->init_speed)
401 speed = hu->proto->init_speed;
406 hci_uart_set_baudrate(hu, speed);
409 if (hu->oper_speed)
410 speed = hu->oper_speed;
411 else if (hu->proto->oper_speed)
412 speed = hu->proto->oper_speed;
416 if (hu->proto->set_baudrate && speed) {
417 err = hu->proto->set_baudrate(hu, speed);
419 hci_uart_set_baudrate(hu, speed);
422 if (hu->proto->setup)
423 return hu->proto->setup(hu);
425 if (!test_bit(HCI_UART_VND_DETECT, &hu->hdev_flags))
478 struct hci_uart *hu;
488 hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL);
489 if (!hu) {
493 if (percpu_init_rwsem(&hu->proto_lock)) {
495 kfree(hu);
499 tty->disc_data = hu;
500 hu->tty = tty;
504 hu->alignment = 1;
505 hu->padding = 0;
507 INIT_WORK(&hu->init_ready, hci_uart_init_work);
508 INIT_WORK(&hu->write_work, hci_uart_write_work);
523 struct hci_uart *hu = tty->disc_data;
531 if (!hu)
534 hdev = hu->hdev;
538 if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
539 percpu_down_write(&hu->proto_lock);
540 clear_bit(HCI_UART_PROTO_READY, &hu->flags);
541 percpu_up_write(&hu->proto_lock);
543 cancel_work_sync(&hu->init_ready);
544 cancel_work_sync(&hu->write_work);
547 if (test_bit(HCI_UART_REGISTERED, &hu->flags))
551 hu->proto->close(hu);
553 clear_bit(HCI_UART_PROTO_SET, &hu->flags);
555 percpu_free_rwsem(&hu->proto_lock);
557 kfree(hu);
570 struct hci_uart *hu = tty->disc_data;
574 if (!hu)
579 if (tty != hu->tty)
582 if (test_bit(HCI_UART_PROTO_READY, &hu->flags))
583 hci_uart_tx_wakeup(hu);
601 struct hci_uart *hu = tty->disc_data;
603 if (!hu || tty != hu->tty)
606 percpu_down_read(&hu->proto_lock);
608 if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
609 percpu_up_read(&hu->proto_lock);
616 hu->proto->recv(hu, data, count);
617 percpu_up_read(&hu->proto_lock);
619 if (hu->hdev)
620 hu->hdev->stat.byte_rx += count;
625 static int hci_uart_register_dev(struct hci_uart *hu)
639 hu->hdev = hdev;
642 hci_set_drvdata(hdev, hu);
648 if (hu->proto->setup)
649 hdev->manufacturer = hu->proto->manufacturer;
656 SET_HCIDEV_DEV(hdev, hu->tty->dev);
658 if (test_bit(HCI_UART_RAW_DEVICE, &hu->hdev_flags))
661 if (test_bit(HCI_UART_EXT_CONFIG, &hu->hdev_flags))
664 if (!test_bit(HCI_UART_RESET_ON_INIT, &hu->hdev_flags))
667 if (test_bit(HCI_UART_CREATE_AMP, &hu->hdev_flags))
675 err = hu->proto->open(hu);
677 hu->hdev = NULL;
682 if (test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags))
687 hu->proto->close(hu);
688 hu->hdev = NULL;
693 set_bit(HCI_UART_REGISTERED, &hu->flags);
698 static int hci_uart_set_proto(struct hci_uart *hu, int id)
707 hu->proto = p;
709 err = hci_uart_register_dev(hu);
714 set_bit(HCI_UART_PROTO_READY, &hu->flags);
718 static int hci_uart_set_flags(struct hci_uart *hu, unsigned long flags)
730 hu->hdev_flags = flags;
751 struct hci_uart *hu = tty->disc_data;
757 if (!hu)
762 if (!test_and_set_bit(HCI_UART_PROTO_SET, &hu->flags)) {
763 err = hci_uart_set_proto(hu, arg);
765 clear_bit(HCI_UART_PROTO_SET, &hu->flags);
771 if (test_bit(HCI_UART_PROTO_SET, &hu->flags) &&
772 test_bit(HCI_UART_PROTO_READY, &hu->flags))
773 err = hu->proto->id;
779 if (test_bit(HCI_UART_REGISTERED, &hu->flags))
780 err = hu->hdev->id;
786 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
789 err = hci_uart_set_flags(hu, arg);
793 err = hu->hdev_flags;