]> Joshua Wise's Git repositories - netwatch.git/blob - net/net.c
Queue up a rxdesc, instead of busy waiting for the card to get back to us. This...
[netwatch.git] / net / net.c
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
23 static struct nic *_nic = 0x0;
24 static struct netif _netif;
25
26 extern struct pci_driver a3c90x_driver;
27
28 void eth_poll()
29 {
30         struct pbuf *p;
31         struct eth_hdr *ethhdr;
32         static int ticks = 0;
33         
34         if (!_nic)
35                 return;
36         
37         smram_tseg_set_state(SMRAM_TSEG_OPEN);
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++;
46
47         if ((p = _nic->recv(_nic)) != NULL)
48         {
49                 outputf("NIC: Packet: %d bytes", p->tot_len);
50                         
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);
67                         pbuf_free(p);
68                         break;
69                 }
70         }
71 }
72
73 static err_t _transmit(struct netif *netif, struct pbuf *p)
74 {
75         struct nic *nic = netif->state;
76
77         outputf("NIC: Transmit packet");
78
79         nic->transmit(p);
80
81         LINK_STATS_INC(link.xmit);
82
83         return ERR_OK;
84 }
85
86 static 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
95         
96         NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
97
98         netif->name[0] = 'e';
99         netif->name[1] = 'n';
100         netif->output = etharp_output;
101         netif->linkoutput = _transmit;
102         
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;
109 }
110
111 int eth_register(struct nic *nic)
112 {
113         static struct ip_addr ipa = { 0 } , netmask = { 0 } , gw = { 0 };
114         
115         if (_nic)
116                 return -1;
117         netif_add(&_netif, &ipa, &netmask, &gw, (void*)nic, _init, ethernet_input);
118         netif_set_default(&_netif);
119         netif_set_up(&_netif);
120         dhcp_start(&_netif);
121         _nic = nic;
122         return 0;
123 }
124
125 void eth_init()
126 {
127         extern void httpd_init();
128         
129         /* Required for DMA to work. :( */
130         smram_tseg_set_state(SMRAM_TSEG_OPEN);
131         lwip_init();
132         httpd_init();
133
134         rfb_init();
135
136 }
This page took 0.028997 seconds and 4 git commands to generate.