]>
Commit | Line | Data |
---|---|---|
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> | |
16 | #include "netif/etharp.h" | |
17 | #include "netif/ppp_oe.h" | |
3b3161a1 | 18 | |
7a914840 | 19 | static struct nic *_nic = 0x0; |
47c41031 | 20 | static struct netif _netif; |
3e6d6106 | 21 | |
7a914840 JW |
22 | extern struct pci_driver a3c90x_driver; |
23 | ||
47c41031 | 24 | void eth_poll() |
6c744a5a | 25 | { |
47c41031 JW |
26 | unsigned char pkt[1600]; |
27 | int len; | |
28 | struct pbuf *p, *q; | |
29 | struct eth_hdr *ethhdr; | |
30 | int pos = 0; | |
31 | ||
32 | if (!_nic) | |
33 | return; | |
34 | ||
35 | smram_tseg_set_state(SMRAM_TSEG_OPEN); | |
6c744a5a | 36 | |
47c41031 JW |
37 | if (!_nic->poll(_nic, 0)) |
38 | return; | |
39 | ||
40 | _nic->packet = pkt; | |
41 | _nic->poll(_nic, 1); | |
42 | ||
43 | len = _nic->packetlen; | |
14e7cde4 | 44 | |
47c41031 JW |
45 | outputf("NIC: Packet: %d bytes", len); |
46 | ||
47 | p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); | |
48 | if (p == NULL) | |
49 | { | |
50 | outputf("NIC: out of memory for packet?"); | |
51 | LINK_STATS_INC(link.memerr); | |
52 | LINK_STATS_INC(link.drop); | |
53 | return; | |
54 | } | |
55 | ||
56 | for(q = p; q != NULL; q = q->next) | |
57 | { | |
58 | memcpy(q->payload, pkt+pos, q->len); | |
59 | pos += q->len; | |
60 | } | |
14e7cde4 | 61 | |
47c41031 JW |
62 | LINK_STATS_INC(link.recv); |
63 | ||
64 | ethhdr = p->payload; | |
65 | ||
66 | switch (htons(ethhdr->type)) { | |
67 | case ETHTYPE_IP: | |
68 | case ETHTYPE_ARP: | |
69 | if (_netif.input(p, &_netif) != ERR_OK) | |
70 | { | |
71 | LWIP_DEBUGF(NETIF_DEBUG, ("netdev_input: IP input error\n")); | |
72 | pbuf_free(p); | |
73 | } | |
31e64b08 | 74 | break; |
47c41031 JW |
75 | |
76 | default: | |
77 | outputf("Unhandled packet type %04x input", ethhdr->type); | |
78 | pbuf_free(p); | |
31e64b08 | 79 | break; |
14e7cde4 JP |
80 | } |
81 | } | |
82 | ||
47c41031 | 83 | static err_t _transmit(struct netif *netif, struct pbuf *p) |
3b3161a1 | 84 | { |
47c41031 JW |
85 | struct nic *nic = netif->state; |
86 | struct pbuf *q; | |
87 | unsigned char pkt[1600]; | |
88 | unsigned int len = 0; | |
99182958 | 89 | |
47c41031 JW |
90 | for(q = p; q != NULL; q = q->next) |
91 | { | |
92 | memcpy(pkt + len, q->payload, q->len); | |
93 | len += q->len; | |
94 | } | |
50d89a31 | 95 | |
47c41031 | 96 | outputf("NIC: Transmit packet: %d bytes", len); |
50d89a31 | 97 | |
47c41031 | 98 | nic->transmit(len, pkt); |
d3411e0d | 99 | |
47c41031 JW |
100 | LINK_STATS_INC(link.xmit); |
101 | ||
102 | return ERR_OK; | |
103 | } | |
104 | ||
105 | static err_t _init(struct netif *netif) | |
106 | { | |
107 | struct nic *nic = netif->state; | |
108 | ||
109 | LWIP_ASSERT("netif != NULL", (netif != NULL)); | |
110 | ||
111 | #if LWIP_NETIF_HOSTNAME | |
112 | netif->hostname = "netwatch"; | |
113 | #endif | |
6c744a5a | 114 | |
47c41031 | 115 | NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000); |
6c744a5a | 116 | |
47c41031 JW |
117 | netif->name[0] = 'e'; |
118 | netif->name[1] = 'n'; | |
119 | netif->output = etharp_output; | |
120 | netif->linkoutput = _transmit; | |
99182958 | 121 | |
47c41031 JW |
122 | memcpy(netif->hwaddr, nic->hwaddr, 6); |
123 | netif->mtu = 1500; | |
124 | netif->hwaddr_len = ETHARP_HWADDR_LEN; | |
125 | netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; | |
126 | ||
127 | return ERR_OK; | |
3b3161a1 JW |
128 | } |
129 | ||
7a914840 | 130 | int eth_register(struct nic *nic) |
3b3161a1 | 131 | { |
47c41031 JW |
132 | static struct ip_addr ipa = { 0x2dba0280 } , netmask = { 0xF0FFFFFF } , gw = { 0x2eba0280 }; |
133 | ||
7a914840 JW |
134 | if (_nic) |
135 | return -1; | |
47c41031 JW |
136 | netif_add(&_netif, &ipa, &netmask, &gw, (void*)nic, _init, ethernet_input); |
137 | netif_set_default(&_netif); | |
138 | netif_set_up(&_netif); | |
7a914840 JW |
139 | _nic = nic; |
140 | return 0; | |
3b3161a1 JW |
141 | } |
142 | ||
143 | void eth_init() | |
144 | { | |
c25f3f39 JW |
145 | /* Required for DMA to work. :( */ |
146 | smram_tseg_set_state(SMRAM_TSEG_OPEN); | |
9552cf46 | 147 | lwip_init(); |
47c41031 | 148 | pci_probe_driver(a3c90x_driver); |
3b3161a1 | 149 | } |