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
This commit is contained in:

committed by
Madan Koyyalamudi

parent
e5255c7253
commit
a8d8b663b2
@@ -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
|
* Permission to use, copy, modify, and/or distribute this software for
|
||||||
* any purpose with or without fee is hereby granted, provided that the
|
* 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);
|
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
|
* qdf_get_time_of_the_day_ms() - get time of the day in millisec
|
||||||
*
|
*
|
||||||
|
@@ -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,
|
void qdf_mem_tx_desc_cnt_update(qdf_atomic_t pending_tx_descs,
|
||||||
int32_t tx_descs_max);
|
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 */
|
#endif /* __QDF_MEMORY_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);
|
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
|
#ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
|
||||||
/**
|
/**
|
||||||
* __qdf_untracked_mem_malloc() - allocates non-QDF memory
|
* __qdf_untracked_mem_malloc() - allocates non-QDF memory
|
||||||
|
@@ -856,42 +856,6 @@ s64 qdf_get_monotonic_boottime_ns(void)
|
|||||||
}
|
}
|
||||||
qdf_export_symbol(qdf_get_monotonic_boottime_ns);
|
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.
|
* 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);
|
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
|
#else
|
||||||
void qdf_get_time_of_the_day_in_hr_min_sec_usec(char *tbuf, int len)
|
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);
|
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);
|
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
|
#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);
|
||||||
|
@@ -2856,3 +2856,28 @@ void qdf_mem_stats_init(void)
|
|||||||
|
|
||||||
qdf_export_symbol(qdf_mem_stats_init);
|
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);
|
||||||
|
@@ -240,15 +240,15 @@ qdf_export_symbol(qdf_trace_hex_ascii_dump);
|
|||||||
#ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY
|
#ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY
|
||||||
static inline QDF_STATUS allocate_g_qdf_trace_tbl_buffer(void)
|
static inline QDF_STATUS allocate_g_qdf_trace_tbl_buffer(void)
|
||||||
{
|
{
|
||||||
g_qdf_trace_tbl = vzalloc(MAX_QDF_TRACE_RECORDS *
|
g_qdf_trace_tbl = qdf_mem_valloc(MAX_QDF_TRACE_RECORDS *
|
||||||
sizeof(*g_qdf_trace_tbl));
|
sizeof(*g_qdf_trace_tbl));
|
||||||
QDF_BUG(g_qdf_trace_tbl);
|
QDF_BUG(g_qdf_trace_tbl);
|
||||||
return g_qdf_trace_tbl ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM;
|
return g_qdf_trace_tbl ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void free_g_qdf_trace_tbl_buffer(void)
|
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;
|
g_qdf_trace_tbl = NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -672,15 +672,15 @@ qdf_export_symbol(qdf_state_info_dump_all);
|
|||||||
#ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY
|
#ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY
|
||||||
static inline QDF_STATUS allocate_g_qdf_dp_trace_tbl_buffer(void)
|
static inline QDF_STATUS allocate_g_qdf_dp_trace_tbl_buffer(void)
|
||||||
{
|
{
|
||||||
g_qdf_dp_trace_tbl = vzalloc(MAX_QDF_DP_TRACE_RECORDS *
|
g_qdf_dp_trace_tbl = qdf_mem_valloc(MAX_QDF_DP_TRACE_RECORDS *
|
||||||
sizeof(*g_qdf_dp_trace_tbl));
|
sizeof(*g_qdf_dp_trace_tbl));
|
||||||
QDF_BUG(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;
|
return g_qdf_dp_trace_tbl ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void free_g_qdf_dp_trace_tbl_buffer(void)
|
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;
|
g_qdf_dp_trace_tbl = NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@@ -4073,7 +4073,7 @@ static ssize_t dbglog_block_read(struct file *file,
|
|||||||
char *buf;
|
char *buf;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
buf = vzalloc(count);
|
buf = qdf_mem_valloc(count);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@@ -4088,7 +4088,7 @@ static ssize_t dbglog_block_read(struct file *file,
|
|||||||
ret =
|
ret =
|
||||||
wait_for_completion_interruptible(&fwlog->fwlog_completion);
|
wait_for_completion_interruptible(&fwlog->fwlog_completion);
|
||||||
if (ret == -ERESTARTSYS) {
|
if (ret == -ERESTARTSYS) {
|
||||||
vfree(buf);
|
qdf_mem_vfree(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4122,7 +4122,7 @@ static ssize_t dbglog_block_read(struct file *file,
|
|||||||
ret_cnt = len;
|
ret_cnt = len;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
vfree(buf);
|
qdf_mem_vfree(buf);
|
||||||
|
|
||||||
return ret_cnt;
|
return ret_cnt;
|
||||||
}
|
}
|
||||||
|
@@ -220,14 +220,14 @@ static struct log_msg *gplog_msg;
|
|||||||
|
|
||||||
static inline QDF_STATUS allocate_log_msg_buffer(void)
|
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;
|
return gplog_msg ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void free_log_msg_buffer(void)
|
static inline void free_log_msg_buffer(void)
|
||||||
{
|
{
|
||||||
vfree(gplog_msg);
|
qdf_mem_vfree(gplog_msg);
|
||||||
gplog_msg = NULL;
|
gplog_msg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1152,7 +1152,7 @@ int wlan_logging_sock_init_svc(void)
|
|||||||
|
|
||||||
/* Initialize the pktStats data structure here */
|
/* Initialize the pktStats data structure here */
|
||||||
pkt_stats_size = sizeof(struct pkt_stats_msg);
|
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) {
|
if (!gpkt_stats_buffers) {
|
||||||
qdf_err("Could not allocate memory for Pkt stats");
|
qdf_err("Could not allocate memory for Pkt stats");
|
||||||
goto err1;
|
goto err1;
|
||||||
@@ -1222,7 +1222,7 @@ err2:
|
|||||||
spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
|
spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
|
||||||
gwlan_logging.pkt_stats_pcur_node = NULL;
|
gwlan_logging.pkt_stats_pcur_node = NULL;
|
||||||
spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
|
spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
|
||||||
vfree(gpkt_stats_buffers);
|
qdf_mem_vfree(gpkt_stats_buffers);
|
||||||
gpkt_stats_buffers = NULL;
|
gpkt_stats_buffers = NULL;
|
||||||
err1:
|
err1:
|
||||||
flush_timer_deinit();
|
flush_timer_deinit();
|
||||||
@@ -1267,7 +1267,7 @@ int wlan_logging_sock_deinit_svc(void)
|
|||||||
dev_kfree_skb(gpkt_stats_buffers[i].skb);
|
dev_kfree_skb(gpkt_stats_buffers[i].skb);
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
|
spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
|
||||||
vfree(gpkt_stats_buffers);
|
qdf_mem_vfree(gpkt_stats_buffers);
|
||||||
gpkt_stats_buffers = NULL;
|
gpkt_stats_buffers = NULL;
|
||||||
|
|
||||||
/* Delete the Flush timer then mark pcur_node NULL */
|
/* Delete the Flush timer then mark pcur_node NULL */
|
||||||
|
@@ -49,7 +49,7 @@ static struct wlan_roam_debug_info *global_wlan_roam_debug_table;
|
|||||||
void wlan_roam_debug_init(void)
|
void wlan_roam_debug_init(void)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
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);
|
sizeof(struct wlan_roam_debug_info) * REC_MAX);
|
||||||
|
|
||||||
QDF_BUG(global_wlan_roam_debug_table);
|
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)
|
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;
|
global_wlan_roam_debug_table = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -125,7 +125,7 @@ int pktlog_alloc_buf(struct hif_opaque_softc *scn)
|
|||||||
}
|
}
|
||||||
qdf_spin_unlock_bh(&pl_info->log_lock);
|
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) {
|
if (!buffer) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ void pktlog_release_buf(struct hif_opaque_softc *scn)
|
|||||||
ClearPageReserved(vpg);
|
ClearPageReserved(vpg);
|
||||||
}
|
}
|
||||||
|
|
||||||
vfree(pl_info->buf);
|
qdf_mem_vfree(pl_info->buf);
|
||||||
pl_info->buf = NULL;
|
pl_info->buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user