From a7ae359debc01b4b5025fd8302ed61d4de2061a6 Mon Sep 17 00:00:00 2001 From: Yue Ma Date: Fri, 4 Dec 2020 14:06:03 -0800 Subject: [PATCH] cnss2: Use CONFIG_IPC_LOGGING to protect MSM IPC logging APIs This makes sure CNSS2 driver is able to work in non-MSM platforms which do not have IPC logging feature. Change-Id: I4c8fe3eb45e38fd106f47c28f0e4da82b0bdf76f Signed-off-by: Yue Ma --- drivers/net/wireless/cnss2/debug.c | 23 ++++++++++-- drivers/net/wireless/cnss2/debug.h | 9 ++++- drivers/net/wireless/cnss2/pci.c | 56 +++++++++++++++++++++--------- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/drivers/net/wireless/cnss2/debug.c b/drivers/net/wireless/cnss2/debug.c index d9f4d08fc2d4..df327ab72b67 100644 --- a/drivers/net/wireless/cnss2/debug.c +++ b/drivers/net/wireless/cnss2/debug.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -/* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. */ +/* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. */ #include #include @@ -11,8 +11,10 @@ #define MMIO_REG_ACCESS_MEM_TYPE 0xFF +#if IS_ENABLED(CONFIG_IPC_LOGGING) void *cnss_ipc_log_context; void *cnss_ipc_log_long_context; +#endif static int cnss_pin_connect_show(struct seq_file *s, void *data) { @@ -872,7 +874,8 @@ void cnss_debugfs_destroy(struct cnss_plat_data *plat_priv) } #endif -int cnss_debug_init(void) +#if IS_ENABLED(CONFIG_IPC_LOGGING) +static int cnss_ipc_logging_init(void) { cnss_ipc_log_context = ipc_log_context_create(CNSS_IPC_LOG_PAGES, "cnss", 0); @@ -892,7 +895,7 @@ int cnss_debug_init(void) return 0; } -void cnss_debug_deinit(void) +static void cnss_ipc_logging_deinit(void) { if (cnss_ipc_log_long_context) { ipc_log_context_destroy(cnss_ipc_log_long_context); @@ -904,3 +907,17 @@ void cnss_debug_deinit(void) cnss_ipc_log_context = NULL; } } +#else +static int cnss_ipc_logging_init(void) { return 0; } +static void cnss_ipc_logging_deinit(void) {} +#endif + +int cnss_debug_init(void) +{ + return cnss_ipc_logging_init(); +} + +void cnss_debug_deinit(void) +{ + cnss_ipc_logging_deinit(); +} diff --git a/drivers/net/wireless/cnss2/debug.h b/drivers/net/wireless/cnss2/debug.h index 6ba436f5dc03..da298d7fbf7a 100644 --- a/drivers/net/wireless/cnss2/debug.h +++ b/drivers/net/wireless/cnss2/debug.h @@ -1,12 +1,15 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -/* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved. */ +/* Copyright (c) 2016-2021, The Linux Foundation. All rights reserved. */ #ifndef _CNSS_DEBUG_H #define _CNSS_DEBUG_H +#if IS_ENABLED(CONFIG_IPC_LOGGING) #include +#endif #include +#if IS_ENABLED(CONFIG_IPC_LOGGING) #define CNSS_IPC_LOG_PAGES 32 extern void *cnss_ipc_log_context; @@ -17,6 +20,10 @@ extern void *cnss_ipc_log_long_context; #define cnss_ipc_log_long_string(_x...) \ ipc_log_string(cnss_ipc_log_long_context, _x) +#else +#define cnss_ipc_log_string(_x...) +#define cnss_ipc_log_long_string(_x...) +#endif #define cnss_pr_err(_fmt, ...) do { \ printk("%scnss: " _fmt, KERN_ERR, ##__VA_ARGS__); \ diff --git a/drivers/net/wireless/cnss2/pci.c b/drivers/net/wireless/cnss2/pci.c index 5fefdf81e8af..5abfdca8efe9 100644 --- a/drivers/net/wireless/cnss2/pci.c +++ b/drivers/net/wireless/cnss2/pci.c @@ -4914,6 +4914,42 @@ static int cnss_mhi_bw_scale(struct mhi_controller *mhi_ctrl, return 0; } +#if IS_ENABLED(CONFIG_IPC_LOGGING) +static int cnss_pci_mhi_ipc_logging_init(struct cnss_pci_data *pci_priv) +{ + struct mhi_controller *mhi_ctrl = pci_priv->mhi_ctrl; + + mhi_ctrl->log_buf = ipc_log_context_create(CNSS_IPC_LOG_PAGES, + "cnss-mhi", 0); + if (!mhi_ctrl->log_buf) + cnss_pr_err("Unable to create CNSS MHI IPC log context\n"); + + mhi_ctrl->cntrl_log_buf = ipc_log_context_create(CNSS_IPC_LOG_PAGES, + "cnss-mhi-cntrl", 0); + if (!mhi_ctrl->cntrl_log_buf) + cnss_pr_err("Unable to create CNSS MHICNTRL IPC log context\n"); + + return 0; +} + +static void cnss_pci_mhi_ipc_logging_deinit(struct cnss_pci_data *pci_priv) +{ + struct mhi_controller *mhi_ctrl = pci_priv->mhi_ctrl; + + if (mhi_ctrl->log_buf) + ipc_log_context_destroy(mhi_ctrl->log_buf); + if (mhi_ctrl->cntrl_log_buf) + ipc_log_context_destroy(mhi_ctrl->cntrl_log_buf); +} +#else +static int cnss_pci_mhi_ipc_logging_init(struct cnss_pci_data *pci_priv) +{ + return 0; +} + +static void cnss_pci_mhi_ipc_logging_deinit(struct cnss_pci_data *pci_priv) {} +#endif + static int cnss_pci_register_mhi(struct cnss_pci_data *pci_priv) { int ret = 0; @@ -4978,15 +5014,7 @@ static int cnss_pci_register_mhi(struct cnss_pci_data *pci_priv) mhi_ctrl->fbc_download = true; mhi_ctrl->rddm_supported = true; - mhi_ctrl->log_buf = ipc_log_context_create(CNSS_IPC_LOG_PAGES, - "cnss-mhi", 0); - if (!mhi_ctrl->log_buf) - cnss_pr_err("Unable to create CNSS MHI IPC log context\n"); - - mhi_ctrl->cntrl_log_buf = ipc_log_context_create(CNSS_IPC_LOG_PAGES, - "cnss-mhi-cntrl", 0); - if (!mhi_ctrl->cntrl_log_buf) - cnss_pr_err("Unable to create CNSS MHICNTRL IPC log context\n"); + cnss_pci_mhi_ipc_logging_init(pci_priv); ret = of_register_mhi_controller(mhi_ctrl); if (ret) { @@ -5003,10 +5031,7 @@ static int cnss_pci_register_mhi(struct cnss_pci_data *pci_priv) unreg_mhi: mhi_unregister_mhi_controller(mhi_ctrl); destroy_ipc: - if (mhi_ctrl->log_buf) - ipc_log_context_destroy(mhi_ctrl->log_buf); - if (mhi_ctrl->cntrl_log_buf) - ipc_log_context_destroy(mhi_ctrl->cntrl_log_buf); + cnss_pci_mhi_ipc_logging_deinit(pci_priv); kfree(mhi_ctrl->irq); free_mhi_ctrl: mhi_free_controller(mhi_ctrl); @@ -5022,10 +5047,7 @@ static void cnss_pci_unregister_mhi(struct cnss_pci_data *pci_priv) return; mhi_unregister_mhi_controller(mhi_ctrl); - if (mhi_ctrl->log_buf) - ipc_log_context_destroy(mhi_ctrl->log_buf); - if (mhi_ctrl->cntrl_log_buf) - ipc_log_context_destroy(mhi_ctrl->cntrl_log_buf); + cnss_pci_mhi_ipc_logging_deinit(pci_priv); kfree(mhi_ctrl->irq); mhi_free_controller(mhi_ctrl); }