net: Introduce devicetree aware DEVICE define macros
Provide versions of NET_DEVICE_INIT, NET_DEVICE_INIT_INSTANCE, and NET_DEVICE_OFFLOAD_INIT that are both devicetree node and instance aware. We use the _DEFINE suffix for the DT versions to match the naming convention in device.h Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
8b01efe8e6
commit
ecba5aaa95
1 changed files with 162 additions and 13 deletions
|
@ -2211,6 +2211,15 @@ struct net_if_api {
|
||||||
|
|
||||||
/* Network device initialization macros */
|
/* Network device initialization macros */
|
||||||
|
|
||||||
|
#define Z_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
|
||||||
|
pm_control_fn, data, cfg, prio, api, l2, \
|
||||||
|
l2_ctx_type, mtu) \
|
||||||
|
Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, \
|
||||||
|
pm_control_fn, data, \
|
||||||
|
cfg, POST_KERNEL, prio, api); \
|
||||||
|
NET_L2_DATA_INIT(dev_name, 0, l2_ctx_type); \
|
||||||
|
NET_IF_INIT(dev_name, 0, l2, mtu, NET_IF_MAX_CONFIGS)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def NET_DEVICE_INIT
|
* @def NET_DEVICE_INIT
|
||||||
*
|
*
|
||||||
|
@ -2235,10 +2244,58 @@ struct net_if_api {
|
||||||
#define NET_DEVICE_INIT(dev_name, drv_name, init_fn, pm_control_fn, \
|
#define NET_DEVICE_INIT(dev_name, drv_name, init_fn, pm_control_fn, \
|
||||||
data, cfg, prio, api, l2, \
|
data, cfg, prio, api, l2, \
|
||||||
l2_ctx_type, mtu) \
|
l2_ctx_type, mtu) \
|
||||||
DEVICE_DEFINE(dev_name, drv_name, init_fn, pm_control_fn, data, \
|
Z_NET_DEVICE_INIT(DT_INVALID_NODE, dev_name, drv_name, init_fn, \
|
||||||
cfg, POST_KERNEL, prio, api); \
|
pm_control_fn, data, cfg, prio, api, l2, \
|
||||||
NET_L2_DATA_INIT(dev_name, 0, l2_ctx_type); \
|
l2_ctx_type, mtu)
|
||||||
NET_IF_INIT(dev_name, 0, l2, mtu, NET_IF_MAX_CONFIGS)
|
|
||||||
|
/**
|
||||||
|
* @def NET_DEVICE_DT_DEFINE
|
||||||
|
*
|
||||||
|
* @brief Like NET_DEVICE_INIT but taking metadata from a devicetree node.
|
||||||
|
* Create a network interface and bind it to network device.
|
||||||
|
*
|
||||||
|
* @param node_id The devicetree node identifier.
|
||||||
|
* @param init_fn Address to the init function of the driver.
|
||||||
|
* @param pm_control_fn Pointer to device_pm_control function.
|
||||||
|
* Can be empty function (device_pm_control_nop) if not implemented.
|
||||||
|
* @param data Pointer to the device's private data.
|
||||||
|
* @param cfg The address to the structure containing the
|
||||||
|
* configuration information for this instance of the driver.
|
||||||
|
* @param prio The initialization level at which configuration occurs.
|
||||||
|
* @param api Provides an initial pointer to the API function struct
|
||||||
|
* used by the driver. Can be NULL.
|
||||||
|
* @param l2 Network L2 layer for this network interface.
|
||||||
|
* @param l2_ctx_type Type of L2 context data.
|
||||||
|
* @param mtu Maximum transfer unit in bytes for this network interface.
|
||||||
|
*/
|
||||||
|
#define NET_DEVICE_DT_DEFINE(node_id, init_fn, pm_control_fn, data, cfg, \
|
||||||
|
prio, api, l2, l2_ctx_type, mtu) \
|
||||||
|
Z_NET_DEVICE_INIT(node_id, node_id, DT_LABEL(node_id), init_fn, \
|
||||||
|
pm_control_fn, data, cfg, prio, api, l2, \
|
||||||
|
l2_ctx_type, mtu)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def NET_DEVICE_DT_INST_DEFINE
|
||||||
|
*
|
||||||
|
* @brief Like NET_DEVICE_DT_DEFINE for an instance of a DT_DRV_COMPAT compatible
|
||||||
|
*
|
||||||
|
* @param inst instance number. This is replaced by
|
||||||
|
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_DEFINE.
|
||||||
|
*
|
||||||
|
* @param ... other parameters as expected by NET_DEVICE_DT_DEFINE.
|
||||||
|
*/
|
||||||
|
#define NET_DEVICE_DT_INST_DEFINE(inst, ...) \
|
||||||
|
NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
|
||||||
|
|
||||||
|
#define Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_name, drv_name, \
|
||||||
|
instance, init_fn, pm_control_fn, \
|
||||||
|
data, cfg, prio, api, l2, \
|
||||||
|
l2_ctx_type, mtu) \
|
||||||
|
Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, \
|
||||||
|
pm_control_fn, data, cfg, POST_KERNEL, \
|
||||||
|
prio, api); \
|
||||||
|
NET_L2_DATA_INIT(dev_name, instance, l2_ctx_type); \
|
||||||
|
NET_IF_INIT(dev_name, instance, l2, mtu, NET_IF_MAX_CONFIGS)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def NET_DEVICE_INIT_INSTANCE
|
* @def NET_DEVICE_INIT_INSTANCE
|
||||||
|
@ -2268,10 +2325,63 @@ struct net_if_api {
|
||||||
#define NET_DEVICE_INIT_INSTANCE(dev_name, drv_name, instance, init_fn, \
|
#define NET_DEVICE_INIT_INSTANCE(dev_name, drv_name, instance, init_fn, \
|
||||||
pm_control_fn, data, cfg, prio, \
|
pm_control_fn, data, cfg, prio, \
|
||||||
api, l2, l2_ctx_type, mtu) \
|
api, l2, l2_ctx_type, mtu) \
|
||||||
DEVICE_DEFINE(dev_name, drv_name, init_fn, pm_control_fn, data, \
|
Z_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_name, drv_name, \
|
||||||
cfg, POST_KERNEL, prio, api); \
|
instance, init_fn, pm_control_fn, \
|
||||||
NET_L2_DATA_INIT(dev_name, instance, l2_ctx_type); \
|
data, cfg, prio, api, l2, \
|
||||||
NET_IF_INIT(dev_name, instance, l2, mtu, NET_IF_MAX_CONFIGS)
|
l2_ctx_type, mtu)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def NET_DEVICE_DT_DEFINE_INSTANCE
|
||||||
|
*
|
||||||
|
* @brief Like NET_DEVICE_OFFLOAD_INIT but taking metadata from a devicetree.
|
||||||
|
* Create multiple network interfaces and bind them to network device.
|
||||||
|
* If your network device needs more than one instance of a network interface,
|
||||||
|
* use this macro below and provide a different instance suffix each time
|
||||||
|
* (0, 1, 2, ... or a, b, c ... whatever works for you)
|
||||||
|
*
|
||||||
|
* @param node_id The devicetree node identifier.
|
||||||
|
* @param instance Instance identifier.
|
||||||
|
* @param init_fn Address to the init function of the driver.
|
||||||
|
* @param pm_control_fn Pointer to device_pm_control function.
|
||||||
|
* Can be empty function (device_pm_control_nop) if not implemented.
|
||||||
|
* @param data Pointer to the device's private data.
|
||||||
|
* @param cfg The address to the structure containing the
|
||||||
|
* configuration information for this instance of the driver.
|
||||||
|
* @param prio The initialization level at which configuration occurs.
|
||||||
|
* @param api Provides an initial pointer to the API function struct
|
||||||
|
* used by the driver. Can be NULL.
|
||||||
|
* @param l2 Network L2 layer for this network interface.
|
||||||
|
* @param l2_ctx_type Type of L2 context data.
|
||||||
|
* @param mtu Maximum transfer unit in bytes for this network interface.
|
||||||
|
*/
|
||||||
|
#define NET_DEVICE_DT_DEFINE_INSTANCE(node_id, instance, init_fn, \
|
||||||
|
pm_control_fn, data, cfg, prio, \
|
||||||
|
api, l2, l2_ctx_type, mtu) \
|
||||||
|
Z_NET_DEVICE_INIT_INSTANCE(node_id, node_id, DT_LABEL(node_id), \
|
||||||
|
instance, init_fn, pm_control_fn, \
|
||||||
|
data, cfg, prio, api, l2, \
|
||||||
|
l2_ctx_type, mtu)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def NET_DEVICE_DT_INST_DEFINE_INSTANCE
|
||||||
|
*
|
||||||
|
* @brief Like NET_DEVICE_DT_DEFINE_INSTANCE for an instance of a DT_DRV_COMPAT
|
||||||
|
* compatible
|
||||||
|
*
|
||||||
|
* @param inst instance number. This is replaced by
|
||||||
|
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_DEFINE_INSTANCE.
|
||||||
|
*
|
||||||
|
* @param ... other parameters as expected by NET_DEVICE_DT_DEFINE_INSTANCE.
|
||||||
|
*/
|
||||||
|
#define NET_DEVICE_DT_INST_DEFINE_INSTANCE(inst, ...) \
|
||||||
|
NET_DEVICE_DT_DEFINE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
|
||||||
|
|
||||||
|
#define Z_NET_DEVICE_OFFLOAD_INIT(node_id, dev_name, drv_name, init_fn, \
|
||||||
|
pm_control_fn, data, cfg, prio, \
|
||||||
|
api, mtu) \
|
||||||
|
Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, \
|
||||||
|
pm_control_fn, data, cfg, POST_KERNEL, prio, api);\
|
||||||
|
NET_IF_OFFLOAD_INIT(dev_name, 0, mtu)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def NET_DEVICE_OFFLOAD_INIT
|
* @def NET_DEVICE_OFFLOAD_INIT
|
||||||
|
@ -2295,11 +2405,50 @@ struct net_if_api {
|
||||||
* @param mtu Maximum transfer unit in bytes for this network interface.
|
* @param mtu Maximum transfer unit in bytes for this network interface.
|
||||||
*/
|
*/
|
||||||
#define NET_DEVICE_OFFLOAD_INIT(dev_name, drv_name, init_fn, \
|
#define NET_DEVICE_OFFLOAD_INIT(dev_name, drv_name, init_fn, \
|
||||||
pm_control_fn, data, cfg, prio, \
|
pm_control_fn, data, cfg, prio, api, mtu)\
|
||||||
api, mtu) \
|
Z_NET_DEVICE_OFFLOAD_INIT(DT_INVALID_NODE, dev_name, drv_name, \
|
||||||
DEVICE_DEFINE(dev_name, drv_name, init_fn, pm_control_fn, data, \
|
init_fn, pm_control_fn, data, cfg, prio,\
|
||||||
cfg, POST_KERNEL, prio, api); \
|
api, mtu)
|
||||||
NET_IF_OFFLOAD_INIT(dev_name, 0, mtu)
|
|
||||||
|
/**
|
||||||
|
* @def NET_DEVICE_DT_OFFLOAD_DEFINE
|
||||||
|
*
|
||||||
|
* @brief Like NET_DEVICE_OFFLOAD_INIT but taking metadata from a devicetree
|
||||||
|
* node. Create a offloaded network interface and bind it to network device.
|
||||||
|
* The offloaded network interface is implemented by a device vendor HAL or
|
||||||
|
* similar.
|
||||||
|
*
|
||||||
|
* @param node_id The devicetree node identifier.
|
||||||
|
* @param init_fn Address to the init function of the driver.
|
||||||
|
* @param pm_control_fn Pointer to device_pm_control function.
|
||||||
|
* Can be empty function (device_pm_control_nop) if not implemented.
|
||||||
|
* @param data Pointer to the device's private data.
|
||||||
|
* @param cfg The address to the structure containing the
|
||||||
|
* configuration information for this instance of the driver.
|
||||||
|
* @param prio The initialization level at which configuration occurs.
|
||||||
|
* @param api Provides an initial pointer to the API function struct
|
||||||
|
* used by the driver. Can be NULL.
|
||||||
|
* @param mtu Maximum transfer unit in bytes for this network interface.
|
||||||
|
*/
|
||||||
|
#define NET_DEVICE_DT_OFFLOAD_DEFINE(node_id, init_fn, pm_control_fn, \
|
||||||
|
data, cfg, prio, api, mtu) \
|
||||||
|
Z_NET_DEVICE_OFFLOAD_INIT(node_id, node_id, DT_LABEL(node_id), \
|
||||||
|
init_fn, pm_control_fn, data, cfg, \
|
||||||
|
prio, api, mtu)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @def NET_DEVICE_DT_INST_OFFLOAD_DEFINE
|
||||||
|
*
|
||||||
|
* @brief Like NET_DEVICE_DT_OFFLOAD_DEFINE for an instance of a DT_DRV_COMPAT
|
||||||
|
* compatible
|
||||||
|
*
|
||||||
|
* @param inst instance number. This is replaced by
|
||||||
|
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to NET_DEVICE_DT_OFFLOAD_DEFINE.
|
||||||
|
*
|
||||||
|
* @param ... other parameters as expected by NET_DEVICE_DT_OFFLOAD_DEFINE.
|
||||||
|
*/
|
||||||
|
#define NET_DEVICE_DT_INST_OFFLOAD_DEFINE(inst, ...) \
|
||||||
|
NET_DEVICE_DT_OFFLOAD_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue