AM263Px MCU+ SDK: enet_ioctl.h Source File

| AM263Px MCU+ SDK 26.00.00 |

enet_ioctl.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) Texas Instruments Incorporated 2020
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
46 #ifndef ENET_IOCTL_H_
47 #define ENET_IOCTL_H_
48
49 /* ========================================================================== */
50 /* Include Files */
51 /* ========================================================================== */
52
53 #include <stdint.h>
54 #include <stdbool.h>
55 #include <enet_cfg.h>
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 /* ========================================================================== */
62 /* Macros */
63 /* ========================================================================== */
64
73 #define ENET_IOCTL_TYPE_OFFSET (24U)
74
76 #define ENET_IOCTL_PER_OFFSET (16U)
77
79 #define ENET_IOCTL_MAJOR_OFFSET (8U)
80
82 #define ENET_IOCTL_MINOR_OFFSET (0U)
83
85 #define ENET_IOCTL_GET_TYPE(x) ((x) & 0xFF000000U)
86
88 #define ENET_IOCTL_GET_PER(x) ((x) & 0x00FF0000U)
89
91 #define ENET_IOCTL_GET_MAJ(x) ((x) & 0x0000FF00U)
92
94 #define ENET_IOCTL_GET_MIN(x) ((x) & 0x000000FFU)
95
97 #define ENET_IOCTL_TYPE(x) ((x) << ENET_IOCTL_TYPE_OFFSET)
98
100 #define ENET_IOCTL_PER(x) ((x) << ENET_IOCTL_PER_OFFSET)
101
103 #define ENET_IOCTL_MAJ(x) ((x) << ENET_IOCTL_MAJOR_OFFSET)
104
106 #define ENET_IOCTL_MIN(x) ((x) << ENET_IOCTL_MINOR_OFFSET)
107
111 #define ENET_IOCTL_SET_NO_ARGS(prms) \
112 { \
113 (prms)->inArgs = NULL; \
114 (prms)->inArgsSize = 0U; \
115 (prms)->outArgs = NULL; \
116 (prms)->outArgsSize = 0U; \
117 }
118
122 #define ENET_IOCTL_SET_IN_ARGS(prms, in) \
123 { \
124 (prms)->inArgs = (in); \
125 (prms)->inArgsSize = sizeof(*(in)); \
126 (prms)->outArgs = NULL; \
127 (prms)->outArgsSize = 0U; \
128 }
129
133 #define ENET_IOCTL_SET_OUT_ARGS(prms, out) \
134 { \
135 (prms)->inArgs = NULL; \
136 (prms)->inArgsSize = 0U; \
137 (prms)->outArgs = (out); \
138 (prms)->outArgsSize = sizeof(*(out)); \
139 }
140
144 #define ENET_IOCTL_SET_INOUT_ARGS(prms, in, out) \
145 { \
146 (prms)->inArgs = (in); \
147 (prms)->inArgsSize = sizeof(*(in)); \
148 (prms)->outArgs = (out); \
149 (prms)->outArgsSize = sizeof(*(out)); \
150 }
151
156 #define ENET_IOCTL_VALID_PRMS(cmdId, inSize, outSize) \
157 [ENET_IOCTL_GET_MIN(cmdId)] = \
158 { \
159 .cmd = (cmdId), \
160 .inArgsSize = (inSize), \
161 .outArgsSize = (outSize), \
162 }
163
164
188 #define ENET_IOCTL(hEnet, coreId, ioctlCmd, prms, status) \
189 do { \
190 extern int32_t Enet_ioctl(Enet_Handle enetHandle, \
191 uint32_t ioctlCoreId, \
192 uint32_t cmd, \
193 Enet_IoctlPrms *ioctlPrms); \
194 \
195 extern int32_t Enet_ioctl_register_##ioctlCmd(Enet_Handle enetHandle, \
196 uint32_t ioctlCoreId); \
197 \
198 status = Enet_ioctl_register_##ioctlCmd(hEnet, coreId); \
199 if (ENET_SOK == status) \
200 { \
201 status = Enet_ioctl(hEnet, coreId, ioctlCmd, prms); \
202 } \
203 } while (0)
204
205
206 /* ========================================================================== */
207 /* Structures and Enums */
208 /* ========================================================================== */
209
213 enum Enet_IoctlType_e
214 {
216 ENET_IOCTL_TYPE_PUBLIC = ENET_IOCTL_TYPE(1U),
217
219 ENET_IOCTL_TYPE_PRIVATE = ENET_IOCTL_TYPE(2U),
220 };
221
225 enum Enet_IoctlPer_e
226 {
228 ENET_IOCTL_PER_GENERIC = ENET_IOCTL_PER(0U),
229
231 ENET_IOCTL_PER_CPSW = ENET_IOCTL_PER(1U),
232
234 ENET_IOCTL_PER_ICSSG = ENET_IOCTL_PER(2U),
235
237 ENET_IOCTL_PER_GMAC = ENET_IOCTL_PER(3U),
238 };
239
243 enum Enet_IoctlMajor_e
244 {
246 ENET_IOCTL_PER_BASE = ENET_IOCTL_MAJ(1U),
247
249 ENET_IOCTL_FDB_BASE = ENET_IOCTL_MAJ(2U),
250
252 ENET_IOCTL_TIMESYNC_BASE = ENET_IOCTL_MAJ(3U),
253
255 ENET_IOCTL_HOSTPORT_BASE = ENET_IOCTL_MAJ(4U),
256
258 ENET_IOCTL_MACPORT_BASE = ENET_IOCTL_MAJ(5U),
259
261 ENET_IOCTL_MDIO_BASE = ENET_IOCTL_MAJ(6U),
262
264 ENET_IOCTL_STATS_BASE = ENET_IOCTL_MAJ(7U),
265
267 ENET_IOCTL_PHY_BASE = ENET_IOCTL_MAJ(9U),
268
270 ENET_IOCTL_RM_BASE = ENET_IOCTL_MAJ(10U),
271
273 ENET_IOCTL_TAS_BASE = ENET_IOCTL_MAJ(11U),
274 };
275
281 typedef struct Enet_IoctlPrms_s
282 {
284 const void *inArgs;
285
287 uint32_t inArgsSize;
288
290 void *outArgs;
291
293 uint32_t outArgsSize;
294 } Enet_IoctlPrms;
295
302 typedef struct Enet_IoctlValidate_s
303 {
305 uint32_t cmd;
306
308 uint32_t inArgsSize;
309
311 uint32_t outArgsSize;
312 } Enet_IoctlValidate;
313
314 /* ========================================================================== */
315 /* Global Variables Declarations */
316 /* ========================================================================== */
317
318 /* None */
319
320 /* ========================================================================== */
321 /* Function Declarations */
322 /* ========================================================================== */
323
336 static inline uint32_t Enet_checkInArgs(const Enet_IoctlPrms *prms,
337 uint32_t inArgsSize);
338
350 static inline uint32_t Enet_checkNoInArgs(const Enet_IoctlPrms *prms);
351
364 static inline uint32_t Enet_checkOutArgs(const Enet_IoctlPrms *prms,
365 uint32_t outArgsSize);
366
378 static inline uint32_t Enet_checkNoOutArgs(const Enet_IoctlPrms *prms);
379
393 static inline uint32_t Enet_checkInOutArgs(const Enet_IoctlPrms *prms,
394 uint32_t inArgsSize,
395 uint32_t outArgsSize);
396
397 #if ENET_CFG_IS_ON(DEV_ERROR)
398
434 int32_t Enet_validateIoctl(uint32_t cmd,
435 const Enet_IoctlPrms *prms,
436 const Enet_IoctlValidate *validIoctls,
437 uint32_t numValidIoctls);
438 #endif
439
440 /* ========================================================================== */
441 /* Deprecated Function Declarations */
442 /* ========================================================================== */
443
444 /* None */
445
446 /* ========================================================================== */
447 /* Static Function Definitions */
448 /* ========================================================================== */
449
450 static inline uint32_t Enet_checkInArgs(const Enet_IoctlPrms *prms,
451 uint32_t inArgsSize)
452 {
453 return ((prms != NULL) &&
454 (prms->inArgs != NULL) &&
455 (prms->inArgsSize == inArgsSize)) ?
456 ENET_SOK : ENET_EMALFORMEDIOCTL;
457 }
458
459 static inline uint32_t Enet_checkNoInArgs(const Enet_IoctlPrms *prms)
460 {
461 return ((prms != NULL) &&
462 (prms->inArgs == NULL) &&
463 (prms->inArgsSize == 0U)) ?
464 ENET_SOK : ENET_EMALFORMEDIOCTL;
465 }
466
467 static inline uint32_t Enet_checkOutArgs(const Enet_IoctlPrms *prms,
468 uint32_t outArgsSize)
469 {
470 return ((prms != NULL) &&
471 (prms->outArgs != NULL) &&
472 (prms->outArgsSize == outArgsSize)) ?
473 ENET_SOK : ENET_EMALFORMEDIOCTL;
474 }
475
476 static inline uint32_t Enet_checkNoOutArgs(const Enet_IoctlPrms *prms)
477 {
478 return ((prms != NULL) &&
479 (prms->outArgs == NULL) &&
480 (prms->outArgsSize == 0U)) ?
481 ENET_SOK : ENET_EMALFORMEDIOCTL;
482 }
483
484 static inline uint32_t Enet_checkInOutArgs(const Enet_IoctlPrms *prms,
485 uint32_t inArgsSize,
486 uint32_t outArgsSize)
487 {
488 return ((prms != NULL) &&
489 (prms->inArgs != NULL) &&
490 (prms->inArgsSize == inArgsSize) &&
491 (prms->outArgs != NULL) &&
492 (prms->outArgsSize == outArgsSize)) ?
493 ENET_SOK : ENET_EMALFORMEDIOCTL;
494 }
495
496 #ifdef __cplusplus
497 }
498 #endif
499
500 #endif /* ENET_IOCTL_H_ */
501
ENET_IOCTL_PER_CPSW
@ ENET_IOCTL_PER_CPSW
Definition: enet_ioctl.h:231
Enet_IoctlMajor_e
Enet_IoctlMajor_e
IOCTL base number.
Definition: enet_ioctl.h:244
ENET_IOCTL_HOSTPORT_BASE
@ ENET_IOCTL_HOSTPORT_BASE
Definition: enet_ioctl.h:255
Enet_IoctlValidate
Enet IOCTL expected param sizes.
Definition: enet_ioctl.h:303
ENET_EMALFORMEDIOCTL
#define ENET_EMALFORMEDIOCTL
Malformed IOCTL (args pointer or size not as expected).
Definition: enet_types.h:118
Enet_IoctlValidate::cmd
uint32_t cmd
Definition: enet_ioctl.h:305
ENET_IOCTL_TYPE_PUBLIC
@ ENET_IOCTL_TYPE_PUBLIC
Definition: enet_ioctl.h:216
ENET_IOCTL_PER_BASE
@ ENET_IOCTL_PER_BASE
Definition: enet_ioctl.h:246
ENET_IOCTL_MAJ
#define ENET_IOCTL_MAJ(x)
Helper macro to set the IOCTL major number.
Definition: enet_ioctl.h:103
Enet_IoctlType_e
Enet_IoctlType_e
IOCTL types.
Definition: enet_ioctl.h:214
Enet_checkInArgs
static uint32_t Enet_checkInArgs(const Enet_IoctlPrms *prms, uint32_t inArgsSize)
Check IOCTL input args for commands that expect an input.
Definition: enet_ioctl.h:450
Enet_IoctlPrms
Enet IOCTL param.
Definition: enet_ioctl.h:282
ENET_IOCTL_PER_GENERIC
@ ENET_IOCTL_PER_GENERIC
Definition: enet_ioctl.h:228
ENET_IOCTL_STATS_BASE
@ ENET_IOCTL_STATS_BASE
Definition: enet_ioctl.h:264
ENET_IOCTL_PER_ICSSG
@ ENET_IOCTL_PER_ICSSG
Definition: enet_ioctl.h:234
ENET_IOCTL_PER
#define ENET_IOCTL_PER(x)
Helper macro to set the IOCTL hardware peripheral.
Definition: enet_ioctl.h:100
ENET_IOCTL_MDIO_BASE
@ ENET_IOCTL_MDIO_BASE
Definition: enet_ioctl.h:261
ENET_IOCTL_FDB_BASE
@ ENET_IOCTL_FDB_BASE
Definition: enet_ioctl.h:249
ENET_IOCTL_PHY_BASE
@ ENET_IOCTL_PHY_BASE
Definition: enet_ioctl.h:267
Enet_IoctlPer_e
Enet_IoctlPer_e
IOCTL peripheral types.
Definition: enet_ioctl.h:226
Enet_IoctlValidate::inArgsSize
uint32_t inArgsSize
Definition: enet_ioctl.h:308
ENET_IOCTL_RM_BASE
@ ENET_IOCTL_RM_BASE
Definition: enet_ioctl.h:270
ENET_IOCTL_PER_GMAC
@ ENET_IOCTL_PER_GMAC
Definition: enet_ioctl.h:237
Enet_checkNoOutArgs
static uint32_t Enet_checkNoOutArgs(const Enet_IoctlPrms *prms)
Check IOCTL output args for commands that don't have output.
Definition: enet_ioctl.h:476
ENET_IOCTL_MACPORT_BASE
@ ENET_IOCTL_MACPORT_BASE
Definition: enet_ioctl.h:258
ENET_IOCTL_TIMESYNC_BASE
@ ENET_IOCTL_TIMESYNC_BASE
Definition: enet_ioctl.h:252
Enet_IoctlPrms::inArgs
const void * inArgs
Definition: enet_ioctl.h:284
ENET_IOCTL_TAS_BASE
@ ENET_IOCTL_TAS_BASE
Definition: enet_ioctl.h:273
ENET_IOCTL_TYPE_PRIVATE
@ ENET_IOCTL_TYPE_PRIVATE
Definition: enet_ioctl.h:219
ENET_SOK
#define ENET_SOK
Success.
Definition: enet_types.h:76
Enet_IoctlPrms::inArgsSize
uint32_t inArgsSize
Definition: enet_ioctl.h:287
Enet_checkInOutArgs
static uint32_t Enet_checkInOutArgs(const Enet_IoctlPrms *prms, uint32_t inArgsSize, uint32_t outArgsSize)
Check IOCTL input and output args.
Definition: enet_ioctl.h:484
Enet_checkNoInArgs
static uint32_t Enet_checkNoInArgs(const Enet_IoctlPrms *prms)
Check IOCTL input args for commands that don't expect an input.
Definition: enet_ioctl.h:459
Enet_IoctlPrms::outArgsSize
uint32_t outArgsSize
Definition: enet_ioctl.h:293
enet_cfg.h
This file contains the Enet configuration parameters.
ENET_IOCTL_TYPE
#define ENET_IOCTL_TYPE(x)
Helper macro to set the IOCTL type.
Definition: enet_ioctl.h:97
Enet_checkOutArgs
static uint32_t Enet_checkOutArgs(const Enet_IoctlPrms *prms, uint32_t outArgsSize)
Check IOCTL output args for commands that expect an output.
Definition: enet_ioctl.h:467
Enet_IoctlPrms::outArgs
void * outArgs
Definition: enet_ioctl.h:290
Enet_IoctlValidate::outArgsSize
uint32_t outArgsSize
Definition: enet_ioctl.h:311