summaryrefslogtreecommitdiff
path: root/sys/dev/dpaa2/dpaa2_frame.h
blob: 0b2a5a7d8e74bcd3e04e136006adce5fdbd11dba (plain)
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
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright © 2026 Dmitry Salychev
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef _DPAA2_FRAME_H
#define _DPAA2_FRAME_H

#include <sys/types.h>
#include <sys/bus.h>
#include <sys/kassert.h>

#include "dpaa2_types.h"
#include "dpaa2_buf.h"

/*
 * Helper routines for the DPAA2 frames (e.g. descriptors, software/hardware
 * annotations, etc.).
 */

/*
 * DPAA2 frame descriptor size, field offsets and masks.
 *
 * See 3.1.1 Frame descriptor format,
 *     4.2.1.2.2 Structure of Frame Descriptors (FDs),
 * LX2160A DPAA2 Low-Level Hardware Reference Manual, Rev. 0, 06/2020
 */
#define DPAA2_FD_SIZE		32u
#define DPAA2_FD_FMT_MASK	(0x3u)
#define DPAA2_FD_FMT_SHIFT	(12)
#define DPAA2_FD_ERR_MASK	(0xFFu)
#define DPAA2_FD_ERR_SHIFT	(0)
#define DPAA2_FD_SL_MASK	(0x1u)
#define DPAA2_FD_SL_SHIFT	(14)
#define DPAA2_FD_LEN_MASK	(0x3FFFFu)
#define DPAA2_FD_OFFSET_MASK	(0x0FFFu)
#define DPAA2_FD_PTAC_MASK	(0x7u)
#define DPAA2_FD_PTAC_SHIFT	(21)

/*
 * DPAA2 frame annotation sizes
 *
 * NOTE: Accelerator-specific (HWA) annotation length is described in the 64-byte
 *       units by the FD[ASAL] bits and can be as big as 960 bytes. Current
 *       values describe what is actually supported by the DPAA2 drivers.
 *
 * See 3.1.1 Frame descriptor format,
 * LX2160A DPAA2 Low-Level Hardware Reference Manual, Rev. 0
 */
#define DPAA2_FA_SIZE			192u	/* DPAA2 frame annotation */
#define DPAA2_FA_SWA_SIZE		64u	/* SW frame annotation */
#define DPAA2_FA_HWA_SIZE		128u	/* HW frame annotation */
#define DPAA2_FA_WRIOP_SIZE		128u	/* WRIOP HW annotation */

/**
 * @brief DPAA2 frame descriptor.
 *
 * addr:		Memory address of the start of the buffer holding the
 *			frame data or the buffer containing the scatter/gather
 *			list.
 * data_length:		Length of the frame data (in bytes).
 * bpid_ivp_bmt:	Buffer pool ID (14 bit + BMT bit + IVP bit)
 * offset_fmt_sl:	Frame data offset, frame format and short-length fields.
 * frame_ctx:		Frame context. This field allows the sender of a frame
 *			to communicate some out-of-band information to the
 *			receiver of the frame.
 * ctrl:		Control bits (ERR, CBMT, ASAL, PTAC, DROPP, SC, DD).
 * flow_ctx:		Frame flow context. Associates the frame with a flow
 *			structure. QMan may use the FLC field for 3 purposes:
 *			stashing control, order definition point identification,
 *			and enqueue replication control.
 *
 * See 3.1.1 Frame descriptor format,
 *     4.2.1.2.2 Structure of Frame Descriptors (FDs),
 * LX2160A DPAA2 Low-Level Hardware Reference Manual, Rev. 0, 06/2020
 */
struct dpaa2_fd {
	uint64_t	addr;
	uint32_t	data_length;
	uint16_t	bpid_ivp_bmt;
	uint16_t	offset_fmt_sl;
	uint32_t	frame_ctx;
	uint32_t	ctrl;
	uint64_t	flow_ctx;
} __packed;
CTASSERT(sizeof(struct dpaa2_fd) == DPAA2_FD_SIZE);

/**
 * @brief WRIOP hardware frame annotation.
 *
 * See 7.34.2 WRIOP hardware frame annotation (FA),
 * LX2160A DPAA2 Low-Level Hardware Reference Manual, Rev. 0, 06/2020
 */
struct dpaa2_hwa_wriop {
	union {
		struct {
			uint64_t fas;
			uint64_t timestamp;
			/* XXX-DSL: more to add here... */
		} __packed;
		uint8_t raw[128];
	};
} __packed;
CTASSERT(sizeof(struct dpaa2_hwa_wriop) == DPAA2_FA_WRIOP_SIZE);

/**
 * @brief DPAA2 hardware frame annotation (accelerator-specific annotation).
 *
 * See 3.4.1.2 Accelerator-specific annotation,
 * LX2160A DPAA2 Low-Level Hardware Reference Manual, Rev. 0, 06/2020 
 */
struct dpaa2_hwa {
	union {
		struct dpaa2_hwa_wriop wriop;
	};
} __packed;
CTASSERT(sizeof(struct dpaa2_hwa) == DPAA2_FA_HWA_SIZE);

/**
 * @brief DPAA2 software frame annotation (pass-through annotation).
 *
 * See 3.4.1.1 Pass-through annotation,
 * LX2160A DPAA2 Low-Level Hardware Reference Manual, Rev. 0, 06/2020
 */
struct dpaa2_swa {
	union {
		struct {
			uint32_t	  magic;
			struct dpaa2_buf *buf;
		};
		struct {
			uint8_t pta1[32];
			uint8_t pta2[32];
		};
		uint8_t raw[64];
	};
} __packed;
CTASSERT(sizeof(struct dpaa2_swa) == DPAA2_FA_SWA_SIZE);

int  dpaa2_fd_build(device_t, const uint16_t, struct dpaa2_buf *,
    bus_dma_segment_t *, const int, struct dpaa2_fd *);

int  dpaa2_fd_err(struct dpaa2_fd *);
uint32_t dpaa2_fd_data_len(struct dpaa2_fd *);
int  dpaa2_fd_format(struct dpaa2_fd *);
bool dpaa2_fd_short_len(struct dpaa2_fd *);
int  dpaa2_fd_offset(struct dpaa2_fd *);

int  dpaa2_fa_get_swa(struct dpaa2_fd *, struct dpaa2_swa **);
int  dpaa2_fa_get_hwa(struct dpaa2_fd *, struct dpaa2_hwa **);

#endif /* _DPAA2_FRAME_H */