AM243x MCU+ SDK  09.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 
181 #define ENET_IOCTL(hEnet, coreId, ioctlCmd,prms,status) \
182  do { \
183  extern int32_t Enet_ioctl(Enet_Handle enetHandle, \
184  uint32_t ioctlCoreId, \
185  uint32_t cmd, \
186  Enet_IoctlPrms *ioctlPrms); \
187  \
188  extern int32_t Enet_ioctl_register_##ioctlCmd(Enet_Handle enetHandle, \
189  uint32_t ioctlCoreId); \
190  \
191  status = Enet_ioctl_register_##ioctlCmd(hEnet, coreId); \
192  if (ENET_SOK == status) \
193  { \
194  status = Enet_ioctl(hEnet, coreId, ioctlCmd,prms); \
195  } \
196  } while (0)
197 
198 
199 /* ========================================================================== */
200 /* Structures and Enums */
201 /* ========================================================================== */
202 
207 {
210 
213 };
214 
219 {
222 
225 
228 
231 };
232 
237 {
240 
243 
246 
249 
252 
255 
258 
261 
264 
267 };
268 
274 typedef struct Enet_IoctlPrms_s
275 {
277  const void *inArgs;
278 
280  uint32_t inArgsSize;
281 
283  void *outArgs;
284 
286  uint32_t outArgsSize;
288 
295 typedef struct Enet_IoctlValidate_s
296 {
298  uint32_t cmd;
299 
301  uint32_t inArgsSize;
302 
304  uint32_t outArgsSize;
306 
307 /* ========================================================================== */
308 /* Global Variables Declarations */
309 /* ========================================================================== */
310 
311 /* None */
312 
313 /* ========================================================================== */
314 /* Function Declarations */
315 /* ========================================================================== */
316 
329 static inline uint32_t Enet_checkInArgs(const Enet_IoctlPrms *prms,
330  uint32_t inArgsSize);
331 
343 static inline uint32_t Enet_checkNoInArgs(const Enet_IoctlPrms *prms);
344 
357 static inline uint32_t Enet_checkOutArgs(const Enet_IoctlPrms *prms,
358  uint32_t outArgsSize);
359 
371 static inline uint32_t Enet_checkNoOutArgs(const Enet_IoctlPrms *prms);
372 
386 static inline uint32_t Enet_checkInOutArgs(const Enet_IoctlPrms *prms,
387  uint32_t inArgsSize,
388  uint32_t outArgsSize);
389 
390 #if ENET_CFG_IS_ON(DEV_ERROR)
391 
427 int32_t Enet_validateIoctl(uint32_t cmd,
428  const Enet_IoctlPrms *prms,
429  const Enet_IoctlValidate *validIoctls,
430  uint32_t numValidIoctls);
431 #endif
432 
433 /* ========================================================================== */
434 /* Deprecated Function Declarations */
435 /* ========================================================================== */
436 
437 /* None */
438 
439 /* ========================================================================== */
440 /* Static Function Definitions */
441 /* ========================================================================== */
442 
443 static inline uint32_t Enet_checkInArgs(const Enet_IoctlPrms *prms,
444  uint32_t inArgsSize)
445 {
446  return ((prms != NULL) &&
447  (prms->inArgs != NULL) &&
448  (prms->inArgsSize == inArgsSize)) ?
450 }
451 
452 static inline uint32_t Enet_checkNoInArgs(const Enet_IoctlPrms *prms)
453 {
454  return ((prms != NULL) &&
455  (prms->inArgs == NULL) &&
456  (prms->inArgsSize == 0U)) ?
458 }
459 
460 static inline uint32_t Enet_checkOutArgs(const Enet_IoctlPrms *prms,
461  uint32_t outArgsSize)
462 {
463  return ((prms != NULL) &&
464  (prms->outArgs != NULL) &&
465  (prms->outArgsSize == outArgsSize)) ?
467 }
468 
469 static inline uint32_t Enet_checkNoOutArgs(const Enet_IoctlPrms *prms)
470 {
471  return ((prms != NULL) &&
472  (prms->outArgs == NULL) &&
473  (prms->outArgsSize == 0U)) ?
475 }
476 
477 static inline uint32_t Enet_checkInOutArgs(const Enet_IoctlPrms *prms,
478  uint32_t inArgsSize,
479  uint32_t outArgsSize)
480 {
481  return ((prms != NULL) &&
482  (prms->inArgs != NULL) &&
483  (prms->inArgsSize == inArgsSize) &&
484  (prms->outArgs != NULL) &&
485  (prms->outArgsSize == outArgsSize)) ?
487 }
488 
489 #ifdef __cplusplus
490 }
491 #endif
492 
493 #endif /* ENET_IOCTL_H_ */
494 
ENET_IOCTL_PER_CPSW
@ ENET_IOCTL_PER_CPSW
Definition: enet_ioctl.h:224
Enet_IoctlMajor_e
Enet_IoctlMajor_e
IOCTL base number.
Definition: enet_ioctl.h:237
ENET_IOCTL_HOSTPORT_BASE
@ ENET_IOCTL_HOSTPORT_BASE
Definition: enet_ioctl.h:248
Enet_IoctlValidate
Enet IOCTL expected param sizes.
Definition: enet_ioctl.h:296
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:298
ENET_IOCTL_TYPE_PUBLIC
@ ENET_IOCTL_TYPE_PUBLIC
Definition: enet_ioctl.h:209
ENET_IOCTL_PER_BASE
@ ENET_IOCTL_PER_BASE
Definition: enet_ioctl.h:239
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:207
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:443
Enet_IoctlPrms
Enet IOCTL param.
Definition: enet_ioctl.h:275
ENET_IOCTL_PER_GENERIC
@ ENET_IOCTL_PER_GENERIC
Definition: enet_ioctl.h:221
ENET_IOCTL_STATS_BASE
@ ENET_IOCTL_STATS_BASE
Definition: enet_ioctl.h:257
ENET_IOCTL_PER_ICSSG
@ ENET_IOCTL_PER_ICSSG
Definition: enet_ioctl.h:227
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:254
ENET_IOCTL_FDB_BASE
@ ENET_IOCTL_FDB_BASE
Definition: enet_ioctl.h:242
ENET_IOCTL_PHY_BASE
@ ENET_IOCTL_PHY_BASE
Definition: enet_ioctl.h:260
Enet_IoctlPer_e
Enet_IoctlPer_e
IOCTL peripheral types.
Definition: enet_ioctl.h:219
Enet_IoctlValidate::inArgsSize
uint32_t inArgsSize
Definition: enet_ioctl.h:301
ENET_IOCTL_RM_BASE
@ ENET_IOCTL_RM_BASE
Definition: enet_ioctl.h:263
ENET_IOCTL_PER_GMAC
@ ENET_IOCTL_PER_GMAC
Definition: enet_ioctl.h:230
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:469
ENET_IOCTL_MACPORT_BASE
@ ENET_IOCTL_MACPORT_BASE
Definition: enet_ioctl.h:251
ENET_IOCTL_TIMESYNC_BASE
@ ENET_IOCTL_TIMESYNC_BASE
Definition: enet_ioctl.h:245
Enet_IoctlPrms::inArgs
const void * inArgs
Definition: enet_ioctl.h:277
ENET_IOCTL_TAS_BASE
@ ENET_IOCTL_TAS_BASE
Definition: enet_ioctl.h:266
ENET_IOCTL_TYPE_PRIVATE
@ ENET_IOCTL_TYPE_PRIVATE
Definition: enet_ioctl.h:212
ENET_SOK
#define ENET_SOK
Success.
Definition: enet_types.h:76
Enet_IoctlPrms::inArgsSize
uint32_t inArgsSize
Definition: enet_ioctl.h:280
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:477
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:452
Enet_IoctlPrms::outArgsSize
uint32_t outArgsSize
Definition: enet_ioctl.h:286
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:460
Enet_IoctlPrms::outArgs
void * outArgs
Definition: enet_ioctl.h:283
Enet_IoctlValidate::outArgsSize
uint32_t outArgsSize
Definition: enet_ioctl.h:304