AM64x MCU+ SDK  08.02.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 
66 #define ENET_IOCTL_TYPE_OFFSET (24U)
67 
69 #define ENET_IOCTL_PER_OFFSET (16U)
70 
72 #define ENET_IOCTL_MAJOR_OFFSET (8U)
73 
75 #define ENET_IOCTL_MINOR_OFFSET (0U)
76 
78 #define ENET_IOCTL_GET_TYPE(x) ((x) & 0xFF000000U)
79 
81 #define ENET_IOCTL_GET_PER(x) ((x) & 0x00FF0000U)
82 
84 #define ENET_IOCTL_GET_MAJ(x) ((x) & 0x0000FF00U)
85 
87 #define ENET_IOCTL_GET_MIN(x) ((x) & 0x000000FFU)
88 
90 #define ENET_IOCTL_TYPE(x) ((x) << ENET_IOCTL_TYPE_OFFSET)
91 
93 #define ENET_IOCTL_PER(x) ((x) << ENET_IOCTL_PER_OFFSET)
94 
96 #define ENET_IOCTL_MAJ(x) ((x) << ENET_IOCTL_MAJOR_OFFSET)
97 
99 #define ENET_IOCTL_MIN(x) ((x) << ENET_IOCTL_MINOR_OFFSET)
100 
104 #define ENET_IOCTL_SET_NO_ARGS(prms) \
105  { \
106  (prms)->inArgs = NULL; \
107  (prms)->inArgsSize = 0U; \
108  (prms)->outArgs = NULL; \
109  (prms)->outArgsSize = 0U; \
110  }
111 
115 #define ENET_IOCTL_SET_IN_ARGS(prms, in) \
116  { \
117  (prms)->inArgs = (in); \
118  (prms)->inArgsSize = sizeof(*(in)); \
119  (prms)->outArgs = NULL; \
120  (prms)->outArgsSize = 0U; \
121  }
122 
126 #define ENET_IOCTL_SET_OUT_ARGS(prms, out) \
127  { \
128  (prms)->inArgs = NULL; \
129  (prms)->inArgsSize = 0U; \
130  (prms)->outArgs = (out); \
131  (prms)->outArgsSize = sizeof(*(out)); \
132  }
133 
137 #define ENET_IOCTL_SET_INOUT_ARGS(prms, in, out) \
138  { \
139  (prms)->inArgs = (in); \
140  (prms)->inArgsSize = sizeof(*(in)); \
141  (prms)->outArgs = (out); \
142  (prms)->outArgsSize = sizeof(*(out)); \
143  }
144 
149 #define ENET_IOCTL_VALID_PRMS(cmdId, inSize, outSize) \
150  [ENET_IOCTL_GET_MIN(cmdId)] = \
151  { \
152  .cmd = (cmdId), \
153  .inArgsSize = (inSize), \
154  .outArgsSize = (outSize), \
155  }
156 
157 /* ========================================================================== */
158 /* Structures and Enums */
159 /* ========================================================================== */
160 
165 {
168 
171 };
172 
177 {
180 
183 
186 
189 };
190 
195 {
198 
201 
204 
207 
210 
213 
216 
219 
222 
225 };
226 
232 typedef struct Enet_IoctlPrms_s
233 {
235  const void *inArgs;
236 
238  uint32_t inArgsSize;
239 
241  void *outArgs;
242 
244  uint32_t outArgsSize;
246 
253 typedef struct Enet_IoctlValidate_s
254 {
256  uint32_t cmd;
257 
259  uint32_t inArgsSize;
260 
262  uint32_t outArgsSize;
264 
265 /* ========================================================================== */
266 /* Global Variables Declarations */
267 /* ========================================================================== */
268 
269 /* None */
270 
271 /* ========================================================================== */
272 /* Function Declarations */
273 /* ========================================================================== */
274 
287 static inline uint32_t Enet_checkInArgs(const Enet_IoctlPrms *prms,
288  uint32_t inArgsSize);
289 
301 static inline uint32_t Enet_checkNoInArgs(const Enet_IoctlPrms *prms);
302 
315 static inline uint32_t Enet_checkOutArgs(const Enet_IoctlPrms *prms,
316  uint32_t outArgsSize);
317 
329 static inline uint32_t Enet_checkNoOutArgs(const Enet_IoctlPrms *prms);
330 
344 static inline uint32_t Enet_checkInOutArgs(const Enet_IoctlPrms *prms,
345  uint32_t inArgsSize,
346  uint32_t outArgsSize);
347 
348 #if ENET_CFG_IS_ON(DEV_ERROR)
349 
385 int32_t Enet_validateIoctl(uint32_t cmd,
386  const Enet_IoctlPrms *prms,
387  const Enet_IoctlValidate *validIoctls,
388  uint32_t numValidIoctls);
389 #endif
390 
391 /* ========================================================================== */
392 /* Deprecated Function Declarations */
393 /* ========================================================================== */
394 
395 /* None */
396 
397 /* ========================================================================== */
398 /* Static Function Definitions */
399 /* ========================================================================== */
400 
401 static inline uint32_t Enet_checkInArgs(const Enet_IoctlPrms *prms,
402  uint32_t inArgsSize)
403 {
404  return ((prms != NULL) &&
405  (prms->inArgs != NULL) &&
406  (prms->inArgsSize == inArgsSize)) ?
408 }
409 
410 static inline uint32_t Enet_checkNoInArgs(const Enet_IoctlPrms *prms)
411 {
412  return ((prms != NULL) &&
413  (prms->inArgs == NULL) &&
414  (prms->inArgsSize == 0U)) ?
416 }
417 
418 static inline uint32_t Enet_checkOutArgs(const Enet_IoctlPrms *prms,
419  uint32_t outArgsSize)
420 {
421  return ((prms != NULL) &&
422  (prms->outArgs != NULL) &&
423  (prms->outArgsSize == outArgsSize)) ?
425 }
426 
427 static inline uint32_t Enet_checkNoOutArgs(const Enet_IoctlPrms *prms)
428 {
429  return ((prms != NULL) &&
430  (prms->outArgs == NULL) &&
431  (prms->outArgsSize == 0U)) ?
433 }
434 
435 static inline uint32_t Enet_checkInOutArgs(const Enet_IoctlPrms *prms,
436  uint32_t inArgsSize,
437  uint32_t outArgsSize)
438 {
439  return ((prms != NULL) &&
440  (prms->inArgs != NULL) &&
441  (prms->inArgsSize == inArgsSize) &&
442  (prms->outArgs != NULL) &&
443  (prms->outArgsSize == outArgsSize)) ?
445 }
446 
447 #ifdef __cplusplus
448 }
449 #endif
450 
451 #endif /* ENET_IOCTL_H_ */
452 
ENET_IOCTL_PER_CPSW
@ ENET_IOCTL_PER_CPSW
Definition: enet_ioctl.h:182
Enet_IoctlMajor_e
Enet_IoctlMajor_e
IOCTL base number.
Definition: enet_ioctl.h:195
ENET_IOCTL_HOSTPORT_BASE
@ ENET_IOCTL_HOSTPORT_BASE
Definition: enet_ioctl.h:206
Enet_IoctlValidate
Enet IOCTL expected param sizes.
Definition: enet_ioctl.h:254
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:256
ENET_IOCTL_TYPE_PUBLIC
@ ENET_IOCTL_TYPE_PUBLIC
Definition: enet_ioctl.h:167
ENET_IOCTL_PER_BASE
@ ENET_IOCTL_PER_BASE
Definition: enet_ioctl.h:197
ENET_IOCTL_MAJ
#define ENET_IOCTL_MAJ(x)
Helper macro to set the IOCTL major number.
Definition: enet_ioctl.h:96
Enet_IoctlType_e
Enet_IoctlType_e
IOCTL types.
Definition: enet_ioctl.h:165
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:401
Enet_IoctlPrms
Enet IOCTL param.
Definition: enet_ioctl.h:233
ENET_IOCTL_PER_GENERIC
@ ENET_IOCTL_PER_GENERIC
Definition: enet_ioctl.h:179
ENET_IOCTL_STATS_BASE
@ ENET_IOCTL_STATS_BASE
Definition: enet_ioctl.h:215
ENET_IOCTL_PER_ICSSG
@ ENET_IOCTL_PER_ICSSG
Definition: enet_ioctl.h:185
ENET_IOCTL_PER
#define ENET_IOCTL_PER(x)
Helper macro to set the IOCTL type.
Definition: enet_ioctl.h:93
ENET_IOCTL_MDIO_BASE
@ ENET_IOCTL_MDIO_BASE
Definition: enet_ioctl.h:212
ENET_IOCTL_FDB_BASE
@ ENET_IOCTL_FDB_BASE
Definition: enet_ioctl.h:200
ENET_IOCTL_PHY_BASE
@ ENET_IOCTL_PHY_BASE
Definition: enet_ioctl.h:218
Enet_IoctlPer_e
Enet_IoctlPer_e
IOCTL peripheral types.
Definition: enet_ioctl.h:177
Enet_IoctlValidate::inArgsSize
uint32_t inArgsSize
Definition: enet_ioctl.h:259
ENET_IOCTL_RM_BASE
@ ENET_IOCTL_RM_BASE
Definition: enet_ioctl.h:221
ENET_IOCTL_PER_GMAC
@ ENET_IOCTL_PER_GMAC
Definition: enet_ioctl.h:188
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:427
ENET_IOCTL_MACPORT_BASE
@ ENET_IOCTL_MACPORT_BASE
Definition: enet_ioctl.h:209
ENET_IOCTL_TIMESYNC_BASE
@ ENET_IOCTL_TIMESYNC_BASE
Definition: enet_ioctl.h:203
Enet_IoctlPrms::inArgs
const void * inArgs
Definition: enet_ioctl.h:235
ENET_IOCTL_TAS_BASE
@ ENET_IOCTL_TAS_BASE
Definition: enet_ioctl.h:224
ENET_IOCTL_TYPE_PRIVATE
@ ENET_IOCTL_TYPE_PRIVATE
Definition: enet_ioctl.h:170
ENET_SOK
#define ENET_SOK
Success.
Definition: enet_types.h:76
Enet_IoctlPrms::inArgsSize
uint32_t inArgsSize
Definition: enet_ioctl.h:238
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:435
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:410
Enet_IoctlPrms::outArgsSize
uint32_t outArgsSize
Definition: enet_ioctl.h:244
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:90
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:418
Enet_IoctlPrms::outArgs
void * outArgs
Definition: enet_ioctl.h:241
Enet_IoctlValidate::outArgsSize
uint32_t outArgsSize
Definition: enet_ioctl.h:262