Bluetooth: btintel: Add TOP silent reset hooks
PATCH v7 1/2 Bluetooth: btintel: Add TOP silent reset hooks
Add an INTEL_TOP_RESET flag so btintel_boot() returns -ECANCELED and the transport can run its own TOP silent reset instead of the Intel soft reset. Cache boot_addr in struct btintel_data for the replay.
No functional change on its own.
--- drivers/bluetooth/btintel.c | 28 ++++++++++++++++++++++++++++ drivers/bluetooth/btintel.h | 2 ++ 2 files changed, 30 insertions(+)
drivers/bluetooth/btintel.c +28 -0
@@ -1313,6 +1313,12 @@ static bool btintel_firmware_version(struct hci_dev *hdev, {const u8 *fw_ptr; +if (hdev->bus ==HCI_PCI ) { +struct btintel_data *data =hci_get_priv (hdev); + + data->boot_addr =0 ; + } + fw_ptr = fw->data;while (fw_ptr - fw->data < fw->size) {
@@ -1330,6 +1336,12 @@ static bool btintel_firmware_version(struct hci_dev *hdev, *boot_addr =le32_to_cpu (params->boot_addr); +if (hdev->bus ==HCI_PCI ) { +struct btintel_data *data =hci_get_priv (hdev); + + data->boot_addr = *boot_addr; + } +bt_dev_info (hdev,"Boot Address: 0x%x" , *boot_addr); bt_dev_info(hdev, "Firmware Version: %u-%u.%u",
@@ -2138,6 +2150,13 @@ static int btintel_boot(struct hci_dev *hdev, u32 boot_addr)ktime_t calltime;int err; +/* Let the transport replace the Intel soft reset for a TOP reset */ +if (hdev->bus ==HCI_PCI && +btintel_test_flag (hdev,INTEL_TOP_RESET )) { +bt_dev_info (hdev,"TOP reset pending, skipping Intel soft reset" ); +return -ECANCELED ; + } + calltime =ktime_get ();btintel_set_flag (hdev,INTEL_BOOTING );
@@ -3908,6 +3927,7 @@ int btintel_bootloader_setup_tlv(struct hci_dev *hdev,struct intel_version_tlv new_ver;struct btintel_data *data =hci_get_priv (hdev);u8 hw_variant =INTEL_HW_VARIANT (ver->cnvi_bt); +bool top_reset =btintel_test_flag (hdev,INTEL_TOP_RESET );bt_dev_dbg (hdev,"" );
@@ -3924,10 +3944,18 @@ int btintel_bootloader_setup_tlv(struct hci_dev *hdev,for (int i =0 ; i < __INTEL_NUM_FLAGS; i++)btintel_clear_flag (hdev, i); +if (top_reset) +btintel_set_flag (hdev,INTEL_TOP_RESET ); +btintel_set_flag (hdev,INTEL_BOOTLOADER ); data->unlocker = false; +if (top_reset && ver->img_type ==BTINTEL_IMG_OP ) { +bt_dev_err (hdev,"TOP reset requested on operational image" ); +return -EALREADY ; + } +/* Legacy unlocker flow (BlazarI / BlazarIW / BlazarU / Gale Peak): * Boot ROM -> unlocker.sfi -> IML -> OPFW *
drivers/bluetooth/btintel.h +2 -0
@@ -260,6 +260,7 @@ enum {INTEL_ACPI_RESET_ACTIVE ,INTEL_WAIT_FOR_D0 ,INTEL_UNLOCKER_LOADED , +INTEL_TOP_RESET , __INTEL_NUM_FLAGS, };
@@ -268,6 +269,7 @@ struct btintel_data {DECLARE_BITMAP (flags, __INTEL_NUM_FLAGS);int (*acpi_reset_method)(struct hci_dev *hdev);u32 cnvi_bt; +u32 boot_addr;bool unlocker; };
Signature · 1 line
2.43.0
PATCH v7 2/2 Bluetooth: btintel_pcie: Add TOP silent reset support
Add TOP silent reset as a lighter alternative to PLDR. It is used on HW >= SCP2 (except BZRIW) with subsystem ID PEP; other devices keep using PLDR.
After the FLR reprobe, replay the Intel soft reset with the cached boot_addr and wait for the GP1 mailbox event, then for boot stage 0. Request a final FLR on success. A missing boot_addr, a failed soft reset, a mailbox timeout or a non-zero boot stage falls back to PLDR.
A WiFi-initiated request is not rate limited and makes BT follow with PLDR. GP1 is added to causes_list[] so it is unmasked on all variants; the handler acts only on the TOP silent reset mailbox values and leaves the target access values unchanged.
Reset requests are now serialized against setup() by reset_gate_lock, so reset_work never runs alongside it. The recovery window restarts on the first attempt after it expired.
Also fix problems in the existing reset paths that the new flow depends on:
- drop the pci_dev reference when disable_work_sync() cancels reset_work
- check the result of btintel_pcie_perform_pldr()
- take pci_dev_trylock() in acpi_reset_method to avoid an ABBA deadlock with the PCI core
- avoid a duplicate recovery entry when two threads race in btintel_pcie_get_recovery()
- check device_is_bound() before reprobing
- take the recovery list lock with irqsave
--- drivers/bluetooth/btintel_pcie.c | 776 ++++++++++++++++++++++++++++--- drivers/bluetooth/btintel_pcie.h | 42 +- 2 files changed, 736 insertions(+), 82 deletions(-)
drivers/bluetooth/btintel_pcie.c +699 -77
@@ -76,6 +76,7 @@ MODULE_DEVICE_TABLE(pci, btintel_pcie_table);struct btintel_pcie_dev_recovery {struct list_head list; +unsigned long flags;u8 count;time64_t last_error;char name[];
@@ -96,6 +97,11 @@ struct btintel_pcie_dev_recovery {#define BTINTEL_PCIE_RESET_WINDOW_SECS 5#define BTINTEL_PCIE_FLR_MAX_RETRY 1 +#define BTINTEL_PCIE_TOP_RESET_INTERVAL_MS 250 +#define BTINTEL_PCIE_RESET_BUSY_RETRIES 25 +#define BTINTEL_PCIE_RESET_BUSY_DELAY_MS 20 +#define BTINTEL_PCIE_TOP_RESET_ROLE_SWITCH_MS 5000 +#define BTINTEL_PCIE_TOP_RESET_FALLBACK_MS 250/* Alive interrupt context */ enum {
@@ -658,6 +664,16 @@ static inline void btintel_pcie_dump_debug_registers(struct hci_dev *hdev) }static inline bool btintel_pcie_in_d3 (struct btintel_pcie_data *data); +static void btintel_pcie_reset_ia (struct btintel_pcie_data *data); +static int btintel_pcie_start_rx (struct btintel_pcie_data *data); +static void btintel_pcie_synchronize_irqs (struct btintel_pcie_data *data); +static struct btintel_pcie_dev_recovery * +btintel_pcie_get_recovery (struct pci_dev *pdev,struct device *dev); +static bool btintel_pcie_queue_reset (struct btintel_pcie_data *data, +enum btintel_pcie_reset_type type, +bool gated); +static bool btintel_pcie_request_reset (struct btintel_pcie_data *data, +enum btintel_pcie_reset_type type);static int btintel_pcie_send_sync (struct btintel_pcie_data *data,struct sk_buff *skb,u32 pkt_type,u16 opcode)
@@ -666,6 +682,7 @@ static int btintel_pcie_send_sync(struct btintel_pcie_data *data,u16 tfd_index;u32 old_ctxt;bool wait_on_alive = false; +bool top_rom = false;struct hci_dev *hdev = data->hdev;struct txq *txq = &data->txq;
@@ -687,7 +704,20 @@ static int btintel_pcie_send_sync(struct btintel_pcie_data *data, wait_on_alive = (pkt_type ==BTINTEL_PCIE_HCI_CMD_PKT && (opcode ==BTINTEL_HCI_OP_RESET || opcode ==HCI_OP_RESET )); -if (wait_on_alive) { +/* After TOP reset the controller is in ROM; no alive interrupt follows */ +if (wait_on_alive &&test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags)) { +u32 stage =btintel_pcie_rd_reg32 (data, +BTINTEL_PCIE_CSR_BOOT_STAGE_REG ); + + top_rom = (stage &BTINTEL_PCIE_CSR_BOOT_STAGE_ROM ) && + !(stage & (BTINTEL_PCIE_CSR_BOOT_STAGE_IML | +BTINTEL_PCIE_CSR_BOOT_STAGE_OPFW )); + } + +if (top_rom) { +/* Set before the doorbell so GP0 never sees a transient context */ + data->alive_intr_ctxt =BTINTEL_PCIE_FW_DL ; + }else if (wait_on_alive) { data->gp0_received = false; old_ctxt = data->alive_intr_ctxt; data->alive_intr_ctxt =
@@ -728,6 +758,18 @@ static int btintel_pcie_send_sync(struct btintel_pcie_data *data,return -ETIME ; } +if (top_rom) { +/* No alive interrupt follows in ROM, so do what the GP0 alive +* handler does for submit_rx. TX completion is flushed first; +* no RX event can be in flight until start_rx() reposts the +* buffers. +*/ +btintel_pcie_synchronize_irqs (data); +btintel_pcie_reset_ia (data); +btintel_pcie_start_rx (data); +return 0 ; + } +if (wait_on_alive) { ret = wait_event_timeout(data->gp0_wait_q, data->gp0_received,
@@ -2261,11 +2303,18 @@ static int btintel_parse_mbox_tlv(struct btintel_pcie_data *data)static void btintel_pcie_msix_gp1_handler (struct btintel_pcie_data *data) { +ktime_t calltime, delta, rettime; +unsigned long long duration; +bool top_reset_mbox = false;bool target_access = false; +bool mbox2_status;u32 addr =0 , size =0 ; + calltime =ktime_get (); +/* Read the Mail box status and registers */ data->mbox.mbox_status =btintel_pcie_rd_reg32 (data,BTINTEL_PCIE_CSR_MBOX_STATUS_REG ); + mbox2_status = data->mbox.mbox_status &BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX2 ;if (data->mbox.mbox_status &BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX1 ) { data->mbox.mbox1 =btintel_pcie_rd_reg32 (data,BTINTEL_PCIE_CSR_MBOX_1_REG ); if (data->mbox.mbox1 ==
@@ -2273,14 +2322,29 @@ static void btintel_pcie_msix_gp1_handler(struct btintel_pcie_data *data)if (data->log_mask &BTINTEL_PCIE_LOG_MBOX )bt_dev_info (data->hdev,"mailbox for target access" ); +clear_bit (BTINTEL_PCIE_TOP_RESET_MBOX1_PENDING , + &data->flags); target_access = true; + }else if (data->mbox.mbox1 ==BTINTEL_PCIE_TOP_SILENT_RESET ) { +if (mbox2_status) + top_reset_mbox = true; +else +set_bit (BTINTEL_PCIE_TOP_RESET_MBOX1_PENDING , + &data->flags); + }else { +clear_bit (BTINTEL_PCIE_TOP_RESET_MBOX1_PENDING , + &data->flags); } } -if (data->mbox.mbox_status &BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX2 ) { - data->mbox.mbox2 =btintel_pcie_rd_reg32 (data,BTINTEL_PCIE_CSR_MBOX_2_REG ); +if (mbox2_status) { + data->mbox.mbox2 =btintel_pcie_rd_reg32 (data, +BTINTEL_PCIE_CSR_MBOX_2_REG );if (target_access) addr = data->mbox.mbox2; +if (test_and_clear_bit (BTINTEL_PCIE_TOP_RESET_MBOX1_PENDING , + &data->flags)) + top_reset_mbox = true; }if (data->mbox.mbox_status &BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX3 ) {
@@ -2321,10 +2385,108 @@ static void btintel_pcie_msix_gp1_handler(struct btintel_pcie_data *data) } } +/* Handle SCU state change inline, just log it */ +if ((data->mbox.mbox_status &BTINTEL_PCIE_CSR_MBOX_STATUS_MBOX1 ) && + data->mbox.mbox1 ==BTINTEL_PCIE_CNVI_SCU_REG_MAIN_FSM_STICKY && + mbox2_status) { +if (data->mbox.mbox2 ==BTINTEL_PCIE_SCU_CORE_IDLE_SET ) +bt_dev_dbg (data->hdev,"TOP reset SCU CORE IDLE set" ); +if (data->mbox.mbox2 ==BTINTEL_PCIE_SCU_CORE_IDLE_RESET ) +bt_dev_dbg (data->hdev,"TOP reset SCU CORE IDLE reset" ); + } + +/* Handle TOP silent reset mbox notification inline */ +if (top_reset_mbox) { +u32 expires =BTINTEL_PCIE_TOP_RESET_INTERVAL_MS ; +struct hci_dev *hdev =READ_ONCE (data->hdev); +struct btintel_pcie_dev_recovery *rec; +u32 reg; + + rec =btintel_pcie_get_recovery (data->pdev, + hdev ? &hdev->dev :NULL ); +if (!rec) { +bt_dev_err (hdev, +"TOP reset: failed to get recovery data" ); + goto skip_top_reset; + } + +switch (data->mbox.mbox2) { +case BTINTEL_PCIE_TOP_RESET_WIFI_REQUEST : +bt_dev_info (hdev, +"TOP reset request from WiFi, triggering PLDR" ); +/* A WiFi request is part of its own TOP reset flow and +* must be answered, so it is not rate limited here. +*/ +set_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , + &rec->flags); +/* Order against the TOP_RESET and SETUP_DONE tests */ +smp_mb__after_atomic (); +if (!test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags)) { +bt_dev_info (hdev, +"BT is follower, triggering PLDR" ); +if (btintel_pcie_request_reset (data, +BTINTEL_PCIE_IOSF_PRR_PLDR )) +set_bit (BTINTEL_PCIE_CORE_HALTED , + &data->flags); + goto skip_top_reset; + } +set_bit (BTINTEL_PCIE_MBOX_TOP_RESET_FAILED , + &rec->flags); +break ; +case BTINTEL_PCIE_TOP_RESET_WIFI_ACK : +bt_dev_info (hdev,"TOP reset ack from WiFi" ); +break ; +case BTINTEL_PCIE_TOP_RESET_WIFI_NACK : +bt_dev_info (hdev,"TOP reset NACK from WiFi" ); +set_bit (BTINTEL_PCIE_MBOX_TOP_RESET_FAILED , &rec->flags); +break ; +case BTINTEL_PCIE_TOP_RESET_WIFI_REQ_ROLE_SWITCH : +bt_dev_info (hdev, +"TOP reset WIFI_REQ_ROLE_SWITCH" ); + expires =BTINTEL_PCIE_TOP_RESET_ROLE_SWITCH_MS ; + reg =btintel_pcie_rd_reg32 (data, +BTINTEL_PCIE_CSR_RESET_DEBUG_AD ); +if (reg ==BTINTEL_PCIE_TOP_RESET_DBG_RESET_REG ) +bt_dev_dbg (hdev, +"TOP reset initiated by WiFi" ); +break ; +case BTINTEL_PCIE_TOP_RESET_WIFI_NO_RESPONSE : +bt_dev_err (hdev,"TOP reset WIFI_NO_RESPONSE" ); +set_bit (BTINTEL_PCIE_MBOX_TOP_RESET_FAILED , &rec->flags); +break ; +case BTINTEL_PCIE_TOP_RESET_WIFI_RESPONSE_INVALID : +bt_dev_err (hdev, +"TOP reset WIFI_RESPONSE_INVALID" ); +set_bit (BTINTEL_PCIE_MBOX_TOP_RESET_FAILED , &rec->flags); +break ; +default : +bt_dev_err (hdev, +"TOP reset with undefined MBOX2 0x%8.8x" , + data->mbox.mbox2); +set_bit (BTINTEL_PCIE_MBOX_TOP_RESET_FAILED , &rec->flags); +break ; + } + +/* A later event must not shorten an earlier role switch timeout */ + expires =max (expires,READ_ONCE (data->top_reset_expires)); +WRITE_ONCE (data->top_reset_expires, expires); +smp_mb__before_atomic ();/* Publish expires before the flag */ +set_bit (BTINTEL_PCIE_MBOX_TOP_RESET , &rec->flags); +bt_dev_info (hdev, +"TOP reset timer expires in %u ms" , expires); +wake_up (&data->gp0_wait_q); + } + +skip_top_reset:/* Mailbox is read, ack to FW */ btintel_pcie_set_reg_bits (data,BTINTEL_PCIE_CSR_IPC_DOORBELL_VEC_REG ,BTINTEL_PCIE_CSR_DOORBELL_MBOX_READ_CONFIRM ); + + rettime =ktime_get (); + delta =ktime_sub (rettime, calltime); + duration =ktime_to_us (delta); +bt_dev_dbg (data->hdev,"Mailbox acked in %llu usecs" , duration); }/* This function handles the MSI-X interrupt for gp0 cause (bit 0 in
@@ -2381,9 +2543,9 @@ static void btintel_pcie_msix_gp0_handler(struct btintel_pcie_data *data) signal_waitq = true;break ;case BTINTEL_PCIE_FW_DL : -/* Error case is already handled. Ideally control shall not -* reach here -*/ +/* Wake the TOP reset boot-stage wait */ +if (test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags)) + signal_waitq = true;break ;case BTINTEL_PCIE_INTEL_HCI_RESET1 :if (btintel_pcie_in_op (data)) {
@@ -3504,6 +3666,7 @@ static struct btintel_pcie_causes_list causes_list[] = { { BTINTEL_PCIE_MSIX_FH_INT_CAUSES_0, BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK, 0x00 }, { BTINTEL_PCIE_MSIX_FH_INT_CAUSES_1, BTINTEL_PCIE_CSR_MSIX_FH_INT_MASK, 0x01 }, { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP0, BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK, 0x20 }, + { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP1, BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK, 0x21 }, { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_GP2, BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK, 0x22 }, { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_HWEXP, BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK, 0x23 }, { BTINTEL_PCIE_MSIX_HW_INT_CAUSES_FWTRIG, BTINTEL_PCIE_CSR_MSIX_HW_INT_MASK, 0x25 },
@@ -4310,17 +4473,166 @@ static int btintel_pcie_setup_internal(struct hci_dev *hdev,return err; } +static bool btintel_pcie_top_reset_done (struct btintel_pcie_data *data, +struct btintel_pcie_dev_recovery *rec) +{ +return !btintel_pcie_rd_reg32 (data,BTINTEL_PCIE_CSR_BOOT_STAGE_REG ) || +test_bit (BTINTEL_PCIE_MBOX_TOP_RESET_FAILED , &rec->flags); +} + +static int btintel_pcie_do_top_reset (struct btintel_pcie_data *data, +struct hci_dev *hdev) +{ +struct btintel_data *intel_data =hci_get_priv (hdev); +enum btintel_pcie_reset_type reset_type; +struct btintel_pcie_dev_recovery *rec; +u32 expires, latest; +long ret; +bool failed; +u32 reg; +int err; + + rec =btintel_pcie_get_recovery (data->pdev, &hdev->dev); +if (!rec) +return -ENOMEM ; + +/* Set scratch register to indicate TOP silent reset to FW */ +btintel_pcie_set_reg_bits (data,BTINTEL_PCIE_CSR_FUNC_SCRATCH_CSR , +BTINTEL_PCIE_CSR_FUNC_SCRATCH_TOP_SILENT_RESET ); + +/* Clear mbox flag before sending reset to avoid race with ISR */ +clear_bit (BTINTEL_PCIE_MBOX_TOP_RESET , &rec->flags); +clear_bit (BTINTEL_PCIE_MBOX_TOP_RESET_FAILED , &rec->flags); + +if (test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , &rec->flags)) { +bt_dev_info (hdev,"TOP reset: WiFi PLDR pending; doing PLDR" ); + reset_type =BTINTEL_PCIE_IOSF_PRR_PLDR ; + goto done; + } + +if (!intel_data->boot_addr) { +bt_dev_err (hdev,"TOP reset: no boot address; doing PLDR" ); + reset_type =BTINTEL_PCIE_IOSF_PRR_PLDR ; + goto done; + } + + err =btintel_send_intel_reset (hdev, intel_data->boot_addr); +if (err) { +bt_dev_err (hdev,"Intel Soft Reset failed (%d)" , err); + reset_type =BTINTEL_PCIE_IOSF_PRR_PLDR ; + goto done; + } + +/* First wait: wait for initial mbox event from FW */ + ret =wait_event_timeout (data->gp0_wait_q, +test_bit (BTINTEL_PCIE_MBOX_TOP_RESET , &rec->flags), +msecs_to_jiffies (BTINTEL_PCIE_TOP_RESET_FALLBACK_MS )); + +if (!ret) { +bt_dev_warn (hdev, +"TOP reset: no mbox received within %u ms; doing PLDR" , +BTINTEL_PCIE_TOP_RESET_FALLBACK_MS ); + reset_type =BTINTEL_PCIE_IOSF_PRR_PLDR ; + goto done; + } + +/* Second wait: mbox received, wait for boot_stage == 0 using the +* timeout determined by the GP1 handler based on mbox2. +*/ +smp_rmb ();/* Pairs with smp_mb__before_atomic() in the GP1 handler */ + expires =READ_ONCE (data->top_reset_expires); + ret =wait_event_timeout (data->gp0_wait_q, +btintel_pcie_top_reset_done (data, rec), +msecs_to_jiffies (expires)); + latest =READ_ONCE (data->top_reset_expires); +if (!ret && latest > expires) + ret =wait_event_timeout (data->gp0_wait_q, +btintel_pcie_top_reset_done (data, rec), +msecs_to_jiffies (latest - expires)); + + reg =btintel_pcie_rd_reg32 (data,BTINTEL_PCIE_CSR_BOOT_STAGE_REG ); +bt_dev_info (hdev,"After side band reset boot-stage: 0x%8.8x" , reg); + + failed =test_and_clear_bit (BTINTEL_PCIE_MBOX_TOP_RESET_FAILED , + &rec->flags) || +test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , &rec->flags); +if ((!ret && reg !=0 ) || failed) { +bt_dev_warn (hdev, +"TOP reset failed (boot_stage:0x%08x), triggering PLDR" , + reg); + reset_type =BTINTEL_PCIE_IOSF_PRR_PLDR ; + }else { + reset_type =BTINTEL_PCIE_IOSF_PRR_FLR ; + } + +done: +clear_bit (BTINTEL_PCIE_MBOX_TOP_RESET , &rec->flags); +btintel_clear_flag (hdev,INTEL_TOP_RESET ); +btintel_pcie_clr_reg_bits (data,BTINTEL_PCIE_CSR_FUNC_SCRATCH_CSR , +BTINTEL_PCIE_CSR_FUNC_SCRATCH_TOP_SILENT_RESET ); + +if (test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , &rec->flags)) + reset_type =BTINTEL_PCIE_IOSF_PRR_PLDR ; + +if (!btintel_pcie_queue_reset (data, reset_type, false)) { +/* No reprobe will follow; let a PLDR request through. Open the +* gate before dropping TOP_RESET so that a GP1 request cannot +* see both clear. +*/ +set_bit (BTINTEL_PCIE_PLDR_RETRY , &data->flags); +smp_mb__after_atomic ();/* Pairs with GP1 handler */ +clear_bit (BTINTEL_PCIE_TOP_RESET , &data->flags); +return -EIO ; + } + +/* Fail the open; reset_work reprobes the device */ +return -ECANCELED ; +} +static int btintel_pcie_setup (struct hci_dev *hdev) { -int err, fw_dl_retry =0 ;struct btintel_pcie_data *data =hci_get_drvdata (hdev); -bool fips_crc_failed; +struct btintel_pcie_dev_recovery *rec; +int err, fw_dl_retry =0 ; +bool pldr_retry, fips_crc_failed, reset_queued; +unsigned long flags; + +/* power_on can run before probe publishes hdev */ +WRITE_ONCE (data->hdev, hdev); + +/* Either a reset is queued, or the PLDR gate is closed before any +* async requester can queue one; queue_reset() tests both under the +* same lock. A queued reset reprobes the device and consumes the TOP +* reset intent kept in rec->flags, so leave it for the reprobed +* instance and keep the gate as it is. +*/ +spin_lock_irqsave (&data->reset_gate_lock, flags); + reset_queued =test_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , &data->flags); +if (!reset_queued) { +clear_bit (BTINTEL_PCIE_SETUP_FAILED , &data->flags); + pldr_retry =test_and_clear_bit (BTINTEL_PCIE_PLDR_RETRY , + &data->flags); + } +spin_unlock_irqrestore (&data->reset_gate_lock, flags); +if (reset_queued) +return -ECANCELED ; + +/* Restore TOP reset intent saved across device_reprobe() */ + rec =btintel_pcie_get_recovery (data->pdev, &hdev->dev); +if (rec &&test_and_clear_bit (BTINTEL_PCIE_REC_TOP_RESET_PENDING , + &rec->flags)) { +set_bit (BTINTEL_PCIE_TOP_RESET , &data->flags); +btintel_set_flag (hdev,INTEL_TOP_RESET ); + }btintel_pcie_fatal_err_load (data);while ((err =btintel_pcie_setup_internal (hdev, &fips_crc_failed)) && fw_dl_retry++ <1 ) { -if (fips_crc_failed) +if (err == -ENODEV || fips_crc_failed || pldr_retry || +test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags) || + (rec &&test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , + &rec->flags)))break ; bt_dev_err(hdev, "Firmware download retry count: %d",
@@ -4345,6 +4657,45 @@ static int btintel_pcie_setup(struct hci_dev *hdev)btintel_pcie_start_rx (data); } +if (err == -ECANCELED &&test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags)) +return btintel_pcie_do_top_reset (data, hdev); + +if (err) { +/* Open the PLDR gate before testing the WiFi request so that +* either this path or the GP1 handler queues the PLDR. Use +* SETUP_FAILED rather than PLDR_RETRY, which the next setup() +* would take as a failed PLDR and skip its firmware retry. +*/ +set_bit (BTINTEL_PCIE_SETUP_FAILED , &data->flags); +smp_mb__after_atomic ();/* Pairs with GP1 handler */ +/* The first lookup can fail; look again after the gate opens */ +if (!rec) + rec =btintel_pcie_get_recovery (data->pdev, &hdev->dev); +if (pldr_retry || +test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags) || + (rec &&test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , + &rec->flags))) { +bt_dev_err (hdev, +"TOP silent reset setup failed (%d), doing PLDR" , + err); +if (btintel_pcie_queue_reset (data, +BTINTEL_PCIE_IOSF_PRR_PLDR , + false)) { +if (rec && +test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , + &rec->flags)) +set_bit (BTINTEL_PCIE_CORE_HALTED , + &data->flags); +return -ECANCELED ; + } + +/* No reprobe will follow; a later reset must be PLDR */ +set_bit (BTINTEL_PCIE_PLDR_RETRY , &data->flags); +clear_bit (BTINTEL_PCIE_TOP_RESET , &data->flags); +btintel_clear_flag (hdev,INTEL_TOP_RESET ); + } + } +if (!err) {/* Fatal error test mode: arm the post-setup injection before * SETUP_DONE so the rfkill work cannot inject a fault ahead of
@@ -4352,7 +4703,24 @@ static int btintel_pcie_setup(struct hci_dev *hdev)*/ if (btintel_pcie_fatal_err_testmode_active (data))set_bit (BTINTEL_PCIE_FATAL_ERR_POST_SETUP_PENDING , &data->flags); +clear_bit (BTINTEL_PCIE_TOP_RESET , &data->flags); +btintel_clear_flag (hdev,INTEL_TOP_RESET );set_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags); +smp_mb__after_atomic ();/* Pairs with GP1 handler */ +if (!rec) + rec =btintel_pcie_get_recovery (data->pdev, &hdev->dev); +if (rec &&test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , + &rec->flags)) { +clear_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags); +if (btintel_pcie_queue_reset (data, +BTINTEL_PCIE_IOSF_PRR_PLDR , + false) || +test_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , + &data->flags)) +set_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags); +return -ECANCELED ; + } +set_bit (BTINTEL_PCIE_HW_RFKILL_STATE_CHECK , &data->flags);btintel_pcie_unmask_hw_rfkill (data);btintel_delayed_hw_rfkill (data, true);
@@ -4367,19 +4735,21 @@ static int btintel_pcie_setup(struct hci_dev *hdev)static struct btintel_pcie_dev_recovery *btintel_pcie_get_recovery (struct pci_dev *pdev,struct device *dev) { +struct hci_dev *hdev = dev ?to_hci_dev (dev) :NULL ;struct btintel_pcie_dev_recovery *tmp, *data =NULL ;const char *name =pci_name (pdev);const size_t name_len =strlen (name) +1 ; -struct hci_dev *hdev =to_hci_dev (dev); +unsigned long flags; -spin_lock (&btintel_pcie_recovery_lock); +/* Also called from the GP1 irq thread */ +spin_lock_irqsave (&btintel_pcie_recovery_lock, flags);list_for_each_entry (tmp, &btintel_pcie_recovery_list, list) {if (strcmp (tmp->name, name))continue ; data = tmp;break ; } -spin_unlock (&btintel_pcie_recovery_lock); +spin_unlock_irqrestore (&btintel_pcie_recovery_lock, flags);if (data) {bt_dev_dbg (hdev,"Found restart data for BDF: %s" , data->name);
@@ -4391,9 +4761,17 @@ btintel_pcie_get_recovery(struct pci_dev *pdev, struct device *dev)return NULL ;strscpy (data->name, name, name_len); -spin_lock (&btintel_pcie_recovery_lock); +spin_lock_irqsave (&btintel_pcie_recovery_lock, flags); +/* Recheck: another caller may have added this BDF meanwhile */ +list_for_each_entry (tmp, &btintel_pcie_recovery_list, list) { +if (strcmp (tmp->name, name)) +continue ; +spin_unlock_irqrestore (&btintel_pcie_recovery_lock, flags); +kfree (data); +return tmp; + }list_add_tail (&data->list, &btintel_pcie_recovery_list); -spin_unlock (&btintel_pcie_recovery_lock); +spin_unlock_irqrestore (&btintel_pcie_recovery_lock, flags);return data; }
@@ -4410,30 +4788,29 @@ static void btintel_pcie_free_restart_list(void) }static void btintel_pcie_inc_recovery_count (struct pci_dev *pdev, -struct device *dev) +struct device *dev,time64_t now) {struct btintel_pcie_dev_recovery *data; -time64_t retry_window; data =btintel_pcie_get_recovery (pdev, dev);if (!data)return ; - retry_window =ktime_get_boottime_seconds () - data->last_error; -if (data->count ==0 ) { - data->last_error =ktime_get_boottime_seconds (); - data->count++; - }else if (retry_window <BTINTEL_PCIE_RESET_WINDOW_SECS && - data->count <=BTINTEL_PCIE_FLR_MAX_RETRY ) { +/* An attempt after the window expired opens a new window, so that +* hw_error() can see it as the previous attempt. +*/ +if (data->count ==0 || + now - data->last_error >=BTINTEL_PCIE_RESET_WINDOW_SECS ) { + data->last_error = now; + data->count =1 ; + }else if (data->count <=BTINTEL_PCIE_FLR_MAX_RETRY ) { data->count++; - }else if (retry_window >BTINTEL_PCIE_RESET_WINDOW_SECS ) { - data->last_error =0 ; - data->count =0 ; } }#ifdef CONFIG_ACPI -static int btintel_pcie_acpi_reset_method (struct btintel_pcie_data *data) +static int btintel_pcie_acpi_reset_method (struct btintel_pcie_data *data, +struct pci_dev *wifi) {union acpi_object *obj, argv4;acpi_handle handle;
@@ -4464,6 +4841,21 @@ static int btintel_pcie_acpi_reset_method(struct btintel_pcie_data *data)return -ENODEV ; } +/* Unbind may hold the device lock while waiting for reset_work. */ +if (!pci_dev_trylock (data->pdev)) +return -EAGAIN ; + +if (wifi) { +pci_dev_unlock (data->pdev); +device_release_driver (&wifi->dev); +if (!pci_dev_trylock (data->pdev)) { +if (device_reprobe (&wifi->dev)) +BT_ERR ("WiFi reprobe failed for BDF:%s" , +pci_name (wifi)); +return -EAGAIN ; + } + } + argv4.buffer.type =ACPI_TYPE_BUFFER ; argv4.buffer.length =sizeof (mode); argv4.buffer.pointer = (void *)&mode;
@@ -4472,29 +4864,33 @@ static int btintel_pcie_acpi_reset_method(struct btintel_pcie_data *data) BTINTEL_PCIE_DSM_DYNAMIC_PLDR, &argv4);if (!obj) {bt_dev_err (data->hdev,"Failed to call dsm to set reset method" ); -return -EIO ; + ret = -EIO ; + goto out_unlock; }ACPI_FREE (obj); -pci_dev_lock (data->pdev);pci_save_state (data->pdev); ret =btintel_acpi_reset_method (hdev);if (ret)bt_dev_err (data->hdev,"ACPI _PRR reset failed (%d), PLDR incomplete" , ret);pci_restore_state (data->pdev); +out_unlock:pci_dev_unlock (data->pdev); +if (wifi &&device_reprobe (&wifi->dev)) +BT_ERR ("WiFi reprobe failed for BDF:%s" ,pci_name (wifi)); return ret; }#else -static int btintel_pcie_acpi_reset_method (struct btintel_pcie_data *data) +static int btintel_pcie_acpi_reset_method (struct btintel_pcie_data *data, +struct pci_dev *wifi) {bt_dev_err (data->hdev,"No support for ACPI, cold boot" );return -EOPNOTSUPP ; }#endif -static void btintel_pcie_perform_pldr (struct btintel_pcie_data *data) +static int btintel_pcie_perform_pldr (struct btintel_pcie_data *data) {struct pci_dev *pdev = data->pdev;struct pci_dev *wifi =NULL ;
@@ -4515,7 +4911,7 @@ static void btintel_pcie_perform_pldr(struct btintel_pcie_data *data) bus = pdev->bus;if (!bus) -return ; +return -ENODEV ;list_for_each_entry (tmp, &bus->devices, bus_list) {if (pci_match_id (wifi_device_ids, tmp)) {
@@ -4524,9 +4920,6 @@ static void btintel_pcie_perform_pldr(struct btintel_pcie_data *data) } } -if (wifi) -device_release_driver (&wifi->dev); -/* Wi-Fi is fully unbound before the reset and fully reprobed after * the normal PCI probe path handles all state setup from scratch. * BT needs pci_save_state()/pci_restore_state() because the BT driver
@@ -4534,18 +4927,25 @@ static void btintel_pcie_perform_pldr(struct btintel_pcie_data *data)* The PCI device needs to remain minimally functional so that * device_reprobe(&pdev->dev) can work afterward */ - ret =btintel_pcie_acpi_reset_method (data); + ret =btintel_pcie_acpi_reset_method (data, wifi); -if (wifi) { -if (device_reprobe (&wifi->dev)) -BT_ERR ("WiFi reprobe failed for BDF:%s" ,pci_name (wifi)); +if (wifi)pci_dev_put (wifi); - }if (!ret) { +struct btintel_pcie_dev_recovery *rec; + +/* This PLDR also reset WiFi; do not replay its request */ + rec =btintel_pcie_get_recovery (pdev, &data->hdev->dev); +if (rec) +clear_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , + &rec->flags); +if (device_reprobe (&pdev->dev))BT_ERR ("BT reprobe failed for BDF:%s" ,pci_name (pdev)); } + +return ret; }/*
@@ -4558,7 +4958,7 @@ static void btintel_pcie_perform_pldr(struct btintel_pcie_data *data)static int btintel_pcie_perform_flr (struct btintel_pcie_data *data) {struct pci_dev *pdev = data->pdev; -int err; +int err, reprobe_err;/* pci_try_reset_function() avoids the device_lock ABBA against * btintel_pcie_remove(): .remove() runs with device_lock held and
@@ -4573,20 +4973,86 @@ static int btintel_pcie_perform_flr(struct btintel_pcie_data *data) }/* device_reprobe() always detaches the driver first (running -* .remove(), which frees 'data'); any re-probe failure leaves the -* device unbound but 'data' is already gone, so just log it. +* .remove(), which frees 'data'). A failed probe leaves the device +* unbound without necessarily making device_reprobe() fail, so check +* the binding as well. 'data' is already gone, so just log it. */ -if (device_reprobe (&pdev->dev)) -BT_ERR ("BT reprobe failed for BDF:%s" ,pci_name (pdev)); + reprobe_err =device_reprobe (&pdev->dev); +if (reprobe_err || !device_is_bound (&pdev->dev)) { +struct btintel_pcie_dev_recovery *rec; + +BT_ERR ("BT reprobe failed for BDF:%s (%d)" ,pci_name (pdev), + reprobe_err); + +/* No setup() will consume the TOP reset intent */ + rec =btintel_pcie_get_recovery (pdev,NULL ); +if (rec) +clear_bit (BTINTEL_PCIE_REC_TOP_RESET_PENDING , + &rec->flags); + }return 0 ; } +/* No reprobe will follow a failed reset; undo the reset state */ +static void btintel_pcie_reset_failed (struct btintel_pcie_data *data) +{ +struct btintel_pcie_dev_recovery *rec; +bool top_reset; + + rec =btintel_pcie_get_recovery (data->pdev, &data->hdev->dev); + top_reset =test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags); + +/* SETUP_DONE is not set during a TOP reset reprobe; allow a PLDR retry +* so that later reset requests are not rejected. +*/ +if (data->reset_type ==BTINTEL_PCIE_IOSF_PRR_PLDR || top_reset) +set_bit (BTINTEL_PCIE_PLDR_RETRY , &data->flags); +if (rec) +clear_bit (BTINTEL_PCIE_REC_TOP_RESET_PENDING , &rec->flags); +clear_bit (BTINTEL_PCIE_TOP_RESET , &data->flags); +btintel_clear_flag (data->hdev,INTEL_TOP_RESET ); +enable_work (&data->coredump_work); +enable_work (&data->hwexp_work); +enable_work (&data->fwtrigger_work); +enable_work (&data->mbox_work); +enable_delayed_work (&data->user_dump_work); +enable_delayed_work (&data->hw_rfkill_work); +btintel_pcie_enable_interrupts (data); +if (test_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags)) +btintel_pcie_unmask_hw_rfkill (data); +clear_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , &data->flags); +smp_mb__after_atomic ();/* Pairs with GP1 handler */ + +if (data->reset_type !=BTINTEL_PCIE_IOSF_PRR_PLDR && + rec &&test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , &rec->flags) && +btintel_pcie_request_reset (data,BTINTEL_PCIE_IOSF_PRR_PLDR )) +set_bit (BTINTEL_PCIE_CORE_HALTED , &data->flags); +} + +/* The reset helpers only trylock the device to stay clear of remove(), so +* ride out brief PM or probe contention instead of giving up. On success the +* device is reprobed and 'data' is gone, so only the result is used. +*/ +static int btintel_pcie_reset_retry_busy (struct btintel_pcie_data *data, +int (*reset)(struct btintel_pcie_data *)) +{ +int err, i =0 ; + +while ((err =reset (data)) == -EAGAIN && + i++ <BTINTEL_PCIE_RESET_BUSY_RETRIES ) +msleep (BTINTEL_PCIE_RESET_BUSY_DELAY_MS ); + +return err; +} +static void btintel_pcie_reset_work (struct work_struct *wk) {struct btintel_pcie_data *data = container_of(wk, struct btintel_pcie_data, reset_work); +struct btintel_pcie_dev_recovery *rec;struct pci_dev *pdev = data->pdev; +int err;pci_lock_rescan_remove ();
@@ -4614,10 +5080,17 @@ static void btintel_pcie_reset_work(struct work_struct *wk)clear_bit (BTINTEL_PCIE_USER_TRIGGERED_DUMP , &data->flags);bt_dev_dbg (data->hdev,"Release bluetooth interface" ); + rec =btintel_pcie_get_recovery (pdev, + data->hdev ? &data->hdev->dev :NULL ); +if (rec &&test_bit (BTINTEL_PCIE_REC_WIFI_PLDR_PENDING , &rec->flags)) { +clear_bit (BTINTEL_PCIE_REC_TOP_RESET_PENDING , &rec->flags); + data->reset_type =BTINTEL_PCIE_IOSF_PRR_PLDR ; + } +/* Both reset paths follow the same contract: on success they * destroy 'data' via device_reprobe() (a fresh probe re-INIT_WORKs * the dump workers with disable count 0), so enable_work() must -* NOT be called on the success path. Only the FLR path can fail +* NOT be called on the success path. Either reset can fail * with 'data' still alive, in which case we balance the * disable_work_sync() calls above so a later successful reset is * not permanently blocked.
@@ -4627,17 +5100,27 @@ static void btintel_pcie_reset_work(struct work_struct *wk)* or removed from the bus list while this code runs. */ if (data->reset_type ==BTINTEL_PCIE_IOSF_PRR_PLDR ) { -btintel_pcie_perform_pldr (data); +if (btintel_pcie_reset_retry_busy (data, btintel_pcie_perform_pldr)) +btintel_pcie_reset_failed (data); goto out; } -if (btintel_pcie_perform_flr (data)) { -enable_work (&data->coredump_work); -enable_work (&data->hwexp_work); -enable_work (&data->fwtrigger_work); -enable_work (&data->mbox_work); -enable_delayed_work (&data->user_dump_work); -enable_delayed_work (&data->hw_rfkill_work); + err =btintel_pcie_reset_retry_busy (data, btintel_pcie_perform_flr); +if (err) { +if (err != -EAGAIN && +test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags)) { +bt_dev_warn (data->hdev, +"FLR failure after TOP silent reset, falling back to PLDR" ); + data->reset_type =BTINTEL_PCIE_IOSF_PRR_PLDR ; +if (rec) +clear_bit (BTINTEL_PCIE_REC_TOP_RESET_PENDING , + &rec->flags); +if (!btintel_pcie_reset_retry_busy (data, + btintel_pcie_perform_pldr)) + goto out; + } + +btintel_pcie_reset_failed (data); } out:
@@ -4645,6 +5128,17 @@ static void btintel_pcie_reset_work(struct work_struct *wk)pci_unlock_rescan_remove (); } +/* Before setup completes, only a PLDR is accepted: as a retry of a failed +* PLDR, or after a failed setup. +*/ +static bool btintel_pcie_retry_gate_open (struct btintel_pcie_data *data, +enum btintel_pcie_reset_type type) +{ +return type ==BTINTEL_PCIE_IOSF_PRR_PLDR && + (test_bit (BTINTEL_PCIE_PLDR_RETRY , &data->flags) || +test_bit (BTINTEL_PCIE_SETUP_FAILED , &data->flags)); +} +/* Schedule a device reset of the requested type. * * BTINTEL_PCIE_RECOVERY_IN_PROGRESS serializes all reset requesters
@@ -4662,24 +5156,85 @@ static void btintel_pcie_reset_work(struct work_struct *wk)* in-flight one (whose recovery will reinitialize the device * regardless of the dropped trigger's variant). * -* The bit is cleared only by .remove() / re-probe via fresh devm -* allocation, which is the intended one-shot semantics: a reset -* tears down and re-probes 'data', so there is no "in-flight" -* reset to follow up after device_reprobe() succeeds. +* A requester admitted before setup completed passes 'gated', so that the +* retry gate is tested again under the lock before it takes the bit. +* setup() closes the gate under the same lock: either the requester owns +* the bit first and setup() returns, or setup() runs first and the +* requester backs out. Exactly one of them proceeds, so reset_work never +* runs alongside setup(). +* +* Successful resets tear down and re-probe 'data'. On failure, +* reset_failed() releases the bit after restoring the recovery state. */ -static void btintel_pcie_request_reset (struct btintel_pcie_data *data, -enum btintel_pcie_reset_type type) +static bool btintel_pcie_queue_reset (struct btintel_pcie_data *data, +enum btintel_pcie_reset_type type, +bool gated) { -if (!test_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags)) -return ; +struct btintel_pcie_dev_recovery *rec =NULL ; +unsigned long flags; -if (test_and_set_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , &data->flags)) -return ; +spin_lock_irqsave (&data->reset_gate_lock, flags); +/* Test the gate first so the bit is never set just to be cleared */ +if (gated && !btintel_pcie_retry_gate_open (data, type)) { +spin_unlock_irqrestore (&data->reset_gate_lock, flags); +return false; + } + +if (test_and_set_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , &data->flags)) { +spin_unlock_irqrestore (&data->reset_gate_lock, flags); +return false; + } +spin_unlock_irqrestore (&data->reset_gate_lock, flags); + +if (type ==BTINTEL_PCIE_IOSF_TOP_RESET ) { + rec =btintel_pcie_get_recovery (data->pdev, &data->hdev->dev); +if (!rec) { +clear_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , + &data->flags); +return false; + } + +set_bit (BTINTEL_PCIE_TOP_RESET , &data->flags); +set_bit (BTINTEL_PCIE_REC_TOP_RESET_PENDING , &rec->flags); + } data->reset_type = type;pci_dev_get (data->pdev); -schedule_work (&data->reset_work); +if (!schedule_work (&data->reset_work)) { +pci_dev_put (data->pdev); +if (type ==BTINTEL_PCIE_IOSF_TOP_RESET ) { +clear_bit (BTINTEL_PCIE_TOP_RESET , &data->flags); +clear_bit (BTINTEL_PCIE_REC_TOP_RESET_PENDING , + &rec->flags); + } +clear_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , &data->flags); +return false; + } + +return true; +} + +static bool btintel_pcie_request_reset (struct btintel_pcie_data *data, +enum btintel_pcie_reset_type type) +{ +bool setup_done; + +/* Any failure during or after a TOP silent reset falls back to PLDR */ +if (test_bit (BTINTEL_PCIE_TOP_RESET , &data->flags) || +test_bit (BTINTEL_PCIE_PLDR_RETRY , &data->flags)) + type =BTINTEL_PCIE_IOSF_PRR_PLDR ; + + setup_done =test_bit (BTINTEL_PCIE_SETUP_DONE , &data->flags); + +/* Allow resets after setup completes, retries of a failed PLDR, or a +* PLDR after a failed setup. +*/ +if (!setup_done && !btintel_pcie_retry_gate_open (data, type)) +return false; + +/* Only a requester admitted by the retry gate must test it again */ +return btintel_pcie_queue_reset (data, type, !setup_done); }static void btintel_pcie_hci_reset (struct hci_dev *hdev)
@@ -4726,13 +5281,50 @@ static struct attribute *btintel_pcie_attrs[] = {ATTRIBUTE_GROUPS (btintel_pcie); +static const char *btintel_pcie_resettype_to_str (u8 reset_type) +{ +switch (reset_type) { +case BTINTEL_PCIE_IOSF_PRR_FLR : +return "FLR" ; +case BTINTEL_PCIE_IOSF_PRR_PLDR : +return "PLDR" ; +case BTINTEL_PCIE_IOSF_TOP_RESET : +return "TOP_RESET" ; +default : +return "UNKNOWN" ; + } +} + +static bool btintel_pcie_top_reset_supported (struct btintel_pcie_data *data) +{ +struct btintel_data *cnvi_data =hci_get_priv (data->hdev); +u8 hw_variant =INTEL_HW_VARIANT (cnvi_data->cnvi_bt); + +/* cnvi_bt stays 0 until the firmware download preparation has run; +* an unknown variant is treated as unsupported and uses PLDR. +*/ +if (hw_variant >=BTINTEL_HWID_SCP2 && + hw_variant !=BTINTEL_HWID_BZRIW && + data->pdev->subsystem_device ==BTINTEL_PCIE_SUBSYSTEM_ID_PEP ) { +bt_dev_info (data->hdev,"HW variant 0x%02x supports top-reset" , + hw_variant); +return true; + } + +bt_dev_dbg (data->hdev, +"HW variant 0x%02x does not support top-reset" , hw_variant); +return false; +} +static void btintel_pcie_hw_error (struct hci_dev *hdev,u8 code) { -struct btintel_pcie_dev_recovery *rec;struct btintel_pcie_data *dev_data =hci_get_drvdata (hdev); +struct btintel_pcie_dev_recovery *rec;struct pci_dev *pdev = dev_data->pdev;enum btintel_pcie_reset_type type; -time64_t retry_window; +time64_t now, retry_window; +bool top_reset; +int max_retry =BTINTEL_PCIE_FLR_MAX_RETRY ;if (test_bit (BTINTEL_PCIE_RECOVERY_IN_PROGRESS , &dev_data->flags))return ;
@@ -4743,25 +5335,41 @@ static void btintel_pcie_hw_error(struct hci_dev *hdev, u8 code)if (!rec)return ; - type = (code ==0x13 ) ?BTINTEL_PCIE_IOSF_PRR_PLDR - :BTINTEL_PCIE_IOSF_PRR_FLR ; + top_reset = code ==0x13 &&btintel_pcie_top_reset_supported (dev_data); +/* Share the timestamp with inc_recovery_count() so both agree on the +* window. +*/ + now =ktime_get_boottime_seconds (); + retry_window = now - rec->last_error; + +if (code !=0x13 ) { + type =BTINTEL_PCIE_IOSF_PRR_FLR ; + }else if (top_reset && !(retry_window <BTINTEL_PCIE_RESET_WINDOW_SECS && + rec->count)) { + type =BTINTEL_PCIE_IOSF_TOP_RESET ; + }else { + type =BTINTEL_PCIE_IOSF_PRR_PLDR ; +/* A repeated error right after a TOP reset gets one PLDR */ +if (top_reset) + max_retry++; + }bt_dev_err (hdev,"Encountered exception err:0x%x triggering: %s" , code, - type ==BTINTEL_PCIE_IOSF_PRR_PLDR ?"PLDR" :"FLR" ); - retry_window =ktime_get_boottime_seconds () - rec->last_error; +btintel_pcie_resettype_to_str (type));if (retry_window <BTINTEL_PCIE_RESET_WINDOW_SECS && - rec->count >=BTINTEL_PCIE_FLR_MAX_RETRY ) { + rec->count >= max_retry) {bt_dev_err (hdev,"Exhausted maximum: %d recovery attempts: %d" , -BTINTEL_PCIE_FLR_MAX_RETRY , rec->count); + max_retry, rec->count);bt_dev_dbg (hdev,"Boot time: %lld seconds" ,ktime_get_boottime_seconds ());bt_dev_dbg (hdev,"last error at: %lld seconds" , rec->last_error);return ; } -btintel_pcie_inc_recovery_count (pdev, &hdev->dev); -btintel_pcie_request_reset (dev_data, type); + +if (btintel_pcie_request_reset (dev_data, type)) +btintel_pcie_inc_recovery_count (pdev, &hdev->dev, now); }static bool btintel_pcie_wakeup (struct hci_dev *hdev)
@@ -4890,7 +5498,7 @@ static int btintel_pcie_setup_hdev(struct btintel_pcie_data *data)* worker bails on !data->hdev, so it never observes a half-set-up * device. */ - data->hdev = hdev; +WRITE_ONCE (data->hdev, hdev); data->dmp_hdr.driver_name =KBUILD_MODNAME ;return 0 ; }
@@ -4914,6 +5522,7 @@ static int btintel_pcie_probe(struct pci_dev *pdev,spin_lock_init (&data->irq_lock);spin_lock_init (&data->hci_rx_lock);spin_lock_init (&data->ipc_lock); +spin_lock_init (&data->reset_gate_lock);mutex_init (&data->rfkill_doorbell_lock);init_waitqueue_head (&data->gp0_wait_q);
@@ -5026,6 +5635,7 @@ static int btintel_pcie_probe(struct pci_dev *pdev,static void btintel_pcie_remove (struct pci_dev *pdev) { +struct btintel_pcie_dev_recovery *rec;struct btintel_pcie_data *data; data =pci_get_drvdata (pdev);
@@ -5049,9 +5659,21 @@ static void btintel_pcie_remove(struct pci_dev *pdev)* within the reset work itself (PLDR device_reprobe path) to avoid * deadlock. current_work() returns the work_struct of the caller if * we are in a workqueue context. +* +* If a queued reset_work is cancelled before it runs, release the +* pci_dev reference that it owned. The TOP reset intent is dropped +* either way, as no setup() will run to consume it. */ -if (current_work () != &data->reset_work) -disable_work_sync (&data->reset_work); +if (current_work () != &data->reset_work) { +if (disable_work_sync (&data->reset_work)) +pci_dev_put (pdev); + + rec =btintel_pcie_get_recovery (pdev, + data->hdev ? &data->hdev->dev :NULL ); +if (rec) +clear_bit (BTINTEL_PCIE_REC_TOP_RESET_PENDING , + &rec->flags); + }btintel_pcie_mask_hw_rfkill (data);btintel_pcie_synchronize_irqs (data);
drivers/bluetooth/btintel_pcie.h +37 -5
93 lines not on this page · raw message
Signature · 1 line
2.43.0