1 /* $NetBSD: 3c509.c,v 1.10 2008/12/14 18:46:33 christos Exp $ */
3 /* stripped down from freebsd:sys/i386/netboot/3c509.c */
5 /**************************************************************************
6 NETBOOT - BOOTP/TFTP Bootstrap Program
8 Author: Martin Renters.
11 This code is based heavily on David Greenman's if_ed.c driver and
12 Andres Vega Garcia's if_ep.c driver.
14 Copyright (C) 1993-1994, David Greenman, Martin Renters.
15 Copyright (C) 1993-1995, Andres Vega Garcia.
16 Copyright (C) 1995, Serge Babkin.
17 This software may be used, modified, copied, distributed, and sold, in
18 both source and binary form provided that the above copyright and these
19 terms are retained. Under no circumstances are the authors responsible for
20 the proper functioning of this software, nor do the authors assume any
21 responsibility for damages incurred with its use.
23 3c509 support added by Serge Babkin (babkin@hq.icb.chel.su)
25 3c509.c,v 1.2 1995/05/30 07:58:52 rgrimes Exp
27 ***************************************************************************/
29 #include <sys/types.h>
30 #include <machine/pio.h>
32 #include <lib/libsa/stand.h>
33 #include <lib/libkern/libkern.h>
43 unsigned ether_medium
;
44 unsigned short eth_base
;
46 extern void epreset(void);
47 extern int ep_get_e(int);
49 static int send_ID_sequence(int);
50 static int get_eeprom_data(int, int);
54 static struct mtabentry
{
55 int address_cfg
; /* configured connector */
56 int config_bit
; /* connector present */
58 } mediatab
[] = { /* indexed by media type - etherdrv.h */
65 static struct btinfo_netif bi_netif
;
69 extern int mapio(void);
72 /**************************************************************************
73 ETH_PROBE - Look for an adapter
74 ***************************************************************************/
76 EtherInit(unsigned char *myadr
)
78 /* common variables */
80 /* variables for 3C509 */
81 int data
, j
, id_port
= EP_ID_PORT
;
83 /* int ep_current_tag = EP_LAST_TAG + 1; */
89 printf("no IO access\n");
94 /*********************************************************
95 Search for 3Com 509 card
96 ***********************************************************/
101 /* Look for the ISA boards. Init and leave them actived */
102 /* search for the first card, ignore all others */
103 outb(id_port
, 0xc0); /* Global reset */
106 for (i = 0; i < EP_MAX_BOARDS; i++) {
110 send_ID_sequence(id_port
);
112 data
= get_eeprom_data(id_port
, EEPROM_MFG_ID
);
116 /* resolve contention using the Ethernet address */
117 for (j
= 0; j
< 3; j
++)
118 data
= get_eeprom_data(id_port
, j
);
121 (get_eeprom_data(id_port
, EEPROM_ADDR_CFG
) & 0x1f) * 0x10 + 0x200;
122 outb(id_port
, EP_LAST_TAG
); /* tags board */
123 outb(id_port
, ACTIVATE_ADAPTER_TO_CONFIG
);
129 if (i == EP_MAX_BOARDS)
134 * The iobase was found and MFG_ID was 0x6d50. PROD_ID should be
138 k
= (u_int
)ep_get_e(EEPROM_PROD_ID
);
139 if ((k
& 0xf0ff) != (PROD_ID
& 0xf0ff))
142 printf("3C5x9 board on ISA at 0x%x - ", eth_base
);
144 /* test for presence of connectors */
145 i
= inw(IS_BASE
+ EP_W0_CONFIG_CTRL
);
146 j
= inw(IS_BASE
+ EP_W0_ADDRESS_CFG
) >> 14;
148 for (ether_medium
= 0, m
= mediatab
;
149 ether_medium
< sizeof(mediatab
) / sizeof(mediatab
[0]);
150 ether_medium
++, m
++) {
151 if (j
== m
->address_cfg
) {
152 if (!(i
& m
->config_bit
)) {
153 printf("%s not present\n", m
->name
);
156 printf("using %s\n", m
->name
);
160 printf("unknown connector\n");
165 * Read the station address from the eeprom
167 p
= (u_short
*) eth_myaddr
;
168 for (i
= 0; i
< 3; i
++) {
172 p
[i
] = ((help
& 0xff) << 8) | ((help
& 0xff00) >> 8);
174 outw(BASE
+ EP_W2_ADDR_0
+ (i
* 2), help
);
176 for (i
= 0; i
< 6; i
++)
177 myadr
[i
] = eth_myaddr
[i
];
182 strncpy(bi_netif
.ifname
, "ep", sizeof(bi_netif
.ifname
));
183 bi_netif
.bus
= BI_BUS_ISA
;
184 bi_netif
.addr
.iobase
= eth_base
;
186 BI_ADD(&bi_netif
, BTINFO_NETIF
, sizeof(bi_netif
));
193 send_ID_sequence(int port
)
197 for (al
= 0xff, cx
= 0; cx
< 255; cx
++) {
207 * We get eeprom data from the id_port given an offset into the eeprom.
208 * Basically; after the ID_sequence is sent to all of the cards; they enter
209 * the ID_CMD state where they will accept command requests. 0x80-0xbf loads
210 * the eeprom data. We then read the port 16 times and with every read; the
211 * cards check for contention (ie: if one card writes a 0 bit and another
212 * writes a 1 bit then the host sees a 0. At the end of the cycle; each card
213 * compares the data on the bus; if there is a difference then that card goes
214 * into ID_WAIT state again). In the meantime; one bit of data is returned in
215 * the AX register which is conveniently returned to us by inb(). Hence; we
216 * read 16 times getting one bit of data with each read.
219 get_eeprom_data(int id_port
, int offset
)
222 outb(id_port
, 0x80 + offset
);
224 for (i
= 0; i
< 16; i
++)
225 data
= (data
<< 1) | (inw(id_port
) & 1);