Skip to content

Commit 16d6965

Browse files
committed
net: Provide new device instantiation macros
Again removing the prio parameter. Managing the ident as a DT node-id or dev_id helps to reduce the number from 12 to 7 macros. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent 1cab0e3 commit 16d6965

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

include/zephyr/net/net_if.h

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,6 +3462,120 @@ struct net_if_api {
34623462
#define NET_DEVICE_DT_INST_OFFLOAD_DEFINE(inst, ...) \
34633463
NET_DEVICE_DT_OFFLOAD_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
34643464

3465+
3466+
/* Network device initialization macros */
3467+
3468+
#define Z_NET_DEVICE_INSTANCE_SFX(ident, sfx, init_fn, pm, data, \
3469+
config, api, l2, l2_ctx_type, mtu) \
3470+
DEVICE_INSTANCE(ident, init_fn, pm, data, config, \
3471+
POST_KERNEL, api); \
3472+
NET_L2_DATA_INIT(Z_DEVICE_ID(ident), sfx, l2_ctx_type); \
3473+
NET_IF_INIT(Z_DEVICE_ID(ident), sfx, l2, mtu, NET_IF_MAX_CONFIGS)
3474+
3475+
/**
3476+
* @brief Create a network interface and bind it to network device.
3477+
*
3478+
* @param ident Either a devicetree node identifier or a plain unique token
3479+
* @param init_fn Address to the init function of the driver.
3480+
* @param pm Reference to struct pm_device associated with the device.
3481+
* (optional).
3482+
* @param data Pointer to the device's private data.
3483+
* @param config The address to the structure containing the
3484+
* configuration information for this instance of the driver.
3485+
* @param api Provides an initial pointer to the API function struct
3486+
* used by the driver. Can be NULL.
3487+
* @param l2 Network L2 layer for this network interface.
3488+
* @param l2_ctx_type Type of L2 context data.
3489+
* @param mtu Maximum transfer unit in bytes for this network interface.
3490+
*/
3491+
#define NET_DEVICE_INSTANCE(ident, init_fn, pm, data, config, \
3492+
api, l2, l2_ctx_type, mtu) \
3493+
Z_NET_DEVICE_INSTANCE_SFX(ident, 0, init_fn, pm, data, config, \
3494+
api, l2, l2_ctx_type, mtu)
3495+
3496+
/**
3497+
* @brief Like NET_DEVICE_INSTANCE for an instance of a DT_DRV_COMPAT compatible
3498+
*
3499+
* @param inst instance number. This is replaced by
3500+
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_INSTANCE.
3501+
*
3502+
* @param ... other parameters as expected by NET_DEVICE_INSTANCE.
3503+
*/
3504+
#define NET_DEVICE_INSTANCE_FROM_DT_INST(inst, ...) \
3505+
NET_DEVICE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
3506+
3507+
/**
3508+
* @brief Create multiple network interfaces and bind them to network device.
3509+
* If your network device needs more than one instance of a network interface,
3510+
* use this macro below and provide a different instance suffix each time
3511+
* (0, 1, 2, ... or a, b, c ... whatever works for you)
3512+
*
3513+
* @param ident Either a devicetree node identifier or a plain unique token
3514+
* @param sfx Instance suffix for differentiation.
3515+
* @param init_fn Address to the init function of the driver.
3516+
* @param pm Reference to struct pm_device associated with the device.
3517+
* (optional).
3518+
* @param data Pointer to the device's private data.
3519+
* @param config The address to the structure containing the
3520+
* configuration information for this instance of the driver.
3521+
* @param api Provides an initial pointer to the API function struct
3522+
* used by the driver. Can be NULL.
3523+
* @param l2 Network L2 layer for this network interface.
3524+
* @param l2_ctx_type Type of L2 context data.
3525+
* @param mtu Maximum transfer unit in bytes for this network interface.
3526+
*/
3527+
#define NET_DEVICE_INSTANCE_MULTI(ident, sfx, init_fn, pm, \
3528+
data, config, api, l2, \
3529+
l2_ctx_type, mtu) \
3530+
Z_NET_DEVICE_INSTANCE_SFX(ident, sfx, init_fn, pm, data, \
3531+
config, api, l2, l2_ctx_type, mtu)
3532+
3533+
/**
3534+
* @brief Like NET_DEVICE_INSTANCE_MULTI for an instance of a DT_DRV_COMPAT
3535+
* compatible
3536+
*
3537+
* @param inst instance number. This is replaced by
3538+
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_INSTANCE_MULTI.
3539+
*
3540+
* @param ... other parameters as expected by NET_DEVICE_INSTANCE_MULTI.
3541+
*/
3542+
#define NET_DEVICE_INSTANCE_MULT_FROM_DT_INST(inst, ...) \
3543+
NET_DEVICE_INSTANCE_MULTI(DT_DRV_INST(inst), __VA_ARGS__)
3544+
3545+
/**
3546+
* @brief Create a offloaded network interface and bind it to network device.
3547+
* The offloaded network interface is implemented by a device vendor HAL or
3548+
* similar.
3549+
*
3550+
* @param ident Either a devicetree node identifier or a plain unique token
3551+
* @param init_fn Address to the init function of the driver.
3552+
* @param pm Reference to struct pm_device associated with the device.
3553+
* (optional).
3554+
* @param data Pointer to the device's private data.
3555+
* @param config The address to the structure containing the
3556+
* configuration information for this instance of the driver.
3557+
* @param api Provides an initial pointer to the API function struct
3558+
* used by the driver. Can be NULL.
3559+
* @param mtu Maximum transfer unit in bytes for this network interface.
3560+
*/
3561+
#define NET_DEVICE_OFFLOAD_INSTANCE(ident, init_fn, pm, data, config, \
3562+
api, mtu) \
3563+
DEVICE_INSTANCE(ident, init_fn, pm, data, config, \
3564+
POST_KERNEL, api); \
3565+
NET_IF_OFFLOAD_INIT(Z_DEVICE_ID(ident), 0, mtu)
3566+
3567+
/**
3568+
* @brief Like NET_DEVICE_OFFLOAD_INSTANCE for an instance of a DT_DRV_COMPAT
3569+
* compatible
3570+
*
3571+
* @param inst instance number. This is replaced by
3572+
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_OFFLOAD_INSTANCE.
3573+
*
3574+
* @param ... other parameters as expected by NET_DEVICE_OFFLOAD_INSTANCE.
3575+
*/
3576+
#define NET_DEVICE_OFFLOAD_INSTANCE_FROM_DT_INST(inst, ...) \
3577+
NET_DEVICE_OFFLOAD_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
3578+
34653579
/**
34663580
* @brief Count the number of network interfaces.
34673581
*

0 commit comments

Comments
 (0)