Skip to content

Commit c7741d1

Browse files
committed
Bluetooth: Perform a power cycle when receiving hardware error event
When receiving a HCI Hardware Error event, the controller should be assumed to be non-functional until issuing a HCI Reset command. The Bluetooth hardware errors are vendor specific and so add a new hdev->hw_error callback that drivers can provide to run extra code to handle the hardware error. After completing the vendor specific error handling perform a full reset of the Bluetooth stack by closing and re-opening the transport. Based-on-patch-by: Johan Hedberg <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Johan Hedberg <[email protected]>
1 parent 5c91249 commit c7741d1

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ struct hci_dev {
232232
__u16 conn_info_min_age;
233233
__u16 conn_info_max_age;
234234
__u8 ssp_debug_mode;
235+
__u8 hw_error_code;
235236
__u32 clock;
236237

237238
__u16 devid_source;
@@ -293,6 +294,7 @@ struct hci_dev {
293294

294295
struct work_struct power_on;
295296
struct delayed_work power_off;
297+
struct work_struct error_reset;
296298

297299
__u16 discov_timeout;
298300
struct delayed_work discov_off;
@@ -369,6 +371,7 @@ struct hci_dev {
369371
int (*setup)(struct hci_dev *hdev);
370372
int (*send)(struct hci_dev *hdev, struct sk_buff *skb);
371373
void (*notify)(struct hci_dev *hdev, unsigned int evt);
374+
void (*hw_error)(struct hci_dev *hdev, u8 code);
372375
int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
373376
};
374377

net/bluetooth/hci_core.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,26 @@ static void hci_power_off(struct work_struct *work)
21512151
smp_unregister(hdev);
21522152
}
21532153

2154+
static void hci_error_reset(struct work_struct *work)
2155+
{
2156+
struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset);
2157+
2158+
BT_DBG("%s", hdev->name);
2159+
2160+
if (hdev->hw_error)
2161+
hdev->hw_error(hdev, hdev->hw_error_code);
2162+
else
2163+
BT_ERR("%s hardware error 0x%2.2x", hdev->name,
2164+
hdev->hw_error_code);
2165+
2166+
if (hci_dev_do_close(hdev))
2167+
return;
2168+
2169+
smp_unregister(hdev);
2170+
2171+
hci_dev_do_open(hdev);
2172+
}
2173+
21542174
static void hci_discov_off(struct work_struct *work)
21552175
{
21562176
struct hci_dev *hdev;
@@ -2943,6 +2963,7 @@ struct hci_dev *hci_alloc_dev(void)
29432963
INIT_WORK(&hdev->cmd_work, hci_cmd_work);
29442964
INIT_WORK(&hdev->tx_work, hci_tx_work);
29452965
INIT_WORK(&hdev->power_on, hci_power_on);
2966+
INIT_WORK(&hdev->error_reset, hci_error_reset);
29462967

29472968
INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
29482969
INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off);

net/bluetooth/hci_event.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3100,7 +3100,9 @@ static void hci_hardware_error_evt(struct hci_dev *hdev, struct sk_buff *skb)
31003100
{
31013101
struct hci_ev_hardware_error *ev = (void *) skb->data;
31023102

3103-
BT_ERR("%s hardware error 0x%2.2x", hdev->name, ev->code);
3103+
hdev->hw_error_code = ev->code;
3104+
3105+
queue_work(hdev->req_workqueue, &hdev->error_reset);
31043106
}
31053107

31063108
static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)

0 commit comments

Comments
 (0)