Bluetooth: btintel_pcie: Fix potential race condition in firmware download
Subsystems (2)
PATCH v2 1/2 Bluetooth: btintel_pcie: Fix potential race condition in firmware download
During firmware download, if an error occurs, interrupts must be disabled, synchronized, and re-enabled before retrying the download. This change ensures proper interrupt handling to prevent race conditions.
--- drivers/bluetooth/btintel_pcie.c | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
drivers/bluetooth/btintel_pcie.c +31 -2
@@ -2028,6 +2028,28 @@ static void btintel_pcie_release_hdev(struct btintel_pcie_data *data) data->hdev =NULL ; } +static void btintel_pcie_disable_interrupts (struct btintel_pcie_data *data) +{ +spin_lock (&data->irq_lock); +btintel_pcie_wr_reg32 (data,BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK , data->fh_init_mask); +btintel_pcie_wr_reg32 (data,BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK , data->hw_init_mask); +spin_unlock (&data->irq_lock); +} + +static void btintel_pcie_enable_interrupts (struct btintel_pcie_data *data) +{ +spin_lock (&data->irq_lock); +btintel_pcie_wr_reg32 (data,BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK , ~data->fh_init_mask); +btintel_pcie_wr_reg32 (data,BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK , ~data->hw_init_mask); +spin_unlock (&data->irq_lock); +} + +static void btintel_pcie_synchronize_irqs (struct btintel_pcie_data *data) +{ +for (int i =0 ; i < data->alloc_vecs; i++) +synchronize_irq (data->msix_entries[i].vector); +} +static int btintel_pcie_setup_internal (struct hci_dev *hdev) {struct btintel_pcie_data *data =hci_get_drvdata (hdev);
@@ -2147,6 +2169,8 @@ static int btintel_pcie_setup(struct hci_dev *hdev)bt_dev_err (hdev,"Firmware download retry count: %d" , fw_dl_retry);btintel_pcie_dump_debug_registers (hdev); +btintel_pcie_disable_interrupts (data); +btintel_pcie_synchronize_irqs (data); err =btintel_pcie_reset_bt (data);if (err) {bt_dev_err (hdev,"Failed to do shr reset: %d" , err);
@@ -2154,6 +2178,7 @@ static int btintel_pcie_setup(struct hci_dev *hdev) }usleep_range (10000 ,12000 );btintel_pcie_reset_ia (data); +btintel_pcie_enable_interrupts (data);btintel_pcie_config_msix (data); err =btintel_pcie_enable_bt (data);if (err) {
@@ -2286,6 +2311,12 @@ static void btintel_pcie_remove(struct pci_dev *pdev) data =pci_get_drvdata (pdev); +btintel_pcie_disable_interrupts (data); + +btintel_pcie_synchronize_irqs (data); + +flush_workqueue (data->workqueue); +btintel_pcie_reset_bt (data);for (int i =0 ; i < data->alloc_vecs; i++) {struct msix_entry *msix_entry;
@@ -2298,8 +2329,6 @@ static void btintel_pcie_remove(struct pci_dev *pdev)btintel_pcie_release_hdev (data); -flush_work (&data->rx_work); -destroy_workqueue (data->workqueue);btintel_pcie_free (data);
Signature · 1 line
2.43.0
PATCH v2 2/2 Bluetooth: btintel_pcie: Support Function level reset
From: Chandrashekar Devegowda <[email protected]>
Support function level reset (flr) on hardware exception to recover controller. Driver also implements the back-off time of 5 seconds and the maximum number of retries are limited to 5 before giving up.
--- drivers/bluetooth/btintel_pcie.c | 234 ++++++++++++++++++++++++++++++- drivers/bluetooth/btintel_pcie.h | 4 +- 2 files changed, 235 insertions(+), 3 deletions(-)
drivers/bluetooth/btintel_pcie.c +232 -2
@@ -41,6 +41,13 @@ static const struct pci_device_id btintel_pcie_table[] = { };MODULE_DEVICE_TABLE (pci, btintel_pcie_table); +struct btintel_pcie_dev_restart_data { +struct list_head list; +u8 restart_count; +time64_t last_error; +char name[]; +}; +/* Intel PCIe uses 4 bytes of HCI type instead of 1 byte BT SIG HCI type */ #define BTINTEL_PCIE_HCI_TYPE_LEN 4#define BTINTEL_PCIE_HCI_CMD_PKT 0x00000001
@@ -62,6 +69,9 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);#define BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER 0x17A2#define BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT 0x1E61 +#define BTINTEL_PCIE_RESET_OK_TIME_SECS 5 +#define BTINTEL_PCIE_FLR_RESET_MAX_RETRY 5 +/* Alive interrupt context */ enum {BTINTEL_PCIE_ROM ,
@@ -99,6 +109,14 @@ struct btintel_pcie_dbgc_ctxt {struct btintel_pcie_dbgc_ctxt_buf bufs[BTINTEL_PCIE_DBGC_BUFFER_COUNT ]; }; +struct btintel_pcie_removal { +struct pci_dev *pdev; +struct work_struct work; +}; + +static LIST_HEAD (btintel_pcie_restart_data_list); +static DEFINE_SPINLOCK (btintel_pcie_restart_data_lock); +/* This function initializes the memory for DBGC buffers and formats the * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and * size as the payload
@@ -1927,6 +1945,9 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev,u32 type;u32 old_ctxt; +if (test_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags)) +return -ENODEV ; +/* Due to the fw limitation, the type header of the packet should be * 4 bytes unlike 1 byte for UART. In UART, the firmware can read * the first byte to get the packet type and redirect the rest of data
@@ -2187,9 +2208,204 @@ static int btintel_pcie_setup(struct hci_dev *hdev) }btintel_pcie_start_rx (data); } + +if (!err) +set_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags);return err; } +static struct btintel_pcie_dev_restart_data *btintel_pcie_get_restart_data (struct pci_dev *pdev, +struct device *dev) +{ +struct btintel_pcie_dev_restart_data *tmp, *data =NULL ; +const char *name =pci_name (pdev); +struct hci_dev *hdev =to_hci_dev (dev); + +spin_lock (&btintel_pcie_restart_data_lock); +list_for_each_entry (tmp, &btintel_pcie_restart_data_list, list) { +if (strcmp (tmp->name, name)) +continue ; + data = tmp; +break ; + } +spin_unlock (&btintel_pcie_restart_data_lock); + +if (data) { +bt_dev_dbg (hdev,"Found restart data for BDF:%s" , data->name); +return data; + } + +/* First time allocate */ + data =kzalloc (struct_size (data, name,strlen (name) +1 ),GFP_ATOMIC ); +if (!data) +return NULL ; + +strscpy_pad (data->name, name,strlen (name) +1 ); +spin_lock (&btintel_pcie_restart_data_lock); +list_add_tail (&data->list, &btintel_pcie_restart_data_list); +spin_unlock (&btintel_pcie_restart_data_lock); + +return data; +} + +static void btintel_pcie_free_restart_list (void ) +{ +struct btintel_pcie_dev_restart_data *tmp; + +while ((tmp =list_first_entry_or_null (&btintel_pcie_restart_data_list, +typeof (*tmp), list))) { +list_del (&tmp->list); +kfree (tmp); + } +} + +static void btintel_pcie_inc_restart_count (struct pci_dev *pdev, +struct device *dev) +{ +struct btintel_pcie_dev_restart_data *data; +struct hci_dev *hdev =to_hci_dev (dev); +time64_t retry_window; + + data =btintel_pcie_get_restart_data (pdev, dev); +if (!data) +return ; + + retry_window =ktime_get_boottime_seconds () - data->last_error; +if (data->restart_count ==0 ) { +/* First iteration initialise the time and counter */ + data->last_error =ktime_get_boottime_seconds (); + data->restart_count++; +bt_dev_dbg (hdev,"First iteration initialise. last_error:%lld seconds restart_count:%d" , + data->last_error, data->restart_count); + }else if (retry_window <BTINTEL_PCIE_RESET_OK_TIME_SECS && + data->restart_count <=BTINTEL_PCIE_FLR_RESET_MAX_RETRY ) { +/* FLR triggered still within the Max retry time so +* increment the counter +*/ + data->restart_count++; +bt_dev_dbg (hdev,"flr triggered still within the max retry time so increment the restart_count:%d" , + data->restart_count); + }else if (retry_window >BTINTEL_PCIE_RESET_OK_TIME_SECS ) { +/* FLR triggered out of the retry window so reset */ +bt_dev_dbg (hdev,"flr triggered out of retry window. last_error:%lld seconds restart_count:%d" , + data->last_error, data->restart_count); + data->last_error =0 ; + data->restart_count =0 ; + } +} + +static int btintel_pcie_setup_hdev (struct btintel_pcie_data *data); + +static void btintel_pcie_removal_work (struct work_struct *wk) +{ +struct btintel_pcie_removal *removal = + container_of(wk, struct btintel_pcie_removal, work); +struct pci_dev *pdev = removal->pdev; +struct btintel_pcie_data *data; +int err; + +pci_lock_rescan_remove (); + +if (!pdev->bus) + goto error; + + data =pci_get_drvdata (pdev); + +btintel_pcie_disable_interrupts (data); +btintel_pcie_synchronize_irqs (data); +flush_workqueue (data->workqueue); + +bt_dev_dbg (data->hdev,"Release bluetooth interface" ); +btintel_pcie_release_hdev (data); + + err =pci_reset_function (pdev); +if (err) { +BT_ERR ("Failed resetting the pcie device (%d)" , err); + goto error; + } + +btintel_pcie_enable_interrupts (data); +btintel_pcie_config_msix (data); + + err =btintel_pcie_enable_bt (data); +if (err) { +BT_ERR ("Failed to enable bluetooth hardware after reset (%d)" , + err); + goto error; + } + +btintel_pcie_reset_ia (data); +btintel_pcie_start_rx (data); + data->flags =0 ; + + err =btintel_pcie_setup_hdev (data); +if (err) { +BT_ERR ("Failed registering hdev (%d)" , err); + goto error; + } +error: +pci_dev_put (pdev); +pci_unlock_rescan_remove (); +kfree (removal); +} + +static void btintel_pcie_reset (struct hci_dev *hdev) +{ +struct btintel_pcie_removal *removal; +struct btintel_pcie_data *data; + + data =hci_get_drvdata (hdev); + +if (!test_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags)) +return ; + + removal =kzalloc (sizeof (*removal),GFP_ATOMIC ); +if (!removal) +return ; + +flush_work (&data->rx_work); +flush_work (&hdev->dump.dump_rx); + + removal->pdev = data->pdev; +INIT_WORK (&removal->work, btintel_pcie_removal_work); +pci_dev_get (removal->pdev); +schedule_work (&removal->work); +} + +static void btintel_pcie_hw_error (struct hci_dev *hdev,u8 code) +{ +struct btintel_pcie_dev_restart_data *data; +struct btintel_pcie_data *dev_data =hci_get_drvdata (hdev); +struct pci_dev *pdev = dev_data->pdev; +time64_t retry_window; + +if (code ==0x13 ) { +bt_dev_err (hdev,"Encountered top exception" ); +return ; + } + + data =btintel_pcie_get_restart_data (pdev, &hdev->dev); +if (!data) +return ; + + retry_window =ktime_get_boottime_seconds () - data->last_error; + +/* If within 5 seconds max 5 attempts have already been made +* then stop any more retry and indicate to user for cold boot +*/ +if (retry_window <BTINTEL_PCIE_RESET_OK_TIME_SECS && + data->restart_count >=BTINTEL_PCIE_FLR_RESET_MAX_RETRY ) { +bt_dev_err (hdev,"Max recovery retries(%d) exhausted." , +BTINTEL_PCIE_FLR_RESET_MAX_RETRY ); +bt_dev_dbg (hdev,"Boot time:%lld seconds first_flr at:%lld seconds restart_count:%d" , +ktime_get_boottime_seconds (), data->last_error, + data->restart_count); +return ; + } +btintel_pcie_inc_restart_count (pdev, &hdev->dev); +btintel_pcie_reset (hdev); +} +static int btintel_pcie_setup_hdev (struct btintel_pcie_data *data) {int err;
@@ -2211,9 +2427,10 @@ static int btintel_pcie_setup_hdev(struct btintel_pcie_data *data) hdev->send = btintel_pcie_send_frame; hdev->setup = btintel_pcie_setup; hdev->shutdown = btintel_shutdown_combined; - hdev->hw_error = btintel_hw_error; + hdev->hw_error = btintel_pcie_hw_error; hdev->set_diag = btintel_set_diag; hdev->set_bdaddr = btintel_set_bdaddr; + hdev->reset = btintel_pcie_reset; err =hci_register_dev (hdev);if (err <0 ) {
@@ -2361,7 +2578,20 @@ static struct pci_driver btintel_pcie_driver = { .driver.coredump = btintel_pcie_coredump#endif }; -module_pci_driver (btintel_pcie_driver); + +static int __init btintel_pcie_init (void ) +{ +return pci_register_driver (&btintel_pcie_driver); +} + +static void __exit btintel_pcie_exit(void) +{ +pci_unregister_driver (&btintel_pcie_driver); +btintel_pcie_free_restart_list (); +} + +module_init (btintel_pcie_init); +module_exit (btintel_pcie_exit);MODULE_AUTHOR ("Tedd Ho-Jeong An <[email protected]>" );MODULE_DESCRIPTION ("Intel Bluetooth PCIe transport driver ver " VERSION );
drivers/bluetooth/btintel_pcie.h +3 -1
@@ -117,7 +117,9 @@ enum {enum {BTINTEL_PCIE_CORE_HALTED ,BTINTEL_PCIE_HWEXP_INPROGRESS , -BTINTEL_PCIE_COREDUMP_INPROGRESS +BTINTEL_PCIE_COREDUMP_INPROGRESS , +BTINTEL_PCIE_RECOVERY_IN_PROGRESS , +BTINTEL_PCIE_SETUP_DONE };enum btintel_pcie_tlv_type {
Signature · 1 line
2.43.0
RE: [PATCH v2 2/2] Bluetooth: btintel_pcie: Support Function level reset
+ [email protected], [email protected]
Quoted 336 lines
-----Original Message-----
From: K, Kiran <[email protected]>
Sent: Sunday, May 25, 2025 3:46 PM
To: [email protected]
Cc: Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; Devegowda, Chandrashekar <[email protected]>; Satija, Vijay <[email protected]>; K, Kiran <[email protected]>
Subject: [PATCH v2 2/2] Bluetooth:btintel_pcie: Support Function level resetFrom: Chandrashekar Devegowda <[email protected]>
Support function level reset (flr) on hardware exception to recover controller. Driver also implements the back-off time of 5 seconds and the maximum number of retries are limited to 5 before giving up.
Signed-off-by: Chandrashekar Devegowda
<[email protected]>Signed-off-by Kiran K <[email protected]>---
drivers/bluetooth/btintel_pcie.c| 234 ++++++++++++++++++++++++++++++-drivers/bluetooth/btintel_pcie.h| 4 +-2 files changed, 235 insertions(+), 3 deletions(-)drivers/bluetooth/btintel_pcie.c +18
-0@@ -41,6 +41,13 @@ static const struct pci_device_id btintel_pcie_table[] = { };MODULE_DEVICE_TABLE (pci, btintel_pcie_table); +struct btintel_pcie_dev_restart_data { +struct list_head list; +u8 restart_count; +time64_t last_error; +char name[]; +}; +/* Intel PCIe uses 4 bytes of HCI type instead of 1 byte BT SIG HCI type */ #define BTINTEL_PCIE_HCI_TYPE_LEN 4#define BTINTEL_PCIE_HCI_CMD_PKT 0x00000001@@ -62,6 +69,9 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);#define BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER 0x17A2#define BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT 0x1E61 +#define BTINTEL_PCIE_RESET_OK_TIME_SECS 5 +#define BTINTEL_PCIE_FLR_RESET_MAX_RETRY 5 +/* Alive interrupt context */ enum {BTINTEL_PCIE_ROM ,@@ -99,6 +109,14 @@ struct btintel_pcie_dbgc_ctxt {struct btintel_pcie_dbgc_ctxt_buf bufs[BTINTEL_PCIE_DBGC_BUFFER_COUNT ]; }; +struct btintel_pcie_removal { +struct pci_dev *pdev; +struct work_struct work; +}; + +static LIST_HEAD (btintel_pcie_restart_data_list); +static DEFINE_SPINLOCK (btintel_pcie_restart_data_lock); +/* This function initializes the memory for DBGC buffers and formats the * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and * size as the payload
drivers/bluetooth/btintel_pcie.c +3
-0@@ -1927,6 +1945,9 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev, u32 type;u32 old_ctxt; +if (test_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags)) +return -ENODEV ; +/* Due to the fw limitation, the type header of the packet should be * 4 bytes unlike 1 byte for UART. In UART, the firmware can read * the first byte to get the packet type and redirect the rest of data @@
-2187,9 +2208,204 @@ static intbtintel_pcie_setup(struct hci_dev *hdev)} btintel_pcie_start_rx(data); }drivers/bluetooth/btintel_pcie.c +3
-0+ +if (!err) +set_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags);return err; }+static struct
btintel_pcie_dev_restart_data*btintel_pcie_get_restart_data(structpci_dev*pdev,drivers/bluetooth/btintel_pcie.c +1
-0+ structdevice *dev)
drivers/bluetooth/btintel_pcie.c +16
-0+{ +struct btintel_pcie_dev_restart_data *tmp, *data =NULL ; +const char *name =pci_name (pdev); +struct hci_dev *hdev =to_hci_dev (dev); + +spin_lock (&btintel_pcie_restart_data_lock); +list_for_each_entry (tmp, &btintel_pcie_restart_data_list, list) { +if (strcmp (tmp->name, name)) +continue ; + data = tmp; +break ; + } +spin_unlock (&btintel_pcie_restart_data_lock); + +if (data) { + bt_dev_dbg(hdev, "Found restart data for BDF:%s", data-Quoted 1 line
name);
drivers/bluetooth/btintel_pcie.c +44
-0+return data; + } + +/* First time allocate */ + data =kzalloc (struct_size (data, name,strlen (name) +1 ),GFP_ATOMIC ); +if (!data) +return NULL ; + +strscpy_pad (data->name, name,strlen (name) +1 ); +spin_lock (&btintel_pcie_restart_data_lock); +list_add_tail (&data->list, &btintel_pcie_restart_data_list); +spin_unlock (&btintel_pcie_restart_data_lock); + +return data; +} + +static void btintel_pcie_free_restart_list (void ) +{ +struct btintel_pcie_dev_restart_data *tmp; + +while ((tmp =list_first_entry_or_null (&btintel_pcie_restart_data_list, +typeof (*tmp), list))) { +list_del (&tmp->list); +kfree (tmp); + } +} + +static void btintel_pcie_inc_restart_count (struct pci_dev *pdev, +struct device *dev) +{ +struct btintel_pcie_dev_restart_data *data; +struct hci_dev *hdev =to_hci_dev (dev); +time64_t retry_window; + + data =btintel_pcie_get_restart_data (pdev, dev); +if (!data) +return ; + + retry_window =ktime_get_boottime_seconds () - data->last_error; +if (data->restart_count ==0 ) { +/* First iteration initialise the time and counter */ + data->last_error =ktime_get_boottime_seconds (); + data->restart_count++; + bt_dev_dbg(hdev, "First iteration initialise. last_error:%lldseconds restart_count:%d",
drivers/bluetooth/btintel_pcie.c +3
-0+ data->last_error, data->restart_count); + } else if (retry_window < BTINTEL_PCIE_RESET_OK_TIME_SECS && + data->restart_count <=
BTINTEL_PCIE_FLR_RESET_MAX_RETRY) {drivers/bluetooth/btintel_pcie.c +5
-0+/* FLR triggered still within the Max retry time so +* increment the counter +*/ + data->restart_count++; + bt_dev_dbg(hdev, "flr triggered still within the max retry timeso increment the restart_count:%d",
drivers/bluetooth/btintel_pcie.c +4
-0+ data->restart_count); + }else if (retry_window >BTINTEL_PCIE_RESET_OK_TIME_SECS ) { +/* FLR triggered out of the retry window so reset */ + bt_dev_dbg(hdev, "flr triggered out of retry window.last_error:%lld seconds restart_count:%d",
drivers/bluetooth/btintel_pcie.c +41
-0+ data->last_error, data->restart_count); + data->last_error =0 ; + data->restart_count =0 ; + } +} + +static int btintel_pcie_setup_hdev (struct btintel_pcie_data *data); + +static void btintel_pcie_removal_work (struct work_struct *wk) { +struct btintel_pcie_removal *removal = + container_of(wk, struct btintel_pcie_removal, work); +struct pci_dev *pdev = removal->pdev; +struct btintel_pcie_data *data; +int err; + +pci_lock_rescan_remove (); + +if (!pdev->bus) + goto error; + + data =pci_get_drvdata (pdev); + +btintel_pcie_disable_interrupts (data); +btintel_pcie_synchronize_irqs (data); +flush_workqueue (data->workqueue); + +bt_dev_dbg (data->hdev,"Release bluetooth interface" ); +btintel_pcie_release_hdev (data); + + err =pci_reset_function (pdev); +if (err) { +BT_ERR ("Failed resetting the pcie device (%d)" , err); + goto error; + } + +btintel_pcie_enable_interrupts (data); +btintel_pcie_config_msix (data); + + err =btintel_pcie_enable_bt (data); +if (err) { + BT_ERR("Failed to enable bluetooth hardware after reset(%d)",
drivers/bluetooth/btintel_pcie.c +66
-0+ err); + goto error; + } + +btintel_pcie_reset_ia (data); +btintel_pcie_start_rx (data); + data->flags =0 ; + + err =btintel_pcie_setup_hdev (data); +if (err) { +BT_ERR ("Failed registering hdev (%d)" , err); + goto error; + } +error: +pci_dev_put (pdev); +pci_unlock_rescan_remove (); +kfree (removal); +} + +static void btintel_pcie_reset (struct hci_dev *hdev) { +struct btintel_pcie_removal *removal; +struct btintel_pcie_data *data; + + data =hci_get_drvdata (hdev); + +if (!test_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags)) +return ; + + removal =kzalloc (sizeof (*removal),GFP_ATOMIC ); +if (!removal) +return ; + +flush_work (&data->rx_work); +flush_work (&hdev->dump.dump_rx); + + removal->pdev = data->pdev; +INIT_WORK (&removal->work, btintel_pcie_removal_work); +pci_dev_get (removal->pdev); +schedule_work (&removal->work); +} + +static void btintel_pcie_hw_error (struct hci_dev *hdev,u8 code) { +struct btintel_pcie_dev_restart_data *data; +struct btintel_pcie_data *dev_data =hci_get_drvdata (hdev); +struct pci_dev *pdev = dev_data->pdev; +time64_t retry_window; + +if (code ==0x13 ) { +bt_dev_err (hdev,"Encountered top exception" ); +return ; + } + + data =btintel_pcie_get_restart_data (pdev, &hdev->dev); +if (!data) +return ; + + retry_window =ktime_get_boottime_seconds () - data->last_error; + +/* If within 5 seconds max 5 attempts have already been made +* then stop any more retry and indicate to user for cold boot +*/ +if (retry_window <BTINTEL_PCIE_RESET_OK_TIME_SECS && + data->restart_count >=BTINTEL_PCIE_FLR_RESET_MAX_RETRY ) { +bt_dev_err (hdev,"Max recovery retries(%d) exhausted." , +BTINTEL_PCIE_FLR_RESET_MAX_RETRY ); + bt_dev_dbg(hdev, "Boot time:%lld seconds first_flr at:%lldseconds restart_count:%d",
drivers/bluetooth/btintel_pcie.c +8
-0+ktime_get_boottime_seconds (), data->last_error, + data->restart_count); +return ; + } +btintel_pcie_inc_restart_count (pdev, &hdev->dev); +btintel_pcie_reset (hdev); +} +static int btintel_pcie_setup_hdev(struct btintel_pcie_data *data) { int err;drivers/bluetooth/btintel_pcie.c +2
-1@@ -2211,9 +2427,10 @@ static int btintel_pcie_setup_hdev(struct btintel_pcie_data *data) hdev->send = btintel_pcie_send_frame; hdev->setup = btintel_pcie_setup; hdev->shutdown = btintel_shutdown_combined; - hdev->hw_error = btintel_hw_error; + hdev->hw_error = btintel_pcie_hw_error; hdev->set_diag = btintel_set_diag; hdev->set_bdaddr = btintel_set_bdaddr; + hdev->reset = btintel_pcie_reset; err =hci_register_dev (hdev);if (err < 0) {drivers/bluetooth/btintel_pcie.c +12
-0@@ -2361,7 +2578,20 @@ static struct pci_driver btintel_pcie_driver = { .driver.coredump = btintel_pcie_coredump #endif }; -module_pci_driver (btintel_pcie_driver); + +static int __init btintel_pcie_init (void ) { +return pci_register_driver (&btintel_pcie_driver); +} + +static void __exit btintel_pcie_exit(void) { +pci_unregister_driver (&btintel_pcie_driver); +btintel_pcie_free_restart_list (); +} + +module_init (btintel_pcie_init); +module_exit (btintel_pcie_exit);MODULE_AUTHOR ("Tedd Ho-Jeong An <[email protected]>" );MODULE_DESCRIPTION ("Intel Bluetooth PCIe transport driver ver " VERSION );drivers/bluetooth/btintel_pcie.h +3
-2@@ -117,7 +117,9 @@ enum {enum {BTINTEL_PCIE_CORE_HALTED ,BTINTEL_PCIE_HWEXP_INPROGRESS , -BTINTEL_PCIE_COREDUMP_INPROGRESS +BTINTEL_PCIE_COREDUMP_INPROGRESS , +BTINTEL_PCIE_RECOVERY_IN_PROGRESS , +BTINTEL_PCIE_SETUP_DONE };enum btintel_pcie_tlv_type { --2.43.0
Re: [PATCH v2 2/2] Bluetooth: btintel_pcie: Support Function level reset
In reply to Kiran KDear Kiran, dear Chandrashekar,
Thank you for your patch.
Am 25.05.25 um 12:16 schrieb Kiran K:
Quoted 5 lines
From: Chandrashekar Devegowda <[email protected]>
Support function level reset (flr) on hardware exception to recover controller. Driver also implements the back-off time of 5 seconds and the maximum number of retries are limited to 5 before giving up.
Could you elaborate on the implementation, and detail how this can be tested?
Quoted 78 lines
Signed-off-by Chandrashekar Devegowda <[email protected]>Signed-off-by Kiran K <[email protected]>--- drivers/bluetooth/btintel_pcie.c | 234 ++++++++++++++++++++++++++++++- drivers/bluetooth/btintel_pcie.h | 4 +- 2 files changed, 235 insertions(+), 3 deletions(-)drivers/bluetooth/btintel_pcie.c +32
-0@@ -41,6 +41,13 @@ static const struct pci_device_id btintel_pcie_table[] = { };MODULE_DEVICE_TABLE (pci, btintel_pcie_table); +struct btintel_pcie_dev_restart_data { +struct list_head list; +u8 restart_count; +time64_t last_error; +char name[]; +}; +/* Intel PCIe uses 4 bytes of HCI type instead of 1 byte BT SIG HCI type */ #define BTINTEL_PCIE_HCI_TYPE_LEN 4#define BTINTEL_PCIE_HCI_CMD_PKT 0x00000001@@ -62,6 +69,9 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);#define BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER 0x17A2#define BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT 0x1E61 +#define BTINTEL_PCIE_RESET_OK_TIME_SECS 5 +#define BTINTEL_PCIE_FLR_RESET_MAX_RETRY 5 +/* Alive interrupt context */ enum {BTINTEL_PCIE_ROM ,@@ -99,6 +109,14 @@ struct btintel_pcie_dbgc_ctxt {struct btintel_pcie_dbgc_ctxt_buf bufs[BTINTEL_PCIE_DBGC_BUFFER_COUNT ]; }; +struct btintel_pcie_removal { +struct pci_dev *pdev; +struct work_struct work; +}; + +static LIST_HEAD (btintel_pcie_restart_data_list); +static DEFINE_SPINLOCK (btintel_pcie_restart_data_lock); +/* This function initializes the memory for DBGC buffers and formats the * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and * size as the payload @@ -1927,6 +1945,9 @@ static int btintel_pcie_send_frame(struct hci_dev *hdev,u32 type;u32 old_ctxt; +if (test_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags)) +return -ENODEV ; +/* Due to the fw limitation, the type header of the packet should be * 4 bytes unlike 1 byte for UART. In UART, the firmware can read * the first byte to get the packet type and redirect the rest of data @@ -2187,9 +2208,204 @@ static int btintel_pcie_setup(struct hci_dev *hdev) }btintel_pcie_start_rx (data); } + +if (!err) +set_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags);return err; } +static struct btintel_pcie_dev_restart_data *btintel_pcie_get_restart_data (struct pci_dev *pdev, +struct device *dev) +{ +struct btintel_pcie_dev_restart_data *tmp, *data =NULL ; +const char *name =pci_name (pdev); +struct hci_dev *hdev =to_hci_dev (dev); + +spin_lock (&btintel_pcie_restart_data_lock);
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2234
Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10
-0+list_for_each_entry (tmp, &btintel_pcie_restart_data_list, list) { +if (strcmp (tmp->name, name)) +continue ; + data = tmp; +break ; + } +spin_unlock (&btintel_pcie_restart_data_lock); + +if (data) { +bt_dev_dbg (hdev,"Found restart data for BDF:%s" , data->name);
Add a space after the colon?
Quoted 31 lines
drivers/bluetooth/btintel_pcie.c +31
-0+return data; + } + +/* First time allocate */ + data =kzalloc (struct_size (data, name,strlen (name) +1 ),GFP_ATOMIC ); +if (!data) +return NULL ; + +strscpy_pad (data->name, name,strlen (name) +1 ); +spin_lock (&btintel_pcie_restart_data_lock); +list_add_tail (&data->list, &btintel_pcie_restart_data_list); +spin_unlock (&btintel_pcie_restart_data_lock); + +return data; +} + +static void btintel_pcie_free_restart_list (void ) +{ +struct btintel_pcie_dev_restart_data *tmp; + +while ((tmp =list_first_entry_or_null (&btintel_pcie_restart_data_list, +typeof (*tmp), list))) { +list_del (&tmp->list); +kfree (tmp); + } +} + +static void btintel_pcie_inc_restart_count (struct pci_dev *pdev, +struct device *dev) +{ +struct btintel_pcie_dev_restart_data *data;
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2275
Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10
-0+struct hci_dev *hdev =to_hci_dev (dev); +time64_t retry_window; + + data =btintel_pcie_get_restart_data (pdev, dev); +if (!data) +return ; + + retry_window =ktime_get_boottime_seconds () - data->last_error; +if (data->restart_count ==0 ) { +/* First iteration initialise the time and counter */
initialises
But with the debug print below, the comment is not needed, in my opinion.
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2278
Quoted 3 lines
drivers/bluetooth/btintel_pcie.c +3
-0+ data->last_error =ktime_get_boottime_seconds (); + data->restart_count++; + bt_dev_dbg(hdev, "First iteration initialise. last_error:%lld seconds restart_count:%d",
Please add a space after the colon.
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2287
Quoted 9 lines
drivers/bluetooth/btintel_pcie.c +9
-0+ data->last_error, data->restart_count); + }else if (retry_window <BTINTEL_PCIE_RESET_OK_TIME_SECS && + data->restart_count <=BTINTEL_PCIE_FLR_RESET_MAX_RETRY ) { +/* FLR triggered still within the Max retry time so +* increment the counter +*/ + data->restart_count++; +bt_dev_dbg (hdev,"flr triggered still within the max retry time so increment the restart_count:%d" , + data->restart_count);
Space after colon.
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2290
Quoted 3 lines
drivers/bluetooth/btintel_pcie.c +3
-0+ }else if (retry_window >BTINTEL_PCIE_RESET_OK_TIME_SECS ) { +/* FLR triggered out of the retry window so reset */ + bt_dev_dbg(hdev, "flr triggered out of retry window. last_error:%lld seconds restart_count:%d",
Space after colons.
Quoted 33 lines
drivers/bluetooth/btintel_pcie.c +33
-0+ data->last_error, data->restart_count); + data->last_error =0 ; + data->restart_count =0 ; + } +} + +static int btintel_pcie_setup_hdev (struct btintel_pcie_data *data); + +static void btintel_pcie_removal_work (struct work_struct *wk) +{ +struct btintel_pcie_removal *removal = + container_of(wk, struct btintel_pcie_removal, work); +struct pci_dev *pdev = removal->pdev; +struct btintel_pcie_data *data; +int err; + +pci_lock_rescan_remove (); + +if (!pdev->bus) + goto error; + + data =pci_get_drvdata (pdev); + +btintel_pcie_disable_interrupts (data); +btintel_pcie_synchronize_irqs (data); +flush_workqueue (data->workqueue); + +bt_dev_dbg (data->hdev,"Release bluetooth interface" ); +btintel_pcie_release_hdev (data); + + err =pci_reset_function (pdev); +if (err) { +BT_ERR ("Failed resetting the pcie device (%d)" , err);
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2333
Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10
-0+ goto error; + } + +btintel_pcie_enable_interrupts (data); +btintel_pcie_config_msix (data); + + err =btintel_pcie_enable_bt (data); +if (err) { +BT_ERR ("Failed to enable bluetooth hardware after reset (%d)" , + err);
What should the user reading this error do?
Quoted 52 lines
drivers/bluetooth/btintel_pcie.c +52
-0+ goto error; + } + +btintel_pcie_reset_ia (data); +btintel_pcie_start_rx (data); + data->flags =0 ; + + err =btintel_pcie_setup_hdev (data); +if (err) { +BT_ERR ("Failed registering hdev (%d)" , err); + goto error; + } +error: +pci_dev_put (pdev); +pci_unlock_rescan_remove (); +kfree (removal); +} + +static void btintel_pcie_reset (struct hci_dev *hdev) +{ +struct btintel_pcie_removal *removal; +struct btintel_pcie_data *data; + + data =hci_get_drvdata (hdev); + +if (!test_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags)) +return ; + + removal =kzalloc (sizeof (*removal),GFP_ATOMIC ); +if (!removal) +return ; + +flush_work (&data->rx_work); +flush_work (&hdev->dump.dump_rx); + + removal->pdev = data->pdev; +INIT_WORK (&removal->work, btintel_pcie_removal_work); +pci_dev_get (removal->pdev); +schedule_work (&removal->work); +} + +static void btintel_pcie_hw_error (struct hci_dev *hdev,u8 code) +{ +struct btintel_pcie_dev_restart_data *data; +struct btintel_pcie_data *dev_data =hci_get_drvdata (hdev); +struct pci_dev *pdev = dev_data->pdev; +time64_t retry_window; + +if (code ==0x13 ) { +bt_dev_err (hdev,"Encountered top exception" ); +return ; + }
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2395
Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10
-0+ + data =btintel_pcie_get_restart_data (pdev, &hdev->dev); +if (!data) +return ; + + retry_window =ktime_get_boottime_seconds () - data->last_error; + +/* If within 5 seconds max 5 attempts have already been made +* then stop any more retry and indicate to user for cold boot +*/
The messages below should be improved, and the comment above can be removed then.
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2398
Quoted 3 lines
drivers/bluetooth/btintel_pcie.c +3
-0+if (retry_window <BTINTEL_PCIE_RESET_OK_TIME_SECS && + data->restart_count >=BTINTEL_PCIE_FLR_RESET_MAX_RETRY ) { + bt_dev_err(hdev, "Max recovery retries(%d) exhausted.",
Please add a space before (, exactly one space before *exhausted*. What should the user do?
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2400
Quoted 2 lines
drivers/bluetooth/btintel_pcie.c +2
-0+ BTINTEL_PCIE_FLR_RESET_MAX_RETRY); + bt_dev_dbg(hdev, "Boot time:%lld seconds first_flr at:%lld seconds restart_count:%d",
Spaces after colons.
Quoted 50 lines
drivers/bluetooth/btintel_pcie.c +24
-2+ktime_get_boottime_seconds (), data->last_error, + data->restart_count); +return ; + } +btintel_pcie_inc_restart_count (pdev, &hdev->dev); +btintel_pcie_reset (hdev); +} +static int btintel_pcie_setup_hdev (struct btintel_pcie_data *data) {int err;@@ -2211,9 +2427,10 @@ static int btintel_pcie_setup_hdev(struct btintel_pcie_data *data) hdev->send = btintel_pcie_send_frame; hdev->setup = btintel_pcie_setup; hdev->shutdown = btintel_shutdown_combined; - hdev->hw_error = btintel_hw_error; + hdev->hw_error = btintel_pcie_hw_error; hdev->set_diag = btintel_set_diag; hdev->set_bdaddr = btintel_set_bdaddr; + hdev->reset = btintel_pcie_reset; err =hci_register_dev (hdev);if (err <0 ) {@@ -2361,7 +2578,20 @@ static struct pci_driver btintel_pcie_driver = { .driver.coredump = btintel_pcie_coredump#endif }; -module_pci_driver (btintel_pcie_driver); + +static int __init btintel_pcie_init (void ) +{ +return pci_register_driver (&btintel_pcie_driver); +} + +static void __exit btintel_pcie_exit(void) +{ +pci_unregister_driver (&btintel_pcie_driver); +btintel_pcie_free_restart_list (); +} + +module_init (btintel_pcie_init); +module_exit (btintel_pcie_exit);MODULE_AUTHOR ("Tedd Ho-Jeong An <[email protected]>" );MODULE_DESCRIPTION ("Intel Bluetooth PCIe transport driver ver " VERSION );drivers/bluetooth/btintel_pcie.h +0
-0
drivers/bluetooth/btintel_pcie.h enum { · line 125
Quoted 10 lines
drivers/bluetooth/btintel_pcie.h +3
-1@@ -117,7 +117,9 @@ enum {enum {BTINTEL_PCIE_CORE_HALTED ,BTINTEL_PCIE_HWEXP_INPROGRESS , -BTINTEL_PCIE_COREDUMP_INPROGRESS +BTINTEL_PCIE_COREDUMP_INPROGRESS , +BTINTEL_PCIE_RECOVERY_IN_PROGRESS , +BTINTEL_PCIE_SETUP_DONE };enum btintel_pcie_tlv_type {
Kind regards,
Paul
RE: [PATCH v2 2/2] Bluetooth: btintel_pcie: Support Function level reset
Hi Paul,
Thanks for your comments.
Quoted 8 lines
Subject: Re: [PATCH v2 2/2] Bluetooth:
btintel_pcie: Support Function level resetDear Kiran, dear Chandrashekar,
Thank you for your patch.
Quoted 8 lines
Am 25.05.25 um 12:16 schrieb Kiran K:
Quoted 5 lines
From: Chandrashekar Devegowda <[email protected]>
Support function level reset (flr) on hardware exception to recover controller. Driver also implements the back-off time of 5 seconds and the maximum number of retries are limited to 5 before giving up.
Could you elaborate on the implementation, and detail how this can be tested?
1. Whenever there is an exception in the firmware, driver gets notified via MSIx. a. Driver shall unregister hdev
b. invoke pci_reset_function() to reset controller
c. make a new instance of hdev and register to bluetooth subsystem
2. The driver must monitor the number of reset attempts triggered within a 5-second window:
a. If the number of resets exceeds 5 attempts within the last 5 seconds, the driver should cease further reset attempts, as this indicates a serious issue with the firmware.
Quoted 95 lines
Quoted 6 lines
Signed-off-by: Chandrashekar Devegowda
<[email protected]>Signed-off-by Kiran K <[email protected]>--- drivers/bluetooth/btintel_pcie.c | 234++++++++++++++++++++++++++++++-
drivers/bluetooth/btintel_pcie.c static const struct pci_device_id btintel_pcie_table[] =
Quoted 9 lines
drivers/bluetooth/btintel_pcie.h | 4 +- 2 files changed, 235 insertions(+), 3 deletions(-)drivers/bluetooth/btintel_pcie.c +0
-0@@ -41,6 +41,13 @@ static const struct pci_device_id btintel_pcie_table[] ={
Quoted 14 lines
drivers/bluetooth/btintel_pcie.c +7
-0};MODULE_DEVICE_TABLE (pci, btintel_pcie_table); +struct btintel_pcie_dev_restart_data { +struct list_head list; +u8 restart_count; +time64_t last_error; +char name[]; +}; +/* Intel PCIe uses 4 bytes of HCI type instead of 1 byte BT SIG HCI type */ #define BTINTEL_PCIE_HCI_TYPE_LEN 4#define BTINTEL_PCIE_HCI_CMD_PKT 0x00000001drivers/bluetooth/btintel_pcie.c MODULE_DEVICE_TABLE(pci, btintel_pcie_table); · line 70
Quoted 2 lines
drivers/bluetooth/btintel_pcie.c +0
-0@@ -62,6 +69,9 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);#define BTINTEL_PCIE_TRIGGER_REASON_USER_TRIGGER 0x17A2#define BTINTEL_PCIE_TRIGGER_REASON_FW_ASSERT 0x1E61drivers/bluetooth/btintel_pcie.c struct btintel_pcie_dbgc_ctxt { · line 109
Quoted 9 lines
drivers/bluetooth/btintel_pcie.c +3
-0+#define BTINTEL_PCIE_RESET_OK_TIME_SECS 5 +#define BTINTEL_PCIE_FLR_RESET_MAX_RETRY 5 +/* Alive interrupt context */ enum {BTINTEL_PCIE_ROM ,@@ -99,6 +109,14 @@ struct btintel_pcie_dbgc_ctxt {struct btintel_pcie_dbgc_ctxt_buf bufs[BTINTEL_PCIE_DBGC_BUFFER_COUNT];
drivers/bluetooth/btintel_pcie.c struct btintel_pcie_dbgc_ctxt {
Quoted 12 lines
drivers/bluetooth/btintel_pcie.c +8
-0}; +struct btintel_pcie_removal { +struct pci_dev *pdev; +struct work_struct work; +}; + +static LIST_HEAD (btintel_pcie_restart_data_list); +static DEFINE_SPINLOCK (btintel_pcie_restart_data_lock); +/* This function initializes the memory for DBGC buffers and formats the * DBGC fragment which consists header info and DBGC buffer's LSB, MSB and
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_send_frame(struct hci_dev
Quoted 2 lines
drivers/bluetooth/btintel_pcie.c +0
-0* size as the payload @@ -1927,6 +1945,9 @@ static int btintel_pcie_send_frame(struct hci_dev*hdev,
Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +3
-0u32 type;u32 old_ctxt; +if (test_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags)) +return -ENODEV ; +/* Due to the fw limitation, the type header of the packet should be * 4 bytes unlike 1 byte for UART. In UART, the firmware can read * the first byte to get the packet type and redirect the rest of data @@ -2187,9 +2208,204 @@ static int btintel_pcie_setup(struct
hci_dev*hdev)
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev)
Quoted 10 lines
} btintel_pcie_start_rx(data); }drivers/bluetooth/btintel_pcie.c +4
-0+ +if (!err) +set_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags);return err; } +static struct btintel_pcie_dev_restart_data*btintel_pcie_get_restart_data(struct
pci_dev*pdev,drivers/bluetooth/btintel_pcie.c
Quoted 1 line
drivers/bluetooth/btintel_pcie.c +1
-0+ structdevice *dev)
Quoted 11 lines
drivers/bluetooth/btintel_pcie.c +11
-0+{ +struct btintel_pcie_dev_restart_data *tmp, *data =NULL ; +const char *name =pci_name (pdev); +struct hci_dev *hdev =to_hci_dev (dev); + +spin_lock (&btintel_pcie_restart_data_lock); +list_for_each_entry (tmp, &btintel_pcie_restart_data_list, list) { +if (strcmp (tmp->name, name)) +continue ; + data = tmp; +break ;
Quoted 8 lines
Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +5
-0+ } +spin_unlock (&btintel_pcie_restart_data_lock); + +if (data) { + bt_dev_dbg(hdev, "Found restart data for BDF:%s", data-name);
Add a space after the colon?
Ack
Quoted 65 lines
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev)
Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +5
-0+return data; + } + +/* First time allocate */ + data = kzalloc(struct_size(data, name, strlen(name) + 1),
GFP_ATOMIC);Quoted 26 lines
drivers/bluetooth/btintel_pcie.c +26
-0+if (!data) +return NULL ; + +strscpy_pad (data->name, name,strlen (name) +1 ); +spin_lock (&btintel_pcie_restart_data_lock); +list_add_tail (&data->list, &btintel_pcie_restart_data_list); +spin_unlock (&btintel_pcie_restart_data_lock); + +return data; +} + +static void btintel_pcie_free_restart_list (void ) +{ +struct btintel_pcie_dev_restart_data *tmp; + +while ((tmp =list_first_entry_or_null (&btintel_pcie_restart_data_list, +typeof (*tmp), list))) { +list_del (&tmp->list); +kfree (tmp); + } +} + +static void btintel_pcie_inc_restart_count (struct pci_dev *pdev, +struct device *dev) +{ +struct btintel_pcie_dev_restart_data *data;drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2275
Quoted 10 lines
drivers/bluetooth/btintel_pcie.c +10
-0+struct hci_dev *hdev =to_hci_dev (dev); +time64_t retry_window; + + data =btintel_pcie_get_restart_data (pdev, dev); +if (!data) +return ; + + retry_window =ktime_get_boottime_seconds () - data->last_error; +if (data->restart_count ==0 ) { +/* First iteration initialise the time and counter */ initialises
But with the debug print below, the comment is not needed, in my opinion.
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev)
Quoted 4 lines
drivers/bluetooth/btintel_pcie.c +4
-0+ data->last_error =ktime_get_boottime_seconds (); + data->restart_count++; + bt_dev_dbg(hdev, "First iteration initialise. last_error:%lld +seconds restart_count:%d",Please add a space after the colon.
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev)
Quoted 3 lines
drivers/bluetooth/btintel_pcie.c +3
-0+ data->last_error, data->restart_count); + } else if (retry_window < BTINTEL_PCIE_RESET_OK_TIME_SECS && + data->restart_count <=
BTINTEL_PCIE_FLR_RESET_MAX_RETRY) {drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev)
Quoted 5 lines
drivers/bluetooth/btintel_pcie.c +5
-0+/* FLR triggered still within the Max retry time so +* increment the counter +*/ + data->restart_count++; + bt_dev_dbg(hdev, "flr triggered still within the max retry timeso increment the restart_count:%d",
Quoted 3 lines
drivers/bluetooth/btintel_pcie.c
Quoted 1 line
drivers/bluetooth/btintel_pcie.c +1
-0+ data->restart_count);Space after colon.
Ack
Quoted 7 lines
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev)
Quoted 5 lines
drivers/bluetooth/btintel_pcie.c +4
-0+ }else if (retry_window >BTINTEL_PCIE_RESET_OK_TIME_SECS ) { +/* FLR triggered out of the retry window so reset */ + bt_dev_dbg(hdev, "flr triggered out of retry window. +last_error:%lld seconds restart_count:%d",Space after colons.
Ack
Quoted 37 lines
Quoted 37 lines
drivers/bluetooth/btintel_pcie.c +36
-0+ data->last_error, data->restart_count); + data->last_error =0 ; + data->restart_count =0 ; + } +} + +static int btintel_pcie_setup_hdev (struct btintel_pcie_data *data); + +static void btintel_pcie_removal_work (struct work_struct *wk) { +struct btintel_pcie_removal *removal = + container_of(wk, struct btintel_pcie_removal, work); +struct pci_dev *pdev = removal->pdev; +struct btintel_pcie_data *data; +int err; + +pci_lock_rescan_remove (); + +if (!pdev->bus) + goto error; + + data =pci_get_drvdata (pdev); + +btintel_pcie_disable_interrupts (data); +btintel_pcie_synchronize_irqs (data); +flush_workqueue (data->workqueue); + +bt_dev_dbg (data->hdev,"Release bluetooth interface" ); +btintel_pcie_release_hdev (data); + + err =pci_reset_function (pdev); +if (err) { +BT_ERR ("Failed resetting the pcie device (%d)" , err); + goto error; + } + +btintel_pcie_enable_interrupts (data);
Quoted 8 lines
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2333
Quoted 6 lines
drivers/bluetooth/btintel_pcie.c +6
-0+btintel_pcie_config_msix (data); + + err =btintel_pcie_enable_bt (data); +if (err) { +BT_ERR ("Failed to enable bluetooth hardware after reset (%d)" , + err);What should the user reading this error do?
The recovery attempt would fail.
Quoted 56 lines
Quoted 56 lines
drivers/bluetooth/btintel_pcie.c +55
-0+ goto error; + } + +btintel_pcie_reset_ia (data); +btintel_pcie_start_rx (data); + data->flags =0 ; + + err =btintel_pcie_setup_hdev (data); +if (err) { +BT_ERR ("Failed registering hdev (%d)" , err); + goto error; + } +error: +pci_dev_put (pdev); +pci_unlock_rescan_remove (); +kfree (removal); +} + +static void btintel_pcie_reset (struct hci_dev *hdev) { +struct btintel_pcie_removal *removal; +struct btintel_pcie_data *data; + + data =hci_get_drvdata (hdev); + +if (!test_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags)) +return ; + + removal =kzalloc (sizeof (*removal),GFP_ATOMIC ); +if (!removal) +return ; + +flush_work (&data->rx_work); +flush_work (&hdev->dump.dump_rx); + + removal->pdev = data->pdev; +INIT_WORK (&removal->work, btintel_pcie_removal_work); +pci_dev_get (removal->pdev); +schedule_work (&removal->work); +} + +static void btintel_pcie_hw_error (struct hci_dev *hdev,u8 code) { +struct btintel_pcie_dev_restart_data *data; +struct btintel_pcie_data *dev_data =hci_get_drvdata (hdev); +struct pci_dev *pdev = dev_data->pdev; +time64_t retry_window; + +if (code ==0x13 ) { +bt_dev_err (hdev,"Encountered top exception" ); +return ; + } + + data =btintel_pcie_get_restart_data (pdev, &hdev->dev); +if (!data) +return ; +
Quoted 8 lines
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2395
Quoted 5 lines
drivers/bluetooth/btintel_pcie.c +5
-0+ retry_window =ktime_get_boottime_seconds () - data->last_error; + +/* If within 5 seconds max 5 attempts have already been made +* then stop any more retry and indicate to user for cold boot +*/ The messages below should be improved, and the comment above can be removed then.
Ack. I will rework on this.
Quoted 7 lines
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup(struct hci_dev *hdev) · line 2398
Quoted 4 lines
drivers/bluetooth/btintel_pcie.c +3
-0+if (retry_window <BTINTEL_PCIE_RESET_OK_TIME_SECS && + data->restart_count >=BTINTEL_PCIE_FLR_RESET_MAX_RETRY ) { + bt_dev_err(hdev, "Max recovery retries(%d) exhausted.",Please add a space before (, exactly one space before *exhausted*. What should the user do?
Ack. I hope I have explained in my first comment.
Quoted 7 lines
drivers/bluetooth/btintel_pcie.c
Quoted 3 lines
drivers/bluetooth/btintel_pcie.c +2
-0+ BTINTEL_PCIE_FLR_RESET_MAX_RETRY); + bt_dev_dbg(hdev, "Boot time:%lld seconds first_flr at:%lldseconds
Quoted 1 line
+restart_count:%d",
Spaces after colons.
Ack.
Quoted 60 lines
drivers/bluetooth/btintel_pcie.c static int btintel_pcie_setup_hdev(struct
Quoted 13 lines
drivers/bluetooth/btintel_pcie.c +8
-0+ktime_get_boottime_seconds (), data->last_error, + data->restart_count); +return ; + } +btintel_pcie_inc_restart_count (pdev, &hdev->dev); +btintel_pcie_reset (hdev); +} +static int btintel_pcie_setup_hdev (struct btintel_pcie_data *data) {int err;@@ -2211,9 +2427,10 @@ static int btintel_pcie_setup_hdev(struct
btintel_pcie_data*data)Quoted 46 lines
drivers/bluetooth/btintel_pcie.c +14
-2hdev->send = btintel_pcie_send_frame; hdev->setup = btintel_pcie_setup; hdev->shutdown = btintel_shutdown_combined; - hdev->hw_error = btintel_hw_error; + hdev->hw_error = btintel_pcie_hw_error; hdev->set_diag = btintel_set_diag; hdev->set_bdaddr = btintel_set_bdaddr; + hdev->reset = btintel_pcie_reset; err =hci_register_dev (hdev);if (err <0 ) {@@ -2361,7 +2578,20 @@ static struct pci_driver btintel_pcie_driver = { .driver.coredump = btintel_pcie_coredump#endif }; -module_pci_driver (btintel_pcie_driver); + +static int __init btintel_pcie_init (void ) { +return pci_register_driver (&btintel_pcie_driver); +} + +static void __exit btintel_pcie_exit(void) { +pci_unregister_driver (&btintel_pcie_driver); +btintel_pcie_free_restart_list (); +} + +module_init (btintel_pcie_init); +module_exit (btintel_pcie_exit);MODULE_AUTHOR ("Tedd Ho-Jeong An <[email protected]>" ); MODULE_DESCRIPTION("Intel Bluetooth PCIe transport driver ver "VERSION); diff --git
a/drivers/bluetooth/btintel_pcie.hb/drivers/bluetooth/btintel_pcie.h
index21b964b15c1c..62b6bcdaf10f100644drivers/bluetooth/btintel_pcie.h +3
-1@@ -117,7 +117,9 @@ enum {enum {BTINTEL_PCIE_CORE_HALTED ,BTINTEL_PCIE_HWEXP_INPROGRESS , -BTINTEL_PCIE_COREDUMP_INPROGRESS +BTINTEL_PCIE_COREDUMP_INPROGRESS , +BTINTEL_PCIE_RECOVERY_IN_PROGRESS , +BTINTEL_PCIE_SETUP_DONE };
Quoted 6 lines
drivers/bluetooth/btintel_pcie.h enum { · line 125
Quoted 1 line
drivers/bluetooth/btintel_pcie.h +0
-0enum btintel_pcie_tlv_type {Kind regards,
Paul
Thanks,
Kiran
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=966204
---Test result---
Test Summary:
CheckPatch PENDING 0.22 seconds GitLint PENDING 0.18 seconds SubjectPrefix PASS 0.18 seconds BuildKernel PASS 24.31 seconds CheckAllWarning PASS 26.64 seconds CheckSparse PASS 30.17 seconds BuildKernel32 PASS 23.88 seconds TestRunnerSetup PASS 454.99 seconds TestRunner_l2cap-tester PASS 25.38 seconds TestRunner_iso-tester PASS 39.81 seconds TestRunner_bnep-tester PASS 5.78 seconds TestRunner_mgmt-tester FAIL 131.41 seconds TestRunner_rfcomm-tester PASS 9.34 seconds TestRunner_sco-tester PASS 14.64 seconds TestRunner_ioctl-tester PASS 10.02 seconds TestRunner_mesh-tester PASS 7.19 seconds TestRunner_smp-tester PASS 8.50 seconds TestRunner_userchan-tester PASS 6.15 seconds IncrementalBuild PENDING 0.38 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 490, Passed: 484 (98.8%), Failed: 2, Not Run: 4
Failed Test Cases
LL Privacy - Add Device 3 (AL is full) Failed 0.230 seconds LL Privacy - Set Flags 1 (Add to RL) Failed 0.166 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth