Commit 702c85b0e876d587c11acdbb55738ee52acd54f4
Committed by
Ben Warren
1 parent
b3ed233198
Exists in
master
and in
54 other branches
net: ne2000: Divided a function of NE2000 driver
get_prom function was used __attriute__ , but it is not enable. ax88796.o does not do link besides ne2000.o. When ld is carried out, get_prom function of ax88796.c is ignored. This problem is a thing by specifications of ld. I checked and test this patch on SuperH and MIPS. Signed-off-by: Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com> Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Showing 5 changed files with 797 additions and 723 deletions Side-by-side Diff
drivers/net/Makefile
... | ... | @@ -44,10 +44,8 @@ |
44 | 44 | COBJS-$(CONFIG_MPC5xxx_FEC) += mpc5xxx_fec.o |
45 | 45 | COBJS-$(CONFIG_MPC512x_FEC) += mpc512x_fec.o |
46 | 46 | COBJS-$(CONFIG_NATSEMI) += natsemi.o |
47 | -ifeq ($(CONFIG_DRIVER_NE2000),y) | |
48 | -COBJS-y += ne2000.o | |
49 | -COBJS-$(CONFIG_DRIVER_AX88796L) += ax88796.o | |
50 | -endif | |
47 | +COBJS-$(CONFIG_DRIVER_NE2000) += ne2000.o ne2000_base.o | |
48 | +COBJS-$(CONFIG_DRIVER_AX88796L) += ax88796.o ne2000_base.o | |
51 | 49 | COBJS-$(CONFIG_DRIVER_NETARMETH) += netarm_eth.o |
52 | 50 | COBJS-$(CONFIG_NETCONSOLE) += netconsole.o |
53 | 51 | COBJS-$(CONFIG_DRIVER_NS7520_ETHERNET) += ns7520_eth.o |
drivers/net/ax88796.c
drivers/net/ne2000.c
... | ... | @@ -74,600 +74,11 @@ |
74 | 74 | |
75 | 75 | #include <common.h> |
76 | 76 | #include <command.h> |
77 | -#include <net.h> | |
78 | -#include <malloc.h> | |
79 | 77 | |
80 | -#define mdelay(n) udelay((n)*1000) | |
81 | -/* forward definition of function used for the uboot interface */ | |
82 | -void uboot_push_packet_len(int len); | |
83 | -void uboot_push_tx_done(int key, int val); | |
84 | - | |
85 | -/* | |
86 | - * Debugging details | |
87 | - * | |
88 | - * Set to perms of: | |
89 | - * 0 disables all debug output | |
90 | - * 1 for process debug output | |
91 | - * 2 for added data IO output: get_reg, put_reg | |
92 | - * 4 for packet allocation/free output | |
93 | - * 8 for only startup status, so we can tell we're installed OK | |
94 | - */ | |
95 | -#if 0 | |
96 | -#define DEBUG 0xf | |
97 | -#else | |
98 | -#define DEBUG 0 | |
99 | -#endif | |
100 | - | |
101 | -#if DEBUG & 1 | |
102 | -#define DEBUG_FUNCTION() do { printf("%s\n", __FUNCTION__); } while (0) | |
103 | -#define DEBUG_LINE() do { printf("%d\n", __LINE__); } while (0) | |
104 | -#define PRINTK(args...) printf(args) | |
105 | -#else | |
106 | -#define DEBUG_FUNCTION() do {} while(0) | |
107 | -#define DEBUG_LINE() do {} while(0) | |
108 | -#define PRINTK(args...) | |
109 | -#endif | |
110 | - | |
111 | 78 | /* NE2000 base header file */ |
112 | 79 | #include "ne2000_base.h" |
113 | 80 | |
114 | -#if defined(CONFIG_DRIVER_AX88796L) | |
115 | -/* AX88796L support */ | |
116 | -#include "ax88796.h" | |
117 | -#else | |
118 | -/* Basic NE2000 chip support */ | |
119 | -#include "ne2000.h" | |
120 | -#endif | |
121 | - | |
122 | -static dp83902a_priv_data_t nic; /* just one instance of the card supported */ | |
123 | - | |
124 | -static bool | |
125 | -dp83902a_init(void) | |
126 | -{ | |
127 | - dp83902a_priv_data_t *dp = &nic; | |
128 | - u8* base; | |
129 | -#if defined(NE2000_BASIC_INIT) | |
130 | - int i; | |
131 | -#endif | |
132 | - | |
133 | - DEBUG_FUNCTION(); | |
134 | - | |
135 | - base = dp->base; | |
136 | - if (!base) | |
137 | - return false; /* No device found */ | |
138 | - | |
139 | - DEBUG_LINE(); | |
140 | - | |
141 | -#if defined(NE2000_BASIC_INIT) | |
142 | - /* AX88796L doesn't need */ | |
143 | - /* Prepare ESA */ | |
144 | - DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE1); /* Select page 1 */ | |
145 | - /* Use the address from the serial EEPROM */ | |
146 | - for (i = 0; i < 6; i++) | |
147 | - DP_IN(base, DP_P1_PAR0+i, dp->esa[i]); | |
148 | - DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0); /* Select page 0 */ | |
149 | - | |
150 | - printf("NE2000 - %s ESA: %02x:%02x:%02x:%02x:%02x:%02x\n", | |
151 | - "eeprom", | |
152 | - dp->esa[0], | |
153 | - dp->esa[1], | |
154 | - dp->esa[2], | |
155 | - dp->esa[3], | |
156 | - dp->esa[4], | |
157 | - dp->esa[5] ); | |
158 | - | |
159 | -#endif /* NE2000_BASIC_INIT */ | |
160 | - return true; | |
161 | -} | |
162 | - | |
163 | -static void | |
164 | -dp83902a_stop(void) | |
165 | -{ | |
166 | - dp83902a_priv_data_t *dp = &nic; | |
167 | - u8 *base = dp->base; | |
168 | - | |
169 | - DEBUG_FUNCTION(); | |
170 | - | |
171 | - DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_STOP); /* Brutal */ | |
172 | - DP_OUT(base, DP_ISR, 0xFF); /* Clear any pending interrupts */ | |
173 | - DP_OUT(base, DP_IMR, 0x00); /* Disable all interrupts */ | |
174 | - | |
175 | - dp->running = false; | |
176 | -} | |
177 | - | |
178 | -/* | |
179 | - * This function is called to "start up" the interface. It may be called | |
180 | - * multiple times, even when the hardware is already running. It will be | |
181 | - * called whenever something "hardware oriented" changes and should leave | |
182 | - * the hardware ready to send/receive packets. | |
183 | - */ | |
184 | -static void | |
185 | -dp83902a_start(u8 * enaddr) | |
186 | -{ | |
187 | - dp83902a_priv_data_t *dp = &nic; | |
188 | - u8 *base = dp->base; | |
189 | - int i; | |
190 | - | |
191 | - DEBUG_FUNCTION(); | |
192 | - | |
193 | - DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_STOP); /* Brutal */ | |
194 | - DP_OUT(base, DP_DCR, DP_DCR_INIT); | |
195 | - DP_OUT(base, DP_RBCH, 0); /* Remote byte count */ | |
196 | - DP_OUT(base, DP_RBCL, 0); | |
197 | - DP_OUT(base, DP_RCR, DP_RCR_MON); /* Accept no packets */ | |
198 | - DP_OUT(base, DP_TCR, DP_TCR_LOCAL); /* Transmitter [virtually] off */ | |
199 | - DP_OUT(base, DP_TPSR, dp->tx_buf1); /* Transmitter start page */ | |
200 | - dp->tx1 = dp->tx2 = 0; | |
201 | - dp->tx_next = dp->tx_buf1; | |
202 | - dp->tx_started = false; | |
203 | - dp->running = true; | |
204 | - DP_OUT(base, DP_PSTART, dp->rx_buf_start); /* Receive ring start page */ | |
205 | - DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1); /* Receive ring boundary */ | |
206 | - DP_OUT(base, DP_PSTOP, dp->rx_buf_end); /* Receive ring end page */ | |
207 | - dp->rx_next = dp->rx_buf_start - 1; | |
208 | - dp->running = true; | |
209 | - DP_OUT(base, DP_ISR, 0xFF); /* Clear any pending interrupts */ | |
210 | - DP_OUT(base, DP_IMR, DP_IMR_All); /* Enable all interrupts */ | |
211 | - DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE1 | DP_CR_STOP); /* Select page 1 */ | |
212 | - DP_OUT(base, DP_P1_CURP, dp->rx_buf_start); /* Current page - next free page for Rx */ | |
213 | - dp->running = true; | |
214 | - for (i = 0; i < ETHER_ADDR_LEN; i++) { | |
215 | - /* FIXME */ | |
216 | - /*((vu_short*)( base + ((DP_P1_PAR0 + i) * 2) + | |
217 | - * 0x1400)) = enaddr[i];*/ | |
218 | - DP_OUT(base, DP_P1_PAR0+i, enaddr[i]); | |
219 | - } | |
220 | - /* Enable and start device */ | |
221 | - DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
222 | - DP_OUT(base, DP_TCR, DP_TCR_NORMAL); /* Normal transmit operations */ | |
223 | - DP_OUT(base, DP_RCR, DP_RCR_AB); /* Accept broadcast, no errors, no multicast */ | |
224 | - dp->running = true; | |
225 | -} | |
226 | - | |
227 | -/* | |
228 | - * This routine is called to start the transmitter. It is split out from the | |
229 | - * data handling routine so it may be called either when data becomes first | |
230 | - * available or when an Tx interrupt occurs | |
231 | - */ | |
232 | - | |
233 | -static void | |
234 | -dp83902a_start_xmit(int start_page, int len) | |
235 | -{ | |
236 | - dp83902a_priv_data_t *dp = (dp83902a_priv_data_t *) &nic; | |
237 | - u8 *base = dp->base; | |
238 | - | |
239 | - DEBUG_FUNCTION(); | |
240 | - | |
241 | -#if DEBUG & 1 | |
242 | - printf("Tx pkt %d len %d\n", start_page, len); | |
243 | - if (dp->tx_started) | |
244 | - printf("TX already started?!?\n"); | |
245 | -#endif | |
246 | - | |
247 | - DP_OUT(base, DP_ISR, (DP_ISR_TxP | DP_ISR_TxE)); | |
248 | - DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
249 | - DP_OUT(base, DP_TBCL, len & 0xFF); | |
250 | - DP_OUT(base, DP_TBCH, len >> 8); | |
251 | - DP_OUT(base, DP_TPSR, start_page); | |
252 | - DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_TXPKT | DP_CR_START); | |
253 | - | |
254 | - dp->tx_started = true; | |
255 | -} | |
256 | - | |
257 | -/* | |
258 | - * This routine is called to send data to the hardware. It is known a-priori | |
259 | - * that there is free buffer space (dp->tx_next). | |
260 | - */ | |
261 | -static void | |
262 | -dp83902a_send(u8 *data, int total_len, u32 key) | |
263 | -{ | |
264 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
265 | - u8 *base = dp->base; | |
266 | - int len, start_page, pkt_len, i, isr; | |
267 | -#if DEBUG & 4 | |
268 | - int dx; | |
269 | -#endif | |
270 | - | |
271 | - DEBUG_FUNCTION(); | |
272 | - | |
273 | - len = pkt_len = total_len; | |
274 | - if (pkt_len < IEEE_8023_MIN_FRAME) | |
275 | - pkt_len = IEEE_8023_MIN_FRAME; | |
276 | - | |
277 | - start_page = dp->tx_next; | |
278 | - if (dp->tx_next == dp->tx_buf1) { | |
279 | - dp->tx1 = start_page; | |
280 | - dp->tx1_len = pkt_len; | |
281 | - dp->tx1_key = key; | |
282 | - dp->tx_next = dp->tx_buf2; | |
283 | - } else { | |
284 | - dp->tx2 = start_page; | |
285 | - dp->tx2_len = pkt_len; | |
286 | - dp->tx2_key = key; | |
287 | - dp->tx_next = dp->tx_buf1; | |
288 | - } | |
289 | - | |
290 | -#if DEBUG & 5 | |
291 | - printf("TX prep page %d len %d\n", start_page, pkt_len); | |
292 | -#endif | |
293 | - | |
294 | - DP_OUT(base, DP_ISR, DP_ISR_RDC); /* Clear end of DMA */ | |
295 | - { | |
296 | - /* | |
297 | - * Dummy read. The manual sez something slightly different, | |
298 | - * but the code is extended a bit to do what Hitachi's monitor | |
299 | - * does (i.e., also read data). | |
300 | - */ | |
301 | - | |
302 | - u16 tmp; | |
303 | - int len = 1; | |
304 | - | |
305 | - DP_OUT(base, DP_RSAL, 0x100 - len); | |
306 | - DP_OUT(base, DP_RSAH, (start_page - 1) & 0xff); | |
307 | - DP_OUT(base, DP_RBCL, len); | |
308 | - DP_OUT(base, DP_RBCH, 0); | |
309 | - DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_RDMA | DP_CR_START); | |
310 | - DP_IN_DATA(dp->data, tmp); | |
311 | - } | |
312 | - | |
313 | -#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA | |
314 | - /* | |
315 | - * Stall for a bit before continuing to work around random data | |
316 | - * corruption problems on some platforms. | |
317 | - */ | |
318 | - CYGACC_CALL_IF_DELAY_US(1); | |
319 | -#endif | |
320 | - | |
321 | - /* Send data to device buffer(s) */ | |
322 | - DP_OUT(base, DP_RSAL, 0); | |
323 | - DP_OUT(base, DP_RSAH, start_page); | |
324 | - DP_OUT(base, DP_RBCL, pkt_len & 0xFF); | |
325 | - DP_OUT(base, DP_RBCH, pkt_len >> 8); | |
326 | - DP_OUT(base, DP_CR, DP_CR_WDMA | DP_CR_START); | |
327 | - | |
328 | - /* Put data into buffer */ | |
329 | -#if DEBUG & 4 | |
330 | - printf(" sg buf %08lx len %08x\n ", (u32)data, len); | |
331 | - dx = 0; | |
332 | -#endif | |
333 | - while (len > 0) { | |
334 | -#if DEBUG & 4 | |
335 | - printf(" %02x", *data); | |
336 | - if (0 == (++dx % 16)) printf("\n "); | |
337 | -#endif | |
338 | - | |
339 | - DP_OUT_DATA(dp->data, *data++); | |
340 | - len--; | |
341 | - } | |
342 | -#if DEBUG & 4 | |
343 | - printf("\n"); | |
344 | -#endif | |
345 | - if (total_len < pkt_len) { | |
346 | -#if DEBUG & 4 | |
347 | - printf(" + %d bytes of padding\n", pkt_len - total_len); | |
348 | -#endif | |
349 | - /* Padding to 802.3 length was required */ | |
350 | - for (i = total_len; i < pkt_len;) { | |
351 | - i++; | |
352 | - DP_OUT_DATA(dp->data, 0); | |
353 | - } | |
354 | - } | |
355 | - | |
356 | -#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA | |
357 | - /* | |
358 | - * After last data write, delay for a bit before accessing the | |
359 | - * device again, or we may get random data corruption in the last | |
360 | - * datum (on some platforms). | |
361 | - */ | |
362 | - CYGACC_CALL_IF_DELAY_US(1); | |
363 | -#endif | |
364 | - | |
365 | - /* Wait for DMA to complete */ | |
366 | - do { | |
367 | - DP_IN(base, DP_ISR, isr); | |
368 | - } while ((isr & DP_ISR_RDC) == 0); | |
369 | - | |
370 | - /* Then disable DMA */ | |
371 | - DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
372 | - | |
373 | - /* Start transmit if not already going */ | |
374 | - if (!dp->tx_started) { | |
375 | - if (start_page == dp->tx1) { | |
376 | - dp->tx_int = 1; /* Expecting interrupt from BUF1 */ | |
377 | - } else { | |
378 | - dp->tx_int = 2; /* Expecting interrupt from BUF2 */ | |
379 | - } | |
380 | - dp83902a_start_xmit(start_page, pkt_len); | |
381 | - } | |
382 | -} | |
383 | - | |
384 | -/* | |
385 | - * This function is called when a packet has been received. It's job is | |
386 | - * to prepare to unload the packet from the hardware. Once the length of | |
387 | - * the packet is known, the upper layer of the driver can be told. When | |
388 | - * the upper layer is ready to unload the packet, the internal function | |
389 | - * 'dp83902a_recv' will be called to actually fetch it from the hardware. | |
390 | - */ | |
391 | -static void | |
392 | -dp83902a_RxEvent(void) | |
393 | -{ | |
394 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
395 | - u8 *base = dp->base; | |
396 | - u8 rsr; | |
397 | - u8 rcv_hdr[4]; | |
398 | - int i, len, pkt, cur; | |
399 | - | |
400 | - DEBUG_FUNCTION(); | |
401 | - | |
402 | - DP_IN(base, DP_RSR, rsr); | |
403 | - while (true) { | |
404 | - /* Read incoming packet header */ | |
405 | - DP_OUT(base, DP_CR, DP_CR_PAGE1 | DP_CR_NODMA | DP_CR_START); | |
406 | - DP_IN(base, DP_P1_CURP, cur); | |
407 | - DP_OUT(base, DP_P1_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
408 | - DP_IN(base, DP_BNDRY, pkt); | |
409 | - | |
410 | - pkt += 1; | |
411 | - if (pkt == dp->rx_buf_end) | |
412 | - pkt = dp->rx_buf_start; | |
413 | - | |
414 | - if (pkt == cur) { | |
415 | - break; | |
416 | - } | |
417 | - DP_OUT(base, DP_RBCL, sizeof(rcv_hdr)); | |
418 | - DP_OUT(base, DP_RBCH, 0); | |
419 | - DP_OUT(base, DP_RSAL, 0); | |
420 | - DP_OUT(base, DP_RSAH, pkt); | |
421 | - if (dp->rx_next == pkt) { | |
422 | - if (cur == dp->rx_buf_start) | |
423 | - DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1); | |
424 | - else | |
425 | - DP_OUT(base, DP_BNDRY, cur - 1); /* Update pointer */ | |
426 | - return; | |
427 | - } | |
428 | - dp->rx_next = pkt; | |
429 | - DP_OUT(base, DP_ISR, DP_ISR_RDC); /* Clear end of DMA */ | |
430 | - DP_OUT(base, DP_CR, DP_CR_RDMA | DP_CR_START); | |
431 | -#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_RX_DMA | |
432 | - CYGACC_CALL_IF_DELAY_US(10); | |
433 | -#endif | |
434 | - | |
435 | - /* read header (get data size)*/ | |
436 | - for (i = 0; i < sizeof(rcv_hdr);) { | |
437 | - DP_IN_DATA(dp->data, rcv_hdr[i++]); | |
438 | - } | |
439 | - | |
440 | -#if DEBUG & 5 | |
441 | - printf("rx hdr %02x %02x %02x %02x\n", | |
442 | - rcv_hdr[0], rcv_hdr[1], rcv_hdr[2], rcv_hdr[3]); | |
443 | -#endif | |
444 | - len = ((rcv_hdr[3] << 8) | rcv_hdr[2]) - sizeof(rcv_hdr); | |
445 | - | |
446 | - /* data read */ | |
447 | - uboot_push_packet_len(len); | |
448 | - | |
449 | - if (rcv_hdr[1] == dp->rx_buf_start) | |
450 | - DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1); | |
451 | - else | |
452 | - DP_OUT(base, DP_BNDRY, rcv_hdr[1] - 1); /* Update pointer */ | |
453 | - } | |
454 | -} | |
455 | - | |
456 | -/* | |
457 | - * This function is called as a result of the "eth_drv_recv()" call above. | |
458 | - * It's job is to actually fetch data for a packet from the hardware once | |
459 | - * memory buffers have been allocated for the packet. Note that the buffers | |
460 | - * may come in pieces, using a scatter-gather list. This allows for more | |
461 | - * efficient processing in the upper layers of the stack. | |
462 | - */ | |
463 | -static void | |
464 | -dp83902a_recv(u8 *data, int len) | |
465 | -{ | |
466 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
467 | - u8 *base = dp->base; | |
468 | - int i, mlen; | |
469 | - u8 saved_char = 0; | |
470 | - bool saved; | |
471 | -#if DEBUG & 4 | |
472 | - int dx; | |
473 | -#endif | |
474 | - | |
475 | - DEBUG_FUNCTION(); | |
476 | - | |
477 | -#if DEBUG & 5 | |
478 | - printf("Rx packet %d length %d\n", dp->rx_next, len); | |
479 | -#endif | |
480 | - | |
481 | - /* Read incoming packet data */ | |
482 | - DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
483 | - DP_OUT(base, DP_RBCL, len & 0xFF); | |
484 | - DP_OUT(base, DP_RBCH, len >> 8); | |
485 | - DP_OUT(base, DP_RSAL, 4); /* Past header */ | |
486 | - DP_OUT(base, DP_RSAH, dp->rx_next); | |
487 | - DP_OUT(base, DP_ISR, DP_ISR_RDC); /* Clear end of DMA */ | |
488 | - DP_OUT(base, DP_CR, DP_CR_RDMA | DP_CR_START); | |
489 | -#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_RX_DMA | |
490 | - CYGACC_CALL_IF_DELAY_US(10); | |
491 | -#endif | |
492 | - | |
493 | - saved = false; | |
494 | - for (i = 0; i < 1; i++) { | |
495 | - if (data) { | |
496 | - mlen = len; | |
497 | -#if DEBUG & 4 | |
498 | - printf(" sg buf %08lx len %08x \n", (u32) data, mlen); | |
499 | - dx = 0; | |
500 | -#endif | |
501 | - while (0 < mlen) { | |
502 | - /* Saved byte from previous loop? */ | |
503 | - if (saved) { | |
504 | - *data++ = saved_char; | |
505 | - mlen--; | |
506 | - saved = false; | |
507 | - continue; | |
508 | - } | |
509 | - | |
510 | - { | |
511 | - u8 tmp; | |
512 | - DP_IN_DATA(dp->data, tmp); | |
513 | -#if DEBUG & 4 | |
514 | - printf(" %02x", tmp); | |
515 | - if (0 == (++dx % 16)) printf("\n "); | |
516 | -#endif | |
517 | - *data++ = tmp;; | |
518 | - mlen--; | |
519 | - } | |
520 | - } | |
521 | -#if DEBUG & 4 | |
522 | - printf("\n"); | |
523 | -#endif | |
524 | - } | |
525 | - } | |
526 | -} | |
527 | - | |
528 | -static void | |
529 | -dp83902a_TxEvent(void) | |
530 | -{ | |
531 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
532 | - u8 *base = dp->base; | |
533 | - u8 tsr; | |
534 | - u32 key; | |
535 | - | |
536 | - DEBUG_FUNCTION(); | |
537 | - | |
538 | - DP_IN(base, DP_TSR, tsr); | |
539 | - if (dp->tx_int == 1) { | |
540 | - key = dp->tx1_key; | |
541 | - dp->tx1 = 0; | |
542 | - } else { | |
543 | - key = dp->tx2_key; | |
544 | - dp->tx2 = 0; | |
545 | - } | |
546 | - /* Start next packet if one is ready */ | |
547 | - dp->tx_started = false; | |
548 | - if (dp->tx1) { | |
549 | - dp83902a_start_xmit(dp->tx1, dp->tx1_len); | |
550 | - dp->tx_int = 1; | |
551 | - } else if (dp->tx2) { | |
552 | - dp83902a_start_xmit(dp->tx2, dp->tx2_len); | |
553 | - dp->tx_int = 2; | |
554 | - } else { | |
555 | - dp->tx_int = 0; | |
556 | - } | |
557 | - /* Tell higher level we sent this packet */ | |
558 | - uboot_push_tx_done(key, 0); | |
559 | -} | |
560 | - | |
561 | -/* | |
562 | - * Read the tally counters to clear them. Called in response to a CNT | |
563 | - * interrupt. | |
564 | - */ | |
565 | -static void | |
566 | -dp83902a_ClearCounters(void) | |
567 | -{ | |
568 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
569 | - u8 *base = dp->base; | |
570 | - u8 cnt1, cnt2, cnt3; | |
571 | - | |
572 | - DP_IN(base, DP_FER, cnt1); | |
573 | - DP_IN(base, DP_CER, cnt2); | |
574 | - DP_IN(base, DP_MISSED, cnt3); | |
575 | - DP_OUT(base, DP_ISR, DP_ISR_CNT); | |
576 | -} | |
577 | - | |
578 | -/* | |
579 | - * Deal with an overflow condition. This code follows the procedure set | |
580 | - * out in section 7.0 of the datasheet. | |
581 | - */ | |
582 | -static void | |
583 | -dp83902a_Overflow(void) | |
584 | -{ | |
585 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *)&nic; | |
586 | - u8 *base = dp->base; | |
587 | - u8 isr; | |
588 | - | |
589 | - /* Issue a stop command and wait 1.6ms for it to complete. */ | |
590 | - DP_OUT(base, DP_CR, DP_CR_STOP | DP_CR_NODMA); | |
591 | - CYGACC_CALL_IF_DELAY_US(1600); | |
592 | - | |
593 | - /* Clear the remote byte counter registers. */ | |
594 | - DP_OUT(base, DP_RBCL, 0); | |
595 | - DP_OUT(base, DP_RBCH, 0); | |
596 | - | |
597 | - /* Enter loopback mode while we clear the buffer. */ | |
598 | - DP_OUT(base, DP_TCR, DP_TCR_LOCAL); | |
599 | - DP_OUT(base, DP_CR, DP_CR_START | DP_CR_NODMA); | |
600 | - | |
601 | - /* | |
602 | - * Read in as many packets as we can and acknowledge any and receive | |
603 | - * interrupts. Since the buffer has overflowed, a receive event of | |
604 | - * some kind will have occured. | |
605 | - */ | |
606 | - dp83902a_RxEvent(); | |
607 | - DP_OUT(base, DP_ISR, DP_ISR_RxP|DP_ISR_RxE); | |
608 | - | |
609 | - /* Clear the overflow condition and leave loopback mode. */ | |
610 | - DP_OUT(base, DP_ISR, DP_ISR_OFLW); | |
611 | - DP_OUT(base, DP_TCR, DP_TCR_NORMAL); | |
612 | - | |
613 | - /* | |
614 | - * If a transmit command was issued, but no transmit event has occured, | |
615 | - * restart it here. | |
616 | - */ | |
617 | - DP_IN(base, DP_ISR, isr); | |
618 | - if (dp->tx_started && !(isr & (DP_ISR_TxP|DP_ISR_TxE))) { | |
619 | - DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_TXPKT | DP_CR_START); | |
620 | - } | |
621 | -} | |
622 | - | |
623 | -static void | |
624 | -dp83902a_poll(void) | |
625 | -{ | |
626 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
627 | - u8 *base = dp->base; | |
628 | - u8 isr; | |
629 | - | |
630 | - DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0 | DP_CR_START); | |
631 | - DP_IN(base, DP_ISR, isr); | |
632 | - while (0 != isr) { | |
633 | - /* | |
634 | - * The CNT interrupt triggers when the MSB of one of the error | |
635 | - * counters is set. We don't much care about these counters, but | |
636 | - * we should read their values to reset them. | |
637 | - */ | |
638 | - if (isr & DP_ISR_CNT) { | |
639 | - dp83902a_ClearCounters(); | |
640 | - } | |
641 | - /* | |
642 | - * Check for overflow. It's a special case, since there's a | |
643 | - * particular procedure that must be followed to get back into | |
644 | - * a running state.a | |
645 | - */ | |
646 | - if (isr & DP_ISR_OFLW) { | |
647 | - dp83902a_Overflow(); | |
648 | - } else { | |
649 | - /* | |
650 | - * Other kinds of interrupts can be acknowledged simply by | |
651 | - * clearing the relevant bits of the ISR. Do that now, then | |
652 | - * handle the interrupts we care about. | |
653 | - */ | |
654 | - DP_OUT(base, DP_ISR, isr); /* Clear set bits */ | |
655 | - if (!dp->running) break; /* Is this necessary? */ | |
656 | - /* | |
657 | - * Check for tx_started on TX event since these may happen | |
658 | - * spuriously it seems. | |
659 | - */ | |
660 | - if (isr & (DP_ISR_TxP|DP_ISR_TxE) && dp->tx_started) { | |
661 | - dp83902a_TxEvent(); | |
662 | - } | |
663 | - if (isr & (DP_ISR_RxP|DP_ISR_RxE)) { | |
664 | - dp83902a_RxEvent(); | |
665 | - } | |
666 | - } | |
667 | - DP_IN(base, DP_ISR, isr); | |
668 | - } | |
669 | -} | |
670 | - | |
81 | +#define mdelay(n) udelay((n)*1000) | |
671 | 82 | /* find prom (taken from pc_net_cs.c from Linux) */ |
672 | 83 | |
673 | 84 | #include "8390.h" |
674 | 85 | |
675 | 86 | |
676 | 87 | |
677 | 88 | |
... | ... | @@ -763,18 +174,16 @@ |
763 | 174 | #define PCNET_RESET 0x1f /* Issue a read to reset, a write to clear. */ |
764 | 175 | #define PCNET_MISC 0x18 /* For IBM CCAE and Socket EA cards */ |
765 | 176 | |
766 | -static void pcnet_reset_8390(void) | |
177 | +static void pcnet_reset_8390(u8* addr) | |
767 | 178 | { |
768 | 179 | int i, r; |
769 | 180 | |
770 | - PRINTK("nic base is %lx\n", nic.base); | |
771 | - | |
772 | 181 | n2k_outb(E8390_NODMA + E8390_PAGE0+E8390_STOP, E8390_CMD); |
773 | - PRINTK("cmd (at %lx) is %x\n", nic.base + E8390_CMD, n2k_inb(E8390_CMD)); | |
182 | + PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(E8390_CMD)); | |
774 | 183 | n2k_outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, E8390_CMD); |
775 | - PRINTK("cmd (at %lx) is %x\n", nic.base + E8390_CMD, n2k_inb(E8390_CMD)); | |
184 | + PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(E8390_CMD)); | |
776 | 185 | n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD); |
777 | - PRINTK("cmd (at %lx) is %x\n", nic.base + E8390_CMD, n2k_inb(E8390_CMD)); | |
186 | + PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(E8390_CMD)); | |
778 | 187 | n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD); |
779 | 188 | |
780 | 189 | n2k_outb(n2k_inb(PCNET_RESET), PCNET_RESET); |
... | ... | @@ -791,8 +200,7 @@ |
791 | 200 | printf("pcnet_reset_8390() did not complete.\n"); |
792 | 201 | } /* pcnet_reset_8390 */ |
793 | 202 | |
794 | -int get_prom(u8* mac_addr) __attribute__ ((weak, alias ("__get_prom"))); | |
795 | -int __get_prom(u8* mac_addr) | |
203 | +int get_prom(u8* mac_addr, u8* base_addr) | |
796 | 204 | { |
797 | 205 | u8 prom[32]; |
798 | 206 | int i, j; |
... | ... | @@ -816,7 +224,7 @@ |
816 | 224 | |
817 | 225 | PRINTK ("trying to get MAC via prom reading\n"); |
818 | 226 | |
819 | - pcnet_reset_8390 (); | |
227 | + pcnet_reset_8390 (base_addr); | |
820 | 228 | |
821 | 229 | mdelay (10); |
822 | 230 | |
... | ... | @@ -846,119 +254,6 @@ |
846 | 254 | } |
847 | 255 | PRINTK ("\n"); |
848 | 256 | return (i < NR_INFO) ? i : 0; |
849 | - } | |
850 | - return 0; | |
851 | -} | |
852 | - | |
853 | -/* U-boot specific routines */ | |
854 | -static u8 *pbuf = NULL; | |
855 | - | |
856 | -static int pkey = -1; | |
857 | -static int initialized = 0; | |
858 | - | |
859 | -void uboot_push_packet_len(int len) { | |
860 | - PRINTK("pushed len = %d\n", len); | |
861 | - if (len >= 2000) { | |
862 | - printf("NE2000: packet too big\n"); | |
863 | - return; | |
864 | - } | |
865 | - dp83902a_recv(&pbuf[0], len); | |
866 | - | |
867 | - /*Just pass it to the upper layer*/ | |
868 | - NetReceive(&pbuf[0], len); | |
869 | -} | |
870 | - | |
871 | -void uboot_push_tx_done(int key, int val) { | |
872 | - PRINTK("pushed key = %d\n", key); | |
873 | - pkey = key; | |
874 | -} | |
875 | - | |
876 | -int eth_init(bd_t *bd) { | |
877 | - int r; | |
878 | - u8 dev_addr[6]; | |
879 | - char ethaddr[20]; | |
880 | - | |
881 | - PRINTK("### eth_init\n"); | |
882 | - | |
883 | - if (!pbuf) { | |
884 | - pbuf = malloc(2000); | |
885 | - if (!pbuf) { | |
886 | - printf("Cannot allocate rx buffer\n"); | |
887 | - return -1; | |
888 | - } | |
889 | - } | |
890 | - | |
891 | -#ifdef CONFIG_DRIVER_NE2000_CCR | |
892 | - { | |
893 | - vu_char *p = (vu_char *) CONFIG_DRIVER_NE2000_CCR; | |
894 | - | |
895 | - PRINTK("CCR before is %x\n", *p); | |
896 | - *p = CONFIG_DRIVER_NE2000_VAL; | |
897 | - PRINTK("CCR after is %x\n", *p); | |
898 | - } | |
899 | -#endif | |
900 | - | |
901 | - nic.base = (u8 *) CONFIG_DRIVER_NE2000_BASE; | |
902 | - | |
903 | - r = get_prom(dev_addr); | |
904 | - if (!r) | |
905 | - return -1; | |
906 | - | |
907 | - sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X", | |
908 | - dev_addr[0], dev_addr[1], | |
909 | - dev_addr[2], dev_addr[3], | |
910 | - dev_addr[4], dev_addr[5]) ; | |
911 | - PRINTK("Set environment from HW MAC addr = \"%s\"\n", ethaddr); | |
912 | - setenv ("ethaddr", ethaddr); | |
913 | - | |
914 | - nic.data = nic.base + DP_DATA; | |
915 | - nic.tx_buf1 = START_PG; | |
916 | - nic.tx_buf2 = START_PG2; | |
917 | - nic.rx_buf_start = RX_START; | |
918 | - nic.rx_buf_end = RX_END; | |
919 | - | |
920 | - if (dp83902a_init() == false) | |
921 | - return -1; | |
922 | - | |
923 | - dp83902a_start(dev_addr); | |
924 | - initialized = 1; | |
925 | - | |
926 | - return 0; | |
927 | -} | |
928 | - | |
929 | -void eth_halt() { | |
930 | - | |
931 | - PRINTK("### eth_halt\n"); | |
932 | - if(initialized) | |
933 | - dp83902a_stop(); | |
934 | - initialized = 0; | |
935 | -} | |
936 | - | |
937 | -int eth_rx() { | |
938 | - dp83902a_poll(); | |
939 | - return 1; | |
940 | -} | |
941 | - | |
942 | -int eth_send(volatile void *packet, int length) { | |
943 | - int tmo; | |
944 | - | |
945 | - PRINTK("### eth_send\n"); | |
946 | - | |
947 | - pkey = -1; | |
948 | - | |
949 | - dp83902a_send((u8 *) packet, length, 666); | |
950 | - tmo = get_timer (0) + TOUT * CFG_HZ; | |
951 | - while(1) { | |
952 | - dp83902a_poll(); | |
953 | - if (pkey != -1) { | |
954 | - PRINTK("Packet sucesfully sent\n"); | |
955 | - return 0; | |
956 | - } | |
957 | - if (get_timer (0) >= tmo) { | |
958 | - printf("transmission error (timoeut)\n"); | |
959 | - return 0; | |
960 | - } | |
961 | - | |
962 | 257 | } |
963 | 258 | return 0; |
964 | 259 | } |
drivers/net/ne2000_base.c
1 | +/* | |
2 | +Ported to U-Boot by Christian Pellegrin <chri@ascensit.com> | |
3 | + | |
4 | +Based on sources from the Linux kernel (pcnet_cs.c, 8390.h) and | |
5 | +eCOS(if_dp83902a.c, if_dp83902a.h). Both of these 2 wonderful world | |
6 | +are GPL, so this is, of course, GPL. | |
7 | + | |
8 | +========================================================================== | |
9 | + | |
10 | +dev/if_dp83902a.c | |
11 | + | |
12 | +Ethernet device driver for NS DP83902a ethernet controller | |
13 | + | |
14 | +========================================================================== | |
15 | +####ECOSGPLCOPYRIGHTBEGIN#### | |
16 | +------------------------------------------- | |
17 | +This file is part of eCos, the Embedded Configurable Operating System. | |
18 | +Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. | |
19 | + | |
20 | +eCos is free software; you can redistribute it and/or modify it under | |
21 | +the terms of the GNU General Public License as published by the Free | |
22 | +Software Foundation; either version 2 or (at your option) any later version. | |
23 | + | |
24 | +eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
25 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
26 | +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
27 | +for more details. | |
28 | + | |
29 | +You should have received a copy of the GNU General Public License along | |
30 | +with eCos; if not, write to the Free Software Foundation, Inc., | |
31 | +59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
32 | + | |
33 | +As a special exception, if other files instantiate templates or use macros | |
34 | +or inline functions from this file, or you compile this file and link it | |
35 | +with other works to produce a work based on this file, this file does not | |
36 | +by itself cause the resulting work to be covered by the GNU General Public | |
37 | +License. However the source code for this file must still be made available | |
38 | +in accordance with section (3) of the GNU General Public License. | |
39 | + | |
40 | +This exception does not invalidate any other reasons why a work based on | |
41 | +this file might be covered by the GNU General Public License. | |
42 | + | |
43 | +Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | |
44 | +at http://sources.redhat.com/ecos/ecos-license/ | |
45 | +------------------------------------------- | |
46 | +####ECOSGPLCOPYRIGHTEND#### | |
47 | +####BSDCOPYRIGHTBEGIN#### | |
48 | + | |
49 | +------------------------------------------- | |
50 | + | |
51 | +Portions of this software may have been derived from OpenBSD or other sources, | |
52 | +and are covered by the appropriate copyright disclaimers included herein. | |
53 | + | |
54 | +------------------------------------------- | |
55 | + | |
56 | +####BSDCOPYRIGHTEND#### | |
57 | +========================================================================== | |
58 | +#####DESCRIPTIONBEGIN#### | |
59 | + | |
60 | +Author(s): gthomas | |
61 | +Contributors: gthomas, jskov, rsandifo | |
62 | +Date: 2001-06-13 | |
63 | +Purpose: | |
64 | +Description: | |
65 | + | |
66 | +FIXME: Will fail if pinged with large packets (1520 bytes) | |
67 | +Add promisc config | |
68 | +Add SNMP | |
69 | + | |
70 | +####DESCRIPTIONEND#### | |
71 | + | |
72 | +========================================================================== | |
73 | +*/ | |
74 | + | |
75 | +#include <common.h> | |
76 | +#include <command.h> | |
77 | +#include <net.h> | |
78 | +#include <malloc.h> | |
79 | + | |
80 | +#define mdelay(n) udelay((n)*1000) | |
81 | +/* forward definition of function used for the uboot interface */ | |
82 | +void uboot_push_packet_len(int len); | |
83 | +void uboot_push_tx_done(int key, int val); | |
84 | + | |
85 | +/* NE2000 base header file */ | |
86 | +#include "ne2000_base.h" | |
87 | + | |
88 | +#if defined(CONFIG_DRIVER_AX88796L) | |
89 | +/* AX88796L support */ | |
90 | +#include "ax88796.h" | |
91 | +#else | |
92 | +/* Basic NE2000 chip support */ | |
93 | +#include "ne2000.h" | |
94 | +#endif | |
95 | + | |
96 | +static dp83902a_priv_data_t nic; /* just one instance of the card supported */ | |
97 | + | |
98 | +static bool | |
99 | +dp83902a_init(void) | |
100 | +{ | |
101 | + dp83902a_priv_data_t *dp = &nic; | |
102 | + u8* base; | |
103 | +#if defined(NE2000_BASIC_INIT) | |
104 | + int i; | |
105 | +#endif | |
106 | + | |
107 | + DEBUG_FUNCTION(); | |
108 | + | |
109 | + base = dp->base; | |
110 | + if (!base) | |
111 | + return false; /* No device found */ | |
112 | + | |
113 | + DEBUG_LINE(); | |
114 | + | |
115 | +#if defined(NE2000_BASIC_INIT) | |
116 | + /* AX88796L doesn't need */ | |
117 | + /* Prepare ESA */ | |
118 | + DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE1); /* Select page 1 */ | |
119 | + /* Use the address from the serial EEPROM */ | |
120 | + for (i = 0; i < 6; i++) | |
121 | + DP_IN(base, DP_P1_PAR0+i, dp->esa[i]); | |
122 | + DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0); /* Select page 0 */ | |
123 | + | |
124 | + printf("NE2000 - %s ESA: %02x:%02x:%02x:%02x:%02x:%02x\n", | |
125 | + "eeprom", | |
126 | + dp->esa[0], | |
127 | + dp->esa[1], | |
128 | + dp->esa[2], | |
129 | + dp->esa[3], | |
130 | + dp->esa[4], | |
131 | + dp->esa[5] ); | |
132 | + | |
133 | +#endif /* NE2000_BASIC_INIT */ | |
134 | + return true; | |
135 | +} | |
136 | + | |
137 | +static void | |
138 | +dp83902a_stop(void) | |
139 | +{ | |
140 | + dp83902a_priv_data_t *dp = &nic; | |
141 | + u8 *base = dp->base; | |
142 | + | |
143 | + DEBUG_FUNCTION(); | |
144 | + | |
145 | + DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_STOP); /* Brutal */ | |
146 | + DP_OUT(base, DP_ISR, 0xFF); /* Clear any pending interrupts */ | |
147 | + DP_OUT(base, DP_IMR, 0x00); /* Disable all interrupts */ | |
148 | + | |
149 | + dp->running = false; | |
150 | +} | |
151 | + | |
152 | +/* | |
153 | + * This function is called to "start up" the interface. It may be called | |
154 | + * multiple times, even when the hardware is already running. It will be | |
155 | + * called whenever something "hardware oriented" changes and should leave | |
156 | + * the hardware ready to send/receive packets. | |
157 | + */ | |
158 | +static void | |
159 | +dp83902a_start(u8 * enaddr) | |
160 | +{ | |
161 | + dp83902a_priv_data_t *dp = &nic; | |
162 | + u8 *base = dp->base; | |
163 | + int i; | |
164 | + | |
165 | + DEBUG_FUNCTION(); | |
166 | + | |
167 | + DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_STOP); /* Brutal */ | |
168 | + DP_OUT(base, DP_DCR, DP_DCR_INIT); | |
169 | + DP_OUT(base, DP_RBCH, 0); /* Remote byte count */ | |
170 | + DP_OUT(base, DP_RBCL, 0); | |
171 | + DP_OUT(base, DP_RCR, DP_RCR_MON); /* Accept no packets */ | |
172 | + DP_OUT(base, DP_TCR, DP_TCR_LOCAL); /* Transmitter [virtually] off */ | |
173 | + DP_OUT(base, DP_TPSR, dp->tx_buf1); /* Transmitter start page */ | |
174 | + dp->tx1 = dp->tx2 = 0; | |
175 | + dp->tx_next = dp->tx_buf1; | |
176 | + dp->tx_started = false; | |
177 | + dp->running = true; | |
178 | + DP_OUT(base, DP_PSTART, dp->rx_buf_start); /* Receive ring start page */ | |
179 | + DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1); /* Receive ring boundary */ | |
180 | + DP_OUT(base, DP_PSTOP, dp->rx_buf_end); /* Receive ring end page */ | |
181 | + dp->rx_next = dp->rx_buf_start - 1; | |
182 | + dp->running = true; | |
183 | + DP_OUT(base, DP_ISR, 0xFF); /* Clear any pending interrupts */ | |
184 | + DP_OUT(base, DP_IMR, DP_IMR_All); /* Enable all interrupts */ | |
185 | + DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE1 | DP_CR_STOP); /* Select page 1 */ | |
186 | + DP_OUT(base, DP_P1_CURP, dp->rx_buf_start); /* Current page - next free page for Rx */ | |
187 | + dp->running = true; | |
188 | + for (i = 0; i < ETHER_ADDR_LEN; i++) { | |
189 | + /* FIXME */ | |
190 | + /*((vu_short*)( base + ((DP_P1_PAR0 + i) * 2) + | |
191 | + * 0x1400)) = enaddr[i];*/ | |
192 | + DP_OUT(base, DP_P1_PAR0+i, enaddr[i]); | |
193 | + } | |
194 | + /* Enable and start device */ | |
195 | + DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
196 | + DP_OUT(base, DP_TCR, DP_TCR_NORMAL); /* Normal transmit operations */ | |
197 | + DP_OUT(base, DP_RCR, DP_RCR_AB); /* Accept broadcast, no errors, no multicast */ | |
198 | + dp->running = true; | |
199 | +} | |
200 | + | |
201 | +/* | |
202 | + * This routine is called to start the transmitter. It is split out from the | |
203 | + * data handling routine so it may be called either when data becomes first | |
204 | + * available or when an Tx interrupt occurs | |
205 | + */ | |
206 | + | |
207 | +static void | |
208 | +dp83902a_start_xmit(int start_page, int len) | |
209 | +{ | |
210 | + dp83902a_priv_data_t *dp = (dp83902a_priv_data_t *) &nic; | |
211 | + u8 *base = dp->base; | |
212 | + | |
213 | + DEBUG_FUNCTION(); | |
214 | + | |
215 | +#if DEBUG & 1 | |
216 | + printf("Tx pkt %d len %d\n", start_page, len); | |
217 | + if (dp->tx_started) | |
218 | + printf("TX already started?!?\n"); | |
219 | +#endif | |
220 | + | |
221 | + DP_OUT(base, DP_ISR, (DP_ISR_TxP | DP_ISR_TxE)); | |
222 | + DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
223 | + DP_OUT(base, DP_TBCL, len & 0xFF); | |
224 | + DP_OUT(base, DP_TBCH, len >> 8); | |
225 | + DP_OUT(base, DP_TPSR, start_page); | |
226 | + DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_TXPKT | DP_CR_START); | |
227 | + | |
228 | + dp->tx_started = true; | |
229 | +} | |
230 | + | |
231 | +/* | |
232 | + * This routine is called to send data to the hardware. It is known a-priori | |
233 | + * that there is free buffer space (dp->tx_next). | |
234 | + */ | |
235 | +static void | |
236 | +dp83902a_send(u8 *data, int total_len, u32 key) | |
237 | +{ | |
238 | + struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
239 | + u8 *base = dp->base; | |
240 | + int len, start_page, pkt_len, i, isr; | |
241 | +#if DEBUG & 4 | |
242 | + int dx; | |
243 | +#endif | |
244 | + | |
245 | + DEBUG_FUNCTION(); | |
246 | + | |
247 | + len = pkt_len = total_len; | |
248 | + if (pkt_len < IEEE_8023_MIN_FRAME) | |
249 | + pkt_len = IEEE_8023_MIN_FRAME; | |
250 | + | |
251 | + start_page = dp->tx_next; | |
252 | + if (dp->tx_next == dp->tx_buf1) { | |
253 | + dp->tx1 = start_page; | |
254 | + dp->tx1_len = pkt_len; | |
255 | + dp->tx1_key = key; | |
256 | + dp->tx_next = dp->tx_buf2; | |
257 | + } else { | |
258 | + dp->tx2 = start_page; | |
259 | + dp->tx2_len = pkt_len; | |
260 | + dp->tx2_key = key; | |
261 | + dp->tx_next = dp->tx_buf1; | |
262 | + } | |
263 | + | |
264 | +#if DEBUG & 5 | |
265 | + printf("TX prep page %d len %d\n", start_page, pkt_len); | |
266 | +#endif | |
267 | + | |
268 | + DP_OUT(base, DP_ISR, DP_ISR_RDC); /* Clear end of DMA */ | |
269 | + { | |
270 | + /* | |
271 | + * Dummy read. The manual sez something slightly different, | |
272 | + * but the code is extended a bit to do what Hitachi's monitor | |
273 | + * does (i.e., also read data). | |
274 | + */ | |
275 | + | |
276 | + u16 tmp; | |
277 | + int len = 1; | |
278 | + | |
279 | + DP_OUT(base, DP_RSAL, 0x100 - len); | |
280 | + DP_OUT(base, DP_RSAH, (start_page - 1) & 0xff); | |
281 | + DP_OUT(base, DP_RBCL, len); | |
282 | + DP_OUT(base, DP_RBCH, 0); | |
283 | + DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_RDMA | DP_CR_START); | |
284 | + DP_IN_DATA(dp->data, tmp); | |
285 | + } | |
286 | + | |
287 | +#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA | |
288 | + /* | |
289 | + * Stall for a bit before continuing to work around random data | |
290 | + * corruption problems on some platforms. | |
291 | + */ | |
292 | + CYGACC_CALL_IF_DELAY_US(1); | |
293 | +#endif | |
294 | + | |
295 | + /* Send data to device buffer(s) */ | |
296 | + DP_OUT(base, DP_RSAL, 0); | |
297 | + DP_OUT(base, DP_RSAH, start_page); | |
298 | + DP_OUT(base, DP_RBCL, pkt_len & 0xFF); | |
299 | + DP_OUT(base, DP_RBCH, pkt_len >> 8); | |
300 | + DP_OUT(base, DP_CR, DP_CR_WDMA | DP_CR_START); | |
301 | + | |
302 | + /* Put data into buffer */ | |
303 | +#if DEBUG & 4 | |
304 | + printf(" sg buf %08lx len %08x\n ", (u32)data, len); | |
305 | + dx = 0; | |
306 | +#endif | |
307 | + while (len > 0) { | |
308 | +#if DEBUG & 4 | |
309 | + printf(" %02x", *data); | |
310 | + if (0 == (++dx % 16)) printf("\n "); | |
311 | +#endif | |
312 | + | |
313 | + DP_OUT_DATA(dp->data, *data++); | |
314 | + len--; | |
315 | + } | |
316 | +#if DEBUG & 4 | |
317 | + printf("\n"); | |
318 | +#endif | |
319 | + if (total_len < pkt_len) { | |
320 | +#if DEBUG & 4 | |
321 | + printf(" + %d bytes of padding\n", pkt_len - total_len); | |
322 | +#endif | |
323 | + /* Padding to 802.3 length was required */ | |
324 | + for (i = total_len; i < pkt_len;) { | |
325 | + i++; | |
326 | + DP_OUT_DATA(dp->data, 0); | |
327 | + } | |
328 | + } | |
329 | + | |
330 | +#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA | |
331 | + /* | |
332 | + * After last data write, delay for a bit before accessing the | |
333 | + * device again, or we may get random data corruption in the last | |
334 | + * datum (on some platforms). | |
335 | + */ | |
336 | + CYGACC_CALL_IF_DELAY_US(1); | |
337 | +#endif | |
338 | + | |
339 | + /* Wait for DMA to complete */ | |
340 | + do { | |
341 | + DP_IN(base, DP_ISR, isr); | |
342 | + } while ((isr & DP_ISR_RDC) == 0); | |
343 | + | |
344 | + /* Then disable DMA */ | |
345 | + DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
346 | + | |
347 | + /* Start transmit if not already going */ | |
348 | + if (!dp->tx_started) { | |
349 | + if (start_page == dp->tx1) { | |
350 | + dp->tx_int = 1; /* Expecting interrupt from BUF1 */ | |
351 | + } else { | |
352 | + dp->tx_int = 2; /* Expecting interrupt from BUF2 */ | |
353 | + } | |
354 | + dp83902a_start_xmit(start_page, pkt_len); | |
355 | + } | |
356 | +} | |
357 | + | |
358 | +/* | |
359 | + * This function is called when a packet has been received. It's job is | |
360 | + * to prepare to unload the packet from the hardware. Once the length of | |
361 | + * the packet is known, the upper layer of the driver can be told. When | |
362 | + * the upper layer is ready to unload the packet, the internal function | |
363 | + * 'dp83902a_recv' will be called to actually fetch it from the hardware. | |
364 | + */ | |
365 | +static void | |
366 | +dp83902a_RxEvent(void) | |
367 | +{ | |
368 | + struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
369 | + u8 *base = dp->base; | |
370 | + u8 rsr; | |
371 | + u8 rcv_hdr[4]; | |
372 | + int i, len, pkt, cur; | |
373 | + | |
374 | + DEBUG_FUNCTION(); | |
375 | + | |
376 | + DP_IN(base, DP_RSR, rsr); | |
377 | + while (true) { | |
378 | + /* Read incoming packet header */ | |
379 | + DP_OUT(base, DP_CR, DP_CR_PAGE1 | DP_CR_NODMA | DP_CR_START); | |
380 | + DP_IN(base, DP_P1_CURP, cur); | |
381 | + DP_OUT(base, DP_P1_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
382 | + DP_IN(base, DP_BNDRY, pkt); | |
383 | + | |
384 | + pkt += 1; | |
385 | + if (pkt == dp->rx_buf_end) | |
386 | + pkt = dp->rx_buf_start; | |
387 | + | |
388 | + if (pkt == cur) { | |
389 | + break; | |
390 | + } | |
391 | + DP_OUT(base, DP_RBCL, sizeof(rcv_hdr)); | |
392 | + DP_OUT(base, DP_RBCH, 0); | |
393 | + DP_OUT(base, DP_RSAL, 0); | |
394 | + DP_OUT(base, DP_RSAH, pkt); | |
395 | + if (dp->rx_next == pkt) { | |
396 | + if (cur == dp->rx_buf_start) | |
397 | + DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1); | |
398 | + else | |
399 | + DP_OUT(base, DP_BNDRY, cur - 1); /* Update pointer */ | |
400 | + return; | |
401 | + } | |
402 | + dp->rx_next = pkt; | |
403 | + DP_OUT(base, DP_ISR, DP_ISR_RDC); /* Clear end of DMA */ | |
404 | + DP_OUT(base, DP_CR, DP_CR_RDMA | DP_CR_START); | |
405 | +#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_RX_DMA | |
406 | + CYGACC_CALL_IF_DELAY_US(10); | |
407 | +#endif | |
408 | + | |
409 | + /* read header (get data size)*/ | |
410 | + for (i = 0; i < sizeof(rcv_hdr);) { | |
411 | + DP_IN_DATA(dp->data, rcv_hdr[i++]); | |
412 | + } | |
413 | + | |
414 | +#if DEBUG & 5 | |
415 | + printf("rx hdr %02x %02x %02x %02x\n", | |
416 | + rcv_hdr[0], rcv_hdr[1], rcv_hdr[2], rcv_hdr[3]); | |
417 | +#endif | |
418 | + len = ((rcv_hdr[3] << 8) | rcv_hdr[2]) - sizeof(rcv_hdr); | |
419 | + | |
420 | + /* data read */ | |
421 | + uboot_push_packet_len(len); | |
422 | + | |
423 | + if (rcv_hdr[1] == dp->rx_buf_start) | |
424 | + DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1); | |
425 | + else | |
426 | + DP_OUT(base, DP_BNDRY, rcv_hdr[1] - 1); /* Update pointer */ | |
427 | + } | |
428 | +} | |
429 | + | |
430 | +/* | |
431 | + * This function is called as a result of the "eth_drv_recv()" call above. | |
432 | + * It's job is to actually fetch data for a packet from the hardware once | |
433 | + * memory buffers have been allocated for the packet. Note that the buffers | |
434 | + * may come in pieces, using a scatter-gather list. This allows for more | |
435 | + * efficient processing in the upper layers of the stack. | |
436 | + */ | |
437 | +static void | |
438 | +dp83902a_recv(u8 *data, int len) | |
439 | +{ | |
440 | + struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
441 | + u8 *base = dp->base; | |
442 | + int i, mlen; | |
443 | + u8 saved_char = 0; | |
444 | + bool saved; | |
445 | +#if DEBUG & 4 | |
446 | + int dx; | |
447 | +#endif | |
448 | + | |
449 | + DEBUG_FUNCTION(); | |
450 | + | |
451 | +#if DEBUG & 5 | |
452 | + printf("Rx packet %d length %d\n", dp->rx_next, len); | |
453 | +#endif | |
454 | + | |
455 | + /* Read incoming packet data */ | |
456 | + DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); | |
457 | + DP_OUT(base, DP_RBCL, len & 0xFF); | |
458 | + DP_OUT(base, DP_RBCH, len >> 8); | |
459 | + DP_OUT(base, DP_RSAL, 4); /* Past header */ | |
460 | + DP_OUT(base, DP_RSAH, dp->rx_next); | |
461 | + DP_OUT(base, DP_ISR, DP_ISR_RDC); /* Clear end of DMA */ | |
462 | + DP_OUT(base, DP_CR, DP_CR_RDMA | DP_CR_START); | |
463 | +#ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_RX_DMA | |
464 | + CYGACC_CALL_IF_DELAY_US(10); | |
465 | +#endif | |
466 | + | |
467 | + saved = false; | |
468 | + for (i = 0; i < 1; i++) { | |
469 | + if (data) { | |
470 | + mlen = len; | |
471 | +#if DEBUG & 4 | |
472 | + printf(" sg buf %08lx len %08x \n", (u32) data, mlen); | |
473 | + dx = 0; | |
474 | +#endif | |
475 | + while (0 < mlen) { | |
476 | + /* Saved byte from previous loop? */ | |
477 | + if (saved) { | |
478 | + *data++ = saved_char; | |
479 | + mlen--; | |
480 | + saved = false; | |
481 | + continue; | |
482 | + } | |
483 | + | |
484 | + { | |
485 | + u8 tmp; | |
486 | + DP_IN_DATA(dp->data, tmp); | |
487 | +#if DEBUG & 4 | |
488 | + printf(" %02x", tmp); | |
489 | + if (0 == (++dx % 16)) printf("\n "); | |
490 | +#endif | |
491 | + *data++ = tmp;; | |
492 | + mlen--; | |
493 | + } | |
494 | + } | |
495 | +#if DEBUG & 4 | |
496 | + printf("\n"); | |
497 | +#endif | |
498 | + } | |
499 | + } | |
500 | +} | |
501 | + | |
502 | +static void | |
503 | +dp83902a_TxEvent(void) | |
504 | +{ | |
505 | + struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
506 | + u8 *base = dp->base; | |
507 | + u8 tsr; | |
508 | + u32 key; | |
509 | + | |
510 | + DEBUG_FUNCTION(); | |
511 | + | |
512 | + DP_IN(base, DP_TSR, tsr); | |
513 | + if (dp->tx_int == 1) { | |
514 | + key = dp->tx1_key; | |
515 | + dp->tx1 = 0; | |
516 | + } else { | |
517 | + key = dp->tx2_key; | |
518 | + dp->tx2 = 0; | |
519 | + } | |
520 | + /* Start next packet if one is ready */ | |
521 | + dp->tx_started = false; | |
522 | + if (dp->tx1) { | |
523 | + dp83902a_start_xmit(dp->tx1, dp->tx1_len); | |
524 | + dp->tx_int = 1; | |
525 | + } else if (dp->tx2) { | |
526 | + dp83902a_start_xmit(dp->tx2, dp->tx2_len); | |
527 | + dp->tx_int = 2; | |
528 | + } else { | |
529 | + dp->tx_int = 0; | |
530 | + } | |
531 | + /* Tell higher level we sent this packet */ | |
532 | + uboot_push_tx_done(key, 0); | |
533 | +} | |
534 | + | |
535 | +/* | |
536 | + * Read the tally counters to clear them. Called in response to a CNT | |
537 | + * interrupt. | |
538 | + */ | |
539 | +static void | |
540 | +dp83902a_ClearCounters(void) | |
541 | +{ | |
542 | + struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
543 | + u8 *base = dp->base; | |
544 | + u8 cnt1, cnt2, cnt3; | |
545 | + | |
546 | + DP_IN(base, DP_FER, cnt1); | |
547 | + DP_IN(base, DP_CER, cnt2); | |
548 | + DP_IN(base, DP_MISSED, cnt3); | |
549 | + DP_OUT(base, DP_ISR, DP_ISR_CNT); | |
550 | +} | |
551 | + | |
552 | +/* | |
553 | + * Deal with an overflow condition. This code follows the procedure set | |
554 | + * out in section 7.0 of the datasheet. | |
555 | + */ | |
556 | +static void | |
557 | +dp83902a_Overflow(void) | |
558 | +{ | |
559 | + struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *)&nic; | |
560 | + u8 *base = dp->base; | |
561 | + u8 isr; | |
562 | + | |
563 | + /* Issue a stop command and wait 1.6ms for it to complete. */ | |
564 | + DP_OUT(base, DP_CR, DP_CR_STOP | DP_CR_NODMA); | |
565 | + CYGACC_CALL_IF_DELAY_US(1600); | |
566 | + | |
567 | + /* Clear the remote byte counter registers. */ | |
568 | + DP_OUT(base, DP_RBCL, 0); | |
569 | + DP_OUT(base, DP_RBCH, 0); | |
570 | + | |
571 | + /* Enter loopback mode while we clear the buffer. */ | |
572 | + DP_OUT(base, DP_TCR, DP_TCR_LOCAL); | |
573 | + DP_OUT(base, DP_CR, DP_CR_START | DP_CR_NODMA); | |
574 | + | |
575 | + /* | |
576 | + * Read in as many packets as we can and acknowledge any and receive | |
577 | + * interrupts. Since the buffer has overflowed, a receive event of | |
578 | + * some kind will have occured. | |
579 | + */ | |
580 | + dp83902a_RxEvent(); | |
581 | + DP_OUT(base, DP_ISR, DP_ISR_RxP|DP_ISR_RxE); | |
582 | + | |
583 | + /* Clear the overflow condition and leave loopback mode. */ | |
584 | + DP_OUT(base, DP_ISR, DP_ISR_OFLW); | |
585 | + DP_OUT(base, DP_TCR, DP_TCR_NORMAL); | |
586 | + | |
587 | + /* | |
588 | + * If a transmit command was issued, but no transmit event has occured, | |
589 | + * restart it here. | |
590 | + */ | |
591 | + DP_IN(base, DP_ISR, isr); | |
592 | + if (dp->tx_started && !(isr & (DP_ISR_TxP|DP_ISR_TxE))) { | |
593 | + DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_TXPKT | DP_CR_START); | |
594 | + } | |
595 | +} | |
596 | + | |
597 | +static void | |
598 | +dp83902a_poll(void) | |
599 | +{ | |
600 | + struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
601 | + u8 *base = dp->base; | |
602 | + u8 isr; | |
603 | + | |
604 | + DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0 | DP_CR_START); | |
605 | + DP_IN(base, DP_ISR, isr); | |
606 | + while (0 != isr) { | |
607 | + /* | |
608 | + * The CNT interrupt triggers when the MSB of one of the error | |
609 | + * counters is set. We don't much care about these counters, but | |
610 | + * we should read their values to reset them. | |
611 | + */ | |
612 | + if (isr & DP_ISR_CNT) { | |
613 | + dp83902a_ClearCounters(); | |
614 | + } | |
615 | + /* | |
616 | + * Check for overflow. It's a special case, since there's a | |
617 | + * particular procedure that must be followed to get back into | |
618 | + * a running state.a | |
619 | + */ | |
620 | + if (isr & DP_ISR_OFLW) { | |
621 | + dp83902a_Overflow(); | |
622 | + } else { | |
623 | + /* | |
624 | + * Other kinds of interrupts can be acknowledged simply by | |
625 | + * clearing the relevant bits of the ISR. Do that now, then | |
626 | + * handle the interrupts we care about. | |
627 | + */ | |
628 | + DP_OUT(base, DP_ISR, isr); /* Clear set bits */ | |
629 | + if (!dp->running) break; /* Is this necessary? */ | |
630 | + /* | |
631 | + * Check for tx_started on TX event since these may happen | |
632 | + * spuriously it seems. | |
633 | + */ | |
634 | + if (isr & (DP_ISR_TxP|DP_ISR_TxE) && dp->tx_started) { | |
635 | + dp83902a_TxEvent(); | |
636 | + } | |
637 | + if (isr & (DP_ISR_RxP|DP_ISR_RxE)) { | |
638 | + dp83902a_RxEvent(); | |
639 | + } | |
640 | + } | |
641 | + DP_IN(base, DP_ISR, isr); | |
642 | + } | |
643 | +} | |
644 | + | |
645 | + | |
646 | +/* U-boot specific routines */ | |
647 | +static u8 *pbuf = NULL; | |
648 | + | |
649 | +static int pkey = -1; | |
650 | +static int initialized = 0; | |
651 | + | |
652 | +void uboot_push_packet_len(int len) { | |
653 | + PRINTK("pushed len = %d\n", len); | |
654 | + if (len >= 2000) { | |
655 | + printf("NE2000: packet too big\n"); | |
656 | + return; | |
657 | + } | |
658 | + dp83902a_recv(&pbuf[0], len); | |
659 | + | |
660 | + /*Just pass it to the upper layer*/ | |
661 | + NetReceive(&pbuf[0], len); | |
662 | +} | |
663 | + | |
664 | +void uboot_push_tx_done(int key, int val) { | |
665 | + PRINTK("pushed key = %d\n", key); | |
666 | + pkey = key; | |
667 | +} | |
668 | + | |
669 | +int eth_init(bd_t *bd) { | |
670 | + int r; | |
671 | + u8 dev_addr[6]; | |
672 | + char ethaddr[20]; | |
673 | + | |
674 | + PRINTK("### eth_init\n"); | |
675 | + | |
676 | + if (!pbuf) { | |
677 | + pbuf = malloc(2000); | |
678 | + if (!pbuf) { | |
679 | + printf("Cannot allocate rx buffer\n"); | |
680 | + return -1; | |
681 | + } | |
682 | + } | |
683 | + | |
684 | +#ifdef CONFIG_DRIVER_NE2000_CCR | |
685 | + { | |
686 | + vu_char *p = (vu_char *) CONFIG_DRIVER_NE2000_CCR; | |
687 | + | |
688 | + PRINTK("CCR before is %x\n", *p); | |
689 | + *p = CONFIG_DRIVER_NE2000_VAL; | |
690 | + PRINTK("CCR after is %x\n", *p); | |
691 | + } | |
692 | +#endif | |
693 | + | |
694 | + nic.base = (u8 *) CONFIG_DRIVER_NE2000_BASE; | |
695 | + | |
696 | + r = get_prom(dev_addr, nic.base); | |
697 | + if (!r) | |
698 | + return -1; | |
699 | + | |
700 | + sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X", | |
701 | + dev_addr[0], dev_addr[1], | |
702 | + dev_addr[2], dev_addr[3], | |
703 | + dev_addr[4], dev_addr[5]) ; | |
704 | + PRINTK("Set environment from HW MAC addr = \"%s\"\n", ethaddr); | |
705 | + setenv ("ethaddr", ethaddr); | |
706 | + | |
707 | + nic.data = nic.base + DP_DATA; | |
708 | + nic.tx_buf1 = START_PG; | |
709 | + nic.tx_buf2 = START_PG2; | |
710 | + nic.rx_buf_start = RX_START; | |
711 | + nic.rx_buf_end = RX_END; | |
712 | + | |
713 | + if (dp83902a_init() == false) | |
714 | + return -1; | |
715 | + | |
716 | + dp83902a_start(dev_addr); | |
717 | + initialized = 1; | |
718 | + | |
719 | + return 0; | |
720 | +} | |
721 | + | |
722 | +void eth_halt() { | |
723 | + | |
724 | + PRINTK("### eth_halt\n"); | |
725 | + if(initialized) | |
726 | + dp83902a_stop(); | |
727 | + initialized = 0; | |
728 | +} | |
729 | + | |
730 | +int eth_rx() { | |
731 | + dp83902a_poll(); | |
732 | + return 1; | |
733 | +} | |
734 | + | |
735 | +int eth_send(volatile void *packet, int length) { | |
736 | + int tmo; | |
737 | + | |
738 | + PRINTK("### eth_send\n"); | |
739 | + | |
740 | + pkey = -1; | |
741 | + | |
742 | + dp83902a_send((u8 *) packet, length, 666); | |
743 | + tmo = get_timer (0) + TOUT * CFG_HZ; | |
744 | + while(1) { | |
745 | + dp83902a_poll(); | |
746 | + if (pkey != -1) { | |
747 | + PRINTK("Packet sucesfully sent\n"); | |
748 | + return 0; | |
749 | + } | |
750 | + if (get_timer (0) >= tmo) { | |
751 | + printf("transmission error (timoeut)\n"); | |
752 | + return 0; | |
753 | + } | |
754 | + | |
755 | + } | |
756 | + return 0; | |
757 | +} |
drivers/net/ne2000_base.h
... | ... | @@ -80,10 +80,35 @@ |
80 | 80 | #define __NE2000_BASE_H__ |
81 | 81 | |
82 | 82 | #define bool int |
83 | - | |
84 | 83 | #define false 0 |
85 | 84 | #define true 1 |
86 | 85 | |
86 | +/* | |
87 | + * Debugging details | |
88 | + * | |
89 | + * Set to perms of: | |
90 | + * 0 disables all debug output | |
91 | + * 1 for process debug output | |
92 | + * 2 for added data IO output: get_reg, put_reg | |
93 | + * 4 for packet allocation/free output | |
94 | + * 8 for only startup status, so we can tell we're installed OK | |
95 | + */ | |
96 | +#if 0 | |
97 | +#define DEBUG 0xf | |
98 | +#else | |
99 | +#define DEBUG 0 | |
100 | +#endif | |
101 | + | |
102 | +#if DEBUG & 1 | |
103 | +#define DEBUG_FUNCTION() do { printf("%s\n", __FUNCTION__); } while (0) | |
104 | +#define DEBUG_LINE() do { printf("%d\n", __LINE__); } while (0) | |
105 | +#define PRINTK(args...) printf(args) | |
106 | +#else | |
107 | +#define DEBUG_FUNCTION() do {} while(0) | |
108 | +#define DEBUG_LINE() do {} while(0) | |
109 | +#define PRINTK(args...) | |
110 | +#endif | |
111 | + | |
87 | 112 | /* timeout for tx/rx in s */ |
88 | 113 | #define TOUT 5 |
89 | 114 | /* Ether MAC address size */ |
... | ... | @@ -119,11 +144,6 @@ |
119 | 144 | int rx_buf_start, rx_buf_end; |
120 | 145 | } dp83902a_priv_data_t; |
121 | 146 | |
122 | -/* | |
123 | - * Some forward declarations | |
124 | - */ | |
125 | -static void dp83902a_poll(void); | |
126 | - | |
127 | 147 | /* ------------------------------------------------------------------------ */ |
128 | 148 | /* Register offsets */ |
129 | 149 | |
... | ... | @@ -281,5 +301,9 @@ |
281 | 301 | |
282 | 302 | #define IEEE_8023_MAX_FRAME 1518 /* Largest possible ethernet frame */ |
283 | 303 | #define IEEE_8023_MIN_FRAME 64 /* Smallest possible ethernet frame */ |
304 | + | |
305 | +/* Functions */ | |
306 | +int get_prom(u8* mac_addr, u8* base_addr); | |
307 | + | |
284 | 308 | #endif /* __NE2000_BASE_H__ */ |