]> Joshua Wise's Git repositories - netwatch.git/blame - net/net.c
Avoid suffering from wrong CS_SEGSEL syndrome.
[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
bec09bd1 28void eth_recv(struct nic *nic, struct pbuf *p)
6c744a5a 29{
47c41031 30 struct eth_hdr *ethhdr;
bec09bd1
JW
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{
98d29191 55 static int ticks = 0;
03bcc4db 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... */
47c41031
JW
57
58 if (!_nic)
59 return;
60
61 smram_tseg_set_state(SMRAM_TSEG_OPEN);
98d29191
JW
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++;
6c744a5a 70
bec09bd1 71 while (i > 0)
47c41031 72 {
bec09bd1
JW
73 int n = _nic->recv(_nic);
74 i -= n;
75 if (n == 0)
4d886842 76 break;
14e7cde4
JP
77 }
78}
79
47c41031 80static err_t _transmit(struct netif *netif, struct pbuf *p)
3b3161a1 81{
47c41031 82 struct nic *nic = netif->state;
99182958 83
bc9e1044 84// outputf("NIC: Transmit packet");
50d89a31 85
6d6494e4 86 nic->transmit(nic, p);
d3411e0d 87
47c41031
JW
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
6c744a5a 102
47c41031 103 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
6c744a5a 104
47c41031
JW
105 netif->name[0] = 'e';
106 netif->name[1] = 'n';
107 netif->output = etharp_output;
108 netif->linkoutput = _transmit;
99182958 109
47c41031
JW
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;
3b3161a1
JW
116}
117
7a914840 118int eth_register(struct nic *nic)
3b3161a1 119{
98d29191 120 static struct ip_addr ipa = { 0 } , netmask = { 0 } , gw = { 0 };
47c41031 121
7a914840
JW
122 if (_nic)
123 return -1;
47c41031
JW
124 netif_add(&_netif, &ipa, &netmask, &gw, (void*)nic, _init, ethernet_input);
125 netif_set_default(&_netif);
126 netif_set_up(&_netif);
98d29191 127 dhcp_start(&_netif);
7a914840
JW
128 _nic = nic;
129 return 0;
3b3161a1
JW
130}
131
132void eth_init()
133{
6f9272bd
JW
134 extern void httpd_init();
135
c25f3f39
JW
136 /* Required for DMA to work. :( */
137 smram_tseg_set_state(SMRAM_TSEG_OPEN);
9552cf46 138 lwip_init();
6f9272bd 139 httpd_init();
80726808 140
7da36fbd 141 rfb_init();
80726808 142
3b3161a1 143}
This page took 0.043262 seconds and 4 git commands to generate.