2 * 3c90x.c -- This file implements the 3c90x driver for etherboot. Written
3 * by Greg Beeley, Greg.Beeley@LightSys.org. Modified by Steve Smith,
4 * Steve.Smith@Juno.Com. Alignment bug fix Neil Newell (nn@icenoir.net).
6 * This program Copyright (C) 1999 LightSys Technology Services, Inc.
7 * Portions Copyright (C) 1999 Steve Smith
9 * This program may be re-distributed in source or binary form, modified,
10 * sold, or copied for any purpose, provided that the above copyright message
11 * and this text are included with all source copies or derivative works, and
12 * provided that the above copyright message and this text are included in the
13 * documentation of any binary-only distributions. This program is distributed
14 * WITHOUT ANY WARRANTY, without even the warranty of FITNESS FOR A PARTICULAR
15 * PURPOSE or MERCHANTABILITY. Please read the associated documentation
16 * "3c90x.txt" before compiling and using this driver.
20 * Program written with the assistance of the 3com documentation for
21 * the 3c905B-TX card, as well as with some assistance from the 3c59x
22 * driver Donald Becker wrote for the Linux kernel, and with some assistance
23 * from the remainder of the Etherboot distribution.
27 * v0.10 1-26-1998 GRB Initial implementation.
28 * v0.90 1-27-1998 GRB System works.
29 * v1.00pre1 2-11-1998 GRB Got prom boot issue fixed.
30 * v2.0 9-24-1999 SCS Modified for 3c905 (from 3c905b code)
31 * Re-wrote poll and transmit for
32 * better error recovery and heavy
33 * network traffic operation
34 * v2.01 5-26-2003 NN Fixed driver alignment issue which
35 * caused system lockups if driver structures
40 #include "etherboot-compat.h"
45 #include <pci-bother.h>
50 #define XCVR_MAGIC (0x5A00)
51 /** any single transmission fails after 16 collisions or other errors
52 ** this is the number of times to retry the transmission -- this should
55 #define XMIT_RETRIES 5
57 /*** Register definitions for the 3c905 ***/
60 regPowerMgmtCtrl_w = 0x7c, /** 905B Revision Only **/
61 regUpMaxBurst_w = 0x7a, /** 905B Revision Only **/
62 regDnMaxBurst_w = 0x78, /** 905B Revision Only **/
63 regDebugControl_w = 0x74, /** 905B Revision Only **/
64 regDebugData_l = 0x70, /** 905B Revision Only **/
65 regRealTimeCnt_l = 0x40, /** Universal **/
66 regUpBurstThresh_b = 0x3e, /** 905B Revision Only **/
67 regUpPoll_b = 0x3d, /** 905B Revision Only **/
68 regUpPriorityThresh_b = 0x3c, /** 905B Revision Only **/
69 regUpListPtr_l = 0x38, /** Universal **/
70 regCountdown_w = 0x36, /** Universal **/
71 regFreeTimer_w = 0x34, /** Universal **/
72 regUpPktStatus_l = 0x30, /** Universal with Exception, pg 130 **/
73 regTxFreeThresh_b = 0x2f, /** 90X Revision Only **/
74 regDnPoll_b = 0x2d, /** 905B Revision Only **/
75 regDnPriorityThresh_b = 0x2c, /** 905B Revision Only **/
76 regDnBurstThresh_b = 0x2a, /** 905B Revision Only **/
77 regDnListPtr_l = 0x24, /** Universal with Exception, pg 107 **/
78 regDmaCtrl_l = 0x20, /** Universal with Exception, pg 106 **/
80 regIntStatusAuto_w = 0x1e, /** 905B Revision Only **/
81 regTxStatus_b = 0x1b, /** Universal with Exception, pg 113 **/
82 regTimer_b = 0x1a, /** Universal **/
83 regTxPktId_b = 0x18, /** 905B Revision Only **/
84 regCommandIntStatus_w = 0x0e, /** Universal (Command Variations) **/
87 /** following are windowed registers **/
90 regPowerMgmtEvent_7_w = 0x0c, /** 905B Revision Only **/
91 regVlanEtherType_7_w = 0x04, /** 905B Revision Only **/
92 regVlanMask_7_w = 0x00, /** 905B Revision Only **/
97 regBytesXmittedOk_6_w = 0x0c, /** Universal **/
98 regBytesRcvdOk_6_w = 0x0a, /** Universal **/
99 regUpperFramesOk_6_b = 0x09, /** Universal **/
100 regFramesDeferred_6_b = 0x08, /** Universal **/
101 regFramesRecdOk_6_b = 0x07, /** Universal with Exceptions, pg 142 **/
102 regFramesXmittedOk_6_b = 0x06, /** Universal **/
103 regRxOverruns_6_b = 0x05, /** Universal **/
104 regLateCollisions_6_b = 0x04, /** Universal **/
105 regSingleCollisions_6_b = 0x03, /** Universal **/
106 regMultipleCollisions_6_b = 0x02, /** Universal **/
107 regSqeErrors_6_b = 0x01, /** Universal **/
108 regCarrierLost_6_b = 0x00, /** Universal **/
113 regIndicationEnable_5_w = 0x0c, /** Universal **/
114 regInterruptEnable_5_w = 0x0a, /** Universal **/
115 regTxReclaimThresh_5_b = 0x09, /** 905B Revision Only **/
116 regRxFilter_5_b = 0x08, /** Universal **/
117 regRxEarlyThresh_5_w = 0x06, /** Universal **/
118 regTxStartThresh_5_w = 0x00, /** Universal **/
123 regUpperBytesOk_4_b = 0x0d, /** Universal **/
124 regBadSSD_4_b = 0x0c, /** Universal **/
125 regMediaStatus_4_w = 0x0a, /** Universal with Exceptions, pg 201 **/
126 regPhysicalMgmt_4_w = 0x08, /** Universal **/
127 regNetworkDiagnostic_4_w = 0x06, /** Universal with Exceptions, pg 203 **/
128 regFifoDiagnostic_4_w = 0x04, /** Universal with Exceptions, pg 196 **/
129 regVcoDiagnostic_4_w = 0x02, /** Undocumented? **/
134 regTxFree_3_w = 0x0c, /** Universal **/
135 regRxFree_3_w = 0x0a, /** Universal with Exceptions, pg 125 **/
136 regResetMediaOptions_3_w = 0x08, /** Media Options on B Revision, **/
137 /** Reset Options on Non-B Revision **/
138 regMacControl_3_w = 0x06, /** Universal with Exceptions, pg 199 **/
139 regMaxPktSize_3_w = 0x04, /** 905B Revision Only **/
140 regInternalConfig_3_l = 0x00, /** Universal, different bit **/
141 /** definitions, pg 59 **/
146 regResetOptions_2_w = 0x0c, /** 905B Revision Only **/
147 regStationMask_2_3w = 0x06, /** Universal with Exceptions, pg 127 **/
148 regStationAddress_2_3w = 0x00, /** Universal with Exceptions, pg 127 **/
153 regRxStatus_1_w = 0x0a, /** 90X Revision Only, Pg 126 **/
158 regEepromData_0_w = 0x0c, /** Universal **/
159 regEepromCommand_0_w = 0x0a, /** Universal **/
160 regBiosRomData_0_b = 0x08, /** 905B Revision Only **/
161 regBiosRomAddr_0_l = 0x04, /** 905B Revision Only **/
165 /*** The names for the eight register windows ***/
168 winPowerVlan7 = 0x07,
169 winStatistics6 = 0x06,
170 winTxRxControl5 = 0x05,
171 winDiagnostics4 = 0x04,
172 winTxRxOptions3 = 0x03,
173 winAddressing2 = 0x02,
175 winEepromBios0 = 0x00,
179 /*** Command definitions for the 3c90X ***/
182 cmdGlobalReset = 0x00, /** Universal with Exceptions, pg 151 **/
183 cmdSelectRegisterWindow = 0x01, /** Universal **/
184 cmdEnableDcConverter = 0x02, /** **/
185 cmdRxDisable = 0x03, /** **/
186 cmdRxEnable = 0x04, /** Universal **/
187 cmdRxReset = 0x05, /** Universal **/
188 cmdStallCtl = 0x06, /** Universal **/
189 cmdTxEnable = 0x09, /** Universal **/
190 cmdTxDisable = 0x0A, /** **/
191 cmdTxReset = 0x0B, /** Universal **/
192 cmdRequestInterrupt = 0x0C, /** **/
193 cmdAcknowledgeInterrupt = 0x0D, /** Universal **/
194 cmdSetInterruptEnable = 0x0E, /** Universal **/
195 cmdSetIndicationEnable = 0x0F, /** Universal **/
196 cmdSetRxFilter = 0x10, /** Universal **/
197 cmdSetRxEarlyThresh = 0x11, /** **/
198 cmdSetTxStartThresh = 0x13, /** **/
199 cmdStatisticsEnable = 0x15, /** **/
200 cmdStatisticsDisable = 0x16, /** **/
201 cmdDisableDcConverter = 0x17, /** **/
202 cmdSetTxReclaimThresh = 0x18, /** **/
203 cmdSetHashFilterBit = 0x19, /** **/
207 /*** Values for int status register bitmask **/
208 #define INT_INTERRUPTLATCH (1<<0)
209 #define INT_HOSTERROR (1<<1)
210 #define INT_TXCOMPLETE (1<<2)
211 #define INT_RXCOMPLETE (1<<4)
212 #define INT_RXEARLY (1<<5)
213 #define INT_INTREQUESTED (1<<6)
214 #define INT_UPDATESTATS (1<<7)
215 #define INT_LINKEVENT (1<<8)
216 #define INT_DNCOMPLETE (1<<9)
217 #define INT_UPCOMPLETE (1<<10)
218 #define INT_CMDINPROGRESS (1<<12)
219 #define INT_WINDOWNUMBER (7<<13)
221 /* These structures are all 64-bit aligned, as needed for bus-mastering I/O. */
225 } segment_t __attribute__ ((aligned(8)));
230 segment_t segments[64 /* XXX magic */];
231 } txdesc_t __attribute__ ((aligned(8)));
233 /*** RX descriptor ***/
237 segment_t segments[64];
238 } rxdesc_t __attribute__ ((aligned(8)));
240 /*** Global variables ***/
243 unsigned int is3c556;
244 unsigned char isBrev;
245 unsigned char CurrentWindow;
247 unsigned char HWAddr[ETH_ALEN];
251 static struct nic nic;
253 #define _outl(v,a) outl((a),(v))
254 #define _outw(v,a) outw((a),(v))
255 #define _outb(v,a) outb((a),(v))
257 static int _issue_command(int ioaddr, int cmd, int param)
259 outw(ioaddr + regCommandIntStatus_w, (cmd << 11) | param);
261 while (inw(ioaddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
268 /*** a3c90x_internal_SetWindow: selects a register window set.
270 static int _set_window(int ioaddr, int window)
272 if (INF_3C90X.CurrentWindow == window)
275 _issue_command(ioaddr, cmdSelectRegisterWindow, window);
276 INF_3C90X.CurrentWindow = window;
282 /*** a3c90x_internal_ReadEeprom - read data from the serial eeprom.
284 static unsigned short
285 a3c90x_internal_ReadEeprom(int ioaddr, int address)
289 /** Select correct window **/
290 _set_window(INF_3C90X.IOAddr, winEepromBios0);
292 /** Make sure the eeprom isn't busy **/
296 for (i = 0; i < 165; i++)
297 inb(0x80); /* wait 165 usec */
299 while(0x8000 & inw(ioaddr + regEepromCommand_0_w));
301 /** Read the value. **/
302 if (INF_3C90X.is3c556)
303 _outw(address + (0x230), ioaddr + regEepromCommand_0_w);
305 _outw(address + 0x80, ioaddr + regEepromCommand_0_w);
310 for (i = 0; i < 165; i++)
311 inb(0x80); /* wait 165 usec */
313 while(0x8000 & inw(ioaddr + regEepromCommand_0_w));
314 val = inw(ioaddr + regEepromData_0_w);
320 #ifdef CFG_3C90X_BOOTROM_FIX
321 /*** a3c90x_internal_WriteEepromWord - write a physical word of
322 *** data to the onboard serial eeprom (not the BIOS prom, but the
323 *** nvram in the card that stores, among other things, the MAC
327 a3c90x_internal_WriteEepromWord(int ioaddr, int address, unsigned short value)
329 /** Select register window **/
330 _set_window(ioaddr, winEepromBios0);
332 /** Verify Eeprom not busy **/
333 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
335 /** Issue WriteEnable, and wait for completion. **/
336 _outw(0x30, ioaddr + regEepromCommand_0_w);
337 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
339 /** Issue EraseRegister, and wait for completion. **/
340 _outw(address + ((0x03)<<6), ioaddr + regEepromCommand_0_w);
341 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
343 /** Send the new data to the eeprom, and wait for completion. **/
344 _outw(value, ioaddr + regEepromData_0_w);
345 _outw(0x30, ioaddr + regEepromCommand_0_w);
346 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
348 /** Burn the new data into the eeprom, and wait for completion. **/
349 _outw(address + ((0x01)<<6), ioaddr + regEepromCommand_0_w);
350 while((1<<15) & inw(ioaddr + regEepromCommand_0_w));
356 #ifdef CFG_3C90X_BOOTROM_FIX
357 /*** a3c90x_internal_WriteEeprom - write data to the serial eeprom,
358 *** and re-compute the eeprom checksum.
361 a3c90x_internal_WriteEeprom(int ioaddr, int address, unsigned short value)
365 int maxAddress, cksumAddress;
367 if (INF_3C90X.isBrev)
378 /** Write the value. **/
379 if (a3c90x_internal_WriteEepromWord(ioaddr, address, value) == -1)
382 /** Recompute the checksum. **/
383 for(i=0;i<=maxAddress;i++)
385 v = a3c90x_internal_ReadEeprom(ioaddr, i);
387 cksum ^= ((v>>8) & 0xFF);
389 /** Write the checksum to the location in the eeprom **/
390 if (a3c90x_internal_WriteEepromWord(ioaddr, cksumAddress, cksum) == -1)
397 /*** a3c90x_reset: exported function that resets the card to its default
398 *** state. This is so the Linux driver can re-set the card up the way
399 *** it wants to. If CFG_3C90X_PRESERVE_XCVR is defined, then the reset will
400 *** not alter the selected transceiver that we used to download the boot
403 static void a3c90x_reset(void)
405 /** Send the reset command to the card **/
406 outputf("3c90x: issuing RESET");
407 _issue_command(INF_3C90X.IOAddr, cmdGlobalReset, 0);
409 /** global reset command resets station mask, non-B revision cards
410 ** require explicit reset of values
412 _set_window(INF_3C90X.IOAddr, winAddressing2);
413 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
414 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
415 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
417 /** Issue transmit reset, wait for command completion **/
418 _issue_command(INF_3C90X.IOAddr, cmdTxReset, 0);
419 if (! INF_3C90X.isBrev)
420 _outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
421 _issue_command(INF_3C90X.IOAddr, cmdTxEnable, 0);
424 ** reset of the receiver on B-revision cards re-negotiates the link
425 ** takes several seconds (a computer eternity)
427 if (INF_3C90X.isBrev)
428 _issue_command(INF_3C90X.IOAddr, cmdRxReset, 0x04);
430 _issue_command(INF_3C90X.IOAddr, cmdRxReset, 0x00);
431 while (inw(INF_3C90X.IOAddr + regCommandIntStatus_w) & INT_CMDINPROGRESS)
433 _issue_command(INF_3C90X.IOAddr, cmdRxEnable, 0);
435 _issue_command(INF_3C90X.IOAddr, cmdSetInterruptEnable, 0);
436 /** enable rxComplete and txComplete **/
437 _issue_command(INF_3C90X.IOAddr, cmdSetIndicationEnable, 0x0014);
438 /** acknowledge any pending status flags **/
439 _issue_command(INF_3C90X.IOAddr, cmdAcknowledgeInterrupt, 0x661);
444 /***************************** Transmit routines *****************************/
448 static txdesc_t txdescs[XMIT_BUFS];
449 static struct pbuf *txpbufs[XMIT_BUFS] = {0,};
451 /* txcons is the index into the ring buffer of the last packet that the
452 * 3c90x was seen processing, or -1 if the 3c90x was idle.
454 static int txcons = -1;
456 /* txprod is the index of the _next_ buffer that the driver will write into. */
457 static int txprod = 0;
459 /* _transmit adds a packet to the transmit ring buffer. If no space is
460 * available in the buffer, then _transmit blocks until a packet has been
463 static void _transmit(struct pbuf *p)
465 unsigned char status;
468 /* Wait for there to be space. */
469 if (txcons == txprod)
473 outputf("3c90x: txbuf full, waiting for space...");
474 while (inl(INF_3C90X.IOAddr + regDnListPtr_l) != 0)
476 outputf("3c90x: took %d iters", i);
479 /* Stall the download engine so it doesn't bother us. */
480 _issue_command(INF_3C90X.IOAddr, cmdStallCtl, 2 /* Stall download */);
482 /* Clean up old txcons. */
485 unsigned long curp = inl(INF_3C90X.IOAddr + regDnListPtr_l);
491 end = (curp - v2p(txdescs)) / sizeof(txdescs[0]);
493 while (txcons != end)
495 pbuf_free(txpbufs[txcons]);
496 txpbufs[txcons] = NULL;
497 txdescs[txcons].hdr = 0;
498 txdescs[txcons].next = 0;
499 txcons = (txcons + 1) % XMIT_BUFS;
501 if (txcons == txprod)
505 /* Look at the TX status */
506 status = inb(INF_3C90X.IOAddr + regTxStatus_b);
509 outputf("3c90x: error: the nus.");
510 outb(INF_3C90X.IOAddr + regTxStatus_b, 0x00);
513 /* Set up the new txdesc. */
514 txdescs[txprod].next = 0;
518 for (; p; p = p->next)
520 txdescs[txprod].segments[n].addr = v2p(p->payload);
521 txdescs[txprod].segments[n].len = p->len | (p->next ? 0 : (1 << 31));
526 txdescs[txprod].hdr = len; /* If we wanted completion notification, bit 15 */
528 /* Now link the new one in, after it's been set up. */
529 txdescs[(txprod + XMIT_BUFS - 1) % XMIT_BUFS].next = v2p(&(txdescs[txprod]));
531 /* If the card is stopped, start it up again. */
532 if (inl(INF_3C90X.IOAddr + regDnListPtr_l) == 0)
534 outl(INF_3C90X.IOAddr + regDnListPtr_l, v2p(&(txdescs[txprod])));
538 txprod = (txprod + 1) % XMIT_BUFS;
540 /* And let it proceed on its way. */
541 _issue_command(INF_3C90X.IOAddr, cmdStallCtl, 3 /* Unstall download */);
544 /** successful completion (sans "interrupt Requested" bit) **/
545 if ((status & 0xbf) == 0x80)
548 outputf("3c90x: Status (%hhX)", status);
549 /** check error codes **/
552 outputf("3c90x: Tx Reclaim Error (%hhX)", status);
554 } else if (status & 0x04) {
555 outputf("3c90x: Tx Status Overflow (%hhX)", status);
557 _outb(0x00, INF_3C90X.IOAddr + regTxStatus_b);
558 /** must re-enable after max collisions before re-issuing tx **/
559 _issue_command(INF_3C90X.IOAddr, cmdTxEnable, 0);
560 } else if (status & 0x08) {
561 outputf("3c90x: Tx Max Collisions (%hhX)", status);
562 /** must re-enable after max collisions before re-issuing tx **/
563 _issue_command(INF_3C90X.IOAddr, cmdTxEnable, 0);
564 } else if (status & 0x10) {
565 outputf("3c90x: Tx Underrun (%hhX)", status);
567 } else if (status & 0x20) {
568 outputf("3c90x: Tx Jabber (%hhX)", status);
570 } else if ((status & 0x80) != 0x80) {
571 outputf("3c90x: Internal Error - Incomplete Transmission (%hhX)", status);
577 /***************************** Receive routines *****************************/
578 #define MAX_RECV_SIZE 1536
581 static rxdesc_t rxdescs[RECV_BUFS];
582 static struct pbuf *rxpbufs[RECV_BUFS] = {0,};
584 /* rxcons is the pointer to the receive descriptor that the ethernet card will
587 static int rxcons = 0;
589 /* rxprod is the pointer to the receive descriptor that the driver will
592 static int rxprod = 0;
594 /* _recv_prepare fills the 3c90x's ring buffer with fresh pbufs from lwIP.
595 * The upload engine need not be stalled.
597 static void _recv_prepare(struct nic *nic)
602 while ((rxprod != rxcons) || !rxpbufs[rxprod])
607 if (!rxpbufs[rxprod])
608 rxpbufs[rxprod] = p = pbuf_alloc(PBUF_RAW, MAX_RECV_SIZE, PBUF_POOL);
610 outputf("WARNING: 3c90x has pbuf in slot %d", rxprod);
616 outputf("3c90x: out of memory for rx pbuf?");
620 rxdescs[rxprod].status = 0;
621 rxdescs[rxprod].next = 0;
622 for (i = 0; p; p = p->next, i++)
624 rxdescs[rxprod].segments[i].addr = v2p(p->payload);
625 rxdescs[rxprod].segments[i].len = p->len | (p->next ? 0 : (1 << 31));
628 /* Hook in the new one after and only after it's been fully set up. */
629 rxdescs[(rxprod + RECV_BUFS - 1) % RECV_BUFS].next = v2p(&(rxdescs[rxprod]));
630 rxprod = (rxprod + 1) % RECV_BUFS;
633 if (inl(INF_3C90X.IOAddr + regUpListPtr_l) == 0 && rxpbufs[oldprod]) /* Ran out of shit, and got new shit? */
635 outl(INF_3C90X.IOAddr + regUpListPtr_l, v2p(&rxdescs[oldprod]));
636 outputf("3c90x: WARNING: Ran out of rx slots");
641 /* _recv polls the ring buffer to see if any packets are available. If any
642 * are, then eth_recv is called for each available. _recv returns how many
643 * packets it received successfully. Whether _recv got any packets or not,
644 * _recv does not block, and reinitializes the ring buffer with fresh pbufs.
646 static int _recv(struct nic *nic)
652 while ((rxdescs[rxcons].status & ((1<<14) | (1<<15))) != 0)
654 /** Check for Error (else we have good packet) **/
655 if (rxdescs[rxcons].status & (1<<14))
657 errcode = rxdescs[rxcons].status;
658 if (errcode & (1<<16))
659 outputf("3C90X: Rx Overrun (%hX)",errcode>>16);
660 else if (errcode & (1<<17))
661 outputf("3C90X: Runt Frame (%hX)",errcode>>16);
662 else if (errcode & (1<<18))
663 outputf("3C90X: Alignment Error (%hX)",errcode>>16);
664 else if (errcode & (1<<19))
665 outputf("3C90X: CRC Error (%hX)",errcode>>16);
666 else if (errcode & (1<<20))
667 outputf("3C90X: Oversized Frame (%hX)",errcode>>16);
669 outputf("3C90X: Packet error (%hX)",errcode>>16);
672 pbuf_free(rxpbufs[rxcons]); /* Bounce the old one before setting it up again. */
675 pbuf_realloc(p, rxdescs[rxcons].status & 0x1FFF); /* Resize the packet to how large it actually is. */
678 rxpbufs[rxcons] = NULL;
679 rxdescs[rxcons].status = 0;
680 rxcons = (rxcons + 1) % RECV_BUFS;
689 _recv_prepare(nic); /* Light the NIC up again. */
693 /*** a3c90x_disable: exported routine to disable the card. What's this for?
694 *** the eepro100.c driver didn't have one, so I just left this one empty too.
696 *** Must turn off receiver at least so stray packets will not corrupt memory
699 void a3c90x_disable(struct dev *dev)
701 /* reset and disable merge */
703 /* Disable the receiver and transmitter. */
704 _outw(cmdRxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
705 _outw(cmdTxDisable, INF_3C90X.IOAddr + regCommandIntStatus_w);
709 /*** a3c90x_probe: exported routine to probe for the 3c905 card and perform
710 *** initialization. If this routine is called, the pci functions did find the
711 *** card. We just have to init it here.
713 static int a3c90x_probe(struct pci_dev * pci, void * data)
715 INF_3C90X.is3c556 = (pci->did == 0x6055);
718 unsigned short eeprom[0x100];
722 unsigned short linktype;
723 #define HWADDR_OFFSET 10
725 unsigned long ioaddr = 0;
726 for (i = 0; i < 6; i++) {
727 if (pci->bars[i].type == PCI_BAR_IO) {
728 ioaddr = pci->bars[i].addr;
735 outputf("3c90x: Unable to find I/O address");
740 pci_write16(pci->bus, pci->dev, pci->fn, 0xE0,
741 pci_read16(pci->bus, pci->dev, pci->fn, 0xE0) & ~0x3);
743 outputf("3c90x: Picked I/O address %04x", ioaddr);
745 nic.ioaddr = ioaddr & ~3;
748 INF_3C90X.IOAddr = ioaddr;
749 INF_3C90X.CurrentWindow = 255;
750 switch (a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, 0x03))
752 case 0x9000: /** 10 Base TPO **/
753 case 0x9001: /** 10/100 T4 **/
754 case 0x9050: /** 10/100 TPO **/
755 case 0x9051: /** 10 Base Combo **/
756 INF_3C90X.isBrev = 0;
759 case 0x9004: /** 10 Base TPO **/
760 case 0x9005: /** 10 Base Combo **/
761 case 0x9006: /** 10 Base TPO and Base2 **/
762 case 0x900A: /** 10 Base FL **/
763 case 0x9055: /** 10/100 TPO **/
764 case 0x9056: /** 10/100 T4 **/
765 case 0x905A: /** 10 Base FX **/
767 INF_3C90X.isBrev = 1;
771 /** Load the EEPROM contents **/
772 if (INF_3C90X.isBrev)
774 for(i=0;i<=/*0x20*/0x7F;i++)
776 eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
779 #ifdef CFG_3C90X_BOOTROM_FIX
780 /** Set xcvrSelect in InternalConfig in eeprom. **/
781 /* only necessary for 3c905b revision cards with boot PROM bug!!! */
782 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x13, 0x0160);
785 #ifdef CFG_3C90X_XCVR
786 if (CFG_3C90X_XCVR == 255)
788 /** Clear the LanWorks register **/
789 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16, 0);
793 /** Set the selected permanent-xcvrSelect in the
796 a3c90x_internal_WriteEeprom(INF_3C90X.IOAddr, 0x16,
797 XCVR_MAGIC + ((CFG_3C90X_XCVR) & 0x000F));
803 for(i=0;i<=/*0x17*/0x7F;i++)
805 eeprom[i] = a3c90x_internal_ReadEeprom(INF_3C90X.IOAddr, i);
809 /** Print identification message **/
810 #ifdef CFG_3C90X_BOOTROM_FIX
811 if (INF_3C90X.isBrev)
813 outputf("NOTE: 3c905b bootrom fix enabled; has side "
814 "effects. See 3c90x.txt for info.");
818 /** Retrieve the Hardware address and print it on the screen. **/
819 INF_3C90X.HWAddr[0] = eeprom[HWADDR_OFFSET + 0]>>8;
820 INF_3C90X.HWAddr[1] = eeprom[HWADDR_OFFSET + 0]&0xFF;
821 INF_3C90X.HWAddr[2] = eeprom[HWADDR_OFFSET + 1]>>8;
822 INF_3C90X.HWAddr[3] = eeprom[HWADDR_OFFSET + 1]&0xFF;
823 INF_3C90X.HWAddr[4] = eeprom[HWADDR_OFFSET + 2]>>8;
824 INF_3C90X.HWAddr[5] = eeprom[HWADDR_OFFSET + 2]&0xFF;
825 outputf("MAC Address = %02x:%02x:%02x:%02x:%02x:%02x",
831 INF_3C90X.HWAddr[5]);
833 /** 3C556: Invert MII power **/
834 if (INF_3C90X.is3c556) {
836 _set_window(INF_3C90X.IOAddr, winAddressing2);
837 tmp = inw(INF_3C90X.IOAddr + regResetOptions_2_w);
839 _outw(tmp, INF_3C90X.IOAddr + regResetOptions_2_w);
842 /* Test if the link is good, if not continue */
843 _set_window(INF_3C90X.IOAddr, winDiagnostics4);
844 mstat = inw(INF_3C90X.IOAddr + regMediaStatus_4_w);
845 if((mstat & (1<<11)) == 0) {
846 outputf("Valid link not established");
850 /** Program the MAC address into the station address registers **/
851 _set_window(INF_3C90X.IOAddr, winAddressing2);
852 _outw(htons(eeprom[HWADDR_OFFSET + 0]), INF_3C90X.IOAddr + regStationAddress_2_3w);
853 _outw(htons(eeprom[HWADDR_OFFSET + 1]), INF_3C90X.IOAddr + regStationAddress_2_3w+2);
854 _outw(htons(eeprom[HWADDR_OFFSET + 2]), INF_3C90X.IOAddr + regStationAddress_2_3w+4);
855 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+0);
856 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+2);
857 _outw(0, INF_3C90X.IOAddr + regStationMask_2_3w+4);
859 /** Read the media options register, print a message and set default
862 ** Uses Media Option command on B revision, Reset Option on non-B
863 ** revision cards -- same register address
865 _set_window(INF_3C90X.IOAddr, winTxRxOptions3);
866 mopt = inw(INF_3C90X.IOAddr + regResetMediaOptions_3_w);
868 /** mask out VCO bit that is defined as 10baseFL bit on B-rev cards **/
869 if (! INF_3C90X.isBrev)
874 outputf("Connectors present: ");
879 outputf(" 100Base-T4");
884 outputf(" 100Base-FX");
889 outputf(" 10Base-2");
902 if ((mopt & 0xA) == 0xA)
904 outputf(" 10Base-T / 100Base-TX");
907 else if ((mopt & 0xA) == 0x2)
909 outputf(" 100Base-TX");
912 else if ((mopt & 0xA) == 0x8)
914 outputf(" 10Base-T");
918 /** Determine transceiver type to use, depending on value stored in
921 if (INF_3C90X.isBrev)
923 if ((eeprom[0x16] & 0xFF00) == XCVR_MAGIC)
926 linktype = eeprom[0x16] & 0x000F;
931 #ifdef CFG_3C90X_XCVR
932 if (CFG_3C90X_XCVR != 255)
933 linktype = CFG_3C90X_XCVR;
934 #endif /* CFG_3C90X_XCVR */
936 /** I don't know what MII MAC only mode is!!! **/
937 if (linktype == 0x0009)
939 if (INF_3C90X.isBrev)
940 outputf("WARNING: MII External MAC Mode only supported on B-revision "
941 "cards!!!!\nFalling Back to MII Mode\n");
946 /** enable DC converter for 10-Base-T **/
947 if (linktype == 0x0003)
949 _issue_command(INF_3C90X.IOAddr, cmdEnableDcConverter, 0);
952 /** Set the link to the type we just determined. **/
953 _set_window(INF_3C90X.IOAddr, winTxRxOptions3);
954 cfg = inl(INF_3C90X.IOAddr + regInternalConfig_3_l);
956 cfg |= (linktype<<20);
957 _outl(cfg, INF_3C90X.IOAddr + regInternalConfig_3_l);
959 /** Now that we set the xcvr type, reset the Tx and Rx, re-enable. **/
960 _issue_command(INF_3C90X.IOAddr, cmdTxReset, 0);
961 if (!INF_3C90X.isBrev)
962 _outb(0x01, INF_3C90X.IOAddr + regTxFreeThresh_b);
964 _issue_command(INF_3C90X.IOAddr, cmdTxEnable, 0);
967 ** reset of the receiver on B-revision cards re-negotiates the link
968 ** takes several seconds (a computer eternity)
970 if (INF_3C90X.isBrev)
971 _issue_command(INF_3C90X.IOAddr, cmdRxReset, 0x04);
973 _issue_command(INF_3C90X.IOAddr, cmdRxReset, 0x00);
975 /** Set the RX filter = receive only individual pkts & multicast & bcast. **/
976 _issue_command(INF_3C90X.IOAddr, cmdSetRxFilter, 0x01 + 0x02 + 0x04);
978 /* Stick some packets in the queue. */
981 /* And light up the RX engine. */
982 _issue_command(INF_3C90X.IOAddr, cmdRxEnable, 0);
985 ** set Indication and Interrupt flags , acknowledge any IRQ's
987 _issue_command(INF_3C90X.IOAddr, cmdSetInterruptEnable, 0);
988 _issue_command(INF_3C90X.IOAddr, cmdSetIndicationEnable, 0x0014);
989 _issue_command(INF_3C90X.IOAddr, cmdAcknowledgeInterrupt, 0x661);
991 /* * Set our exported functions **/
993 nic.transmit = _transmit;
994 memcpy(nic.hwaddr, INF_3C90X.HWAddr, 6);
1000 static struct pci_id a3c90x_nics[] = {
1001 /* Original 90x revisions: */
1002 PCI_ROM(0x10b7, 0x6055, "3c556", "3C556"), /* Huricane */
1003 PCI_ROM(0x10b7, 0x9000, "3c905-tpo", "3Com900-TPO"), /* 10 Base TPO */
1004 PCI_ROM(0x10b7, 0x9001, "3c905-t4", "3Com900-Combo"), /* 10/100 T4 */
1005 PCI_ROM(0x10b7, 0x9050, "3c905-tpo100", "3Com905-TX"), /* 100 Base TX / 10/100 TPO */
1006 PCI_ROM(0x10b7, 0x9051, "3c905-combo", "3Com905-T4"), /* 100 Base T4 / 10 Base Combo */
1007 /* Newer 90xB revisions: */
1008 PCI_ROM(0x10b7, 0x9004, "3c905b-tpo", "3Com900B-TPO"), /* 10 Base TPO */
1009 PCI_ROM(0x10b7, 0x9005, "3c905b-combo", "3Com900B-Combo"), /* 10 Base Combo */
1010 PCI_ROM(0x10b7, 0x9006, "3c905b-tpb2", "3Com900B-2/T"), /* 10 Base TP and Base2 */
1011 PCI_ROM(0x10b7, 0x900a, "3c905b-fl", "3Com900B-FL"), /* 10 Base FL */
1012 PCI_ROM(0x10b7, 0x9055, "3c905b-tpo100", "3Com905B-TX"), /* 10/100 TPO */
1013 PCI_ROM(0x10b7, 0x9056, "3c905b-t4", "3Com905B-T4"), /* 10/100 T4 */
1014 PCI_ROM(0x10b7, 0x9058, "3c905b-9058", "3Com905B-9058"), /* Cyclone 10/100/BNC */
1015 PCI_ROM(0x10b7, 0x905a, "3c905b-fx", "3Com905B-FL"), /* 100 Base FX / 10 Base FX */
1016 /* Newer 90xC revision: */
1017 PCI_ROM(0x10b7, 0x9200, "3c905c-tpo", "3Com905C-TXM"), /* 10/100 TPO (3C905C-TXM) */
1018 PCI_ROM(0x10b7, 0x9202, "3c920b-emb-ati", "3c920B-EMB-WNM (ATI Radeon 9100 IGP)"), /* 3c920B-EMB-WNM (ATI Radeon 9100 IGP) */
1019 PCI_ROM(0x10b7, 0x9210, "3c920b-emb-wnm","3Com20B-EMB WNM"),
1020 PCI_ROM(0x10b7, 0x9800, "3c980", "3Com980-Cyclone"), /* Cyclone */
1021 PCI_ROM(0x10b7, 0x9805, "3c9805", "3Com9805"), /* Dual Port Server Cyclone */
1022 PCI_ROM(0x10b7, 0x7646, "3csoho100-tx", "3CSOHO100-TX"), /* Hurricane */
1023 PCI_ROM(0x10b7, 0x4500, "3c450", "3Com450 HomePNA Tornado"),
1024 PCI_ROM(0x10b7, 0x1201, "3c982a", "3Com982A"),
1025 PCI_ROM(0x10b7, 0x1202, "3c982b", "3Com982B"),
1028 struct pci_driver a3c90x_driver = {
1030 .probe = a3c90x_probe,
1032 .id_count = sizeof(a3c90x_nics)/sizeof(a3c90x_nics[0]),