Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  AVM BlueFRITZ! USB driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2003-2006  Marcel Holtmann <marcel@holtmann.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define VERSION "1.2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static struct usb_driver bfusb_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static const struct usb_device_id bfusb_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	/* AVM BlueFRITZ! USB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	{ USB_DEVICE(0x057c, 0x2200) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	{ }	/* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) MODULE_DEVICE_TABLE(usb, bfusb_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define BFUSB_MAX_BLOCK_SIZE	256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define BFUSB_BLOCK_TIMEOUT	3000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define BFUSB_TX_PROCESS	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define BFUSB_TX_WAKEUP		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define BFUSB_MAX_BULK_TX	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define BFUSB_MAX_BULK_RX	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) struct bfusb_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct hci_dev		*hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned long		state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct usb_device	*udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	unsigned int		bulk_in_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	unsigned int		bulk_out_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned int		bulk_pkt_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	rwlock_t		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct sk_buff_head	transmit_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct sk_buff		*reassembly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	atomic_t		pending_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct sk_buff_head	pending_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct sk_buff_head	completed_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) struct bfusb_data_scb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static void bfusb_tx_complete(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static void bfusb_rx_complete(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static struct urb *bfusb_get_completed(struct bfusb_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct urb *urb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	BT_DBG("bfusb %p", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	skb = skb_dequeue(&data->completed_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		urb = ((struct bfusb_data_scb *) skb->cb)->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static void bfusb_unlink_urbs(struct bfusb_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	BT_DBG("bfusb %p", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	while ((skb = skb_dequeue(&data->pending_q))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		urb = ((struct bfusb_data_scb *) skb->cb)->urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		usb_kill_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		skb_queue_tail(&data->completed_q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	while ((urb = bfusb_get_completed(data)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int bfusb_send_bulk(struct bfusb_data *data, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct bfusb_data_scb *scb = (void *) skb->cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct urb *urb = bfusb_get_completed(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int err, pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	BT_DBG("bfusb %p skb %p len %d", data, skb, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	usb_fill_bulk_urb(urb, data->udev, pipe, skb->data, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			bfusb_tx_complete, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	scb->urb = urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	skb_queue_tail(&data->pending_q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		bt_dev_err(data->hdev, "bulk tx submit failed urb %p err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			   urb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		skb_unlink(skb, &data->pending_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		atomic_inc(&data->pending_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static void bfusb_tx_wakeup(struct bfusb_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	BT_DBG("bfusb %p", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (test_and_set_bit(BFUSB_TX_PROCESS, &data->state)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		set_bit(BFUSB_TX_WAKEUP, &data->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		clear_bit(BFUSB_TX_WAKEUP, &data->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		while ((atomic_read(&data->pending_tx) < BFUSB_MAX_BULK_TX) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				(skb = skb_dequeue(&data->transmit_q))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			if (bfusb_send_bulk(data, skb) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				skb_queue_head(&data->transmit_q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	} while (test_bit(BFUSB_TX_WAKEUP, &data->state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	clear_bit(BFUSB_TX_PROCESS, &data->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static void bfusb_tx_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct sk_buff *skb = (struct sk_buff *) urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct bfusb_data *data = (struct bfusb_data *) skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	BT_DBG("bfusb %p urb %p skb %p len %d", data, urb, skb, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	atomic_dec(&data->pending_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (!test_bit(HCI_RUNNING, &data->hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (!urb->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		data->hdev->stat.byte_tx += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		data->hdev->stat.err_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	read_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	skb_unlink(skb, &data->pending_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	skb_queue_tail(&data->completed_q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	bfusb_tx_wakeup(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	read_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static int bfusb_rx_submit(struct bfusb_data *data, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct bfusb_data_scb *scb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	int err, pipe, size = HCI_MAX_FRAME_SIZE + 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	BT_DBG("bfusb %p urb %p", data, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (!urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	skb = bt_skb_alloc(size, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	skb->dev = (void *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	scb = (struct bfusb_data_scb *) skb->cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	scb->urb = urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	pipe = usb_rcvbulkpipe(data->udev, data->bulk_in_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	usb_fill_bulk_urb(urb, data->udev, pipe, skb->data, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			bfusb_rx_complete, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	skb_queue_tail(&data->pending_q, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		bt_dev_err(data->hdev, "bulk rx submit failed urb %p err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			   urb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		skb_unlink(skb, &data->pending_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static inline int bfusb_recv_block(struct bfusb_data *data, int hdr, unsigned char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	BT_DBG("bfusb %p hdr 0x%02x data %p len %d", data, hdr, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (hdr & 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		bt_dev_err(data->hdev, "error in block");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		kfree_skb(data->reassembly);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		data->reassembly = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (hdr & 0x04) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		unsigned char pkt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		int pkt_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		if (data->reassembly) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			bt_dev_err(data->hdev, "unexpected start block");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			kfree_skb(data->reassembly);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			data->reassembly = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		if (len < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			bt_dev_err(data->hdev, "no packet type found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		pkt_type = *buf++; len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		switch (pkt_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		case HCI_EVENT_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			if (len >= HCI_EVENT_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				struct hci_event_hdr *hdr = (struct hci_event_hdr *) buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				pkt_len = HCI_EVENT_HDR_SIZE + hdr->plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				bt_dev_err(data->hdev, "event block is too short");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			if (len >= HCI_ACL_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 				struct hci_acl_hdr *hdr = (struct hci_acl_hdr *) buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				pkt_len = HCI_ACL_HDR_SIZE + __le16_to_cpu(hdr->dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 				bt_dev_err(data->hdev, "data block is too short");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 				return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			if (len >= HCI_SCO_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 				struct hci_sco_hdr *hdr = (struct hci_sco_hdr *) buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 				pkt_len = HCI_SCO_HDR_SIZE + hdr->dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				bt_dev_err(data->hdev, "audio block is too short");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 				return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		skb = bt_skb_alloc(pkt_len, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			bt_dev_err(data->hdev, "no memory for the packet");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		hci_skb_pkt_type(skb) = pkt_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		data->reassembly = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		if (!data->reassembly) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			bt_dev_err(data->hdev, "unexpected continuation block");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (len > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		skb_put_data(data->reassembly, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (hdr & 0x08) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		hci_recv_frame(data->hdev, data->reassembly);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		data->reassembly = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static void bfusb_rx_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct sk_buff *skb = (struct sk_buff *) urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct bfusb_data *data = (struct bfusb_data *) skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	unsigned char *buf = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	int count = urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	int err, hdr, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	BT_DBG("bfusb %p urb %p skb %p len %d", data, urb, skb, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	read_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if (!test_bit(HCI_RUNNING, &data->hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (urb->status || !count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		goto resubmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	data->hdev->stat.byte_rx += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	skb_put(skb, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		hdr = buf[0] | (buf[1] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		if (hdr & 0x4000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			count -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			buf   += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			len = (buf[2] == 0) ? 256 : buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			count -= 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			buf   += 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		if (count < len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			bt_dev_err(data->hdev, "block extends over URB buffer ranges");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		if ((hdr & 0xe1) == 0xc1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			bfusb_recv_block(data, hdr, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		buf   += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	skb_unlink(skb, &data->pending_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	bfusb_rx_submit(data, urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	read_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) resubmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	urb->dev = data->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		bt_dev_err(data->hdev, "bulk resubmit failed urb %p err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 			   urb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	read_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static int bfusb_open(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct bfusb_data *data = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	BT_DBG("hdev %p bfusb %p", hdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	write_lock_irqsave(&data->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	err = bfusb_rx_submit(data, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		for (i = 1; i < BFUSB_MAX_BULK_RX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 			bfusb_rx_submit(data, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	write_unlock_irqrestore(&data->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static int bfusb_flush(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	struct bfusb_data *data = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	BT_DBG("hdev %p bfusb %p", hdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	skb_queue_purge(&data->transmit_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static int bfusb_close(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	struct bfusb_data *data = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	BT_DBG("hdev %p bfusb %p", hdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	write_lock_irqsave(&data->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	write_unlock_irqrestore(&data->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	bfusb_unlink_urbs(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	bfusb_flush(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static int bfusb_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	struct bfusb_data *data = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct sk_buff *nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	unsigned char buf[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	int sent = 0, size, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	BT_DBG("hdev %p skb %p type %d len %d", hdev, skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	       hci_skb_pkt_type(skb), skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	switch (hci_skb_pkt_type(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	case HCI_COMMAND_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		hdev->stat.cmd_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		hdev->stat.acl_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		hdev->stat.sco_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	/* Prepend skb with frame type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	count = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	/* Max HCI frame size seems to be 1511 + 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	nskb = bt_skb_alloc(count + 32, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	if (!nskb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		bt_dev_err(hdev, "Can't allocate memory for new packet");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	nskb->dev = (void *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		buf[0] = 0xc1 | ((sent == 0) ? 0x04 : 0) | ((count == size) ? 0x08 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		buf[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		buf[2] = (size == BFUSB_MAX_BLOCK_SIZE) ? 0 : size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		skb_put_data(nskb, buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		skb_copy_from_linear_data_offset(skb, sent, skb_put(nskb, size), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		sent  += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		count -= size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	/* Don't send frame with multiple size of bulk max packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if ((nskb->len % data->bulk_pkt_size) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		buf[0] = 0xdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		buf[1] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		skb_put_data(nskb, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	read_lock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	skb_queue_tail(&data->transmit_q, nskb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	bfusb_tx_wakeup(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	read_unlock(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static int bfusb_load_firmware(struct bfusb_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 			       const unsigned char *firmware, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	int err, pipe, len, size, sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	BT_DBG("bfusb %p udev %p", data, data->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	BT_INFO("BlueFRITZ! USB loading firmware");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	buf = kmalloc(BFUSB_MAX_BLOCK_SIZE + 3, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		BT_ERR("Can't allocate memory chunk for firmware");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	pipe = usb_sndctrlpipe(data->udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	if (usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 				0, 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		BT_ERR("Can't change to loading configuration");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	data->udev->toggle[0] = data->udev->toggle[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	pipe = usb_sndbulkpipe(data->udev, data->bulk_out_ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		size = min_t(uint, count, BFUSB_MAX_BLOCK_SIZE + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		memcpy(buf, firmware + sent, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		err = usb_bulk_msg(data->udev, pipe, buf, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 					&len, BFUSB_BLOCK_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		if (err || (len != size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			BT_ERR("Error in firmware loading");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		sent  += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		count -= size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	err = usb_bulk_msg(data->udev, pipe, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 					&len, BFUSB_BLOCK_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		BT_ERR("Error in null packet request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	pipe = usb_sndctrlpipe(data->udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	err = usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 				0, 2, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		BT_ERR("Can't change to running configuration");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	data->udev->toggle[0] = data->udev->toggle[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	BT_INFO("BlueFRITZ! USB device ready");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	pipe = usb_sndctrlpipe(data->udev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	usb_control_msg(data->udev, pipe, USB_REQ_SET_CONFIGURATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 				0, 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static int bfusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	const struct firmware *firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	struct usb_host_endpoint *bulk_out_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	struct usb_host_endpoint *bulk_in_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	struct bfusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	BT_DBG("intf %p id %p", intf, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	/* Check number of endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	if (intf->cur_altsetting->desc.bNumEndpoints < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	bulk_out_ep = &intf->cur_altsetting->endpoint[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	bulk_in_ep  = &intf->cur_altsetting->endpoint[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	if (!bulk_out_ep || !bulk_in_ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		BT_ERR("Bulk endpoints not found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	/* Initialize control structure and load firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	data = devm_kzalloc(&intf->dev, sizeof(struct bfusb_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	data->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	data->bulk_in_ep    = bulk_in_ep->desc.bEndpointAddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	data->bulk_out_ep   = bulk_out_ep->desc.bEndpointAddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	data->bulk_pkt_size = le16_to_cpu(bulk_out_ep->desc.wMaxPacketSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	if (!data->bulk_pkt_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	rwlock_init(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	data->reassembly = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	skb_queue_head_init(&data->transmit_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	skb_queue_head_init(&data->pending_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	skb_queue_head_init(&data->completed_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	if (request_firmware(&firmware, "bfubase.frm", &udev->dev) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		BT_ERR("Firmware request failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	BT_DBG("firmware data %p size %zu", firmware->data, firmware->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	if (bfusb_load_firmware(data, firmware->data, firmware->size) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 		BT_ERR("Firmware loading failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		goto release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	release_firmware(firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	/* Initialize and register HCI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	hdev = hci_alloc_dev();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		BT_ERR("Can't allocate HCI device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	data->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	hdev->bus = HCI_USB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	hci_set_drvdata(hdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	SET_HCIDEV_DEV(hdev, &intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	hdev->open  = bfusb_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	hdev->close = bfusb_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	hdev->flush = bfusb_flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	hdev->send  = bfusb_send_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	set_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	if (hci_register_dev(hdev) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		BT_ERR("Can't register HCI device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	usb_set_intfdata(intf, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	release_firmware(firmware);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) static void bfusb_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	struct bfusb_data *data = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	struct hci_dev *hdev = data->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	BT_DBG("intf %p", intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	if (!hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	bfusb_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	hci_unregister_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static struct usb_driver bfusb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	.name		= "bfusb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	.probe		= bfusb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	.disconnect	= bfusb_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	.id_table	= bfusb_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	.disable_hub_initiated_lpm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) module_usb_driver(bfusb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) MODULE_DESCRIPTION("BlueFRITZ! USB driver ver " VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) MODULE_VERSION(VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) MODULE_FIRMWARE("bfubase.frm");