]> Joshua Wise's Git repositories - netwatch.git/blame - net/net.c
Allow NIC poll routine to do packet chain handling on our behalf.
[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;
47c41031
JW
33
34 if (!_nic)
35 return;
36
37 smram_tseg_set_state(SMRAM_TSEG_OPEN);
98d29191
JW
38
39 if ((ticks % 1000) == 0) /* About a minute */
40 dhcp_coarse_tmr();
41 if ((ticks % 8) == 0) /* About 500msec*/
42 dhcp_fine_tmr();
43 if ((ticks % 4) == 0) /* About 250msec*/
44 tcp_tmr();
45 ticks++;
6c744a5a 46
9c86d6da 47 if ((p = _nic->recv(_nic)) != NULL)
47c41031 48 {
9c86d6da 49 outputf("NIC: Packet: %d bytes", p->tot_len);
4d886842 50
4d886842
JW
51 LINK_STATS_INC(link.recv);
52
53 ethhdr = p->payload;
54
55 switch (htons(ethhdr->type)) {
56 case ETHTYPE_IP:
57 case ETHTYPE_ARP:
58 if (_netif.input(p, &_netif) != ERR_OK)
59 {
60 LWIP_DEBUGF(NETIF_DEBUG, ("netdev_input: IP input error\n"));
61 pbuf_free(p);
62 }
63 break;
64
65 default:
66 outputf("Unhandled packet type %04x input", ethhdr->type);
47c41031 67 pbuf_free(p);
4d886842 68 break;
47c41031 69 }
14e7cde4
JP
70 }
71}
72
47c41031 73static err_t _transmit(struct netif *netif, struct pbuf *p)
3b3161a1 74{
47c41031 75 struct nic *nic = netif->state;
99182958 76
54d4b877 77 outputf("NIC: Transmit packet");
50d89a31 78
54d4b877 79 nic->transmit(p);
d3411e0d 80
47c41031
JW
81 LINK_STATS_INC(link.xmit);
82
83 return ERR_OK;
84}
85
86static err_t _init(struct netif *netif)
87{
88 struct nic *nic = netif->state;
89
90 LWIP_ASSERT("netif != NULL", (netif != NULL));
91
92#if LWIP_NETIF_HOSTNAME
93 netif->hostname = "netwatch";
94#endif
6c744a5a 95
47c41031 96 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
6c744a5a 97
47c41031
JW
98 netif->name[0] = 'e';
99 netif->name[1] = 'n';
100 netif->output = etharp_output;
101 netif->linkoutput = _transmit;
99182958 102
47c41031
JW
103 memcpy(netif->hwaddr, nic->hwaddr, 6);
104 netif->mtu = 1500;
105 netif->hwaddr_len = ETHARP_HWADDR_LEN;
106 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
107
108 return ERR_OK;
3b3161a1
JW
109}
110
7a914840 111int eth_register(struct nic *nic)
3b3161a1 112{
98d29191 113 static struct ip_addr ipa = { 0 } , netmask = { 0 } , gw = { 0 };
47c41031 114
7a914840
JW
115 if (_nic)
116 return -1;
47c41031
JW
117 netif_add(&_netif, &ipa, &netmask, &gw, (void*)nic, _init, ethernet_input);
118 netif_set_default(&_netif);
119 netif_set_up(&_netif);
98d29191 120 dhcp_start(&_netif);
7a914840
JW
121 _nic = nic;
122 return 0;
3b3161a1
JW
123}
124
125void eth_init()
126{
6f9272bd
JW
127 extern void httpd_init();
128
c25f3f39
JW
129 /* Required for DMA to work. :( */
130 smram_tseg_set_state(SMRAM_TSEG_OPEN);
9552cf46 131 lwip_init();
6f9272bd 132 httpd_init();
80726808 133
7da36fbd 134 rfb_init();
80726808 135
3b3161a1 136}
This page took 0.042014 seconds and 4 git commands to generate.