Skip to contentSkip to conversation

Bluetooth: handle device reset event

PATCH In review Tomas Winkler 2 participants 4 messages Mar 18, 2010 – Mar 21, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Bluetooth: handle device reset event

From: Gregory Paskar <[email protected]>

A Bluetooth device experiencing hardware failure may issue a HARDWARE_ERROR hci event. The reaction to this event is device reset flow implemented in following sequence.

1. Notify: HCI_DEV_DOWN
2. Reinitialize internal structures.
3. Call driver flush function
4. Send HCI reset request to the device.
5. Send HCI init sequence reset to the device.
6. Notify HCI_DEV_UP.

---
V2:
1. Fix email typo
2. Fix style issues
V3:
1. align with naming convention hw_err_work -> work_hw_err
2. use per controller workqueue

 include/net/bluetooth/hci.h      |    5 ++++
 include/net/bluetooth/hci_core.h |    2 +
 net/bluetooth/hci_core.c         |   47 +++++++++++++++++++++++++++++++++++++-
 net/bluetooth/hci_event.c        |    3 ++
 4 files changed, 56 insertions(+), 1 deletions(-)
include/net/bluetooth/hci.h +5 -0
index fc0c502..3f986e7 100644
@@ -695,6 +695,11 @@ struct hci_ev_cmd_status {
 	__le16   opcode;
 } __attribute__ ((packed));
 
+#define HCI_EV_HARDWARE_ERROR 0x10
+struct hci_ev_hw_error {
+	__u8     hw_code;
+} __attribute__ ((packed));
+
 #define HCI_EV_ROLE_CHANGE		0x12
 struct hci_ev_role_change {
 	__u8     status;
include/net/bluetooth/hci_core.h +2 -0
index e17849e..1c9601d 100644
@@ -113,6 +113,8 @@ struct hci_dev {
 	struct tasklet_struct	rx_task;
 	struct tasklet_struct	tx_task;
 
+	struct work_struct	work_hw_err;
+
 	struct sk_buff_head	rx_q;
 	struct sk_buff_head	raw_q;
 	struct sk_buff_head	cmd_q;
net/bluetooth/hci_core.c +46 -1

59 lines not on this page · raw message

net/bluetooth/hci_event.c +3 -0
index 6c57fc7..6bcf3e9 100644
@@ -1955,6 +1955,9 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
 	case HCI_EV_REMOTE_HOST_FEATURES:
 		hci_remote_host_features_evt(hdev, skb);
 		break;
+	case HCI_EV_HARDWARE_ERROR:
+		queue_work(hdev->workqueue, &hdev->work_hw_err);
+		break;
 
 	default:
 		BT_DBG("%s event 0x%x", hdev->name, event);
Signature · 9 lines
1.6.6.1

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
maintainer
#1 lore raw

Hi Tomas,

Quoted 35 lines

From: Gregory Paskar <[email protected]>

A Bluetooth device experiencing hardware failure may issue a HARDWARE_ERROR hci event. The reaction to this event is device reset flow implemented in following sequence.

1. Notify: HCI_DEV_DOWN
2. Reinitialize internal structures.
3. Call driver flush function
4. Send HCI reset request to the device.
5. Send HCI init sequence reset to the device.
6. Notify HCI_DEV_UP.

---
V2:
1. Fix email typo
2. Fix style issues
V3:
1. align with naming convention hw_err_work -> work_hw_err
2. use per controller workqueue

 include/net/bluetooth/hci.h      |    5 ++++
 include/net/bluetooth/hci_core.h |    2 +
 net/bluetooth/hci_core.c         |   47 +++++++++++++++++++++++++++++++++++++-
 net/bluetooth/hci_event.c        |    3 ++
 4 files changed, 56 insertions(+), 1 deletions(-)
include/net/bluetooth/hci.h +0 -0
index fc0c502..3f986e7 100644

include/net/bluetooth/hci.h struct hci_ev_cmd_status { · line 702

Quoted 8 lines
include/net/bluetooth/hci.h +5 -0
@@ -695,6 +695,11 @@ struct hci_ev_cmd_status {
 	__le16   opcode;
 } __attribute__ ((packed));
 
+#define HCI_EV_HARDWARE_ERROR 0x10
+struct hci_ev_hw_error {
+	__u8     hw_code;
+} __attribute__ ((packed));
+

So the rule is that the HCI_EV and hci_ev struct names are matching up. It should be matching what we have in the library (not a hard requirement though):

#define EVT_HARDWARE_ERROR 0x10

typedef struct {
        uint8_t         code;
} __attribute__ ((packed)) evt_hardware_error;

So just spell it out hardware_error. This means it is also code and not hw_code inside the struct.

include/net/bluetooth/hci_core.h struct hci_dev { · line 117

Quoted 13 lines
include/net/bluetooth/hci.h +0 -0
 #define HCI_EV_ROLE_CHANGE		0x12
 struct hci_ev_role_change {
 	__u8     status;
include/net/bluetooth/hci_core.h +2 -0
index e17849e..1c9601d 100644
@@ -113,6 +113,8 @@ struct hci_dev {
 	struct tasklet_struct	rx_task;
 	struct tasklet_struct	tx_task;
 
+	struct work_struct	work_hw_err;
+

I would prefer if you just call it reset_work actually. I know that we are acting on a hardware error, but the action that we are performing is actually a full reset. It might be useful for other parts of the stack as well.

Quoted 46 lines
include/net/bluetooth/hci_core.h +0 -0
 	struct sk_buff_head	rx_q;
 	struct sk_buff_head	raw_q;
 	struct sk_buff_head	cmd_q;
net/bluetooth/hci_core.c +35 -0
index 8b4baac..c5a43e3 100644
@@ -839,6 +839,51 @@ static int hci_rfkill_set_block(void *data, bool blocked)
 	return 0;
 }
 
+static void hci_device_hw_error(struct hci_dev *hdev)
+{
+	hci_req_lock(hdev);
+
+	/* notify: going down */
+	clear_bit(HCI_UP, &hdev->flags);
+	hci_notify(hdev, HCI_DEV_DOWN);
+
+	tasklet_disable(&hdev->tx_task);
+	skb_queue_purge(&hdev->rx_q);
+	skb_queue_purge(&hdev->cmd_q);
+
+	hci_dev_lock_bh(hdev);
+	inquiry_cache_flush(hdev);
+	hci_conn_hash_flush(hdev);
+	hci_dev_unlock_bh(hdev);
+
+	if (hdev->flush)
+		hdev->flush(hdev);
+
+	/* reset device */
+	atomic_set(&hdev->cmd_cnt, 1);
+	hdev->acl_cnt = 0;
+	hdev->sco_cnt = 0;
+	hci_reset_req(hdev, 0);
+
+	/* init device */
+	atomic_set(&hdev->cmd_cnt, 1);
+	hci_init_req(hdev, 0);
+
+	tasklet_enable(&hdev->tx_task);
+
+	/* notify: going back up */
+	set_bit(HCI_UP, &hdev->flags);
+	hci_notify(hdev, HCI_DEV_UP);

net/bluetooth/hci_core.c static int hci_rfkill_set_block(void *data, bool blocked) · line 886

Quoted 10 lines
net/bluetooth/hci_core.c +10 -0
+
+	hci_req_unlock(hdev);
+}
+
+static void hci_work_hw_err(struct work_struct *ws)
+{
+	struct hci_dev *hdev = container_of(ws, struct hci_dev, work_hw_err);
+	hci_device_hw_error(hdev);
+}
+

Please name it hci_reset_work to match it properly. And then put everything in the same function. No need to really split it here.

What I would prefer if we can split out the open/close code and re-use it it here.

net/bluetooth/hci_core.c int hci_register_dev(struct hci_dev *hdev) · line 959

Quoted 12 lines
net/bluetooth/hci_core.c +1 -1
 static const struct rfkill_ops hci_rfkill_ops = {
 	.set_block = hci_rfkill_set_block,
 };
@@ -908,7 +953,7 @@ int hci_register_dev(struct hci_dev *hdev)
 	tasklet_init(&hdev->cmd_task, hci_cmd_task,(unsigned long) hdev);
 	tasklet_init(&hdev->rx_task, hci_rx_task, (unsigned long) hdev);
 	tasklet_init(&hdev->tx_task, hci_tx_task, (unsigned long) hdev);
-
+	INIT_WORK(&hdev->work_hw_err, hci_work_hw_err);
 	skb_queue_head_init(&hdev->rx_q);
 	skb_queue_head_init(&hdev->cmd_q);
 	skb_queue_head_init(&hdev->raw_q);

I am missing the cancel_work_sync() call in hci_unregister_dev().

Quoted 5 lines
net/bluetooth/hci_event.c +0 -0
index 6c57fc7..6bcf3e9 100644

net/bluetooth/hci_event.c void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) · line 1963

Quoted 9 lines
net/bluetooth/hci_event.c +3 -0
@@ -1955,6 +1955,9 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
 	case HCI_EV_REMOTE_HOST_FEATURES:
 		hci_remote_host_features_evt(hdev, skb);
 		break;
+	case HCI_EV_HARDWARE_ERROR:
+		queue_work(hdev->workqueue, &hdev->work_hw_err);
+		break;
 
 	default:
 		BT_DBG("%s event 0x%x", hdev->name, event);

Since it seems you have the only hardware where this can be re-produced, it would be great if you include some hcidump -X -V extracts inside the commit message.

Regards

Marcel

#2 lore raw

DQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlL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lmaWNpYWxseSB0cmlnZ2VyaW5nIHRoZSBlcnJvci4g RG9lcyBoY2kgZHVtcCBoYXMgYW55IHZhbHVlIGluIHRoYXQgY2FzZT8NCg0KVGhhbmtzDQpUb21h cw0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tCkludGVsIElzcmFlbCAoNzQpIExpbWl0ZWQKClRoaXMgZS1tYWlsIGFu ZCBhbnkgYXR0YWNobWVudHMgbWF5IGNvbnRhaW4gY29uZmlkZW50aWFsIG1hdGVyaWFsIGZvcgp0 aGUgc29sZSB1c2Ugb2YgdGhlIGludGVuZGVkIHJlY2lwaWVudChzKS4gQW55IHJldmlldyBvciBk aXN0cmlidXRpb24KYnkgb3RoZXJzIGlzIHN0cmljdGx5IHByb2hpYml0ZWQuIElmIHlvdSBhcmUg bm90IHRoZSBpbnRlbmRlZApyZWNpcGllbnQsIHBsZWFzZSBjb250YWN0IHRoZSBzZW5kZXIgYW5k IGRlbGV0ZSBhbGwgY29waWVzLgo=

maintainer
#3 lore raw

Hi Tomas,

Quoted 175 lines
Quoted 167 lines
Quoted 22 lines

A Bluetooth device experiencing hardware failure may issue a HARDWARE_ERROR hci event. The reaction to this event is device reset flow implemented in following sequence.

1. Notify: HCI_DEV_DOWN
2. Reinitialize internal structures.
3. Call driver flush function
4. Send HCI reset request to the device.
5. Send HCI init sequence reset to the device.
6. Notify HCI_DEV_UP.

---
V2:
1. Fix email typo
2. Fix style issues
V3:
1. align with naming convention hw_err_work -> work_hw_err
2. use per controller workqueue

Quoted 3 lines
 include/net/bluetooth/hci.h      |    5 ++++
 include/net/bluetooth/hci_core.h |    2 +
 net/bluetooth/hci_core.c         |   47

+++++++++++++++++++++++++++++++++++++-

Quoted 8 lines
 net/bluetooth/hci_event.c        |    3 ++
 4 files changed, 56 insertions(+), 1 deletions(-)
include/net/bluetooth/hci.h +0 -0
index fc0c502..3f986e7 100644

include/net/bluetooth/hci.h struct hci_ev_cmd_status { · line 702

Quoted 8 lines
include/net/bluetooth/hci.h +5 -0
@@ -695,6 +695,11 @@ struct hci_ev_cmd_status {
 	__le16   opcode;
 } __attribute__ ((packed));
 
+#define HCI_EV_HARDWARE_ERROR 0x10
+struct hci_ev_hw_error {
+	__u8     hw_code;
+} __attribute__ ((packed));
+

So the rule is that the HCI_EV and hci_ev struct names are matching up. It should be matching what we have in the library (not a hard requirement though):

#define EVT_HARDWARE_ERROR 0x10

typedef struct {
        uint8_t         code;
} __attribute__ ((packed)) evt_hardware_error;

So just spell it out hardware_error. This means it is also code and not hw_code inside the struct.

Review

Quoted 4 lines
include/net/bluetooth/hci.h +0 -0
 #define HCI_EV_ROLE_CHANGE		0x12
 struct hci_ev_role_change {
 	__u8     status;
(quoted diff) +0 -0

b/include/net/bluetooth/hci_core.h

include/net/bluetooth/hci_core.h struct hci_dev { · line 117

Quoted 9 lines

index e17849e..1c9601d 100644

include/net/bluetooth/hci_core.h +2 -0
@@ -113,6 +113,8 @@ struct hci_dev {
 	struct tasklet_struct	rx_task;
 	struct tasklet_struct	tx_task;
 
+	struct work_struct	work_hw_err;
+

I would prefer if you just call it reset_work actually. I know that we are acting on a hardware error, but the action that we are performing is actually a full reset. It might be useful for other parts of the stack as well.

net/bluetooth/hci_core.c static int hci_rfkill_set_block(void *data, bool

Quoted 8 lines
include/net/bluetooth/hci_core.h +0 -0
 	struct sk_buff_head	rx_q;
 	struct sk_buff_head	raw_q;
 	struct sk_buff_head	cmd_q;
net/bluetooth/hci_core.c +0 -0
index 8b4baac..c5a43e3 100644
@@ -839,6 +839,51 @@ static int hci_rfkill_set_block(void *data, bool

blocked)

Quoted 38 lines
net/bluetooth/hci_core.c +35 -0
 	return 0;
 }
 
+static void hci_device_hw_error(struct hci_dev *hdev)
+{
+	hci_req_lock(hdev);
+
+	/* notify: going down */
+	clear_bit(HCI_UP, &hdev->flags);
+	hci_notify(hdev, HCI_DEV_DOWN);
+
+	tasklet_disable(&hdev->tx_task);
+	skb_queue_purge(&hdev->rx_q);
+	skb_queue_purge(&hdev->cmd_q);
+
+	hci_dev_lock_bh(hdev);
+	inquiry_cache_flush(hdev);
+	hci_conn_hash_flush(hdev);
+	hci_dev_unlock_bh(hdev);
+
+	if (hdev->flush)
+		hdev->flush(hdev);
+
+	/* reset device */
+	atomic_set(&hdev->cmd_cnt, 1);
+	hdev->acl_cnt = 0;
+	hdev->sco_cnt = 0;
+	hci_reset_req(hdev, 0);
+
+	/* init device */
+	atomic_set(&hdev->cmd_cnt, 1);
+	hci_init_req(hdev, 0);
+
+	tasklet_enable(&hdev->tx_task);
+
+	/* notify: going back up */
+	set_bit(HCI_UP, &hdev->flags);
+	hci_notify(hdev, HCI_DEV_UP);

net/bluetooth/hci_core.c static int hci_rfkill_set_block(void *data, bool blocked) · line 886

Quoted 10 lines
net/bluetooth/hci_core.c +10 -0
+
+	hci_req_unlock(hdev);
+}
+
+static void hci_work_hw_err(struct work_struct *ws)
+{
+	struct hci_dev *hdev = container_of(ws, struct hci_dev, work_hw_err);
+	hci_device_hw_error(hdev);
+}
+

Please name it hci_reset_work to match it properly. And then put everything in the same function. No need to really split it here.

What I would prefer if we can split out the open/close code and re-use it it here.

net/bluetooth/hci_core.c int hci_register_dev(struct hci_dev *hdev) · line 959

Quoted 12 lines
net/bluetooth/hci_core.c +1 -1
 static const struct rfkill_ops hci_rfkill_ops = {
 	.set_block = hci_rfkill_set_block,
 };
@@ -908,7 +953,7 @@ int hci_register_dev(struct hci_dev *hdev)
 	tasklet_init(&hdev->cmd_task, hci_cmd_task,(unsigned long) hdev);
 	tasklet_init(&hdev->rx_task, hci_rx_task, (unsigned long) hdev);
 	tasklet_init(&hdev->tx_task, hci_tx_task, (unsigned long) hdev);
-
+	INIT_WORK(&hdev->work_hw_err, hci_work_hw_err);
 	skb_queue_head_init(&hdev->rx_q);
 	skb_queue_head_init(&hdev->cmd_q);
 	skb_queue_head_init(&hdev->raw_q);

I am missing the cancel_work_sync() call in hci_unregister_dev().

net/bluetooth/hci_event.c void hci_event_packet(struct hci_dev *hdev, struct

Quoted 5 lines
net/bluetooth/hci_event.c +0 -0
index 6c57fc7..6bcf3e9 100644
@@ -1955,6 +1955,9 @@ void hci_event_packet(struct hci_dev *hdev, struct

sk_buff *skb)

Quoted 7 lines
net/bluetooth/hci_event.c +3 -0
 	case HCI_EV_REMOTE_HOST_FEATURES:
 		hci_remote_host_features_evt(hdev, skb);
 		break;
+	case HCI_EV_HARDWARE_ERROR:
+		queue_work(hdev->workqueue, &hdev->work_hw_err);
+		break;
 
Quoted 7 lines

net/bluetooth/hci_event.c void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) · line 1963

Quoted 2 lines
net/bluetooth/hci_event.c +0 -0
 	default:
 		BT_DBG("%s event 0x%x", hdev->name, event);

Since it seems you have the only hardware where this can be re-produced, it would be great if you include some hcidump -X -V extracts inside the commit message.

Quoted 1 line

What exactly are you looking for? I'm testing it by artificially triggering the error. Does hci dump has any value in that case?

you mentioned that you see hardware error events on real hardware. I like to see the hcidump from that actually.

And btw. the bluetooth-testing tree now contains the patches to push event processing into a workqueue. They have limit testing so far, but seems to work fine. Someone still needs to do some performance testing before we can clear that patch for upstream. However it should make your reset logic patch a lot simpler.

Regards

Marcel