use netifapi to initialize the NICs
This commit is contained in:
parent
0bd2888869
commit
2dd6fb87d1
2 changed files with 45 additions and 63 deletions
103
kernel/init.c
103
kernel/init.c
|
@ -34,7 +34,7 @@
|
||||||
#include <lwip/tcp.h>
|
#include <lwip/tcp.h>
|
||||||
#include <lwip/tcpip.h>
|
#include <lwip/tcpip.h>
|
||||||
#include <lwip/dhcp.h>
|
#include <lwip/dhcp.h>
|
||||||
#include <lwip/netif.h>
|
#include <lwip/netifapi.h>
|
||||||
#include <lwip/timers.h>
|
#include <lwip/timers.h>
|
||||||
#include <netif/etharp.h>
|
#include <netif/etharp.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -47,7 +47,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void echo_init(void);
|
void echo_init(void);
|
||||||
void ping_init(void);
|
|
||||||
void netio_init(void);
|
void netio_init(void);
|
||||||
int test_init(void);
|
int test_init(void);
|
||||||
|
|
||||||
|
@ -71,26 +70,20 @@ int lowlevel_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||||
static struct netif* default_netif = NULL;
|
static struct netif default_netif;
|
||||||
|
|
||||||
static int init_netifs(void)
|
static int init_netifs(void)
|
||||||
{
|
{
|
||||||
struct ip_addr ipaddr;
|
struct ip_addr ipaddr;
|
||||||
struct ip_addr netmask;
|
struct ip_addr netmask;
|
||||||
struct ip_addr gw;
|
struct ip_addr gw;
|
||||||
|
err_t err;
|
||||||
|
|
||||||
kputs("Initialize NICs...\n");
|
kputs("Initialize NICs...\n");
|
||||||
|
|
||||||
// Set up the lwIP network interface
|
// Set up the lwIP network interface
|
||||||
// Allocate and configure netif
|
memset(&default_netif, 0x00, sizeof(struct netif));
|
||||||
default_netif = (struct netif *) mem_malloc(sizeof(struct netif));
|
|
||||||
if(default_netif == NULL)
|
|
||||||
{
|
|
||||||
kprintf("ERROR: Out of memory for default netif\n");
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(default_netif, 0x00, sizeof(struct netif));
|
|
||||||
#ifdef CONFIG_ROCKCREEK
|
#ifdef CONFIG_ROCKCREEK
|
||||||
/* Set network address variables */
|
/* Set network address variables */
|
||||||
IP4_ADDR(&gw, 192,168,28,254);
|
IP4_ADDR(&gw, 192,168,28,254);
|
||||||
|
@ -98,15 +91,13 @@ static int init_netifs(void)
|
||||||
IP4_ADDR(&netmask, 255,255,255,0);
|
IP4_ADDR(&netmask, 255,255,255,0);
|
||||||
|
|
||||||
/* Bring up the network interface */
|
/* Bring up the network interface */
|
||||||
if (!netif_add(default_netif, &ipaddr, &netmask, &gw, NULL, rckemacif_init, tcpip_input)) {
|
if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rckemacif_init, tcpip_input)) != ERR_OK) {
|
||||||
kputs("Unable to add network interface\n");
|
kprintf("Unable to add network interface: err = %d\n", err);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
netif_set_default(default_netif);
|
netifapi_netif_set_default(&default_netif);
|
||||||
netif_set_up(default_netif);
|
netifapi_netif_set_up(&default_netif);
|
||||||
|
|
||||||
//mmnif_open();
|
|
||||||
#else
|
#else
|
||||||
/* Clear network address because we use DHCP to get an ip address */
|
/* Clear network address because we use DHCP to get an ip address */
|
||||||
IP4_ADDR(&gw, 0,0,0,0);
|
IP4_ADDR(&gw, 0,0,0,0);
|
||||||
|
@ -114,15 +105,27 @@ static int init_netifs(void)
|
||||||
IP4_ADDR(&netmask, 0,0,0,0);
|
IP4_ADDR(&netmask, 0,0,0,0);
|
||||||
|
|
||||||
/* Bring up the network interface */
|
/* Bring up the network interface */
|
||||||
if (!netif_add(default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, tcpip_input)) {
|
if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, tcpip_input)) != ERR_OK) {
|
||||||
kputs("Unable to add network interface\n");
|
kprintf("Unable to add network interface: err = %d\n", err);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
netif_set_default(default_netif);
|
netifapi_netif_set_default(&default_netif);
|
||||||
|
|
||||||
kprintf("Starting DHCPCD...\n");
|
kprintf("Starting DHCPCD...\n");
|
||||||
dhcp_start(default_netif);
|
netifapi_dhcp_start(&default_netif);
|
||||||
|
|
||||||
|
int mscnt = 0;
|
||||||
|
/* wait for ip address */
|
||||||
|
while(!default_netif.ip_addr.addr) {
|
||||||
|
sys_msleep(DHCP_FINE_TIMER_MSECS);
|
||||||
|
dhcp_fine_tmr();
|
||||||
|
mscnt += DHCP_FINE_TIMER_MSECS;
|
||||||
|
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000) {
|
||||||
|
dhcp_coarse_tmr();
|
||||||
|
mscnt = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -134,43 +137,30 @@ static void tcpip_init_done(void* arg)
|
||||||
{
|
{
|
||||||
sys_sem_t* sem = (sys_sem_t*)arg;
|
sys_sem_t* sem = (sys_sem_t*)arg;
|
||||||
|
|
||||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
|
||||||
init_netifs();
|
|
||||||
#endif
|
|
||||||
sys_sem_signal(sem);
|
sys_sem_signal(sem);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_LWIP
|
|
||||||
static int network_shutdown(void)
|
static int network_shutdown(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_ROCKCREEK
|
#if defined(CONFIG_LWIP) && defined(CONFIG_ROCKCREEK)
|
||||||
if (default_netif) {
|
netifapi_netif_set_link_down(&default_netif);
|
||||||
netif_set_link_down(default_netif);
|
memset(&default_netif, 0x00, sizeof(struct netif));
|
||||||
mem_free(default_netif);
|
#elif defined(CONFIG_LWIP) && defined(CONFIG_PCI)
|
||||||
default_netif = NULL;
|
netifapi_dhcp_stop(&default_netif);
|
||||||
}
|
memset(&default_netif, 0x00, sizeof(struct netif));
|
||||||
//mmnif_close();
|
|
||||||
#elif defined(CONFIG_PCI)
|
|
||||||
if (default_netif) {
|
|
||||||
dhcp_release(default_netif);
|
|
||||||
dhcp_stop(default_netif);
|
|
||||||
mem_free(default_netif);
|
|
||||||
default_netif = NULL;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int shutdown(void)
|
int shutdown(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_LWIP
|
int ret;
|
||||||
return network_shutdown();
|
|
||||||
#else
|
ret = network_shutdown();
|
||||||
return 0;
|
|
||||||
#endif
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void list_fs(vfs_node_t* node, uint32_t depth)
|
static void list_fs(vfs_node_t* node, uint32_t depth)
|
||||||
|
@ -229,30 +219,17 @@ int initd(void* arg)
|
||||||
sys_sem_free(&sem);
|
sys_sem_free(&sem);
|
||||||
|
|
||||||
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
|
||||||
|
init_netifs();
|
||||||
|
|
||||||
/* test if interface is really up */
|
/* test if interface is really up */
|
||||||
if (!netif_is_up(default_netif)) {
|
if (!netif_is_up(&default_netif)) {
|
||||||
kputs("network interface is not up\n");
|
kputs("network interface is not up\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_ROCKCREEK
|
// start echo and/or netio server
|
||||||
int mscnt = 0;
|
|
||||||
/* wait for ip address */
|
|
||||||
while(default_netif && !default_netif->ip_addr.addr) {
|
|
||||||
sys_msleep(DHCP_FINE_TIMER_MSECS);
|
|
||||||
dhcp_fine_tmr();
|
|
||||||
mscnt += DHCP_FINE_TIMER_MSECS;
|
|
||||||
if (mscnt >= DHCP_COARSE_TIMER_SECS*1000) {
|
|
||||||
dhcp_coarse_tmr();
|
|
||||||
mscnt = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// start echo, ping and/or netio server
|
|
||||||
//echo_init();
|
//echo_init();
|
||||||
//ping_init();
|
|
||||||
//netio_init();
|
//netio_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,11 @@
|
||||||
*/
|
*/
|
||||||
#define LWIP_NETCONN 1
|
#define LWIP_NETCONN 1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
|
||||||
|
*/
|
||||||
|
#define LWIP_NETIF_API 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_DHCP==1: Enable DHCP module.
|
* LWIP_DHCP==1: Enable DHCP module.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue