From 88de1dba44e0ad713a9ed40a1486e66216d9c716 Mon Sep 17 00:00:00 2001 From: Rajeev Kumar Date: Fri, 9 Mar 2018 15:00:36 -0800 Subject: [PATCH 1/2] qcacmn: Add common QDF API qdf_is_fw_down() to check fw status Add common QDF API qdf_is_fw_down() to check if FW is down. Change-Id: I8215665bec6975c8dd47ae3bb8423eeaaeba159c CRs-Fixed: 2202731 --- qdf/inc/qdf_platform.h | 58 ++++++++++++++++++++++++++ qdf/inc/qdf_util.h | 14 ------- qdf/src/{qdf_util.c => qdf_platform.c} | 15 ++++++- 3 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 qdf/inc/qdf_platform.h rename qdf/src/{qdf_util.c => qdf_platform.c} (78%) diff --git a/qdf/inc/qdf_platform.h b/qdf/inc/qdf_platform.h new file mode 100644 index 000000000000..2e288b19ba6f --- /dev/null +++ b/qdf/inc/qdf_platform.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018 The Linux Foundation. All rights reserved. + * + * Previously licensed under the ISC license by Qualcomm Atheros, Inc. + * + * + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted, provided that the + * above copyright notice and this permission notice appear in all + * copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * This file was originally distributed by Qualcomm Atheros, Inc. + * under proprietary terms before Copyright ownership was assigned + * to the Linux Foundation. + */ + +/** + * DOC: qdf_platform.h + * This file defines platform API abstractions. + */ + +#ifndef _QDF_PLATFORM_H +#define _QDF_PLATFORM_H + +/** + * qdf_is_fw_down_callback - callback to query if fw is down + * + * Return: true if fw is down and false if fw is not down + */ +typedef bool (*qdf_is_fw_down_callback)(void); + +/** + * qdf_register_fw_down_callback() - API to register fw down callback + * @is_fw_down: callback to query if fw is down or not + * + * Return: none + */ +void qdf_register_fw_down_callback(qdf_is_fw_down_callback is_fw_down); + +/** + * qdf_is_fw_down() - API to check if fw is down or not + * + * Return: true: if fw is down + * false: if fw is not down + */ +bool qdf_is_fw_down(void); +#endif /*_QDF_PLATFORM_H*/ diff --git a/qdf/inc/qdf_util.h b/qdf/inc/qdf_util.h index 5d219447cba5..36d45547be87 100644 --- a/qdf/inc/qdf_util.h +++ b/qdf/inc/qdf_util.h @@ -42,12 +42,6 @@ #endif typedef __qdf_wait_queue_head_t qdf_wait_queue_head_t; -/** - * qdf_is_fw_down_callback - callback to query if fw is down - * - * Return: true if fw is down and false if fw is not down - */ -typedef bool (*qdf_is_fw_down_callback)(void); /** * qdf_unlikely - Compiler-dependent macro denoting code likely to execute @@ -675,12 +669,4 @@ void qdf_get_random_bytes(void *buf, int nbytes) { return __qdf_get_random_bytes(buf, nbytes); } - -/** - * qdf_register_fw_down_callback() - API to register fw down callback - * @is_fw_down: callback to query if fw is down or not - * - * Return: none - */ -void qdf_register_fw_down_callback(qdf_is_fw_down_callback is_fw_down); #endif /*_QDF_UTIL_H*/ diff --git a/qdf/src/qdf_util.c b/qdf/src/qdf_platform.c similarity index 78% rename from qdf/src/qdf_util.c rename to qdf/src/qdf_platform.c index e6ddc1a5a8d9..9c3fb414c173 100644 --- a/qdf/src/qdf_util.c +++ b/qdf/src/qdf_platform.c @@ -17,7 +17,8 @@ */ #include "qdf_module.h" -#include "qdf_util.h" +#include "qdf_trace.h" +#include "qdf_platform.h" static qdf_is_fw_down_callback is_fw_down_cb; @@ -26,3 +27,15 @@ void qdf_register_fw_down_callback(qdf_is_fw_down_callback is_fw_down) is_fw_down_cb = is_fw_down; } qdf_export_symbol(qdf_register_fw_down_callback); + +bool qdf_is_fw_down(void) +{ + if (!is_fw_down_cb) { + QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, + "fw down callback is not registered"); + return false; + } + + return is_fw_down_cb(); +} +qdf_export_symbol(qdf_is_fw_down); From 9a94c9a29db03f5e92d3d689ad6b5b190dbc0c36 Mon Sep 17 00:00:00 2001 From: Dustin Brown Date: Tue, 13 Mar 2018 17:02:05 -0700 Subject: [PATCH 2/2] qcacmn: Rate limit logs based on elapsed time QDF_TRACE_RATE_LIMITED() currently rate limits by only printing every rate'th call to the function from the same location. Instead, prevent logging messages more than some constant 'k' times per second. This means any subsequent calls to the API from the same location within 1/k seconds will be dropped. Change-Id: I31a3f48f68fb6bc67f59f3157a635345943d3331 CRs-Fixed: 2205794 --- hif/inc/hif.h | 2 -- hif/src/hif_debug.h | 12 ++++++++++-- hif/src/sdio/hif_sdio_dev.c | 8 ++------ qdf/linux/src/i_qdf_trace.h | 26 +++++++++++++++++++------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/hif/inc/hif.h b/hif/inc/hif.h index 3df076e4fe55..4804549fae15 100644 --- a/hif/inc/hif.h +++ b/hif/inc/hif.h @@ -52,8 +52,6 @@ extern "C" { typedef void __iomem *A_target_id_t; typedef void *hif_handle_t; -#define HIF_DBG_PRINT_RATE 1000 - #define HIF_TYPE_AR6002 2 #define HIF_TYPE_AR6003 3 #define HIF_TYPE_AR6004 5 diff --git a/hif/src/hif_debug.h b/hif/src/hif_debug.h index a51437bebf31..8fa8508d11c2 100644 --- a/hif/src/hif_debug.h +++ b/hif/src/hif_debug.h @@ -1,9 +1,8 @@ /* - * Copyright (c) 2014, 2016 The Linux Foundation. All rights reserved. + * Copyright (c) 2014, 2016, 2018 The Linux Foundation. All rights reserved. * * Previously licensed under the ISC license by Qualcomm Atheros, Inc. * - * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all @@ -23,6 +22,15 @@ #define __HIF_DEBUG_H__ #include "qdf_trace.h" +#define __hif_log_rl(level, format, args...) \ + QDF_TRACE_RATE_LIMITED(QDF_MODULE_ID_HIF, level, FL(format), ## args) + +#define hif_alert_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_FATAL, params) +#define hif_err_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_ERROR, params) +#define hif_warn_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_WARN, params) +#define hif_info_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_INFO, params) +#define hif_debug_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_DEBUG, params) + #define HIF_ERROR(args ...) \ QDF_TRACE(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_ERROR, ## args) #define HIF_WARN(args ...) \ diff --git a/hif/src/sdio/hif_sdio_dev.c b/hif/src/sdio/hif_sdio_dev.c index a85a48a92a8b..8ad65dcf7e38 100644 --- a/hif/src/sdio/hif_sdio_dev.c +++ b/hif/src/sdio/hif_sdio_dev.c @@ -1,9 +1,8 @@ /* - * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved. + * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved. * * Previously licensed under the ISC license by Qualcomm Atheros, Inc. * - * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all @@ -190,10 +189,7 @@ HTC_PACKET *hif_dev_alloc_rx_buffer(struct hif_sdio_device *pdev) headsize = sizeof(HTC_PACKET); netbuf = qdf_nbuf_alloc(NULL, bufsize + headsize, 0, 4, false); if (netbuf == NULL) { - QDF_TRACE_RATE_LIMITED(HIF_DBG_PRINT_RATE, QDF_MODULE_ID_HIF, - QDF_TRACE_LEVEL_ERROR, - "(%s)Allocate netbuf failed\n", - __func__); + hif_err_rl("Allocate netbuf failed"); return NULL; } packet = (HTC_PACKET *) qdf_nbuf_data(netbuf); diff --git a/qdf/linux/src/i_qdf_trace.h b/qdf/linux/src/i_qdf_trace.h index aa3ac261ed6b..e1b27176c5b3 100644 --- a/qdf/linux/src/i_qdf_trace.h +++ b/qdf/linux/src/i_qdf_trace.h @@ -58,14 +58,26 @@ #define QDF_TRACE qdf_trace_msg #define QDF_VTRACE qdf_vtrace_msg #define QDF_TRACE_HEX_DUMP qdf_trace_hex_dump -#define QDF_TRACE_RATE_LIMITED(rate, module, level, format, ...)\ +#define QDF_MAX_LOGS_PER_SEC 2 +/** + * QDF_TRACE_RATE_LIMITED() - rate limited version of QDF_TRACE + * @params: parameters to pass through to QDF_TRACE + * + * This API prevents logging a message more than QDF_MAX_LOGS_PER_SEC times per + * second. This means any subsequent calls to this API from the same location + * within 1/QDF_MAX_LOGS_PER_SEC seconds will be dropped. + * + * Return: None + */ +#define QDF_TRACE_RATE_LIMITED(params...)\ do {\ - static int rate_limit;\ - rate_limit++;\ - if (rate)\ - if (0 == (rate_limit % rate))\ - qdf_trace_msg(module, level, format,\ - ##__VA_ARGS__);\ + static ulong __last_ticks;\ + ulong __ticks = jiffies;\ + if (time_after(__ticks,\ + __last_ticks + HZ / QDF_MAX_LOGS_PER_SEC)) {\ + QDF_TRACE(params);\ + __last_ticks = __ticks;\ + } \ } while (0) #else #define QDF_TRACE(arg ...)