]> Joshua Wise's Git repositories - netwatch.git/blame - net/net.c
Manage to get a nice big packet queue going inside lwIP.
[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{
47c41031
JW
30 unsigned char pkt[1600];
31 int len;
32 struct pbuf *p, *q;
33 struct eth_hdr *ethhdr;
34 int pos = 0;
98d29191 35 static int ticks = 0;
47c41031
JW
36
37 if (!_nic)
38 return;
39
40 smram_tseg_set_state(SMRAM_TSEG_OPEN);
98d29191
JW
41
42 if ((ticks % 1000) == 0) /* About a minute */
43 dhcp_coarse_tmr();
44 if ((ticks % 8) == 0) /* About 500msec*/
45 dhcp_fine_tmr();
46 if ((ticks % 4) == 0) /* About 250msec*/
47 tcp_tmr();
48 ticks++;
6c744a5a 49
4d886842 50 if (_nic->poll(_nic, 0))
47c41031 51 {
4d886842
JW
52 _nic->packet = pkt;
53 _nic->poll(_nic, 1);
54
55 len = _nic->packetlen;
56
57 outputf("NIC: Packet: %d bytes", len);
58
59 p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
60 if (p == NULL)
61 {
62 outputf("NIC: out of memory for packet?");
63 LINK_STATS_INC(link.memerr);
64 LINK_STATS_INC(link.drop);
65 return;
66 }
47c41031 67
4d886842 68 for(q = p; q != NULL; q = q->next)
47c41031 69 {
4d886842
JW
70 memcpy(q->payload, pkt+pos, q->len);
71 pos += q->len;
72 }
73
74 LINK_STATS_INC(link.recv);
75
76 ethhdr = p->payload;
77
78 switch (htons(ethhdr->type)) {
79 case ETHTYPE_IP:
80 case ETHTYPE_ARP:
81 if (_netif.input(p, &_netif) != ERR_OK)
82 {
83 LWIP_DEBUGF(NETIF_DEBUG, ("netdev_input: IP input error\n"));
84 pbuf_free(p);
85 }
86 break;
87
88 default:
89 outputf("Unhandled packet type %04x input", ethhdr->type);
47c41031 90 pbuf_free(p);
4d886842 91 break;
47c41031 92 }
14e7cde4
JP
93 }
94}
95
47c41031 96static err_t _transmit(struct netif *netif, struct pbuf *p)
3b3161a1 97{
47c41031 98 struct nic *nic = netif->state;
99182958 99
54d4b877 100/* for(q = p; q != NULL; q = q->next)
47c41031
JW
101 {
102 memcpy(pkt + len, q->payload, q->len);
103 len += q->len;
54d4b877 104 }*/
50d89a31 105
54d4b877 106 outputf("NIC: Transmit packet");
50d89a31 107
54d4b877 108 nic->transmit(p);
d3411e0d 109
47c41031
JW
110 LINK_STATS_INC(link.xmit);
111
112 return ERR_OK;
113}
114
115static err_t _init(struct netif *netif)
116{
117 struct nic *nic = netif->state;
118
119 LWIP_ASSERT("netif != NULL", (netif != NULL));
120
121#if LWIP_NETIF_HOSTNAME
122 netif->hostname = "netwatch";
123#endif
6c744a5a 124
47c41031 125 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
6c744a5a 126
47c41031
JW
127 netif->name[0] = 'e';
128 netif->name[1] = 'n';
129 netif->output = etharp_output;
130 netif->linkoutput = _transmit;
99182958 131
47c41031
JW
132 memcpy(netif->hwaddr, nic->hwaddr, 6);
133 netif->mtu = 1500;
134 netif->hwaddr_len = ETHARP_HWADDR_LEN;
135 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
136
137 return ERR_OK;
3b3161a1
JW
138}
139
7a914840 140int eth_register(struct nic *nic)
3b3161a1 141{
98d29191 142 static struct ip_addr ipa = { 0 } , netmask = { 0 } , gw = { 0 };
47c41031 143
7a914840
JW
144 if (_nic)
145 return -1;
47c41031
JW
146 netif_add(&_netif, &ipa, &netmask, &gw, (void*)nic, _init, ethernet_input);
147 netif_set_default(&_netif);
148 netif_set_up(&_netif);
98d29191 149 dhcp_start(&_netif);
7a914840
JW
150 _nic = nic;
151 return 0;
3b3161a1
JW
152}
153
154void eth_init()
155{
6f9272bd
JW
156 extern void httpd_init();
157
c25f3f39
JW
158 /* Required for DMA to work. :( */
159 smram_tseg_set_state(SMRAM_TSEG_OPEN);
9552cf46 160 lwip_init();
6f9272bd 161 httpd_init();
80726808 162
7da36fbd 163 rfb_init();
80726808 164
3b3161a1 165}
This page took 0.040733 seconds and 4 git commands to generate.