From 59325ffeed8da986068ec6dc70531212e88d9d6c Mon Sep 17 00:00:00 2001 From: Zhou Xiao Date: Mon, 13 Oct 2025 09:13:37 +0800 Subject: [PATCH] fix(ble): copy acl data by omdata buffer copy (cherry picked from commit 322eb33f0d19a7abdd8d430c6e742224fe3274f5) Co-authored-by: Zhou Xiao --- .../bt/common/ble_log/ble_log_spi_out.c | 31 ++++++++++++++----- .../bt/common/ble_log/ble_log_uhci_out.c | 27 ++++++++++++---- .../bt/common/ble_log/src/ble_log_lbm.c | 24 +++++++++++--- .../src/internal_include/ble_log_lbm.h | 1 + 4 files changed, 64 insertions(+), 19 deletions(-) diff --git a/components/bt/common/ble_log/ble_log_spi_out.c b/components/bt/common/ble_log/ble_log_spi_out.c index a5434f9677..d244143183 100644 --- a/components/bt/common/ble_log/ble_log_spi_out.c +++ b/components/bt/common/ble_log/ble_log_spi_out.c @@ -89,6 +89,10 @@ SPI_OUT_HCI_QUEUE_SIZE +\ SPI_OUT_MESH_QUEUE_SIZE) +#if SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER +#include "os/os_mbuf.h" +#endif /* SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER */ + // Private typedefs typedef struct { // CRITICAL: 0 for available, 1 for need queue (ISR), 2 for in queue @@ -156,6 +160,7 @@ enum { LL_LOG_FLAG_ISR, LL_LOG_FLAG_HCI, LL_LOG_FLAG_RAW, + LL_LOG_FLAG_OMDATA, LL_LOG_FLAG_HCI_UPSTREAM, }; @@ -205,7 +210,7 @@ static inline void spi_out_log_cb_append_trans(spi_out_log_cb_t *log_cb); static inline void spi_out_log_cb_flush_trans(spi_out_log_cb_t *log_cb); static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len, const uint8_t *addr_append, uint16_t len_append, uint8_t source, - bool with_checksum); + bool with_checksum, bool omdata); static void spi_out_log_cb_write_loss(spi_out_log_cb_t *log_cb); static void spi_out_log_cb_dump(spi_out_log_cb_t *log_cb); @@ -582,7 +587,7 @@ IRAM_ATTR static inline void spi_out_log_cb_flush_trans(spi_out_log_cb_t *log_cb // Return value: Need append IRAM_ATTR static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len, const uint8_t *addr_append, uint16_t len_append, uint8_t source, - bool with_checksum) + bool with_checksum, bool omdata) { spi_out_trans_cb_t *trans_cb = log_cb->trans_cb[log_cb->trans_cb_idx]; @@ -598,7 +603,16 @@ IRAM_ATTR static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8 memcpy(buf, (const uint8_t *)&head, SPI_OUT_FRAME_HEAD_LEN); memcpy(buf + SPI_OUT_FRAME_HEAD_LEN, addr, len); if (len_append && addr_append) { - memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append); +#if SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER + if (omdata) { + os_mbuf_copydata((struct os_mbuf *)addr_append, 0, + len_append, buf + SPI_OUT_FRAME_HEAD_LEN + len); + } + else +#endif /* SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER */ + { + memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append); + } } uint32_t checksum = 0; @@ -628,7 +642,7 @@ IRAM_ATTR static void spi_out_log_cb_write_loss(spi_out_log_cb_t *log_cb) .lost_bytes_cnt = log_cb->lost_bytes_cnt, }; spi_out_log_cb_write(log_cb, (const uint8_t *)&payload, sizeof(loss_payload_t), - NULL, 0, BLE_LOG_SPI_OUT_SOURCE_LOSS, true); + NULL, 0, BLE_LOG_SPI_OUT_SOURCE_LOSS, true, false); log_cb->lost_frame_cnt = 0; log_cb->lost_bytes_cnt = 0; @@ -756,9 +770,9 @@ static void spi_out_write_hex(spi_out_log_cb_t *log_cb, uint8_t source, if (with_ts) { uint32_t os_ts = pdTICKS_TO_MS(xTaskGetTickCount()); need_append |= spi_out_log_cb_write(log_cb, (const uint8_t *)&os_ts, - sizeof(uint32_t), addr, len, source, true); + sizeof(uint32_t), addr, len, source, true, false); } else { - need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0, source, true); + need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0, source, true, false); } } if (need_append) { @@ -1157,11 +1171,12 @@ IRAM_ATTR void ble_log_spi_out_ll_write(uint32_t len, const uint8_t *addr, uint3 log_cb = ll_task_log_cb; source = BLE_LOG_SPI_OUT_SOURCE_ESP; } + bool omdata = flag & BIT(LL_LOG_FLAG_OMDATA); bool need_append; if (spi_out_log_cb_check_trans(log_cb, (uint16_t)(len + len_append), &need_append)) { need_append |= spi_out_log_cb_write(log_cb, addr, (uint16_t)len, addr_append, - (uint16_t)len_append, source, true); + (uint16_t)len_append, source, true, omdata); } if (need_append) { if (in_isr) { @@ -1288,7 +1303,7 @@ IRAM_ATTR void ble_log_spi_out_le_audio_write(const uint8_t *addr, uint16_t len) bool need_append; if (spi_out_log_cb_check_trans(log_cb, len, &need_append)) { need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0, - BLE_LOG_SPI_OUT_SOURCE_LE_AUDIO, false); + BLE_LOG_SPI_OUT_SOURCE_LE_AUDIO, false, false); } if (need_append) { spi_out_log_cb_append_trans(log_cb); diff --git a/components/bt/common/ble_log/ble_log_uhci_out.c b/components/bt/common/ble_log/ble_log_uhci_out.c index 6a6727985a..d6c987bdbd 100644 --- a/components/bt/common/ble_log/ble_log_uhci_out.c +++ b/components/bt/common/ble_log/ble_log_uhci_out.c @@ -39,6 +39,10 @@ #define UHCI_OUT_LL_QUEUE_SIZE (3 * UHCI_OUT_PING_PONG_BUF_CNT) #define UHCI_OUT_QUEUE_SIZE (UHCI_OUT_USER_QUEUE_SIZE + UHCI_OUT_LL_QUEUE_SIZE) +#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER +#include "os/os_mbuf.h" +#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */ + // Private typedefs typedef struct { // This flag is for multithreading, must be a word, do not modify @@ -95,7 +99,8 @@ enum { LL_LOG_FLAG_ISR, LL_LOG_FLAG_HCI, LL_LOG_FLAG_RAW, - LL_LOG_FLAG_SYNC + LL_LOG_FLAG_OMDATA, + LL_LOG_FLAG_HCI_UPSTREAM, }; enum { @@ -136,7 +141,7 @@ static inline bool uhci_out_log_cb_check_trans(uhci_out_log_cb_t *log_cb, uint16 static inline void uhci_out_log_cb_append_trans(uhci_out_log_cb_t *log_cb); static inline void uhci_out_log_cb_flush_trans(uhci_out_log_cb_t *log_cb); static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len, - const uint8_t *addr_append, uint16_t len_append, uint8_t source); + const uint8_t *addr_append, uint16_t len_append, uint8_t source, bool omdata); static void uhci_out_log_cb_write_loss(uhci_out_log_cb_t *log_cb); static void uhci_out_log_cb_dump(uhci_out_log_cb_t *log_cb); @@ -318,7 +323,7 @@ IRAM_ATTR static inline void uhci_out_log_cb_flush_trans(uhci_out_log_cb_t *log_ // Return value: Need append IRAM_ATTR static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len, - const uint8_t *addr_append, uint16_t len_append, uint8_t source) + const uint8_t *addr_append, uint16_t len_append, uint8_t source, bool omdata) { uhci_out_trans_cb_t *trans_cb = log_cb->trans_cb[log_cb->trans_cb_idx]; @@ -334,7 +339,16 @@ IRAM_ATTR static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uin memcpy(buf, (const uint8_t *)&head, UHCI_OUT_FRAME_HEAD_LEN); memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN, addr, len); if (len_append && addr_append) { - memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append); +#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER + if (omdata) { + os_mbuf_copydata((struct os_mbuf *)addr_append, 0, + len_append, buf + UHCI_OUT_FRAME_HEAD_LEN + len); + } + else +#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */ + { + memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append); + } } uint32_t checksum = 0; @@ -365,7 +379,7 @@ IRAM_ATTR static void uhci_out_log_cb_write_loss(uhci_out_log_cb_t *log_cb) .lost_bytes_cnt = log_cb->lost_bytes_cnt, }; uhci_out_log_cb_write(log_cb, (const uint8_t *)&payload, sizeof(loss_payload_t), - NULL, 0, BLE_LOG_UHCI_OUT_SOURCE_LOSS); + NULL, 0, BLE_LOG_UHCI_OUT_SOURCE_LOSS, false); log_cb->lost_frame_cnt = 0; log_cb->lost_bytes_cnt = 0; @@ -676,12 +690,13 @@ IRAM_ATTR void ble_log_uhci_out_ll_write(uint32_t len, const uint8_t *addr, uint log_cb = ll_task_log_cb; source = BLE_LOG_UHCI_OUT_SOURCE_ESP; } + bool omdata = flag & BIT(LL_LOG_FLAG_OMDATA); bool need_append; uint16_t frame_len = len + len_append + UHCI_OUT_FRAME_OVERHEAD; if (uhci_out_log_cb_check_trans(log_cb, frame_len, &need_append)) { need_append |= uhci_out_log_cb_write(log_cb, addr, len, addr_append, - len_append, source); + len_append, source, omdata); } ll_last_write_ts = in_isr?\ diff --git a/components/bt/common/ble_log/src/ble_log_lbm.c b/components/bt/common/ble_log/src/ble_log_lbm.c index 109589a947..5078f2bad7 100644 --- a/components/bt/common/ble_log/src/ble_log_lbm.c +++ b/components/bt/common/ble_log/src/ble_log_lbm.c @@ -12,6 +12,10 @@ #include "ble_log_lbm.h" #include "ble_log_rt.h" +#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER +#include "os/os_mbuf.h" +#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */ + /* VARIABLE */ BLE_LOG_STATIC volatile uint32_t lbm_ref_count = 0; BLE_LOG_STATIC bool lbm_inited = false; @@ -25,7 +29,7 @@ BLE_LOG_STATIC void ble_log_lbm_release(ble_log_lbm_t *lbm); BLE_LOG_STATIC void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_code, const uint8_t *addr, uint16_t len, - const uint8_t *addr_append, uint16_t len_append); + const uint8_t *addr_append, uint16_t len_append, bool omdata); #if CONFIG_BLE_LOG_ENH_STAT_ENABLED BLE_LOG_STATIC void ble_log_stat_mgr_update(ble_log_src_t src_code, uint32_t len, bool lost); #endif /* CONFIG_BLE_LOG_ENH_STAT_ENABLED */ @@ -84,7 +88,7 @@ void ble_log_lbm_release(ble_log_lbm_t *lbm) BLE_LOG_IRAM_ATTR BLE_LOG_STATIC void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_code, const uint8_t *addr, uint16_t len, - const uint8_t *addr_append, uint16_t len_append) + const uint8_t *addr_append, uint16_t len_append, bool omdata) { /* Preparation before writing */ uint8_t *buf = (*trans)->buf + (*trans)->pos; @@ -102,7 +106,16 @@ void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_cod BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN, addr, len); } if (len_append) { - BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN + len, addr_append, len_append); +#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER + if (omdata) { + os_mbuf_copydata((struct os_mbuf *)addr_append, 0, + len_append, buf + BLE_LOG_FRAME_HEAD_LEN + len); + } + else +#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */ + { + BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN + len, addr_append, len_append); + } } /* Data integrity check */ @@ -429,7 +442,7 @@ bool ble_log_write_hex(ble_log_src_t src_code, const uint8_t *addr, size_t len) xTaskGetTickCountFromISR(): xTaskGetTickCount()); ble_log_lbm_write_trans(trans, src_code, (const uint8_t *)&os_ts, - sizeof(uint32_t), addr, len); + sizeof(uint32_t), addr, len, false); /* Release */ ble_log_lbm_release(lbm); @@ -467,6 +480,7 @@ void ble_log_write_hex_ll(uint32_t len, const uint8_t *addr, src_code = BLE_LOG_SRC_LL_TASK; use_ll_task = true; } + bool omdata = flag & BIT(BLE_LOG_LL_FLAG_OMDATA); if (!lbm_enabled) { goto exit; @@ -489,7 +503,7 @@ void ble_log_write_hex_ll(uint32_t len, const uint8_t *addr, } /* Write transport */ - ble_log_lbm_write_trans(trans, src_code, addr, len, addr_append, len_append); + ble_log_lbm_write_trans(trans, src_code, addr, len, addr_append, len_append, omdata); ble_log_lbm_release(lbm); BLE_LOG_REF_COUNT_RELEASE(&lbm_ref_count); diff --git a/components/bt/common/ble_log/src/internal_include/ble_log_lbm.h b/components/bt/common/ble_log/src/internal_include/ble_log_lbm.h index c3d79a6714..8f0e34ded0 100644 --- a/components/bt/common/ble_log/src/internal_include/ble_log_lbm.h +++ b/components/bt/common/ble_log/src/internal_include/ble_log_lbm.h @@ -158,6 +158,7 @@ enum { BLE_LOG_LL_FLAG_ISR, BLE_LOG_LL_FLAG_HCI, BLE_LOG_LL_FLAG_RAW, + BLE_LOG_LL_FLAG_OMDATA, BLE_LOG_LL_FLAG_HCI_UPSTREAM, }; #endif /* CONFIG_BLE_LOG_LL_ENABLED */