2 * Top-level network glue code
3 * NetWatch system management mode administration console
5 * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved.
6 * This program is free software; you can redistribute and/or modify it under
7 * the terms found in the file LICENSE in the root of this source tree.
13 #include <pci-bother.h>
16 #include <lwip/init.h>
22 #include "lwip/pbuf.h"
24 #include <lwip/stats.h>
25 #include <lwip/snmp.h>
26 #include <lwip/dhcp.h>
28 #include "netif/etharp.h"
29 #include "netif/ppp_oe.h"
33 static struct nic *_nic = 0x0;
34 static struct netif _netif;
36 extern struct pci_driver a3c90x_driver;
38 void eth_recv(struct nic *nic, struct pbuf *p)
40 struct eth_hdr *ethhdr;
42 LINK_STATS_INC(link.recv);
46 switch (htons(ethhdr->type)) {
49 if (_netif.input(p, &_netif) != ERR_OK)
51 LWIP_DEBUGF(NETIF_DEBUG, ("netdev_input: IP input error\n"));
57 outputf("Unhandled packet type %04x input", ethhdr->type);
66 int i = 15; /* Don't process more than 15 packets at a time; we don't want the host to get TOO badly slowed down... */
71 smram_tseg_set_state(SMRAM_TSEG_OPEN);
73 if ((ticks % 1000) == 0) /* About a minute */
75 if ((ticks % 8) == 0) /* About 500msec*/
77 if ((ticks % 4) == 0) /* About 250msec*/
83 int n = _nic->recv(_nic);
90 static err_t _transmit(struct netif *netif, struct pbuf *p)
92 struct nic *nic = netif->state;
94 // outputf("NIC: Transmit packet");
96 nic->transmit(nic, p);
98 LINK_STATS_INC(link.xmit);
103 static err_t _init(struct netif *netif)
105 struct nic *nic = netif->state;
107 LWIP_ASSERT("netif != NULL", (netif != NULL));
109 #if LWIP_NETIF_HOSTNAME
110 netif->hostname = "netwatch";
113 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
115 netif->name[0] = 'e';
116 netif->name[1] = 'n';
117 netif->output = etharp_output;
118 netif->linkoutput = _transmit;
120 memcpy(netif->hwaddr, nic->hwaddr, 6);
122 netif->hwaddr_len = ETHARP_HWADDR_LEN;
123 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
128 int eth_register(struct nic *nic)
130 static struct ip_addr ipa = { 0 } , netmask = { 0 } , gw = { 0 };
134 netif_add(&_netif, &ipa, &netmask, &gw, (void*)nic, _init, ethernet_input);
135 netif_set_default(&_netif);
136 netif_set_up(&_netif);
144 extern void httpd_init();
146 /* Required for DMA to work. :( */
147 smram_tseg_set_state(SMRAM_TSEG_OPEN);