From 89985878911e80cb5635d6ccd0882c20ada4b1e8 Mon Sep 17 00:00:00 2001 From: Balakrishna Godavarthi Date: Tue, 20 Jun 2023 20:46:07 +0530 Subject: [PATCH] btfmcodec: Enable Dynamic logging This change will enable dynamic logging based on below flags Below bit has to be set to enable respective logging. * Bit 0: Error message. * Bit 1: Warning message. * Bit 2: Debug message. * Bit 3: Info message. * 0x08 is similar to 0x0F. * 0x04 is similar to 0x07. * 0x02 is similar to 0x03. * 0x03 is default log level for BTFM Codec. Change-Id: Ia986a49f73d6144f2631936b8d02985d3ccf98d0 Signed-off-by: Balakrishna Godavarthi --- btfmcodec/btfm_codec.c | 11 +++++++++++ btfmcodec/include/btfm_codec.h | 18 ++++++++++++++++-- btfmcodec/include/btfm_codec_pkt.h | 18 ++++++++++-------- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/btfmcodec/btfm_codec.c b/btfmcodec/btfm_codec.c index 6b62f91936..aeb1130491 100644 --- a/btfmcodec/btfm_codec.c +++ b/btfmcodec/btfm_codec.c @@ -23,6 +23,7 @@ static dev_t dev_major; struct btfmcodec_data *btfmcodec; struct device_driver driver = {.name = "btfmcodec-driver", .owner = THIS_MODULE}; struct btfmcodec_char_device *btfmcodec_dev; + #define cdev_to_btfmchardev(_cdev) container_of(_cdev, struct btfmcodec_char_device, cdev) #define MIN_PKT_LEN 0x9 @@ -214,6 +215,16 @@ static void btfmcodec_dev_rxwork(struct work_struct *work) status); wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]); break; + case BTM_BTFMCODEC_CTRL_LOG_LVL_IND: + if (len == BTM_LOG_LVL_IND_LEN) { + log_lvl = skb->data[0]; + } else { + BTFMCODEC_ERR("wrong packet format with len:%d", len); + } + BTFMCODEC_INFO("Rx BTM_BTFMCODEC_CTRL_LOG_LVL_IND status:%d", + log_lvl); + wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]); + break; default: BTFMCODEC_ERR("wrong opcode:%08x", opcode); } diff --git a/btfmcodec/include/btfm_codec.h b/btfmcodec/include/btfm_codec.h index 4ed3ecea44..2f05639a78 100644 --- a/btfmcodec/include/btfm_codec.h +++ b/btfmcodec/include/btfm_codec.h @@ -13,10 +13,24 @@ #include #include "btfm_codec_hw_interface.h" -#define BTFMCODEC_DBG(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg) -#define BTFMCODEC_INFO(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg) +#define BTM_BTFMCODEC_DEFAULT_LOG_LVL 0x03 +#define BTM_BTFMCODEC_DEBUG_LOG_LVL 0x04 +#define BTM_BTFMCODEC_INFO_LOG_LVL 0x08 + +static uint8_t log_lvl = BTM_BTFMCODEC_DEFAULT_LOG_LVL; + #define BTFMCODEC_ERR(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg) #define BTFMCODEC_WARN(fmt, arg...) pr_warn("%s: " fmt "\n", __func__, ## arg) +#define BTFMCODEC_DBG(fmt, arg...) { if(log_lvl >= BTM_BTFMCODEC_DEBUG_LOG_LVL) \ + pr_err("%s: " fmt "\n", __func__, ## arg); \ + else \ + pr_debug("%s: " fmt "\n", __func__, ## arg); \ + } +#define BTFMCODEC_INFO(fmt, arg...) { if(log_lvl >= BTM_BTFMCODEC_INFO_LOG_LVL) \ + pr_err("%s: " fmt "\n", __func__, ## arg);\ + else \ + pr_info("%s: " fmt "\n", __func__, ## arg);\ + } #define DEVICE_NAME_MAX_LEN 64 diff --git a/btfmcodec/include/btfm_codec_pkt.h b/btfmcodec/include/btfm_codec_pkt.h index e8e83f7710..12f604bc60 100644 --- a/btfmcodec/include/btfm_codec_pkt.h +++ b/btfmcodec/include/btfm_codec_pkt.h @@ -32,14 +32,15 @@ struct btm_ctrl_pkt { uint8_t status; }__attribute__((packed)); -#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_REQ 0x50000000 -#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_RSP 0x50000001 -#define BTM_BTFMCODEC_MASTER_CONFIG_REQ 0x50000002 -#define BTM_BTFMCODEC_MASTER_CONFIG_RSP 0x50000003 -#define BTM_BTFMCODEC_MASTER_SHUTDOWN_REQ 0x50000004 -#define BTM_BTFMCODEC_CTRL_MASTER_SHUTDOWN_RSP 0x50000005 -#define BTM_BTFMCODEC_BEARER_SWITCH_IND 0x58000001 -#define BTM_BTFMCODEC_TRANSPORT_SWITCH_FAILED_IND 0x58000002 +#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_REQ 0x50000000 +#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_RSP 0x50000001 +#define BTM_BTFMCODEC_MASTER_CONFIG_REQ 0x50000002 +#define BTM_BTFMCODEC_MASTER_CONFIG_RSP 0x50000003 +#define BTM_BTFMCODEC_MASTER_SHUTDOWN_REQ 0x50000004 +#define BTM_BTFMCODEC_CTRL_MASTER_SHUTDOWN_RSP 0x50000005 +#define BTM_BTFMCODEC_BEARER_SWITCH_IND 0x58000001 +#define BTM_BTFMCODEC_TRANSPORT_SWITCH_FAILED_IND 0x58000002 +#define BTM_BTFMCODEC_CTRL_LOG_LVL_IND 0x58000004 #define BTM_MASTER_CONFIG_REQ_LEN 13 #define BTM_MASTER_CONFIG_RSP_TIMEOUT 5000 @@ -49,6 +50,7 @@ struct btm_ctrl_pkt { #define BTM_MASTER_SHUTDOWN_REQ_LEN 1 #define BTM_PREPARE_AUDIO_BEARER_SWITCH_REQ_LEN 1 #define BTM_BEARER_SWITCH_IND_LEN 1 +#define BTM_LOG_LVL_IND_LEN 1 enum rx_status { /* Waiting for response */