blob: 5a90cc57dde4740b08910023299fe44df8e66afb [file] [log] [blame]
wdenkc7de8292002-11-19 11:04:11 +00001/*
2 * (C) Copyright 2002
3 * Adam Kowalczyk, ACK Software Controls Inc. akowalczyk@cogeco.ca
4 *
5 * Some portions taken from 3c59x.c Written 1996-1999 by Donald Becker.
6 *
7 * Outline of the program based on eepro100.c which is
8 *
9 * (C) Copyright 2002
10 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <malloc.h>
30#include <net.h>
31#include <asm/io.h>
32#include <pci.h>
33
34#include "articiaS.h"
35#include "memio.h"
36
37/* 3Com Ethernet PCI definitions*/
38
wdenk8bde7f72003-06-27 21:31:46 +000039/* #define PCI_VENDOR_ID_3COM 0x10B7 */
wdenkc7de8292002-11-19 11:04:11 +000040#define PCI_DEVICE_ID_3COM_3C905C 0x9200
41
42/* 3Com Commands, top 5 bits are command and bottom 11 bits are parameters */
43
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010044#define TotalReset (0<<11)
45#define SelectWindow (1<<11)
46#define StartCoax (2<<11)
47#define RxDisable (3<<11)
48#define RxEnable (4<<11)
49#define RxReset (5<<11)
50#define UpStall (6<<11)
51#define UpUnstall (6<<11)+1
52#define DownStall (6<<11)+2
53#define DownUnstall (6<<11)+3
54#define RxDiscard (8<<11)
55#define TxEnable (9<<11)
56#define TxDisable (10<<11)
57#define TxReset (11<<11)
58#define FakeIntr (12<<11)
59#define AckIntr (13<<11)
60#define SetIntrEnb (14<<11)
61#define SetStatusEnb (15<<11)
62#define SetRxFilter (16<<11)
63#define SetRxThreshold (17<<11)
64#define SetTxThreshold (18<<11)
65#define SetTxStart (19<<11)
66#define StartDMAUp (20<<11)
67#define StartDMADown (20<<11)+1
wdenkc7de8292002-11-19 11:04:11 +000068#define StatsEnable (21<<11)
wdenk8bde7f72003-06-27 21:31:46 +000069#define StatsDisable (22<<11)
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010070#define StopCoax (23<<11)
71#define SetFilterBit (25<<11)
wdenkc7de8292002-11-19 11:04:11 +000072
73/* The SetRxFilter command accepts the following classes */
74
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010075#define RxStation 1
wdenk8bde7f72003-06-27 21:31:46 +000076#define RxMulticast 2
77#define RxBroadcast 4
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010078#define RxProm 8
wdenkc7de8292002-11-19 11:04:11 +000079
80/* 3Com status word defnitions */
81
Wolfgang Denkdd520bf2006-11-30 18:02:20 +010082#define IntLatch 0x0001
83#define HostError 0x0002
84#define TxComplete 0x0004
85#define TxAvailable 0x0008
86#define RxComplete 0x0010
87#define RxEarly 0x0020
88#define IntReq 0x0040
89#define StatsFull 0x0080
90#define DMADone (1<<8)
91#define DownComplete (1<<9)
92#define UpComplete (1<<10)
Wolfgang Denk53677ef2008-05-20 16:00:29 +020093#define DMAInProgress (1<<11) /* DMA controller is still busy.*/
94#define CmdInProgress (1<<12) /* EL3_CMD is still busy.*/
wdenkc7de8292002-11-19 11:04:11 +000095
96/* Polling Registers */
97
98#define DnPoll 0x2d
99#define UpPoll 0x3d
100
101/* Register window 0 offets */
102
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200103#define Wn0EepromCmd 10 /* Window 0: EEPROM command register. */
104#define Wn0EepromData 12 /* Window 0: EEPROM results register. */
105#define IntrStatus 0x0E /* Valid in all windows. */
wdenkc7de8292002-11-19 11:04:11 +0000106
107/* Register window 0 EEPROM bits */
108
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100109#define EEPROM_Read 0x80
110#define EEPROM_WRITE 0x40
111#define EEPROM_ERASE 0xC0
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200112#define EEPROM_EWENB 0x30 /* Enable erasing/writing for 10 msec. */
113#define EEPROM_EWDIS 0x00 /* Disable EWENB before 10 msec timeout. */
wdenkc7de8292002-11-19 11:04:11 +0000114
115/* EEPROM locations. */
116
wdenk8bde7f72003-06-27 21:31:46 +0000117#define PhysAddr01 0
wdenkc7de8292002-11-19 11:04:11 +0000118#define PhysAddr23 1
wdenk8bde7f72003-06-27 21:31:46 +0000119#define PhysAddr45 2
wdenkc7de8292002-11-19 11:04:11 +0000120#define ModelID 3
wdenk8bde7f72003-06-27 21:31:46 +0000121#define EtherLink3ID 7
122#define IFXcvrIO 8
wdenkc7de8292002-11-19 11:04:11 +0000123#define IRQLine 9
wdenk8bde7f72003-06-27 21:31:46 +0000124#define NodeAddr01 10
125#define NodeAddr23 11
wdenkc7de8292002-11-19 11:04:11 +0000126#define NodeAddr45 12
wdenk8bde7f72003-06-27 21:31:46 +0000127#define DriverTune 13
wdenkc7de8292002-11-19 11:04:11 +0000128#define Checksum 15
129
130/* Register window 1 offsets, the window used in normal operation */
131
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100132#define TX_FIFO 0x10
133#define RX_FIFOa 0x10
134#define RxErrors 0x14
135#define RxStatus 0x18
wdenk8bde7f72003-06-27 21:31:46 +0000136#define Timer 0x1A
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100137#define TxStatus 0x1B
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200138#define TxFree 0x1C /* Remaining free bytes in Tx buffer. */
wdenkc7de8292002-11-19 11:04:11 +0000139
140/* Register Window 2 */
wdenk8bde7f72003-06-27 21:31:46 +0000141
wdenkc7de8292002-11-19 11:04:11 +0000142#define Wn2_ResetOptions 12
143
144/* Register Window 3: MAC/config bits */
145
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200146#define Wn3_Config 0 /* Internal Configuration */
wdenkc7de8292002-11-19 11:04:11 +0000147#define Wn3_MAC_Ctrl 6
148#define Wn3_Options 8
149
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100150#define BFEXT(value, offset, bitcount) \
wdenk8bde7f72003-06-27 21:31:46 +0000151 ((((unsigned long)(value)) >> (offset)) & ((1 << (bitcount)) - 1))
wdenkc7de8292002-11-19 11:04:11 +0000152
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200153#define BFINS(lhs, rhs, offset, bitcount) \
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100154 (((lhs) & ~((((1 << (bitcount)) - 1)) << (offset))) | \
wdenk8bde7f72003-06-27 21:31:46 +0000155 (((rhs) & ((1 << (bitcount)) - 1)) << (offset)))
wdenkc7de8292002-11-19 11:04:11 +0000156
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200157#define RAM_SIZE(v) BFEXT(v, 0, 3)
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100158#define RAM_WIDTH(v) BFEXT(v, 3, 1)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200159#define RAM_SPEED(v) BFEXT(v, 4, 2)
160#define ROM_SIZE(v) BFEXT(v, 6, 2)
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100161#define RAM_SPLIT(v) BFEXT(v, 16, 2)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200162#define XCVR(v) BFEXT(v, 20, 4)
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100163#define AUTOSELECT(v) BFEXT(v, 24, 1)
wdenkc7de8292002-11-19 11:04:11 +0000164
165/* Register Window 4: Xcvr/media bits */
wdenk8bde7f72003-06-27 21:31:46 +0000166
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100167#define Wn4_FIFODiag 4
168#define Wn4_NetDiag 6
wdenkc7de8292002-11-19 11:04:11 +0000169#define Wn4_PhysicalMgmt 8
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100170#define Wn4_Media 10
wdenkc7de8292002-11-19 11:04:11 +0000171
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100172#define Media_SQE 0x0008 /* Enable SQE error counting for AUI. */
173#define Media_10TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
174#define Media_Lnk 0x0080 /* Enable just link beat for 100TX/100FX. */
175#define Media_LnkBeat 0x0800
wdenkc7de8292002-11-19 11:04:11 +0000176
177/* Register Window 7: Bus Master control */
178
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100179#define Wn7_MasterAddr 0
180#define Wn7_MasterLen 6
181#define Wn7_MasterStatus 12
wdenkc7de8292002-11-19 11:04:11 +0000182
183/* Boomerang bus master control registers. */
184
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100185#define PktStatus 0x20
wdenkc7de8292002-11-19 11:04:11 +0000186#define DownListPtr 0x24
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100187#define FragAddr 0x28
188#define FragLen 0x2c
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200189#define TxFreeThreshold 0x2f
Wolfgang Denkdd520bf2006-11-30 18:02:20 +0100190#define UpPktStatus 0x30
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200191#define UpListPtr 0x38
wdenkc7de8292002-11-19 11:04:11 +0000192
193/* The Rx and Tx descriptor lists. */
194
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200195#define LAST_FRAG 0x80000000 /* Last Addr/Len pair in descriptor. */
196#define DN_COMPLETE 0x00010000 /* This packet has been downloaded */
wdenkc7de8292002-11-19 11:04:11 +0000197
198struct rx_desc_3com {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200199 u32 next; /* Last entry points to 0 */
200 u32 status; /* FSH -> Frame Start Header */
201 u32 addr; /* Up to 63 addr/len pairs possible */
202 u32 length; /* Set LAST_FRAG to indicate last pair */
wdenkc7de8292002-11-19 11:04:11 +0000203};
204
205/* Values for the Rx status entry. */
206
207#define RxDComplete 0x00008000
208#define RxDError 0x4000
wdenk8bde7f72003-06-27 21:31:46 +0000209#define IPChksumErr (1<<25)
210#define TCPChksumErr (1<<26)
wdenkc7de8292002-11-19 11:04:11 +0000211#define UDPChksumErr (1<<27)
wdenk8bde7f72003-06-27 21:31:46 +0000212#define IPChksumValid (1<<29)
wdenkc7de8292002-11-19 11:04:11 +0000213#define TCPChksumValid (1<<30)
214#define UDPChksumValid (1<<31)
215
216struct tx_desc_3com {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200217 u32 next; /* Last entry points to 0 */
218 u32 status; /* bits 0:12 length, others see below */
wdenk8bde7f72003-06-27 21:31:46 +0000219 u32 addr;
220 u32 length;
wdenkc7de8292002-11-19 11:04:11 +0000221};
222
223/* Values for the Tx status entry. */
224
225#define CRCDisable 0x2000
226#define TxDComplete 0x8000
227#define AddIPChksum 0x02000000
228#define AddTCPChksum 0x04000000
229#define AddUDPChksum 0x08000000
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200230#define TxIntrUploaded 0x80000000 /* IRQ when in FIFO, but maybe not sent. */
wdenkc7de8292002-11-19 11:04:11 +0000231
232/* XCVR Types */
233
234#define XCVR_10baseT 0
wdenk8bde7f72003-06-27 21:31:46 +0000235#define XCVR_AUI 1
wdenkc7de8292002-11-19 11:04:11 +0000236#define XCVR_10baseTOnly 2
wdenk8bde7f72003-06-27 21:31:46 +0000237#define XCVR_10base2 3
wdenkc7de8292002-11-19 11:04:11 +0000238#define XCVR_100baseTx 4
239#define XCVR_100baseFx 5
240#define XCVR_MII 6
241#define XCVR_NWAY 8
242#define XCVR_ExtMII 9
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200243#define XCVR_Default 10 /* I don't think this is correct -> should have been 0x10 if Auto Negotiate */
wdenkc7de8292002-11-19 11:04:11 +0000244
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200245struct descriptor { /* A generic descriptor. */
246 u32 next; /* Last entry points to 0 */
247 u32 status; /* FSH -> Frame Start Header */
248 u32 addr; /* Up to 63 addr/len pairs possible */
249 u32 length; /* Set LAST_FRAG to indicate last pair */
wdenkc7de8292002-11-19 11:04:11 +0000250};
251
252/* Misc. definitions */
253
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200254#define NUM_RX_DESC PKTBUFSRX * 10
255#define NUM_TX_DESC 1 /* Number of TX descriptors */
wdenkc7de8292002-11-19 11:04:11 +0000256
257#define TOUT_LOOP 1000000
258
259#define ETH_ALEN 6
260
261#define EL3WINDOW(dev, win_num) ETH_OUTW(dev, SelectWindow + (win_num), EL3_CMD)
262#define EL3_CMD 0x0e
263#define EL3_STATUS 0x0e
264
265
266#undef ETH_DEBUG
267
268#ifdef ETH_DEBUG
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200269#define PRINTF(fmt,args...) printf (fmt ,##args)
wdenkc7de8292002-11-19 11:04:11 +0000270#else
271#define PRINTF(fmt,args...)
272#endif
273
274
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200275static struct rx_desc_3com *rx_ring; /* RX descriptor ring */
276static struct tx_desc_3com *tx_ring; /* TX descriptor ring */
277static u8 rx_buffer[NUM_RX_DESC][PKTSIZE_ALIGN];/* storage for the incoming messages */
278static int rx_next = 0; /* RX descriptor ring pointer */
279static int tx_next = 0; /* TX descriptor ring pointer */
wdenkc7de8292002-11-19 11:04:11 +0000280static int tx_threshold;
281
282static void init_rx_ring(struct eth_device* dev);
283static void purge_tx_ring(struct eth_device* dev);
284
285static void read_hw_addr(struct eth_device* dev, bd_t * bis);
286
287static int eth_3com_init(struct eth_device* dev, bd_t *bis);
288static int eth_3com_send(struct eth_device* dev, volatile void *packet, int length);
289static int eth_3com_recv(struct eth_device* dev);
290static void eth_3com_halt(struct eth_device* dev);
291
292#define io_to_phys(a) pci_io_to_phys((pci_dev_t)dev->priv, a)
293#define phys_to_io(a) pci_phys_to_io((pci_dev_t)dev->priv, a)
294#define mem_to_phys(a) pci_mem_to_phys((pci_dev_t)dev->priv, a)
295#define phys_to_mem(a) pci_phys_to_mem((pci_dev_t)dev->priv, a)
296
297static inline int ETH_INL(struct eth_device* dev, u_long addr)
298{
299 __asm volatile ("eieio");
300 return le32_to_cpu(*(volatile u32 *)io_to_phys(addr + dev->iobase));
301}
302
303static inline int ETH_INW(struct eth_device* dev, u_long addr)
304{
305 __asm volatile ("eieio");
306 return le16_to_cpu(*(volatile u16 *)io_to_phys(addr + dev->iobase));
307}
308
309static inline int ETH_INB(struct eth_device* dev, u_long addr)
310{
311 __asm volatile ("eieio");
312 return *(volatile u8 *)io_to_phys(addr + dev->iobase);
313}
314
315static inline void ETH_OUTB(struct eth_device* dev, int command, u_long addr)
316{
317 *(volatile u8 *)io_to_phys(addr + dev->iobase) = command;
318 __asm volatile ("eieio");
319}
320
321static inline void ETH_OUTW(struct eth_device* dev, int command, u_long addr)
322{
323 *(volatile u16 *)io_to_phys(addr + dev->iobase) = cpu_to_le16(command);
324 __asm volatile ("eieio");
325}
326
327static inline void ETH_OUTL(struct eth_device* dev, int command, u_long addr)
328{
329 *(volatile u32 *)io_to_phys(addr + dev->iobase) = cpu_to_le32(command);
330 __asm volatile ("eieio");
331}
332
333static inline int ETH_STATUS(struct eth_device* dev)
334{
335 __asm volatile ("eieio");
336 return le16_to_cpu(*(volatile u16 *)io_to_phys(EL3_STATUS + dev->iobase));
337}
338
339static inline void ETH_CMD(struct eth_device* dev, int command)
340{
wdenk8bde7f72003-06-27 21:31:46 +0000341 *(volatile u16 *)io_to_phys(EL3_CMD + dev->iobase) = cpu_to_le16(command);
wdenkc7de8292002-11-19 11:04:11 +0000342 __asm volatile ("eieio");
343}
344
345/* Command register is always in the same spot in all the register windows */
346/* This function issues a command and waits for it so complete by checking the CmdInProgress bit */
347
348static int issue_and_wait(struct eth_device* dev, int command)
349{
350
wdenk8bde7f72003-06-27 21:31:46 +0000351 int i, status;
wdenkc7de8292002-11-19 11:04:11 +0000352
353 ETH_CMD(dev, command);
wdenk8bde7f72003-06-27 21:31:46 +0000354 for (i = 0; i < 2000; i++) {
355 status = ETH_STATUS(dev);
356 /*printf ("Issue: status 0x%4x.\n", status); */
wdenkc7de8292002-11-19 11:04:11 +0000357 if (!(status & CmdInProgress))
wdenk8bde7f72003-06-27 21:31:46 +0000358 return 1;
359 }
wdenkc7de8292002-11-19 11:04:11 +0000360
wdenk8bde7f72003-06-27 21:31:46 +0000361 /* OK, that didn't work. Do it the slow way. One second */
362 for (i = 0; i < 100000; i++) {
363 status = ETH_STATUS(dev);
364 /*printf ("Issue: status 0x%4x.\n", status); */
365 return 1;
366 udelay(10);
367 }
368 PRINTF("Ethernet command: 0x%4x did not complete! Status: 0x%4x\n", command, ETH_STATUS(dev) );
wdenkc7de8292002-11-19 11:04:11 +0000369 return 0;
370}
371
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200372/* Determine network media type and set up 3com accordingly */
wdenkc7de8292002-11-19 11:04:11 +0000373/* I think I'm going to start with something known first like 10baseT */
374
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200375static int auto_negotiate (struct eth_device *dev)
wdenkc7de8292002-11-19 11:04:11 +0000376{
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200377 int i;
wdenkc7de8292002-11-19 11:04:11 +0000378
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200379 EL3WINDOW (dev, 1);
wdenkc7de8292002-11-19 11:04:11 +0000380
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200381 /* Wait for Auto negotiation to complete */
382 for (i = 0; i <= 1000; i++) {
383 if (ETH_INW (dev, 2) & 0x04)
384 break;
385 udelay (100);
wdenkc7de8292002-11-19 11:04:11 +0000386
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200387 if (i == 1000) {
388 PRINTF ("Error: Auto negotiation failed\n");
389 return 0;
390 }
wdenkc7de8292002-11-19 11:04:11 +0000391 }
wdenkc7de8292002-11-19 11:04:11 +0000392
393
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200394 return 1;
wdenkc7de8292002-11-19 11:04:11 +0000395}
396
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200397void eth_interrupt (struct eth_device *dev)
wdenkc7de8292002-11-19 11:04:11 +0000398{
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200399 u16 status = ETH_STATUS (dev);
wdenkc7de8292002-11-19 11:04:11 +0000400
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200401 printf ("eth0: status = 0x%04x\n", status);
wdenkc7de8292002-11-19 11:04:11 +0000402
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200403 if (!(status & IntLatch))
404 return;
wdenkc7de8292002-11-19 11:04:11 +0000405
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200406 if (status & (1 << 6)) {
407 ETH_CMD (dev, AckIntr | (1 << 6));
408 printf ("Acknowledged Interrupt command\n");
409 }
wdenkc7de8292002-11-19 11:04:11 +0000410
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200411 if (status & DownComplete) {
412 ETH_CMD (dev, AckIntr | DownComplete);
413 printf ("Acknowledged DownComplete\n");
414 }
wdenkc7de8292002-11-19 11:04:11 +0000415
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200416 if (status & UpComplete) {
417 ETH_CMD (dev, AckIntr | UpComplete);
418 printf ("Acknowledged UpComplete\n");
419 }
wdenkc7de8292002-11-19 11:04:11 +0000420
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200421 ETH_CMD (dev, AckIntr | IntLatch);
422 printf ("Acknowledged IntLatch\n");
wdenkc7de8292002-11-19 11:04:11 +0000423}
424
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200425int eth_3com_initialize (bd_t * bis)
wdenkc7de8292002-11-19 11:04:11 +0000426{
wdenk8bde7f72003-06-27 21:31:46 +0000427 u32 eth_iobase = 0, status;
428 int card_number = 0, ret;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200429 struct eth_device *dev;
wdenk8bde7f72003-06-27 21:31:46 +0000430 pci_dev_t devno;
wdenkc7de8292002-11-19 11:04:11 +0000431 char *s;
432
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200433 s = getenv ("3com_base");
wdenkc7de8292002-11-19 11:04:11 +0000434
435 /* Find ethernet controller on the PCI bus */
436
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200437 if ((devno =
438 pci_find_device (PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C905C,
439 0)) < 0) {
440 PRINTF ("Error: Cannot find the ethernet device on the PCI bus\n");
wdenkc7de8292002-11-19 11:04:11 +0000441 goto Done;
442 }
443
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200444 if (s) {
445 unsigned long base = atoi (s);
446
447 pci_write_config_dword (devno, PCI_BASE_ADDRESS_0,
448 base | 0x01);
wdenkc7de8292002-11-19 11:04:11 +0000449 }
450
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200451 ret = pci_read_config_dword (devno, PCI_BASE_ADDRESS_0, &eth_iobase);
wdenk8bde7f72003-06-27 21:31:46 +0000452 eth_iobase &= ~0xf;
wdenkc7de8292002-11-19 11:04:11 +0000453
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200454 PRINTF ("eth: 3Com Found at Address: 0x%x\n", eth_iobase);
wdenk8bde7f72003-06-27 21:31:46 +0000455
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200456 pci_write_config_dword (devno, PCI_COMMAND,
457 PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
458 PCI_COMMAND_MASTER);
wdenkc7de8292002-11-19 11:04:11 +0000459
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200460 /* Check if I/O accesses and Bus Mastering are enabled */
wdenkc7de8292002-11-19 11:04:11 +0000461
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200462 ret = pci_read_config_dword (devno, PCI_COMMAND, &status);
wdenkc7de8292002-11-19 11:04:11 +0000463
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200464 if (!(status & PCI_COMMAND_IO)) {
465 printf ("Error: Cannot enable IO access.\n");
wdenkc7de8292002-11-19 11:04:11 +0000466 goto Done;
467 }
468
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200469 if (!(status & PCI_COMMAND_MEMORY)) {
470 printf ("Error: Cannot enable MEMORY access.\n");
wdenkc7de8292002-11-19 11:04:11 +0000471 goto Done;
472 }
473
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200474 if (!(status & PCI_COMMAND_MASTER)) {
475 printf ("Error: Cannot enable Bus Mastering.\n");
wdenkc7de8292002-11-19 11:04:11 +0000476 goto Done;
477 }
478
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200479 dev = (struct eth_device *) malloc (sizeof (*dev)); /*struct eth_device)); */
wdenkc7de8292002-11-19 11:04:11 +0000480
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200481 sprintf (dev->name, "3Com 3c920c#%d", card_number);
wdenk8bde7f72003-06-27 21:31:46 +0000482 dev->iobase = eth_iobase;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200483 dev->priv = (void *) devno;
484 dev->init = eth_3com_init;
485 dev->halt = eth_3com_halt;
486 dev->send = eth_3com_send;
487 dev->recv = eth_3com_recv;
wdenkc7de8292002-11-19 11:04:11 +0000488
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200489 eth_register (dev);
wdenkc7de8292002-11-19 11:04:11 +0000490
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200491/* { */
492/* char interrupt; */
493/* devno = pci_find_device(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C905C, 0); */
494/* pci_read_config_byte(devno, PCI_INTERRUPT_LINE, &interrupt); */
wdenk8bde7f72003-06-27 21:31:46 +0000495
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200496/* printf("Installing eth0 interrupt handler to %d\n", interrupt); */
497/* irq_install_handler(interrupt, eth_interrupt, dev); */
498/* } */
wdenkc7de8292002-11-19 11:04:11 +0000499
wdenk8bde7f72003-06-27 21:31:46 +0000500 card_number++;
wdenkc7de8292002-11-19 11:04:11 +0000501
502 /* Set the latency timer for value */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200503 s = getenv ("3com_latency");
504 if (s) {
505 ret = pci_write_config_byte (devno, PCI_LATENCY_TIMER,
506 (unsigned char) atoi (s));
507 } else
508 ret = pci_write_config_byte (devno, PCI_LATENCY_TIMER, 0x0a);
wdenkc7de8292002-11-19 11:04:11 +0000509
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200510 read_hw_addr (dev, bis); /* get the MAC address from Window 2 */
wdenkc7de8292002-11-19 11:04:11 +0000511
512 /* Reset the ethernet controller */
513
514 PRINTF ("Issuing reset command....\n");
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200515 if (!issue_and_wait (dev, TotalReset)) {
516 printf ("Error: Cannot reset ethernet controller.\n");
wdenkc7de8292002-11-19 11:04:11 +0000517 goto Done;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200518 } else
wdenkc7de8292002-11-19 11:04:11 +0000519 PRINTF ("Ethernet controller reset.\n");
520
521 /* allocate memory for rx and tx rings */
522
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200523 if (!(rx_ring = memalign (sizeof (struct rx_desc_3com) * NUM_RX_DESC, 16))) {
wdenkc7de8292002-11-19 11:04:11 +0000524 PRINTF ("Cannot allocate memory for RX_RING.....\n");
525 goto Done;
526 }
wdenk8bde7f72003-06-27 21:31:46 +0000527
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200528 if (!(tx_ring = memalign (sizeof (struct tx_desc_3com) * NUM_TX_DESC, 16))) {
wdenkc7de8292002-11-19 11:04:11 +0000529 PRINTF ("Cannot allocate memory for TX_RING.....\n");
530 goto Done;
531 }
wdenk8bde7f72003-06-27 21:31:46 +0000532
wdenkc7de8292002-11-19 11:04:11 +0000533Done:
534 return status;
535}
536
537
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200538static int eth_3com_init (struct eth_device *dev, bd_t * bis)
wdenkc7de8292002-11-19 11:04:11 +0000539{
540 int i, status = 0;
541 int tx_cur, loop;
542 u16 status_enable, intr_enable;
543 struct descriptor *ias_cmd;
544
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200545 /* Determine what type of network the machine is connected to */
546 /* presently drops the connect to 10Mbps */
wdenkc7de8292002-11-19 11:04:11 +0000547
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200548 if (!auto_negotiate (dev)) {
549 printf ("Error: Cannot determine network media.\n");
wdenkc7de8292002-11-19 11:04:11 +0000550 goto Done;
551 }
552
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200553 issue_and_wait (dev, TxReset);
554 issue_and_wait (dev, RxReset | 0x04);
wdenkc7de8292002-11-19 11:04:11 +0000555
wdenk8bde7f72003-06-27 21:31:46 +0000556 /* Switch to register set 7 for normal use. */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200557 EL3WINDOW (dev, 7);
wdenkc7de8292002-11-19 11:04:11 +0000558
559 /* Initialize Rx and Tx rings */
560
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200561 init_rx_ring (dev);
562 purge_tx_ring (dev);
wdenkc7de8292002-11-19 11:04:11 +0000563
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200564 ETH_CMD (dev, SetRxFilter | RxStation | RxBroadcast | RxProm);
wdenkc7de8292002-11-19 11:04:11 +0000565
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200566 issue_and_wait (dev, SetTxStart | 0x07ff);
wdenkc7de8292002-11-19 11:04:11 +0000567
wdenk8bde7f72003-06-27 21:31:46 +0000568 /* Below sets which indication bits to be seen. */
wdenkc7de8292002-11-19 11:04:11 +0000569
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200570 status_enable =
571 SetStatusEnb | HostError | DownComplete | UpComplete | (1 <<
572 6);
573 ETH_CMD (dev, status_enable);
wdenkc7de8292002-11-19 11:04:11 +0000574
575 /* Below sets no bits are to cause an interrupt since this is just polling */
576
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200577 intr_enable = SetIntrEnb;
wdenk8bde7f72003-06-27 21:31:46 +0000578/* intr_enable = SetIntrEnb | (1<<9) | (1<<10) | (1<<6); */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200579 ETH_CMD (dev, intr_enable);
580 ETH_OUTB (dev, 127, UpPoll);
wdenkc7de8292002-11-19 11:04:11 +0000581
wdenk8bde7f72003-06-27 21:31:46 +0000582 /* Ack all pending events, and set active indicator mask */
wdenkc7de8292002-11-19 11:04:11 +0000583
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200584 ETH_CMD (dev, AckIntr | IntLatch | TxAvailable | RxEarly | IntReq);
585 ETH_CMD (dev, intr_enable);
wdenkc7de8292002-11-19 11:04:11 +0000586
587 /* Tell the adapter where the RX ring is located */
588
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200589 issue_and_wait (dev, UpStall); /* Stall and set the UplistPtr */
590 ETH_OUTL (dev, (u32) & rx_ring[rx_next], UpListPtr);
591 ETH_CMD (dev, RxEnable); /* Enable the receiver. */
592 issue_and_wait (dev, UpUnstall);
wdenkc7de8292002-11-19 11:04:11 +0000593
594 /* Send the Individual Address Setup frame */
595
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200596 tx_cur = tx_next;
597 tx_next = ((tx_next + 1) % NUM_TX_DESC);
wdenkc7de8292002-11-19 11:04:11 +0000598
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200599 ias_cmd = (struct descriptor *) &tx_ring[tx_cur];
600 ias_cmd->status = cpu_to_le32 (1 << 31); /* set DnIndicate bit. */
601 ias_cmd->next = 0;
602 ias_cmd->addr = cpu_to_le32 ((u32) & bis->bi_enetaddr[0]);
603 ias_cmd->length = cpu_to_le32 (6 | LAST_FRAG);
wdenkc7de8292002-11-19 11:04:11 +0000604
605 /* Tell the adapter where the TX ring is located */
606
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200607 ETH_CMD (dev, TxEnable); /* Enable transmitter. */
608 issue_and_wait (dev, DownStall); /* Stall and set the DownListPtr. */
609 ETH_OUTL (dev, (u32) & tx_ring[tx_cur], DownListPtr);
610 issue_and_wait (dev, DownUnstall);
611 for (i = 0; !(ETH_STATUS (dev) & DownComplete); i++) {
612 if (i >= TOUT_LOOP) {
613 PRINTF ("TX Ring status (Init): 0x%4x\n",
614 le32_to_cpu (tx_ring[tx_cur].status));
615 PRINTF ("ETH_STATUS: 0x%x\n", ETH_STATUS (dev));
wdenkc7de8292002-11-19 11:04:11 +0000616 goto Done;
617 }
618 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200619 if (ETH_STATUS (dev) & DownComplete) { /* If DownLoad Complete ACK the bit */
620 ETH_CMD (dev, AckIntr | DownComplete); /* acknowledge the indication bit */
621 issue_and_wait (dev, DownStall); /* stall and clear DownListPtr */
622 ETH_OUTL (dev, 0, DownListPtr);
623 issue_and_wait (dev, DownUnstall);
wdenkc7de8292002-11-19 11:04:11 +0000624 }
625 status = 1;
wdenkc7de8292002-11-19 11:04:11 +0000626Done:
627 return status;
628}
629
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200630int eth_3com_send (struct eth_device *dev, volatile void *packet, int length)
wdenkc7de8292002-11-19 11:04:11 +0000631{
632 int i, status = 0;
633 int tx_cur;
634
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200635 if (length <= 0) {
636 PRINTF ("eth: bad packet size: %d\n", length);
wdenkc7de8292002-11-19 11:04:11 +0000637 goto Done;
638 }
639
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200640 tx_cur = tx_next;
641 tx_next = (tx_next + 1) % NUM_TX_DESC;
wdenkc7de8292002-11-19 11:04:11 +0000642
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200643 tx_ring[tx_cur].status = cpu_to_le32 (1 << 31); /* set DnIndicate bit */
644 tx_ring[tx_cur].next = 0;
645 tx_ring[tx_cur].addr = cpu_to_le32 (((u32) packet));
646 tx_ring[tx_cur].length = cpu_to_le32 (length | LAST_FRAG);
wdenkc7de8292002-11-19 11:04:11 +0000647
648 /* Send the packet */
649
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200650 issue_and_wait (dev, DownStall); /* stall and set the DownListPtr */
651 ETH_OUTL (dev, (u32) & tx_ring[tx_cur], DownListPtr);
652 issue_and_wait (dev, DownUnstall);
wdenkc7de8292002-11-19 11:04:11 +0000653
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200654 for (i = 0; !(ETH_STATUS (dev) & DownComplete); i++) {
655 if (i >= TOUT_LOOP) {
656 PRINTF ("TX Ring status (send): 0x%4x\n",
657 le32_to_cpu (tx_ring[tx_cur].status));
wdenkc7de8292002-11-19 11:04:11 +0000658 goto Done;
659 }
660 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200661 if (ETH_STATUS (dev) & DownComplete) { /* If DownLoad Complete ACK the bit */
662 ETH_CMD (dev, AckIntr | DownComplete); /* acknowledge the indication bit */
663 issue_and_wait (dev, DownStall); /* stall and clear DownListPtr */
664 ETH_OUTL (dev, 0, DownListPtr);
665 issue_and_wait (dev, DownUnstall);
wdenkc7de8292002-11-19 11:04:11 +0000666 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200667 status = 1;
668Done:
wdenkc7de8292002-11-19 11:04:11 +0000669 return status;
670}
671
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200672void PrintPacket (uchar * packet, int length)
wdenkc7de8292002-11-19 11:04:11 +0000673{
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200674 int loop;
675 uchar *ptr;
wdenkc7de8292002-11-19 11:04:11 +0000676
677 printf ("Printing packet of length %x.\n\n", length);
678 ptr = packet;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200679 for (loop = 1; loop <= length; loop++) {
wdenkc7de8292002-11-19 11:04:11 +0000680 printf ("%2x ", *ptr++);
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200681 if ((loop % 40) == 0)
wdenkc7de8292002-11-19 11:04:11 +0000682 printf ("\n");
683 }
684}
685
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200686int eth_3com_recv (struct eth_device *dev)
wdenkc7de8292002-11-19 11:04:11 +0000687{
688 u16 stat = 0;
689 u32 status;
690 int rx_prev, length = 0;
691
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200692 while (!(ETH_STATUS (dev) & UpComplete)) /* wait on receipt of packet */
wdenkc7de8292002-11-19 11:04:11 +0000693 ;
694
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200695 status = le32_to_cpu (rx_ring[rx_next].status); /* packet status */
wdenkc7de8292002-11-19 11:04:11 +0000696
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200697 while (status & (1 << 15)) {
wdenkc7de8292002-11-19 11:04:11 +0000698 /* A packet has been received */
699
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200700 if (status & (1 << 15)) {
wdenkc7de8292002-11-19 11:04:11 +0000701 /* A valid frame received */
wdenk8bde7f72003-06-27 21:31:46 +0000702
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200703 length = le32_to_cpu (rx_ring[rx_next].status) & 0x1fff; /* length is in bits 0 - 12 */
wdenk8bde7f72003-06-27 21:31:46 +0000704
wdenkc7de8292002-11-19 11:04:11 +0000705 /* Pass the packet up to the protocol layers */
706
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200707 NetReceive ((uchar *)
708 le32_to_cpu (rx_ring[rx_next].addr),
709 length);
710 rx_ring[rx_next].status = 0; /* clear the status word */
711 ETH_CMD (dev, AckIntr | UpComplete);
712 issue_and_wait (dev, UpUnstall);
713 } else if (stat & HostError) {
wdenkc7de8292002-11-19 11:04:11 +0000714 /* There was an error */
715
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200716 printf ("Rx error status: 0x%4x\n", stat);
717 init_rx_ring (dev);
wdenkc7de8292002-11-19 11:04:11 +0000718 goto Done;
719 }
720
721 rx_prev = rx_next;
722 rx_next = (rx_next + 1) % NUM_RX_DESC;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200723 stat = ETH_STATUS (dev); /* register status */
724 status = le32_to_cpu (rx_ring[rx_next].status); /* packet status */
wdenkc7de8292002-11-19 11:04:11 +0000725 }
wdenkc7de8292002-11-19 11:04:11 +0000726Done:
727 return length;
728}
729
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200730void eth_3com_halt (struct eth_device *dev)
wdenkc7de8292002-11-19 11:04:11 +0000731{
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200732 if (!(dev->iobase)) {
wdenkc7de8292002-11-19 11:04:11 +0000733 goto Done;
734 }
735
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200736 issue_and_wait (dev, DownStall); /* shut down transmit and receive */
737 issue_and_wait (dev, UpStall);
738 issue_and_wait (dev, RxDisable);
739 issue_and_wait (dev, TxDisable);
wdenkc7de8292002-11-19 11:04:11 +0000740
wdenk8bde7f72003-06-27 21:31:46 +0000741/* free(tx_ring); /###* release memory allocated to the DPD and UPD rings */
742/* free(rx_ring); */
wdenkc7de8292002-11-19 11:04:11 +0000743
744Done:
745 return;
746}
747
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200748static void init_rx_ring (struct eth_device *dev)
wdenkc7de8292002-11-19 11:04:11 +0000749{
750 int i;
751
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200752 PRINTF ("Initializing rx_ring. rx_buffer = %p\n", rx_buffer);
753 issue_and_wait (dev, UpStall);
wdenkc7de8292002-11-19 11:04:11 +0000754
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200755 for (i = 0; i < NUM_RX_DESC; i++) {
756 rx_ring[i].next =
757 cpu_to_le32 (((u32) &
758 rx_ring[(i + 1) % NUM_RX_DESC]));
759 rx_ring[i].status = 0;
760 rx_ring[i].addr = cpu_to_le32 (((u32) & rx_buffer[i][0]));
761 rx_ring[i].length = cpu_to_le32 (PKTSIZE_ALIGN | LAST_FRAG);
wdenkc7de8292002-11-19 11:04:11 +0000762 }
763 rx_next = 0;
764}
765
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200766static void purge_tx_ring (struct eth_device *dev)
wdenkc7de8292002-11-19 11:04:11 +0000767{
768 int i;
769
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200770 PRINTF ("Purging tx_ring.\n");
wdenkc7de8292002-11-19 11:04:11 +0000771
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200772 tx_next = 0;
wdenkc7de8292002-11-19 11:04:11 +0000773
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200774 for (i = 0; i < NUM_TX_DESC; i++) {
775 tx_ring[i].next = 0;
776 tx_ring[i].status = 0;
777 tx_ring[i].addr = 0;
778 tx_ring[i].length = 0;
wdenkc7de8292002-11-19 11:04:11 +0000779 }
780}
781
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200782static void read_hw_addr (struct eth_device *dev, bd_t * bis)
wdenkc7de8292002-11-19 11:04:11 +0000783{
784 u8 hw_addr[ETH_ALEN];
785 unsigned int eeprom[0x40];
786 unsigned int checksum = 0;
787 int i, j, timer;
788
wdenk8bde7f72003-06-27 21:31:46 +0000789 /* Read the station address from the EEPROM. */
wdenkc7de8292002-11-19 11:04:11 +0000790
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200791 EL3WINDOW (dev, 0);
792 for (i = 0; i < 0x40; i++) {
793 ETH_OUTW (dev, EEPROM_Read + i, Wn0EepromCmd);
wdenk8bde7f72003-06-27 21:31:46 +0000794 /* Pause for at least 162 us. for the read to take place. */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200795 for (timer = 10; timer >= 0; timer--) {
796 udelay (162);
797 if ((ETH_INW (dev, Wn0EepromCmd) & 0x8000) == 0)
wdenk8bde7f72003-06-27 21:31:46 +0000798 break;
799 }
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200800 eeprom[i] = ETH_INW (dev, Wn0EepromData);
wdenk8bde7f72003-06-27 21:31:46 +0000801 }
wdenkc7de8292002-11-19 11:04:11 +0000802
803 /* Checksum calculation. I'm not sure about this part and there seems to be a bug on the 3com side of things */
804
wdenk8bde7f72003-06-27 21:31:46 +0000805 for (i = 0; i < 0x21; i++)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200806 checksum ^= eeprom[i];
wdenk8bde7f72003-06-27 21:31:46 +0000807 checksum = (checksum ^ (checksum >> 8)) & 0xff;
wdenkc7de8292002-11-19 11:04:11 +0000808
wdenk8bde7f72003-06-27 21:31:46 +0000809 if (checksum != 0xbb)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200810 printf (" *** INVALID EEPROM CHECKSUM %4.4x *** \n",
811 checksum);
wdenkc7de8292002-11-19 11:04:11 +0000812
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200813 for (i = 0, j = 0; i < 3; i++) {
814 hw_addr[j++] = (u8) ((eeprom[i + 10] >> 8) & 0xff);
815 hw_addr[j++] = (u8) (eeprom[i + 10] & 0xff);
wdenkc7de8292002-11-19 11:04:11 +0000816 }
817
818 /* MAC Address is in window 2, write value from EEPROM to window 2 */
819
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200820 EL3WINDOW (dev, 2);
wdenk8bde7f72003-06-27 21:31:46 +0000821 for (i = 0; i < 6; i++)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200822 ETH_OUTB (dev, hw_addr[i], i);
wdenkc7de8292002-11-19 11:04:11 +0000823
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200824 for (j = 0; j < ETH_ALEN; j += 2) {
825 hw_addr[j] = (u8) (ETH_INW (dev, j) & 0xff);
826 hw_addr[j + 1] = (u8) ((ETH_INW (dev, j) >> 8) & 0xff);
wdenkc7de8292002-11-19 11:04:11 +0000827 }
828
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200829 for (i = 0; i < ETH_ALEN; i++) {
830 if (hw_addr[i] != bis->bi_enetaddr[i]) {
831/* printf("Warning: HW address don't match:\n"); */
832/* printf("Address in 3Com Window 2 is " */
833/* "%02X:%02X:%02X:%02X:%02X:%02X\n", */
834/* hw_addr[0], hw_addr[1], hw_addr[2], */
835/* hw_addr[3], hw_addr[4], hw_addr[5]); */
836/* printf("Address used by U-Boot is " */
837/* "%02X:%02X:%02X:%02X:%02X:%02X\n", */
838/* bis->bi_enetaddr[0], bis->bi_enetaddr[1], */
839/* bis->bi_enetaddr[2], bis->bi_enetaddr[3], */
840/* bis->bi_enetaddr[4], bis->bi_enetaddr[5]); */
841/* goto Done; */
842 char buffer[256];
wdenkc7de8292002-11-19 11:04:11 +0000843
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200844 if (bis->bi_enetaddr[0] == 0
845 && bis->bi_enetaddr[1] == 0
846 && bis->bi_enetaddr[2] == 0
847 && bis->bi_enetaddr[3] == 0
848 && bis->bi_enetaddr[4] == 0
849 && bis->bi_enetaddr[5] == 0) {
850
851 sprintf (buffer,
852 "%02X:%02X:%02X:%02X:%02X:%02X",
853 hw_addr[0], hw_addr[1], hw_addr[2],
854 hw_addr[3], hw_addr[4], hw_addr[5]);
855 setenv ("ethaddr", buffer);
856 }
wdenkc7de8292002-11-19 11:04:11 +0000857 }
858 }
859
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200860 for (i = 0; i < ETH_ALEN; i++)
861 dev->enetaddr[i] = hw_addr[i];
wdenkc7de8292002-11-19 11:04:11 +0000862
863Done:
864 return;
865}