Skip to contentSkip to conversation

DFU Driver and firmware for Atheros bluetooth chipset AR3011

PATCH In review Kandukuri Vikram 4 participants 8 messages Nov 17, 2009 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DFU Driver and firmware for Atheros bluetooth chipset AR3011

---
 drivers/bluetooth/Kconfig  |   12 +++
 drivers/bluetooth/Makefile |    2 +
 drivers/bluetooth/athbt.c  |  208 ++++++++++++++++++++++++++++++++++++++++++++
 firmware/atherosbt.bin     |  Bin 0 -> 246804 bytes
 4 files changed, 222 insertions(+), 0 deletions(-)
 create mode 100644 drivers/bluetooth/athbt.c
 create mode 100644 firmware/atherosbt.bin
drivers/bluetooth/Kconfig +12 -0
index 652367a..5bc174e 100644
@@ -195,5 +195,17 @@ config BT_MRVL_SDIO
 	  Say Y here to compile support for Marvell BT-over-SDIO driver
 	  into the kernel or say M to compile it as module.
 
+config BT_ATHR
+	tristate "Atheros firmware download driver"
+	depends on BT_HCIBTUSB
+	select FW_LOADER
+	help
+	  Bluetooth firmware download driver.
+	  This driver loads the firmware into the Atheros bluetooth
+          chipset.
+
+	  Say Y here to compile support for "Atheros firmware download driver"
+          into the  kernel or say M to compile it as module (athbt).
+
 endmenu
 
drivers/bluetooth/Makefile +2 -0
index b3f57d2..f5b27e0 100644
@@ -18,6 +18,8 @@ obj-$(CONFIG_BT_HCIBTSDIO)	+= btsdio.o
 obj-$(CONFIG_BT_MRVL)		+= btmrvl.o
 obj-$(CONFIG_BT_MRVL_SDIO)	+= btmrvl_sdio.o
 
+obj-$(CONFIG_BT_ATHR)	        += athbt.o
+
 btmrvl-y			:= btmrvl_main.o
 btmrvl-$(CONFIG_DEBUG_FS)	+= btmrvl_debugfs.o
 
drivers/bluetooth/athbt.c new file +208 -0

208 lines not on this page · raw message

firmware/atherosbt.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4a5ffb8de898fab1595662742f287493689e2b3b
GIT binary patch
Signature · 1 line
1.6.0.4
maintainer
#1 lore raw

Hi Vikram,

your email ended up in my spam folder because of your binary attachment.

Quoted 10 lines
---
 drivers/bluetooth/Kconfig  |   12 +++
 drivers/bluetooth/Makefile |    2 +
 drivers/bluetooth/athbt.c  |  208 ++++++++++++++++++++++++++++++++++++++++++++
 firmware/atherosbt.bin     |  Bin 0 -> 246804 bytes
 4 files changed, 222 insertions(+), 0 deletions(-)
 create mode 100644 drivers/bluetooth/athbt.c
 create mode 100644 firmware/atherosbt.bin

Following the naming convention from your WiFi drivers, this should either by ath3k or ar3011 or ar30xx or something like that.

Quoted 11 lines
drivers/bluetooth/Kconfig +3 -0
index 652367a..5bc174e 100644
@@ -195,5 +195,17 @@ config BT_MRVL_SDIO
 	  Say Y here to compile support for Marvell BT-over-SDIO driver
 	  into the kernel or say M to compile it as module.
 
+config BT_ATHR
+	tristate "Atheros firmware download driver"
+	depends on BT_HCIBTUSB

drivers/bluetooth/Kconfig config BT_MRVL_SDIO · line 210

Quoted 10 lines
drivers/bluetooth/Kconfig +9 -0
+	select FW_LOADER
+	help
+	  Bluetooth firmware download driver.
+	  This driver loads the firmware into the Atheros bluetooth
+          chipset.
+
+	  Say Y here to compile support for "Atheros firmware download driver"
+          into the  kernel or say M to compile it as module (athbt).
+
 endmenu

To make this a little bit more consistent for the planned future changes, I would propose that you use BT_ATH30XX or BT_ATH3K for this.

drivers/bluetooth/Makefile obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o · line 24

Quoted 12 lines
drivers/bluetooth/Makefile +2 -0
index b3f57d2..f5b27e0 100644
@@ -18,6 +18,8 @@ obj-$(CONFIG_BT_HCIBTSDIO)	+= btsdio.o
 obj-$(CONFIG_BT_MRVL)		+= btmrvl.o
 obj-$(CONFIG_BT_MRVL_SDIO)	+= btmrvl_sdio.o
 
+obj-$(CONFIG_BT_ATHR)	        += athbt.o
+
 btmrvl-y			:= btmrvl_main.o
 btmrvl-$(CONFIG_DEBUG_FS)	+= btmrvl_debugfs.o

Just sort this before the MRVL driver since this is a one file driver.

Quoted 28 lines
drivers/bluetooth/athbt.c new file +22 -0
new file mode 100644
index 0000000..cb940c9
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2008-2009 Atheros Communications Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+
+#include <linux/module.h>
+#include <linux/kernel.h>

drivers/bluetooth/athbt.c line 32

Quoted 10 lines
drivers/bluetooth/athbt.c new file +10 -0
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/device.h>
+#include <linux/firmware.h>
+#include <linux/usb.h>
+#include <net/bluetooth/bluetooth.h>
+
+#define DRV_VERSION "1.1"

We just use VERSION "1.1" in all the other drivers.

drivers/bluetooth/athbt.c line 39

Quoted 7 lines
drivers/bluetooth/athbt.c new file +7 -0
+
+MODULE_AUTHOR("Atheros Communications");
+MODULE_DESCRIPTION("Atheros AR3011 firmware driver");
+MODULE_VERSION(DRV_VERSION);
+MODULE_SUPPORTED_DEVICE("Atheros AR3011 chipset");
+MODULE_LICENSE("GPL");
+MODULE_FIRMWARE("atherosbt.bin");

And to be consistent, please put this at the end of the driver. The module author needs to have a contact information and not just the company name. Read it as who maintains this driver.

For the firmware file name, I prefer ar3011.fw or similar like you do for your other WiFi devices. Be at least a little bit consistent across your own products here.

drivers/bluetooth/athbt.c line 45

Quoted 5 lines
drivers/bluetooth/athbt.c new file +5 -0
+static struct usb_device_id athbt_table[] = {
+	/* Atheros USB deviceID */
+	{ USB_DEVICE(0x0CF3, 0x3000) },
+	{ }	/* Terminating entry */
+};

The word "deviceID" is pointless here. Use /* Atheros AR3011 without firmware */

drivers/bluetooth/athbt.c line 51

Quoted 5 lines
drivers/bluetooth/athbt.c new file +5 -0
+MODULE_DEVICE_TABLE(usb, athbt_table);
+
+#define USB_REQ_DFU_DNLOAD	1
+#define FIRST_20BYTE            20
+#define BLUK_SIZE               4096

BLUK? Typo?

drivers/bluetooth/athbt.c line 61

Quoted 9 lines
drivers/bluetooth/athbt.c new file +9 -0
+#define ATHBT_IN_EP(data)       (0x81)
+#define ATHBT_OUT_EP(data)	(0x02)
+
+struct athbt_data {
+    struct usb_device *udev;
+    u8 *fw_data;
+    u32 fw_size;
+    u32 fw_sent;
+};

Tabs versus spaces.

drivers/bluetooth/athbt.c line 69

Quoted 7 lines
drivers/bluetooth/athbt.c new file +7 -0
+static int athbt_load_firmware(struct athbt_data *data, unsigned char *firmware
+				, int count)
+{
+	u8 *send_buf;
+	int err, pipe, len, size, sent = 0;
+
+	BT_INFO("athbt %p udev %p\n", data, data->udev);

This is BT_DBG for and not BT_INFO.

drivers/bluetooth/athbt.c line 67

Quoted 2 lines
drivers/bluetooth/athbt.c new file +2 -0
+
+	BT_INFO("ATHBT! USB loading firmware\n");

And this is pointless. Or at least include the firmware name and ATHBT makes no sense to anybody.

drivers/bluetooth/athbt.c line 79

Quoted 8 lines
drivers/bluetooth/athbt.c new file +8 -0
+
+	pipe = usb_sndctrlpipe(data->udev, 0);
+
+	if ((usb_control_msg(data->udev, pipe,
+				USB_REQ_DFU_DNLOAD,
+				USB_TYPE_VENDOR, 0, 0,
+				firmware, 20, USB_CTRL_SET_TIMEOUT)) < 0) {
+		BT_INFO("Can't change to loading configuration err\n");

This is BT_ERR.

drivers/bluetooth/athbt.c line 87

Quoted 8 lines
drivers/bluetooth/athbt.c new file +8 -0
+		return -EBUSY;
+	}
+	sent += 20;
+	count -= 20;
+
+	send_buf = kmalloc(BLUK_SIZE, GFP_ATOMIC);
+	if (!send_buf) {
+		BT_INFO("Can't allocate memory chunk for firmware\n");

Same here.

Quoted 4 lines
drivers/bluetooth/athbt.c new file +4 -0
+		return -ENOMEM;
+	}
+
+	while (count) {

drivers/bluetooth/athbt.c line 101

Quoted 10 lines
drivers/bluetooth/athbt.c new file +10 -0
+		size = min_t(uint, count, BLUK_SIZE);
+		pipe = usb_sndbulkpipe(data->udev, ATHBT_OUT_EP(data));
+		memcpy(send_buf, firmware + sent, size);
+
+		err = usb_bulk_msg(data->udev, pipe, send_buf, size,
+					&len, 3000);
+
+		if (err || (len != size)) {
+			BT_INFO("Error in firmware loading err = %d,"
+				"len = %d, size = %d\n", err, len, size);

And here.

Quoted 14 lines
drivers/bluetooth/athbt.c new file +14 -0
+			goto error;
+		}
+
+		sent  += size;
+		count -= size;
+	}
+
+	kfree(send_buf);
+	return 0;
+
+error:
+	kfree(send_buf);
+	return err;
+}

drivers/bluetooth/athbt.c line 125

Quoted 10 lines
drivers/bluetooth/athbt.c new file +10 -0
+
+static int athbt_probe(struct usb_interface *intf,
+			const struct usb_device_id *id)
+{
+	const struct firmware *firmware;
+	struct usb_device *udev = interface_to_usbdev(intf);
+	struct athbt_data *data;
+	int size;
+
+	BT_INFO("athbt_probe intf %p id %p\n", intf, id);

BT_DBG.

drivers/bluetooth/athbt.c line 129

Quoted 4 lines
drivers/bluetooth/athbt.c new file +4 -0
+
+	/* Check number of endpoints */
+	BT_INFO("intf->cur_altsetting->desc.bInterfaceNumber = %d\n",
+		intf->cur_altsetting->desc.bInterfaceNumber);

Don't do that. Pointless information.

drivers/bluetooth/athbt.c line 132

Quoted 3 lines
drivers/bluetooth/athbt.c new file +3 -0
+
+	if (intf->cur_altsetting->desc.bInterfaceNumber != 0) {
+		BT_INFO("athbt_probe: ENODEV\n");

This is not an error. Just return -ENODEV. Stop spamming dmesg like crazy. This driver is suppose to load a firmware and not operate a nuclear reactor.

drivers/bluetooth/athbt.c line 138

Quoted 6 lines
drivers/bluetooth/athbt.c new file +6 -0
+		return -ENODEV;
+	}
+
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data) {
+		BT_INFO("Can't allocate memory for data structure");

BT_ERR.

Quoted 5 lines
drivers/bluetooth/athbt.c new file +5 -0
+		return -ENOMEM;
+	}
+
+	data->udev  = udev;
+

drivers/bluetooth/athbt.c line 153

Quoted 10 lines
drivers/bluetooth/athbt.c new file +10 -0
+	if (request_firmware(&firmware, "atherosbt.bin", &udev->dev) < 0) {
+		BT_INFO("atherosbt firmware request failed");
+		kfree(data);
+		return -EIO;
+	}
+
+	size = max_t(uint, firmware->size, 4096);
+	data->fw_data = kmalloc(size, GFP_KERNEL);
+	if (!data->fw_data) {
+		BT_INFO("Can't allocate memory for firmware\n");

BT_ERR.

drivers/bluetooth/athbt.c line 166

Quoted 13 lines
drivers/bluetooth/athbt.c new file +13 -0
+		release_firmware(firmware);
+		kfree(data);
+		return -ENOMEM;
+	}
+
+	memcpy(data->fw_data, firmware->data, firmware->size);
+	data->fw_size = firmware->size;
+	data->fw_sent = 0;
+	release_firmware(firmware);
+
+	usb_set_intfdata(intf, data);
+	if (athbt_load_firmware(data, data->fw_data, data->fw_size))
+		BT_INFO("ath_load_firmware   failed\n");

If it fails loading the firmware you wanna keep it claiming the interface. That is stupid. Return an error here and give some other drivers a chance.

drivers/bluetooth/athbt.c line 175

Quoted 9 lines
drivers/bluetooth/athbt.c new file +9 -0
+
+	return 0;
+}
+
+static void athbt_disconnect(struct usb_interface *intf)
+{
+	struct athbt_data *data = usb_get_intfdata(intf);
+
+	BT_INFO("athbt_disconnect intf %p\n", intf);

BT_DBG.

Quoted 11 lines
drivers/bluetooth/athbt.c new file +11 -0
+
+	kfree(data->fw_data);
+	kfree(data);
+}
+
+static struct usb_driver athbt_driver = {
+	.name		= "athbt",
+	.probe		= athbt_probe,
+	.disconnect	= athbt_disconnect,
+	.id_table	= athbt_table,
+};

drivers/bluetooth/athbt.c line 196

Quoted 10 lines
drivers/bluetooth/athbt.c new file +10 -0
+
+static int __init athbt_init(void)
+{
+	int err;
+
+	BT_INFO("Atheros firmware driver ver %s", DRV_VERSION);
+
+	err = usb_register(&athbt_driver);
+	if (err < 0)
+		BT_INFO("Failed to register USB driver");

Pointless. Just to return usb_register().

drivers/bluetooth/athbt.c line 203

Quoted 7 lines
drivers/bluetooth/athbt.c new file +7 -0
+
+	return err;
+}
+
+static void __exit athbt_exit(void)
+{
+	BT_INFO("athbt_exit\n");

Don't even bother with that info here.

firmware/atherosbt.bin

Quoted 9 lines
drivers/bluetooth/athbt.c new file +5 -0
+	usb_deregister(&athbt_driver);
+}
+
+module_init(athbt_init);
+module_exit(athbt_exit);
firmware/atherosbt.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4a5ffb8de898fab1595662742f287493689e2b3b
GIT binary patch

What license is on this firmware. We can't include it into the Linux kernel unless it us under GPL. If it is a binary license and has a proper distribution license then it can go to the linux-firmware tree once you fixed the name of it of course.

Regards

Marcel

#2 lore raw
Quoted 7 lines · Marcel Holtmann

firmware/atherosbt.bin

Quoted 4 lines
firmware/atherosbt.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4a5ffb8de898fab1595662742f287493689e2b3b
GIT binary patch

What license is on this firmware. We can't include it into the Linux kernel unless it us under GPL.

Actually GPL-compatible.

Quoted 3 lines

If it is a binary license and has a
proper distribution license then it can go to the linux-firmware tree once you fixed the name of it of course.

Vikram, you can use this firmware if you are not opening up the firmware:

http://kernel.org/pub/linux/kernel/people/mcgrof/firmware/LICENCE.atheros_firmware

Our legal department has given us the blessing to use this for our firmware for 802.11 when we don't open it up and release it under a GPL-compatible license.

Luis

maintainer
#3 lore raw

Hi Luis,

Quoted 9 lines
Quoted 7 lines

firmware/atherosbt.bin

Quoted 4 lines
firmware/atherosbt.bin new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..4a5ffb8de898fab1595662742f287493689e2b3b
GIT binary patch

What license is on this firmware. We can't include it into the Linux kernel unless it us under GPL.

Actually GPL-compatible.

true.

Quoted 10 lines
Quoted 3 lines

If it is a binary license and has a
proper distribution license then it can go to the linux-firmware tree once you fixed the name of it of course.

Vikram, you can use this firmware if you are not opening up the firmware:

http://kernel.org/pub/linux/kernel/people/mcgrof/firmware/LICENCE.atheros_firmware

Our legal department has given us the blessing to use this for our firmware for 802.11 when we don't open it up and release it under a GPL-compatible license.

I am more than happy to work on getting a fully open source and GPL compatible firmware into the kernel, but until then, this needs to be send to the linux-firmware tree with a similar LICENSE file.

Regards

Marcel

#4 lore raw
In reply to Marcel Holtmann
Quoted 10 lines · Marcel Holtmann

drivers/bluetooth/athbt.c line 39

Quoted 6 lines
drivers/bluetooth/athbt.c new file +6 -0
+MODULE_AUTHOR("Atheros Communications");
+MODULE_DESCRIPTION("Atheros AR3011 firmware driver");
+MODULE_VERSION(DRV_VERSION);
+MODULE_SUPPORTED_DEVICE("Atheros AR3011 chipset");
+MODULE_LICENSE("GPL");
+MODULE_FIRMWARE("atherosbt.bin");

The
module author needs to have a contact information and not just the company name. Read it as who maintains this driver.

This is probably just following what we have on ath9k / ath9k_common / ath9k_hw / ath modules which so far no one has asked us to change:

MODULE_AUTHOR("Atheros Communications"); MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards"); MODULE_LICENSE("Dual BSD/GPL");

Using one contact point for ath9k stuff doesn't work for us as we have a group and for that the MAINTAINERS file seems just suitable. Plus -- some module authors are sometimes not the current maintainers so the MDOULE_AUTHOR really doesn't mean much. Wouldn't updating the MAINTAINERS file accordingly be better?

Also Vikram -- why not just ISC license the files as we do with ath9k ? Then also use:

MODULE_LICENSE("Dual BSD/GPL");

This would be more consistant with what we do with our other upstream Atheros modules.

Luis

maintainer
#5 lore raw

Hi Luis,

Quoted 20 lines · Marcel Holtmann
Quoted 10 lines

drivers/bluetooth/athbt.c line 39

Quoted 6 lines
drivers/bluetooth/athbt.c new file +6 -0
+MODULE_AUTHOR("Atheros Communications");
+MODULE_DESCRIPTION("Atheros AR3011 firmware driver");
+MODULE_VERSION(DRV_VERSION);
+MODULE_SUPPORTED_DEVICE("Atheros AR3011 chipset");
+MODULE_LICENSE("GPL");
+MODULE_FIRMWARE("atherosbt.bin");

The
module author needs to have a contact information and not just the company name. Read it as who maintains this driver.

This is probably just following what we have on ath9k / ath9k_common / ath9k_hw / ath modules which so far no one has asked us to change:

MODULE_AUTHOR("Atheros Communications"); MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards"); MODULE_LICENSE("Dual BSD/GPL");

Quoted 4 lines

Using one contact point for ath9k stuff doesn't work for us as we have a group and for that the MAINTAINERS file seems just suitable. Plus -- some module authors are sometimes not the current maintainers so the MDOULE_AUTHOR really doesn't mean much. Wouldn't updating the MAINTAINERS file accordingly be better?

my personal advise for the long term would be to create a mailing list sort of contact address. As I said, the MODULE_AUTHOR is meant to reflect the current maintainer. It is of course not a hard requirement, but it is the intention. If you don't have that right now, we go with this, but think about establishing something like it.

Quoted 7 lines

Also Vikram -- why not just ISC license the files as we do with ath9k ? Then also use:

MODULE_LICENSE("Dual BSD/GPL");

This would be more consistant with what we do with our other upstream Atheros modules.

Since this is just a firmware loading driver, I prefer if you just keep it GPL only. It is not worth going into too much details. Especially since it looks inspired (nicely phrased) from bcm203x.c driver.

Regards

Marcel

#6 lore raw
Quoted 5 lines · Marcel Holtmann
Quoted 5 lines

Also Vikram -- why not just ISC license the files as we do with ath9k ? Then also use:

MODULE_LICENSE("Dual BSD/GPL");

Quoted 8 lines
Quoted 3 lines

This would be more consistant with what we do with our other upstream Atheros modules.

Since this is just a firmware loading driver, I prefer if you just keep it GPL only. It is not worth going into too much details. Especially since it looks inspired (nicely phrased) from bcm203x.c driver.

In the interests of supporting the device from *BSD operating systems it'd be nice if it was clear that the firmware itself could be included under a BSD licence.

#7 lore raw
Quoted 10 lines · David Sainty
Quoted 9 lines · Marcel Holtmann
Quoted 8 lines

Also Vikram -- why not just ISC license the files as we do with ath9k ? Then also use:

MODULE_LICENSE("Dual BSD/GPL");

This would be more consistant with what we do with our other upstream Atheros modules.

Quoted 8 lines
Quoted 4 lines

Since this is just a firmware loading driver, I prefer if you just keep it GPL only. It is not worth going into too much details. Especially since it looks inspired (nicely phrased) from bcm203x.c driver.

In the interests of supporting the device from *BSD operating systems it'd be nice if it was clear that the firmware itself could be included under a BSD licence.

Did you read the license? It allow free redistribution.

Luis