00001 /* de4x5.c: A DIGITAL DC21x4x DECchip and DE425/DE434/DE435/DE450/DE500 00002 ethernet driver for Linux. 00003 00004 Copyright 1994, 1995 Digital Equipment Corporation. 00005 00006 Testing resources for this driver have been made available 00007 in part by NASA Ames Research Center (mjacob@nas.nasa.gov). 00008 00009 The author may be reached at davies@maniac.ultranet.com. 00010 00011 This program is free software; you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 option) any later version. 00015 00016 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00017 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00019 NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00022 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00023 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 00027 You should have received a copy of the GNU General Public License along 00028 with this program; if not, write to the Free Software Foundation, Inc., 00029 675 Mass Ave, Cambridge, MA 02139, USA. 00030 00031 Originally, this driver was written for the Digital Equipment 00032 Corporation series of EtherWORKS ethernet cards: 00033 00034 DE425 TP/COAX EISA 00035 DE434 TP PCI 00036 DE435 TP/COAX/AUI PCI 00037 DE450 TP/COAX/AUI PCI 00038 DE500 10/100 PCI Fasternet 00039 00040 but it will now attempt to support all cards which conform to the 00041 Digital Semiconductor SROM Specification. The driver currently 00042 recognises the following chips: 00043 00044 DC21040 (no SROM) 00045 DC21041[A] 00046 DC21140[A] 00047 DC21142 00048 DC21143 00049 00050 So far the driver is known to work with the following cards: 00051 00052 KINGSTON 00053 Linksys 00054 ZNYX342 00055 SMC8432 00056 SMC9332 (w/new SROM) 00057 ZNYX31[45] 00058 ZNYX346 10/100 4 port (can act as a 10/100 bridge!) 00059 00060 The driver has been tested on a relatively busy network using the DE425, 00061 DE434, DE435 and DE500 cards and benchmarked with 'ttcp': it transferred 00062 16M of data to a DECstation 5000/200 as follows: 00063 00064 TCP UDP 00065 TX RX TX RX 00066 DE425 1030k 997k 1170k 1128k 00067 DE434 1063k 995k 1170k 1125k 00068 DE435 1063k 995k 1170k 1125k 00069 DE500 1063k 998k 1170k 1125k in 10Mb/s mode 00070 00071 All values are typical (in kBytes/sec) from a sample of 4 for each 00072 measurement. Their error is +/-20k on a quiet (private) network and also 00073 depend on what load the CPU has. 00074 00075 ========================================================================= 00076 This driver has been written substantially from scratch, although its 00077 inheritance of style and stack interface from 'ewrk3.c' and in turn from 00078 Donald Becker's 'lance.c' should be obvious. With the module autoload of 00079 every usable DECchip board, I pinched Donald's 'next_module' field to 00080 link my modules together. 00081 00082 Upto 15 EISA cards can be supported under this driver, limited primarily 00083 by the available IRQ lines. I have checked different configurations of 00084 multiple depca, EtherWORKS 3 cards and de4x5 cards and have not found a 00085 problem yet (provided you have at least depca.c v0.38) ... 00086 00087 PCI support has been added to allow the driver to work with the DE434, 00088 DE435, DE450 and DE500 cards. The I/O accesses are a bit of a kludge due 00089 to the differences in the EISA and PCI CSR address offsets from the base 00090 address. 00091 00092 The ability to load this driver as a loadable module has been included 00093 and used extensively during the driver development (to save those long 00094 reboot sequences). Loadable module support under PCI and EISA has been 00095 achieved by letting the driver autoprobe as if it were compiled into the 00096 kernel. Do make sure you're not sharing interrupts with anything that 00097 cannot accommodate interrupt sharing! 00098 00099 To utilise this ability, you have to do 8 things: 00100 00101 0) have a copy of the loadable modules code installed on your system. 00102 1) copy de4x5.c from the /linux/drivers/net directory to your favourite 00103 temporary directory. 00104 2) for fixed autoprobes (not recommended), edit the source code near 00105 line 5594 to reflect the I/O address you're using, or assign these when 00106 loading by: 00107 00108 insmod de4x5 io=0xghh where g = bus number 00109 hh = device number 00110 00111 NB: autoprobing for modules is now supported by default. You may just 00112 use: 00113 00114 insmod de4x5 00115 00116 to load all available boards. For a specific board, still use 00117 the 'io=?' above. 00118 3) compile de4x5.c, but include -DMODULE in the command line to ensure 00119 that the correct bits are compiled (see end of source code). 00120 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a 00121 kernel with the de4x5 configuration turned off and reboot. 00122 5) insmod de4x5 [io=0xghh] 00123 6) run the net startup bits for your new eth?? interface(s) manually 00124 (usually /etc/rc.inet[12] at boot time). 00125 7) enjoy! 00126 00127 To unload a module, turn off the associated interface(s) 00128 'ifconfig eth?? down' then 'rmmod de4x5'. 00129 00130 Automedia detection is included so that in principal you can disconnect 00131 from, e.g. TP, reconnect to BNC and things will still work (after a 00132 pause whilst the driver figures out where its media went). My tests 00133 using ping showed that it appears to work.... 00134 00135 By default, the driver will now autodetect any DECchip based card. 00136 Should you have a need to restrict the driver to DIGITAL only cards, you 00137 can compile with a DEC_ONLY define, or if loading as a module, use the 00138 'dec_only=1' parameter. 00139 00140 I've changed the timing routines to use the kernel timer and scheduling 00141 functions so that the hangs and other assorted problems that occurred 00142 while autosensing the media should be gone. A bonus for the DC21040 00143 auto media sense algorithm is that it can now use one that is more in 00144 line with the rest (the DC21040 chip doesn't have a hardware timer). 00145 The downside is the 1 'jiffies' (10ms) resolution. 00146 00147 IEEE 802.3u MII interface code has been added in anticipation that some 00148 products may use it in the future. 00149 00150 The SMC9332 card has a non-compliant SROM which needs fixing - I have 00151 patched this driver to detect it because the SROM format used complies 00152 to a previous DEC-STD format. 00153 00154 I have removed the buffer copies needed for receive on Intels. I cannot 00155 remove them for Alphas since the Tulip hardware only does longword 00156 aligned DMA transfers and the Alphas get alignment traps with non 00157 longword aligned data copies (which makes them really slow). No comment. 00158 00159 I have added SROM decoding routines to make this driver work with any 00160 card that supports the Digital Semiconductor SROM spec. This will help 00161 all cards running the dc2114x series chips in particular. Cards using 00162 the dc2104x chips should run correctly with the basic driver. I'm in 00163 debt to <mjacob@feral.com> for the testing and feedback that helped get 00164 this feature working. So far we have tested KINGSTON, SMC8432, SMC9332 00165 (with the latest SROM complying with the SROM spec V3: their first was 00166 broken), ZNYX342 and LinkSys. ZYNX314 (dual 21041 MAC) and ZNYX 315 00167 (quad 21041 MAC) cards also appear to work despite their incorrectly 00168 wired IRQs. 00169 00170 I have added a temporary fix for interrupt problems when some SCSI cards 00171 share the same interrupt as the DECchip based cards. The problem occurs 00172 because the SCSI card wants to grab the interrupt as a fast interrupt 00173 (runs the service routine with interrupts turned off) vs. this card 00174 which really needs to run the service routine with interrupts turned on. 00175 This driver will now add the interrupt service routine as a fast 00176 interrupt if it is bounced from the slow interrupt. THIS IS NOT A 00177 RECOMMENDED WAY TO RUN THE DRIVER and has been done for a limited time 00178 until people sort out their compatibility issues and the kernel 00179 interrupt service code is fixed. YOU SHOULD SEPARATE OUT THE FAST 00180 INTERRUPT CARDS FROM THE SLOW INTERRUPT CARDS to ensure that they do not 00181 run on the same interrupt. PCMCIA/CardBus is another can of worms... 00182 00183 Finally, I think I have really fixed the module loading problem with 00184 more than one DECchip based card. As a side effect, I don't mess with 00185 the device structure any more which means that if more than 1 card in 00186 2.0.x is installed (4 in 2.1.x), the user will have to edit 00187 linux/drivers/net/Space.c to make room for them. Hence, module loading 00188 is the preferred way to use this driver, since it doesn't have this 00189 limitation. 00190 00191 Where SROM media detection is used and full duplex is specified in the 00192 SROM, the feature is ignored unless lp->params.fdx is set at compile 00193 time OR during a module load (insmod de4x5 args='eth??:fdx' [see 00194 below]). This is because there is no way to automatically detect full 00195 duplex links except through autonegotiation. When I include the 00196 autonegotiation feature in the SROM autoconf code, this detection will 00197 occur automatically for that case. 00198 00199 Command line arguments are now allowed, similar to passing arguments 00200 through LILO. This will allow a per adapter board set up of full duplex 00201 and media. The only lexical constraints are: the board name (dev->name) 00202 appears in the list before its parameters. The list of parameters ends 00203 either at the end of the parameter list or with another board name. The 00204 following parameters are allowed: 00205 00206 fdx for full duplex 00207 autosense to set the media/speed; with the following 00208 sub-parameters: 00209 TP, TP_NW, BNC, AUI, BNC_AUI, 100Mb, 10Mb, AUTO 00210 00211 Case sensitivity is important for the sub-parameters. They *must* be 00212 upper case. Examples: 00213 00214 insmod de4x5 args='eth1:fdx autosense=BNC eth0:autosense=100Mb'. 00215 00216 For a compiled in driver, at or above line 548, place e.g. 00217 #define DE4X5_PARM "eth0:fdx autosense=AUI eth2:autosense=TP" 00218 00219 Yes, I know full duplex isn't permissible on BNC or AUI; they're just 00220 examples. By default, full duplex is turned off and AUTO is the default 00221 autosense setting. In reality, I expect only the full duplex option to 00222 be used. Note the use of single quotes in the two examples above and the 00223 lack of commas to separate items. ALSO, you must get the requested media 00224 correct in relation to what the adapter SROM says it has. There's no way 00225 to determine this in advance other than by trial and error and common 00226 sense, e.g. call a BNC connectored port 'BNC', not '10Mb'. 00227 00228 Changed the bus probing. EISA used to be done first, followed by PCI. 00229 Most people probably don't even know what a de425 is today and the EISA 00230 probe has messed up some SCSI cards in the past, so now PCI is always 00231 probed first followed by EISA if a) the architecture allows EISA and 00232 either b) there have been no PCI cards detected or c) an EISA probe is 00233 forced by the user. To force a probe include "force_eisa" in your 00234 insmod "args" line; for built-in kernels either change the driver to do 00235 this automatically or include #define DE4X5_FORCE_EISA on or before 00236 line 1040 in the driver. 00237 00238 TO DO: 00239 ------ 00240 00241 Revision History 00242 ---------------- 00243 00244 Version Date Description 00245 00246 0.1 17-Nov-94 Initial writing. ALPHA code release. 00247 0.2 13-Jan-95 Added PCI support for DE435's. 00248 0.21 19-Jan-95 Added auto media detection. 00249 0.22 10-Feb-95 Fix interrupt handler call <chris@cosy.sbg.ac.at>. 00250 Fix recognition bug reported by <bkm@star.rl.ac.uk>. 00251 Add request/release_region code. 00252 Add loadable modules support for PCI. 00253 Clean up loadable modules support. 00254 0.23 28-Feb-95 Added DC21041 and DC21140 support. 00255 Fix missed frame counter value and initialisation. 00256 Fixed EISA probe. 00257 0.24 11-Apr-95 Change delay routine to use <linux/udelay>. 00258 Change TX_BUFFS_AVAIL macro. 00259 Change media autodetection to allow manual setting. 00260 Completed DE500 (DC21140) support. 00261 0.241 18-Apr-95 Interim release without DE500 Autosense Algorithm. 00262 0.242 10-May-95 Minor changes. 00263 0.30 12-Jun-95 Timer fix for DC21140. 00264 Portability changes. 00265 Add ALPHA changes from <jestabro@ant.tay1.dec.com>. 00266 Add DE500 semi automatic autosense. 00267 Add Link Fail interrupt TP failure detection. 00268 Add timer based link change detection. 00269 Plugged a memory leak in de4x5_queue_pkt(). 00270 0.31 13-Jun-95 Fixed PCI stuff for 1.3.1. 00271 0.32 26-Jun-95 Added verify_area() calls in de4x5_ioctl() from a 00272 suggestion by <heiko@colossus.escape.de>. 00273 0.33 8-Aug-95 Add shared interrupt support (not released yet). 00274 0.331 21-Aug-95 Fix de4x5_open() with fast CPUs. 00275 Fix de4x5_interrupt(). 00276 Fix dc21140_autoconf() mess. 00277 No shared interrupt support. 00278 0.332 11-Sep-95 Added MII management interface routines. 00279 0.40 5-Mar-96 Fix setup frame timeout <maartenb@hpkuipc.cern.ch>. 00280 Add kernel timer code (h/w is too flaky). 00281 Add MII based PHY autosense. 00282 Add new multicasting code. 00283 Add new autosense algorithms for media/mode 00284 selection using kernel scheduling/timing. 00285 Re-formatted. 00286 Made changes suggested by <jeff@router.patch.net>: 00287 Change driver to detect all DECchip based cards 00288 with DEC_ONLY restriction a special case. 00289 Changed driver to autoprobe as a module. No irq 00290 checking is done now - assume BIOS is good! 00291 Added SMC9332 detection <manabe@Roy.dsl.tutics.ac.jp> 00292 0.41 21-Mar-96 Don't check for get_hw_addr checksum unless DEC card 00293 only <niles@axp745gsfc.nasa.gov> 00294 Fix for multiple PCI cards reported by <jos@xos.nl> 00295 Duh, put the SA_SHIRQ flag into request_interrupt(). 00296 Fix SMC ethernet address in enet_det[]. 00297 Print chip name instead of "UNKNOWN" during boot. 00298 0.42 26-Apr-96 Fix MII write TA bit error. 00299 Fix bug in dc21040 and dc21041 autosense code. 00300 Remove buffer copies on receive for Intels. 00301 Change sk_buff handling during media disconnects to 00302 eliminate DUP packets. 00303 Add dynamic TX thresholding. 00304 Change all chips to use perfect multicast filtering. 00305 Fix alloc_device() bug <jari@markkus2.fimr.fi> 00306 0.43 21-Jun-96 Fix unconnected media TX retry bug. 00307 Add Accton to the list of broken cards. 00308 Fix TX under-run bug for non DC21140 chips. 00309 Fix boot command probe bug in alloc_device() as 00310 reported by <koen.gadeyne@barco.com> and 00311 <orava@nether.tky.hut.fi>. 00312 Add cache locks to prevent a race condition as 00313 reported by <csd@microplex.com> and 00314 <baba@beckman.uiuc.edu>. 00315 Upgraded alloc_device() code. 00316 0.431 28-Jun-96 Fix potential bug in queue_pkt() from discussion 00317 with <csd@microplex.com> 00318 0.44 13-Aug-96 Fix RX overflow bug in 2114[023] chips. 00319 Fix EISA probe bugs reported by <os2@kpi.kharkov.ua> 00320 and <michael@compurex.com>. 00321 0.441 9-Sep-96 Change dc21041_autoconf() to probe quiet BNC media 00322 with a loopback packet. 00323 0.442 9-Sep-96 Include AUI in dc21041 media printout. Bug reported 00324 by <bhat@mundook.cs.mu.OZ.AU> 00325 0.45 8-Dec-96 Include endian functions for PPC use, from work 00326 by <cort@cs.nmt.edu> and <g.thomas@opengroup.org>. 00327 0.451 28-Dec-96 Added fix to allow autoprobe for modules after 00328 suggestion from <mjacob@feral.com>. 00329 0.5 30-Jan-97 Added SROM decoding functions. 00330 Updated debug flags. 00331 Fix sleep/wakeup calls for PCI cards, bug reported 00332 by <cross@gweep.lkg.dec.com>. 00333 Added multi-MAC, one SROM feature from discussion 00334 with <mjacob@feral.com>. 00335 Added full module autoprobe capability. 00336 Added attempt to use an SMC9332 with broken SROM. 00337 Added fix for ZYNX multi-mac cards that didn't 00338 get their IRQs wired correctly. 00339 0.51 13-Feb-97 Added endian fixes for the SROM accesses from 00340 <paubert@iram.es> 00341 Fix init_connection() to remove extra device reset. 00342 Fix MAC/PHY reset ordering in dc21140m_autoconf(). 00343 Fix initialisation problem with lp->timeout in 00344 typeX_infoblock() from <paubert@iram.es>. 00345 Fix MII PHY reset problem from work done by 00346 <paubert@iram.es>. 00347 0.52 26-Apr-97 Some changes may not credit the right people - 00348 a disk crash meant I lost some mail. 00349 Change RX interrupt routine to drop rather than 00350 defer packets to avoid hang reported by 00351 <g.thomas@opengroup.org>. 00352 Fix srom_exec() to return for COMPACT and type 1 00353 infoblocks. 00354 Added DC21142 and DC21143 functions. 00355 Added byte counters from <phil@tazenda.demon.co.uk> 00356 Added SA_INTERRUPT temporary fix from 00357 <mjacob@feral.com>. 00358 0.53 12-Nov-97 Fix the *_probe() to include 'eth??' name during 00359 module load: bug reported by 00360 <Piete.Brooks@cl.cam.ac.uk> 00361 Fix multi-MAC, one SROM, to work with 2114x chips: 00362 bug reported by <cmetz@inner.net>. 00363 Make above search independent of BIOS device scan 00364 direction. 00365 Completed DC2114[23] autosense functions. 00366 0.531 21-Dec-97 Fix DE500-XA 100Mb/s bug reported by 00367 <robin@intercore.com 00368 Fix type1_infoblock() bug introduced in 0.53, from 00369 problem reports by 00370 <parmee@postecss.ncrfran.france.ncr.com> and 00371 <jo@ice.dillingen.baynet.de>. 00372 Added argument list to set up each board from either 00373 a module's command line or a compiled in #define. 00374 Added generic MII PHY functionality to deal with 00375 newer PHY chips. 00376 Fix the mess in 2.1.67. 00377 0.532 5-Jan-98 Fix bug in mii_get_phy() reported by 00378 <redhat@cococo.net>. 00379 Fix bug in pci_probe() for 64 bit systems reported 00380 by <belliott@accessone.com>. 00381 0.533 9-Jan-98 Fix more 64 bit bugs reported by <jal@cs.brown.edu>. 00382 0.534 24-Jan-98 Fix last (?) endian bug from <geert@linux-m68k.org> 00383 0.535 21-Feb-98 Fix Ethernet Address PROM reset bug for DC21040. 00384 0.536 21-Mar-98 Change pci_probe() to use the pci_dev structure. 00385 **Incompatible with 2.0.x from here.** 00386 0.540 5-Jul-98 Atomicize assertion of dev->interrupt for SMP 00387 from <lma@varesearch.com> 00388 Add TP, AUI and BNC cases to 21140m_autoconf() for 00389 case where a 21140 under SROM control uses, e.g. AUI 00390 from problem report by <delchini@lpnp09.in2p3.fr> 00391 Add MII parallel detection to 2114x_autoconf() for 00392 case where no autonegotiation partner exists from 00393 problem report by <mlapsley@ndirect.co.uk>. 00394 Add ability to force connection type directly even 00395 when using SROM control from problem report by 00396 <earl@exis.net>. 00397 Updated the PCI interface to conform with the latest 00398 version. I hope nothing is broken... 00399 Add TX done interrupt modification from suggestion 00400 by <Austin.Donnelly@cl.cam.ac.uk>. 00401 Fix is_anc_capable() bug reported by 00402 <Austin.Donnelly@cl.cam.ac.uk>. 00403 Fix type[13]_infoblock() bug: during MII search, PHY 00404 lp->rst not run because lp->ibn not initialised - 00405 from report & fix by <paubert@iram.es>. 00406 Fix probe bug with EISA & PCI cards present from 00407 report by <eirik@netcom.com>. 00408 0.541 24-Aug-98 Fix compiler problems associated with i386-string 00409 ops from multiple bug reports and temporary fix 00410 from <paubert@iram.es>. 00411 Fix pci_probe() to correctly emulate the old 00412 pcibios_find_class() function. 00413 Add an_exception() for old ZYNX346 and fix compile 00414 warning on PPC & SPARC, from <ecd@skynet.be>. 00415 Fix lastPCI to correctly work with compiled in 00416 kernels and modules from bug report by 00417 <Zlatko.Calusic@CARNet.hr> et al. 00418 0.542 15-Sep-98 Fix dc2114x_autoconf() to stop multiple messages 00419 when media is unconnected. 00420 Change dev->interrupt to lp->interrupt to ensure 00421 alignment for Alpha's and avoid their unaligned 00422 access traps. This flag is merely for log messages: 00423 should do something more definitive though... 00424 0.543 30-Dec-98 Add SMP spin locking. 00425 0.544 8-May-99 Fix for buggy SROM in Motorola embedded boards using 00426 a 21143 by <mmporter@home.com>. 00427 Change PCI/EISA bus probing order. 00428 00429 ========================================================================= 00430 */ 00431 00432 static const char *version = "de4x5.c:V0.544 1999/5/8 davies@maniac.ultranet.com\n"; 00433 00434 #include <linux/config.h> 00435 #include <linux/module.h> 00436 00437 #include <linux/kernel.h> 00438 #include <linux/sched.h> 00439 #include <linux/string.h> 00440 #include <linux/interrupt.h> 00441 #include <linux/ptrace.h> 00442 #include <linux/errno.h> 00443 #include <linux/ioport.h> 00444 #include <linux/malloc.h> 00445 #include <linux/pci.h> 00446 #include <linux/delay.h> 00447 #include <linux/init.h> 00448 #include <linux/version.h> 00449 00450 #include <asm/bitops.h> 00451 #include <asm/io.h> 00452 #include <asm/dma.h> 00453 #include <asm/byteorder.h> 00454 #include <asm/unaligned.h> 00455 #include <asm/uaccess.h> 00456 #include <asm/spinlock.h> 00457 00458 #include <linux/netdevice.h> 00459 #include <linux/etherdevice.h> 00460 #include <linux/skbuff.h> 00461 00462 #include <linux/time.h> 00463 #include <linux/types.h> 00464 #include <linux/unistd.h> 00465 #include <linux/ctype.h> 00466 00467 #include "de4x5.h" 00468 00469 #define c_char const char 00470 #define TWIDDLE(a) (u_short)le16_to_cpu(get_unaligned((u_short *)(a))) 00471 00472 /* 00473 ** MII Information 00474 */ 00475 struct phy_table { 00476 int reset; /* Hard reset required? */ 00477 int id; /* IEEE OUI */ 00478 int ta; /* One cycle TA time - 802.3u is confusing here */ 00479 struct { /* Non autonegotiation (parallel) speed det. */ 00480 int reg; 00481 int mask; 00482 int value; 00483 } spd; 00484 }; 00485 00486 struct mii_phy { 00487 int reset; /* Hard reset required? */ 00488 int id; /* IEEE OUI */ 00489 int ta; /* One cycle TA time */ 00490 struct { /* Non autonegotiation (parallel) speed det. */ 00491 int reg; 00492 int mask; 00493 int value; 00494 } spd; 00495 int addr; /* MII address for the PHY */ 00496 u_char *gep; /* Start of GEP sequence block in SROM */ 00497 u_char *rst; /* Start of reset sequence in SROM */ 00498 u_int mc; /* Media Capabilities */ 00499 u_int ana; /* NWay Advertisement */ 00500 u_int fdx; /* Full DupleX capabilites for each media */ 00501 u_int ttm; /* Transmit Threshold Mode for each media */ 00502 u_int mci; /* 21142 MII Connector Interrupt info */ 00503 }; 00504 00505 #define DE4X5_MAX_PHY 8 /* Allow upto 8 attached PHY devices per board */ 00506 00507 struct sia_phy { 00508 u_char mc; /* Media Code */ 00509 u_char ext; /* csr13-15 valid when set */ 00510 int csr13; /* SIA Connectivity Register */ 00511 int csr14; /* SIA TX/RX Register */ 00512 int csr15; /* SIA General Register */ 00513 int gepc; /* SIA GEP Control Information */ 00514 int gep; /* SIA GEP Data */ 00515 }; 00516 00517 /* 00518 ** Define the know universe of PHY devices that can be 00519 ** recognised by this driver. 00520 */ 00521 static struct phy_table phy_info[] = { 00522 {0, NATIONAL_TX, 1, {0x19, 0x40, 0x00}}, /* National TX */ 00523 {1, BROADCOM_T4, 1, {0x10, 0x02, 0x02}}, /* Broadcom T4 */ 00524 {0, SEEQ_T4 , 1, {0x12, 0x10, 0x10}}, /* SEEQ T4 */ 00525 {0, CYPRESS_T4 , 1, {0x05, 0x20, 0x20}}, /* Cypress T4 */ 00526 {0, 0x7810 , 1, {0x14, 0x0800, 0x0800}} /* Level One LTX970 */ 00527 }; 00528 00529 /* 00530 ** These GENERIC values assumes that the PHY devices follow 802.3u and 00531 ** allow parallel detection to set the link partner ability register. 00532 ** Detection of 100Base-TX [H/F Duplex] and 100Base-T4 is supported. 00533 */ 00534 #define GENERIC_REG 0x05 /* Autoneg. Link Partner Advertisement Reg. */ 00535 #define GENERIC_MASK MII_ANLPA_100M /* All 100Mb/s Technologies */ 00536 #define GENERIC_VALUE MII_ANLPA_100M /* 100B-TX, 100B-TX FDX, 100B-T4 */ 00537 00538 /* 00539 ** Define special SROM detection cases 00540 */ 00541 static c_char enet_det[][ETH_ALEN] = { 00542 {0x00, 0x00, 0xc0, 0x00, 0x00, 0x00}, 00543 {0x00, 0x00, 0xe8, 0x00, 0x00, 0x00} 00544 }; 00545 00546 #define SMC 1 00547 #define ACCTON 2 00548 00549 /* 00550 ** SROM Repair definitions. If a broken SROM is detected a card may 00551 ** use this information to help figure out what to do. This is a 00552 ** "stab in the dark" and so far for SMC9332's only. 00553 */ 00554 static c_char srom_repair_info[][100] = { 00555 {0x00,0x1e,0x00,0x00,0x00,0x08, /* SMC9332 */ 00556 0x1f,0x01,0x8f,0x01,0x00,0x01,0x00,0x02, 00557 0x01,0x00,0x00,0x78,0xe0,0x01,0x00,0x50, 00558 0x00,0x18,} 00559 }; 00560 00561 00562 #ifdef DE4X5_DEBUG 00563 static int de4x5_debug = DE4X5_DEBUG; 00564 #else 00565 /*static int de4x5_debug = (DEBUG_MII | DEBUG_SROM | DEBUG_PCICFG | DEBUG_MEDIA | DEBUG_VERSION);*/ 00566 static int de4x5_debug = (DEBUG_MEDIA | DEBUG_VERSION); 00567 #endif 00568 00569 /* 00570 ** Allow per adapter set up. For modules this is simply a command line 00571 ** parameter, e.g.: 00572 ** insmod de4x5 args='eth1:fdx autosense=BNC eth0:autosense=100Mb'. 00573 ** 00574 ** For a compiled in driver, place e.g. 00575 ** #define DE4X5_PARM "eth0:fdx autosense=AUI eth2:autosense=TP" 00576 ** here 00577 */ 00578 #ifdef DE4X5_PARM 00579 static char *args = DE4X5_PARM; 00580 #else 00581 static char *args = NULL; 00582 #endif 00583 00584 struct parameters { 00585 int fdx; 00586 int autosense; 00587 }; 00588 00589 #define DE4X5_AUTOSENSE_MS 250 /* msec autosense tick (DE500) */ 00590 00591 #define DE4X5_NDA 0xffe0 /* No Device (I/O) Address */ 00592 00593 /* 00594 ** Ethernet PROM defines 00595 */ 00596 #define PROBE_LENGTH 32 00597 #define ETH_PROM_SIG 0xAA5500FFUL 00598 00599 /* 00600 ** Ethernet Info 00601 */ 00602 #define PKT_BUF_SZ 1536 /* Buffer size for each Tx/Rx buffer */ 00603 #define IEEE802_3_SZ 1518 /* Packet + CRC */ 00604 #define MAX_PKT_SZ 1514 /* Maximum ethernet packet length */ 00605 #define MAX_DAT_SZ 1500 /* Maximum ethernet data length */ 00606 #define MIN_DAT_SZ 1 /* Minimum ethernet data length */ 00607 #define PKT_HDR_LEN 14 /* Addresses and data length info */ 00608 #define FAKE_FRAME_LEN (MAX_PKT_SZ + 1) 00609 #define QUEUE_PKT_TIMEOUT (3*HZ) /* 3 second timeout */ 00610 00611 00612 #define CRC_POLYNOMIAL_BE 0x04c11db7UL /* Ethernet CRC, big endian */ 00613 #define CRC_POLYNOMIAL_LE 0xedb88320UL /* Ethernet CRC, little endian */ 00614 00615 /* 00616 ** EISA bus defines 00617 */ 00618 #define DE4X5_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */ 00619 #define DE4X5_EISA_TOTAL_SIZE 0x100 /* I/O address extent */ 00620 00621 #define MAX_EISA_SLOTS 16 00622 #define EISA_SLOT_INC 0x1000 00623 #define EISA_ALLOWED_IRQ_LIST {5, 9, 10, 11} 00624 00625 #define DE4X5_SIGNATURE {"DE425","DE434","DE435","DE450","DE500"} 00626 #define DE4X5_NAME_LENGTH 8 00627 00628 /* 00629 ** Ethernet PROM defines for DC21040 00630 */ 00631 #define PROBE_LENGTH 32 00632 #define ETH_PROM_SIG 0xAA5500FFUL 00633 00634 /* 00635 ** PCI Bus defines 00636 */ 00637 #define PCI_MAX_BUS_NUM 8 00638 #define DE4X5_PCI_TOTAL_SIZE 0x80 /* I/O address extent */ 00639 #define DE4X5_CLASS_CODE 0x00020000 /* Network controller, Ethernet */ 00640 #define NO_MORE_PCI -2 /* PCI bus search all done */ 00641 00642 /* 00643 ** Memory Alignment. Each descriptor is 4 longwords long. To force a 00644 ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and 00645 ** DESC_ALIGN. ALIGN aligns the start address of the private memory area 00646 ** and hence the RX descriptor ring's first entry. 00647 */ 00648 #define ALIGN4 ((u_long)4 - 1) /* 1 longword align */ 00649 #define ALIGN8 ((u_long)8 - 1) /* 2 longword align */ 00650 #define ALIGN16 ((u_long)16 - 1) /* 4 longword align */ 00651 #define ALIGN32 ((u_long)32 - 1) /* 8 longword align */ 00652 #define ALIGN64 ((u_long)64 - 1) /* 16 longword align */ 00653 #define ALIGN128 ((u_long)128 - 1) /* 32 longword align */ 00654 00655 #ifndef __powerpc__ 00656 #define ALIGN ALIGN32 /* Keep the DC21040 happy... */ 00657 #define CACHE_ALIGN CAL_16LONG 00658 #define DESC_SKIP_LEN DSL_0 /* Must agree with DESC_ALIGN */ 00659 /*#define DESC_ALIGN u32 dummy[4]; / * Must agree with DESC_SKIP_LEN */ 00660 #define DESC_ALIGN 00661 00662 #else /* __powerpc__ */ 00663 #define ALIGN ALIGN32 /* Keep the DC21040 happy... */ 00664 #define CACHE_ALIGN CAL_8LONG 00665 #define DESC_SKIP_LEN DSL_4 /* Must agree with DESC_ALIGN */ 00666 #define DESC_ALIGN u32 dummy[4]; /* Must agree with DESC_SKIP_LEN */ 00667 #endif /* __powerpc__ */ 00668 00669 #ifndef DEC_ONLY /* See README.de4x5 for using this */ 00670 static int dec_only = 0; 00671 #else 00672 static int dec_only = 1; 00673 #endif 00674 00675 /* 00676 ** DE4X5 IRQ ENABLE/DISABLE 00677 */ 00678 #define ENABLE_IRQs { \ 00679 imr |= lp->irq_en;\ 00680 outl(imr, DE4X5_IMR); /* Enable the IRQs */\ 00681 } 00682 00683 #define DISABLE_IRQs {\ 00684 imr = inl(DE4X5_IMR);\ 00685 imr &= ~lp->irq_en;\ 00686 outl(imr, DE4X5_IMR); /* Disable the IRQs */\ 00687 } 00688 00689 #define UNMASK_IRQs {\ 00690 imr |= lp->irq_mask;\ 00691 outl(imr, DE4X5_IMR); /* Unmask the IRQs */\ 00692 } 00693 00694 #define MASK_IRQs {\ 00695 imr = inl(DE4X5_IMR);\ 00696 imr &= ~lp->irq_mask;\ 00697 outl(imr, DE4X5_IMR); /* Mask the IRQs */\ 00698 } 00699 00700 /* 00701 ** DE4X5 START/STOP 00702 */ 00703 #define START_DE4X5 {\ 00704 omr = inl(DE4X5_OMR);\ 00705 omr |= OMR_ST | OMR_SR;\ 00706 outl(omr, DE4X5_OMR); /* Enable the TX and/or RX */\ 00707 } 00708 00709 #define STOP_DE4X5 {\ 00710 omr = inl(DE4X5_OMR);\ 00711 omr &= ~(OMR_ST|OMR_SR);\ 00712 outl(omr, DE4X5_OMR); /* Disable the TX and/or RX */ \ 00713 } 00714 00715 /* 00716 ** DE4X5 SIA RESET 00717 */ 00718 #define RESET_SIA outl(0, DE4X5_SICR); /* Reset SIA connectivity regs */ 00719 00720 /* 00721 ** DE500 AUTOSENSE TIMER INTERVAL (MILLISECS) 00722 */ 00723 #define DE4X5_AUTOSENSE_MS 250 00724 00725 /* 00726 ** SROM Structure 00727 */ 00728 struct de4x5_srom { 00729 char sub_vendor_id[2]; 00730 char sub_system_id[2]; 00731 char reserved[12]; 00732 char id_block_crc; 00733 char reserved2; 00734 char version; 00735 char num_controllers; 00736 char ieee_addr[6]; 00737 char info[100]; 00738 short chksum; 00739 }; 00740 #define SUB_VENDOR_ID 0x500a 00741 00742 /* 00743 ** DE4X5 Descriptors. Make sure that all the RX buffers are contiguous 00744 ** and have sizes of both a power of 2 and a multiple of 4. 00745 ** A size of 256 bytes for each buffer could be chosen because over 90% of 00746 ** all packets in our network are <256 bytes long and 64 longword alignment 00747 ** is possible. 1536 showed better 'ttcp' performance. Take your pick. 32 TX 00748 ** descriptors are needed for machines with an ALPHA CPU. 00749 */ 00750 #define NUM_RX_DESC 8 /* Number of RX descriptors */ 00751 #define NUM_TX_DESC 32 /* Number of TX descriptors */ 00752 #define RX_BUFF_SZ 1536 /* Power of 2 for kmalloc and */ 00753 /* Multiple of 4 for DC21040 */ 00754 /* Allows 512 byte alignment */ 00755 struct de4x5_desc { 00756 volatile s32 status; 00757 u32 des1; 00758 u32 buf; 00759 u32 next; 00760 DESC_ALIGN 00761 }; 00762 00763 /* 00764 ** The DE4X5 private structure 00765 */ 00766 #define DE4X5_PKT_STAT_SZ 16 00767 #define DE4X5_PKT_BIN_SZ 128 /* Should be >=100 unless you 00768 increase DE4X5_PKT_STAT_SZ */ 00769 00770 struct de4x5_private { 00771 char adapter_name[80]; /* Adapter name */ 00772 u_long interrupt; /* Aligned ISR flag */ 00773 #ifdef __powerpc__ 00774 u_long dummy[3]; /* Keep rx_ring 32-byte aligned */ 00775 #endif 00776 struct de4x5_desc rx_ring[NUM_RX_DESC]; /* RX descriptor ring */ 00777 struct de4x5_desc tx_ring[NUM_TX_DESC]; /* TX descriptor ring */ 00778 struct sk_buff *tx_skb[NUM_TX_DESC]; /* TX skb for freeing when sent */ 00779 struct sk_buff *rx_skb[NUM_RX_DESC]; /* RX skb's */ 00780 int rx_new, rx_old; /* RX descriptor ring pointers */ 00781 int tx_new, tx_old; /* TX descriptor ring pointers */ 00782 char setup_frame[SETUP_FRAME_LEN]; /* Holds MCA and PA info. */ 00783 char frame[64]; /* Min sized packet for loopback*/ 00784 spinlock_t lock; /* Adapter specific spinlock */ 00785 struct net_device_stats stats; /* Public stats */ 00786 struct { 00787 u_int bins[DE4X5_PKT_STAT_SZ]; /* Private stats counters */ 00788 u_int unicast; 00789 u_int multicast; 00790 u_int broadcast; 00791 u_int excessive_collisions; 00792 u_int tx_underruns; 00793 u_int excessive_underruns; 00794 u_int rx_runt_frames; 00795 u_int rx_collision; 00796 u_int rx_dribble; 00797 u_int rx_overflow; 00798 } pktStats; 00799 char rxRingSize; 00800 char txRingSize; 00801 int bus; /* EISA or PCI */ 00802 int bus_num; /* PCI Bus number */ 00803 int device; /* Device number on PCI bus */ 00804 int state; /* Adapter OPENED or CLOSED */ 00805 int chipset; /* DC21040, DC21041 or DC21140 */ 00806 s32 irq_mask; /* Interrupt Mask (Enable) bits */ 00807 s32 irq_en; /* Summary interrupt bits */ 00808 int media; /* Media (eg TP), mode (eg 100B)*/ 00809 int c_media; /* Remember the last media conn */ 00810 int fdx; /* media full duplex flag */ 00811 int linkOK; /* Link is OK */ 00812 int autosense; /* Allow/disallow autosensing */ 00813 int tx_enable; /* Enable descriptor polling */ 00814 int setup_f; /* Setup frame filtering type */ 00815 int local_state; /* State within a 'media' state */ 00816 struct mii_phy phy[DE4X5_MAX_PHY]; /* List of attached PHY devices */ 00817 struct sia_phy sia; /* SIA PHY Information */ 00818 int active; /* Index to active PHY device */ 00819 int mii_cnt; /* Number of attached PHY's */ 00820 int timeout; /* Scheduling counter */ 00821 struct timer_list timer; /* Timer info for kernel */ 00822 int tmp; /* Temporary global per card */ 00823 struct { 00824 void *priv; /* Original kmalloc'd mem addr */ 00825 void *buf; /* Original kmalloc'd mem addr */ 00826 u_long lock; /* Lock the cache accesses */ 00827 s32 csr0; /* Saved Bus Mode Register */ 00828 s32 csr6; /* Saved Operating Mode Reg. */ 00829 s32 csr7; /* Saved IRQ Mask Register */ 00830 s32 gep; /* Saved General Purpose Reg. */ 00831 s32 gepc; /* Control info for GEP */ 00832 s32 csr13; /* Saved SIA Connectivity Reg. */ 00833 s32 csr14; /* Saved SIA TX/RX Register */ 00834 s32 csr15; /* Saved SIA General Register */ 00835 int save_cnt; /* Flag if state already saved */ 00836 struct sk_buff *skb; /* Save the (re-ordered) skb's */ 00837 } cache; 00838 struct de4x5_srom srom; /* A copy of the SROM */ 00839 struct device *next_module; /* Link to the next module */ 00840 int rx_ovf; /* Check for 'RX overflow' tag */ 00841 int useSROM; /* For non-DEC card use SROM */ 00842 int useMII; /* Infoblock using the MII */ 00843 int asBitValid; /* Autosense bits in GEP? */ 00844 int asPolarity; /* 0 => asserted high */ 00845 int asBit; /* Autosense bit number in GEP */ 00846 int defMedium; /* SROM default medium */ 00847 int tcount; /* Last infoblock number */ 00848 int infoblock_init; /* Initialised this infoblock? */ 00849 int infoleaf_offset; /* SROM infoleaf for controller */ 00850 s32 infoblock_csr6; /* csr6 value in SROM infoblock */ 00851 int infoblock_media; /* infoblock media */ 00852 int (*infoleaf_fn)(struct device *); /* Pointer to infoleaf function */ 00853 u_char *rst; /* Pointer to Type 5 reset info */ 00854 u_char ibn; /* Infoblock number */ 00855 struct parameters params; /* Command line/ #defined params */ 00856 }; 00857 00858 /* 00859 ** Kludge to get around the fact that the CSR addresses have different 00860 ** offsets in the PCI and EISA boards. Also note that the ethernet address 00861 ** PROM is accessed differently. 00862 */ 00863 static struct bus_type { 00864 int bus; 00865 int bus_num; 00866 int device; 00867 int chipset; 00868 struct de4x5_srom srom; 00869 int autosense; 00870 int useSROM; 00871 } bus; 00872 00873 /* 00874 ** To get around certain poxy cards that don't provide an SROM 00875 ** for the second and more DECchip, I have to key off the first 00876 ** chip's address. I'll assume there's not a bad SROM iff: 00877 ** 00878 ** o the chipset is the same 00879 ** o the bus number is the same and > 0 00880 ** o the sum of all the returned hw address bytes is 0 or 0x5fa 00881 ** 00882 ** Also have to save the irq for those cards whose hardware designers 00883 ** can't follow the PCI to PCI Bridge Architecture spec. 00884 */ 00885 static struct { 00886 int chipset; 00887 int bus; 00888 int irq; 00889 u_char addr[ETH_ALEN]; 00890 } last = {0,}; 00891 00892 /* 00893 ** The transmit ring full condition is described by the tx_old and tx_new 00894 ** pointers by: 00895 ** tx_old = tx_new Empty ring 00896 ** tx_old = tx_new+1 Full ring 00897 ** tx_old+txRingSize = tx_new+1 Full ring (wrapped condition) 00898 */ 00899 #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\ 00900 lp->tx_old+lp->txRingSize-lp->tx_new-1:\ 00901 lp->tx_old -lp->tx_new-1) 00902 00903 #define TX_PKT_PENDING (lp->tx_old != lp->tx_new) 00904 00905 /* 00906 ** Public Functions 00907 */ 00908 static int de4x5_open(struct device *dev); 00909 static int de4x5_queue_pkt(struct sk_buff *skb, struct device *dev); 00910 static void de4x5_interrupt(int irq, void *dev_id, struct pt_regs *regs); 00911 static int de4x5_close(struct device *dev); 00912 static struct net_device_stats *de4x5_get_stats(struct device *dev); 00913 static void de4x5_local_stats(struct device *dev, char *buf, int pkt_len); 00914 static void set_multicast_list(struct device *dev); 00915 static int de4x5_ioctl(struct device *dev, struct ifreq *rq, int cmd); 00916 00917 /* 00918 ** Private functions 00919 */ 00920 static int de4x5_hw_init(struct device *dev, u_long iobase); 00921 static int de4x5_init(struct device *dev); 00922 static int de4x5_sw_reset(struct device *dev); 00923 static int de4x5_rx(struct device *dev); 00924 static int de4x5_tx(struct device *dev); 00925 static int de4x5_ast(struct device *dev); 00926 static int de4x5_txur(struct device *dev); 00927 static int de4x5_rx_ovfc(struct device *dev); 00928 00929 static int autoconf_media(struct device *dev); 00930 static void create_packet(struct device *dev, char *frame, int len); 00931 static void de4x5_us_delay(u32 usec); 00932 static void de4x5_ms_delay(u32 msec); 00933 static void load_packet(struct device *dev, char *buf, u32 flags, struct sk_buff *skb); 00934 static int dc21040_autoconf(struct device *dev); 00935 static int dc21041_autoconf(struct device *dev); 00936 static int dc21140m_autoconf(struct device *dev); 00937 static int dc2114x_autoconf(struct device *dev); 00938 static int srom_autoconf(struct device *dev); 00939 static int de4x5_suspect_state(struct device *dev, int timeout, int prev_state, int (*fn)(struct device *, int), int (*asfn)(struct device *)); 00940 static int dc21040_state(struct device *dev, int csr13, int csr14, int csr15, int timeout, int next_state, int suspect_state, int (*fn)(struct device *, int)); 00941 static int test_media(struct device *dev, s32 irqs, s32 irq_mask, s32 csr13, s32 csr14, s32 csr15, s32 msec); 00942 static int test_for_100Mb(struct device *dev, int msec); 00943 static int wait_for_link(struct device *dev); 00944 static int test_mii_reg(struct device *dev, int reg, int mask, int pol, long msec); 00945 static int is_spd_100(struct device *dev); 00946 static int is_100_up(struct device *dev); 00947 static int is_10_up(struct device *dev); 00948 static int is_anc_capable(struct device *dev); 00949 static int ping_media(struct device *dev, int msec); 00950 static struct sk_buff *de4x5_alloc_rx_buff(struct device *dev, int index, int len); 00951 static void de4x5_free_rx_buffs(struct device *dev); 00952 static void de4x5_free_tx_buffs(struct device *dev); 00953 static void de4x5_save_skbs(struct device *dev); 00954 static void de4x5_rst_desc_ring(struct device *dev); 00955 static void de4x5_cache_state(struct device *dev, int flag); 00956 static void de4x5_put_cache(struct device *dev, struct sk_buff *skb); 00957 static void de4x5_putb_cache(struct device *dev, struct sk_buff *skb); 00958 static struct sk_buff *de4x5_get_cache(struct device *dev); 00959 static void de4x5_setup_intr(struct device *dev); 00960 static void de4x5_init_connection(struct device *dev); 00961 static int de4x5_reset_phy(struct device *dev); 00962 static void reset_init_sia(struct device *dev, s32 sicr, s32 strr, s32 sigr); 00963 static int test_ans(struct device *dev, s32 irqs, s32 irq_mask, s32 msec); 00964 static int test_tp(struct device *dev, s32 msec); 00965 static int EISA_signature(char *name, s32 eisa_id); 00966 static int PCI_signature(char *name, struct bus_type *lp); 00967 static void DevicePresent(u_long iobase); 00968 static void enet_addr_rst(u_long aprom_addr); 00969 static int de4x5_bad_srom(struct bus_type *lp); 00970 static short srom_rd(u_long address, u_char offset); 00971 static void srom_latch(u_int command, u_long address); 00972 static void srom_command(u_int command, u_long address); 00973 static void srom_address(u_int command, u_long address, u_char offset); 00974 static short srom_data(u_int command, u_long address); 00975 /*static void srom_busy(u_int command, u_long address);*/ 00976 static void sendto_srom(u_int command, u_long addr); 00977 static int getfrom_srom(u_long addr); 00978 static int srom_map_media(struct device *dev); 00979 static int srom_infoleaf_info(struct device *dev); 00980 static void srom_init(struct device *dev); 00981 static void srom_exec(struct device *dev, u_char *p); 00982 static int mii_rd(u_char phyreg, u_char phyaddr, u_long ioaddr); 00983 static void mii_wr(int data, u_char phyreg, u_char phyaddr, u_long ioaddr); 00984 static int mii_rdata(u_long ioaddr); 00985 static void mii_wdata(int data, int len<