1 /**************************************************************************
2 Etherboot - BOOTP/TFTP Bootstrap Program
3 Intel EEPRO/10 NIC driver for Etherboot
4 Adapted from Linux eepro.c from kernel 2.2.17
6 This board accepts a 32 pin EEPROM (29C256), however a test with a
7 27C010 shows that this EPROM also works in the socket, but it's not clear
8 how repeatably. The two top address pins appear to be held low, thus
9 the bottom 32kB of the 27C010 is visible in the CPU's address space.
10 To be sure you could put 4 copies of the code in the 27C010, then
11 it doesn't matter whether the extra lines are held low or high, just
12 hopefully not floating as CMOS chips don't like floating inputs.
14 Be careful with seating the EPROM as the socket on my board actually
15 has 34 pins, the top row of 2 are not used.
16 ***************************************************************************/
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License as
21 * published by the Free Software Foundation; either version 2, or (at
22 * your option) any later version.
25 /* to get some global routines like printf */
26 #include "etherboot.h"
27 /* to get the interface to the body of the program */
29 /* to get our own prototype */
31 /* we use timer2 for microsecond waits */
34 #undef DEBUG /* only after include files */
36 /* Different 82595 chips */
40 #define LAN595FX_10ISA 3
42 #define SLOW_DOWN inb(0x80);
44 /* The station (ethernet) address prefix, used for IDing the board. */
45 #define SA_ADDR0 0x00 /* Etherexpress Pro/10 */
49 #define GetBit(x,y) ((x & (1<<y))>>y)
52 #define ee_PnP 0 /* Plug 'n Play enable bit */
53 #define ee_Word1 1 /* Word 1? */
54 #define ee_BusWidth 2 /* 8/16 bit */
55 #define ee_FlashAddr 3 /* Flash Address */
56 #define ee_FlashMask 0x7 /* Mask */
57 #define ee_AutoIO 6 /* */
58 #define ee_reserved0 7 /* =0! */
59 #define ee_Flash 8 /* Flash there? */
60 #define ee_AutoNeg 9 /* Auto Negotiation enabled? */
61 #define ee_IO0 10 /* IO Address LSB */
62 #define ee_IO0Mask 0x /*...*/
63 #define ee_IO1 15 /* IO MSB */
66 #define ee_IntSel 0 /* Interrupt */
67 #define ee_IntMask 0x7
68 #define ee_LI 3 /* Link Integrity 0= enabled */
69 #define ee_PC 4 /* Polarity Correction 0= enabled */
70 #define ee_TPE_AUI 5 /* PortSelection 1=TPE */
71 #define ee_Jabber 6 /* Jabber prevention 0= enabled */
72 #define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */
73 #define ee_SMOUT 8 /* SMout Pin Control 0= Input */
74 #define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */
75 #define ee_reserved1 10 /* .. 12 =0! */
76 #define ee_AltReady 13 /* Alternate Ready, 0=normal */
77 #define ee_reserved2 14 /* =0! */
81 #define ee_IA5 0 /*bit start for individual Addr Byte 5 */
82 #define ee_IA4 8 /*bit start for individual Addr Byte 5 */
83 #define ee_IA3 0 /*bit start for individual Addr Byte 5 */
84 #define ee_IA2 8 /*bit start for individual Addr Byte 5 */
85 #define ee_IA1 0 /*bit start for individual Addr Byte 5 */
86 #define ee_IA0 8 /*bit start for individual Addr Byte 5 */
89 #define ee_BNC_TPE 0 /* 0=TPE */
90 #define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */
91 #define ee_BootTypeMask 0x3
92 #define ee_NumConn 3 /* Number of Connections 0= One or Two */
93 #define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */
97 #define ee_PowerMgt 10 /* 0= disabled */
98 #define ee_CP 13 /* Concurrent Processing */
102 #define ee_Stepping 0 /* Stepping info */
103 #define ee_StepMask 0x0F
104 #define ee_BoardID 4 /* Manucaturer Board ID, reserved */
105 #define ee_BoardMask 0x0FFF
108 #define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */
109 #define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips */
112 #define ee_SIZE 0x40 /* total EEprom Size */
113 #define ee_Checksum 0xBABA /* initial and final value for adding checksum */
116 /* Card identification via EEprom: */
117 #define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */
118 #define ee_addr_id 0x11 /* Word offset for Card ID */
119 #define ee_addr_SN 0x12 /* Serial Number */
120 #define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */
123 #define ee_vendor_intel0 0x25 /* Vendor ID Intel */
124 #define ee_vendor_intel1 0xD4
125 #define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */
126 #define ee_id_eepro10p1 0x31
128 /* now this section could be used by both boards: the oldies and the ee10:
129 * ee10 uses tx buffer before of rx buffer and the oldies the inverse.
132 #define RAM_SIZE 0x8000
135 #define RCV_DEFAULT_RAM 0x6000
136 #define RCV_RAM rcv_ram
138 static unsigned rcv_ram
= RCV_DEFAULT_RAM
;
141 #define XMT_RAM (RAM_SIZE - RCV_RAM)
143 #define XMT_START ((rcv_start + RCV_RAM) % RAM_SIZE)
145 #define RCV_LOWER_LIMIT (rcv_start >> 8)
146 #define RCV_UPPER_LIMIT (((rcv_start + RCV_RAM) - 2) >> 8)
147 #define XMT_LOWER_LIMIT (XMT_START >> 8)
148 #define XMT_UPPER_LIMIT (((XMT_START + XMT_RAM) - 2) >> 8)
150 #define RCV_START_PRO 0x00
151 #define RCV_START_10 XMT_RAM
152 /* by default the old driver */
153 static unsigned rcv_start
= RCV_START_PRO
;
155 #define RCV_DONE 0x0008
157 #define RX_ERROR 0x0d81
159 #define TX_DONE_BIT 0x0080
160 #define CHAIN_BIT 0x8000
161 #define XMT_STATUS 0x02
162 #define XMT_CHAIN 0x04
163 #define XMT_COUNT 0x06
165 #define BANK0_SELECT 0x00
166 #define BANK1_SELECT 0x40
167 #define BANK2_SELECT 0x80
169 /* Bank 0 registers */
170 #define COMMAND_REG 0x00 /* Register 0 */
171 #define MC_SETUP 0x03
173 #define DIAGNOSE_CMD 0x07
174 #define RCV_ENABLE_CMD 0x08
175 #define RCV_DISABLE_CMD 0x0a
176 #define STOP_RCV_CMD 0x0b
177 #define RESET_CMD 0x0e
178 #define POWER_DOWN_CMD 0x18
179 #define RESUME_XMT_CMD 0x1c
180 #define SEL_RESET_CMD 0x1e
181 #define STATUS_REG 0x01 /* Register 1 */
184 #define EXEC_STATUS 0x30
185 #define ID_REG 0x02 /* Register 2 */
186 #define R_ROBIN_BITS 0xc0 /* round robin counter */
187 #define ID_REG_MASK 0x2c
188 #define ID_REG_SIG 0x24
189 #define AUTO_ENABLE 0x10
190 #define INT_MASK_REG 0x03 /* Register 3 */
191 #define RX_STOP_MASK 0x01
194 #define EXEC_MASK 0x08
195 #define ALL_MASK 0x0f
196 #define IO_32_BIT 0x10
197 #define RCV_BAR 0x04 /* The following are word (16-bit) registers */
198 #define RCV_STOP 0x06
200 #define XMT_BAR_PRO 0x0a
201 #define XMT_BAR_10 0x0b
202 static unsigned xmt_bar
= XMT_BAR_PRO
;
204 #define HOST_ADDRESS_REG 0x0c
206 #define IO_PORT_32_BIT 0x0c
208 /* Bank 1 registers */
210 #define WORD_WIDTH 0x02
211 #define INT_ENABLE 0x80
212 #define INT_NO_REG 0x02
213 #define RCV_LOWER_LIMIT_REG 0x08
214 #define RCV_UPPER_LIMIT_REG 0x09
216 #define XMT_LOWER_LIMIT_REG_PRO 0x0a
217 #define XMT_UPPER_LIMIT_REG_PRO 0x0b
218 #define XMT_LOWER_LIMIT_REG_10 0x0b
219 #define XMT_UPPER_LIMIT_REG_10 0x0a
220 static unsigned xmt_lower_limit_reg
= XMT_LOWER_LIMIT_REG_PRO
;
221 static unsigned xmt_upper_limit_reg
= XMT_UPPER_LIMIT_REG_PRO
;
223 /* Bank 2 registers */
224 #define XMT_Chain_Int 0x20 /* Interrupt at the end of the transmit chain */
225 #define XMT_Chain_ErrStop 0x40 /* Interrupt at the end of the chain even if there are errors */
226 #define RCV_Discard_BadFrame 0x80 /* Throw bad frames away, and continue to receive others */
228 #define PRMSC_Mode 0x01
229 #define Multi_IA 0x20
235 #define A_N_ENABLE 0x02
237 #define I_ADD_REG0 0x04
238 #define I_ADD_REG1 0x05
239 #define I_ADD_REG2 0x06
240 #define I_ADD_REG3 0x07
241 #define I_ADD_REG4 0x08
242 #define I_ADD_REG5 0x09
244 #define EEPROM_REG_PRO 0x0a
245 #define EEPROM_REG_10 0x0b
246 static unsigned eeprom_reg
= EEPROM_REG_PRO
;
253 /* The horrible routine to read a word from the serial EEPROM. */
254 /* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
256 /* The delay between EEPROM clock transitions. */
257 #define eeprom_delay() { udelay(40); }
258 #define EE_READ_CMD (6 << 6)
260 /* do a full reset */
261 #define eepro_full_reset(ioaddr) outb(RESET_CMD, ioaddr); udelay(40);
263 /* do a nice reset */
264 #define eepro_sel_reset(ioaddr) { \
265 outb(SEL_RESET_CMD, ioaddr); \
270 /* clear all interrupts */
271 #define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
274 #define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
277 #define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
280 #define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
281 #define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
282 #define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
284 static unsigned int rx_start
, tx_start
;
286 static unsigned tx_end
;
287 static int eepro
= 0;
288 static unsigned short ioaddr
= 0;
289 static unsigned int mem_start
, mem_end
= RCV_DEFAULT_RAM
/ 1024;
291 #define udelay(n) waiton_timer2(((n)*TICKS_PER_MS)/1000)
293 /**************************************************************************
294 RESET - Reset adapter
295 ***************************************************************************/
296 static void eepro_reset(struct nic
*nic
)
300 /* put the card in its initial state */
301 eepro_sw2bank2(ioaddr
); /* be careful, bank2 now */
302 temp_reg
= inb(ioaddr
+ eeprom_reg
);
304 printf("Stepping %d\n", temp_reg
>> 5);
306 if (temp_reg
& 0x10) /* check the TurnOff Enable bit */
307 outb(temp_reg
& 0xEF, ioaddr
+ eeprom_reg
);
308 for (i
= 0; i
< ETH_ALEN
; i
++) /* fill the MAC address */
309 outb(nic
->node_addr
[i
], ioaddr
+ I_ADD_REG0
+ i
);
310 temp_reg
= inb(ioaddr
+ REG1
);
311 /* setup Transmit Chaining and discard bad RCV frames */
312 outb(temp_reg
| XMT_Chain_Int
| XMT_Chain_ErrStop
313 | RCV_Discard_BadFrame
, ioaddr
+ REG1
);
314 temp_reg
= inb(ioaddr
+ REG2
); /* match broadcast */
315 outb(temp_reg
| 0x14, ioaddr
+ REG2
);
316 temp_reg
= inb(ioaddr
+ REG3
);
317 outb(temp_reg
& 0x3F, ioaddr
+ REG3
); /* clear test mode */
318 /* set the receiving mode */
319 eepro_sw2bank1(ioaddr
); /* be careful, bank1 now */
320 /* initialise the RCV and XMT upper and lower limits */
321 outb(RCV_LOWER_LIMIT
, ioaddr
+ RCV_LOWER_LIMIT_REG
);
322 outb(RCV_UPPER_LIMIT
, ioaddr
+ RCV_UPPER_LIMIT_REG
);
323 outb(XMT_LOWER_LIMIT
, ioaddr
+ xmt_lower_limit_reg
);
324 outb(XMT_UPPER_LIMIT
, ioaddr
+ xmt_upper_limit_reg
);
325 eepro_sw2bank0(ioaddr
); /* Switch back to bank 0 */
326 eepro_clear_int(ioaddr
);
328 outw(rx_start
= (RCV_LOWER_LIMIT
<< 8), ioaddr
+ RCV_BAR
);
329 outw(((RCV_UPPER_LIMIT
<< 8) | 0xFE), ioaddr
+ RCV_STOP
);
331 outw((XMT_LOWER_LIMIT
<< 8), ioaddr
+ xmt_bar
);
332 eepro_sel_reset(ioaddr
);
333 tx_start
= tx_end
= (XMT_LOWER_LIMIT
<< 8);
338 /**************************************************************************
339 POLL - Wait for a frame
340 ***************************************************************************/
341 static int eepro_poll(struct nic
*nic
)
344 unsigned int rcv_car
= rx_start
;
345 unsigned int rcv_event
, rcv_status
, rcv_next_frame
, rcv_size
;
347 /* return true if there's an ethernet packet ready to read */
348 /* nic->packet should contain data on return */
349 /* nic->packetlen should contain length of data */
351 if ((inb(ioaddr
+ STATUS_REG
) & 0x40) == 0)
353 outb(0x40, ioaddr
+ STATUS_REG
);
355 outw(rcv_car
, ioaddr
+ HOST_ADDRESS_REG
);
356 rcv_event
= inw(ioaddr
+ IO_PORT
);
357 if (rcv_event
!= RCV_DONE
)
359 rcv_status
= inw(ioaddr
+ IO_PORT
);
360 rcv_next_frame
= inw(ioaddr
+ IO_PORT
);
361 rcv_size
= inw(ioaddr
+ IO_PORT
);
363 printf("%hX %hX %d %hhX\n", rcv_status
, rcv_next_frame
, rcv_size
,
364 inb(ioaddr
+ STATUS_REG
));
366 if ((rcv_status
& (RX_OK
|RX_ERROR
)) != RX_OK
) {
367 printf("Receive error %hX\n", rcv_status
);
371 insw(ioaddr
+ IO_PORT
, nic
->packet
, ((rcv_size
+ 3) >> 1));
373 for (i
= 0; i
< 48; i
++) {
374 printf("%hhX", nic
->packet
[i
]);
375 putchar(i
% 16 == 15 ? '\n' : ' ');
378 nic
->packetlen
= rcv_size
;
379 rcv_car
= rx_start
+ RCV_HEADER
+ rcv_size
;
380 rx_start
= rcv_next_frame
;
382 rcv_car
= ((RCV_UPPER_LIMIT
<< 8) | 0xff);
383 outw(rcv_car
- 1, ioaddr
+ RCV_STOP
);
387 /**************************************************************************
388 TRANSMIT - Transmit a frame
389 ***************************************************************************/
390 static void eepro_transmit(
392 const char *d
, /* Destination */
393 unsigned int t
, /* Type */
394 unsigned int s
, /* size */
395 const char *p
) /* Packet */
397 unsigned int status
, tx_available
, last
, end
, length
;
401 length
= s
+ ETH_HLEN
;
402 if (tx_end
> tx_start
)
403 tx_available
= XMT_RAM
- (tx_end
- tx_start
);
404 else if (tx_end
< tx_start
)
405 tx_available
= tx_start
- tx_end
;
407 tx_available
= XMT_RAM
;
409 end
= last
+ (((length
+ 3) >> 1) << 1) + XMT_HEADER
;
410 if (end
>= (XMT_UPPER_LIMIT
<< 8)) {
411 last
= (XMT_LOWER_LIMIT
<< 8);
412 end
= last
+ (((length
+ 3) >> 1) << 1) + XMT_HEADER
;
414 outw(last
, ioaddr
+ HOST_ADDRESS_REG
);
415 outw(XMT_CMD
, ioaddr
+ IO_PORT
);
416 outw(0, ioaddr
+ IO_PORT
);
417 outw(end
, ioaddr
+ IO_PORT
);
418 outw(length
, ioaddr
+ IO_PORT
);
419 outsw(ioaddr
+ IO_PORT
, d
, ETH_ALEN
/ 2);
420 outsw(ioaddr
+ IO_PORT
, nic
->node_addr
, ETH_ALEN
/ 2);
422 outsw(ioaddr
+ IO_PORT
, &type
, sizeof(type
) / 2);
423 outsw(ioaddr
+ IO_PORT
, p
, (s
+ 3) >> 1);
424 /* A dummy read to flush the DRAM write pipeline */
425 status
= inw(ioaddr
+ IO_PORT
);
426 outw(last
, ioaddr
+ xmt_bar
);
427 outb(XMT_CMD
, ioaddr
);
432 printf("%d %d\n", tx_start
, tx_end
);
434 while (boguscount
> 0) {
435 if (((status
= inw(ioaddr
+ IO_PORT
)) & TX_DONE_BIT
) == 0) {
441 if ((status
& 0x2000) == 0)
442 printf("Transmit status %hX\n", status
);
447 /**************************************************************************
448 DISABLE - Turn off ethernet interface
449 ***************************************************************************/
450 static void eepro_disable(struct nic
*nic
)
452 eepro_sw2bank0(ioaddr
); /* Switch to bank 0 */
453 /* Flush the Tx and disable Rx */
454 outb(STOP_RCV_CMD
, ioaddr
);
455 tx_start
= tx_end
= (XMT_LOWER_LIMIT
<< 8);
457 /* Reset the 82595 */
458 eepro_full_reset(ioaddr
);
461 static int read_eeprom(int location
)
464 unsigned short retval
= 0;
465 int ee_addr
= ioaddr
+ eeprom_reg
;
466 int read_cmd
= location
| EE_READ_CMD
;
469 if (eepro
== LAN595FX_10ISA
) {
470 eepro_sw2bank1(ioaddr
);
471 outb(0x00, ioaddr
+ STATUS_REG
);
473 eepro_sw2bank2(ioaddr
);
474 outb(ctrl_val
, ee_addr
);
475 /* shift the read command bits out */
476 for (i
= 8; i
>= 0; i
--) {
477 short outval
= (read_cmd
& (1 << i
)) ? ctrl_val
| EEDI
: ctrl_val
;
478 outb(outval
, ee_addr
);
479 outb(outval
| EESK
, ee_addr
); /* EEPROM clock tick */
481 outb(outval
, ee_addr
); /* finish EEPROM clock tick */
484 outb(ctrl_val
, ee_addr
);
485 for (i
= 16; i
> 0; i
--) {
486 outb(ctrl_val
| EESK
, ee_addr
);
488 retval
= (retval
<< 1) | ((inb(ee_addr
) & EEDO
) ? 1 : 0);
489 outb(ctrl_val
, ee_addr
);
492 /* terminate the EEPROM access */
494 outb(ctrl_val
| EESK
, ee_addr
);
496 outb(ctrl_val
, ee_addr
);
498 eepro_sw2bank0(ioaddr
);
502 static int eepro_probe1(struct nic
*nic
)
504 int i
, id
, counter
, l_eepro
= 0;
506 unsigned char caddr
[ETH_ALEN
];
507 unsigned short saddr
[ETH_ALEN
/2];
511 id
= inb(ioaddr
+ ID_REG
);
512 if ((id
& ID_REG_MASK
) != ID_REG_SIG
)
514 counter
= id
& R_ROBIN_BITS
;
515 if (((id
= inb(ioaddr
+ ID_REG
)) & R_ROBIN_BITS
) != (counter
+ 0x40))
517 /* yes the 82595 has been found */
518 station_addr
.saddr
[2] = read_eeprom(2);
519 if (station_addr
.saddr
[2] == 0x0000 || station_addr
.saddr
[2] == 0xFFFF) {
521 eepro
= LAN595FX_10ISA
;
522 eeprom_reg
= EEPROM_REG_10
;
523 rcv_start
= RCV_START_10
;
524 xmt_lower_limit_reg
= XMT_LOWER_LIMIT_REG_10
;
525 xmt_upper_limit_reg
= XMT_UPPER_LIMIT_REG_10
;
526 station_addr
.saddr
[2] = read_eeprom(2);
528 station_addr
.saddr
[1] = read_eeprom(3);
529 station_addr
.saddr
[0] = read_eeprom(4);
531 name
= "Intel EtherExpress 10 ISA";
532 else if (read_eeprom(7) == ee_FX_INT2IRQ
) {
533 name
= "Intel EtherExpress Pro/10+ ISA";
535 } else if (station_addr
.saddr
[0] == SA_ADDR1
) {
536 name
= "Intel EtherExpress Pro/10 ISA";
540 name
= "Intel 82595-based LAN card";
542 station_addr
.saddr
[0] = swap16(station_addr
.saddr
[0]);
543 station_addr
.saddr
[1] = swap16(station_addr
.saddr
[1]);
544 station_addr
.saddr
[2] = swap16(station_addr
.saddr
[2]);
545 for (i
= 0; i
< ETH_ALEN
; i
++) {
546 nic
->node_addr
[i
] = station_addr
.caddr
[i
];
548 printf("\n%s ioaddr %#hX, addr %!", name
, ioaddr
, nic
->node_addr
);
549 mem_start
= RCV_LOWER_LIMIT
<< 8;
550 if ((mem_end
& 0x3F) < 3 || (mem_end
& 0x3F) > 29)
551 mem_end
= RCV_UPPER_LIMIT
<< 8;
553 mem_end
= mem_end
* 1024 + (RCV_LOWER_LIMIT
<< 8);
554 rcv_ram
= mem_end
- (RCV_LOWER_LIMIT
<< 8);
556 printf(", Rx mem %dK, if %s\n", (mem_end
- mem_start
) >> 10,
557 GetBit(read_eeprom(5), ee_BNC_TPE
) ? "BNC" : "TP");
561 /**************************************************************************
562 PROBE - Look for an adapter, this routine's visible to the outside
563 ***************************************************************************/
564 struct nic
*eepro_probe(struct nic
*nic
, unsigned short *probe_addrs
)
567 /* same probe list as the Linux driver */
568 static unsigned short ioaddrs
[] = {
569 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360, 0};
571 if (probe_addrs
== 0 || probe_addrs
[0] == 0)
572 probe_addrs
= ioaddrs
;
573 for (p
= probe_addrs
; (ioaddr
= *p
) != 0; p
++) {
574 if (eepro_probe1(nic
))
580 /* point to NIC specific routines */
581 nic
->reset
= eepro_reset
;
582 nic
->poll
= eepro_poll
;
583 nic
->transmit
= eepro_transmit
;
584 nic
->disable
= eepro_disable
;