]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
c609719b WD |
2 | |
3 | #include <common.h> | |
7b51b576 | 4 | #include <env.h> |
c609719b WD |
5 | #include <malloc.h> |
6 | #include <net.h> | |
8ca0b3f9 | 7 | #include <netdev.h> |
c609719b WD |
8 | #include <pci.h> |
9 | ||
c2abfca9 | 10 | #define SROM_DLEVEL 0 |
c609719b WD |
11 | |
12 | #undef UPDATE_SROM | |
13 | ||
eb216f1e MV |
14 | /* PCI Registers. */ |
15 | #define PCI_CFDA_PSM 0x43 | |
c609719b WD |
16 | |
17 | #define CFRV_RN 0x000000f0 /* Revision Number */ | |
18 | ||
19 | #define WAKEUP 0x00 /* Power Saving Wakeup */ | |
20 | #define SLEEP 0x80 /* Power Saving Sleep Mode */ | |
21 | ||
eb216f1e | 22 | #define DC2114x_BRK 0x0020 /* CFRV break between DC21142 & DC21143 */ |
c609719b | 23 | |
eb216f1e | 24 | /* Ethernet chip registers. */ |
c609719b WD |
25 | #define DE4X5_BMR 0x000 /* Bus Mode Register */ |
26 | #define DE4X5_TPD 0x008 /* Transmit Poll Demand Reg */ | |
27 | #define DE4X5_RRBA 0x018 /* RX Ring Base Address Reg */ | |
28 | #define DE4X5_TRBA 0x020 /* TX Ring Base Address Reg */ | |
29 | #define DE4X5_STS 0x028 /* Status Register */ | |
30 | #define DE4X5_OMR 0x030 /* Operation Mode Register */ | |
31 | #define DE4X5_SICR 0x068 /* SIA Connectivity Register */ | |
32 | #define DE4X5_APROM 0x048 /* Ethernet Address PROM */ | |
33 | ||
eb216f1e | 34 | /* Register bits. */ |
c609719b WD |
35 | #define BMR_SWR 0x00000001 /* Software Reset */ |
36 | #define STS_TS 0x00700000 /* Transmit Process State */ | |
37 | #define STS_RS 0x000e0000 /* Receive Process State */ | |
38 | #define OMR_ST 0x00002000 /* Start/Stop Transmission Command */ | |
39 | #define OMR_SR 0x00000002 /* Start/Stop Receive */ | |
40 | #define OMR_PS 0x00040000 /* Port Select */ | |
41 | #define OMR_SDP 0x02000000 /* SD Polarity - MUST BE ASSERTED */ | |
42 | #define OMR_PM 0x00000080 /* Pass All Multicast */ | |
43 | ||
eb216f1e | 44 | /* Descriptor bits. */ |
c609719b WD |
45 | #define R_OWN 0x80000000 /* Own Bit */ |
46 | #define RD_RER 0x02000000 /* Receive End Of Ring */ | |
47 | #define RD_LS 0x00000100 /* Last Descriptor */ | |
48 | #define RD_ES 0x00008000 /* Error Summary */ | |
49 | #define TD_TER 0x02000000 /* Transmit End Of Ring */ | |
50 | #define T_OWN 0x80000000 /* Own Bit */ | |
51 | #define TD_LS 0x40000000 /* Last Segment */ | |
52 | #define TD_FS 0x20000000 /* First Segment */ | |
53 | #define TD_ES 0x00008000 /* Error Summary */ | |
54 | #define TD_SET 0x08000000 /* Setup Packet */ | |
55 | ||
56 | /* The EEPROM commands include the alway-set leading bit. */ | |
57 | #define SROM_WRITE_CMD 5 | |
58 | #define SROM_READ_CMD 6 | |
59 | #define SROM_ERASE_CMD 7 | |
60 | ||
eb216f1e | 61 | #define SROM_HWADD 0x0014 /* Hardware Address offset in SROM */ |
c609719b | 62 | #define SROM_RD 0x00004000 /* Read from Boot ROM */ |
eb216f1e MV |
63 | #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */ |
64 | #define EE_WRITE_0 0x4801 | |
65 | #define EE_WRITE_1 0x4805 | |
66 | #define EE_DATA_READ 0x08 /* EEPROM chip data out. */ | |
c609719b WD |
67 | #define SROM_SR 0x00000800 /* Select Serial ROM when set */ |
68 | ||
69 | #define DT_IN 0x00000004 /* Serial Data In */ | |
70 | #define DT_CLK 0x00000002 /* Serial ROM Clock */ | |
71 | #define DT_CS 0x00000001 /* Serial ROM Chip Select */ | |
72 | ||
73 | #define POLL_DEMAND 1 | |
74 | ||
04da0612 MV |
75 | #if defined(CONFIG_E500) |
76 | #define phys_to_bus(a) (a) | |
77 | #else | |
78 | #define phys_to_bus(a) pci_phys_to_mem((pci_dev_t)dev->priv, a) | |
79 | #endif | |
80 | ||
dbe9c0c1 MV |
81 | #define NUM_RX_DESC PKTBUFSRX |
82 | #define NUM_TX_DESC 1 /* Number of TX descriptors */ | |
83 | #define RX_BUFF_SZ PKTSIZE_ALIGN | |
84 | ||
85 | #define TOUT_LOOP 1000000 | |
86 | ||
87 | #define SETUP_FRAME_LEN 192 | |
88 | ||
89 | struct de4x5_desc { | |
90 | volatile s32 status; | |
91 | u32 des1; | |
92 | u32 buf; | |
93 | u32 next; | |
94 | }; | |
95 | ||
96 | /* RX and TX descriptor ring */ | |
97 | static struct de4x5_desc rx_ring[NUM_RX_DESC] __aligned(32); | |
98 | static struct de4x5_desc tx_ring[NUM_TX_DESC] __aligned(32); | |
99 | static int rx_new; /* RX descriptor ring pointer */ | |
100 | static int tx_new; /* TX descriptor ring pointer */ | |
101 | ||
102 | static char rx_ring_size; | |
103 | static char tx_ring_size; | |
104 | ||
3b7b9e2e | 105 | static u32 dc2114x_inl(struct eth_device *dev, u32 addr) |
04da0612 | 106 | { |
3b7b9e2e | 107 | return le32_to_cpu(*(volatile u32 *)(addr + dev->iobase)); |
04da0612 MV |
108 | } |
109 | ||
3b7b9e2e | 110 | static void dc2114x_outl(struct eth_device *dev, u32 command, u32 addr) |
04da0612 | 111 | { |
3b7b9e2e | 112 | *(volatile u32 *)(addr + dev->iobase) = cpu_to_le32(command); |
04da0612 MV |
113 | } |
114 | ||
115 | static void reset_de4x5(struct eth_device *dev) | |
116 | { | |
3b7b9e2e | 117 | u32 i; |
04da0612 | 118 | |
3b7b9e2e | 119 | i = dc2114x_inl(dev, DE4X5_BMR); |
04da0612 | 120 | mdelay(1); |
3b7b9e2e | 121 | dc2114x_outl(dev, i | BMR_SWR, DE4X5_BMR); |
04da0612 | 122 | mdelay(1); |
3b7b9e2e | 123 | dc2114x_outl(dev, i, DE4X5_BMR); |
04da0612 MV |
124 | mdelay(1); |
125 | ||
126 | for (i = 0; i < 5; i++) { | |
3b7b9e2e | 127 | dc2114x_inl(dev, DE4X5_BMR); |
04da0612 MV |
128 | mdelay(10); |
129 | } | |
130 | ||
131 | mdelay(1); | |
c609719b WD |
132 | } |
133 | ||
04da0612 MV |
134 | static void start_de4x5(struct eth_device *dev) |
135 | { | |
3b7b9e2e | 136 | u32 omr; |
04da0612 | 137 | |
3b7b9e2e | 138 | omr = dc2114x_inl(dev, DE4X5_OMR); |
04da0612 | 139 | omr |= OMR_ST | OMR_SR; |
3b7b9e2e | 140 | dc2114x_outl(dev, omr, DE4X5_OMR); /* Enable the TX and/or RX */ |
c609719b WD |
141 | } |
142 | ||
04da0612 MV |
143 | static void stop_de4x5(struct eth_device *dev) |
144 | { | |
3b7b9e2e | 145 | u32 omr; |
04da0612 | 146 | |
3b7b9e2e | 147 | omr = dc2114x_inl(dev, DE4X5_OMR); |
04da0612 | 148 | omr &= ~(OMR_ST | OMR_SR); |
3b7b9e2e | 149 | dc2114x_outl(dev, omr, DE4X5_OMR); /* Disable the TX and/or RX */ |
c609719b WD |
150 | } |
151 | ||
dbe9c0c1 MV |
152 | /* SROM Read and write routines. */ |
153 | static void sendto_srom(struct eth_device *dev, u_int command, u_long addr) | |
154 | { | |
155 | dc2114x_outl(dev, command, addr); | |
156 | udelay(1); | |
157 | } | |
c609719b | 158 | |
dbe9c0c1 MV |
159 | static int getfrom_srom(struct eth_device *dev, u_long addr) |
160 | { | |
161 | u32 tmp = dc2114x_inl(dev, addr); | |
c609719b | 162 | |
dbe9c0c1 MV |
163 | udelay(1); |
164 | return tmp; | |
165 | } | |
c609719b | 166 | |
dbe9c0c1 MV |
167 | /* Note: this routine returns extra data bits for size detection. */ |
168 | static int do_read_eeprom(struct eth_device *dev, u_long ioaddr, int location, | |
169 | int addr_len) | |
170 | { | |
171 | int read_cmd = location | (SROM_READ_CMD << addr_len); | |
172 | unsigned int retval = 0; | |
173 | int i; | |
eb216f1e | 174 | |
dbe9c0c1 MV |
175 | sendto_srom(dev, SROM_RD | SROM_SR, ioaddr); |
176 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); | |
eb216f1e | 177 | |
c2abfca9 | 178 | debug_cond(SROM_DLEVEL >= 1, " EEPROM read at %d ", location); |
c609719b | 179 | |
dbe9c0c1 MV |
180 | /* Shift the read command bits out. */ |
181 | for (i = 4 + addr_len; i >= 0; i--) { | |
182 | short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; | |
c609719b | 183 | |
dbe9c0c1 MV |
184 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | dataval, |
185 | ioaddr); | |
186 | udelay(10); | |
187 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | dataval | DT_CLK, | |
188 | ioaddr); | |
189 | udelay(10); | |
c2abfca9 MV |
190 | debug_cond(SROM_DLEVEL >= 2, "%X", |
191 | getfrom_srom(dev, ioaddr) & 15); | |
dbe9c0c1 MV |
192 | retval = (retval << 1) | |
193 | !!(getfrom_srom(dev, ioaddr) & EE_DATA_READ); | |
194 | } | |
c609719b | 195 | |
dbe9c0c1 | 196 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); |
ca5cb04b | 197 | |
c2abfca9 | 198 | debug_cond(SROM_DLEVEL >= 2, " :%X:", getfrom_srom(dev, ioaddr) & 15); |
c609719b | 199 | |
dbe9c0c1 MV |
200 | for (i = 16; i > 0; i--) { |
201 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | DT_CLK, ioaddr); | |
202 | udelay(10); | |
c2abfca9 MV |
203 | debug_cond(SROM_DLEVEL >= 2, "%X", |
204 | getfrom_srom(dev, ioaddr) & 15); | |
dbe9c0c1 MV |
205 | retval = (retval << 1) | |
206 | !!(getfrom_srom(dev, ioaddr) & EE_DATA_READ); | |
207 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); | |
208 | udelay(10); | |
209 | } | |
c609719b | 210 | |
dbe9c0c1 MV |
211 | /* Terminate the EEPROM access. */ |
212 | sendto_srom(dev, SROM_RD | SROM_SR, ioaddr); | |
c609719b | 213 | |
c2abfca9 MV |
214 | debug_cond(SROM_DLEVEL >= 2, " EEPROM value at %d is %5.5x.\n", |
215 | location, retval); | |
c609719b | 216 | |
dbe9c0c1 MV |
217 | return retval; |
218 | } | |
c609719b | 219 | |
dbe9c0c1 MV |
220 | /* |
221 | * This executes a generic EEPROM command, typically a write or write | |
222 | * enable. It returns the data output from the EEPROM, and thus may | |
223 | * also be used for reads. | |
224 | */ | |
225 | static int do_eeprom_cmd(struct eth_device *dev, u_long ioaddr, int cmd, | |
226 | int cmd_len) | |
227 | { | |
228 | unsigned int retval = 0; | |
c609719b | 229 | |
c2abfca9 | 230 | debug_cond(SROM_DLEVEL >= 1, " EEPROM op 0x%x: ", cmd); |
c609719b | 231 | |
dbe9c0c1 | 232 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS | DT_CLK, ioaddr); |
c609719b | 233 | |
dbe9c0c1 MV |
234 | /* Shift the command bits out. */ |
235 | do { | |
236 | short dataval = (cmd & BIT(cmd_len)) ? EE_WRITE_1 : EE_WRITE_0; | |
c609719b | 237 | |
dbe9c0c1 MV |
238 | sendto_srom(dev, dataval, ioaddr); |
239 | udelay(10); | |
ca5cb04b | 240 | |
c2abfca9 MV |
241 | debug_cond(SROM_DLEVEL >= 2, "%X", |
242 | getfrom_srom(dev, ioaddr) & 15); | |
be44f758 | 243 | |
dbe9c0c1 MV |
244 | sendto_srom(dev, dataval | DT_CLK, ioaddr); |
245 | udelay(10); | |
246 | retval = (retval << 1) | | |
247 | !!(getfrom_srom(dev, ioaddr) & EE_DATA_READ); | |
248 | } while (--cmd_len >= 0); | |
63f34912 | 249 | |
dbe9c0c1 | 250 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); |
c609719b | 251 | |
dbe9c0c1 MV |
252 | /* Terminate the EEPROM access. */ |
253 | sendto_srom(dev, SROM_RD | SROM_SR, ioaddr); | |
c609719b | 254 | |
c2abfca9 | 255 | debug_cond(SROM_DLEVEL >= 1, " EEPROM result is 0x%5.5x.\n", retval); |
c609719b | 256 | |
dbe9c0c1 MV |
257 | return retval; |
258 | } | |
171f5e58 | 259 | |
dbe9c0c1 MV |
260 | static int read_srom(struct eth_device *dev, u_long ioaddr, int index) |
261 | { | |
262 | int ee_addr_size; | |
c609719b | 263 | |
dbe9c0c1 | 264 | ee_addr_size = (do_read_eeprom(dev, ioaddr, 0xff, 8) & BIT(18)) ? 8 : 6; |
c609719b | 265 | |
dbe9c0c1 MV |
266 | return do_eeprom_cmd(dev, ioaddr, 0xffff | |
267 | (((SROM_READ_CMD << ee_addr_size) | index) << 16), | |
268 | 3 + ee_addr_size + 16); | |
c609719b WD |
269 | } |
270 | ||
dbe9c0c1 MV |
271 | #ifdef UPDATE_SROM |
272 | static int write_srom(struct eth_device *dev, u_long ioaddr, int index, | |
273 | int new_value) | |
c609719b | 274 | { |
dbe9c0c1 MV |
275 | unsigned short newval; |
276 | int ee_addr_size; | |
ca5cb04b | 277 | int i; |
c609719b | 278 | |
dbe9c0c1 | 279 | ee_addr_size = (do_read_eeprom(dev, ioaddr, 0xff, 8) & BIT(18)) ? 8 : 6; |
c609719b | 280 | |
dbe9c0c1 | 281 | udelay(10 * 1000); /* test-only */ |
c609719b | 282 | |
c2abfca9 MV |
283 | debug_cond(SROM_DLEVEL >= 1, "ee_addr_size=%d.\n", ee_addr_size); |
284 | debug_cond(SROM_DLEVEL >= 1, | |
285 | "Writing new entry 0x%4.4x to offset %d.\n", | |
286 | new_value, index); | |
c609719b | 287 | |
dbe9c0c1 MV |
288 | /* Enable programming modes. */ |
289 | do_eeprom_cmd(dev, ioaddr, 0x4f << (ee_addr_size - 4), | |
290 | 3 + ee_addr_size); | |
c609719b | 291 | |
dbe9c0c1 MV |
292 | /* Do the actual write. */ |
293 | do_eeprom_cmd(dev, ioaddr, new_value | | |
294 | (((SROM_WRITE_CMD << ee_addr_size) | index) << 16), | |
295 | 3 + ee_addr_size + 16); | |
296 | ||
297 | /* Poll for write finished. */ | |
298 | sendto_srom(dev, SROM_RD | SROM_SR | DT_CS, ioaddr); | |
299 | for (i = 0; i < 10000; i++) { /* Typical 2000 ticks */ | |
300 | if (getfrom_srom(dev, ioaddr) & EE_DATA_READ) | |
301 | break; | |
c609719b WD |
302 | } |
303 | ||
c2abfca9 | 304 | debug_cond(SROM_DLEVEL >= 1, " Write finished after %d ticks.\n", i); |
dbe9c0c1 MV |
305 | |
306 | /* Disable programming. */ | |
307 | do_eeprom_cmd(dev, ioaddr, (0x40 << (ee_addr_size - 4)), | |
308 | 3 + ee_addr_size); | |
309 | ||
310 | /* And read the result. */ | |
311 | newval = do_eeprom_cmd(dev, ioaddr, | |
312 | (((SROM_READ_CMD << ee_addr_size) | index) << 16) | |
313 | | 0xffff, 3 + ee_addr_size + 16); | |
c2abfca9 MV |
314 | |
315 | debug_cond(SROM_DLEVEL >= 1, " New value at offset %d is %4.4x.\n", | |
316 | index, newval); | |
dbe9c0c1 MV |
317 | |
318 | return 1; | |
319 | } | |
320 | ||
321 | static void update_srom(struct eth_device *dev, bd_t *bis) | |
322 | { | |
323 | static unsigned short eeprom[0x40] = { | |
324 | 0x140b, 0x6610, 0x0000, 0x0000, /* 00 */ | |
325 | 0x0000, 0x0000, 0x0000, 0x0000, /* 04 */ | |
326 | 0x00a3, 0x0103, 0x0000, 0x0000, /* 08 */ | |
327 | 0x0000, 0x1f00, 0x0000, 0x0000, /* 0c */ | |
328 | 0x0108, 0x038d, 0x0000, 0x0000, /* 10 */ | |
329 | 0xe078, 0x0001, 0x0040, 0x0018, /* 14 */ | |
330 | 0x0000, 0x0000, 0x0000, 0x0000, /* 18 */ | |
331 | 0x0000, 0x0000, 0x0000, 0x0000, /* 1c */ | |
332 | 0x0000, 0x0000, 0x0000, 0x0000, /* 20 */ | |
333 | 0x0000, 0x0000, 0x0000, 0x0000, /* 24 */ | |
334 | 0x0000, 0x0000, 0x0000, 0x0000, /* 28 */ | |
335 | 0x0000, 0x0000, 0x0000, 0x0000, /* 2c */ | |
336 | 0x0000, 0x0000, 0x0000, 0x0000, /* 30 */ | |
337 | 0x0000, 0x0000, 0x0000, 0x0000, /* 34 */ | |
338 | 0x0000, 0x0000, 0x0000, 0x0000, /* 38 */ | |
339 | 0x0000, 0x0000, 0x0000, 0x4e07, /* 3c */ | |
340 | }; | |
341 | uchar enetaddr[6]; | |
342 | int i; | |
343 | ||
344 | /* Ethernet Addr... */ | |
345 | if (!eth_env_get_enetaddr("ethaddr", enetaddr)) | |
346 | return; | |
347 | ||
348 | eeprom[0x0a] = (enetaddr[1] << 8) | enetaddr[0]; | |
349 | eeprom[0x0b] = (enetaddr[3] << 8) | enetaddr[2]; | |
350 | eeprom[0x0c] = (enetaddr[5] << 8) | enetaddr[4]; | |
351 | ||
352 | for (i = 0; i < 0x40; i++) | |
353 | write_srom(dev, DE4X5_APROM, i, eeprom[i]); | |
354 | } | |
355 | #endif /* UPDATE_SROM */ | |
356 | ||
357 | static void send_setup_frame(struct eth_device *dev, bd_t *bis) | |
358 | { | |
359 | char setup_frame[SETUP_FRAME_LEN]; | |
360 | char *pa = &setup_frame[0]; | |
361 | int i; | |
362 | ||
363 | memset(pa, 0xff, SETUP_FRAME_LEN); | |
364 | ||
365 | for (i = 0; i < ETH_ALEN; i++) { | |
366 | *(pa + (i & 1)) = dev->enetaddr[i]; | |
367 | if (i & 0x01) | |
368 | pa += 4; | |
c609719b WD |
369 | } |
370 | ||
dbe9c0c1 MV |
371 | for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) { |
372 | if (i < TOUT_LOOP) | |
373 | continue; | |
c609719b | 374 | |
dbe9c0c1 MV |
375 | printf("%s: tx error buffer not ready\n", dev->name); |
376 | return; | |
377 | } | |
c609719b | 378 | |
dbe9c0c1 MV |
379 | tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus((u32)&setup_frame[0])); |
380 | tx_ring[tx_new].des1 = cpu_to_le32(TD_TER | TD_SET | SETUP_FRAME_LEN); | |
381 | tx_ring[tx_new].status = cpu_to_le32(T_OWN); | |
c609719b | 382 | |
dbe9c0c1 | 383 | dc2114x_outl(dev, POLL_DEMAND, DE4X5_TPD); |
c609719b | 384 | |
dbe9c0c1 MV |
385 | for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) { |
386 | if (i < TOUT_LOOP) | |
387 | continue; | |
c609719b | 388 | |
dbe9c0c1 MV |
389 | printf("%s: tx buffer not ready\n", dev->name); |
390 | return; | |
391 | } | |
c609719b | 392 | |
dbe9c0c1 MV |
393 | if (le32_to_cpu(tx_ring[tx_new].status) != 0x7FFFFFFF) { |
394 | printf("TX error status2 = 0x%08X\n", | |
395 | le32_to_cpu(tx_ring[tx_new].status)); | |
396 | } | |
397 | ||
398 | tx_new = (tx_new + 1) % NUM_TX_DESC; | |
c609719b WD |
399 | } |
400 | ||
6636c701 | 401 | static int dc21x4x_send(struct eth_device *dev, void *packet, int length) |
c609719b | 402 | { |
7c53e336 MV |
403 | int status = -1; |
404 | int i; | |
c609719b WD |
405 | |
406 | if (length <= 0) { | |
407 | printf("%s: bad packet size: %d\n", dev->name, length); | |
7c53e336 | 408 | goto done; |
c609719b WD |
409 | } |
410 | ||
7c53e336 MV |
411 | for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) { |
412 | if (i < TOUT_LOOP) | |
413 | continue; | |
414 | ||
415 | printf("%s: tx error buffer not ready\n", dev->name); | |
416 | goto done; | |
c609719b WD |
417 | } |
418 | ||
7c53e336 MV |
419 | tx_ring[tx_new].buf = cpu_to_le32(phys_to_bus((u32)packet)); |
420 | tx_ring[tx_new].des1 = cpu_to_le32(TD_TER | TD_LS | TD_FS | length); | |
c609719b WD |
421 | tx_ring[tx_new].status = cpu_to_le32(T_OWN); |
422 | ||
3b7b9e2e | 423 | dc2114x_outl(dev, POLL_DEMAND, DE4X5_TPD); |
c609719b | 424 | |
7c53e336 MV |
425 | for (i = 0; tx_ring[tx_new].status & cpu_to_le32(T_OWN); i++) { |
426 | if (i < TOUT_LOOP) | |
427 | continue; | |
428 | ||
429 | printf(".%s: tx buffer not ready\n", dev->name); | |
430 | goto done; | |
c609719b WD |
431 | } |
432 | ||
433 | if (le32_to_cpu(tx_ring[tx_new].status) & TD_ES) { | |
63f34912 | 434 | tx_ring[tx_new].status = 0x0; |
7c53e336 | 435 | goto done; |
c609719b WD |
436 | } |
437 | ||
438 | status = length; | |
439 | ||
7c53e336 MV |
440 | done: |
441 | tx_new = (tx_new + 1) % NUM_TX_DESC; | |
c609719b WD |
442 | return status; |
443 | } | |
444 | ||
9308df81 | 445 | static int dc21x4x_recv(struct eth_device *dev) |
c609719b | 446 | { |
9308df81 MV |
447 | int length = 0; |
448 | u32 status; | |
c609719b | 449 | |
9308df81 MV |
450 | while (true) { |
451 | status = le32_to_cpu(rx_ring[rx_new].status); | |
c609719b | 452 | |
9308df81 | 453 | if (status & R_OWN) |
c609719b | 454 | break; |
c609719b WD |
455 | |
456 | if (status & RD_LS) { | |
9308df81 | 457 | /* Valid frame status. */ |
c609719b | 458 | if (status & RD_ES) { |
9308df81 | 459 | /* There was an error. */ |
c609719b WD |
460 | printf("RX error status = 0x%08X\n", status); |
461 | } else { | |
9308df81 MV |
462 | /* A valid frame received. */ |
463 | length = (le32_to_cpu(rx_ring[rx_new].status) | |
464 | >> 16); | |
465 | ||
466 | /* Pass the packet up to the protocol layers */ | |
467 | net_process_received_packet | |
468 | (net_rx_packets[rx_new], length - 4); | |
c609719b WD |
469 | } |
470 | ||
9308df81 MV |
471 | /* |
472 | * Change buffer ownership for this frame, | |
473 | * back to the adapter. | |
c609719b WD |
474 | */ |
475 | rx_ring[rx_new].status = cpu_to_le32(R_OWN); | |
476 | } | |
477 | ||
9308df81 | 478 | /* Update entry information. */ |
eb216f1e | 479 | rx_new = (rx_new + 1) % rx_ring_size; |
c609719b WD |
480 | } |
481 | ||
482 | return length; | |
483 | } | |
484 | ||
dbe9c0c1 | 485 | static int dc21x4x_init(struct eth_device *dev, bd_t *bis) |
c609719b | 486 | { |
dbe9c0c1 | 487 | int i; |
5b4e7dfb | 488 | int devbusfn = (int)dev->priv; |
c609719b | 489 | |
dbe9c0c1 MV |
490 | /* Ensure we're not sleeping. */ |
491 | pci_write_config_byte(devbusfn, PCI_CFDA_PSM, WAKEUP); | |
c609719b | 492 | |
dbe9c0c1 | 493 | reset_de4x5(dev); |
c609719b | 494 | |
dbe9c0c1 MV |
495 | if (dc2114x_inl(dev, DE4X5_STS) & (STS_TS | STS_RS)) { |
496 | printf("Error: Cannot reset ethernet controller.\n"); | |
497 | return -1; | |
498 | } | |
c609719b | 499 | |
dbe9c0c1 | 500 | dc2114x_outl(dev, OMR_SDP | OMR_PS | OMR_PM, DE4X5_OMR); |
c609719b | 501 | |
dbe9c0c1 MV |
502 | for (i = 0; i < NUM_RX_DESC; i++) { |
503 | rx_ring[i].status = cpu_to_le32(R_OWN); | |
504 | rx_ring[i].des1 = cpu_to_le32(RX_BUFF_SZ); | |
505 | rx_ring[i].buf = | |
506 | cpu_to_le32(phys_to_bus((u32)net_rx_packets[i])); | |
507 | rx_ring[i].next = 0; | |
c609719b WD |
508 | } |
509 | ||
dbe9c0c1 MV |
510 | for (i = 0; i < NUM_TX_DESC; i++) { |
511 | tx_ring[i].status = 0; | |
512 | tx_ring[i].des1 = 0; | |
513 | tx_ring[i].buf = 0; | |
514 | tx_ring[i].next = 0; | |
c609719b WD |
515 | } |
516 | ||
dbe9c0c1 MV |
517 | rx_ring_size = NUM_RX_DESC; |
518 | tx_ring_size = NUM_TX_DESC; | |
c609719b | 519 | |
dbe9c0c1 MV |
520 | /* Write the end of list marker to the descriptor lists. */ |
521 | rx_ring[rx_ring_size - 1].des1 |= cpu_to_le32(RD_RER); | |
522 | tx_ring[tx_ring_size - 1].des1 |= cpu_to_le32(TD_TER); | |
c609719b | 523 | |
dbe9c0c1 MV |
524 | /* Tell the adapter where the TX/RX rings are located. */ |
525 | dc2114x_outl(dev, phys_to_bus((u32)&rx_ring), DE4X5_RRBA); | |
526 | dc2114x_outl(dev, phys_to_bus((u32)&tx_ring), DE4X5_TRBA); | |
5a0c332a | 527 | |
dbe9c0c1 | 528 | start_de4x5(dev); |
c609719b | 529 | |
dbe9c0c1 MV |
530 | tx_new = 0; |
531 | rx_new = 0; | |
63f34912 | 532 | |
dbe9c0c1 | 533 | send_setup_frame(dev, bis); |
c609719b | 534 | |
dbe9c0c1 | 535 | return 0; |
c609719b WD |
536 | } |
537 | ||
dbe9c0c1 | 538 | static void dc21x4x_halt(struct eth_device *dev) |
c609719b | 539 | { |
dbe9c0c1 | 540 | int devbusfn = (int)dev->priv; |
c609719b | 541 | |
dbe9c0c1 MV |
542 | stop_de4x5(dev); |
543 | dc2114x_outl(dev, 0, DE4X5_SICR); | |
544 | ||
545 | pci_write_config_byte(devbusfn, PCI_CFDA_PSM, SLEEP); | |
c609719b WD |
546 | } |
547 | ||
dbe9c0c1 | 548 | static void read_hw_addr(struct eth_device *dev, bd_t *bis) |
c609719b | 549 | { |
dbe9c0c1 MV |
550 | u_short tmp, *p = (u_short *)(&dev->enetaddr[0]); |
551 | int i, j = 0; | |
2e5c2a10 | 552 | |
dbe9c0c1 MV |
553 | for (i = 0; i < (ETH_ALEN >> 1); i++) { |
554 | tmp = read_srom(dev, DE4X5_APROM, (SROM_HWADD >> 1) + i); | |
555 | *p = le16_to_cpu(tmp); | |
556 | j += *p++; | |
c609719b WD |
557 | } |
558 | ||
dbe9c0c1 MV |
559 | if (!j || j == 0x2fffd) { |
560 | memset(dev->enetaddr, 0, ETH_ALEN); | |
561 | debug("Warning: can't read HW address from SROM.\n"); | |
562 | #ifdef UPDATE_SROM | |
563 | update_srom(dev, bis); | |
c609719b | 564 | #endif |
c609719b | 565 | } |
c609719b WD |
566 | } |
567 | ||
dbe9c0c1 MV |
568 | static struct pci_device_id supported[] = { |
569 | { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TULIP_FAST }, | |
570 | { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21142 }, | |
571 | { } | |
572 | }; | |
c609719b | 573 | |
dbe9c0c1 | 574 | int dc21x4x_initialize(bd_t *bis) |
c609719b | 575 | { |
dbe9c0c1 MV |
576 | struct eth_device *dev; |
577 | unsigned short status; | |
578 | unsigned char timer; | |
579 | unsigned int iobase; | |
580 | int card_number = 0; | |
581 | pci_dev_t devbusfn; | |
582 | unsigned int cfrv; | |
583 | int idx = 0; | |
2e5c2a10 | 584 | |
dbe9c0c1 MV |
585 | while (1) { |
586 | devbusfn = pci_find_devices(supported, idx++); | |
587 | if (devbusfn == -1) | |
588 | break; | |
c609719b | 589 | |
dbe9c0c1 MV |
590 | /* Get the chip configuration revision register. */ |
591 | pci_read_config_dword(devbusfn, PCI_REVISION_ID, &cfrv); | |
c609719b | 592 | |
dbe9c0c1 MV |
593 | if ((cfrv & CFRV_RN) < DC2114x_BRK) { |
594 | printf("Error: The chip is not DC21143.\n"); | |
595 | continue; | |
596 | } | |
2e5c2a10 | 597 | |
dbe9c0c1 MV |
598 | pci_read_config_word(devbusfn, PCI_COMMAND, &status); |
599 | status |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; | |
600 | pci_write_config_word(devbusfn, PCI_COMMAND, status); | |
c609719b | 601 | |
dbe9c0c1 MV |
602 | pci_read_config_word(devbusfn, PCI_COMMAND, &status); |
603 | if (!(status & PCI_COMMAND_MEMORY)) { | |
604 | printf("Error: Can not enable MEMORY access.\n"); | |
605 | continue; | |
606 | } | |
c609719b | 607 | |
dbe9c0c1 MV |
608 | if (!(status & PCI_COMMAND_MASTER)) { |
609 | printf("Error: Can not enable Bus Mastering.\n"); | |
610 | continue; | |
611 | } | |
c609719b | 612 | |
dbe9c0c1 MV |
613 | /* Check the latency timer for values >= 0x60. */ |
614 | pci_read_config_byte(devbusfn, PCI_LATENCY_TIMER, &timer); | |
c609719b | 615 | |
dbe9c0c1 MV |
616 | if (timer < 0x60) { |
617 | pci_write_config_byte(devbusfn, PCI_LATENCY_TIMER, | |
618 | 0x60); | |
619 | } | |
c609719b | 620 | |
dbe9c0c1 MV |
621 | /* read BAR for memory space access */ |
622 | pci_read_config_dword(devbusfn, PCI_BASE_ADDRESS_1, &iobase); | |
623 | iobase &= PCI_BASE_ADDRESS_MEM_MASK; | |
624 | debug("dc21x4x: DEC 21142 PCI Device @0x%x\n", iobase); | |
c609719b | 625 | |
dbe9c0c1 MV |
626 | dev = (struct eth_device *)malloc(sizeof(*dev)); |
627 | if (!dev) { | |
628 | printf("Can not allocalte memory of dc21x4x\n"); | |
629 | break; | |
630 | } | |
c609719b | 631 | |
dbe9c0c1 | 632 | memset(dev, 0, sizeof(*dev)); |
2e5c2a10 | 633 | |
dbe9c0c1 | 634 | sprintf(dev->name, "dc21x4x#%d", card_number); |
c609719b | 635 | |
dbe9c0c1 MV |
636 | dev->iobase = pci_mem_to_phys(devbusfn, iobase); |
637 | dev->priv = (void *)devbusfn; | |
638 | dev->init = dc21x4x_init; | |
639 | dev->halt = dc21x4x_halt; | |
640 | dev->send = dc21x4x_send; | |
641 | dev->recv = dc21x4x_recv; | |
c609719b | 642 | |
dbe9c0c1 MV |
643 | /* Ensure we're not sleeping. */ |
644 | pci_write_config_byte(devbusfn, PCI_CFDA_PSM, WAKEUP); | |
c609719b | 645 | |
dbe9c0c1 | 646 | udelay(10 * 1000); |
c609719b | 647 | |
dbe9c0c1 | 648 | read_hw_addr(dev, bis); |
c609719b | 649 | |
dbe9c0c1 | 650 | eth_register(dev); |
2e5c2a10 | 651 | |
dbe9c0c1 MV |
652 | card_number++; |
653 | } | |
c609719b | 654 | |
dbe9c0c1 | 655 | return card_number; |
c609719b | 656 | } |