hc
2024-03-25 edb30157bad0c0001c32b854271ace01d3b9a16a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <linux/slab.h>
#include "aicsdio_txrxif.h"
#include "aic_bsp_driver.h"
 
struct prealloc_txq{
    int prealloced;
    void *txq;
    size_t size;
};
 
struct prealloc_txq prealloc_txq;
#define MAX_TXQ_SIZE 100 * 1024
 
void *aicwf_prealloc_txq_alloc(size_t size)
{
 
    BUG_ON(size > MAX_TXQ_SIZE);
 
    //check prealloc_txq.size
    if((int)prealloc_txq.size != (int)size)
    {
        AICWFDBG(LOGINFO, "%s size is diff will to be kzalloc \r\n", __func__);
 
        if(prealloc_txq.txq != NULL)
        {
            AICWFDBG(LOGINFO, "%s txq to kfree \r\n", __func__);
            kfree(prealloc_txq.txq);
            prealloc_txq.txq = NULL;
        }
        
        prealloc_txq.size = size;
        prealloc_txq.prealloced = 0;
    }
 
    //check prealloc or not
    if(!prealloc_txq.prealloced)
    {
        prealloc_txq.txq = kzalloc(size, GFP_KERNEL);
        if(!prealloc_txq.txq){
            AICWFDBG(LOGERROR, "%s txq kzalloc fail \r\n", __func__);
        }else{
            AICWFDBG(LOGINFO, "%s txq kzalloc successful \r\n", __func__);
            prealloc_txq.prealloced = 1;
        }
    }else{
         AICWFDBG(LOGINFO, "%s txq not need to kzalloc \r\n", __func__);
    }
 
    return prealloc_txq.txq;
}
void aicwf_prealloc_txq_free(void)
{
    if(prealloc_txq.txq != NULL)
    {
        AICWFDBG(LOGINFO, "%s txq to kfree \r\n", __func__);
        kfree(prealloc_txq.txq);
        prealloc_txq.txq = NULL;
    }
}
 
EXPORT_SYMBOL(aicwf_prealloc_txq_alloc);