From a8d8b663b2d3e8bd33ed08033faa1407c339d0fd Mon Sep 17 00:00:00 2001 From: Pragaspathi Thilagaraj Date: Tue, 14 Sep 2021 15:50:06 +0530 Subject: [PATCH] qcacmn: Define QDF API for vzalloc and vfree Define QDF API for virtual memory allocation and free. Also add new api to get time of the day in microseconds. Change-Id: I2921055bbb6b5d2a1105d19448b2a10fa2d6ccc5 CRs-Fixed: 3038180 --- qdf/inc/qdf_mc_timer.h | 9 ++- qdf/inc/qdf_mem.h | 17 +++++ qdf/linux/src/i_qdf_mem.h | 18 +++++ qdf/linux/src/qdf_mc_timer.c | 90 ++++++++++++++--------- qdf/linux/src/qdf_mem.c | 25 +++++++ qdf/linux/src/qdf_trace.c | 12 +-- utils/fwlog/dbglog_host.c | 6 +- utils/logging/src/wlan_logging_sock_svc.c | 10 +-- utils/logging/src/wlan_roam_debug.c | 4 +- utils/pktlog/linux_ac.c | 4 +- 10 files changed, 140 insertions(+), 55 deletions(-) diff --git a/qdf/inc/qdf_mc_timer.h b/qdf/inc/qdf_mc_timer.h index 5d94df6d98..d5862074d7 100644 --- a/qdf/inc/qdf_mc_timer.h +++ b/qdf/inc/qdf_mc_timer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2019, 2021 The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -284,6 +284,13 @@ s64 qdf_get_monotonic_boottime_ns(void); */ void qdf_timer_module_init(void); +/** + * qdf_get_time_of_the_day_us() - Get time of the day in microseconds + * + * Return: None + */ +uint64_t qdf_get_time_of_the_day_us(void); + /** * qdf_get_time_of_the_day_ms() - get time of the day in millisec * diff --git a/qdf/inc/qdf_mem.h b/qdf/inc/qdf_mem.h index 59787f6864..b47eb29d41 100644 --- a/qdf/inc/qdf_mem.h +++ b/qdf/inc/qdf_mem.h @@ -1183,4 +1183,21 @@ int32_t qdf_mem_dp_rx_skb_max_cnt_read(void); void qdf_mem_tx_desc_cnt_update(qdf_atomic_t pending_tx_descs, int32_t tx_descs_max); +/** + * qdf_mem_vfree() - Free the virtual memory pointed to by ptr + * @ptr: Pointer to the starting address of the memory to + * be freed. + * + * Return: None + */ +#define qdf_mem_vfree(ptr) __qdf_mem_vfree(ptr) + +/** + * qdf_mem_valloc() - Allocate virtual memory for the given + * size + * @size: Number of bytes of memory to be allocated + * + * Return: Pointer to the starting address of the allocated virtual memory + */ +#define qdf_mem_valloc(size) __qdf_mem_valloc(size, __func__, __LINE__) #endif /* __QDF_MEMORY_H */ diff --git a/qdf/linux/src/i_qdf_mem.h b/qdf/linux/src/i_qdf_mem.h index 3fa74c39fd..a6aae939ee 100644 --- a/qdf/linux/src/i_qdf_mem.h +++ b/qdf/linux/src/i_qdf_mem.h @@ -495,6 +495,24 @@ void *__qdf_mem_malloc(qdf_size_t size, const char *func, uint32_t line); */ void __qdf_mem_free(void *ptr); +/** + * __qdf_mem_valloc() - QDF virtual memory allocation API + * @size: Number of bytes of virtual memory to allocate. + * @func: Caller function name + * @line: Line number + * + * Return: A valid memory location on success, or NULL on failure + */ +void *__qdf_mem_valloc(size_t size, const char *func, uint32_t line); + +/** + * __qdf_mem_vfree() - QDF API to free virtual memory + * @ptr: Pointer to the virtual memory to free + * + * Return: None + */ +void __qdf_mem_vfree(void *ptr); + #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI /** * __qdf_untracked_mem_malloc() - allocates non-QDF memory diff --git a/qdf/linux/src/qdf_mc_timer.c b/qdf/linux/src/qdf_mc_timer.c index 029ee2bbe4..6926702481 100644 --- a/qdf/linux/src/qdf_mc_timer.c +++ b/qdf/linux/src/qdf_mc_timer.c @@ -856,42 +856,6 @@ s64 qdf_get_monotonic_boottime_ns(void) } qdf_export_symbol(qdf_get_monotonic_boottime_ns); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) -qdf_time_t qdf_get_time_of_the_day_ms(void) -{ - struct timespec64 tv; - qdf_time_t local_time; - struct rtc_time tm; - - ktime_get_real_ts64(&tv); - local_time = (qdf_time_t)(tv.tv_sec - (sys_tz.tz_minuteswest * 60)); - rtc_time64_to_tm(local_time, &tm); - - return (tm.tm_hour * 60 * 60 * 1000) + - (tm.tm_min * 60 * 1000) + (tm.tm_sec * 1000) + - (tv.tv_nsec / 1000000); -} - -qdf_export_symbol(qdf_get_time_of_the_day_ms); - -#else -qdf_time_t qdf_get_time_of_the_day_ms(void) -{ - struct timeval tv; - qdf_time_t local_time; - struct rtc_time tm; - - do_gettimeofday(&tv); - local_time = (qdf_time_t)(tv.tv_sec - (sys_tz.tz_minuteswest * 60)); - rtc_time_to_tm(local_time, &tm); - - return (tm.tm_hour * 60 * 60 * 1000) + - (tm.tm_min * 60 * 1000) + (tm.tm_sec * 1000) + - (tv.tv_usec / 1000); -} -qdf_export_symbol(qdf_get_time_of_the_day_ms); -#endif - /** * qdf_timer_module_deinit() - Deinitializes a QDF timer module. * @@ -925,6 +889,27 @@ void qdf_get_time_of_the_day_in_hr_min_sec_usec(char *tbuf, int len) qdf_export_symbol(qdf_get_time_of_the_day_in_hr_min_sec_usec); +uint64_t qdf_get_time_of_the_day_us(void) +{ + struct timespec64 tv; + struct rtc_time tm; + unsigned long local_time; + uint64_t time_of_day_us = 0; + + ktime_get_real_ts64(&tv); + /* Convert rtc to local time */ + local_time = (u32)(tv.tv_sec - (sys_tz.tz_minuteswest * 60)); + rtc_time64_to_tm(local_time, &tm); + + time_of_day_us += (uint64_t)tm.tm_hour * 60 * 60 * 1000 * 1000; + time_of_day_us += (uint64_t)tm.tm_min * 60 * 1000 * 1000; + time_of_day_us += (uint64_t)tm.tm_sec * 1000 * 1000; + time_of_day_us += qdf_do_div((uint64_t)tv.tv_nsec, 1000); + + return time_of_day_us; +} + +qdf_export_symbol(qdf_get_time_of_the_day_us); #else void qdf_get_time_of_the_day_in_hr_min_sec_usec(char *tbuf, int len) { @@ -942,4 +927,37 @@ void qdf_get_time_of_the_day_in_hr_min_sec_usec(char *tbuf, int len) tm.tm_hour, tm.tm_min, tm.tm_sec, tv.tv_usec); } qdf_export_symbol(qdf_get_time_of_the_day_in_hr_min_sec_usec); + +uint64_t qdf_get_time_of_the_day_us(void) +{ + struct timeval tv; + struct rtc_time tm; + unsigned long local_time; + uint64_t time_of_day_us = 0; + + do_gettimeofday(&tv); + /* Convert rtc to local time */ + local_time = (u32)(tv.tv_sec - (sys_tz.tz_minuteswest * 60)); + rtc_time_to_tm(local_time, &tm); + + time_of_day_us += (uint64_t)tm.tm_hour * 60 * 60 * 1000 * 1000; + time_of_day_us += (uint64_t)tm.tm_min * 60 * 1000 * 1000; + time_of_day_us += (uint64_t)tm.tm_sec * 1000 * 1000; + time_of_day_us += (uint64_t)tv.tv_usec; + + return time_of_day_us; +} + +qdf_export_symbol(qdf_get_time_of_the_day_us); #endif + +qdf_time_t qdf_get_time_of_the_day_ms(void) +{ + qdf_time_t time_of_the_day_ms; + + time_of_the_day_ms = qdf_do_div(qdf_get_time_of_the_day_us(), 1000); + + return time_of_the_day_ms; +} + +qdf_export_symbol(qdf_get_time_of_the_day_ms); diff --git a/qdf/linux/src/qdf_mem.c b/qdf/linux/src/qdf_mem.c index ac4a076517..09e1ead629 100644 --- a/qdf/linux/src/qdf_mem.c +++ b/qdf/linux/src/qdf_mem.c @@ -2856,3 +2856,28 @@ void qdf_mem_stats_init(void) qdf_export_symbol(qdf_mem_stats_init); +void *__qdf_mem_valloc(size_t size, const char *func, uint32_t line) +{ + void *ptr; + + if (!size) { + qdf_err("Valloc called with 0 bytes @ %s:%d", func, line); + return NULL; + } + + ptr = vzalloc(size); + + return ptr; +} + +qdf_export_symbol(__qdf_mem_valloc); + +void __qdf_mem_vfree(void *ptr) +{ + if (qdf_unlikely(!ptr)) + return; + + vfree(ptr); +} + +qdf_export_symbol(__qdf_mem_vfree); diff --git a/qdf/linux/src/qdf_trace.c b/qdf/linux/src/qdf_trace.c index 9283e2189e..6326ccd648 100644 --- a/qdf/linux/src/qdf_trace.c +++ b/qdf/linux/src/qdf_trace.c @@ -240,15 +240,15 @@ qdf_export_symbol(qdf_trace_hex_ascii_dump); #ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY static inline QDF_STATUS allocate_g_qdf_trace_tbl_buffer(void) { - g_qdf_trace_tbl = vzalloc(MAX_QDF_TRACE_RECORDS * - sizeof(*g_qdf_trace_tbl)); + g_qdf_trace_tbl = qdf_mem_valloc(MAX_QDF_TRACE_RECORDS * + sizeof(*g_qdf_trace_tbl)); QDF_BUG(g_qdf_trace_tbl); return g_qdf_trace_tbl ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM; } static inline void free_g_qdf_trace_tbl_buffer(void) { - vfree(g_qdf_trace_tbl); + qdf_mem_vfree(g_qdf_trace_tbl); g_qdf_trace_tbl = NULL; } #else @@ -672,15 +672,15 @@ qdf_export_symbol(qdf_state_info_dump_all); #ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY static inline QDF_STATUS allocate_g_qdf_dp_trace_tbl_buffer(void) { - g_qdf_dp_trace_tbl = vzalloc(MAX_QDF_DP_TRACE_RECORDS * - sizeof(*g_qdf_dp_trace_tbl)); + g_qdf_dp_trace_tbl = qdf_mem_valloc(MAX_QDF_DP_TRACE_RECORDS * + sizeof(*g_qdf_dp_trace_tbl)); QDF_BUG(g_qdf_dp_trace_tbl); return g_qdf_dp_trace_tbl ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM; } static inline void free_g_qdf_dp_trace_tbl_buffer(void) { - vfree(g_qdf_dp_trace_tbl); + qdf_mem_vfree(g_qdf_dp_trace_tbl); g_qdf_dp_trace_tbl = NULL; } #else diff --git a/utils/fwlog/dbglog_host.c b/utils/fwlog/dbglog_host.c index ddeaadc3e6..db40048025 100644 --- a/utils/fwlog/dbglog_host.c +++ b/utils/fwlog/dbglog_host.c @@ -4073,7 +4073,7 @@ static ssize_t dbglog_block_read(struct file *file, char *buf; int ret; - buf = vzalloc(count); + buf = qdf_mem_valloc(count); if (!buf) return -ENOMEM; @@ -4088,7 +4088,7 @@ static ssize_t dbglog_block_read(struct file *file, ret = wait_for_completion_interruptible(&fwlog->fwlog_completion); if (ret == -ERESTARTSYS) { - vfree(buf); + qdf_mem_vfree(buf); return ret; } @@ -4122,7 +4122,7 @@ static ssize_t dbglog_block_read(struct file *file, ret_cnt = len; out: - vfree(buf); + qdf_mem_vfree(buf); return ret_cnt; } diff --git a/utils/logging/src/wlan_logging_sock_svc.c b/utils/logging/src/wlan_logging_sock_svc.c index 4c1e356f08..18377cc0c2 100644 --- a/utils/logging/src/wlan_logging_sock_svc.c +++ b/utils/logging/src/wlan_logging_sock_svc.c @@ -220,14 +220,14 @@ static struct log_msg *gplog_msg; static inline QDF_STATUS allocate_log_msg_buffer(void) { - gplog_msg = vzalloc(MAX_LOGMSG_COUNT * sizeof(*gplog_msg)); + gplog_msg = qdf_mem_valloc(MAX_LOGMSG_COUNT * sizeof(*gplog_msg)); return gplog_msg ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM; } static inline void free_log_msg_buffer(void) { - vfree(gplog_msg); + qdf_mem_vfree(gplog_msg); gplog_msg = NULL; } @@ -1152,7 +1152,7 @@ int wlan_logging_sock_init_svc(void) /* Initialize the pktStats data structure here */ pkt_stats_size = sizeof(struct pkt_stats_msg); - gpkt_stats_buffers = vmalloc(MAX_PKTSTATS_BUFF * pkt_stats_size); + gpkt_stats_buffers = qdf_mem_valloc(MAX_PKTSTATS_BUFF * pkt_stats_size); if (!gpkt_stats_buffers) { qdf_err("Could not allocate memory for Pkt stats"); goto err1; @@ -1222,7 +1222,7 @@ err2: spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag); gwlan_logging.pkt_stats_pcur_node = NULL; spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag); - vfree(gpkt_stats_buffers); + qdf_mem_vfree(gpkt_stats_buffers); gpkt_stats_buffers = NULL; err1: flush_timer_deinit(); @@ -1267,7 +1267,7 @@ int wlan_logging_sock_deinit_svc(void) dev_kfree_skb(gpkt_stats_buffers[i].skb); } spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag); - vfree(gpkt_stats_buffers); + qdf_mem_vfree(gpkt_stats_buffers); gpkt_stats_buffers = NULL; /* Delete the Flush timer then mark pcur_node NULL */ diff --git a/utils/logging/src/wlan_roam_debug.c b/utils/logging/src/wlan_roam_debug.c index 1f0b0c9560..30a4ad7d7d 100644 --- a/utils/logging/src/wlan_roam_debug.c +++ b/utils/logging/src/wlan_roam_debug.c @@ -49,7 +49,7 @@ static struct wlan_roam_debug_info *global_wlan_roam_debug_table; void wlan_roam_debug_init(void) { uint8_t i; - global_wlan_roam_debug_table = vzalloc( + global_wlan_roam_debug_table = qdf_mem_valloc( sizeof(struct wlan_roam_debug_info) * REC_MAX); QDF_BUG(global_wlan_roam_debug_table); @@ -86,7 +86,7 @@ static inline struct wlan_roam_debug_info *wlan_roam_debug_get_table( */ void wlan_roam_debug_deinit(void) { - vfree(global_wlan_roam_debug_table); + qdf_mem_vfree(global_wlan_roam_debug_table); global_wlan_roam_debug_table = NULL; } diff --git a/utils/pktlog/linux_ac.c b/utils/pktlog/linux_ac.c index cea9c655b9..de7427f580 100644 --- a/utils/pktlog/linux_ac.c +++ b/utils/pktlog/linux_ac.c @@ -125,7 +125,7 @@ int pktlog_alloc_buf(struct hif_opaque_softc *scn) } qdf_spin_unlock_bh(&pl_info->log_lock); - buffer = vmalloc((page_cnt + 2) * PAGE_SIZE); + buffer = qdf_mem_valloc((page_cnt + 2) * PAGE_SIZE); if (!buffer) { return -ENOMEM; } @@ -182,7 +182,7 @@ void pktlog_release_buf(struct hif_opaque_softc *scn) ClearPageReserved(vpg); } - vfree(pl_info->buf); + qdf_mem_vfree(pl_info->buf); pl_info->buf = NULL; }