PageRenderTime 92ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/ethernet/dec/tulip/de4x5.c

https://github.com/mturquette/linux
C | 1140 lines | 499 code | 72 blank | 569 comment | 14 complexity | d95bd6f51e548d1d6031efc9b8034826 MD5 | raw file
  1. /* de4x5.c: A DIGITAL DC21x4x DECchip and DE425/DE434/DE435/DE450/DE500
  2. ethernet driver for Linux.
  3. Copyright 1994, 1995 Digital Equipment Corporation.
  4. Testing resources for this driver have been made available
  5. in part by NASA Ames Research Center (mjacob@nas.nasa.gov).
  6. The author may be reached at davies@maniac.ultranet.com.
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  14. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  17. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  18. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. You should have received a copy of the GNU General Public License along
  22. with this program; if not, write to the Free Software Foundation, Inc.,
  23. 675 Mass Ave, Cambridge, MA 02139, USA.
  24. Originally, this driver was written for the Digital Equipment
  25. Corporation series of EtherWORKS ethernet cards:
  26. DE425 TP/COAX EISA
  27. DE434 TP PCI
  28. DE435 TP/COAX/AUI PCI
  29. DE450 TP/COAX/AUI PCI
  30. DE500 10/100 PCI Fasternet
  31. but it will now attempt to support all cards which conform to the
  32. Digital Semiconductor SROM Specification. The driver currently
  33. recognises the following chips:
  34. DC21040 (no SROM)
  35. DC21041[A]
  36. DC21140[A]
  37. DC21142
  38. DC21143
  39. So far the driver is known to work with the following cards:
  40. KINGSTON
  41. Linksys
  42. ZNYX342
  43. SMC8432
  44. SMC9332 (w/new SROM)
  45. ZNYX31[45]
  46. ZNYX346 10/100 4 port (can act as a 10/100 bridge!)
  47. The driver has been tested on a relatively busy network using the DE425,
  48. DE434, DE435 and DE500 cards and benchmarked with 'ttcp': it transferred
  49. 16M of data to a DECstation 5000/200 as follows:
  50. TCP UDP
  51. TX RX TX RX
  52. DE425 1030k 997k 1170k 1128k
  53. DE434 1063k 995k 1170k 1125k
  54. DE435 1063k 995k 1170k 1125k
  55. DE500 1063k 998k 1170k 1125k in 10Mb/s mode
  56. All values are typical (in kBytes/sec) from a sample of 4 for each
  57. measurement. Their error is +/-20k on a quiet (private) network and also
  58. depend on what load the CPU has.
  59. =========================================================================
  60. This driver has been written substantially from scratch, although its
  61. inheritance of style and stack interface from 'ewrk3.c' and in turn from
  62. Donald Becker's 'lance.c' should be obvious. With the module autoload of
  63. every usable DECchip board, I pinched Donald's 'next_module' field to
  64. link my modules together.
  65. Up to 15 EISA cards can be supported under this driver, limited primarily
  66. by the available IRQ lines. I have checked different configurations of
  67. multiple depca, EtherWORKS 3 cards and de4x5 cards and have not found a
  68. problem yet (provided you have at least depca.c v0.38) ...
  69. PCI support has been added to allow the driver to work with the DE434,
  70. DE435, DE450 and DE500 cards. The I/O accesses are a bit of a kludge due
  71. to the differences in the EISA and PCI CSR address offsets from the base
  72. address.
  73. The ability to load this driver as a loadable module has been included
  74. and used extensively during the driver development (to save those long
  75. reboot sequences). Loadable module support under PCI and EISA has been
  76. achieved by letting the driver autoprobe as if it were compiled into the
  77. kernel. Do make sure you're not sharing interrupts with anything that
  78. cannot accommodate interrupt sharing!
  79. To utilise this ability, you have to do 8 things:
  80. 0) have a copy of the loadable modules code installed on your system.
  81. 1) copy de4x5.c from the /linux/drivers/net directory to your favourite
  82. temporary directory.
  83. 2) for fixed autoprobes (not recommended), edit the source code near
  84. line 5594 to reflect the I/O address you're using, or assign these when
  85. loading by:
  86. insmod de4x5 io=0xghh where g = bus number
  87. hh = device number
  88. NB: autoprobing for modules is now supported by default. You may just
  89. use:
  90. insmod de4x5
  91. to load all available boards. For a specific board, still use
  92. the 'io=?' above.
  93. 3) compile de4x5.c, but include -DMODULE in the command line to ensure
  94. that the correct bits are compiled (see end of source code).
  95. 4) if you are wanting to add a new card, goto 5. Otherwise, recompile a
  96. kernel with the de4x5 configuration turned off and reboot.
  97. 5) insmod de4x5 [io=0xghh]
  98. 6) run the net startup bits for your new eth?? interface(s) manually
  99. (usually /etc/rc.inet[12] at boot time).
  100. 7) enjoy!
  101. To unload a module, turn off the associated interface(s)
  102. 'ifconfig eth?? down' then 'rmmod de4x5'.
  103. Automedia detection is included so that in principal you can disconnect
  104. from, e.g. TP, reconnect to BNC and things will still work (after a
  105. pause whilst the driver figures out where its media went). My tests
  106. using ping showed that it appears to work....
  107. By default, the driver will now autodetect any DECchip based card.
  108. Should you have a need to restrict the driver to DIGITAL only cards, you
  109. can compile with a DEC_ONLY define, or if loading as a module, use the
  110. 'dec_only=1' parameter.
  111. I've changed the timing routines to use the kernel timer and scheduling
  112. functions so that the hangs and other assorted problems that occurred
  113. while autosensing the media should be gone. A bonus for the DC21040
  114. auto media sense algorithm is that it can now use one that is more in
  115. line with the rest (the DC21040 chip doesn't have a hardware timer).
  116. The downside is the 1 'jiffies' (10ms) resolution.
  117. IEEE 802.3u MII interface code has been added in anticipation that some
  118. products may use it in the future.
  119. The SMC9332 card has a non-compliant SROM which needs fixing - I have
  120. patched this driver to detect it because the SROM format used complies
  121. to a previous DEC-STD format.
  122. I have removed the buffer copies needed for receive on Intels. I cannot
  123. remove them for Alphas since the Tulip hardware only does longword
  124. aligned DMA transfers and the Alphas get alignment traps with non
  125. longword aligned data copies (which makes them really slow). No comment.
  126. I have added SROM decoding routines to make this driver work with any
  127. card that supports the Digital Semiconductor SROM spec. This will help
  128. all cards running the dc2114x series chips in particular. Cards using
  129. the dc2104x chips should run correctly with the basic driver. I'm in
  130. debt to <mjacob@feral.com> for the testing and feedback that helped get
  131. this feature working. So far we have tested KINGSTON, SMC8432, SMC9332
  132. (with the latest SROM complying with the SROM spec V3: their first was
  133. broken), ZNYX342 and LinkSys. ZYNX314 (dual 21041 MAC) and ZNYX 315
  134. (quad 21041 MAC) cards also appear to work despite their incorrectly
  135. wired IRQs.
  136. I have added a temporary fix for interrupt problems when some SCSI cards
  137. share the same interrupt as the DECchip based cards. The problem occurs
  138. because the SCSI card wants to grab the interrupt as a fast interrupt
  139. (runs the service routine with interrupts turned off) vs. this card
  140. which really needs to run the service routine with interrupts turned on.
  141. This driver will now add the interrupt service routine as a fast
  142. interrupt if it is bounced from the slow interrupt. THIS IS NOT A
  143. RECOMMENDED WAY TO RUN THE DRIVER and has been done for a limited time
  144. until people sort out their compatibility issues and the kernel
  145. interrupt service code is fixed. YOU SHOULD SEPARATE OUT THE FAST
  146. INTERRUPT CARDS FROM THE SLOW INTERRUPT CARDS to ensure that they do not
  147. run on the same interrupt. PCMCIA/CardBus is another can of worms...
  148. Finally, I think I have really fixed the module loading problem with
  149. more than one DECchip based card. As a side effect, I don't mess with
  150. the device structure any more which means that if more than 1 card in
  151. 2.0.x is installed (4 in 2.1.x), the user will have to edit
  152. linux/drivers/net/Space.c to make room for them. Hence, module loading
  153. is the preferred way to use this driver, since it doesn't have this
  154. limitation.
  155. Where SROM media detection is used and full duplex is specified in the
  156. SROM, the feature is ignored unless lp->params.fdx is set at compile
  157. time OR during a module load (insmod de4x5 args='eth??:fdx' [see
  158. below]). This is because there is no way to automatically detect full
  159. duplex links except through autonegotiation. When I include the
  160. autonegotiation feature in the SROM autoconf code, this detection will
  161. occur automatically for that case.
  162. Command line arguments are now allowed, similar to passing arguments
  163. through LILO. This will allow a per adapter board set up of full duplex
  164. and media. The only lexical constraints are: the board name (dev->name)
  165. appears in the list before its parameters. The list of parameters ends
  166. either at the end of the parameter list or with another board name. The
  167. following parameters are allowed:
  168. fdx for full duplex
  169. autosense to set the media/speed; with the following
  170. sub-parameters:
  171. TP, TP_NW, BNC, AUI, BNC_AUI, 100Mb, 10Mb, AUTO
  172. Case sensitivity is important for the sub-parameters. They *must* be
  173. upper case. Examples:
  174. insmod de4x5 args='eth1:fdx autosense=BNC eth0:autosense=100Mb'.
  175. For a compiled in driver, at or above line 548, place e.g.
  176. #define DE4X5_PARM "eth0:fdx autosense=AUI eth2:autosense=TP"
  177. Yes, I know full duplex isn't permissible on BNC or AUI; they're just
  178. examples. By default, full duplex is turned off and AUTO is the default
  179. autosense setting. In reality, I expect only the full duplex option to
  180. be used. Note the use of single quotes in the two examples above and the
  181. lack of commas to separate items. ALSO, you must get the requested media
  182. correct in relation to what the adapter SROM says it has. There's no way
  183. to determine this in advance other than by trial and error and common
  184. sense, e.g. call a BNC connectored port 'BNC', not '10Mb'.
  185. Changed the bus probing. EISA used to be done first, followed by PCI.
  186. Most people probably don't even know what a de425 is today and the EISA
  187. probe has messed up some SCSI cards in the past, so now PCI is always
  188. probed first followed by EISA if a) the architecture allows EISA and
  189. either b) there have been no PCI cards detected or c) an EISA probe is
  190. forced by the user. To force a probe include "force_eisa" in your
  191. insmod "args" line; for built-in kernels either change the driver to do
  192. this automatically or include #define DE4X5_FORCE_EISA on or before
  193. line 1040 in the driver.
  194. TO DO:
  195. ------
  196. Revision History
  197. ----------------
  198. Version Date Description
  199. 0.1 17-Nov-94 Initial writing. ALPHA code release.
  200. 0.2 13-Jan-95 Added PCI support for DE435's.
  201. 0.21 19-Jan-95 Added auto media detection.
  202. 0.22 10-Feb-95 Fix interrupt handler call <chris@cosy.sbg.ac.at>.
  203. Fix recognition bug reported by <bkm@star.rl.ac.uk>.
  204. Add request/release_region code.
  205. Add loadable modules support for PCI.
  206. Clean up loadable modules support.
  207. 0.23 28-Feb-95 Added DC21041 and DC21140 support.
  208. Fix missed frame counter value and initialisation.
  209. Fixed EISA probe.
  210. 0.24 11-Apr-95 Change delay routine to use <linux/udelay>.
  211. Change TX_BUFFS_AVAIL macro.
  212. Change media autodetection to allow manual setting.
  213. Completed DE500 (DC21140) support.
  214. 0.241 18-Apr-95 Interim release without DE500 Autosense Algorithm.
  215. 0.242 10-May-95 Minor changes.
  216. 0.30 12-Jun-95 Timer fix for DC21140.
  217. Portability changes.
  218. Add ALPHA changes from <jestabro@ant.tay1.dec.com>.
  219. Add DE500 semi automatic autosense.
  220. Add Link Fail interrupt TP failure detection.
  221. Add timer based link change detection.
  222. Plugged a memory leak in de4x5_queue_pkt().
  223. 0.31 13-Jun-95 Fixed PCI stuff for 1.3.1.
  224. 0.32 26-Jun-95 Added verify_area() calls in de4x5_ioctl() from a
  225. suggestion by <heiko@colossus.escape.de>.
  226. 0.33 8-Aug-95 Add shared interrupt support (not released yet).
  227. 0.331 21-Aug-95 Fix de4x5_open() with fast CPUs.
  228. Fix de4x5_interrupt().
  229. Fix dc21140_autoconf() mess.
  230. No shared interrupt support.
  231. 0.332 11-Sep-95 Added MII management interface routines.
  232. 0.40 5-Mar-96 Fix setup frame timeout <maartenb@hpkuipc.cern.ch>.
  233. Add kernel timer code (h/w is too flaky).
  234. Add MII based PHY autosense.
  235. Add new multicasting code.
  236. Add new autosense algorithms for media/mode
  237. selection using kernel scheduling/timing.
  238. Re-formatted.
  239. Made changes suggested by <jeff@router.patch.net>:
  240. Change driver to detect all DECchip based cards
  241. with DEC_ONLY restriction a special case.
  242. Changed driver to autoprobe as a module. No irq
  243. checking is done now - assume BIOS is good!
  244. Added SMC9332 detection <manabe@Roy.dsl.tutics.ac.jp>
  245. 0.41 21-Mar-96 Don't check for get_hw_addr checksum unless DEC card
  246. only <niles@axp745gsfc.nasa.gov>
  247. Fix for multiple PCI cards reported by <jos@xos.nl>
  248. Duh, put the IRQF_SHARED flag into request_interrupt().
  249. Fix SMC ethernet address in enet_det[].
  250. Print chip name instead of "UNKNOWN" during boot.
  251. 0.42 26-Apr-96 Fix MII write TA bit error.
  252. Fix bug in dc21040 and dc21041 autosense code.
  253. Remove buffer copies on receive for Intels.
  254. Change sk_buff handling during media disconnects to
  255. eliminate DUP packets.
  256. Add dynamic TX thresholding.
  257. Change all chips to use perfect multicast filtering.
  258. Fix alloc_device() bug <jari@markkus2.fimr.fi>
  259. 0.43 21-Jun-96 Fix unconnected media TX retry bug.
  260. Add Accton to the list of broken cards.
  261. Fix TX under-run bug for non DC21140 chips.
  262. Fix boot command probe bug in alloc_device() as
  263. reported by <koen.gadeyne@barco.com> and
  264. <orava@nether.tky.hut.fi>.
  265. Add cache locks to prevent a race condition as
  266. reported by <csd@microplex.com> and
  267. <baba@beckman.uiuc.edu>.
  268. Upgraded alloc_device() code.
  269. 0.431 28-Jun-96 Fix potential bug in queue_pkt() from discussion
  270. with <csd@microplex.com>
  271. 0.44 13-Aug-96 Fix RX overflow bug in 2114[023] chips.
  272. Fix EISA probe bugs reported by <os2@kpi.kharkov.ua>
  273. and <michael@compurex.com>.
  274. 0.441 9-Sep-96 Change dc21041_autoconf() to probe quiet BNC media
  275. with a loopback packet.
  276. 0.442 9-Sep-96 Include AUI in dc21041 media printout. Bug reported
  277. by <bhat@mundook.cs.mu.OZ.AU>
  278. 0.45 8-Dec-96 Include endian functions for PPC use, from work
  279. by <cort@cs.nmt.edu> and <g.thomas@opengroup.org>.
  280. 0.451 28-Dec-96 Added fix to allow autoprobe for modules after
  281. suggestion from <mjacob@feral.com>.
  282. 0.5 30-Jan-97 Added SROM decoding functions.
  283. Updated debug flags.
  284. Fix sleep/wakeup calls for PCI cards, bug reported
  285. by <cross@gweep.lkg.dec.com>.
  286. Added multi-MAC, one SROM feature from discussion
  287. with <mjacob@feral.com>.
  288. Added full module autoprobe capability.
  289. Added attempt to use an SMC9332 with broken SROM.
  290. Added fix for ZYNX multi-mac cards that didn't
  291. get their IRQs wired correctly.
  292. 0.51 13-Feb-97 Added endian fixes for the SROM accesses from
  293. <paubert@iram.es>
  294. Fix init_connection() to remove extra device reset.
  295. Fix MAC/PHY reset ordering in dc21140m_autoconf().
  296. Fix initialisation problem with lp->timeout in
  297. typeX_infoblock() from <paubert@iram.es>.
  298. Fix MII PHY reset problem from work done by
  299. <paubert@iram.es>.
  300. 0.52 26-Apr-97 Some changes may not credit the right people -
  301. a disk crash meant I lost some mail.
  302. Change RX interrupt routine to drop rather than
  303. defer packets to avoid hang reported by
  304. <g.thomas@opengroup.org>.
  305. Fix srom_exec() to return for COMPACT and type 1
  306. infoblocks.
  307. Added DC21142 and DC21143 functions.
  308. Added byte counters from <phil@tazenda.demon.co.uk>
  309. Added IRQF_DISABLED temporary fix from
  310. <mjacob@feral.com>.
  311. 0.53 12-Nov-97 Fix the *_probe() to include 'eth??' name during
  312. module load: bug reported by
  313. <Piete.Brooks@cl.cam.ac.uk>
  314. Fix multi-MAC, one SROM, to work with 2114x chips:
  315. bug reported by <cmetz@inner.net>.
  316. Make above search independent of BIOS device scan
  317. direction.
  318. Completed DC2114[23] autosense functions.
  319. 0.531 21-Dec-97 Fix DE500-XA 100Mb/s bug reported by
  320. <robin@intercore.com
  321. Fix type1_infoblock() bug introduced in 0.53, from
  322. problem reports by
  323. <parmee@postecss.ncrfran.france.ncr.com> and
  324. <jo@ice.dillingen.baynet.de>.
  325. Added argument list to set up each board from either
  326. a module's command line or a compiled in #define.
  327. Added generic MII PHY functionality to deal with
  328. newer PHY chips.
  329. Fix the mess in 2.1.67.
  330. 0.532 5-Jan-98 Fix bug in mii_get_phy() reported by
  331. <redhat@cococo.net>.
  332. Fix bug in pci_probe() for 64 bit systems reported
  333. by <belliott@accessone.com>.
  334. 0.533 9-Jan-98 Fix more 64 bit bugs reported by <jal@cs.brown.edu>.
  335. 0.534 24-Jan-98 Fix last (?) endian bug from <geert@linux-m68k.org>
  336. 0.535 21-Feb-98 Fix Ethernet Address PROM reset bug for DC21040.
  337. 0.536 21-Mar-98 Change pci_probe() to use the pci_dev structure.
  338. **Incompatible with 2.0.x from here.**
  339. 0.540 5-Jul-98 Atomicize assertion of dev->interrupt for SMP
  340. from <lma@varesearch.com>
  341. Add TP, AUI and BNC cases to 21140m_autoconf() for
  342. case where a 21140 under SROM control uses, e.g. AUI
  343. from problem report by <delchini@lpnp09.in2p3.fr>
  344. Add MII parallel detection to 2114x_autoconf() for
  345. case where no autonegotiation partner exists from
  346. problem report by <mlapsley@ndirect.co.uk>.
  347. Add ability to force connection type directly even
  348. when using SROM control from problem report by
  349. <earl@exis.net>.
  350. Updated the PCI interface to conform with the latest
  351. version. I hope nothing is broken...
  352. Add TX done interrupt modification from suggestion
  353. by <Austin.Donnelly@cl.cam.ac.uk>.
  354. Fix is_anc_capable() bug reported by
  355. <Austin.Donnelly@cl.cam.ac.uk>.
  356. Fix type[13]_infoblock() bug: during MII search, PHY
  357. lp->rst not run because lp->ibn not initialised -
  358. from report & fix by <paubert@iram.es>.
  359. Fix probe bug with EISA & PCI cards present from
  360. report by <eirik@netcom.com>.
  361. 0.541 24-Aug-98 Fix compiler problems associated with i386-string
  362. ops from multiple bug reports and temporary fix
  363. from <paubert@iram.es>.
  364. Fix pci_probe() to correctly emulate the old
  365. pcibios_find_class() function.
  366. Add an_exception() for old ZYNX346 and fix compile
  367. warning on PPC & SPARC, from <ecd@skynet.be>.
  368. Fix lastPCI to correctly work with compiled in
  369. kernels and modules from bug report by
  370. <Zlatko.Calusic@CARNet.hr> et al.
  371. 0.542 15-Sep-98 Fix dc2114x_autoconf() to stop multiple messages
  372. when media is unconnected.
  373. Change dev->interrupt to lp->interrupt to ensure
  374. alignment for Alpha's and avoid their unaligned
  375. access traps. This flag is merely for log messages:
  376. should do something more definitive though...
  377. 0.543 30-Dec-98 Add SMP spin locking.
  378. 0.544 8-May-99 Fix for buggy SROM in Motorola embedded boards using
  379. a 21143 by <mmporter@home.com>.
  380. Change PCI/EISA bus probing order.
  381. 0.545 28-Nov-99 Further Moto SROM bug fix from
  382. <mporter@eng.mcd.mot.com>
  383. Remove double checking for DEBUG_RX in de4x5_dbg_rx()
  384. from report by <geert@linux-m68k.org>
  385. 0.546 22-Feb-01 Fixes Alpha XP1000 oops. The srom_search function
  386. was causing a page fault when initializing the
  387. variable 'pb', on a non de4x5 PCI device, in this
  388. case a PCI bridge (DEC chip 21152). The value of
  389. 'pb' is now only initialized if a de4x5 chip is
  390. present.
  391. <france@handhelds.org>
  392. 0.547 08-Nov-01 Use library crc32 functions by <Matt_Domsch@dell.com>
  393. 0.548 30-Aug-03 Big 2.6 cleanup. Ported to PCI/EISA probing and
  394. generic DMA APIs. Fixed DE425 support on Alpha.
  395. <maz@wild-wind.fr.eu.org>
  396. =========================================================================
  397. */
  398. #include <linux/module.h>
  399. #include <linux/kernel.h>
  400. #include <linux/string.h>
  401. #include <linux/interrupt.h>
  402. #include <linux/ptrace.h>
  403. #include <linux/errno.h>
  404. #include <linux/ioport.h>
  405. #include <linux/pci.h>
  406. #include <linux/eisa.h>
  407. #include <linux/delay.h>
  408. #include <linux/init.h>
  409. #include <linux/spinlock.h>
  410. #include <linux/crc32.h>
  411. #include <linux/netdevice.h>
  412. #include <linux/etherdevice.h>
  413. #include <linux/skbuff.h>
  414. #include <linux/time.h>
  415. #include <linux/types.h>
  416. #include <linux/unistd.h>
  417. #include <linux/ctype.h>
  418. #include <linux/dma-mapping.h>
  419. #include <linux/moduleparam.h>
  420. #include <linux/bitops.h>
  421. #include <linux/gfp.h>
  422. #include <asm/io.h>
  423. #include <asm/dma.h>
  424. #include <asm/byteorder.h>
  425. #include <asm/unaligned.h>
  426. #include <asm/uaccess.h>
  427. #ifdef CONFIG_PPC_PMAC
  428. #include <asm/machdep.h>
  429. #endif /* CONFIG_PPC_PMAC */
  430. #include "de4x5.h"
  431. static const char version[] =
  432. KERN_INFO "de4x5.c:V0.546 2001/02/22 davies@maniac.ultranet.com\n";
  433. #define c_char const char
  434. /*
  435. ** MII Information
  436. */
  437. struct phy_table {
  438. int reset; /* Hard reset required? */
  439. int id; /* IEEE OUI */
  440. int ta; /* One cycle TA time - 802.3u is confusing here */
  441. struct { /* Non autonegotiation (parallel) speed det. */
  442. int reg;
  443. int mask;
  444. int value;
  445. } spd;
  446. };
  447. struct mii_phy {
  448. int reset; /* Hard reset required? */
  449. int id; /* IEEE OUI */
  450. int ta; /* One cycle TA time */
  451. struct { /* Non autonegotiation (parallel) speed det. */
  452. int reg;
  453. int mask;
  454. int value;
  455. } spd;
  456. int addr; /* MII address for the PHY */
  457. u_char *gep; /* Start of GEP sequence block in SROM */
  458. u_char *rst; /* Start of reset sequence in SROM */
  459. u_int mc; /* Media Capabilities */
  460. u_int ana; /* NWay Advertisement */
  461. u_int fdx; /* Full DupleX capabilities for each media */
  462. u_int ttm; /* Transmit Threshold Mode for each media */
  463. u_int mci; /* 21142 MII Connector Interrupt info */
  464. };
  465. #define DE4X5_MAX_PHY 8 /* Allow up to 8 attached PHY devices per board */
  466. struct sia_phy {
  467. u_char mc; /* Media Code */
  468. u_char ext; /* csr13-15 valid when set */
  469. int csr13; /* SIA Connectivity Register */
  470. int csr14; /* SIA TX/RX Register */
  471. int csr15; /* SIA General Register */
  472. int gepc; /* SIA GEP Control Information */
  473. int gep; /* SIA GEP Data */
  474. };
  475. /*
  476. ** Define the know universe of PHY devices that can be
  477. ** recognised by this driver.
  478. */
  479. static struct phy_table phy_info[] = {
  480. {0, NATIONAL_TX, 1, {0x19, 0x40, 0x00}}, /* National TX */
  481. {1, BROADCOM_T4, 1, {0x10, 0x02, 0x02}}, /* Broadcom T4 */
  482. {0, SEEQ_T4 , 1, {0x12, 0x10, 0x10}}, /* SEEQ T4 */
  483. {0, CYPRESS_T4 , 1, {0x05, 0x20, 0x20}}, /* Cypress T4 */
  484. {0, 0x7810 , 1, {0x14, 0x0800, 0x0800}} /* Level One LTX970 */
  485. };
  486. /*
  487. ** These GENERIC values assumes that the PHY devices follow 802.3u and
  488. ** allow parallel detection to set the link partner ability register.
  489. ** Detection of 100Base-TX [H/F Duplex] and 100Base-T4 is supported.
  490. */
  491. #define GENERIC_REG 0x05 /* Autoneg. Link Partner Advertisement Reg. */
  492. #define GENERIC_MASK MII_ANLPA_100M /* All 100Mb/s Technologies */
  493. #define GENERIC_VALUE MII_ANLPA_100M /* 100B-TX, 100B-TX FDX, 100B-T4 */
  494. /*
  495. ** Define special SROM detection cases
  496. */
  497. static c_char enet_det[][ETH_ALEN] = {
  498. {0x00, 0x00, 0xc0, 0x00, 0x00, 0x00},
  499. {0x00, 0x00, 0xe8, 0x00, 0x00, 0x00}
  500. };
  501. #define SMC 1
  502. #define ACCTON 2
  503. /*
  504. ** SROM Repair definitions. If a broken SROM is detected a card may
  505. ** use this information to help figure out what to do. This is a
  506. ** "stab in the dark" and so far for SMC9332's only.
  507. */
  508. static c_char srom_repair_info[][100] = {
  509. {0x00,0x1e,0x00,0x00,0x00,0x08, /* SMC9332 */
  510. 0x1f,0x01,0x8f,0x01,0x00,0x01,0x00,0x02,
  511. 0x01,0x00,0x00,0x78,0xe0,0x01,0x00,0x50,
  512. 0x00,0x18,}
  513. };
  514. #ifdef DE4X5_DEBUG
  515. static int de4x5_debug = DE4X5_DEBUG;
  516. #else
  517. /*static int de4x5_debug = (DEBUG_MII | DEBUG_SROM | DEBUG_PCICFG | DEBUG_MEDIA | DEBUG_VERSION);*/
  518. static int de4x5_debug = (DEBUG_MEDIA | DEBUG_VERSION);
  519. #endif
  520. /*
  521. ** Allow per adapter set up. For modules this is simply a command line
  522. ** parameter, e.g.:
  523. ** insmod de4x5 args='eth1:fdx autosense=BNC eth0:autosense=100Mb'.
  524. **
  525. ** For a compiled in driver, place e.g.
  526. ** #define DE4X5_PARM "eth0:fdx autosense=AUI eth2:autosense=TP"
  527. ** here
  528. */
  529. #ifdef DE4X5_PARM
  530. static char *args = DE4X5_PARM;
  531. #else
  532. static char *args;
  533. #endif
  534. struct parameters {
  535. bool fdx;
  536. int autosense;
  537. };
  538. #define DE4X5_AUTOSENSE_MS 250 /* msec autosense tick (DE500) */
  539. #define DE4X5_NDA 0xffe0 /* No Device (I/O) Address */
  540. /*
  541. ** Ethernet PROM defines
  542. */
  543. #define PROBE_LENGTH 32
  544. #define ETH_PROM_SIG 0xAA5500FFUL
  545. /*
  546. ** Ethernet Info
  547. */
  548. #define PKT_BUF_SZ 1536 /* Buffer size for each Tx/Rx buffer */
  549. #define IEEE802_3_SZ 1518 /* Packet + CRC */
  550. #define MAX_PKT_SZ 1514 /* Maximum ethernet packet length */
  551. #define MAX_DAT_SZ 1500 /* Maximum ethernet data length */
  552. #define MIN_DAT_SZ 1 /* Minimum ethernet data length */
  553. #define PKT_HDR_LEN 14 /* Addresses and data length info */
  554. #define FAKE_FRAME_LEN (MAX_PKT_SZ + 1)
  555. #define QUEUE_PKT_TIMEOUT (3*HZ) /* 3 second timeout */
  556. /*
  557. ** EISA bus defines
  558. */
  559. #define DE4X5_EISA_IO_PORTS 0x0c00 /* I/O port base address, slot 0 */
  560. #define DE4X5_EISA_TOTAL_SIZE 0x100 /* I/O address extent */
  561. #define EISA_ALLOWED_IRQ_LIST {5, 9, 10, 11}
  562. #define DE4X5_SIGNATURE {"DE425","DE434","DE435","DE450","DE500"}
  563. #define DE4X5_NAME_LENGTH 8
  564. static c_char *de4x5_signatures[] = DE4X5_SIGNATURE;
  565. /*
  566. ** Ethernet PROM defines for DC21040
  567. */
  568. #define PROBE_LENGTH 32
  569. #define ETH_PROM_SIG 0xAA5500FFUL
  570. /*
  571. ** PCI Bus defines
  572. */
  573. #define PCI_MAX_BUS_NUM 8
  574. #define DE4X5_PCI_TOTAL_SIZE 0x80 /* I/O address extent */
  575. #define DE4X5_CLASS_CODE 0x00020000 /* Network controller, Ethernet */
  576. /*
  577. ** Memory Alignment. Each descriptor is 4 longwords long. To force a
  578. ** particular alignment on the TX descriptor, adjust DESC_SKIP_LEN and
  579. ** DESC_ALIGN. ALIGN aligns the start address of the private memory area
  580. ** and hence the RX descriptor ring's first entry.
  581. */
  582. #define DE4X5_ALIGN4 ((u_long)4 - 1) /* 1 longword align */
  583. #define DE4X5_ALIGN8 ((u_long)8 - 1) /* 2 longword align */
  584. #define DE4X5_ALIGN16 ((u_long)16 - 1) /* 4 longword align */
  585. #define DE4X5_ALIGN32 ((u_long)32 - 1) /* 8 longword align */
  586. #define DE4X5_ALIGN64 ((u_long)64 - 1) /* 16 longword align */
  587. #define DE4X5_ALIGN128 ((u_long)128 - 1) /* 32 longword align */
  588. #define DE4X5_ALIGN DE4X5_ALIGN32 /* Keep the DC21040 happy... */
  589. #define DE4X5_CACHE_ALIGN CAL_16LONG
  590. #define DESC_SKIP_LEN DSL_0 /* Must agree with DESC_ALIGN */
  591. /*#define DESC_ALIGN u32 dummy[4]; / * Must agree with DESC_SKIP_LEN */
  592. #define DESC_ALIGN
  593. #ifndef DEC_ONLY /* See README.de4x5 for using this */
  594. static int dec_only;
  595. #else
  596. static int dec_only = 1;
  597. #endif
  598. /*
  599. ** DE4X5 IRQ ENABLE/DISABLE
  600. */
  601. #define ENABLE_IRQs { \
  602. imr |= lp->irq_en;\
  603. outl(imr, DE4X5_IMR); /* Enable the IRQs */\
  604. }
  605. #define DISABLE_IRQs {\
  606. imr = inl(DE4X5_IMR);\
  607. imr &= ~lp->irq_en;\
  608. outl(imr, DE4X5_IMR); /* Disable the IRQs */\
  609. }
  610. #define UNMASK_IRQs {\
  611. imr |= lp->irq_mask;\
  612. outl(imr, DE4X5_IMR); /* Unmask the IRQs */\
  613. }
  614. #define MASK_IRQs {\
  615. imr = inl(DE4X5_IMR);\
  616. imr &= ~lp->irq_mask;\
  617. outl(imr, DE4X5_IMR); /* Mask the IRQs */\
  618. }
  619. /*
  620. ** DE4X5 START/STOP
  621. */
  622. #define START_DE4X5 {\
  623. omr = inl(DE4X5_OMR);\
  624. omr |= OMR_ST | OMR_SR;\
  625. outl(omr, DE4X5_OMR); /* Enable the TX and/or RX */\
  626. }
  627. #define STOP_DE4X5 {\
  628. omr = inl(DE4X5_OMR);\
  629. omr &= ~(OMR_ST|OMR_SR);\
  630. outl(omr, DE4X5_OMR); /* Disable the TX and/or RX */ \
  631. }
  632. /*
  633. ** DE4X5 SIA RESET
  634. */
  635. #define RESET_SIA outl(0, DE4X5_SICR); /* Reset SIA connectivity regs */
  636. /*
  637. ** DE500 AUTOSENSE TIMER INTERVAL (MILLISECS)
  638. */
  639. #define DE4X5_AUTOSENSE_MS 250
  640. /*
  641. ** SROM Structure
  642. */
  643. struct de4x5_srom {
  644. char sub_vendor_id[2];
  645. char sub_system_id[2];
  646. char reserved[12];
  647. char id_block_crc;
  648. char reserved2;
  649. char version;
  650. char num_controllers;
  651. char ieee_addr[6];
  652. char info[100];
  653. short chksum;
  654. };
  655. #define SUB_VENDOR_ID 0x500a
  656. /*
  657. ** DE4X5 Descriptors. Make sure that all the RX buffers are contiguous
  658. ** and have sizes of both a power of 2 and a multiple of 4.
  659. ** A size of 256 bytes for each buffer could be chosen because over 90% of
  660. ** all packets in our network are <256 bytes long and 64 longword alignment
  661. ** is possible. 1536 showed better 'ttcp' performance. Take your pick. 32 TX
  662. ** descriptors are needed for machines with an ALPHA CPU.
  663. */
  664. #define NUM_RX_DESC 8 /* Number of RX descriptors */
  665. #define NUM_TX_DESC 32 /* Number of TX descriptors */
  666. #define RX_BUFF_SZ 1536 /* Power of 2 for kmalloc and */
  667. /* Multiple of 4 for DC21040 */
  668. /* Allows 512 byte alignment */
  669. struct de4x5_desc {
  670. volatile __le32 status;
  671. __le32 des1;
  672. __le32 buf;
  673. __le32 next;
  674. DESC_ALIGN
  675. };
  676. /*
  677. ** The DE4X5 private structure
  678. */
  679. #define DE4X5_PKT_STAT_SZ 16
  680. #define DE4X5_PKT_BIN_SZ 128 /* Should be >=100 unless you
  681. increase DE4X5_PKT_STAT_SZ */
  682. struct pkt_stats {
  683. u_int bins[DE4X5_PKT_STAT_SZ]; /* Private stats counters */
  684. u_int unicast;
  685. u_int multicast;
  686. u_int broadcast;
  687. u_int excessive_collisions;
  688. u_int tx_underruns;
  689. u_int excessive_underruns;
  690. u_int rx_runt_frames;
  691. u_int rx_collision;
  692. u_int rx_dribble;
  693. u_int rx_overflow;
  694. };
  695. struct de4x5_private {
  696. char adapter_name[80]; /* Adapter name */
  697. u_long interrupt; /* Aligned ISR flag */
  698. struct de4x5_desc *rx_ring; /* RX descriptor ring */
  699. struct de4x5_desc *tx_ring; /* TX descriptor ring */
  700. struct sk_buff *tx_skb[NUM_TX_DESC]; /* TX skb for freeing when sent */
  701. struct sk_buff *rx_skb[NUM_RX_DESC]; /* RX skb's */
  702. int rx_new, rx_old; /* RX descriptor ring pointers */
  703. int tx_new, tx_old; /* TX descriptor ring pointers */
  704. char setup_frame[SETUP_FRAME_LEN]; /* Holds MCA and PA info. */
  705. char frame[64]; /* Min sized packet for loopback*/
  706. spinlock_t lock; /* Adapter specific spinlock */
  707. struct net_device_stats stats; /* Public stats */
  708. struct pkt_stats pktStats; /* Private stats counters */
  709. char rxRingSize;
  710. char txRingSize;
  711. int bus; /* EISA or PCI */
  712. int bus_num; /* PCI Bus number */
  713. int device; /* Device number on PCI bus */
  714. int state; /* Adapter OPENED or CLOSED */
  715. int chipset; /* DC21040, DC21041 or DC21140 */
  716. s32 irq_mask; /* Interrupt Mask (Enable) bits */
  717. s32 irq_en; /* Summary interrupt bits */
  718. int media; /* Media (eg TP), mode (eg 100B)*/
  719. int c_media; /* Remember the last media conn */
  720. bool fdx; /* media full duplex flag */
  721. int linkOK; /* Link is OK */
  722. int autosense; /* Allow/disallow autosensing */
  723. bool tx_enable; /* Enable descriptor polling */
  724. int setup_f; /* Setup frame filtering type */
  725. int local_state; /* State within a 'media' state */
  726. struct mii_phy phy[DE4X5_MAX_PHY]; /* List of attached PHY devices */
  727. struct sia_phy sia; /* SIA PHY Information */
  728. int active; /* Index to active PHY device */
  729. int mii_cnt; /* Number of attached PHY's */
  730. int timeout; /* Scheduling counter */
  731. struct timer_list timer; /* Timer info for kernel */
  732. int tmp; /* Temporary global per card */
  733. struct {
  734. u_long lock; /* Lock the cache accesses */
  735. s32 csr0; /* Saved Bus Mode Register */
  736. s32 csr6; /* Saved Operating Mode Reg. */
  737. s32 csr7; /* Saved IRQ Mask Register */
  738. s32 gep; /* Saved General Purpose Reg. */
  739. s32 gepc; /* Control info for GEP */
  740. s32 csr13; /* Saved SIA Connectivity Reg. */
  741. s32 csr14; /* Saved SIA TX/RX Register */
  742. s32 csr15; /* Saved SIA General Register */
  743. int save_cnt; /* Flag if state already saved */
  744. struct sk_buff_head queue; /* Save the (re-ordered) skb's */
  745. } cache;
  746. struct de4x5_srom srom; /* A copy of the SROM */
  747. int cfrv; /* Card CFRV copy */
  748. int rx_ovf; /* Check for 'RX overflow' tag */
  749. bool useSROM; /* For non-DEC card use SROM */
  750. bool useMII; /* Infoblock using the MII */
  751. int asBitValid; /* Autosense bits in GEP? */
  752. int asPolarity; /* 0 => asserted high */
  753. int asBit; /* Autosense bit number in GEP */
  754. int defMedium; /* SROM default medium */
  755. int tcount; /* Last infoblock number */
  756. int infoblock_init; /* Initialised this infoblock? */
  757. int infoleaf_offset; /* SROM infoleaf for controller */
  758. s32 infoblock_csr6; /* csr6 value in SROM infoblock */
  759. int infoblock_media; /* infoblock media */
  760. int (*infoleaf_fn)(struct net_device *); /* Pointer to infoleaf function */
  761. u_char *rst; /* Pointer to Type 5 reset info */
  762. u_char ibn; /* Infoblock number */
  763. struct parameters params; /* Command line/ #defined params */
  764. struct device *gendev; /* Generic device */
  765. dma_addr_t dma_rings; /* DMA handle for rings */
  766. int dma_size; /* Size of the DMA area */
  767. char *rx_bufs; /* rx bufs on alpha, sparc, ... */
  768. };
  769. /*
  770. ** To get around certain poxy cards that don't provide an SROM
  771. ** for the second and more DECchip, I have to key off the first
  772. ** chip's address. I'll assume there's not a bad SROM iff:
  773. **
  774. ** o the chipset is the same
  775. ** o the bus number is the same and > 0
  776. ** o the sum of all the returned hw address bytes is 0 or 0x5fa
  777. **
  778. ** Also have to save the irq for those cards whose hardware designers
  779. ** can't follow the PCI to PCI Bridge Architecture spec.
  780. */
  781. static struct {
  782. int chipset;
  783. int bus;
  784. int irq;
  785. u_char addr[ETH_ALEN];
  786. } last = {0,};
  787. /*
  788. ** The transmit ring full condition is described by the tx_old and tx_new
  789. ** pointers by:
  790. ** tx_old = tx_new Empty ring
  791. ** tx_old = tx_new+1 Full ring
  792. ** tx_old+txRingSize = tx_new+1 Full ring (wrapped condition)
  793. */
  794. #define TX_BUFFS_AVAIL ((lp->tx_old<=lp->tx_new)?\
  795. lp->tx_old+lp->txRingSize-lp->tx_new-1:\
  796. lp->tx_old -lp->tx_new-1)
  797. #define TX_PKT_PENDING (lp->tx_old != lp->tx_new)
  798. /*
  799. ** Public Functions
  800. */
  801. static int de4x5_open(struct net_device *dev);
  802. static netdev_tx_t de4x5_queue_pkt(struct sk_buff *skb,
  803. struct net_device *dev);
  804. static irqreturn_t de4x5_interrupt(int irq, void *dev_id);
  805. static int de4x5_close(struct net_device *dev);
  806. static struct net_device_stats *de4x5_get_stats(struct net_device *dev);
  807. static void de4x5_local_stats(struct net_device *dev, char *buf, int pkt_len);
  808. static void set_multicast_list(struct net_device *dev);
  809. static int de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  810. /*
  811. ** Private functions
  812. */
  813. static int de4x5_hw_init(struct net_device *dev, u_long iobase, struct device *gendev);
  814. static int de4x5_init(struct net_device *dev);
  815. static int de4x5_sw_reset(struct net_device *dev);
  816. static int de4x5_rx(struct net_device *dev);
  817. static int de4x5_tx(struct net_device *dev);
  818. static void de4x5_ast(struct net_device *dev);
  819. static int de4x5_txur(struct net_device *dev);
  820. static int de4x5_rx_ovfc(struct net_device *dev);
  821. static int autoconf_media(struct net_device *dev);
  822. static void create_packet(struct net_device *dev, char *frame, int len);
  823. static void load_packet(struct net_device *dev, char *buf, u32 flags, struct sk_buff *skb);
  824. static int dc21040_autoconf(struct net_device *dev);
  825. static int dc21041_autoconf(struct net_device *dev);
  826. static int dc21140m_autoconf(struct net_device *dev);
  827. static int dc2114x_autoconf(struct net_device *dev);
  828. static int srom_autoconf(struct net_device *dev);
  829. static int de4x5_suspect_state(struct net_device *dev, int timeout, int prev_state, int (*fn)(struct net_device *, int), int (*asfn)(struct net_device *));
  830. static int dc21040_state(struct net_device *dev, int csr13, int csr14, int csr15, int timeout, int next_state, int suspect_state, int (*fn)(struct net_device *, int));
  831. static int test_media(struct net_device *dev, s32 irqs, s32 irq_mask, s32 csr13, s32 csr14, s32 csr15, s32 msec);
  832. static int test_for_100Mb(struct net_device *dev, int msec);
  833. static int wait_for_link(struct net_device *dev);
  834. static int test_mii_reg(struct net_device *dev, int reg, int mask, bool pol, long msec);
  835. static int is_spd_100(struct net_device *dev);
  836. static int is_100_up(struct net_device *dev);
  837. static int is_10_up(struct net_device *dev);
  838. static int is_anc_capable(struct net_device *dev);
  839. static int ping_media(struct net_device *dev, int msec);
  840. static struct sk_buff *de4x5_alloc_rx_buff(struct net_device *dev, int index, int len);
  841. static void de4x5_free_rx_buffs(struct net_device *dev);
  842. static void de4x5_free_tx_buffs(struct net_device *dev);
  843. static void de4x5_save_skbs(struct net_device *dev);
  844. static void de4x5_rst_desc_ring(struct net_device *dev);
  845. static void de4x5_cache_state(struct net_device *dev, int flag);
  846. static void de4x5_put_cache(struct net_device *dev, struct sk_buff *skb);
  847. static void de4x5_putb_cache(struct net_device *dev, struct sk_buff *skb);
  848. static struct sk_buff *de4x5_get_cache(struct net_device *dev);
  849. static void de4x5_setup_intr(struct net_device *dev);
  850. static void de4x5_init_connection(struct net_device *dev);
  851. static int de4x5_reset_phy(struct net_device *dev);
  852. static void reset_init_sia(struct net_device *dev, s32 sicr, s32 strr, s32 sigr);
  853. static int test_ans(struct net_device *dev, s32 irqs, s32 irq_mask, s32 msec);
  854. static int test_tp(struct net_device *dev, s32 msec);
  855. static int EISA_signature(char *name, struct device *device);
  856. static int PCI_signature(char *name, struct de4x5_private *lp);
  857. static void DevicePresent(struct net_device *dev, u_long iobase);
  858. static void enet_addr_rst(u_long aprom_addr);
  859. static int de4x5_bad_srom(struct de4x5_private *lp);
  860. static short srom_rd(u_long address, u_char offset);
  861. static void srom_latch(u_int command, u_long address);
  862. static void srom_command(u_int command, u_long address);
  863. static void srom_address(u_int command, u_long address, u_char offset);
  864. static short srom_data(u_int command, u_long address);
  865. /*static void srom_busy(u_int command, u_long address);*/
  866. static void sendto_srom(u_int command, u_long addr);
  867. static int getfrom_srom(u_long addr);
  868. static int srom_map_media(struct net_device *dev);
  869. static int srom_infoleaf_info(struct net_device *dev);
  870. static void srom_init(struct net_device *dev);
  871. static void srom_exec(struct net_device *dev, u_char *p);
  872. static int mii_rd(u_char phyreg, u_char phyaddr, u_long ioaddr);
  873. static void mii_wr(int data, u_char phyreg, u_char phyaddr, u_long ioaddr);
  874. static int mii_rdata(u_long ioaddr);
  875. static void mii_wdata(int data, int len, u_long ioaddr);
  876. static void mii_ta(u_long rw, u_long ioaddr);
  877. static int mii_swap(int data, int len);
  878. static void mii_address(u_char addr, u_long ioaddr);
  879. static void sendto_mii(u32 command, int data, u_long ioaddr);
  880. static int getfrom_mii(u32 command, u_long ioaddr);
  881. static int mii_get_oui(u_char phyaddr, u_long ioaddr);
  882. static int mii_get_phy(struct net_device *dev);
  883. static void SetMulticastFilter(struct net_device *dev);
  884. static int get_hw_addr(struct net_device *dev);
  885. static void srom_repair(struct net_device *dev, int card);
  886. static int test_bad_enet(struct net_device *dev, int status);
  887. static int an_exception(struct de4x5_private *lp);
  888. static char *build_setup_frame(struct net_device *dev, int mode);
  889. static void disable_ast(struct net_device *dev);
  890. static long de4x5_switch_mac_port(struct net_device *dev);
  891. static int gep_rd(struct net_device *dev);
  892. static void gep_wr(s32 data, struct net_device *dev);
  893. static void yawn(struct net_device *dev, int state);
  894. static void de4x5_parse_params(struct net_device *dev);
  895. static void de4x5_dbg_open(struct net_device *dev);
  896. static void de4x5_dbg_mii(struct net_device *dev, int k);
  897. static void de4x5_dbg_media(struct net_device *dev);
  898. static void de4x5_dbg_srom(struct de4x5_srom *p);
  899. static void de4x5_dbg_rx(struct sk_buff *skb, int len);
  900. static int dc21041_infoleaf(struct net_device *dev);
  901. static int dc21140_infoleaf(struct net_device *dev);
  902. static int dc21142_infoleaf(struct net_device *dev);
  903. static int dc21143_infoleaf(struct net_device *dev);
  904. static int type0_infoblock(struct net_device *dev, u_char count, u_char *p);
  905. static int type1_infoblock(struct net_device *dev, u_char count, u_char *p);
  906. static int type2_infoblock(struct net_device *dev, u_char count, u_char *p);
  907. static int type3_infoblock(struct net_device *dev, u_char count, u_char *p);
  908. static int type4_infoblock(struct net_device *dev, u_char count, u_char *p);
  909. static int type5_infoblock(struct net_device *dev, u_char count, u_char *p);
  910. static int compact_infoblock(struct net_device *dev, u_char count, u_char *p);
  911. /*
  912. ** Note now that module autoprobing is allowed under EISA and PCI. The
  913. ** IRQ lines will not be auto-detected; instead I'll rely on the BIOSes
  914. ** to "do the right thing".
  915. */
  916. static int io=0x0;/* EDIT THIS LINE FOR YOUR CONFIGURATION IF NEEDED */
  917. module_param(io, int, 0);
  918. module_param(de4x5_debug, int, 0);
  919. module_param(dec_only, int, 0);
  920. module_param(args, charp, 0);
  921. MODULE_PARM_DESC(io, "de4x5 I/O base address");
  922. MODULE_PARM_DESC(de4x5_debug, "de4x5 debug mask");
  923. MODULE_PARM_DESC(dec_only, "de4x5 probe only for Digital boards (0-1)");
  924. MODULE_PARM_DESC(args, "de4x5 full duplex and media type settings; see de4x5.c for details");
  925. MODULE_LICENSE("GPL");
  926. /*
  927. ** List the SROM infoleaf functions and chipsets
  928. */
  929. struct InfoLeaf {
  930. int chipset;
  931. int (*fn)(struct net_device *);
  932. };
  933. static struct InfoLeaf infoleaf_array[] = {
  934. {DC21041, dc21041_infoleaf},
  935. {DC21140, dc21140_infoleaf},
  936. {DC21142, dc21142_infoleaf},
  937. {DC21143, dc21143_infoleaf}
  938. };
  939. #define INFOLEAF_SIZE ARRAY_SIZE(infoleaf_array)
  940. /*
  941. ** List the SROM info block functions
  942. */
  943. static int (*dc_infoblock[])(struct net_device *dev, u_char, u_char *) = {
  944. type0_infoblock,
  945. type1_infoblock,
  946. type2_infoblock,
  947. type3_infoblock,
  948. type4_infoblock,
  949. type5_infoblock,
  950. compact_infoblock
  951. };
  952. #define COMPACT (ARRAY_SIZE(dc_infoblock) - 1)
  953. /*
  954. ** Miscellaneous defines...
  955. */
  956. #define RESET_DE4X5 {\
  957. int i;\
  958. i=inl(DE4X5_BMR);\
  959. mdelay(1);\
  960. outl(i | BMR_SWR, DE4X5_BMR);\
  961. mdelay(1);\
  962. outl(i, DE4X5_BMR);\
  963. mdelay(1);\
  964. for (i=0;i<5;i++) {inl(DE4X5_BMR); mdelay(1);}\
  965. mdelay(1);\
  966. }
  967. #define PHY_HARD_RESET {\
  968. outl(GEP_HRST, DE4X5_GEP); /* Hard RESET the PHY dev. */\
  969. mdelay(1); /* Assert for 1ms */\
  970. outl(0x00, DE4X5_GEP);\
  971. mdelay(2); /* Wait for 2ms */\
  972. }
  973. static const struct net_device_ops de4x5_netdev_ops = {
  974. .ndo_open = de4x5_open,
  975. .ndo_stop = de4x5_close,
  976. .ndo_start_xmit = de4x5_queue_pkt,
  977. .ndo_get_stats = de4x5_get_stats,
  978. .ndo_set_rx_mode = set_multicast_list,
  979. .ndo_do_ioctl = de4x5_ioctl,
  980. .ndo_change_mtu = eth_change_mtu,
  981. .ndo_set_mac_address= eth_mac_addr,
  982. .ndo_validate_addr = eth_validate_addr,
  983. };
  984. static int
  985. de4x5_hw_init(struct net_device *dev, u_long iobase, struct device *gendev)
  986. {
  987. char name[DE4X5_NAME_LENGTH + 1];
  988. struct de4x5_private *lp = netdev_priv(dev);
  989. struct pci_dev *pdev = NULL;
  990. int i, status=0;
  991. dev_set_drvdata(gendev, dev);
  992. /* Ensure we're not sleeping */
  993. if (lp->bus == EISA) {
  994. outb(WAKEUP, PCI_CFPM);
  995. } else {
  996. pdev = to_pci_dev (gendev);
  997. pci_write_config_byte(pdev, PCI_CFDA_PSM, WAKEUP);
  998. }
  999. mdelay(10);
  1000. RESET_DE4X5;
  1001. if ((inl(DE4X5_STS) & (STS_TS | STS_RS)) != 0) {
  1002. return -ENXIO; /* Hardware could not reset */
  1003. }
  1004. /*
  1005. ** Now find out what kind of DC21040/DC21041/DC21140 board we have.
  1006. */
  1007. lp->useSROM = false;
  1008. if (lp->bus == PCI) {
  1009. PCI_signature(name, lp);
  1010. } else {
  1011. EISA_signature(name, gendev);
  1012. }
  1013. if (*name == '\0') { /* Not found a board signature */
  1014. return -ENXIO;
  1015. }
  1016. dev->base_addr = iobase;
  1017. printk ("%s: %s at 0x%04lx", dev_name(gendev), name, iobase);
  1018. status = get_hw_addr(dev);
  1019. printk(", h/w address %pM\n", dev->dev_addr);
  1020. if (status != 0) {
  1021. printk(" which has an Ethernet PRO