Revision | e8d79dcb72f7625af8ad5d6542982f6a3b86dfc8 (tree) |
---|---|
Zeit | 2016-05-22 22:22:56 |
Autor | Yoshinori Sato <ysato@user...> |
Commiter | Yoshinori Sato |
ne2000: private data for dynamic allocation
driver private data assigned to heap
Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
@@ -41,8 +41,8 @@ are GPL, so this is, of course, GPL. | ||
41 | 41 | * - removed AMIGA_PCMCIA from this list, handled as ISA io now |
42 | 42 | */ |
43 | 43 | |
44 | -#define n2k_inb(port) (*((volatile unsigned char *)(port+CONFIG_DRIVER_NE2000_BASE))) | |
45 | -#define n2k_outb(val,port) (*((volatile unsigned char *)(port+CONFIG_DRIVER_NE2000_BASE)) = val) | |
44 | +#define n2k_inb(base, port) (*((volatile unsigned char *)(port+base))) | |
45 | +#define n2k_outb(val, base, port) (*((volatile unsigned char *)(port+base)) = val) | |
46 | 46 | |
47 | 47 | #define EI_SHIFT(x) (x) |
48 | 48 |
@@ -178,23 +178,23 @@ static void pcnet_reset_8390(u8* addr) | ||
178 | 178 | { |
179 | 179 | int i, r; |
180 | 180 | |
181 | - n2k_outb(E8390_NODMA + E8390_PAGE0+E8390_STOP, E8390_CMD); | |
182 | - PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(E8390_CMD)); | |
183 | - n2k_outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, E8390_CMD); | |
184 | - PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(E8390_CMD)); | |
185 | - n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD); | |
186 | - PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(E8390_CMD)); | |
187 | - n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD); | |
181 | + n2k_outb(E8390_NODMA + E8390_PAGE0+E8390_STOP, addr, E8390_CMD); | |
182 | + PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(addr,E8390_CMD)); | |
183 | + n2k_outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, addr, E8390_CMD); | |
184 | + PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(addr, E8390_CMD)); | |
185 | + n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr, E8390_CMD); | |
186 | + PRINTK("cmd (at %lx) is %x\n", addr + E8390_CMD, n2k_inb(addr, E8390_CMD)); | |
187 | + n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, addr, E8390_CMD); | |
188 | 188 | |
189 | - n2k_outb(n2k_inb(PCNET_RESET), PCNET_RESET); | |
189 | + n2k_outb(n2k_inb(addr, PCNET_RESET), addr, PCNET_RESET); | |
190 | 190 | |
191 | 191 | for (i = 0; i < 100; i++) { |
192 | - if ((r = (n2k_inb(EN0_ISR) & ENISR_RESET)) != 0) | |
192 | + if ((r = (n2k_inb(addr, EN0_ISR) & ENISR_RESET)) != 0) | |
193 | 193 | break; |
194 | 194 | PRINTK("got %x in reset\n", r); |
195 | 195 | udelay(100); |
196 | 196 | } |
197 | - n2k_outb(ENISR_RESET, EN0_ISR); /* Ack intr. */ | |
197 | + n2k_outb(ENISR_RESET, addr, EN0_ISR); /* Ack intr. */ | |
198 | 198 | |
199 | 199 | if (i == 100) |
200 | 200 | printf("pcnet_reset_8390() did not complete.\n"); |
@@ -229,11 +229,11 @@ int get_prom(u8* mac_addr, u8* base_addr) | ||
229 | 229 | mdelay (10); |
230 | 230 | |
231 | 231 | for (i = 0; i < ARRAY_SIZE(program_seq); i++) |
232 | - n2k_outb (program_seq[i].value, program_seq[i].offset); | |
232 | + n2k_outb (program_seq[i].value, base_addr, program_seq[i].offset); | |
233 | 233 | |
234 | 234 | PRINTK ("PROM:"); |
235 | 235 | for (i = 0; i < 32; i++) { |
236 | - prom[i] = n2k_inb (PCNET_DATAPORT); | |
236 | + prom[i] = n2k_inb (base_addr, PCNET_DATAPORT); | |
237 | 237 | PRINTK (" %02x", prom[i]); |
238 | 238 | } |
239 | 239 | PRINTK ("\n"); |
@@ -78,10 +78,6 @@ Add SNMP | ||
78 | 78 | #include <malloc.h> |
79 | 79 | #include <linux/compiler.h> |
80 | 80 | |
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 | 81 | /* NE2000 base header file */ |
86 | 82 | #include "ne2000_base.h" |
87 | 83 |
@@ -93,24 +89,23 @@ void uboot_push_tx_done(int key, int val); | ||
93 | 89 | #include "ne2000.h" |
94 | 90 | #endif |
95 | 91 | |
96 | -static dp83902a_priv_data_t nic; /* just one instance of the card supported */ | |
92 | +/* forward definition of function used for the uboot interface */ | |
93 | +static void uboot_push_packet_len(dp83902a_priv_data_t *dp, u8 *base, int len); | |
94 | +static void uboot_push_tx_done(dp83902a_priv_data_t *dp, int key, int val); | |
97 | 95 | |
98 | 96 | /** |
99 | 97 | * This function reads the MAC address from the serial EEPROM, |
100 | 98 | * used if PROM read fails. Does nothing for ax88796 chips (sh boards) |
101 | 99 | */ |
102 | 100 | static bool |
103 | -dp83902a_init(unsigned char *enetaddr) | |
101 | +dp83902a_init(u8 *base, u8 enetaddr[]) | |
104 | 102 | { |
105 | - dp83902a_priv_data_t *dp = &nic; | |
106 | - u8* base; | |
107 | 103 | #if defined(NE2000_BASIC_INIT) |
108 | 104 | int i; |
109 | 105 | #endif |
110 | 106 | |
111 | 107 | DEBUG_FUNCTION(); |
112 | 108 | |
113 | - base = dp->base; | |
114 | 109 | if (!base) |
115 | 110 | return false; /* No device found */ |
116 | 111 |
@@ -122,29 +117,25 @@ dp83902a_init(unsigned char *enetaddr) | ||
122 | 117 | DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE1); /* Select page 1 */ |
123 | 118 | /* Use the address from the serial EEPROM */ |
124 | 119 | for (i = 0; i < 6; i++) |
125 | - DP_IN(base, DP_P1_PAR0+i, dp->esa[i]); | |
120 | + DP_IN(base, DP_P1_PAR0+i, enetaddr[i]); | |
126 | 121 | DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0); /* Select page 0 */ |
127 | 122 | |
128 | 123 | printf("NE2000 - %s ESA: %02x:%02x:%02x:%02x:%02x:%02x\n", |
129 | 124 | "eeprom", |
130 | - dp->esa[0], | |
131 | - dp->esa[1], | |
132 | - dp->esa[2], | |
133 | - dp->esa[3], | |
134 | - dp->esa[4], | |
135 | - dp->esa[5] ); | |
136 | - | |
137 | - memcpy(enetaddr, dp->esa, 6); /* Use MAC from serial EEPROM */ | |
125 | + enetaddr[0], | |
126 | + enetaddr[1], | |
127 | + enetaddr[2], | |
128 | + enetaddr[3], | |
129 | + enetaddr[4], | |
130 | + enetaddr[5] ); | |
131 | + | |
138 | 132 | #endif /* NE2000_BASIC_INIT */ |
139 | 133 | return true; |
140 | 134 | } |
141 | 135 | |
142 | 136 | static void |
143 | -dp83902a_stop(void) | |
137 | +dp83902a_stop(dp83902a_priv_data_t *dp, u8 *base) | |
144 | 138 | { |
145 | - dp83902a_priv_data_t *dp = &nic; | |
146 | - u8 *base = dp->base; | |
147 | - | |
148 | 139 | DEBUG_FUNCTION(); |
149 | 140 | |
150 | 141 | DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_STOP); /* Brutal */ |
@@ -161,13 +152,11 @@ dp83902a_stop(void) | ||
161 | 152 | * the hardware ready to send/receive packets. |
162 | 153 | */ |
163 | 154 | static void |
164 | -dp83902a_start(u8 * enaddr) | |
155 | +dp83902a_start(dp83902a_priv_data_t *dp, u8 *base, u8 enetaddr[]) | |
165 | 156 | { |
166 | - dp83902a_priv_data_t *dp = &nic; | |
167 | - u8 *base = dp->base; | |
168 | 157 | int i; |
169 | 158 | |
170 | - debug("The MAC is %pM\n", enaddr); | |
159 | + debug("The MAC is %pM\n", enetaddr); | |
171 | 160 | |
172 | 161 | DEBUG_FUNCTION(); |
173 | 162 |
@@ -196,7 +185,7 @@ dp83902a_start(u8 * enaddr) | ||
196 | 185 | /* FIXME */ |
197 | 186 | /*((vu_short*)( base + ((DP_P1_PAR0 + i) * 2) + |
198 | 187 | * 0x1400)) = enaddr[i];*/ |
199 | - DP_OUT(base, DP_P1_PAR0+i, enaddr[i]); | |
188 | + DP_OUT(base, DP_P1_PAR0+i, enetaddr[i]); | |
200 | 189 | } |
201 | 190 | /* Enable and start device */ |
202 | 191 | DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_NODMA | DP_CR_START); |
@@ -212,10 +201,9 @@ dp83902a_start(u8 * enaddr) | ||
212 | 201 | */ |
213 | 202 | |
214 | 203 | static void |
215 | -dp83902a_start_xmit(int start_page, int len) | |
204 | +dp83902a_start_xmit(dp83902a_priv_data_t *dp, u8 *base, | |
205 | + int start_page, int len) | |
216 | 206 | { |
217 | - dp83902a_priv_data_t *dp = (dp83902a_priv_data_t *) &nic; | |
218 | - u8 *base = dp->base; | |
219 | 207 | |
220 | 208 | DEBUG_FUNCTION(); |
221 | 209 |
@@ -240,10 +228,9 @@ dp83902a_start_xmit(int start_page, int len) | ||
240 | 228 | * that there is free buffer space (dp->tx_next). |
241 | 229 | */ |
242 | 230 | static void |
243 | -dp83902a_send(u8 *data, int total_len, u32 key) | |
231 | +dp83902a_send(dp83902a_priv_data_t *dp, u8 *base, | |
232 | + u8 *data, int total_len, u32 key) | |
244 | 233 | { |
245 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
246 | - u8 *base = dp->base; | |
247 | 234 | int len, start_page, pkt_len, i, isr; |
248 | 235 | #if DEBUG & 4 |
249 | 236 | int dx; |
@@ -288,7 +275,7 @@ dp83902a_send(u8 *data, int total_len, u32 key) | ||
288 | 275 | DP_OUT(base, DP_RBCL, len); |
289 | 276 | DP_OUT(base, DP_RBCH, 0); |
290 | 277 | DP_OUT(base, DP_CR, DP_CR_PAGE0 | DP_CR_RDMA | DP_CR_START); |
291 | - DP_IN_DATA(dp->data, tmp); | |
278 | + DP_IN_DATA(base + DP_DATA, tmp); | |
292 | 279 | } |
293 | 280 | |
294 | 281 | #ifdef CYGHWR_NS_DP83902A_PLF_BROKEN_TX_DMA |
@@ -317,7 +304,7 @@ dp83902a_send(u8 *data, int total_len, u32 key) | ||
317 | 304 | if (0 == (++dx % 16)) printf("\n "); |
318 | 305 | #endif |
319 | 306 | |
320 | - DP_OUT_DATA(dp->data, *data++); | |
307 | + DP_OUT_DATA(base + DP_DATA, *data++); | |
321 | 308 | len--; |
322 | 309 | } |
323 | 310 | #if DEBUG & 4 |
@@ -330,7 +317,7 @@ dp83902a_send(u8 *data, int total_len, u32 key) | ||
330 | 317 | /* Padding to 802.3 length was required */ |
331 | 318 | for (i = total_len; i < pkt_len;) { |
332 | 319 | i++; |
333 | - DP_OUT_DATA(dp->data, 0); | |
320 | + DP_OUT_DATA(base + DP_DATA, 0); | |
334 | 321 | } |
335 | 322 | } |
336 | 323 |
@@ -358,7 +345,7 @@ dp83902a_send(u8 *data, int total_len, u32 key) | ||
358 | 345 | } else { |
359 | 346 | dp->tx_int = 2; /* Expecting interrupt from BUF2 */ |
360 | 347 | } |
361 | - dp83902a_start_xmit(start_page, pkt_len); | |
348 | + dp83902a_start_xmit(dp, base, start_page, pkt_len); | |
362 | 349 | } |
363 | 350 | } |
364 | 351 |
@@ -370,10 +357,8 @@ dp83902a_send(u8 *data, int total_len, u32 key) | ||
370 | 357 | * 'dp83902a_recv' will be called to actually fetch it from the hardware. |
371 | 358 | */ |
372 | 359 | static void |
373 | -dp83902a_RxEvent(void) | |
360 | +dp83902a_RxEvent(dp83902a_priv_data_t *dp, u8 *base) | |
374 | 361 | { |
375 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
376 | - u8 *base = dp->base; | |
377 | 362 | __maybe_unused u8 rsr; |
378 | 363 | u8 rcv_hdr[4]; |
379 | 364 | int i, len, pkt, cur; |
@@ -415,7 +400,7 @@ dp83902a_RxEvent(void) | ||
415 | 400 | |
416 | 401 | /* read header (get data size)*/ |
417 | 402 | for (i = 0; i < sizeof(rcv_hdr);) { |
418 | - DP_IN_DATA(dp->data, rcv_hdr[i++]); | |
403 | + DP_IN_DATA(base + DP_DATA, rcv_hdr[i++]); | |
419 | 404 | } |
420 | 405 | |
421 | 406 | #if DEBUG & 5 |
@@ -425,7 +410,7 @@ dp83902a_RxEvent(void) | ||
425 | 410 | len = ((rcv_hdr[3] << 8) | rcv_hdr[2]) - sizeof(rcv_hdr); |
426 | 411 | |
427 | 412 | /* data read */ |
428 | - uboot_push_packet_len(len); | |
413 | + uboot_push_packet_len(dp, base, len); | |
429 | 414 | |
430 | 415 | if (rcv_hdr[1] == dp->rx_buf_start) |
431 | 416 | DP_OUT(base, DP_BNDRY, dp->rx_buf_end - 1); |
@@ -442,10 +427,8 @@ dp83902a_RxEvent(void) | ||
442 | 427 | * efficient processing in the upper layers of the stack. |
443 | 428 | */ |
444 | 429 | static void |
445 | -dp83902a_recv(u8 *data, int len) | |
430 | +dp83902a_recv(dp83902a_priv_data_t *dp, u8 *base, u8 *data, int len) | |
446 | 431 | { |
447 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
448 | - u8 *base = dp->base; | |
449 | 432 | int i, mlen; |
450 | 433 | u8 saved_char = 0; |
451 | 434 | bool saved; |
@@ -490,7 +473,7 @@ dp83902a_recv(u8 *data, int len) | ||
490 | 473 | |
491 | 474 | { |
492 | 475 | u8 tmp; |
493 | - DP_IN_DATA(dp->data, tmp); | |
476 | + DP_IN_DATA(base + DP_DATA, tmp); | |
494 | 477 | #if DEBUG & 4 |
495 | 478 | printf(" %02x", tmp); |
496 | 479 | if (0 == (++dx % 16)) printf("\n "); |
@@ -507,10 +490,8 @@ dp83902a_recv(u8 *data, int len) | ||
507 | 490 | } |
508 | 491 | |
509 | 492 | static void |
510 | -dp83902a_TxEvent(void) | |
493 | +dp83902a_TxEvent(dp83902a_priv_data_t *dp, u8 *base) | |
511 | 494 | { |
512 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
513 | - u8 *base = dp->base; | |
514 | 495 | __maybe_unused u8 tsr; |
515 | 496 | u32 key; |
516 | 497 |
@@ -527,16 +508,16 @@ dp83902a_TxEvent(void) | ||
527 | 508 | /* Start next packet if one is ready */ |
528 | 509 | dp->tx_started = false; |
529 | 510 | if (dp->tx1) { |
530 | - dp83902a_start_xmit(dp->tx1, dp->tx1_len); | |
511 | + dp83902a_start_xmit(dp, base, dp->tx1, dp->tx1_len); | |
531 | 512 | dp->tx_int = 1; |
532 | 513 | } else if (dp->tx2) { |
533 | - dp83902a_start_xmit(dp->tx2, dp->tx2_len); | |
514 | + dp83902a_start_xmit(dp, base, dp->tx2, dp->tx2_len); | |
534 | 515 | dp->tx_int = 2; |
535 | 516 | } else { |
536 | 517 | dp->tx_int = 0; |
537 | 518 | } |
538 | 519 | /* Tell higher level we sent this packet */ |
539 | - uboot_push_tx_done(key, 0); | |
520 | + uboot_push_tx_done(dp, key, 0); | |
540 | 521 | } |
541 | 522 | |
542 | 523 | /* |
@@ -544,10 +525,8 @@ dp83902a_TxEvent(void) | ||
544 | 525 | * interrupt. |
545 | 526 | */ |
546 | 527 | static void |
547 | -dp83902a_ClearCounters(void) | |
528 | +dp83902a_ClearCounters(u8 *base) | |
548 | 529 | { |
549 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
550 | - u8 *base = dp->base; | |
551 | 530 | __maybe_unused u8 cnt1, cnt2, cnt3; |
552 | 531 | |
553 | 532 | DP_IN(base, DP_FER, cnt1); |
@@ -561,10 +540,8 @@ dp83902a_ClearCounters(void) | ||
561 | 540 | * out in section 7.0 of the datasheet. |
562 | 541 | */ |
563 | 542 | static void |
564 | -dp83902a_Overflow(void) | |
543 | +dp83902a_Overflow(dp83902a_priv_data_t *dp, u8 *base) | |
565 | 544 | { |
566 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *)&nic; | |
567 | - u8 *base = dp->base; | |
568 | 545 | u8 isr; |
569 | 546 | |
570 | 547 | /* Issue a stop command and wait 1.6ms for it to complete. */ |
@@ -584,7 +561,7 @@ dp83902a_Overflow(void) | ||
584 | 561 | * interrupts. Since the buffer has overflowed, a receive event of |
585 | 562 | * some kind will have occurred. |
586 | 563 | */ |
587 | - dp83902a_RxEvent(); | |
564 | + dp83902a_RxEvent(dp, base); | |
588 | 565 | DP_OUT(base, DP_ISR, DP_ISR_RxP|DP_ISR_RxE); |
589 | 566 | |
590 | 567 | /* Clear the overflow condition and leave loopback mode. */ |
@@ -602,10 +579,8 @@ dp83902a_Overflow(void) | ||
602 | 579 | } |
603 | 580 | |
604 | 581 | static void |
605 | -dp83902a_poll(void) | |
582 | +dp83902a_poll(dp83902a_priv_data_t *dp, u8 *base) | |
606 | 583 | { |
607 | - struct dp83902a_priv_data *dp = (struct dp83902a_priv_data *) &nic; | |
608 | - u8 *base = dp->base; | |
609 | 584 | u8 isr; |
610 | 585 | |
611 | 586 | DP_OUT(base, DP_CR, DP_CR_NODMA | DP_CR_PAGE0 | DP_CR_START); |
@@ -617,7 +592,7 @@ dp83902a_poll(void) | ||
617 | 592 | * we should read their values to reset them. |
618 | 593 | */ |
619 | 594 | if (isr & DP_ISR_CNT) { |
620 | - dp83902a_ClearCounters(); | |
595 | + dp83902a_ClearCounters(base); | |
621 | 596 | } |
622 | 597 | /* |
623 | 598 | * Check for overflow. It's a special case, since there's a |
@@ -625,7 +600,7 @@ dp83902a_poll(void) | ||
625 | 600 | * a running state.a |
626 | 601 | */ |
627 | 602 | if (isr & DP_ISR_OFLW) { |
628 | - dp83902a_Overflow(); | |
603 | + dp83902a_Overflow(dp, base); | |
629 | 604 | } else { |
630 | 605 | /* |
631 | 606 | * Other kinds of interrupts can be acknowledged simply by |
@@ -639,10 +614,10 @@ dp83902a_poll(void) | ||
639 | 614 | * spuriously it seems. |
640 | 615 | */ |
641 | 616 | if (isr & (DP_ISR_TxP|DP_ISR_TxE) && dp->tx_started) { |
642 | - dp83902a_TxEvent(); | |
617 | + dp83902a_TxEvent(dp, base); | |
643 | 618 | } |
644 | 619 | if (isr & (DP_ISR_RxP|DP_ISR_RxE)) { |
645 | - dp83902a_RxEvent(); | |
620 | + dp83902a_RxEvent(dp, base); | |
646 | 621 | } |
647 | 622 | } |
648 | 623 | DP_IN(base, DP_ISR, isr); |
@@ -651,26 +626,24 @@ dp83902a_poll(void) | ||
651 | 626 | |
652 | 627 | |
653 | 628 | /* U-Boot specific routines */ |
654 | -static u8 *pbuf = NULL; | |
655 | - | |
656 | -static int pkey = -1; | |
657 | -static int initialized = 0; | |
658 | 629 | |
659 | -void uboot_push_packet_len(int len) { | |
630 | +static void uboot_push_packet_len(dp83902a_priv_data_t *dp, u8 *base, int len) | |
631 | +{ | |
660 | 632 | PRINTK("pushed len = %d\n", len); |
661 | 633 | if (len >= 2000) { |
662 | 634 | printf("NE2000: packet too big\n"); |
663 | 635 | return; |
664 | 636 | } |
665 | - dp83902a_recv(&pbuf[0], len); | |
637 | + dp83902a_recv(dp, base, dp->pbuf, len); | |
666 | 638 | |
667 | 639 | /*Just pass it to the upper layer*/ |
668 | - net_process_received_packet(&pbuf[0], len); | |
640 | + net_process_received_packet(dp->pbuf, len); | |
669 | 641 | } |
670 | 642 | |
671 | -void uboot_push_tx_done(int key, int val) { | |
643 | +void uboot_push_tx_done(dp83902a_priv_data_t *dp, int key, int val) | |
644 | +{ | |
672 | 645 | PRINTK("pushed key = %d\n", key); |
673 | - pkey = key; | |
646 | + dp->pkey = key; | |
674 | 647 | } |
675 | 648 | |
676 | 649 | /** |
@@ -680,13 +653,13 @@ void uboot_push_tx_done(int key, int val) { | ||
680 | 653 | * @param struct ethdevice of this instance of the driver for dev->enetaddr |
681 | 654 | * @return 0 on success, -1 on error (causing caller to print error msg) |
682 | 655 | */ |
683 | -static int ne2k_setup_driver(struct eth_device *dev) | |
656 | +static int ne2k_setup_driver(dp83902a_priv_data_t *dp, u8 *base, u8 enetaddr[]) | |
684 | 657 | { |
685 | 658 | PRINTK("### ne2k_setup_driver\n"); |
686 | 659 | |
687 | - if (!pbuf) { | |
688 | - pbuf = malloc(2000); | |
689 | - if (!pbuf) { | |
660 | + if (!dp->pbuf) { | |
661 | + dp->pbuf = malloc(2000); | |
662 | + if (!dp->pbuf) { | |
690 | 663 | printf("Cannot allocate rx buffer\n"); |
691 | 664 | return -1; |
692 | 665 | } |
@@ -702,66 +675,70 @@ static int ne2k_setup_driver(struct eth_device *dev) | ||
702 | 675 | } |
703 | 676 | #endif |
704 | 677 | |
705 | - nic.base = (u8 *) CONFIG_DRIVER_NE2000_BASE; | |
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; | |
678 | + dp->tx_buf1 = START_PG; | |
679 | + dp->tx_buf2 = START_PG2; | |
680 | + dp->rx_buf_start = RX_START; | |
681 | + dp->rx_buf_end = RX_END; | |
712 | 682 | |
713 | 683 | /* |
714 | 684 | * According to doc/README.enetaddr, drivers shall give priority |
715 | 685 | * to the MAC address value in the environment, so we do not read |
716 | 686 | * it from the prom or eeprom if it is specified in the environment. |
717 | 687 | */ |
718 | - if (!eth_getenv_enetaddr("ethaddr", dev->enetaddr)) { | |
688 | + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { | |
719 | 689 | /* If the MAC address is not in the environment, get it: */ |
720 | - if (!get_prom(dev->enetaddr, nic.base)) /* get MAC from prom */ | |
721 | - dp83902a_init(dev->enetaddr); /* fallback: seeprom */ | |
690 | + if (!get_prom(enetaddr, base)) /* get MAC from prom */ | |
691 | + dp83902a_init(base, enetaddr); /* fallback: seeprom */ | |
722 | 692 | /* And write it into the environment otherwise eth_write_hwaddr |
723 | 693 | * returns -1 due to eth_getenv_enetaddr_by_index() failing, |
724 | 694 | * and this causes "Warning: failed to set MAC address", and |
725 | 695 | * cmd_bdinfo has no ethaddr value which it can show: */ |
726 | - eth_setenv_enetaddr("ethaddr", dev->enetaddr); | |
696 | + eth_setenv_enetaddr("ethaddr", enetaddr); | |
727 | 697 | } |
728 | 698 | return 0; |
729 | 699 | } |
730 | 700 | |
731 | 701 | static int ne2k_init(struct eth_device *dev, bd_t *bd) |
732 | 702 | { |
733 | - dp83902a_start(dev->enetaddr); | |
734 | - initialized = 1; | |
703 | + struct dp83902a_priv_data *dp = dev->priv; | |
704 | + | |
705 | + dp83902a_start(dp, (u8 *)dev->iobase, dev->enetaddr); | |
706 | + dp->initialized = 1; | |
735 | 707 | return 0; |
736 | 708 | } |
737 | 709 | |
738 | 710 | static void ne2k_halt(struct eth_device *dev) |
739 | 711 | { |
712 | + struct dp83902a_priv_data *dp = dev->priv; | |
713 | + | |
740 | 714 | debug("### ne2k_halt\n"); |
741 | - if(initialized) | |
742 | - dp83902a_stop(); | |
743 | - initialized = 0; | |
715 | + if(dp->initialized) | |
716 | + dp83902a_stop(dp, (u8 *)dev->iobase); | |
717 | + dp->initialized = 0; | |
744 | 718 | } |
745 | 719 | |
746 | 720 | static int ne2k_recv(struct eth_device *dev) |
747 | 721 | { |
748 | - dp83902a_poll(); | |
722 | + struct dp83902a_priv_data *dp = dev->priv; | |
723 | + | |
724 | + dp83902a_poll(dp, (u8 *)dev->iobase); | |
749 | 725 | return 1; |
750 | 726 | } |
751 | 727 | |
752 | 728 | static int ne2k_send(struct eth_device *dev, void *packet, int length) |
753 | 729 | { |
730 | + struct dp83902a_priv_data *dp = dev->priv; | |
754 | 731 | int tmo; |
755 | 732 | |
756 | 733 | debug("### ne2k_send\n"); |
757 | 734 | |
758 | - pkey = -1; | |
735 | + dp->pkey = -1; | |
759 | 736 | |
760 | - dp83902a_send((u8 *) packet, length, 666); | |
737 | + dp83902a_send(dp, (u8 *)dev->iobase, (u8 *) packet, length, 666); | |
761 | 738 | tmo = get_timer (0) + TOUT * CONFIG_SYS_HZ; |
762 | 739 | while(1) { |
763 | - dp83902a_poll(); | |
764 | - if (pkey != -1) { | |
740 | + dp83902a_poll(dp, (u8 *)dev->iobase); | |
741 | + if (dp->pkey != -1) { | |
765 | 742 | PRINTK("Packet sucesfully sent\n"); |
766 | 743 | return 0; |
767 | 744 | } |
@@ -785,8 +762,14 @@ int ne2k_register(void) | ||
785 | 762 | dev = calloc(sizeof(*dev), 1); |
786 | 763 | if (dev == NULL) |
787 | 764 | return -1; |
765 | + dev->priv = calloc(sizeof(struct dp83902a_priv_data), 1); | |
766 | + if (dev == NULL) | |
767 | + return -1; | |
788 | 768 | |
789 | - if (ne2k_setup_driver(dev)) | |
769 | + dev->iobase = CONFIG_DRIVER_NE2000_BASE; | |
770 | + if (ne2k_setup_driver((struct dp83902a_priv_data *)dev->priv, | |
771 | + (u8 *)dev->iobase, | |
772 | + dev->enetaddr)) | |
790 | 773 | return -1; |
791 | 774 | |
792 | 775 | dev->init = ne2k_init; |
@@ -122,9 +122,6 @@ typedef struct hw_info_t { | ||
122 | 122 | } hw_info_t; |
123 | 123 | |
124 | 124 | typedef struct dp83902a_priv_data { |
125 | - u8* base; | |
126 | - u8* data; | |
127 | - u8* reset; | |
128 | 125 | int tx_next; /* First free Tx page */ |
129 | 126 | int tx_int; /* Expecting interrupt from this buffer */ |
130 | 127 | int rx_next; /* First free Rx page */ |
@@ -132,12 +129,15 @@ typedef struct dp83902a_priv_data { | ||
132 | 129 | u32 tx1_key, tx2_key; /* Used to ack when packet sent */ |
133 | 130 | int tx1_len, tx2_len; |
134 | 131 | bool tx_started, running, hardwired_esa; |
135 | - u8 esa[6]; | |
136 | 132 | void* plf_priv; |
137 | 133 | |
138 | 134 | /* Buffer allocation */ |
139 | 135 | int tx_buf1, tx_buf2; |
140 | 136 | int rx_buf_start, rx_buf_end; |
137 | + unsigned char *pbuf; | |
138 | + int initialized; | |
139 | + int pkey; | |
140 | + | |
141 | 141 | } dp83902a_priv_data_t; |
142 | 142 | |
143 | 143 | /* ------------------------------------------------------------------------ */ |