|
@@ -11,6 +11,7 @@
|
|
|
#include <linux/err.h>
|
|
|
#include <linux/of.h>
|
|
|
#include <linux/version.h>
|
|
|
+#include "cnss_common.h"
|
|
|
#ifdef CONFIG_CNSS_OUT_OF_TREE
|
|
|
#include "cnss_prealloc.h"
|
|
|
#else
|
|
@@ -68,7 +69,7 @@ struct cnss_pool {
|
|
|
*/
|
|
|
|
|
|
/* size, min pool reserve, name, memorypool handler, cache handler*/
|
|
|
-static struct cnss_pool cnss_pools[] = {
|
|
|
+static struct cnss_pool cnss_pools_default[] = {
|
|
|
{8 * 1024, 16, "cnss-pool-8k", NULL, NULL},
|
|
|
{16 * 1024, 16, "cnss-pool-16k", NULL, NULL},
|
|
|
{32 * 1024, 22, "cnss-pool-32k", NULL, NULL},
|
|
@@ -76,6 +77,17 @@ static struct cnss_pool cnss_pools[] = {
|
|
|
{128 * 1024, 10, "cnss-pool-128k", NULL, NULL},
|
|
|
};
|
|
|
|
|
|
+static struct cnss_pool cnss_pools_adrastea[] = {
|
|
|
+ {8 * 1024, 2, "cnss-pool-8k", NULL, NULL},
|
|
|
+ {16 * 1024, 10, "cnss-pool-16k", NULL, NULL},
|
|
|
+ {32 * 1024, 8, "cnss-pool-32k", NULL, NULL},
|
|
|
+ {64 * 1024, 4, "cnss-pool-64k", NULL, NULL},
|
|
|
+ {128 * 1024, 2, "cnss-pool-128k", NULL, NULL},
|
|
|
+};
|
|
|
+
|
|
|
+struct cnss_pool *cnss_pools;
|
|
|
+unsigned int cnss_prealloc_pool_size = ARRAY_SIZE(cnss_pools_default);
|
|
|
+
|
|
|
/**
|
|
|
* cnss_pool_alloc_threshold() - Allocation threshold
|
|
|
*
|
|
@@ -104,7 +116,7 @@ static int cnss_pool_init(void)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
- for (i = 0; i < ARRAY_SIZE(cnss_pools); i++) {
|
|
|
+ for (i = 0; i < cnss_prealloc_pool_size; i++) {
|
|
|
/* Create the slab cache */
|
|
|
cnss_pools[i].cache =
|
|
|
kmem_cache_create_usercopy(cnss_pools[i].name,
|
|
@@ -149,7 +161,7 @@ static void cnss_pool_deinit(void)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
- for (i = 0; i < ARRAY_SIZE(cnss_pools); i++) {
|
|
|
+ for (i = 0; i < cnss_prealloc_pool_size; i++) {
|
|
|
pr_info("cnss_prealloc: destroy mempool %s\n",
|
|
|
cnss_pools[i].name);
|
|
|
mempool_destroy(cnss_pools[i].mp);
|
|
@@ -157,6 +169,41 @@ static void cnss_pool_deinit(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void cnss_assign_prealloc_pool(unsigned long device_id)
|
|
|
+{
|
|
|
+ pr_info("cnss_prealloc: assign cnss pool for device id 0x%lx", device_id);
|
|
|
+
|
|
|
+ switch (device_id) {
|
|
|
+ case ADRASTEA_DEVICE_ID:
|
|
|
+ cnss_pools = cnss_pools_adrastea;
|
|
|
+ cnss_prealloc_pool_size = ARRAY_SIZE(cnss_pools_adrastea);
|
|
|
+ break;
|
|
|
+ case WCN6750_DEVICE_ID:
|
|
|
+ case WCN6450_DEVICE_ID:
|
|
|
+ case QCA6390_DEVICE_ID:
|
|
|
+ case QCA6490_DEVICE_ID:
|
|
|
+ case MANGO_DEVICE_ID:
|
|
|
+ case PEACH_DEVICE_ID:
|
|
|
+ case KIWI_DEVICE_ID:
|
|
|
+ default:
|
|
|
+ cnss_pools = cnss_pools_default;
|
|
|
+ cnss_prealloc_pool_size = ARRAY_SIZE(cnss_pools_default);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void cnss_initialize_prealloc_pool(unsigned long device_id)
|
|
|
+{
|
|
|
+ cnss_assign_prealloc_pool(device_id);
|
|
|
+ cnss_pool_init();
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(cnss_initialize_prealloc_pool);
|
|
|
+
|
|
|
+void cnss_deinitialize_prealloc_pool(void)
|
|
|
+{
|
|
|
+ cnss_pool_deinit();
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(cnss_deinitialize_prealloc_pool);
|
|
|
+
|
|
|
/**
|
|
|
* cnss_pool_get_index() - Get the index of memory pool
|
|
|
* @mem: Allocated memory
|
|
@@ -186,7 +233,7 @@ static int cnss_pool_get_index(void *mem)
|
|
|
return -ENOENT;
|
|
|
|
|
|
/* Check if memory belongs to a pool */
|
|
|
- for (i = 0; i < ARRAY_SIZE(cnss_pools); i++) {
|
|
|
+ for (i = 0; i < cnss_prealloc_pool_size; i++) {
|
|
|
if (cnss_pools[i].cache == cache)
|
|
|
return i;
|
|
|
}
|
|
@@ -213,7 +260,7 @@ static int cnss_pool_get_index(void *mem)
|
|
|
return -ENOENT;
|
|
|
|
|
|
/* Check if memory belongs to a pool */
|
|
|
- for (i = 0; i < ARRAY_SIZE(cnss_pools); i++) {
|
|
|
+ for (i = 0; i < cnss_prealloc_pool_size; i++) {
|
|
|
if (cnss_pools[i].cache == cache)
|
|
|
return i;
|
|
|
}
|
|
@@ -245,7 +292,7 @@ void *wcnss_prealloc_get(size_t size)
|
|
|
|
|
|
if (size >= cnss_pool_alloc_threshold()) {
|
|
|
|
|
|
- for (i = 0; i < ARRAY_SIZE(cnss_pools); i++) {
|
|
|
+ for (i = 0; i < cnss_prealloc_pool_size; i++) {
|
|
|
if (cnss_pools[i].size >= size && cnss_pools[i].mp) {
|
|
|
mem = mempool_alloc(cnss_pools[i].mp, gfp_mask);
|
|
|
if (mem)
|
|
@@ -281,7 +328,7 @@ int wcnss_prealloc_put(void *mem)
|
|
|
return 0;
|
|
|
|
|
|
i = cnss_pool_get_index(mem);
|
|
|
- if (i >= 0 && i < ARRAY_SIZE(cnss_pools) && cnss_pools[i].mp) {
|
|
|
+ if (i >= 0 && i < cnss_prealloc_pool_size && cnss_pools[i].mp) {
|
|
|
mempool_free(mem, cnss_pools[i].mp);
|
|
|
return 1;
|
|
|
}
|
|
@@ -327,12 +374,12 @@ static int __init cnss_prealloc_init(void)
|
|
|
if (!cnss_prealloc_is_valid_dt_node_found())
|
|
|
return -ENODEV;
|
|
|
|
|
|
- return cnss_pool_init();
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
static void __exit cnss_prealloc_exit(void)
|
|
|
{
|
|
|
- cnss_pool_deinit();
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
module_init(cnss_prealloc_init);
|