-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnubuff.c
More file actions
executable file
·181 lines (152 loc) · 3.57 KB
/
Copy pathnubuff.c
File metadata and controls
executable file
·181 lines (152 loc) · 3.57 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* ------------
* nubuff.c
* ------------
* Project Name : MCS8140-SerialServer-2.1
* File Revision: 1.1
* Author : from excelstore
* Date Created : Thu Apr 3 2018
*
* Modification History:
* Id Date By Description
* $Id: nubuff.c,v 1.1 2018/06/28 11:46:20 sami Exp $
*
**/
#include <linux/skbuff.h>
#include <linux/list.h>
#include <linux/spinlock_types.h>
#include <linux/interrupt.h>
#include <linux/cache.h>
#include "nubuff.h"
#include "debug.h"
struct nu_buff * dev_alloc_nub(unsigned int size)
{
struct nu_buff *nub;
nub = kmalloc(sizeof(struct nu_buff),GFP_ATOMIC);
if(!nub) {
DPRINTK("nub alloc failed\n");
return NULL;
}
nub->data = kzalloc(size,GFP_ATOMIC);
if(!(nub->data)) {
DPRINTK("nub data alloc failed\n");
kfree(nub);
return NULL;
}
nub->buffer = kzalloc(size,GFP_ATOMIC);
if(!(nub->buffer)) {
DPRINTK("nub data alloc failed\n");
kfree(nub);
return NULL;
}
return nub;
}
void dev_free_nub(struct nu_buff *nub)
{
// printk("in dev free nub\n");
#if 1
if(nub) {
if(nub->data != NULL) {
kfree(nub->data);
}
if(nub->buffer != NULL) {
kfree(nub->buffer);
}
kfree(nub);
}
//printk("end of dev free nub\n");
#endif
}
struct nu_buff * dev_alloc_rx_nub(unsigned int size)
{
struct nu_buff *nub;
nub = kmalloc(sizeof(struct nu_buff),GFP_ATOMIC);
if(!nub) {
DPRINTK("nub alloc failed\n");
return NULL;
}
nub->data = kzalloc(size,GFP_ATOMIC);
if(!(nub->data)) {
DPRINTK("nub data alloc failed\n");
kfree(nub);
return NULL;
}
nub->buffer = NULL;
return nub;
}
void dev_free_rx_nub(struct nu_buff *nub)
{
if(nub) {
if(nub->data != NULL) {
kfree(nub->data);
}
kfree(nub);
}
}
int nub_queue_empty(const struct nu_buff_head *list)
{
return list->next == (struct nu_buff *)list;
}
void __nub_unlink(struct nu_buff *nub, struct nu_buff_head *list)
{
struct nu_buff *next, *prev;
list->qlen--;
next = nub->next;
prev = nub->prev;
nub->next = nub->prev = NULL;
next->prev = prev;
prev->next = next;
}
struct nu_buff *__nub_dequeue(struct nu_buff_head *list)
{
struct nu_buff *next, *prev, *result;
prev = (struct nu_buff *) list;
next = prev->next;
result = NULL;
if (next != prev) {
result = next;
next = next->next;
list->qlen--;
next->prev = prev;
prev->next = next;
result->next = result->prev = NULL;
}
return result;
}
struct nu_buff *nub_dequeue(struct nu_buff_head *list)
{
unsigned long flags;
struct nu_buff *result;
spin_lock_irqsave(&list->lock, flags);
result = __nub_dequeue(list);
spin_unlock_irqrestore(&list->lock, flags);
return result;
}
void __nub_queue_tail(struct nu_buff_head *list,
struct nu_buff *newsk)
{
struct nu_buff *prev, *next;
list->qlen++;
next = (struct nu_buff *)list;
prev = next->prev;
newsk->next = next;
newsk->prev = prev;
next->prev = prev->next = newsk;
}
void nub_queue_tail(struct nu_buff_head *list, struct nu_buff *newsk)
{
unsigned long flags;
spin_lock_irqsave(&list->lock, flags);
__nub_queue_tail(list, newsk);
spin_unlock_irqrestore(&list->lock, flags);
}
__u32 nub_queue_len(const struct nu_buff_head *list_)
{
return list_->qlen;
}
void nub_queue_head_init(struct nu_buff_head *list)
{
spin_lock_init(&list->lock);
list->prev = list->next = (struct nu_buff *)list;
list->qlen = 0;
}