net: Add generic network interface header
This will be used by the new network stack to relate a device to actual network context, and used in the different layers (mac, ip ...). Change-Id: I30c08fa975314544c36b71636fd9653d562891b3 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
257379d0ff
commit
5f165e743f
7 changed files with 208 additions and 1 deletions
|
@ -266,6 +266,16 @@ SECTION_PROLOGUE (_k_task_list, (OPTIONAL),)
|
|||
__bss_end = ALIGN(4);
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
|
||||
#ifdef CONFIG_NET_YAIP
|
||||
SECTION_PROLOGUE(net_if, (OPTIONAL),)
|
||||
{
|
||||
__net_if_start = .;
|
||||
*(".net_if.*")
|
||||
KEEP(*(SORT_BY_NAME(".net_if*")))
|
||||
__net_if_end = .;
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
#endif
|
||||
|
||||
SECTION_PROLOGUE(_NOINIT_SECTION_NAME,(NOLOAD),) {
|
||||
/*
|
||||
* This section is used for non-initialized objects that
|
||||
|
|
|
@ -221,6 +221,16 @@ SECTIONS
|
|||
DEVICE_INIT_SECTIONS()
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
|
||||
#ifdef CONFIG_NET_YAIP
|
||||
SECTION_PROLOGUE(net_if, (OPTIONAL),)
|
||||
{
|
||||
__net_if_start = .;
|
||||
*(".net_if.*")
|
||||
KEEP(*(SORT_BY_NAME(".net_if*")))
|
||||
__net_if_end = .;
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
#endif
|
||||
|
||||
SECTION_PROLOGUE (_k_task_list, (OPTIONAL),)
|
||||
{
|
||||
_k_task_list_start = .;
|
||||
|
|
|
@ -196,6 +196,16 @@ SECTIONS
|
|||
KEXEC_PGALIGN_PAD(MMU_PAGE_SIZE)
|
||||
} GROUP_LINK_IN(RAM)
|
||||
|
||||
#ifdef CONFIG_NET_YAIP
|
||||
SECTION_PROLOGUE(net_if, (OPTIONAL),)
|
||||
{
|
||||
__net_if_start = .;
|
||||
*(".net_if.*")
|
||||
KEEP(*(SORT_BY_NAME(".net_if*")))
|
||||
__net_if_end = .;
|
||||
} GROUP_LINK_IN(RAM)
|
||||
#endif
|
||||
|
||||
SECTION_PROLOGUE(_k_task_list, ALIGN(4), ALIGN(4))
|
||||
{
|
||||
_k_task_list_start = .;
|
||||
|
|
131
include/net/net_if.h
Normal file
131
include/net/net_if.h
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public API for network interface
|
||||
*/
|
||||
|
||||
#ifndef __NET_IF_H__
|
||||
#define __NET_IF_H__
|
||||
|
||||
#include <device.h>
|
||||
|
||||
#include <net/net_linkaddr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Network Interface structure
|
||||
*
|
||||
* Used to handle a network interface on top of a device driver instance.
|
||||
* There can be many net_if instance against the same device.
|
||||
*
|
||||
* Such interface is mainly to be used by the link layer, but is also tight
|
||||
* to a network context: it then makes the relation with a network context
|
||||
* and the network device.
|
||||
*
|
||||
* Because of the strong relationship between a device driver and such
|
||||
* network interface, each net_if should be instanciated by
|
||||
*/
|
||||
struct net_if {
|
||||
/** The actualy device driver instance the net_if is related to */
|
||||
struct device *dev;
|
||||
|
||||
/** The harware link address */
|
||||
struct net_linkaddr link_addr;
|
||||
|
||||
/** The hardware MTU */
|
||||
uint16_t mtu;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's device
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return a pointer on the device driver instance
|
||||
*/
|
||||
static inline struct device *net_if_get_device(struct net_if *iface)
|
||||
{
|
||||
return iface->dev;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's link address
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return a pointer on the network link address
|
||||
*/
|
||||
static inline struct net_linkaddr *net_if_get_link_addr(struct net_if *iface)
|
||||
{
|
||||
return &iface->link_addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a network interfac's link address
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @param addr a pointer on a uint8_t buffer representing the address
|
||||
* @param len length of the address buffer
|
||||
*/
|
||||
static inline void net_if_set_link_addr(struct net_if *iface,
|
||||
uint8_t *addr, uint8_t len)
|
||||
{
|
||||
iface->link_addr.addr = addr;
|
||||
iface->link_addr.len = len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an network interface's MTU
|
||||
* @param iface Pointer to a network interface structure
|
||||
* @return the MTU
|
||||
*/
|
||||
static inline uint16_t net_if_get_mtu(struct net_if *iface)
|
||||
{
|
||||
return iface->mtu;
|
||||
}
|
||||
|
||||
struct net_if_api {
|
||||
void (*init)(struct net_if *iface);
|
||||
};
|
||||
|
||||
#ifdef CONFIG_NET_YAIP
|
||||
|
||||
#define NET_IF_INIT(dev_name, sfx, _mtu) \
|
||||
static struct net_if (__net_if_ ##dev_name _##sfx) __used \
|
||||
__attribute__((__section__(".net_if.data"))) = { \
|
||||
.dev = &(__device_##dev_name), \
|
||||
.mtu = _mtu, \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define NET_IF_INIT(...)
|
||||
|
||||
#endif /* CONFIG_NET_YAIP */
|
||||
|
||||
/* Network device intialization macro */
|
||||
|
||||
#define NET_DEVICE_INIT(dev_name, drv_name, init_fn, \
|
||||
data, cfg_info, prio, api, mtu) \
|
||||
DEVICE_AND_API_INIT(dev_name, drv_name, init_fn, data, \
|
||||
cfg_info, NANOKERNEL, prio, api); \
|
||||
NET_IF_INIT(dev_name, 0, mtu)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NET_IFACE_H__ */
|
|
@ -15,3 +15,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
config NET_YAIP_INIT_PRIO
|
||||
int
|
||||
default 99
|
|
@ -1,2 +1,2 @@
|
|||
ccflags-y += -I${srctree}/net/ip
|
||||
obj-y = net_core.o
|
||||
obj-y = net_core.o net_if.o
|
||||
|
|
42
net/yaip/net_if.c
Normal file
42
net/yaip/net_if.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <init.h>
|
||||
#include <net/net_if.h>
|
||||
|
||||
/* net_if dedicated section limiters */
|
||||
extern struct net_if __net_if_start[];
|
||||
extern struct net_if __net_if_end[];
|
||||
|
||||
static int net_if_init(struct device *unused)
|
||||
{
|
||||
struct net_if_api *api;
|
||||
struct net_if *iface;
|
||||
|
||||
ARG_UNUSED(unused);
|
||||
|
||||
for (iface = __net_if_start; iface != __net_if_end; iface++) {
|
||||
api = (struct net_if_api *) iface->dev->driver_api;
|
||||
|
||||
if (api && api->init) {
|
||||
api->init(iface);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(net_if_init, NANOKERNEL, CONFIG_NET_YAIP_INIT_PRIO);
|
Loading…
Add table
Add a link
Reference in a new issue