2 #error multicast support is not yet implemented
4 /**************************************************************************
5 Etherboot - BOOTP/TFTP Bootstrap Program
6 Intel EEPRO/10 NIC driver for Etherboot
7 Adapted from Linux eepro.c from kernel 2.2.17
9 This board accepts a 32 pin EEPROM (29C256), however a test with a
10 27C010 shows that this EPROM also works in the socket, but it's not clear
11 how repeatably. The two top address pins appear to be held low, thus
12 the bottom 32kB of the 27C010 is visible in the CPU's address space.
13 To be sure you could put 4 copies of the code in the 27C010, then
14 it doesn't matter whether the extra lines are held low or high, just
15 hopefully not floating as CMOS chips don't like floating inputs.
17 Be careful with seating the EPROM as the socket on my board actually
18 has 34 pins, the top row of 2 are not used.
19 ***************************************************************************/
23 timlegge 2005-05-18 remove the relocation changes cards that
24 write directly to the hardware don't need it
28 * This program is free software; you can redistribute it and/or
29 * modify it under the terms of the GNU General Public License as
30 * published by the Free Software Foundation; either version 2, or (at
31 * your option) any later version.
34 #include "etherboot.h"
38 #include <gpxe/ethernet.h>
40 /* Different 82595 chips */
44 #define LAN595FX_10ISA 3
46 #define SLOW_DOWN inb(0x80);
48 /* The station (ethernet) address prefix, used for IDing the board. */
49 #define SA_ADDR0 0x00 /* Etherexpress Pro/10 */
53 #define GetBit(x,y) ((x & (1<<y))>>y)
56 #define ee_PnP 0 /* Plug 'n Play enable bit */
57 #define ee_Word1 1 /* Word 1? */
58 #define ee_BusWidth 2 /* 8/16 bit */
59 #define ee_FlashAddr 3 /* Flash Address */
60 #define ee_FlashMask 0x7 /* Mask */
61 #define ee_AutoIO 6 /* */
62 #define ee_reserved0 7 /* =0! */
63 #define ee_Flash 8 /* Flash there? */
64 #define ee_AutoNeg 9 /* Auto Negotiation enabled? */
65 #define ee_IO0 10 /* IO Address LSB */
66 #define ee_IO0Mask 0x /*...*/
67 #define ee_IO1 15 /* IO MSB */
70 #define ee_IntSel 0 /* Interrupt */
71 #define ee_IntMask 0x7
72 #define ee_LI 3 /* Link Integrity 0= enabled */
73 #define ee_PC 4 /* Polarity Correction 0= enabled */
74 #define ee_TPE_AUI 5 /* PortSelection 1=TPE */
75 #define ee_Jabber 6 /* Jabber prevention 0= enabled */
76 #define ee_AutoPort 7 /* Auto Port Selection 1= Disabled */
77 #define ee_SMOUT 8 /* SMout Pin Control 0= Input */
78 #define ee_PROM 9 /* Flash EPROM / PROM 0=Flash */
79 #define ee_reserved1 10 /* .. 12 =0! */
80 #define ee_AltReady 13 /* Alternate Ready, 0=normal */
81 #define ee_reserved2 14 /* =0! */
85 #define ee_IA5 0 /*bit start for individual Addr Byte 5 */
86 #define ee_IA4 8 /*bit start for individual Addr Byte 5 */
87 #define ee_IA3 0 /*bit start for individual Addr Byte 5 */
88 #define ee_IA2 8 /*bit start for individual Addr Byte 5 */
89 #define ee_IA1 0 /*bit start for individual Addr Byte 5 */
90 #define ee_IA0 8 /*bit start for individual Addr Byte 5 */
93 #define ee_BNC_TPE 0 /* 0=TPE */
94 #define ee_BootType 1 /* 00=None, 01=IPX, 10=ODI, 11=NDIS */
95 #define ee_BootTypeMask 0x3
96 #define ee_NumConn 3 /* Number of Connections 0= One or Two */
97 #define ee_FlashSock 4 /* Presence of Flash Socket 0= Present */
101 #define ee_PowerMgt 10 /* 0= disabled */
102 #define ee_CP 13 /* Concurrent Processing */
103 #define ee_CPMask 0x7
106 #define ee_Stepping 0 /* Stepping info */
107 #define ee_StepMask 0x0F
108 #define ee_BoardID 4 /* Manucaturer Board ID, reserved */
109 #define ee_BoardMask 0x0FFF
112 #define ee_INT_TO_IRQ 0 /* int to IRQ Mapping = 0x1EB8 for Pro/10+ */
113 #define ee_FX_INT2IRQ 0x1EB8 /* the _only_ mapping allowed for FX chips */
116 #define ee_SIZE 0x40 /* total EEprom Size */
117 #define ee_Checksum 0xBABA /* initial and final value for adding checksum */
120 /* Card identification via EEprom: */
121 #define ee_addr_vendor 0x10 /* Word offset for EISA Vendor ID */
122 #define ee_addr_id 0x11 /* Word offset for Card ID */
123 #define ee_addr_SN 0x12 /* Serial Number */
124 #define ee_addr_CRC_8 0x14 /* CRC over last thee Bytes */
127 #define ee_vendor_intel0 0x25 /* Vendor ID Intel */
128 #define ee_vendor_intel1 0xD4
129 #define ee_id_eepro10p0 0x10 /* ID for eepro/10+ */
130 #define ee_id_eepro10p1 0x31
132 /* now this section could be used by both boards: the oldies and the ee10:
133 * ee10 uses tx buffer before of rx buffer and the oldies the inverse.
136 #define RAM_SIZE 0x8000
139 #define RCV_DEFAULT_RAM 0x6000
140 #define RCV_RAM rcv_ram
142 static unsigned rcv_ram = RCV_DEFAULT_RAM;
145 #define XMT_RAM (RAM_SIZE - RCV_RAM)
147 #define XMT_START ((rcv_start + RCV_RAM) % RAM_SIZE)
149 #define RCV_LOWER_LIMIT (rcv_start >> 8)
150 #define RCV_UPPER_LIMIT (((rcv_start + RCV_RAM) - 2) >> 8)
151 #define XMT_LOWER_LIMIT (XMT_START >> 8)
152 #define XMT_UPPER_LIMIT (((XMT_START + XMT_RAM) - 2) >> 8)
154 #define RCV_START_PRO 0x00
155 #define RCV_START_10 XMT_RAM
156 /* by default the old driver */
157 static unsigned rcv_start = RCV_START_PRO;
159 #define RCV_DONE 0x0008
161 #define RX_ERROR 0x0d81
163 #define TX_DONE_BIT 0x0080
164 #define CHAIN_BIT 0x8000
165 #define XMT_STATUS 0x02
166 #define XMT_CHAIN 0x04
167 #define XMT_COUNT 0x06
169 #define BANK0_SELECT 0x00
170 #define BANK1_SELECT 0x40
171 #define BANK2_SELECT 0x80
173 /* Bank 0 registers */
174 #define COMMAND_REG 0x00 /* Register 0 */
175 #define MC_SETUP 0x03
177 #define DIAGNOSE_CMD 0x07
178 #define RCV_ENABLE_CMD 0x08
179 #define RCV_DISABLE_CMD 0x0a
180 #define STOP_RCV_CMD 0x0b
181 #define RESET_CMD 0x0e
182 #define POWER_DOWN_CMD 0x18
183 #define RESUME_XMT_CMD 0x1c
184 #define SEL_RESET_CMD 0x1e
185 #define STATUS_REG 0x01 /* Register 1 */
188 #define EXEC_STATUS 0x30
189 #define ID_REG 0x02 /* Register 2 */
190 #define R_ROBIN_BITS 0xc0 /* round robin counter */
191 #define ID_REG_MASK 0x2c
192 #define ID_REG_SIG 0x24
193 #define AUTO_ENABLE 0x10
194 #define INT_MASK_REG 0x03 /* Register 3 */
195 #define RX_STOP_MASK 0x01
198 #define EXEC_MASK 0x08
199 #define ALL_MASK 0x0f
200 #define IO_32_BIT 0x10
201 #define RCV_BAR 0x04 /* The following are word (16-bit) registers */
202 #define RCV_STOP 0x06
204 #define XMT_BAR_PRO 0x0a
205 #define XMT_BAR_10 0x0b
206 static unsigned xmt_bar = XMT_BAR_PRO;
208 #define HOST_ADDRESS_REG 0x0c
210 #define IO_PORT_32_BIT 0x0c
212 /* Bank 1 registers */
214 #define WORD_WIDTH 0x02
215 #define INT_ENABLE 0x80
216 #define INT_NO_REG 0x02
217 #define RCV_LOWER_LIMIT_REG 0x08
218 #define RCV_UPPER_LIMIT_REG 0x09
220 #define XMT_LOWER_LIMIT_REG_PRO 0x0a
221 #define XMT_UPPER_LIMIT_REG_PRO 0x0b
222 #define XMT_LOWER_LIMIT_REG_10 0x0b
223 #define XMT_UPPER_LIMIT_REG_10 0x0a
224 static unsigned xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_PRO;
225 static unsigned xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_PRO;
227 /* Bank 2 registers */
228 #define XMT_Chain_Int 0x20 /* Interrupt at the end of the transmit chain */
229 #define XMT_Chain_ErrStop 0x40 /* Interrupt at the end of the chain even if there are errors */
230 #define RCV_Discard_BadFrame 0x80 /* Throw bad frames away, and continue to receive others */
232 #define PRMSC_Mode 0x01
233 #define Multi_IA 0x20
239 #define A_N_ENABLE 0x02
241 #define I_ADD_REG0 0x04
242 #define I_ADD_REG1 0x05
243 #define I_ADD_REG2 0x06
244 #define I_ADD_REG3 0x07
245 #define I_ADD_REG4 0x08
246 #define I_ADD_REG5 0x09
248 #define EEPROM_REG_PRO 0x0a
249 #define EEPROM_REG_10 0x0b
250 static unsigned eeprom_reg = EEPROM_REG_PRO;
257 /* The horrible routine to read a word from the serial EEPROM. */
258 /* IMPORTANT - the 82595 will be set to Bank 0 after the eeprom is read */
260 /* The delay between EEPROM clock transitions. */
261 #define eeprom_delay() { udelay(40); }
262 #define EE_READ_CMD (6 << 6)
264 /* do a full reset; data sheet asks for 250us delay */
265 #define eepro_full_reset(ioaddr) outb(RESET_CMD, ioaddr); udelay(255);
267 /* do a nice reset */
268 #define eepro_sel_reset(ioaddr) { \
269 outb(SEL_RESET_CMD, ioaddr); \
274 /* clear all interrupts */
275 #define eepro_clear_int(ioaddr) outb(ALL_MASK, ioaddr + STATUS_REG)
278 #define eepro_en_rx(ioaddr) outb(RCV_ENABLE_CMD, ioaddr)
281 #define eepro_dis_rx(ioaddr) outb(RCV_DISABLE_CMD, ioaddr)
284 #define eepro_sw2bank0(ioaddr) outb(BANK0_SELECT, ioaddr)
285 #define eepro_sw2bank1(ioaddr) outb(BANK1_SELECT, ioaddr)
286 #define eepro_sw2bank2(ioaddr) outb(BANK2_SELECT, ioaddr)
288 static unsigned int rx_start, tx_start;
290 static unsigned int tx_end;
291 static int eepro = 0;
292 static unsigned int mem_start, mem_end = RCV_DEFAULT_RAM / 1024;
294 /**************************************************************************
295 RESET - Reset adapter
296 ***************************************************************************/
297 static void eepro_reset(struct nic *nic)
301 /* put the card in its initial state */
302 eepro_sw2bank2(nic->ioaddr); /* be careful, bank2 now */
303 temp_reg = inb(nic->ioaddr + eeprom_reg);
304 DBG("Stepping %d\n", temp_reg >> 5);
305 if (temp_reg & 0x10) /* check the TurnOff Enable bit */
306 outb(temp_reg & 0xEF, nic->ioaddr + eeprom_reg);
307 for (i = 0; i < ETH_ALEN; i++) /* fill the MAC address */
308 outb(nic->node_addr[i], nic->ioaddr + I_ADD_REG0 + i);
309 temp_reg = inb(nic->ioaddr + REG1);
310 /* setup Transmit Chaining and discard bad RCV frames */
311 outb(temp_reg | XMT_Chain_Int | XMT_Chain_ErrStop
312 | RCV_Discard_BadFrame, nic->ioaddr + REG1);
313 temp_reg = inb(nic->ioaddr + REG2); /* match broadcast */
314 outb(temp_reg | 0x14, nic->ioaddr + REG2);
315 temp_reg = inb(nic->ioaddr + REG3);
316 outb(temp_reg & 0x3F, nic->ioaddr + REG3); /* clear test mode */
317 /* set the receiving mode */
318 eepro_sw2bank1(nic->ioaddr); /* be careful, bank1 now */
319 /* initialise the RCV and XMT upper and lower limits */
320 outb(RCV_LOWER_LIMIT, nic->ioaddr + RCV_LOWER_LIMIT_REG);
321 outb(RCV_UPPER_LIMIT, nic->ioaddr + RCV_UPPER_LIMIT_REG);
322 outb(XMT_LOWER_LIMIT, nic->ioaddr + xmt_lower_limit_reg);
323 outb(XMT_UPPER_LIMIT, nic->ioaddr + xmt_upper_limit_reg);
324 eepro_sw2bank0(nic->ioaddr); /* Switch back to bank 0 */
325 eepro_clear_int(nic->ioaddr);
327 outw(rx_start = (RCV_LOWER_LIMIT << 8), nic->ioaddr + RCV_BAR);
328 outw(((RCV_UPPER_LIMIT << 8) | 0xFE), nic->ioaddr + RCV_STOP);
329 /* Make sure 1st poll won't find a valid packet header */
330 outw((RCV_LOWER_LIMIT << 8), nic->ioaddr + HOST_ADDRESS_REG);
331 outw(0, nic->ioaddr + IO_PORT);
333 outw((XMT_LOWER_LIMIT << 8), nic->ioaddr + xmt_bar);
334 eepro_sel_reset(nic->ioaddr);
335 tx_start = tx_end = (XMT_LOWER_LIMIT << 8);
337 eepro_en_rx(nic->ioaddr);
340 /**************************************************************************
341 POLL - Wait for a frame
342 ***************************************************************************/
343 static int eepro_poll(struct nic *nic, int retrieve)
345 unsigned int rcv_car = rx_start;
346 unsigned int rcv_event, rcv_status, rcv_next_frame, rcv_size;
348 /* return true if there's an ethernet packet ready to read */
349 /* nic->packet should contain data on return */
350 /* nic->packetlen should contain length of data */
352 if ((inb(nic->ioaddr + STATUS_REG) & 0x40) == 0)
354 outb(0x40, nic->ioaddr + STATUS_REG);
356 outw(rcv_car, nic->ioaddr + HOST_ADDRESS_REG);
357 rcv_event = inw(nic->ioaddr + IO_PORT);
358 if (rcv_event != RCV_DONE)
361 /* FIXME: I'm guessing this might not work with this card, since
362 it looks like once a rcv_event is started it must be completed.
363 maybe there's another way. */
364 if ( ! retrieve ) return 1;
366 rcv_status = inw(nic->ioaddr + IO_PORT);
367 rcv_next_frame = inw(nic->ioaddr + IO_PORT);
368 rcv_size = inw(nic->ioaddr + IO_PORT);
370 printf("%hX %hX %d %hhX\n", rcv_status, rcv_next_frame, rcv_size,
371 inb(nic->ioaddr + STATUS_REG));
373 if ((rcv_status & (RX_OK|RX_ERROR)) != RX_OK) {
374 printf("Receive error %hX\n", rcv_status);
378 insw(nic->ioaddr + IO_PORT, nic->packet, ((rcv_size + 3) >> 1));
382 for (i = 0; i < 48; i++) {
383 printf("%hhX", nic->packet[i]);
384 putchar(i % 16 == 15 ? '\n' : ' ');
388 nic->packetlen = rcv_size;
389 rcv_car = (rx_start + RCV_HEADER + rcv_size);
390 rx_start = rcv_next_frame;
392 hex_dump(rcv_car, nic->packetlen);
396 rcv_car = ((RCV_UPPER_LIMIT << 8) | 0xff);
397 outw(rcv_car - 1, nic->ioaddr + RCV_STOP);
401 /**************************************************************************
402 TRANSMIT - Transmit a frame
403 ***************************************************************************/
404 static void eepro_transmit(
406 const char *d, /* Destination */
407 unsigned int t, /* Type */
408 unsigned int s, /* size */
409 const char *p) /* Packet */
411 unsigned int status, tx_available, last, end, length;
415 length = s + ETH_HLEN;
416 if (tx_end > tx_start)
417 tx_available = XMT_RAM - (tx_end - tx_start);
418 else if (tx_end < tx_start)
419 tx_available = tx_start - tx_end;
421 tx_available = XMT_RAM;
423 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
424 if (end >= (XMT_UPPER_LIMIT << 8)) {
425 last = (XMT_LOWER_LIMIT << 8);
426 end = last + (((length + 3) >> 1) << 1) + XMT_HEADER;
428 outw(last, nic->ioaddr + HOST_ADDRESS_REG);
429 outw(XMT_CMD, nic->ioaddr + IO_PORT);
430 outw(0, nic->ioaddr + IO_PORT);
431 outw(end, nic->ioaddr + IO_PORT);
432 outw(length, nic->ioaddr + IO_PORT);
433 outsw(nic->ioaddr + IO_PORT, d, ETH_ALEN / 2);
434 outsw(nic->ioaddr + IO_PORT, nic->node_addr, ETH_ALEN / 2);
436 outsw(nic->ioaddr + IO_PORT, &type, sizeof(type) / 2);
437 outsw(nic->ioaddr + IO_PORT, p, (s + 3) >> 1);
438 /* A dummy read to flush the DRAM write pipeline */
439 status = inw(nic->ioaddr + IO_PORT);
440 outw(last, nic->ioaddr + xmt_bar);
441 outb(XMT_CMD, nic->ioaddr);
446 printf("%d %d\n", tx_start, tx_end);
448 while (boguscount > 0) {
449 if (((status = inw(nic->ioaddr + IO_PORT)) & TX_DONE_BIT) == 0) {
454 if ((status & 0x2000) == 0) {
455 DBG("Transmit status %hX\n", status);
460 /**************************************************************************
461 DISABLE - Turn off ethernet interface
462 ***************************************************************************/
463 static void eepro_disable ( struct nic *nic, struct isa_device *isa __unused ) {
464 eepro_sw2bank0(nic->ioaddr); /* Switch to bank 0 */
465 /* Flush the Tx and disable Rx */
466 outb(STOP_RCV_CMD, nic->ioaddr);
467 tx_start = tx_end = (XMT_LOWER_LIMIT << 8);
469 /* Reset the 82595 */
470 eepro_full_reset(nic->ioaddr);
473 /**************************************************************************
474 DISABLE - Enable, Disable, or Force interrupts
475 ***************************************************************************/
476 static void eepro_irq(struct nic *nic __unused, irq_action_t action __unused)
488 static int read_eeprom(uint16_t ioaddr, int location)
491 unsigned short retval = 0;
492 int ee_addr = ioaddr + eeprom_reg;
493 int read_cmd = location | EE_READ_CMD;
496 if (eepro == LAN595FX_10ISA) {
497 eepro_sw2bank1(ioaddr);
498 outb(0x00, ioaddr + STATUS_REG);
500 eepro_sw2bank2(ioaddr);
501 outb(ctrl_val, ee_addr);
502 /* shift the read command bits out */
503 for (i = 8; i >= 0; i--) {
504 short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI : ctrl_val;
505 outb(outval, ee_addr);
506 outb(outval | EESK, ee_addr); /* EEPROM clock tick */
508 outb(outval, ee_addr); /* finish EEPROM clock tick */
511 outb(ctrl_val, ee_addr);
512 for (i = 16; i > 0; i--) {
513 outb(ctrl_val | EESK, ee_addr);
515 retval = (retval << 1) | ((inb(ee_addr) & EEDO) ? 1 : 0);
516 outb(ctrl_val, ee_addr);
519 /* terminate the EEPROM access */
521 outb(ctrl_val | EESK, ee_addr);
523 outb(ctrl_val, ee_addr);
525 eepro_sw2bank0(ioaddr);
529 static int eepro_probe1 ( isa_probe_addr_t ioaddr ) {
532 id = inb(ioaddr + ID_REG);
533 if ((id & ID_REG_MASK) != ID_REG_SIG)
535 counter = id & R_ROBIN_BITS;
536 if (((id = inb(ioaddr + ID_REG)) & R_ROBIN_BITS) != (counter + 0x40))
538 /* yes the 82595 has been found */
542 static struct nic_operations eepro_operations = {
543 .connect = dummy_connect,
545 .transmit = eepro_transmit,
550 /**************************************************************************
551 PROBE - Look for an adapter, this routine's visible to the outside
552 ***************************************************************************/
553 static int eepro_probe ( struct nic *nic, struct isa_device *isa ) {
557 unsigned char caddr[ETH_ALEN];
558 unsigned short saddr[ETH_ALEN/2];
562 isa_fill_nic ( nic, isa );
563 nic->ioaddr = isa->ioaddr;
565 station_addr.saddr[2] = read_eeprom(nic->ioaddr,2);
566 if ( ( station_addr.saddr[2] == 0x0000 ) ||
567 ( station_addr.saddr[2] == 0xFFFF ) ) {
569 eepro = LAN595FX_10ISA;
570 eeprom_reg= EEPROM_REG_10;
571 rcv_start = RCV_START_10;
572 xmt_lower_limit_reg = XMT_LOWER_LIMIT_REG_10;
573 xmt_upper_limit_reg = XMT_UPPER_LIMIT_REG_10;
574 station_addr.saddr[2] = read_eeprom(nic->ioaddr,2);
576 station_addr.saddr[1] = read_eeprom(nic->ioaddr,3);
577 station_addr.saddr[0] = read_eeprom(nic->ioaddr,4);
579 isa->name = "Intel EtherExpress 10 ISA";
580 else if (read_eeprom(nic->ioaddr,7) == ee_FX_INT2IRQ) {
581 isa->name = "Intel EtherExpress Pro/10+ ISA";
583 } else if (station_addr.saddr[0] == SA_ADDR1) {
584 isa->name = "Intel EtherExpress Pro/10 ISA";
588 isa->name = "Intel 82595-based LAN card";
590 station_addr.saddr[0] = swap16(station_addr.saddr[0]);
591 station_addr.saddr[1] = swap16(station_addr.saddr[1]);
592 station_addr.saddr[2] = swap16(station_addr.saddr[2]);
593 for (i = 0; i < ETH_ALEN; i++) {
594 nic->node_addr[i] = station_addr.caddr[i];
597 DBG ( "%s ioaddr %#hX, addr %s", isa->name, nic->ioaddr, eth_ntoa ( nic->node_addr ) );
599 mem_start = RCV_LOWER_LIMIT << 8;
600 if ((mem_end & 0x3F) < 3 || (mem_end & 0x3F) > 29)
601 mem_end = RCV_UPPER_LIMIT << 8;
603 mem_end = mem_end * 1024 + (RCV_LOWER_LIMIT << 8);
604 rcv_ram = mem_end - (RCV_LOWER_LIMIT << 8);
606 printf(", Rx mem %dK, if %s\n", (mem_end - mem_start) >> 10,
607 GetBit(read_eeprom(nic->ioaddr,5), ee_BNC_TPE) ? "BNC" : "TP");
611 /* point to NIC specific routines */
612 nic->nic_op = &eepro_operations;
616 static isa_probe_addr_t eepro_probe_addrs[] = {
617 0x300, 0x210, 0x240, 0x280, 0x2C0, 0x200, 0x320, 0x340, 0x360,
620 ISA_DRIVER ( eepro_driver, eepro_probe_addrs, eepro_probe1,
621 GENERIC_ISAPNP_VENDOR, 0x828a );
623 DRIVER ( "eepro", nic_driver, isa_driver, eepro_driver,
624 eepro_probe, eepro_disable );
626 ISA_ROM ( "eepro", "Intel Etherexpress Pro/10" );