1
2#ifndef _LINUX_BYTEORDER_GENERIC_H
3#define _LINUX_BYTEORDER_GENERIC_H
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#define cpu_to_le64 __cpu_to_le64
87#define le64_to_cpu __le64_to_cpu
88#define cpu_to_le32 __cpu_to_le32
89#define le32_to_cpu __le32_to_cpu
90#define cpu_to_le16 __cpu_to_le16
91#define le16_to_cpu __le16_to_cpu
92#define cpu_to_be64 __cpu_to_be64
93#define be64_to_cpu __be64_to_cpu
94#define cpu_to_be32 __cpu_to_be32
95#define be32_to_cpu __be32_to_cpu
96#define cpu_to_be16 __cpu_to_be16
97#define be16_to_cpu __be16_to_cpu
98#define cpu_to_le64p __cpu_to_le64p
99#define le64_to_cpup __le64_to_cpup
100#define cpu_to_le32p __cpu_to_le32p
101#define le32_to_cpup __le32_to_cpup
102#define cpu_to_le16p __cpu_to_le16p
103#define le16_to_cpup __le16_to_cpup
104#define cpu_to_be64p __cpu_to_be64p
105#define be64_to_cpup __be64_to_cpup
106#define cpu_to_be32p __cpu_to_be32p
107#define be32_to_cpup __be32_to_cpup
108#define cpu_to_be16p __cpu_to_be16p
109#define be16_to_cpup __be16_to_cpup
110#define cpu_to_le64s __cpu_to_le64s
111#define le64_to_cpus __le64_to_cpus
112#define cpu_to_le32s __cpu_to_le32s
113#define le32_to_cpus __le32_to_cpus
114#define cpu_to_le16s __cpu_to_le16s
115#define le16_to_cpus __le16_to_cpus
116#define cpu_to_be64s __cpu_to_be64s
117#define be64_to_cpus __be64_to_cpus
118#define cpu_to_be32s __cpu_to_be32s
119#define be32_to_cpus __be32_to_cpus
120#define cpu_to_be16s __cpu_to_be16s
121#define be16_to_cpus __be16_to_cpus
122
123
124
125
126
127
128
129#undef ntohl
130#undef ntohs
131#undef htonl
132#undef htons
133
134#define ___htonl(x) __cpu_to_be32(x)
135#define ___htons(x) __cpu_to_be16(x)
136#define ___ntohl(x) __be32_to_cpu(x)
137#define ___ntohs(x) __be16_to_cpu(x)
138
139#define htonl(x) ___htonl(x)
140#define ntohl(x) ___ntohl(x)
141#define htons(x) ___htons(x)
142#define ntohs(x) ___ntohs(x)
143
144static inline void le16_add_cpu(__le16 *var, u16 val)
145{
146 *var = cpu_to_le16(le16_to_cpu(*var) + val);
147}
148
149static inline void le32_add_cpu(__le32 *var, u32 val)
150{
151 *var = cpu_to_le32(le32_to_cpu(*var) + val);
152}
153
154static inline void le64_add_cpu(__le64 *var, u64 val)
155{
156 *var = cpu_to_le64(le64_to_cpu(*var) + val);
157}
158
159
160static inline void le32_to_cpu_array(u32 *buf, unsigned int words)
161{
162 while (words--) {
163 __le32_to_cpus(buf);
164 buf++;
165 }
166}
167
168static inline void cpu_to_le32_array(u32 *buf, unsigned int words)
169{
170 while (words--) {
171 __cpu_to_le32s(buf);
172 buf++;
173 }
174}
175
176static inline void be16_add_cpu(__be16 *var, u16 val)
177{
178 *var = cpu_to_be16(be16_to_cpu(*var) + val);
179}
180
181static inline void be32_add_cpu(__be32 *var, u32 val)
182{
183 *var = cpu_to_be32(be32_to_cpu(*var) + val);
184}
185
186static inline void be64_add_cpu(__be64 *var, u64 val)
187{
188 *var = cpu_to_be64(be64_to_cpu(*var) + val);
189}
190
191static inline void cpu_to_be32_array(__be32 *dst, const u32 *src, size_t len)
192{
193 int i;
194
195 for (i = 0; i < len; i++)
196 dst[i] = cpu_to_be32(src[i]);
197}
198
199static inline void be32_to_cpu_array(u32 *dst, const __be32 *src, size_t len)
200{
201 int i;
202
203 for (i = 0; i < len; i++)
204 dst[i] = be32_to_cpu(src[i]);
205}
206
207#endif
208