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