]> Joshua Wise's Git repositories - netwatch.git/blame - net/net.c
Enable caching while in SMM.
[netwatch.git] / net / net.c
CommitLineData
3b3161a1 1#include <pci.h>
6c744a5a 2#include <smram.h>
4d898e0b 3#include <pci-bother.h>
3b3161a1 4#include <output.h>
14e7cde4 5#include <minilib.h>
9552cf46 6#include <lwip/init.h>
4d898e0b 7#include "net.h"
47c41031
JW
8
9#include "lwip/opt.h"
10#include "lwip/def.h"
11#include "lwip/mem.h"
12#include "lwip/pbuf.h"
13#include "lwip/sys.h"
14#include <lwip/stats.h>
15#include <lwip/snmp.h>
98d29191
JW
16#include <lwip/dhcp.h>
17#include <lwip/tcp.h>
47c41031
JW
18#include "netif/etharp.h"
19#include "netif/ppp_oe.h"
3b3161a1 20
7da36fbd
JP
21#include "rfb.h"
22
7a914840 23static struct nic *_nic = 0x0;
47c41031 24static struct netif _netif;
3e6d6106 25
7a914840
JW
26extern struct pci_driver a3c90x_driver;
27
47c41031 28void eth_poll()
6c744a5a 29{
9c86d6da 30 struct pbuf *p;
47c41031 31 struct eth_hdr *ethhdr;
98d29191 32 static int ticks = 0;
03bcc4db 33 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... */
47c41031
JW
34
35 if (!_nic)
36 return;
37
38 smram_tseg_set_state(SMRAM_TSEG_OPEN);
98d29191
JW
39
40 if ((ticks % 1000) == 0) /* About a minute */
41 dhcp_coarse_tmr();
42 if ((ticks % 8) == 0) /* About 500msec*/
43 dhcp_fine_tmr();
44 if ((ticks % 4) == 0) /* About 250msec*/
45 tcp_tmr();
46 ticks++;
6c744a5a 47
03bcc4db 48 while ((i--) && ((p = _nic->recv(_nic)) != NULL))
47c41031 49 {
bc9e1044 50// outputf("NIC: Packet: %d bytes", p->tot_len);
4d886842 51
4d886842
JW
52 LINK_STATS_INC(link.recv);
53
54 ethhdr = p->payload;
55
56 switch (htons(ethhdr->type)) {
57 case ETHTYPE_IP:
58 case ETHTYPE_ARP:
59 if (_netif.input(p, &_netif) != ERR_OK)
60 {
61 LWIP_DEBUGF(NETIF_DEBUG, ("netdev_input: IP input error\n"));
62 pbuf_free(p);
63 }
64 break;
65
66 default:
67 outputf("Unhandled packet type %04x input", ethhdr->type);
47c41031 68 pbuf_free(p);
4d886842 69 break;
47c41031 70 }
14e7cde4
JP
71 }
72}
73
47c41031 74static err_t _transmit(struct netif *netif, struct pbuf *p)
3b3161a1 75{
47c41031 76 struct nic *nic = netif->state;
99182958 77
bc9e1044 78// outputf("NIC: Transmit packet");
50d89a31 79
54d4b877 80 nic->transmit(p);
d3411e0d 81
47c41031
JW
82 LINK_STATS_INC(link.xmit);
83
84 return ERR_OK;
85}
86
87static err_t _init(struct netif *netif)
88{
89 struct nic *nic = netif->state;
90
91 LWIP_ASSERT("netif != NULL", (netif != NULL));
92
93#if LWIP_NETIF_HOSTNAME
94 netif->hostname = "netwatch";
95#endif
6c744a5a 96
47c41031 97 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
6c744a5a 98
47c41031
JW
99 netif->name[0] = 'e';
100 netif->name[1] = 'n';
101 netif->output = etharp_output;
102 netif->linkoutput = _transmit;
99182958 103
47c41031
JW
104 memcpy(netif->hwaddr, nic->hwaddr, 6);
105 netif->mtu = 1500;
106 netif->hwaddr_len = ETHARP_HWADDR_LEN;
107 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
108
109 return ERR_OK;
3b3161a1
JW
110}
111
7a914840 112int eth_register(struct nic *nic)
3b3161a1 113{
98d29191 114 static struct ip_addr ipa = { 0 } , netmask = { 0 } , gw = { 0 };
47c41031 115
7a914840
JW
116 if (_nic)
117 return -1;
47c41031
JW
118 netif_add(&_netif, &ipa, &netmask, &gw, (void*)nic, _init, ethernet_input);
119 netif_set_default(&_netif);
120 netif_set_up(&_netif);
98d29191 121 dhcp_start(&_netif);
7a914840
JW
122 _nic = nic;
123 return 0;
3b3161a1
JW
124}
125
126void eth_init()
127{
6f9272bd
JW
128 extern void httpd_init();
129
c25f3f39
JW
130 /* Required for DMA to work. :( */
131 smram_tseg_set_state(SMRAM_TSEG_OPEN);
9552cf46 132 lwip_init();
6f9272bd 133 httpd_init();
80726808 134
7da36fbd 135 rfb_init();
80726808 136
3b3161a1 137}
This page took 0.043017 seconds and 4 git commands to generate.