2 * Split out into 3c509.c and 3c5x9.c, to make it possible to build a
3 * 3c529 module without including ISA, ISAPnP and EISA code.
16 * 3c509 cards have their own method of contention resolution; this
17 * effectively defines another bus type similar to ISAPnP. Even the
18 * original ISA cards can be programatically mapped to any I/O address
19 * in the range 0x200-0x3e0.
21 * However, there is a small problem: once you've activated a card,
22 * the only ways to deactivate it will also wipe its tag, meaning that
23 * you won't be able to subsequently reactivate it without going
24 * through the whole ID sequence again. The solution we adopt is to
25 * isolate and tag all cards at the start, and to immediately
26 * re-isolate and re-tag a card after disabling it.
30 static uint16_t t509_id_port
= 0;
31 static uint8_t t509_max_tag
= 0;
34 * A location on a t509 bus
42 * A physical t509 device
51 * t509 utility functions
55 static inline void t509_set_id_port ( void ) {
56 outb ( 0x00, t509_id_port
);
59 static inline void t509_wait_for_id_sequence ( void ) {
60 outb ( 0x00, t509_id_port
);
63 static inline void t509_global_reset ( void ) {
64 outb ( 0xc0, t509_id_port
);
67 static inline void t509_reset_tag ( void ) {
68 outb ( 0xd0, t509_id_port
);
71 static inline void t509_set_tag ( uint8_t tag
) {
72 outb ( 0xd0 | tag
, t509_id_port
);
75 static inline void t509_select_tag ( uint8_t tag
) {
76 outb ( 0xd8 | tag
, t509_id_port
);
79 static inline void t509_activate ( uint16_t ioaddr
) {
80 outb ( 0xe0 | ( ioaddr
>> 4 ), t509_id_port
);
83 static inline void t509_deactivate_and_reset_tag ( uint16_t ioaddr
) {
84 outb ( GLOBAL_RESET
, ioaddr
+ EP_COMMAND
);
87 static inline void t509_load_eeprom_word ( uint8_t offset
) {
88 outb ( 0x80 | offset
, t509_id_port
);
92 * Find a suitable ID port
95 static inline int t509_find_id_port ( void ) {
97 for ( t509_id_port
= EP_ID_PORT_START
;
98 t509_id_port
< EP_ID_PORT_END
;
99 t509_id_port
+= EP_ID_PORT_INC
) {
101 /* See if anything's listening */
102 outb ( 0xff, t509_id_port
);
103 if ( inb ( t509_id_port
) & 0x01 ) {
104 /* Found a suitable port */
105 DBG ( "T509 using ID port at %hx\n", t509_id_port
);
109 /* No id port available */
110 DBG ( "T509 found no available ID port\n" );
115 * Send ID sequence to the ID port
118 static void t509_send_id_sequence ( void ) {
119 unsigned short lrs_state
, i
;
122 /* Reset IDS on cards */
123 t509_wait_for_id_sequence ();
125 for ( i
= 0; i
< 255; i
++ ) {
126 outb ( lrs_state
, t509_id_port
);
128 lrs_state
= lrs_state
& 0x100 ? lrs_state
^ 0xcf : lrs_state
;
133 * We get eeprom data from the id_port given an offset into the eeprom.
134 * Basically; after the ID_sequence is sent to all of the cards; they enter
135 * the ID_CMD state where they will accept command requests. 0x80-0xbf loads
136 * the eeprom data. We then read the port 16 times and with every read; the
137 * cards check for contention (ie: if one card writes a 0 bit and another
138 * writes a 1 bit then the host sees a 0. At the end of the cycle; each card
139 * compares the data on the bus; if there is a difference then that card goes
140 * into ID_WAIT state again). In the meantime; one bit of data is returned in
141 * the AX register which is conveniently returned to us by inb(). Hence; we
142 * read 16 times getting one bit of data with each read.
144 static uint16_t t509_id_read_eeprom ( int offset
) {
147 t509_load_eeprom_word ( offset
);
148 /* Do we really need this wait? Won't be noticeable anyway */
151 for ( i
= 0; i
< 16; i
++ ) {
152 data
= ( data
<< 1 ) | ( inw ( t509_id_port
) & 1 );
158 * Isolate and tag all t509 cards
161 static void t509_isolate ( void ) {
165 /* Find a suitable ID port */
166 if ( ! t509_find_id_port () )
171 /* All cards are in ID_WAIT state each time we go
175 /* Send the ID sequence */
176 t509_send_id_sequence ();
178 /* First time through, reset all tags. On subsequent
179 * iterations, kill off any already-tagged cards
181 if ( t509_max_tag
== 0 ) {
187 /* Read the manufacturer ID, to see if there are any
190 if ( t509_id_read_eeprom ( EEPROM_MFG_ID
) != MFG_ID
) {
191 DBG ( "T509 saw %s signs of life\n",
192 t509_max_tag
? "no further" : "no" );
196 /* Perform contention selection on the MAC address */
197 for ( i
= 0 ; i
< 3 ; i
++ ) {
198 contend
[i
] = t509_id_read_eeprom ( i
);
201 /* Only one device will still be left alive. Tag it. */
203 DBG ( "T509 found card %hx%hx%hx, assigning tag %hhx\n",
204 contend
[0], contend
[1], contend
[2], t509_max_tag
);
205 t509_set_tag ( t509_max_tag
);
207 /* Return all cards back to ID_WAIT state */
208 t509_wait_for_id_sequence();
211 DBG ( "T509 found %d cards using ID port %hx\n",
212 t509_max_tag
, t509_id_port
);
217 * Increment a bus_loc structure to the next possible T509 location.
218 * Leave the structure zeroed and return 0 if there are no more valid
222 static int t509_next_location ( struct bus_loc
*bus_loc
) {
223 struct t509_loc
*t509_loc
= ( struct t509_loc
* ) bus_loc
;
226 * Ensure that there is sufficient space in the shared bus
227 * structures for a struct t509_loc and a struct t509_dev,
228 * as mandated by bus.h.
231 BUS_LOC_CHECK ( struct t509_loc
);
232 BUS_DEV_CHECK ( struct t509_device
);
234 return ( t509_loc
->tag
= ( ++t509_loc
->tag
& EP_TAG_MAX
) );
238 * Fill in parameters for a T509 device based on tag
240 * Return 1 if device present, 0 otherwise
243 static int t509_fill_device ( struct bus_dev
*bus_dev
,
244 struct bus_loc
*bus_loc
) {
245 struct t509_device
*t509
= ( struct t509_device
* ) bus_dev
;
246 struct t509_loc
*t509_loc
= ( struct t509_loc
* ) bus_loc
;
249 /* Copy tag to struct t509 */
250 t509
->tag
= t509_loc
->tag
;
252 /* Tag 0 is never valid, but may be passed in */
256 /* Perform isolation if it hasn't yet been done */
257 if ( ! t509_id_port
)
260 /* Check tag is in range */
261 if ( t509
->tag
> t509_max_tag
)
264 /* Send the ID sequence */
265 t509_send_id_sequence ();
267 /* Select the specified tag */
268 t509_select_tag ( t509
->tag
);
270 /* Read the default I/O address */
271 iobase
= t509_id_read_eeprom ( EEPROM_ADDR_CFG
);
272 t509
->ioaddr
= 0x200 + ( ( iobase
& 0x1f ) << 4 );
274 /* Send card back to ID_WAIT */
275 t509_wait_for_id_sequence();
277 DBG ( "T509 found device %hhx, base %hx\n", t509
->tag
, t509
->ioaddr
);
282 * Test whether or not a driver is capable of driving the device.
283 * This is a no-op for T509.
286 static int t509_check_driver ( struct bus_dev
*bus_dev __unused
,
287 struct device_driver
*device_driver __unused
) {
292 * Describe a T509 device
295 static char * t509_describe_device ( struct bus_dev
*bus_dev
) {
296 struct t509_device
*t509
= ( struct t509_device
* ) bus_dev
;
297 static char t509_description
[] = "T509 00";
299 sprintf ( t509_description
+ 4, "%hhx", t509
->tag
);
300 return t509_description
;
307 static const char * t509_name_device ( struct bus_dev
*bus_dev __unused
) {
312 * T509 bus operations table
315 struct bus_driver t509_driver __bus_driver
= {
317 .next_location
= t509_next_location
,
318 .fill_device
= t509_fill_device
,
319 .check_driver
= t509_check_driver
,
320 .describe_device
= t509_describe_device
,
321 .name_device
= t509_name_device
,
325 * Activate a T509 device
327 * The device will be enabled at whatever ioaddr is specified in the
328 * struct t509_device; there is no need to stick with the default
329 * ioaddr read from the EEPROM.
332 static inline void activate_t509_device ( struct t509_device
*t509
) {
333 t509_send_id_sequence ();
334 t509_select_tag ( t509
->tag
);
335 t509_activate ( t509
->ioaddr
);
336 DBG ( "T509 activated device %hhx at ioaddr %hx\n",
337 t509
->tag
, t509
->ioaddr
);
341 * Deactivate a T509 device
343 * Disabling also clears the tag, so we immediately isolate and re-tag
347 static inline void deactivate_t509_device ( struct t509_device
*t509
) {
348 t509_deactivate_and_reset_tag ( t509
->ioaddr
);
350 t509_send_id_sequence ();
351 t509_select_tag ( 0 );
352 t509_set_tag ( t509
->tag
);
353 t509_wait_for_id_sequence ();
354 DBG ( "T509 deactivated device at %hx and re-tagged as %hhx\n",
355 t509
->ioaddr
, t509
->tag
);
359 * Fill in a nic structure
361 * Called only once, so inlined for efficiency
364 static inline void t509_fill_nic ( struct nic
*nic
,
365 struct t509_device
*t509
) {
367 /* Fill in ioaddr and irqno */
368 nic
->ioaddr
= t509
->ioaddr
;
371 /* Fill in DHCP device ID structure */
372 nic
->dhcp_dev_id
.bus_type
= ISA_BUS_TYPE
;
373 nic
->dhcp_dev_id
.vendor_id
= htons ( MFG_ID
);
374 nic
->dhcp_dev_id
.device_id
= htons ( PROD_ID
);
378 * The ISA probe function
381 static int el3_t509_probe ( struct nic
*nic
, struct t509_device
*t509
) {
383 /* We could change t509->ioaddr if we wanted to */
384 activate_t509_device ( t509
);
385 t509_fill_nic ( nic
, t509
);
387 /* Hand off to generic t5x9 probe routine */
388 return t5x9_probe ( nic
, ISA_PROD_ID ( PROD_ID
), ISA_PROD_ID_MASK
);
391 static void el3_t509_disable ( struct nic
*nic
, struct t509_device
*t509
) {
392 t5x9_disable ( nic
);
393 deactivate_t509_device ( t509
);
396 struct {} el3_t509_driver
;
398 DRIVER ( "3c509", nic_driver
, t509_driver
, el3_t509_driver
,
399 el3_t509_probe
, el3_t509_disable
);
401 ISA_ROM ( "3c509", "3c509" );