1
2
3
4
5
6
7#ifndef __FSL_DPAA2_FD_H
8#define __FSL_DPAA2_FD_H
9
10#include <linux/kernel.h>
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
38struct dpaa2_fd {
39 union {
40 u32 words[8];
41 struct dpaa2_fd_simple {
42 __le64 addr;
43 __le32 len;
44 __le16 bpid;
45 __le16 format_offset;
46 __le32 frc;
47 __le32 ctrl;
48 __le64 flc;
49 } simple;
50 };
51};
52
53#define FD_SHORT_LEN_FLAG_MASK 0x1
54#define FD_SHORT_LEN_FLAG_SHIFT 14
55#define FD_SHORT_LEN_MASK 0x3FFFF
56#define FD_OFFSET_MASK 0x0FFF
57#define FD_FORMAT_MASK 0x3
58#define FD_FORMAT_SHIFT 12
59#define FD_BPID_MASK 0x3FFF
60#define SG_SHORT_LEN_FLAG_MASK 0x1
61#define SG_SHORT_LEN_FLAG_SHIFT 14
62#define SG_SHORT_LEN_MASK 0x1FFFF
63#define SG_OFFSET_MASK 0x0FFF
64#define SG_FORMAT_MASK 0x3
65#define SG_FORMAT_SHIFT 12
66#define SG_BPID_MASK 0x3FFF
67#define SG_FINAL_FLAG_MASK 0x1
68#define SG_FINAL_FLAG_SHIFT 15
69
70enum dpaa2_fd_format {
71 dpaa2_fd_single = 0,
72 dpaa2_fd_list,
73 dpaa2_fd_sg
74};
75
76
77
78
79
80
81
82static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)
83{
84 return (dma_addr_t)le64_to_cpu(fd->simple.addr);
85}
86
87
88
89
90
91
92static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)
93{
94 fd->simple.addr = cpu_to_le64(addr);
95}
96
97
98
99
100
101
102
103static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)
104{
105 return le32_to_cpu(fd->simple.frc);
106}
107
108
109
110
111
112
113static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)
114{
115 fd->simple.frc = cpu_to_le32(frc);
116}
117
118
119
120
121
122
123
124static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)
125{
126 return le32_to_cpu(fd->simple.ctrl);
127}
128
129
130
131
132
133
134static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)
135{
136 fd->simple.ctrl = cpu_to_le32(ctrl);
137}
138
139
140
141
142
143
144
145static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)
146{
147 return (dma_addr_t)le64_to_cpu(fd->simple.flc);
148}
149
150
151
152
153
154
155static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)
156{
157 fd->simple.flc = cpu_to_le64(flc_addr);
158}
159
160static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)
161{
162 return !!((le16_to_cpu(fd->simple.format_offset) >>
163 FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);
164}
165
166
167
168
169
170
171
172static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)
173{
174 if (dpaa2_fd_short_len(fd))
175 return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;
176
177 return le32_to_cpu(fd->simple.len);
178}
179
180
181
182
183
184
185static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)
186{
187 fd->simple.len = cpu_to_le32(len);
188}
189
190
191
192
193
194
195
196static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)
197{
198 return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;
199}
200
201
202
203
204
205
206static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)
207{
208 fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);
209 fd->simple.format_offset |= cpu_to_le16(offset);
210}
211
212
213
214
215
216
217
218static inline enum dpaa2_fd_format dpaa2_fd_get_format(
219 const struct dpaa2_fd *fd)
220{
221 return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)
222 >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);
223}
224
225
226
227
228
229
230static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,
231 enum dpaa2_fd_format format)
232{
233 fd->simple.format_offset &=
234 cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));
235 fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);
236}
237
238
239
240
241
242
243
244static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)
245{
246 return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;
247}
248
249
250
251
252
253
254static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)
255{
256 fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));
257 fd->simple.bpid |= cpu_to_le16(bpid);
258}
259
260
261
262
263
264
265
266
267struct dpaa2_sg_entry {
268 __le64 addr;
269 __le32 len;
270 __le16 bpid;
271 __le16 format_offset;
272};
273
274enum dpaa2_sg_format {
275 dpaa2_sg_single = 0,
276 dpaa2_sg_frame_data,
277 dpaa2_sg_sgt_ext
278};
279
280
281
282
283
284
285
286
287
288static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)
289{
290 return (dma_addr_t)le64_to_cpu(sg->addr);
291}
292
293
294
295
296
297
298static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)
299{
300 sg->addr = cpu_to_le64(addr);
301}
302
303static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)
304{
305 return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)
306 & SG_SHORT_LEN_FLAG_MASK);
307}
308
309
310
311
312
313
314
315static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)
316{
317 if (dpaa2_sg_short_len(sg))
318 return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;
319
320 return le32_to_cpu(sg->len);
321}
322
323
324
325
326
327
328static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)
329{
330 sg->len = cpu_to_le32(len);
331}
332
333
334
335
336
337
338
339static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)
340{
341 return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;
342}
343
344
345
346
347
348
349static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,
350 u16 offset)
351{
352 sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);
353 sg->format_offset |= cpu_to_le16(offset);
354}
355
356
357
358
359
360
361
362static inline enum dpaa2_sg_format
363 dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)
364{
365 return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)
366 >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);
367}
368
369
370
371
372
373
374static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,
375 enum dpaa2_sg_format format)
376{
377 sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));
378 sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);
379}
380
381
382
383
384
385
386
387static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)
388{
389 return le16_to_cpu(sg->bpid) & SG_BPID_MASK;
390}
391
392
393
394
395
396
397static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)
398{
399 sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));
400 sg->bpid |= cpu_to_le16(bpid);
401}
402
403
404
405
406
407
408
409static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)
410{
411 return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);
412}
413
414
415
416
417
418
419static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)
420{
421 sg->format_offset &= cpu_to_le16((~(SG_FINAL_FLAG_MASK
422 << SG_FINAL_FLAG_SHIFT)) & 0xFFFF);
423 sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);
424}
425
426#endif
427