3c59x.c 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390
  1. /* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. */
  2. /*
  3. Written 1996-1999 by Donald Becker.
  4. This software may be used and distributed according to the terms
  5. of the GNU General Public License, incorporated herein by reference.
  6. This driver is for the 3Com "Vortex" and "Boomerang" series ethercards.
  7. Members of the series include Fast EtherLink 3c590/3c592/3c595/3c597
  8. and the EtherLink XL 3c900 and 3c905 cards.
  9. Problem reports and questions should be directed to
  10. vortex@scyld.com
  11. The author may be reached as becker@scyld.com, or C/O
  12. Scyld Computing Corporation
  13. 410 Severn Ave., Suite 210
  14. Annapolis MD 21403
  15. Linux Kernel Additions:
  16. 0.99H+lk0.9 - David S. Miller - softnet, PCI DMA updates
  17. 0.99H+lk1.0 - Jeff Garzik <jgarzik@pobox.com>
  18. Remove compatibility defines for kernel versions < 2.2.x.
  19. Update for new 2.3.x module interface
  20. LK1.1.2 (March 19, 2000)
  21. * New PCI interface (jgarzik)
  22. LK1.1.3 25 April 2000, Andrew Morton <andrewm@uow.edu.au>
  23. - Merged with 3c575_cb.c
  24. - Don't set RxComplete in boomerang interrupt enable reg
  25. - spinlock in vortex_timer to protect mdio functions
  26. - disable local interrupts around call to vortex_interrupt in
  27. vortex_tx_timeout() (So vortex_interrupt can use spin_lock())
  28. - Select window 3 in vortex_timer()'s write to Wn3_MAC_Ctrl
  29. - In vortex_start_xmit(), move the lock to _after_ we've altered
  30. vp->cur_tx and vp->tx_full. This defeats the race between
  31. vortex_start_xmit() and vortex_interrupt which was identified
  32. by Bogdan Costescu.
  33. - Merged back support for six new cards from various sources
  34. - Set vortex_have_pci if pci_module_init returns zero (fixes cardbus
  35. insertion oops)
  36. - Tell it that 3c905C has NWAY for 100bT autoneg
  37. - Fix handling of SetStatusEnd in 'Too much work..' code, as
  38. per 2.3.99's 3c575_cb (Dave Hinds).
  39. - Split ISR into two for vortex & boomerang
  40. - Fix MOD_INC/DEC races
  41. - Handle resource allocation failures.
  42. - Fix 3CCFE575CT LED polarity
  43. - Make tx_interrupt_mitigation the default
  44. LK1.1.4 25 April 2000, Andrew Morton <andrewm@uow.edu.au>
  45. - Add extra TxReset to vortex_up() to fix 575_cb hotplug initialisation probs.
  46. - Put vortex_info_tbl into __devinitdata
  47. - In the vortex_error StatsFull HACK, disable stats in vp->intr_enable as well
  48. as in the hardware.
  49. - Increased the loop counter in issue_and_wait from 2,000 to 4,000.
  50. LK1.1.5 28 April 2000, andrewm
  51. - Added powerpc defines (John Daniel <jdaniel@etresoft.com> said these work...)
  52. - Some extra diagnostics
  53. - In vortex_error(), reset the Tx on maxCollisions. Otherwise most
  54. chips usually get a Tx timeout.
  55. - Added extra_reset module parm
  56. - Replaced some inline timer manip with mod_timer
  57. (Franois romieu <Francois.Romieu@nic.fr>)
  58. - In vortex_up(), don't make Wn3_config initialisation dependent upon has_nway
  59. (this came across from 3c575_cb).
  60. LK1.1.6 06 Jun 2000, andrewm
  61. - Backed out the PPC defines.
  62. - Use del_timer_sync(), mod_timer().
  63. - Fix wrapped ulong comparison in boomerang_rx()
  64. - Add IS_TORNADO, use it to suppress 3c905C checksum error msg
  65. (Donald Becker, I Lee Hetherington <ilh@sls.lcs.mit.edu>)
  66. - Replace union wn3_config with BFINS/BFEXT manipulation for
  67. sparc64 (Pete Zaitcev, Peter Jones)
  68. - In vortex_error, do_tx_reset and vortex_tx_timeout(Vortex):
  69. do a netif_wake_queue() to better recover from errors. (Anders Pedersen,
  70. Donald Becker)
  71. - Print a warning on out-of-memory (rate limited to 1 per 10 secs)
  72. - Added two more Cardbus 575 NICs: 5b57 and 6564 (Paul Wagland)
  73. LK1.1.7 2 Jul 2000 andrewm
  74. - Better handling of shared IRQs
  75. - Reset the transmitter on a Tx reclaim error
  76. - Fixed crash under OOM during vortex_open() (Mark Hemment)
  77. - Fix Rx cessation problem during OOM (help from Mark Hemment)
  78. - The spinlocks around the mdio access were blocking interrupts for 300uS.
  79. Fix all this to use spin_lock_bh() within mdio_read/write
  80. - Only write to TxFreeThreshold if it's a boomerang - other NICs don't
  81. have one.
  82. - Added 802.3x MAC-layer flow control support
  83. LK1.1.8 13 Aug 2000 andrewm
  84. - Ignore request_region() return value - already reserved if Cardbus.
  85. - Merged some additional Cardbus flags from Don's 0.99Qk
  86. - Some fixes for 3c556 (Fred Maciel)
  87. - Fix for EISA initialisation (Jan Rekorajski)
  88. - Renamed MII_XCVR_PWR and EEPROM_230 to align with 3c575_cb and D. Becker's drivers
  89. - Fixed MII_XCVR_PWR for 3CCFE575CT
  90. - Added INVERT_LED_PWR, used it.
  91. - Backed out the extra_reset stuff
  92. LK1.1.9 12 Sep 2000 andrewm
  93. - Backed out the tx_reset_resume flags. It was a no-op.
  94. - In vortex_error, don't reset the Tx on txReclaim errors
  95. - In vortex_error, don't reset the Tx on maxCollisions errors.
  96. Hence backed out all the DownListPtr logic here.
  97. - In vortex_error, give Tornado cards a partial TxReset on
  98. maxCollisions (David Hinds). Defined MAX_COLLISION_RESET for this.
  99. - Redid some driver flags and device names based on pcmcia_cs-3.1.20.
  100. - Fixed a bug where, if vp->tx_full is set when the interface
  101. is downed, it remains set when the interface is upped. Bad
  102. things happen.
  103. LK1.1.10 17 Sep 2000 andrewm
  104. - Added EEPROM_8BIT for 3c555 (Fred Maciel)
  105. - Added experimental support for the 3c556B Laptop Hurricane (Louis Gerbarg)
  106. - Add HAS_NWAY to "3c900 Cyclone 10Mbps TPO"
  107. LK1.1.11 13 Nov 2000 andrewm
  108. - Dump MOD_INC/DEC_USE_COUNT, use SET_MODULE_OWNER
  109. LK1.1.12 1 Jan 2001 andrewm (2.4.0-pre1)
  110. - Call pci_enable_device before we request our IRQ (Tobias Ringstrom)
  111. - Add 3c590 PCI latency timer hack to vortex_probe1 (from 0.99Ra)
  112. - Added extended issue_and_wait for the 3c905CX.
  113. - Look for an MII on PHY index 24 first (3c905CX oddity).
  114. - Add HAS_NWAY to 3cSOHO100-TX (Brett Frankenberger)
  115. - Don't free skbs we don't own on oom path in vortex_open().
  116. LK1.1.13 27 Jan 2001
  117. - Added explicit `medialock' flag so we can truly
  118. lock the media type down with `options'.
  119. - "check ioremap return and some tidbits" (Arnaldo Carvalho de Melo <acme@conectiva.com.br>)
  120. - Added and used EEPROM_NORESET for 3c556B PM resumes.
  121. - Fixed leakage of vp->rx_ring.
  122. - Break out separate HAS_HWCKSM device capability flag.
  123. - Kill vp->tx_full (ANK)
  124. - Merge zerocopy fragment handling (ANK?)
  125. LK1.1.14 15 Feb 2001
  126. - Enable WOL. Can be turned on with `enable_wol' module option.
  127. - EISA and PCI initialisation fixes (jgarzik, Manfred Spraul)
  128. - If a device's internalconfig register reports it has NWAY,
  129. use it, even if autoselect is enabled.
  130. LK1.1.15 6 June 2001 akpm
  131. - Prevent double counting of received bytes (Lars Christensen)
  132. - Add ethtool support (jgarzik)
  133. - Add module parm descriptions (Andrzej M. Krzysztofowicz)
  134. - Implemented alloc_etherdev() API
  135. - Special-case the 'Tx error 82' message.
  136. LK1.1.16 18 July 2001 akpm
  137. - Make NETIF_F_SG dependent upon nr_free_highpages(), not on CONFIG_HIGHMEM
  138. - Lessen verbosity of bootup messages
  139. - Fix WOL - use new PM API functions.
  140. - Use netif_running() instead of vp->open in suspend/resume.
  141. - Don't reset the interface logic on open/close/rmmod. It upsets
  142. autonegotiation, and hence DHCP (from 0.99T).
  143. - Back out EEPROM_NORESET flag because of the above (we do it for all
  144. NICs).
  145. - Correct 3c982 identification string
  146. - Rename wait_for_completion() to issue_and_wait() to avoid completion.h
  147. clash.
  148. LK1.1.17 18Dec01 akpm
  149. - PCI ID 9805 is a Python-T, not a dual-port Cyclone. Apparently.
  150. And it has NWAY.
  151. - Mask our advertised modes (vp->advertising) with our capabilities
  152. (MII reg5) when deciding which duplex mode to use.
  153. - Add `global_options' as default for options[]. Ditto global_enable_wol,
  154. global_full_duplex.
  155. LK1.1.18 01Jul02 akpm
  156. - Fix for undocumented transceiver power-up bit on some 3c566B's
  157. (Donald Becker, Rahul Karnik)
  158. - See http://www.zip.com.au/~akpm/linux/#3c59x-2.3 for more details.
  159. - Also see Documentation/networking/vortex.txt
  160. LK1.1.19 10Nov02 Marc Zyngier <maz@wild-wind.fr.eu.org>
  161. - EISA sysfs integration.
  162. */
  163. /*
  164. * FIXME: This driver _could_ support MTU changing, but doesn't. See Don's hamachi.c implementation
  165. * as well as other drivers
  166. *
  167. * NOTE: If you make 'vortex_debug' a constant (#define vortex_debug 0) the driver shrinks by 2k
  168. * due to dead code elimination. There will be some performance benefits from this due to
  169. * elimination of all the tests and reduced cache footprint.
  170. */
  171. #define DRV_NAME "3c59x"
  172. /* A few values that may be tweaked. */
  173. /* Keep the ring sizes a power of two for efficiency. */
  174. #define TX_RING_SIZE 16
  175. #define RX_RING_SIZE 32
  176. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
  177. /* "Knobs" that adjust features and parameters. */
  178. /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
  179. Setting to > 1512 effectively disables this feature. */
  180. #ifndef __arm__
  181. static int rx_copybreak = 200;
  182. #else
  183. /* ARM systems perform better by disregarding the bus-master
  184. transfer capability of these cards. -- rmk */
  185. static int rx_copybreak = 1513;
  186. #endif
  187. /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
  188. static const int mtu = 1500;
  189. /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
  190. static int max_interrupt_work = 32;
  191. /* Tx timeout interval (millisecs) */
  192. static int watchdog = 5000;
  193. /* Allow aggregation of Tx interrupts. Saves CPU load at the cost
  194. * of possible Tx stalls if the system is blocking interrupts
  195. * somewhere else. Undefine this to disable.
  196. */
  197. #define tx_interrupt_mitigation 1
  198. /* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */
  199. #define vortex_debug debug
  200. #ifdef VORTEX_DEBUG
  201. static int vortex_debug = VORTEX_DEBUG;
  202. #else
  203. static int vortex_debug = 1;
  204. #endif
  205. #include <linux/config.h>
  206. #include <linux/module.h>
  207. #include <linux/kernel.h>
  208. #include <linux/string.h>
  209. #include <linux/timer.h>
  210. #include <linux/errno.h>
  211. #include <linux/in.h>
  212. #include <linux/ioport.h>
  213. #include <linux/slab.h>
  214. #include <linux/interrupt.h>
  215. #include <linux/pci.h>
  216. #include <linux/mii.h>
  217. #include <linux/init.h>
  218. #include <linux/netdevice.h>
  219. #include <linux/etherdevice.h>
  220. #include <linux/skbuff.h>
  221. #include <linux/ethtool.h>
  222. #include <linux/highmem.h>
  223. #include <linux/eisa.h>
  224. #include <linux/bitops.h>
  225. #include <linux/jiffies.h>
  226. #include <asm/irq.h> /* For NR_IRQS only. */
  227. #include <asm/io.h>
  228. #include <asm/uaccess.h>
  229. /* Kernel compatibility defines, some common to David Hinds' PCMCIA package.
  230. This is only in the support-all-kernels source code. */
  231. #define RUN_AT(x) (jiffies + (x))
  232. #include <linux/delay.h>
  233. static char version[] __devinitdata =
  234. DRV_NAME ": Donald Becker and others. www.scyld.com/network/vortex.html\n";
  235. MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
  236. MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver ");
  237. MODULE_LICENSE("GPL");
  238. /* Operational parameter that usually are not changed. */
  239. /* The Vortex size is twice that of the original EtherLinkIII series: the
  240. runtime register window, window 1, is now always mapped in.
  241. The Boomerang size is twice as large as the Vortex -- it has additional
  242. bus master control registers. */
  243. #define VORTEX_TOTAL_SIZE 0x20
  244. #define BOOMERANG_TOTAL_SIZE 0x40
  245. /* Set iff a MII transceiver on any interface requires mdio preamble.
  246. This only set with the original DP83840 on older 3c905 boards, so the extra
  247. code size of a per-interface flag is not worthwhile. */
  248. static char mii_preamble_required;
  249. #define PFX DRV_NAME ": "
  250. /*
  251. Theory of Operation
  252. I. Board Compatibility
  253. This device driver is designed for the 3Com FastEtherLink and FastEtherLink
  254. XL, 3Com's PCI to 10/100baseT adapters. It also works with the 10Mbs
  255. versions of the FastEtherLink cards. The supported product IDs are
  256. 3c590, 3c592, 3c595, 3c597, 3c900, 3c905
  257. The related ISA 3c515 is supported with a separate driver, 3c515.c, included
  258. with the kernel source or available from
  259. cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.html
  260. II. Board-specific settings
  261. PCI bus devices are configured by the system at boot time, so no jumpers
  262. need to be set on the board. The system BIOS should be set to assign the
  263. PCI INTA signal to an otherwise unused system IRQ line.
  264. The EEPROM settings for media type and forced-full-duplex are observed.
  265. The EEPROM media type should be left at the default "autoselect" unless using
  266. 10base2 or AUI connections which cannot be reliably detected.
  267. III. Driver operation
  268. The 3c59x series use an interface that's very similar to the previous 3c5x9
  269. series. The primary interface is two programmed-I/O FIFOs, with an
  270. alternate single-contiguous-region bus-master transfer (see next).
  271. The 3c900 "Boomerang" series uses a full-bus-master interface with separate
  272. lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
  273. DEC Tulip and Intel Speedo3. The first chip version retains a compatible
  274. programmed-I/O interface that has been removed in 'B' and subsequent board
  275. revisions.
  276. One extension that is advertised in a very large font is that the adapters
  277. are capable of being bus masters. On the Vortex chip this capability was
  278. only for a single contiguous region making it far less useful than the full
  279. bus master capability. There is a significant performance impact of taking
  280. an extra interrupt or polling for the completion of each transfer, as well
  281. as difficulty sharing the single transfer engine between the transmit and
  282. receive threads. Using DMA transfers is a win only with large blocks or
  283. with the flawed versions of the Intel Orion motherboard PCI controller.
  284. The Boomerang chip's full-bus-master interface is useful, and has the
  285. currently-unused advantages over other similar chips that queued transmit
  286. packets may be reordered and receive buffer groups are associated with a
  287. single frame.
  288. With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme.
  289. Rather than a fixed intermediate receive buffer, this scheme allocates
  290. full-sized skbuffs as receive buffers. The value RX_COPYBREAK is used as
  291. the copying breakpoint: it is chosen to trade-off the memory wasted by
  292. passing the full-sized skbuff to the queue layer for all frames vs. the
  293. copying cost of copying a frame to a correctly-sized skbuff.
  294. IIIC. Synchronization
  295. The driver runs as two independent, single-threaded flows of control. One
  296. is the send-packet routine, which enforces single-threaded use by the
  297. dev->tbusy flag. The other thread is the interrupt handler, which is single
  298. threaded by the hardware and other software.
  299. IV. Notes
  300. Thanks to Cameron Spitzer and Terry Murphy of 3Com for providing development
  301. 3c590, 3c595, and 3c900 boards.
  302. The name "Vortex" is the internal 3Com project name for the PCI ASIC, and
  303. the EISA version is called "Demon". According to Terry these names come
  304. from rides at the local amusement park.
  305. The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes!
  306. This driver only supports ethernet packets because of the skbuff allocation
  307. limit of 4K.
  308. */
  309. /* This table drives the PCI probe routines. It's mostly boilerplate in all
  310. of the drivers, and will likely be provided by some future kernel.
  311. */
  312. enum pci_flags_bit {
  313. PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
  314. PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
  315. };
  316. enum { IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4, IS_TORNADO=8,
  317. EEPROM_8BIT=0x10, /* AKPM: Uses 0x230 as the base bitmaps for EEPROM reads */
  318. HAS_PWR_CTRL=0x20, HAS_MII=0x40, HAS_NWAY=0x80, HAS_CB_FNS=0x100,
  319. INVERT_MII_PWR=0x200, INVERT_LED_PWR=0x400, MAX_COLLISION_RESET=0x800,
  320. EEPROM_OFFSET=0x1000, HAS_HWCKSM=0x2000, WNO_XCVR_PWR=0x4000,
  321. EXTRA_PREAMBLE=0x8000, EEPROM_RESET=0x10000, };
  322. enum vortex_chips {
  323. CH_3C590 = 0,
  324. CH_3C592,
  325. CH_3C597,
  326. CH_3C595_1,
  327. CH_3C595_2,
  328. CH_3C595_3,
  329. CH_3C900_1,
  330. CH_3C900_2,
  331. CH_3C900_3,
  332. CH_3C900_4,
  333. CH_3C900_5,
  334. CH_3C900B_FL,
  335. CH_3C905_1,
  336. CH_3C905_2,
  337. CH_3C905B_1,
  338. CH_3C905B_2,
  339. CH_3C905B_FX,
  340. CH_3C905C,
  341. CH_3C9202,
  342. CH_3C980,
  343. CH_3C9805,
  344. CH_3CSOHO100_TX,
  345. CH_3C555,
  346. CH_3C556,
  347. CH_3C556B,
  348. CH_3C575,
  349. CH_3C575_1,
  350. CH_3CCFE575,
  351. CH_3CCFE575CT,
  352. CH_3CCFE656,
  353. CH_3CCFEM656,
  354. CH_3CCFEM656_1,
  355. CH_3C450,
  356. CH_3C920,
  357. CH_3C982A,
  358. CH_3C982B,
  359. CH_905BT4,
  360. CH_920B_EMB_WNM,
  361. };
  362. /* note: this array directly indexed by above enums, and MUST
  363. * be kept in sync with both the enums above, and the PCI device
  364. * table below
  365. */
  366. static struct vortex_chip_info {
  367. const char *name;
  368. int flags;
  369. int drv_flags;
  370. int io_size;
  371. } vortex_info_tbl[] __devinitdata = {
  372. {"3c590 Vortex 10Mbps",
  373. PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
  374. {"3c592 EISA 10Mbps Demon/Vortex", /* AKPM: from Don's 3c59x_cb.c 0.49H */
  375. PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
  376. {"3c597 EISA Fast Demon/Vortex", /* AKPM: from Don's 3c59x_cb.c 0.49H */
  377. PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
  378. {"3c595 Vortex 100baseTx",
  379. PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
  380. {"3c595 Vortex 100baseT4",
  381. PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
  382. {"3c595 Vortex 100base-MII",
  383. PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, },
  384. {"3c900 Boomerang 10baseT",
  385. PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|EEPROM_RESET, 64, },
  386. {"3c900 Boomerang 10Mbps Combo",
  387. PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|EEPROM_RESET, 64, },
  388. {"3c900 Cyclone 10Mbps TPO", /* AKPM: from Don's 0.99M */
  389. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  390. {"3c900 Cyclone 10Mbps Combo",
  391. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  392. {"3c900 Cyclone 10Mbps TPC", /* AKPM: from Don's 0.99M */
  393. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  394. {"3c900B-FL Cyclone 10base-FL",
  395. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  396. {"3c905 Boomerang 100baseTx",
  397. PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_RESET, 64, },
  398. {"3c905 Boomerang 100baseT4",
  399. PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_RESET, 64, },
  400. {"3c905B Cyclone 100baseTx",
  401. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  402. {"3c905B Cyclone 10/100/BNC",
  403. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
  404. {"3c905B-FX Cyclone 100baseFx",
  405. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  406. {"3c905C Tornado",
  407. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  408. {"3c920B-EMB-WNM (ATI Radeon 9100 IGP)",
  409. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_MII|HAS_HWCKSM, 128, },
  410. {"3c980 Cyclone",
  411. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
  412. {"3c980C Python-T",
  413. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
  414. {"3cSOHO100-TX Hurricane",
  415. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
  416. {"3c555 Laptop Hurricane",
  417. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|EEPROM_8BIT|HAS_HWCKSM, 128, },
  418. {"3c556 Laptop Tornado",
  419. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_8BIT|HAS_CB_FNS|INVERT_MII_PWR|
  420. HAS_HWCKSM, 128, },
  421. {"3c556B Laptop Hurricane",
  422. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|EEPROM_OFFSET|HAS_CB_FNS|INVERT_MII_PWR|
  423. WNO_XCVR_PWR|HAS_HWCKSM, 128, },
  424. {"3c575 [Megahertz] 10/100 LAN CardBus",
  425. PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },
  426. {"3c575 Boomerang CardBus",
  427. PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII|EEPROM_8BIT, 128, },
  428. {"3CCFE575BT Cyclone CardBus",
  429. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|
  430. INVERT_LED_PWR|HAS_HWCKSM, 128, },
  431. {"3CCFE575CT Tornado CardBus",
  432. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
  433. MAX_COLLISION_RESET|HAS_HWCKSM, 128, },
  434. {"3CCFE656 Cyclone CardBus",
  435. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
  436. INVERT_LED_PWR|HAS_HWCKSM, 128, },
  437. {"3CCFEM656B Cyclone+Winmodem CardBus",
  438. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
  439. INVERT_LED_PWR|HAS_HWCKSM, 128, },
  440. {"3CXFEM656C Tornado+Winmodem CardBus", /* From pcmcia-cs-3.1.5 */
  441. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_CB_FNS|EEPROM_8BIT|INVERT_MII_PWR|
  442. MAX_COLLISION_RESET|HAS_HWCKSM, 128, },
  443. {"3c450 HomePNA Tornado", /* AKPM: from Don's 0.99Q */
  444. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
  445. {"3c920 Tornado",
  446. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
  447. {"3c982 Hydra Dual Port A",
  448. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_HWCKSM|HAS_NWAY, 128, },
  449. {"3c982 Hydra Dual Port B",
  450. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_HWCKSM|HAS_NWAY, 128, },
  451. {"3c905B-T4",
  452. PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM|EXTRA_PREAMBLE, 128, },
  453. {"3c920B-EMB-WNM Tornado",
  454. PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
  455. {NULL,}, /* NULL terminated list. */
  456. };
  457. static struct pci_device_id vortex_pci_tbl[] = {
  458. { 0x10B7, 0x5900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C590 },
  459. { 0x10B7, 0x5920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C592 },
  460. { 0x10B7, 0x5970, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C597 },
  461. { 0x10B7, 0x5950, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_1 },
  462. { 0x10B7, 0x5951, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_2 },
  463. { 0x10B7, 0x5952, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C595_3 },
  464. { 0x10B7, 0x9000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_1 },
  465. { 0x10B7, 0x9001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_2 },
  466. { 0x10B7, 0x9004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_3 },
  467. { 0x10B7, 0x9005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_4 },
  468. { 0x10B7, 0x9006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900_5 },
  469. { 0x10B7, 0x900A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C900B_FL },
  470. { 0x10B7, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_1 },
  471. { 0x10B7, 0x9051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905_2 },
  472. { 0x10B7, 0x9055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_1 },
  473. { 0x10B7, 0x9058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_2 },
  474. { 0x10B7, 0x905A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905B_FX },
  475. { 0x10B7, 0x9200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C905C },
  476. { 0x10B7, 0x9202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C9202 },
  477. { 0x10B7, 0x9800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C980 },
  478. { 0x10B7, 0x9805, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C9805 },
  479. { 0x10B7, 0x7646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CSOHO100_TX },
  480. { 0x10B7, 0x5055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C555 },
  481. { 0x10B7, 0x6055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C556 },
  482. { 0x10B7, 0x6056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C556B },
  483. { 0x10B7, 0x5b57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575 },
  484. { 0x10B7, 0x5057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C575_1 },
  485. { 0x10B7, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575 },
  486. { 0x10B7, 0x5257, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE575CT },
  487. { 0x10B7, 0x6560, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFE656 },
  488. { 0x10B7, 0x6562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656 },
  489. { 0x10B7, 0x6564, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3CCFEM656_1 },
  490. { 0x10B7, 0x4500, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C450 },
  491. { 0x10B7, 0x9201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C920 },
  492. { 0x10B7, 0x1201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C982A },
  493. { 0x10B7, 0x1202, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_3C982B },
  494. { 0x10B7, 0x9056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_905BT4 },
  495. { 0x10B7, 0x9210, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_920B_EMB_WNM },
  496. {0,} /* 0 terminated list. */
  497. };
  498. MODULE_DEVICE_TABLE(pci, vortex_pci_tbl);
  499. /* Operational definitions.
  500. These are not used by other compilation units and thus are not
  501. exported in a ".h" file.
  502. First the windows. There are eight register windows, with the command
  503. and status registers available in each.
  504. */
  505. #define EL3WINDOW(win_num) iowrite16(SelectWindow + (win_num), ioaddr + EL3_CMD)
  506. #define EL3_CMD 0x0e
  507. #define EL3_STATUS 0x0e
  508. /* The top five bits written to EL3_CMD are a command, the lower
  509. 11 bits are the parameter, if applicable.
  510. Note that 11 parameters bits was fine for ethernet, but the new chip
  511. can handle FDDI length frames (~4500 octets) and now parameters count
  512. 32-bit 'Dwords' rather than octets. */
  513. enum vortex_cmd {
  514. TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
  515. RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11,
  516. UpStall = 6<<11, UpUnstall = (6<<11)+1,
  517. DownStall = (6<<11)+2, DownUnstall = (6<<11)+3,
  518. RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
  519. FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
  520. SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
  521. SetTxThreshold = 18<<11, SetTxStart = 19<<11,
  522. StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
  523. StatsDisable = 22<<11, StopCoax = 23<<11, SetFilterBit = 25<<11,};
  524. /* The SetRxFilter command accepts the following classes: */
  525. enum RxFilter {
  526. RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
  527. /* Bits in the general status register. */
  528. enum vortex_status {
  529. IntLatch = 0x0001, HostError = 0x0002, TxComplete = 0x0004,
  530. TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
  531. IntReq = 0x0040, StatsFull = 0x0080,
  532. DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10,
  533. DMAInProgress = 1<<11, /* DMA controller is still busy.*/
  534. CmdInProgress = 1<<12, /* EL3_CMD is still busy.*/
  535. };
  536. /* Register window 1 offsets, the window used in normal operation.
  537. On the Vortex this window is always mapped at offsets 0x10-0x1f. */
  538. enum Window1 {
  539. TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
  540. RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
  541. TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
  542. };
  543. enum Window0 {
  544. Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */
  545. Wn0EepromData = 12, /* Window 0: EEPROM results register. */
  546. IntrStatus=0x0E, /* Valid in all windows. */
  547. };
  548. enum Win0_EEPROM_bits {
  549. EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
  550. EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
  551. EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
  552. };
  553. /* EEPROM locations. */
  554. enum eeprom_offset {
  555. PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
  556. EtherLink3ID=7, IFXcvrIO=8, IRQLine=9,
  557. NodeAddr01=10, NodeAddr23=11, NodeAddr45=12,
  558. DriverTune=13, Checksum=15};
  559. enum Window2 { /* Window 2. */
  560. Wn2_ResetOptions=12,
  561. };
  562. enum Window3 { /* Window 3: MAC/config bits. */
  563. Wn3_Config=0, Wn3_MaxPktSize=4, Wn3_MAC_Ctrl=6, Wn3_Options=8,
  564. };
  565. #define BFEXT(value, offset, bitcount) \
  566. ((((unsigned long)(value)) >> (offset)) & ((1 << (bitcount)) - 1))
  567. #define BFINS(lhs, rhs, offset, bitcount) \
  568. (((lhs) & ~((((1 << (bitcount)) - 1)) << (offset))) | \
  569. (((rhs) & ((1 << (bitcount)) - 1)) << (offset)))
  570. #define RAM_SIZE(v) BFEXT(v, 0, 3)
  571. #define RAM_WIDTH(v) BFEXT(v, 3, 1)
  572. #define RAM_SPEED(v) BFEXT(v, 4, 2)
  573. #define ROM_SIZE(v) BFEXT(v, 6, 2)
  574. #define RAM_SPLIT(v) BFEXT(v, 16, 2)
  575. #define XCVR(v) BFEXT(v, 20, 4)
  576. #define AUTOSELECT(v) BFEXT(v, 24, 1)
  577. enum Window4 { /* Window 4: Xcvr/media bits. */
  578. Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
  579. };
  580. enum Win4_Media_bits {
  581. Media_SQE = 0x0008, /* Enable SQE error counting for AUI. */
  582. Media_10TP = 0x00C0, /* Enable link beat and jabber for 10baseT. */
  583. Media_Lnk = 0x0080, /* Enable just link beat for 100TX/100FX. */
  584. Media_LnkBeat = 0x0800,
  585. };
  586. enum Window7 { /* Window 7: Bus Master control. */
  587. Wn7_MasterAddr = 0, Wn7_VlanEtherType=4, Wn7_MasterLen = 6,
  588. Wn7_MasterStatus = 12,
  589. };
  590. /* Boomerang bus master control registers. */
  591. enum MasterCtrl {
  592. PktStatus = 0x20, DownListPtr = 0x24, FragAddr = 0x28, FragLen = 0x2c,
  593. TxFreeThreshold = 0x2f, UpPktStatus = 0x30, UpListPtr = 0x38,
  594. };
  595. /* The Rx and Tx descriptor lists.
  596. Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
  597. alignment contraint on tx_ring[] and rx_ring[]. */
  598. #define LAST_FRAG 0x80000000 /* Last Addr/Len pair in descriptor. */
  599. #define DN_COMPLETE 0x00010000 /* This packet has been downloaded */
  600. struct boom_rx_desc {
  601. u32 next; /* Last entry points to 0. */
  602. s32 status;
  603. u32 addr; /* Up to 63 addr/len pairs possible. */
  604. s32 length; /* Set LAST_FRAG to indicate last pair. */
  605. };
  606. /* Values for the Rx status entry. */
  607. enum rx_desc_status {
  608. RxDComplete=0x00008000, RxDError=0x4000,
  609. /* See boomerang_rx() for actual error bits */
  610. IPChksumErr=1<<25, TCPChksumErr=1<<26, UDPChksumErr=1<<27,
  611. IPChksumValid=1<<29, TCPChksumValid=1<<30, UDPChksumValid=1<<31,
  612. };
  613. #ifdef MAX_SKB_FRAGS
  614. #define DO_ZEROCOPY 1
  615. #else
  616. #define DO_ZEROCOPY 0
  617. #endif
  618. struct boom_tx_desc {
  619. u32 next; /* Last entry points to 0. */
  620. s32 status; /* bits 0:12 length, others see below. */
  621. #if DO_ZEROCOPY
  622. struct {
  623. u32 addr;
  624. s32 length;
  625. } frag[1+MAX_SKB_FRAGS];
  626. #else
  627. u32 addr;
  628. s32 length;
  629. #endif
  630. };
  631. /* Values for the Tx status entry. */
  632. enum tx_desc_status {
  633. CRCDisable=0x2000, TxDComplete=0x8000,
  634. AddIPChksum=0x02000000, AddTCPChksum=0x04000000, AddUDPChksum=0x08000000,
  635. TxIntrUploaded=0x80000000, /* IRQ when in FIFO, but maybe not sent. */
  636. };
  637. /* Chip features we care about in vp->capabilities, read from the EEPROM. */
  638. enum ChipCaps { CapBusMaster=0x20, CapPwrMgmt=0x2000 };
  639. struct vortex_extra_stats {
  640. unsigned long tx_deferred;
  641. unsigned long tx_max_collisions;
  642. unsigned long tx_multiple_collisions;
  643. unsigned long tx_single_collisions;
  644. unsigned long rx_bad_ssd;
  645. };
  646. struct vortex_private {
  647. /* The Rx and Tx rings should be quad-word-aligned. */
  648. struct boom_rx_desc* rx_ring;
  649. struct boom_tx_desc* tx_ring;
  650. dma_addr_t rx_ring_dma;
  651. dma_addr_t tx_ring_dma;
  652. /* The addresses of transmit- and receive-in-place skbuffs. */
  653. struct sk_buff* rx_skbuff[RX_RING_SIZE];
  654. struct sk_buff* tx_skbuff[TX_RING_SIZE];
  655. unsigned int cur_rx, cur_tx; /* The next free ring entry */
  656. unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
  657. struct net_device_stats stats; /* Generic stats */
  658. struct vortex_extra_stats xstats; /* NIC-specific extra stats */
  659. struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */
  660. dma_addr_t tx_skb_dma; /* Allocated DMA address for bus master ctrl DMA. */
  661. /* PCI configuration space information. */
  662. struct device *gendev;
  663. void __iomem *ioaddr; /* IO address space */
  664. void __iomem *cb_fn_base; /* CardBus function status addr space. */
  665. /* Some values here only for performance evaluation and path-coverage */
  666. int rx_nocopy, rx_copy, queued_packet, rx_csumhits;
  667. int card_idx;
  668. /* The remainder are related to chip state, mostly media selection. */
  669. struct timer_list timer; /* Media selection timer. */
  670. struct timer_list rx_oom_timer; /* Rx skb allocation retry timer */
  671. int options; /* User-settable misc. driver options. */
  672. unsigned int media_override:4, /* Passed-in media type. */
  673. default_media:4, /* Read from the EEPROM/Wn3_Config. */
  674. full_duplex:1, autoselect:1,
  675. bus_master:1, /* Vortex can only do a fragment bus-m. */
  676. full_bus_master_tx:1, full_bus_master_rx:2, /* Boomerang */
  677. flow_ctrl:1, /* Use 802.3x flow control (PAUSE only) */
  678. partner_flow_ctrl:1, /* Partner supports flow control */
  679. has_nway:1,
  680. enable_wol:1, /* Wake-on-LAN is enabled */
  681. pm_state_valid:1, /* pci_dev->saved_config_space has sane contents */
  682. open:1,
  683. medialock:1,
  684. must_free_region:1, /* Flag: if zero, Cardbus owns the I/O region */
  685. large_frames:1; /* accept large frames */
  686. int drv_flags;
  687. u16 status_enable;
  688. u16 intr_enable;
  689. u16 available_media; /* From Wn3_Options. */
  690. u16 capabilities, info1, info2; /* Various, from EEPROM. */
  691. u16 advertising; /* NWay media advertisement */
  692. unsigned char phys[2]; /* MII device addresses. */
  693. u16 deferred; /* Resend these interrupts when we
  694. * bale from the ISR */
  695. u16 io_size; /* Size of PCI region (for release_region) */
  696. spinlock_t lock; /* Serialise access to device & its vortex_private */
  697. struct mii_if_info mii; /* MII lib hooks/info */
  698. };
  699. #ifdef CONFIG_PCI
  700. #define DEVICE_PCI(dev) (((dev)->bus == &pci_bus_type) ? to_pci_dev((dev)) : NULL)
  701. #else
  702. #define DEVICE_PCI(dev) NULL
  703. #endif
  704. #define VORTEX_PCI(vp) (((vp)->gendev) ? DEVICE_PCI((vp)->gendev) : NULL)
  705. #ifdef CONFIG_EISA
  706. #define DEVICE_EISA(dev) (((dev)->bus == &eisa_bus_type) ? to_eisa_device((dev)) : NULL)
  707. #else
  708. #define DEVICE_EISA(dev) NULL
  709. #endif
  710. #define VORTEX_EISA(vp) (((vp)->gendev) ? DEVICE_EISA((vp)->gendev) : NULL)
  711. /* The action to take with a media selection timer tick.
  712. Note that we deviate from the 3Com order by checking 10base2 before AUI.
  713. */
  714. enum xcvr_types {
  715. XCVR_10baseT=0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
  716. XCVR_100baseFx, XCVR_MII=6, XCVR_NWAY=8, XCVR_ExtMII=9, XCVR_Default=10,
  717. };
  718. static const struct media_table {
  719. char *name;
  720. unsigned int media_bits:16, /* Bits to set in Wn4_Media register. */
  721. mask:8, /* The transceiver-present bit in Wn3_Config.*/
  722. next:8; /* The media type to try next. */
  723. int wait; /* Time before we check media status. */
  724. } media_tbl[] = {
  725. { "10baseT", Media_10TP,0x08, XCVR_10base2, (14*HZ)/10},
  726. { "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1*HZ)/10},
  727. { "undefined", 0, 0x80, XCVR_10baseT, 10000},
  728. { "10base2", 0, 0x10, XCVR_AUI, (1*HZ)/10},
  729. { "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14*HZ)/10},
  730. { "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14*HZ)/10},
  731. { "MII", 0, 0x41, XCVR_10baseT, 3*HZ },
  732. { "undefined", 0, 0x01, XCVR_10baseT, 10000},
  733. { "Autonegotiate", 0, 0x41, XCVR_10baseT, 3*HZ},
  734. { "MII-External", 0, 0x41, XCVR_10baseT, 3*HZ },
  735. { "Default", 0, 0xFF, XCVR_10baseT, 10000},
  736. };
  737. static struct {
  738. const char str[ETH_GSTRING_LEN];
  739. } ethtool_stats_keys[] = {
  740. { "tx_deferred" },
  741. { "tx_max_collisions" },
  742. { "tx_multiple_collisions" },
  743. { "tx_single_collisions" },
  744. { "rx_bad_ssd" },
  745. };
  746. /* number of ETHTOOL_GSTATS u64's */
  747. #define VORTEX_NUM_STATS 5
  748. static int vortex_probe1(struct device *gendev, void __iomem *ioaddr, int irq,
  749. int chip_idx, int card_idx);
  750. static void vortex_up(struct net_device *dev);
  751. static void vortex_down(struct net_device *dev, int final);
  752. static int vortex_open(struct net_device *dev);
  753. static void mdio_sync(void __iomem *ioaddr, int bits);
  754. static int mdio_read(struct net_device *dev, int phy_id, int location);
  755. static void mdio_write(struct net_device *vp, int phy_id, int location, int value);
  756. static void vortex_timer(unsigned long arg);
  757. static void rx_oom_timer(unsigned long arg);
  758. static int vortex_start_xmit(struct sk_buff *skb, struct net_device *dev);
  759. static int boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev);
  760. static int vortex_rx(struct net_device *dev);
  761. static int boomerang_rx(struct net_device *dev);
  762. static irqreturn_t vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  763. static irqreturn_t boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  764. static int vortex_close(struct net_device *dev);
  765. static void dump_tx_ring(struct net_device *dev);
  766. static void update_stats(void __iomem *ioaddr, struct net_device *dev);
  767. static struct net_device_stats *vortex_get_stats(struct net_device *dev);
  768. static void set_rx_mode(struct net_device *dev);
  769. #ifdef CONFIG_PCI
  770. static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  771. #endif
  772. static void vortex_tx_timeout(struct net_device *dev);
  773. static void acpi_set_WOL(struct net_device *dev);
  774. static struct ethtool_ops vortex_ethtool_ops;
  775. static void set_8021q_mode(struct net_device *dev, int enable);
  776. /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
  777. /* Option count limit only -- unlimited interfaces are supported. */
  778. #define MAX_UNITS 8
  779. static int options[MAX_UNITS] = { [0 ... MAX_UNITS-1] = -1 };
  780. static int full_duplex[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  781. static int hw_checksums[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  782. static int flow_ctrl[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  783. static int enable_wol[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  784. static int use_mmio[MAX_UNITS] = {[0 ... MAX_UNITS-1] = -1 };
  785. static int global_options = -1;
  786. static int global_full_duplex = -1;
  787. static int global_enable_wol = -1;
  788. static int global_use_mmio = -1;
  789. /* Variables to work-around the Compaq PCI BIOS32 problem. */
  790. static int compaq_ioaddr, compaq_irq, compaq_device_id = 0x5900;
  791. static struct net_device *compaq_net_device;
  792. static int vortex_cards_found;
  793. module_param(debug, int, 0);
  794. module_param(global_options, int, 0);
  795. module_param_array(options, int, NULL, 0);
  796. module_param(global_full_duplex, int, 0);
  797. module_param_array(full_duplex, int, NULL, 0);
  798. module_param_array(hw_checksums, int, NULL, 0);
  799. module_param_array(flow_ctrl, int, NULL, 0);
  800. module_param(global_enable_wol, int, 0);
  801. module_param_array(enable_wol, int, NULL, 0);
  802. module_param(rx_copybreak, int, 0);
  803. module_param(max_interrupt_work, int, 0);
  804. module_param(compaq_ioaddr, int, 0);
  805. module_param(compaq_irq, int, 0);
  806. module_param(compaq_device_id, int, 0);
  807. module_param(watchdog, int, 0);
  808. module_param(global_use_mmio, int, 0);
  809. module_param_array(use_mmio, int, NULL, 0);
  810. MODULE_PARM_DESC(debug, "3c59x debug level (0-6)");
  811. MODULE_PARM_DESC(options, "3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex");
  812. MODULE_PARM_DESC(global_options, "3c59x: same as options, but applies to all NICs if options is unset");
  813. MODULE_PARM_DESC(full_duplex, "3c59x full duplex setting(s) (1)");
  814. MODULE_PARM_DESC(global_full_duplex, "3c59x: same as full_duplex, but applies to all NICs if full_duplex is unset");
  815. MODULE_PARM_DESC(hw_checksums, "3c59x Hardware checksum checking by adapter(s) (0-1)");
  816. MODULE_PARM_DESC(flow_ctrl, "3c59x 802.3x flow control usage (PAUSE only) (0-1)");
  817. MODULE_PARM_DESC(enable_wol, "3c59x: Turn on Wake-on-LAN for adapter(s) (0-1)");
  818. MODULE_PARM_DESC(global_enable_wol, "3c59x: same as enable_wol, but applies to all NICs if enable_wol is unset");
  819. MODULE_PARM_DESC(rx_copybreak, "3c59x copy breakpoint for copy-only-tiny-frames");
  820. MODULE_PARM_DESC(max_interrupt_work, "3c59x maximum events handled per interrupt");
  821. MODULE_PARM_DESC(compaq_ioaddr, "3c59x PCI I/O base address (Compaq BIOS problem workaround)");
  822. MODULE_PARM_DESC(compaq_irq, "3c59x PCI IRQ number (Compaq BIOS problem workaround)");
  823. MODULE_PARM_DESC(compaq_device_id, "3c59x PCI device ID (Compaq BIOS problem workaround)");
  824. MODULE_PARM_DESC(watchdog, "3c59x transmit timeout in milliseconds");
  825. MODULE_PARM_DESC(global_use_mmio, "3c59x: same as use_mmio, but applies to all NICs if options is unset");
  826. MODULE_PARM_DESC(use_mmio, "3c59x: use memory-mapped PCI I/O resource (0-1)");
  827. #ifdef CONFIG_NET_POLL_CONTROLLER
  828. static void poll_vortex(struct net_device *dev)
  829. {
  830. struct vortex_private *vp = netdev_priv(dev);
  831. unsigned long flags;
  832. local_save_flags(flags);
  833. local_irq_disable();
  834. (vp->full_bus_master_rx ? boomerang_interrupt:vortex_interrupt)(dev->irq,dev,NULL);
  835. local_irq_restore(flags);
  836. }
  837. #endif
  838. #ifdef CONFIG_PM
  839. static int vortex_suspend(struct pci_dev *pdev, pm_message_t state)
  840. {
  841. struct net_device *dev = pci_get_drvdata(pdev);
  842. if (dev && dev->priv) {
  843. if (netif_running(dev)) {
  844. netif_device_detach(dev);
  845. vortex_down(dev, 1);
  846. }
  847. pci_save_state(pdev);
  848. pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
  849. free_irq(dev->irq, dev);
  850. pci_disable_device(pdev);
  851. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  852. }
  853. return 0;
  854. }
  855. static int vortex_resume(struct pci_dev *pdev)
  856. {
  857. struct net_device *dev = pci_get_drvdata(pdev);
  858. struct vortex_private *vp = netdev_priv(dev);
  859. if (dev && vp) {
  860. pci_set_power_state(pdev, PCI_D0);
  861. pci_restore_state(pdev);
  862. pci_enable_device(pdev);
  863. pci_set_master(pdev);
  864. if (request_irq(dev->irq, vp->full_bus_master_rx ?
  865. &boomerang_interrupt : &vortex_interrupt, SA_SHIRQ, dev->name, dev)) {
  866. printk(KERN_WARNING "%s: Could not reserve IRQ %d\n", dev->name, dev->irq);
  867. pci_disable_device(pdev);
  868. return -EBUSY;
  869. }
  870. if (netif_running(dev)) {
  871. vortex_up(dev);
  872. netif_device_attach(dev);
  873. }
  874. }
  875. return 0;
  876. }
  877. #endif /* CONFIG_PM */
  878. #ifdef CONFIG_EISA
  879. static struct eisa_device_id vortex_eisa_ids[] = {
  880. { "TCM5920", CH_3C592 },
  881. { "TCM5970", CH_3C597 },
  882. { "" }
  883. };
  884. static int vortex_eisa_probe(struct device *device);
  885. static int vortex_eisa_remove(struct device *device);
  886. static struct eisa_driver vortex_eisa_driver = {
  887. .id_table = vortex_eisa_ids,
  888. .driver = {
  889. .name = "3c59x",
  890. .probe = vortex_eisa_probe,
  891. .remove = vortex_eisa_remove
  892. }
  893. };
  894. static int vortex_eisa_probe(struct device *device)
  895. {
  896. void __iomem *ioaddr;
  897. struct eisa_device *edev;
  898. edev = to_eisa_device(device);
  899. if (!request_region(edev->base_addr, VORTEX_TOTAL_SIZE, DRV_NAME))
  900. return -EBUSY;
  901. ioaddr = ioport_map(edev->base_addr, VORTEX_TOTAL_SIZE);
  902. if (vortex_probe1(device, ioaddr, ioread16(ioaddr + 0xC88) >> 12,
  903. edev->id.driver_data, vortex_cards_found)) {
  904. release_region(edev->base_addr, VORTEX_TOTAL_SIZE);
  905. return -ENODEV;
  906. }
  907. vortex_cards_found++;
  908. return 0;
  909. }
  910. static int vortex_eisa_remove(struct device *device)
  911. {
  912. struct eisa_device *edev;
  913. struct net_device *dev;
  914. struct vortex_private *vp;
  915. void __iomem *ioaddr;
  916. edev = to_eisa_device(device);
  917. dev = eisa_get_drvdata(edev);
  918. if (!dev) {
  919. printk("vortex_eisa_remove called for Compaq device!\n");
  920. BUG();
  921. }
  922. vp = netdev_priv(dev);
  923. ioaddr = vp->ioaddr;
  924. unregister_netdev(dev);
  925. iowrite16(TotalReset|0x14, ioaddr + EL3_CMD);
  926. release_region(dev->base_addr, VORTEX_TOTAL_SIZE);
  927. free_netdev(dev);
  928. return 0;
  929. }
  930. #endif
  931. /* returns count found (>= 0), or negative on error */
  932. static int __init vortex_eisa_init(void)
  933. {
  934. int eisa_found = 0;
  935. int orig_cards_found = vortex_cards_found;
  936. #ifdef CONFIG_EISA
  937. int err;
  938. err = eisa_driver_register (&vortex_eisa_driver);
  939. if (!err) {
  940. /*
  941. * Because of the way EISA bus is probed, we cannot assume
  942. * any device have been found when we exit from
  943. * eisa_driver_register (the bus root driver may not be
  944. * initialized yet). So we blindly assume something was
  945. * found, and let the sysfs magic happend...
  946. */
  947. eisa_found = 1;
  948. }
  949. #endif
  950. /* Special code to work-around the Compaq PCI BIOS32 problem. */
  951. if (compaq_ioaddr) {
  952. vortex_probe1(NULL, ioport_map(compaq_ioaddr, VORTEX_TOTAL_SIZE),
  953. compaq_irq, compaq_device_id, vortex_cards_found++);
  954. }
  955. return vortex_cards_found - orig_cards_found + eisa_found;
  956. }
  957. /* returns count (>= 0), or negative on error */
  958. static int __devinit vortex_init_one(struct pci_dev *pdev,
  959. const struct pci_device_id *ent)
  960. {
  961. int rc, unit, pci_bar;
  962. struct vortex_chip_info *vci;
  963. void __iomem *ioaddr;
  964. /* wake up and enable device */
  965. rc = pci_enable_device(pdev);
  966. if (rc < 0)
  967. goto out;
  968. unit = vortex_cards_found;
  969. if (global_use_mmio < 0 && (unit >= MAX_UNITS || use_mmio[unit] < 0)) {
  970. /* Determine the default if the user didn't override us */
  971. vci = &vortex_info_tbl[ent->driver_data];
  972. pci_bar = vci->drv_flags & (IS_CYCLONE | IS_TORNADO) ? 1 : 0;
  973. } else if (unit < MAX_UNITS && use_mmio[unit] >= 0)
  974. pci_bar = use_mmio[unit] ? 1 : 0;
  975. else
  976. pci_bar = global_use_mmio ? 1 : 0;
  977. ioaddr = pci_iomap(pdev, pci_bar, 0);
  978. if (!ioaddr) /* If mapping fails, fall-back to BAR 0... */
  979. ioaddr = pci_iomap(pdev, 0, 0);
  980. rc = vortex_probe1(&pdev->dev, ioaddr, pdev->irq,
  981. ent->driver_data, unit);
  982. if (rc < 0) {
  983. pci_disable_device(pdev);
  984. goto out;
  985. }
  986. vortex_cards_found++;
  987. out:
  988. return rc;
  989. }
  990. /*
  991. * Start up the PCI/EISA device which is described by *gendev.
  992. * Return 0 on success.
  993. *
  994. * NOTE: pdev can be NULL, for the case of a Compaq device
  995. */
  996. static int __devinit vortex_probe1(struct device *gendev,
  997. void __iomem *ioaddr, int irq,
  998. int chip_idx, int card_idx)
  999. {
  1000. struct vortex_private *vp;
  1001. int option;
  1002. unsigned int eeprom[0x40], checksum = 0; /* EEPROM contents */
  1003. int i, step;
  1004. struct net_device *dev;
  1005. static int printed_version;
  1006. int retval, print_info;
  1007. struct vortex_chip_info * const vci = &vortex_info_tbl[chip_idx];
  1008. char *print_name = "3c59x";
  1009. struct pci_dev *pdev = NULL;
  1010. struct eisa_device *edev = NULL;
  1011. if (!printed_version) {
  1012. printk (version);
  1013. printed_version = 1;
  1014. }
  1015. if (gendev) {
  1016. if ((pdev = DEVICE_PCI(gendev))) {
  1017. print_name = pci_name(pdev);
  1018. }
  1019. if ((edev = DEVICE_EISA(gendev))) {
  1020. print_name = edev->dev.bus_id;
  1021. }
  1022. }
  1023. dev = alloc_etherdev(sizeof(*vp));
  1024. retval = -ENOMEM;
  1025. if (!dev) {
  1026. printk (KERN_ERR PFX "unable to allocate etherdev, aborting\n");
  1027. goto out;
  1028. }
  1029. SET_MODULE_OWNER(dev);
  1030. SET_NETDEV_DEV(dev, gendev);
  1031. vp = netdev_priv(dev);
  1032. option = global_options;
  1033. /* The lower four bits are the media type. */
  1034. if (dev->mem_start) {
  1035. /*
  1036. * The 'options' param is passed in as the third arg to the
  1037. * LILO 'ether=' argument for non-modular use
  1038. */
  1039. option = dev->mem_start;
  1040. }
  1041. else if (card_idx < MAX_UNITS) {
  1042. if (options[card_idx] >= 0)
  1043. option = options[card_idx];
  1044. }
  1045. if (option > 0) {
  1046. if (option & 0x8000)
  1047. vortex_debug = 7;
  1048. if (option & 0x4000)
  1049. vortex_debug = 2;
  1050. if (option & 0x0400)
  1051. vp->enable_wol = 1;
  1052. }
  1053. print_info = (vortex_debug > 1);
  1054. if (print_info)
  1055. printk (KERN_INFO "See Documentation/networking/vortex.txt\n");
  1056. printk(KERN_INFO "%s: 3Com %s %s at %p.\n",
  1057. print_name,
  1058. pdev ? "PCI" : "EISA",
  1059. vci->name,
  1060. ioaddr);
  1061. dev->base_addr = (unsigned long)ioaddr;
  1062. dev->irq = irq;
  1063. dev->mtu = mtu;
  1064. vp->ioaddr = ioaddr;
  1065. vp->large_frames = mtu > 1500;
  1066. vp->drv_flags = vci->drv_flags;
  1067. vp->has_nway = (vci->drv_flags & HAS_NWAY) ? 1 : 0;
  1068. vp->io_size = vci->io_size;
  1069. vp->card_idx = card_idx;
  1070. /* module list only for Compaq device */
  1071. if (gendev == NULL) {
  1072. compaq_net_device = dev;
  1073. }
  1074. /* PCI-only startup logic */
  1075. if (pdev) {
  1076. /* EISA resources already marked, so only PCI needs to do this here */
  1077. /* Ignore return value, because Cardbus drivers already allocate for us */
  1078. if (request_region(dev->base_addr, vci->io_size, print_name) != NULL)
  1079. vp->must_free_region = 1;
  1080. /* enable bus-mastering if necessary */
  1081. if (vci->flags & PCI_USES_MASTER)
  1082. pci_set_master(pdev);
  1083. if (vci->drv_flags & IS_VORTEX) {
  1084. u8 pci_latency;
  1085. u8 new_latency = 248;
  1086. /* Check the PCI latency value. On the 3c590 series the latency timer
  1087. must be set to the maximum value to avoid data corruption that occurs
  1088. when the timer expires during a transfer. This bug exists the Vortex
  1089. chip only. */
  1090. pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
  1091. if (pci_latency < new_latency) {
  1092. printk(KERN_INFO "%s: Overriding PCI latency"
  1093. " timer (CFLT) setting of %d, new value is %d.\n",
  1094. print_name, pci_latency, new_latency);
  1095. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, new_latency);
  1096. }
  1097. }
  1098. }
  1099. spin_lock_init(&vp->lock);
  1100. vp->gendev = gendev;
  1101. vp->mii.dev = dev;
  1102. vp->mii.mdio_read = mdio_read;
  1103. vp->mii.mdio_write = mdio_write;
  1104. vp->mii.phy_id_mask = 0x1f;
  1105. vp->mii.reg_num_mask = 0x1f;
  1106. /* Makes sure rings are at least 16 byte aligned. */
  1107. vp->rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
  1108. + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
  1109. &vp->rx_ring_dma);
  1110. retval = -ENOMEM;
  1111. if (vp->rx_ring == 0)
  1112. goto free_region;
  1113. vp->tx_ring = (struct boom_tx_desc *)(vp->rx_ring + RX_RING_SIZE);
  1114. vp->tx_ring_dma = vp->rx_ring_dma + sizeof(struct boom_rx_desc) * RX_RING_SIZE;
  1115. /* if we are a PCI driver, we store info in pdev->driver_data
  1116. * instead of a module list */
  1117. if (pdev)
  1118. pci_set_drvdata(pdev, dev);
  1119. if (edev)
  1120. eisa_set_drvdata(edev, dev);
  1121. vp->media_override = 7;
  1122. if (option >= 0) {
  1123. vp->media_override = ((option & 7) == 2) ? 0 : option & 15;
  1124. if (vp->media_override != 7)
  1125. vp->medialock = 1;
  1126. vp->full_duplex = (option & 0x200) ? 1 : 0;
  1127. vp->bus_master = (option & 16) ? 1 : 0;
  1128. }
  1129. if (global_full_duplex > 0)
  1130. vp->full_duplex = 1;
  1131. if (global_enable_wol > 0)
  1132. vp->enable_wol = 1;
  1133. if (card_idx < MAX_UNITS) {
  1134. if (full_duplex[card_idx] > 0)
  1135. vp->full_duplex = 1;
  1136. if (flow_ctrl[card_idx] > 0)
  1137. vp->flow_ctrl = 1;
  1138. if (enable_wol[card_idx] > 0)
  1139. vp->enable_wol = 1;
  1140. }
  1141. vp->mii.force_media = vp->full_duplex;
  1142. vp->options = option;
  1143. /* Read the station address from the EEPROM. */
  1144. EL3WINDOW(0);
  1145. {
  1146. int base;
  1147. if (vci->drv_flags & EEPROM_8BIT)
  1148. base = 0x230;
  1149. else if (vci->drv_flags & EEPROM_OFFSET)
  1150. base = EEPROM_Read + 0x30;
  1151. else
  1152. base = EEPROM_Read;
  1153. for (i = 0; i < 0x40; i++) {
  1154. int timer;
  1155. iowrite16(base + i, ioaddr + Wn0EepromCmd);
  1156. /* Pause for at least 162 us. for the read to take place. */
  1157. for (timer = 10; timer >= 0; timer--) {
  1158. udelay(162);
  1159. if ((ioread16(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
  1160. break;
  1161. }
  1162. eeprom[i] = ioread16(ioaddr + Wn0EepromData);
  1163. }
  1164. }
  1165. for (i = 0; i < 0x18; i++)
  1166. checksum ^= eeprom[i];
  1167. checksum = (checksum ^ (checksum >> 8)) & 0xff;
  1168. if (checksum != 0x00) { /* Grrr, needless incompatible change 3Com. */
  1169. while (i < 0x21)
  1170. checksum ^= eeprom[i++];
  1171. checksum = (checksum ^ (checksum >> 8)) & 0xff;
  1172. }
  1173. if ((checksum != 0x00) && !(vci->drv_flags & IS_TORNADO))
  1174. printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
  1175. for (i = 0; i < 3; i++)
  1176. ((u16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]);
  1177. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  1178. if (print_info) {
  1179. for (i = 0; i < 6; i++)
  1180. printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
  1181. }
  1182. /* Unfortunately an all zero eeprom passes the checksum and this
  1183. gets found in the wild in failure cases. Crypto is hard 8) */
  1184. if (!is_valid_ether_addr(dev->dev_addr)) {
  1185. retval = -EINVAL;
  1186. printk(KERN_ERR "*** EEPROM MAC address is invalid.\n");
  1187. goto free_ring; /* With every pack */
  1188. }
  1189. EL3WINDOW(2);
  1190. for (i = 0; i < 6; i++)
  1191. iowrite8(dev->dev_addr[i], ioaddr + i);
  1192. #ifdef __sparc__
  1193. if (print_info)
  1194. printk(", IRQ %s\n", __irq_itoa(dev->irq));
  1195. #else
  1196. if (print_info)
  1197. printk(", IRQ %d\n", dev->irq);
  1198. /* Tell them about an invalid IRQ. */
  1199. if (dev->irq <= 0 || dev->irq >= NR_IRQS)
  1200. printk(KERN_WARNING " *** Warning: IRQ %d is unlikely to work! ***\n",
  1201. dev->irq);
  1202. #endif
  1203. EL3WINDOW(4);
  1204. step = (ioread8(ioaddr + Wn4_NetDiag) & 0x1e) >> 1;
  1205. if (print_info) {
  1206. printk(KERN_INFO " product code %02x%02x rev %02x.%d date %02d-"
  1207. "%02d-%02d\n", eeprom[6]&0xff, eeprom[6]>>8, eeprom[0x14],
  1208. step, (eeprom[4]>>5) & 15, eeprom[4] & 31, eeprom[4]>>9);
  1209. }
  1210. if (pdev && vci->drv_flags & HAS_CB_FNS) {
  1211. unsigned short n;
  1212. vp->cb_fn_base = pci_iomap(pdev, 2, 0);
  1213. if (!vp->cb_fn_base) {
  1214. retval = -ENOMEM;
  1215. goto free_ring;
  1216. }
  1217. if (print_info) {
  1218. printk(KERN_INFO "%s: CardBus functions mapped %8.8lx->%p\n",
  1219. print_name, pci_resource_start(pdev, 2),
  1220. vp->cb_fn_base);
  1221. }
  1222. EL3WINDOW(2);
  1223. n = ioread16(ioaddr + Wn2_ResetOptions) & ~0x4010;
  1224. if (vp->drv_flags & INVERT_LED_PWR)
  1225. n |= 0x10;
  1226. if (vp->drv_flags & INVERT_MII_PWR)
  1227. n |= 0x4000;
  1228. iowrite16(n, ioaddr + Wn2_ResetOptions);
  1229. if (vp->drv_flags & WNO_XCVR_PWR) {
  1230. EL3WINDOW(0);
  1231. iowrite16(0x0800, ioaddr);
  1232. }
  1233. }
  1234. /* Extract our information from the EEPROM data. */
  1235. vp->info1 = eeprom[13];
  1236. vp->info2 = eeprom[15];
  1237. vp->capabilities = eeprom[16];
  1238. if (vp->info1 & 0x8000) {
  1239. vp->full_duplex = 1;
  1240. if (print_info)
  1241. printk(KERN_INFO "Full duplex capable\n");
  1242. }
  1243. {
  1244. static const char * const ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
  1245. unsigned int config;
  1246. EL3WINDOW(3);
  1247. vp->available_media = ioread16(ioaddr + Wn3_Options);
  1248. if ((vp->available_media & 0xff) == 0) /* Broken 3c916 */
  1249. vp->available_media = 0x40;
  1250. config = ioread32(ioaddr + Wn3_Config);
  1251. if (print_info) {
  1252. printk(KERN_DEBUG " Internal config register is %4.4x, "
  1253. "transceivers %#x.\n", config, ioread16(ioaddr + Wn3_Options));
  1254. printk(KERN_INFO " %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
  1255. 8 << RAM_SIZE(config),
  1256. RAM_WIDTH(config) ? "word" : "byte",
  1257. ram_split[RAM_SPLIT(config)],
  1258. AUTOSELECT(config) ? "autoselect/" : "",
  1259. XCVR(config) > XCVR_ExtMII ? "<invalid transceiver>" :
  1260. media_tbl[XCVR(config)].name);
  1261. }
  1262. vp->default_media = XCVR(config);
  1263. if (vp->default_media == XCVR_NWAY)
  1264. vp->has_nway = 1;
  1265. vp->autoselect = AUTOSELECT(config);
  1266. }
  1267. if (vp->media_override != 7) {
  1268. printk(KERN_INFO "%s: Media override to transceiver type %d (%s).\n",
  1269. print_name, vp->media_override,
  1270. media_tbl[vp->media_override].name);
  1271. dev->if_port = vp->media_override;
  1272. } else
  1273. dev->if_port = vp->default_media;
  1274. if ((vp->available_media & 0x40) || (vci->drv_flags & HAS_NWAY) ||
  1275. dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
  1276. int phy, phy_idx = 0;
  1277. EL3WINDOW(4);
  1278. mii_preamble_required++;
  1279. if (vp->drv_flags & EXTRA_PREAMBLE)
  1280. mii_preamble_required++;
  1281. mdio_sync(ioaddr, 32);
  1282. mdio_read(dev, 24, MII_BMSR);
  1283. for (phy = 0; phy < 32 && phy_idx < 1; phy++) {
  1284. int mii_status, phyx;
  1285. /*
  1286. * For the 3c905CX we look at index 24 first, because it bogusly
  1287. * reports an external PHY at all indices
  1288. */
  1289. if (phy == 0)
  1290. phyx = 24;
  1291. else if (phy <= 24)
  1292. phyx = phy - 1;
  1293. else
  1294. phyx = phy;
  1295. mii_status = mdio_read(dev, phyx, MII_BMSR);
  1296. if (mii_status && mii_status != 0xffff) {
  1297. vp->phys[phy_idx++] = phyx;
  1298. if (print_info) {
  1299. printk(KERN_INFO " MII transceiver found at address %d,"
  1300. " status %4x.\n", phyx, mii_status);
  1301. }
  1302. if ((mii_status & 0x0040) == 0)
  1303. mii_preamble_required++;
  1304. }
  1305. }
  1306. mii_preamble_required--;
  1307. if (phy_idx == 0) {
  1308. printk(KERN_WARNING" ***WARNING*** No MII transceivers found!\n");
  1309. vp->phys[0] = 24;
  1310. } else {
  1311. vp->advertising = mdio_read(dev, vp->phys[0], MII_ADVERTISE);
  1312. if (vp->full_duplex) {
  1313. /* Only advertise the FD media types. */
  1314. vp->advertising &= ~0x02A0;
  1315. mdio_write(dev, vp->phys[0], 4, vp->advertising);
  1316. }
  1317. }
  1318. vp->mii.phy_id = vp->phys[0];
  1319. }
  1320. if (vp->capabilities & CapBusMaster) {
  1321. vp->full_bus_master_tx = 1;
  1322. if (print_info) {
  1323. printk(KERN_INFO " Enabling bus-master transmits and %s receives.\n",
  1324. (vp->info2 & 1) ? "early" : "whole-frame" );
  1325. }
  1326. vp->full_bus_master_rx = (vp->info2 & 1) ? 1 : 2;
  1327. vp->bus_master = 0; /* AKPM: vortex only */
  1328. }
  1329. /* The 3c59x-specific entries in the device structure. */
  1330. dev->open = vortex_open;
  1331. if (vp->full_bus_master_tx) {
  1332. dev->hard_start_xmit = boomerang_start_xmit;
  1333. /* Actually, it still should work with iommu. */
  1334. if (card_idx < MAX_UNITS &&
  1335. ((hw_checksums[card_idx] == -1 && (vp->drv_flags & HAS_HWCKSM)) ||
  1336. hw_checksums[card_idx] == 1)) {
  1337. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  1338. }
  1339. } else {
  1340. dev->hard_start_xmit = vortex_start_xmit;
  1341. }
  1342. if (print_info) {
  1343. printk(KERN_INFO "%s: scatter/gather %sabled. h/w checksums %sabled\n",
  1344. print_name,
  1345. (dev->features & NETIF_F_SG) ? "en":"dis",
  1346. (dev->features & NETIF_F_IP_CSUM) ? "en":"dis");
  1347. }
  1348. dev->stop = vortex_close;
  1349. dev->get_stats = vortex_get_stats;
  1350. #ifdef CONFIG_PCI
  1351. dev->do_ioctl = vortex_ioctl;
  1352. #endif
  1353. dev->ethtool_ops = &vortex_ethtool_ops;
  1354. dev->set_multicast_list = set_rx_mode;
  1355. dev->tx_timeout = vortex_tx_timeout;
  1356. dev->watchdog_timeo = (watchdog * HZ) / 1000;
  1357. #ifdef CONFIG_NET_POLL_CONTROLLER
  1358. dev->poll_controller = poll_vortex;
  1359. #endif
  1360. if (pdev) {
  1361. vp->pm_state_valid = 1;
  1362. pci_save_state(VORTEX_PCI(vp));
  1363. acpi_set_WOL(dev);
  1364. }
  1365. retval = register_netdev(dev);
  1366. if (retval == 0)
  1367. return 0;
  1368. free_ring:
  1369. pci_free_consistent(pdev,
  1370. sizeof(struct boom_rx_desc) * RX_RING_SIZE
  1371. + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
  1372. vp->rx_ring,
  1373. vp->rx_ring_dma);
  1374. free_region:
  1375. if (vp->must_free_region)
  1376. release_region(dev->base_addr, vci->io_size);
  1377. free_netdev(dev);
  1378. printk(KERN_ERR PFX "vortex_probe1 fails. Returns %d\n", retval);
  1379. out:
  1380. return retval;
  1381. }
  1382. static void
  1383. issue_and_wait(struct net_device *dev, int cmd)
  1384. {
  1385. struct vortex_private *vp = netdev_priv(dev);
  1386. void __iomem *ioaddr = vp->ioaddr;
  1387. int i;
  1388. iowrite16(cmd, ioaddr + EL3_CMD);
  1389. for (i = 0; i < 2000; i++) {
  1390. if (!(ioread16(ioaddr + EL3_STATUS) & CmdInProgress))
  1391. return;
  1392. }
  1393. /* OK, that didn't work. Do it the slow way. One second */
  1394. for (i = 0; i < 100000; i++) {
  1395. if (!(ioread16(ioaddr + EL3_STATUS) & CmdInProgress)) {
  1396. if (vortex_debug > 1)
  1397. printk(KERN_INFO "%s: command 0x%04x took %d usecs\n",
  1398. dev->name, cmd, i * 10);
  1399. return;
  1400. }
  1401. udelay(10);
  1402. }
  1403. printk(KERN_ERR "%s: command 0x%04x did not complete! Status=0x%x\n",
  1404. dev->name, cmd, ioread16(ioaddr + EL3_STATUS));
  1405. }
  1406. static void
  1407. vortex_set_duplex(struct net_device *dev)
  1408. {
  1409. struct vortex_private *vp = netdev_priv(dev);
  1410. void __iomem *ioaddr = vp->ioaddr;
  1411. printk(KERN_INFO "%s: setting %s-duplex.\n",
  1412. dev->name, (vp->full_duplex) ? "full" : "half");
  1413. EL3WINDOW(3);
  1414. /* Set the full-duplex bit. */
  1415. iowrite16(((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
  1416. (vp->large_frames ? 0x40 : 0) |
  1417. ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ?
  1418. 0x100 : 0),
  1419. ioaddr + Wn3_MAC_Ctrl);
  1420. }
  1421. static void vortex_check_media(struct net_device *dev, unsigned int init)
  1422. {
  1423. struct vortex_private *vp = netdev_priv(dev);
  1424. unsigned int ok_to_print = 0;
  1425. if (vortex_debug > 3)
  1426. ok_to_print = 1;
  1427. if (mii_check_media(&vp->mii, ok_to_print, init)) {
  1428. vp->full_duplex = vp->mii.full_duplex;
  1429. vortex_set_duplex(dev);
  1430. } else if (init) {
  1431. vortex_set_duplex(dev);
  1432. }
  1433. }
  1434. static void
  1435. vortex_up(struct net_device *dev)
  1436. {
  1437. struct vortex_private *vp = netdev_priv(dev);
  1438. void __iomem *ioaddr = vp->ioaddr;
  1439. unsigned int config;
  1440. int i, mii_reg1, mii_reg5;
  1441. if (VORTEX_PCI(vp)) {
  1442. pci_set_power_state(VORTEX_PCI(vp), PCI_D0); /* Go active */
  1443. if (vp->pm_state_valid)
  1444. pci_restore_state(VORTEX_PCI(vp));
  1445. pci_enable_device(VORTEX_PCI(vp));
  1446. }
  1447. /* Before initializing select the active media port. */
  1448. EL3WINDOW(3);
  1449. config = ioread32(ioaddr + Wn3_Config);
  1450. if (vp->media_override != 7) {
  1451. printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
  1452. dev->name, vp->media_override,
  1453. media_tbl[vp->media_override].name);
  1454. dev->if_port = vp->media_override;
  1455. } else if (vp->autoselect) {
  1456. if (vp->has_nway) {
  1457. if (vortex_debug > 1)
  1458. printk(KERN_INFO "%s: using NWAY device table, not %d\n",
  1459. dev->name, dev->if_port);
  1460. dev->if_port = XCVR_NWAY;
  1461. } else {
  1462. /* Find first available media type, starting with 100baseTx. */
  1463. dev->if_port = XCVR_100baseTx;
  1464. while (! (vp->available_media & media_tbl[dev->if_port].mask))
  1465. dev->if_port = media_tbl[dev->if_port].next;
  1466. if (vortex_debug > 1)
  1467. printk(KERN_INFO "%s: first available media type: %s\n",
  1468. dev->name, media_tbl[dev->if_port].name);
  1469. }
  1470. } else {
  1471. dev->if_port = vp->default_media;
  1472. if (vortex_debug > 1)
  1473. printk(KERN_INFO "%s: using default media %s\n",
  1474. dev->name, media_tbl[dev->if_port].name);
  1475. }
  1476. init_timer(&vp->timer);
  1477. vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
  1478. vp->timer.data = (unsigned long)dev;
  1479. vp->timer.function = vortex_timer; /* timer handler */
  1480. add_timer(&vp->timer);
  1481. init_timer(&vp->rx_oom_timer);
  1482. vp->rx_oom_timer.data = (unsigned long)dev;
  1483. vp->rx_oom_timer.function = rx_oom_timer;
  1484. if (vortex_debug > 1)
  1485. printk(KERN_DEBUG "%s: Initial media type %s.\n",
  1486. dev->name, media_tbl[dev->if_port].name);
  1487. vp->full_duplex = vp->mii.force_media;
  1488. config = BFINS(config, dev->if_port, 20, 4);
  1489. if (vortex_debug > 6)
  1490. printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config);
  1491. iowrite32(config, ioaddr + Wn3_Config);
  1492. if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
  1493. EL3WINDOW(4);
  1494. mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
  1495. mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
  1496. vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);
  1497. vortex_check_media(dev, 1);
  1498. }
  1499. else
  1500. vortex_set_duplex(dev);
  1501. issue_and_wait(dev, TxReset);
  1502. /*
  1503. * Don't reset the PHY - that upsets autonegotiation during DHCP operations.
  1504. */
  1505. issue_and_wait(dev, RxReset|0x04);
  1506. iowrite16(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
  1507. if (vortex_debug > 1) {
  1508. EL3WINDOW(4);
  1509. printk(KERN_DEBUG "%s: vortex_up() irq %d media status %4.4x.\n",
  1510. dev->name, dev->irq, ioread16(ioaddr + Wn4_Media));
  1511. }
  1512. /* Set the station address and mask in window 2 each time opened. */
  1513. EL3WINDOW(2);
  1514. for (i = 0; i < 6; i++)
  1515. iowrite8(dev->dev_addr[i], ioaddr + i);
  1516. for (; i < 12; i+=2)
  1517. iowrite16(0, ioaddr + i);
  1518. if (vp->cb_fn_base) {
  1519. unsigned short n = ioread16(ioaddr + Wn2_ResetOptions) & ~0x4010;
  1520. if (vp->drv_flags & INVERT_LED_PWR)
  1521. n |= 0x10;
  1522. if (vp->drv_flags & INVERT_MII_PWR)
  1523. n |= 0x4000;
  1524. iowrite16(n, ioaddr + Wn2_ResetOptions);
  1525. }
  1526. if (dev->if_port == XCVR_10base2)
  1527. /* Start the thinnet transceiver. We should really wait 50ms...*/
  1528. iowrite16(StartCoax, ioaddr + EL3_CMD);
  1529. if (dev->if_port != XCVR_NWAY) {
  1530. EL3WINDOW(4);
  1531. iowrite16((ioread16(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |
  1532. media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
  1533. }
  1534. /* Switch to the stats window, and clear all stats by reading. */
  1535. iowrite16(StatsDisable, ioaddr + EL3_CMD);
  1536. EL3WINDOW(6);
  1537. for (i = 0; i < 10; i++)
  1538. ioread8(ioaddr + i);
  1539. ioread16(ioaddr + 10);
  1540. ioread16(ioaddr + 12);
  1541. /* New: On the Vortex we must also clear the BadSSD counter. */
  1542. EL3WINDOW(4);
  1543. ioread8(ioaddr + 12);
  1544. /* ..and on the Boomerang we enable the extra statistics bits. */
  1545. iowrite16(0x0040, ioaddr + Wn4_NetDiag);
  1546. /* Switch to register set 7 for normal use. */
  1547. EL3WINDOW(7);
  1548. if (vp->full_bus_master_rx) { /* Boomerang bus master. */
  1549. vp->cur_rx = vp->dirty_rx = 0;
  1550. /* Initialize the RxEarly register as recommended. */
  1551. iowrite16(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);
  1552. iowrite32(0x0020, ioaddr + PktStatus);
  1553. iowrite32(vp->rx_ring_dma, ioaddr + UpListPtr);
  1554. }
  1555. if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */
  1556. vp->cur_tx = vp->dirty_tx = 0;
  1557. if (vp->drv_flags & IS_BOOMERANG)
  1558. iowrite8(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */
  1559. /* Clear the Rx, Tx rings. */
  1560. for (i = 0; i < RX_RING_SIZE; i++) /* AKPM: this is done in vortex_open, too */
  1561. vp->rx_ring[i].status = 0;
  1562. for (i = 0; i < TX_RING_SIZE; i++)
  1563. vp->tx_skbuff[i] = NULL;
  1564. iowrite32(0, ioaddr + DownListPtr);
  1565. }
  1566. /* Set receiver mode: presumably accept b-case and phys addr only. */
  1567. set_rx_mode(dev);
  1568. /* enable 802.1q tagged frames */
  1569. set_8021q_mode(dev, 1);
  1570. iowrite16(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
  1571. iowrite16(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
  1572. iowrite16(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
  1573. /* Allow status bits to be seen. */
  1574. vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|
  1575. (vp->full_bus_master_tx ? DownComplete : TxAvailable) |
  1576. (vp->full_bus_master_rx ? UpComplete : RxComplete) |
  1577. (vp->bus_master ? DMADone : 0);
  1578. vp->intr_enable = SetIntrEnb | IntLatch | TxAvailable |
  1579. (vp->full_bus_master_rx ? 0 : RxComplete) |
  1580. StatsFull | HostError | TxComplete | IntReq
  1581. | (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;
  1582. iowrite16(vp->status_enable, ioaddr + EL3_CMD);
  1583. /* Ack all pending events, and set active indicator mask. */
  1584. iowrite16(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
  1585. ioaddr + EL3_CMD);
  1586. iowrite16(vp->intr_enable, ioaddr + EL3_CMD);
  1587. if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
  1588. iowrite32(0x8000, vp->cb_fn_base + 4);
  1589. netif_start_queue (dev);
  1590. }
  1591. static int
  1592. vortex_open(struct net_device *dev)
  1593. {
  1594. struct vortex_private *vp = netdev_priv(dev);
  1595. int i;
  1596. int retval;
  1597. /* Use the now-standard shared IRQ implementation. */
  1598. if ((retval = request_irq(dev->irq, vp->full_bus_master_rx ?
  1599. &boomerang_interrupt : &vortex_interrupt, SA_SHIRQ, dev->name, dev))) {
  1600. printk(KERN_ERR "%s: Could not reserve IRQ %d\n", dev->name, dev->irq);
  1601. goto out;
  1602. }
  1603. if (vp->full_bus_master_rx) { /* Boomerang bus master. */
  1604. if (vortex_debug > 2)
  1605. printk(KERN_DEBUG "%s: Filling in the Rx ring.\n", dev->name);
  1606. for (i = 0; i < RX_RING_SIZE; i++) {
  1607. struct sk_buff *skb;
  1608. vp->rx_ring[i].next = cpu_to_le32(vp->rx_ring_dma + sizeof(struct boom_rx_desc) * (i+1));
  1609. vp->rx_ring[i].status = 0; /* Clear complete bit. */
  1610. vp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LAST_FRAG);
  1611. skb = dev_alloc_skb(PKT_BUF_SZ);
  1612. vp->rx_skbuff[i] = skb;
  1613. if (skb == NULL)
  1614. break; /* Bad news! */
  1615. skb->dev = dev; /* Mark as being used by this device. */
  1616. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  1617. vp->rx_ring[i].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
  1618. }
  1619. if (i != RX_RING_SIZE) {
  1620. int j;
  1621. printk(KERN_EMERG "%s: no memory for rx ring\n", dev->name);
  1622. for (j = 0; j < i; j++) {
  1623. if (vp->rx_skbuff[j]) {
  1624. dev_kfree_skb(vp->rx_skbuff[j]);
  1625. vp->rx_skbuff[j] = NULL;
  1626. }
  1627. }
  1628. retval = -ENOMEM;
  1629. goto out_free_irq;
  1630. }
  1631. /* Wrap the ring. */
  1632. vp->rx_ring[i-1].next = cpu_to_le32(vp->rx_ring_dma);
  1633. }
  1634. vortex_up(dev);
  1635. return 0;
  1636. out_free_irq:
  1637. free_irq(dev->irq, dev);
  1638. out:
  1639. if (vortex_debug > 1)
  1640. printk(KERN_ERR "%s: vortex_open() fails: returning %d\n", dev->name, retval);
  1641. return retval;
  1642. }
  1643. static void
  1644. vortex_timer(unsigned long data)
  1645. {
  1646. struct net_device *dev = (struct net_device *)data;
  1647. struct vortex_private *vp = netdev_priv(dev);
  1648. void __iomem *ioaddr = vp->ioaddr;
  1649. int next_tick = 60*HZ;
  1650. int ok = 0;
  1651. int media_status, old_window;
  1652. if (vortex_debug > 2) {
  1653. printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n",
  1654. dev->name, media_tbl[dev->if_port].name);
  1655. printk(KERN_DEBUG "dev->watchdog_timeo=%d\n", dev->watchdog_timeo);
  1656. }
  1657. disable_irq(dev->irq);
  1658. old_window = ioread16(ioaddr + EL3_CMD) >> 13;
  1659. EL3WINDOW(4);
  1660. media_status = ioread16(ioaddr + Wn4_Media);
  1661. switch (dev->if_port) {
  1662. case XCVR_10baseT: case XCVR_100baseTx: case XCVR_100baseFx:
  1663. if (media_status & Media_LnkBeat) {
  1664. netif_carrier_on(dev);
  1665. ok = 1;
  1666. if (vortex_debug > 1)
  1667. printk(KERN_DEBUG "%s: Media %s has link beat, %x.\n",
  1668. dev->name, media_tbl[dev->if_port].name, media_status);
  1669. } else {
  1670. netif_carrier_off(dev);
  1671. if (vortex_debug > 1) {
  1672. printk(KERN_DEBUG "%s: Media %s has no link beat, %x.\n",
  1673. dev->name, media_tbl[dev->if_port].name, media_status);
  1674. }
  1675. }
  1676. break;
  1677. case XCVR_MII: case XCVR_NWAY:
  1678. {
  1679. ok = 1;
  1680. spin_lock_bh(&vp->lock);
  1681. vortex_check_media(dev, 0);
  1682. spin_unlock_bh(&vp->lock);
  1683. }
  1684. break;
  1685. default: /* Other media types handled by Tx timeouts. */
  1686. if (vortex_debug > 1)
  1687. printk(KERN_DEBUG "%s: Media %s has no indication, %x.\n",
  1688. dev->name, media_tbl[dev->if_port].name, media_status);
  1689. ok = 1;
  1690. }
  1691. if (!netif_carrier_ok(dev))
  1692. next_tick = 5*HZ;
  1693. if (vp->medialock)
  1694. goto leave_media_alone;
  1695. if (!ok) {
  1696. unsigned int config;
  1697. do {
  1698. dev->if_port = media_tbl[dev->if_port].next;
  1699. } while ( ! (vp->available_media & media_tbl[dev->if_port].mask));
  1700. if (dev->if_port == XCVR_Default) { /* Go back to default. */
  1701. dev->if_port = vp->default_media;
  1702. if (vortex_debug > 1)
  1703. printk(KERN_DEBUG "%s: Media selection failing, using default "
  1704. "%s port.\n",
  1705. dev->name, media_tbl[dev->if_port].name);
  1706. } else {
  1707. if (vortex_debug > 1)
  1708. printk(KERN_DEBUG "%s: Media selection failed, now trying "
  1709. "%s port.\n",
  1710. dev->name, media_tbl[dev->if_port].name);
  1711. next_tick = media_tbl[dev->if_port].wait;
  1712. }
  1713. iowrite16((media_status & ~(Media_10TP|Media_SQE)) |
  1714. media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
  1715. EL3WINDOW(3);
  1716. config = ioread32(ioaddr + Wn3_Config);
  1717. config = BFINS(config, dev->if_port, 20, 4);
  1718. iowrite32(config, ioaddr + Wn3_Config);
  1719. iowrite16(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax,
  1720. ioaddr + EL3_CMD);
  1721. if (vortex_debug > 1)
  1722. printk(KERN_DEBUG "wrote 0x%08x to Wn3_Config\n", config);
  1723. /* AKPM: FIXME: Should reset Rx & Tx here. P60 of 3c90xc.pdf */
  1724. }
  1725. leave_media_alone:
  1726. if (vortex_debug > 2)
  1727. printk(KERN_DEBUG "%s: Media selection timer finished, %s.\n",
  1728. dev->name, media_tbl[dev->if_port].name);
  1729. EL3WINDOW(old_window);
  1730. enable_irq(dev->irq);
  1731. mod_timer(&vp->timer, RUN_AT(next_tick));
  1732. if (vp->deferred)
  1733. iowrite16(FakeIntr, ioaddr + EL3_CMD);
  1734. return;
  1735. }
  1736. static void vortex_tx_timeout(struct net_device *dev)
  1737. {
  1738. struct vortex_private *vp = netdev_priv(dev);
  1739. void __iomem *ioaddr = vp->ioaddr;
  1740. printk(KERN_ERR "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
  1741. dev->name, ioread8(ioaddr + TxStatus),
  1742. ioread16(ioaddr + EL3_STATUS));
  1743. EL3WINDOW(4);
  1744. printk(KERN_ERR " diagnostics: net %04x media %04x dma %08x fifo %04x\n",
  1745. ioread16(ioaddr + Wn4_NetDiag),
  1746. ioread16(ioaddr + Wn4_Media),
  1747. ioread32(ioaddr + PktStatus),
  1748. ioread16(ioaddr + Wn4_FIFODiag));
  1749. /* Slight code bloat to be user friendly. */
  1750. if ((ioread8(ioaddr + TxStatus) & 0x88) == 0x88)
  1751. printk(KERN_ERR "%s: Transmitter encountered 16 collisions --"
  1752. " network cable problem?\n", dev->name);
  1753. if (ioread16(ioaddr + EL3_STATUS) & IntLatch) {
  1754. printk(KERN_ERR "%s: Interrupt posted but not delivered --"
  1755. " IRQ blocked by another device?\n", dev->name);
  1756. /* Bad idea here.. but we might as well handle a few events. */
  1757. {
  1758. /*
  1759. * Block interrupts because vortex_interrupt does a bare spin_lock()
  1760. */
  1761. unsigned long flags;
  1762. local_irq_save(flags);
  1763. if (vp->full_bus_master_tx)
  1764. boomerang_interrupt(dev->irq, dev, NULL);
  1765. else
  1766. vortex_interrupt(dev->irq, dev, NULL);
  1767. local_irq_restore(flags);
  1768. }
  1769. }
  1770. if (vortex_debug > 0)
  1771. dump_tx_ring(dev);
  1772. issue_and_wait(dev, TxReset);
  1773. vp->stats.tx_errors++;
  1774. if (vp->full_bus_master_tx) {
  1775. printk(KERN_DEBUG "%s: Resetting the Tx ring pointer.\n", dev->name);
  1776. if (vp->cur_tx - vp->dirty_tx > 0 && ioread32(ioaddr + DownListPtr) == 0)
  1777. iowrite32(vp->tx_ring_dma + (vp->dirty_tx % TX_RING_SIZE) * sizeof(struct boom_tx_desc),
  1778. ioaddr + DownListPtr);
  1779. if (vp->cur_tx - vp->dirty_tx < TX_RING_SIZE)
  1780. netif_wake_queue (dev);
  1781. if (vp->drv_flags & IS_BOOMERANG)
  1782. iowrite8(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
  1783. iowrite16(DownUnstall, ioaddr + EL3_CMD);
  1784. } else {
  1785. vp->stats.tx_dropped++;
  1786. netif_wake_queue(dev);
  1787. }
  1788. /* Issue Tx Enable */
  1789. iowrite16(TxEnable, ioaddr + EL3_CMD);
  1790. dev->trans_start = jiffies;
  1791. /* Switch to register set 7 for normal use. */
  1792. EL3WINDOW(7);
  1793. }
  1794. /*
  1795. * Handle uncommon interrupt sources. This is a separate routine to minimize
  1796. * the cache impact.
  1797. */
  1798. static void
  1799. vortex_error(struct net_device *dev, int status)
  1800. {
  1801. struct vortex_private *vp = netdev_priv(dev);
  1802. void __iomem *ioaddr = vp->ioaddr;
  1803. int do_tx_reset = 0, reset_mask = 0;
  1804. unsigned char tx_status = 0;
  1805. if (vortex_debug > 2) {
  1806. printk(KERN_ERR "%s: vortex_error(), status=0x%x\n", dev->name, status);
  1807. }
  1808. if (status & TxComplete) { /* Really "TxError" for us. */
  1809. tx_status = ioread8(ioaddr + TxStatus);
  1810. /* Presumably a tx-timeout. We must merely re-enable. */
  1811. if (vortex_debug > 2
  1812. || (tx_status != 0x88 && vortex_debug > 0)) {
  1813. printk(KERN_ERR "%s: Transmit error, Tx status register %2.2x.\n",
  1814. dev->name, tx_status);
  1815. if (tx_status == 0x82) {
  1816. printk(KERN_ERR "Probably a duplex mismatch. See "
  1817. "Documentation/networking/vortex.txt\n");
  1818. }
  1819. dump_tx_ring(dev);
  1820. }
  1821. if (tx_status & 0x14) vp->stats.tx_fifo_errors++;
  1822. if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
  1823. if (tx_status & 0x08) vp->xstats.tx_max_collisions++;
  1824. iowrite8(0, ioaddr + TxStatus);
  1825. if (tx_status & 0x30) { /* txJabber or txUnderrun */
  1826. do_tx_reset = 1;
  1827. } else if ((tx_status & 0x08) && (vp->drv_flags & MAX_COLLISION_RESET)) { /* maxCollisions */
  1828. do_tx_reset = 1;
  1829. reset_mask = 0x0108; /* Reset interface logic, but not download logic */
  1830. } else { /* Merely re-enable the transmitter. */
  1831. iowrite16(TxEnable, ioaddr + EL3_CMD);
  1832. }
  1833. }
  1834. if (status & RxEarly) { /* Rx early is unused. */
  1835. vortex_rx(dev);
  1836. iowrite16(AckIntr | RxEarly, ioaddr + EL3_CMD);
  1837. }
  1838. if (status & StatsFull) { /* Empty statistics. */
  1839. static int DoneDidThat;
  1840. if (vortex_debug > 4)
  1841. printk(KERN_DEBUG "%s: Updating stats.\n", dev->name);
  1842. update_stats(ioaddr, dev);
  1843. /* HACK: Disable statistics as an interrupt source. */
  1844. /* This occurs when we have the wrong media type! */
  1845. if (DoneDidThat == 0 &&
  1846. ioread16(ioaddr + EL3_STATUS) & StatsFull) {
  1847. printk(KERN_WARNING "%s: Updating statistics failed, disabling "
  1848. "stats as an interrupt source.\n", dev->name);
  1849. EL3WINDOW(5);
  1850. iowrite16(SetIntrEnb | (ioread16(ioaddr + 10) & ~StatsFull), ioaddr + EL3_CMD);
  1851. vp->intr_enable &= ~StatsFull;
  1852. EL3WINDOW(7);
  1853. DoneDidThat++;
  1854. }
  1855. }
  1856. if (status & IntReq) { /* Restore all interrupt sources. */
  1857. iowrite16(vp->status_enable, ioaddr + EL3_CMD);
  1858. iowrite16(vp->intr_enable, ioaddr + EL3_CMD);
  1859. }
  1860. if (status & HostError) {
  1861. u16 fifo_diag;
  1862. EL3WINDOW(4);
  1863. fifo_diag = ioread16(ioaddr + Wn4_FIFODiag);
  1864. printk(KERN_ERR "%s: Host error, FIFO diagnostic register %4.4x.\n",
  1865. dev->name, fifo_diag);
  1866. /* Adapter failure requires Tx/Rx reset and reinit. */
  1867. if (vp->full_bus_master_tx) {
  1868. int bus_status = ioread32(ioaddr + PktStatus);
  1869. /* 0x80000000 PCI master abort. */
  1870. /* 0x40000000 PCI target abort. */
  1871. if (vortex_debug)
  1872. printk(KERN_ERR "%s: PCI bus error, bus status %8.8x\n", dev->name, bus_status);
  1873. /* In this case, blow the card away */
  1874. /* Must not enter D3 or we can't legally issue the reset! */
  1875. vortex_down(dev, 0);
  1876. issue_and_wait(dev, TotalReset | 0xff);
  1877. vortex_up(dev); /* AKPM: bug. vortex_up() assumes that the rx ring is full. It may not be. */
  1878. } else if (fifo_diag & 0x0400)
  1879. do_tx_reset = 1;
  1880. if (fifo_diag & 0x3000) {
  1881. /* Reset Rx fifo and upload logic */
  1882. issue_and_wait(dev, RxReset|0x07);
  1883. /* Set the Rx filter to the current state. */
  1884. set_rx_mode(dev);
  1885. /* enable 802.1q VLAN tagged frames */
  1886. set_8021q_mode(dev, 1);
  1887. iowrite16(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
  1888. iowrite16(AckIntr | HostError, ioaddr + EL3_CMD);
  1889. }
  1890. }
  1891. if (do_tx_reset) {
  1892. issue_and_wait(dev, TxReset|reset_mask);
  1893. iowrite16(TxEnable, ioaddr + EL3_CMD);
  1894. if (!vp->full_bus_master_tx)
  1895. netif_wake_queue(dev);
  1896. }
  1897. }
  1898. static int
  1899. vortex_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1900. {
  1901. struct vortex_private *vp = netdev_priv(dev);
  1902. void __iomem *ioaddr = vp->ioaddr;
  1903. /* Put out the doubleword header... */
  1904. iowrite32(skb->len, ioaddr + TX_FIFO);
  1905. if (vp->bus_master) {
  1906. /* Set the bus-master controller to transfer the packet. */
  1907. int len = (skb->len + 3) & ~3;
  1908. iowrite32(vp->tx_skb_dma = pci_map_single(VORTEX_PCI(vp), skb->data, len, PCI_DMA_TODEVICE),
  1909. ioaddr + Wn7_MasterAddr);
  1910. iowrite16(len, ioaddr + Wn7_MasterLen);
  1911. vp->tx_skb = skb;
  1912. iowrite16(StartDMADown, ioaddr + EL3_CMD);
  1913. /* netif_wake_queue() will be called at the DMADone interrupt. */
  1914. } else {
  1915. /* ... and the packet rounded to a doubleword. */
  1916. iowrite32_rep(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
  1917. dev_kfree_skb (skb);
  1918. if (ioread16(ioaddr + TxFree) > 1536) {
  1919. netif_start_queue (dev); /* AKPM: redundant? */
  1920. } else {
  1921. /* Interrupt us when the FIFO has room for max-sized packet. */
  1922. netif_stop_queue(dev);
  1923. iowrite16(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
  1924. }
  1925. }
  1926. dev->trans_start = jiffies;
  1927. /* Clear the Tx status stack. */
  1928. {
  1929. int tx_status;
  1930. int i = 32;
  1931. while (--i > 0 && (tx_status = ioread8(ioaddr + TxStatus)) > 0) {
  1932. if (tx_status & 0x3C) { /* A Tx-disabling error occurred. */
  1933. if (vortex_debug > 2)
  1934. printk(KERN_DEBUG "%s: Tx error, status %2.2x.\n",
  1935. dev->name, tx_status);
  1936. if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
  1937. if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
  1938. if (tx_status & 0x30) {
  1939. issue_and_wait(dev, TxReset);
  1940. }
  1941. iowrite16(TxEnable, ioaddr + EL3_CMD);
  1942. }
  1943. iowrite8(0x00, ioaddr + TxStatus); /* Pop the status stack. */
  1944. }
  1945. }
  1946. return 0;
  1947. }
  1948. static int
  1949. boomerang_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1950. {
  1951. struct vortex_private *vp = netdev_priv(dev);
  1952. void __iomem *ioaddr = vp->ioaddr;
  1953. /* Calculate the next Tx descriptor entry. */
  1954. int entry = vp->cur_tx % TX_RING_SIZE;
  1955. struct boom_tx_desc *prev_entry = &vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
  1956. unsigned long flags;
  1957. if (vortex_debug > 6) {
  1958. printk(KERN_DEBUG "boomerang_start_xmit()\n");
  1959. printk(KERN_DEBUG "%s: Trying to send a packet, Tx index %d.\n",
  1960. dev->name, vp->cur_tx);
  1961. }
  1962. if (vp->cur_tx - vp->dirty_tx >= TX_RING_SIZE) {
  1963. if (vortex_debug > 0)
  1964. printk(KERN_WARNING "%s: BUG! Tx Ring full, refusing to send buffer.\n",
  1965. dev->name);
  1966. netif_stop_queue(dev);
  1967. return 1;
  1968. }
  1969. vp->tx_skbuff[entry] = skb;
  1970. vp->tx_ring[entry].next = 0;
  1971. #if DO_ZEROCOPY
  1972. if (skb->ip_summed != CHECKSUM_HW)
  1973. vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
  1974. else
  1975. vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded | AddTCPChksum | AddUDPChksum);
  1976. if (!skb_shinfo(skb)->nr_frags) {
  1977. vp->tx_ring[entry].frag[0].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data,
  1978. skb->len, PCI_DMA_TODEVICE));
  1979. vp->tx_ring[entry].frag[0].length = cpu_to_le32(skb->len | LAST_FRAG);
  1980. } else {
  1981. int i;
  1982. vp->tx_ring[entry].frag[0].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data,
  1983. skb->len-skb->data_len, PCI_DMA_TODEVICE));
  1984. vp->tx_ring[entry].frag[0].length = cpu_to_le32(skb->len-skb->data_len);
  1985. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  1986. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1987. vp->tx_ring[entry].frag[i+1].addr =
  1988. cpu_to_le32(pci_map_single(VORTEX_PCI(vp),
  1989. (void*)page_address(frag->page) + frag->page_offset,
  1990. frag->size, PCI_DMA_TODEVICE));
  1991. if (i == skb_shinfo(skb)->nr_frags-1)
  1992. vp->tx_ring[entry].frag[i+1].length = cpu_to_le32(frag->size|LAST_FRAG);
  1993. else
  1994. vp->tx_ring[entry].frag[i+1].length = cpu_to_le32(frag->size);
  1995. }
  1996. }
  1997. #else
  1998. vp->tx_ring[entry].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, skb->len, PCI_DMA_TODEVICE));
  1999. vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG);
  2000. vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
  2001. #endif
  2002. spin_lock_irqsave(&vp->lock, flags);
  2003. /* Wait for the stall to complete. */
  2004. issue_and_wait(dev, DownStall);
  2005. prev_entry->next = cpu_to_le32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc));
  2006. if (ioread32(ioaddr + DownListPtr) == 0) {
  2007. iowrite32(vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc), ioaddr + DownListPtr);
  2008. vp->queued_packet++;
  2009. }
  2010. vp->cur_tx++;
  2011. if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1) {
  2012. netif_stop_queue (dev);
  2013. } else { /* Clear previous interrupt enable. */
  2014. #if defined(tx_interrupt_mitigation)
  2015. /* Dubious. If in boomeang_interrupt "faster" cyclone ifdef
  2016. * were selected, this would corrupt DN_COMPLETE. No?
  2017. */
  2018. prev_entry->status &= cpu_to_le32(~TxIntrUploaded);
  2019. #endif
  2020. }
  2021. iowrite16(DownUnstall, ioaddr + EL3_CMD);
  2022. spin_unlock_irqrestore(&vp->lock, flags);
  2023. dev->trans_start = jiffies;
  2024. return 0;
  2025. }
  2026. /* The interrupt handler does all of the Rx thread work and cleans up
  2027. after the Tx thread. */
  2028. /*
  2029. * This is the ISR for the vortex series chips.
  2030. * full_bus_master_tx == 0 && full_bus_master_rx == 0
  2031. */
  2032. static irqreturn_t
  2033. vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  2034. {
  2035. struct net_device *dev = dev_id;
  2036. struct vortex_private *vp = netdev_priv(dev);
  2037. void __iomem *ioaddr;
  2038. int status;
  2039. int work_done = max_interrupt_work;
  2040. int handled = 0;
  2041. ioaddr = vp->ioaddr;
  2042. spin_lock(&vp->lock);
  2043. status = ioread16(ioaddr + EL3_STATUS);
  2044. if (vortex_debug > 6)
  2045. printk("vortex_interrupt(). status=0x%4x\n", status);
  2046. if ((status & IntLatch) == 0)
  2047. goto handler_exit; /* No interrupt: shared IRQs cause this */
  2048. handled = 1;
  2049. if (status & IntReq) {
  2050. status |= vp->deferred;
  2051. vp->deferred = 0;
  2052. }
  2053. if (status == 0xffff) /* h/w no longer present (hotplug)? */
  2054. goto handler_exit;
  2055. if (vortex_debug > 4)
  2056. printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
  2057. dev->name, status, ioread8(ioaddr + Timer));
  2058. do {
  2059. if (vortex_debug > 5)
  2060. printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
  2061. dev->name, status);
  2062. if (status & RxComplete)
  2063. vortex_rx(dev);
  2064. if (status & TxAvailable) {
  2065. if (vortex_debug > 5)
  2066. printk(KERN_DEBUG " TX room bit was handled.\n");
  2067. /* There's room in the FIFO for a full-sized packet. */
  2068. iowrite16(AckIntr | TxAvailable, ioaddr + EL3_CMD);
  2069. netif_wake_queue (dev);
  2070. }
  2071. if (status & DMADone) {
  2072. if (ioread16(ioaddr + Wn7_MasterStatus) & 0x1000) {
  2073. iowrite16(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
  2074. pci_unmap_single(VORTEX_PCI(vp), vp->tx_skb_dma, (vp->tx_skb->len + 3) & ~3, PCI_DMA_TODEVICE);
  2075. dev_kfree_skb_irq(vp->tx_skb); /* Release the transferred buffer */
  2076. if (ioread16(ioaddr + TxFree) > 1536) {
  2077. /*
  2078. * AKPM: FIXME: I don't think we need this. If the queue was stopped due to
  2079. * insufficient FIFO room, the TxAvailable test will succeed and call
  2080. * netif_wake_queue()
  2081. */
  2082. netif_wake_queue(dev);
  2083. } else { /* Interrupt when FIFO has room for max-sized packet. */
  2084. iowrite16(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
  2085. netif_stop_queue(dev);
  2086. }
  2087. }
  2088. }
  2089. /* Check for all uncommon interrupts at once. */
  2090. if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq)) {
  2091. if (status == 0xffff)
  2092. break;
  2093. vortex_error(dev, status);
  2094. }
  2095. if (--work_done < 0) {
  2096. printk(KERN_WARNING "%s: Too much work in interrupt, status "
  2097. "%4.4x.\n", dev->name, status);
  2098. /* Disable all pending interrupts. */
  2099. do {
  2100. vp->deferred |= status;
  2101. iowrite16(SetStatusEnb | (~vp->deferred & vp->status_enable),
  2102. ioaddr + EL3_CMD);
  2103. iowrite16(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
  2104. } while ((status = ioread16(ioaddr + EL3_CMD)) & IntLatch);
  2105. /* The timer will reenable interrupts. */
  2106. mod_timer(&vp->timer, jiffies + 1*HZ);
  2107. break;
  2108. }
  2109. /* Acknowledge the IRQ. */
  2110. iowrite16(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
  2111. } while ((status = ioread16(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
  2112. if (vortex_debug > 4)
  2113. printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
  2114. dev->name, status);
  2115. handler_exit:
  2116. spin_unlock(&vp->lock);
  2117. return IRQ_RETVAL(handled);
  2118. }
  2119. /*
  2120. * This is the ISR for the boomerang series chips.
  2121. * full_bus_master_tx == 1 && full_bus_master_rx == 1
  2122. */
  2123. static irqreturn_t
  2124. boomerang_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  2125. {
  2126. struct net_device *dev = dev_id;
  2127. struct vortex_private *vp = netdev_priv(dev);
  2128. void __iomem *ioaddr;
  2129. int status;
  2130. int work_done = max_interrupt_work;
  2131. ioaddr = vp->ioaddr;
  2132. /*
  2133. * It seems dopey to put the spinlock this early, but we could race against vortex_tx_timeout
  2134. * and boomerang_start_xmit
  2135. */
  2136. spin_lock(&vp->lock);
  2137. status = ioread16(ioaddr + EL3_STATUS);
  2138. if (vortex_debug > 6)
  2139. printk(KERN_DEBUG "boomerang_interrupt. status=0x%4x\n", status);
  2140. if ((status & IntLatch) == 0)
  2141. goto handler_exit; /* No interrupt: shared IRQs can cause this */
  2142. if (status == 0xffff) { /* h/w no longer present (hotplug)? */
  2143. if (vortex_debug > 1)
  2144. printk(KERN_DEBUG "boomerang_interrupt(1): status = 0xffff\n");
  2145. goto handler_exit;
  2146. }
  2147. if (status & IntReq) {
  2148. status |= vp->deferred;
  2149. vp->deferred = 0;
  2150. }
  2151. if (vortex_debug > 4)
  2152. printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
  2153. dev->name, status, ioread8(ioaddr + Timer));
  2154. do {
  2155. if (vortex_debug > 5)
  2156. printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
  2157. dev->name, status);
  2158. if (status & UpComplete) {
  2159. iowrite16(AckIntr | UpComplete, ioaddr + EL3_CMD);
  2160. if (vortex_debug > 5)
  2161. printk(KERN_DEBUG "boomerang_interrupt->boomerang_rx\n");
  2162. boomerang_rx(dev);
  2163. }
  2164. if (status & DownComplete) {
  2165. unsigned int dirty_tx = vp->dirty_tx;
  2166. iowrite16(AckIntr | DownComplete, ioaddr + EL3_CMD);
  2167. while (vp->cur_tx - dirty_tx > 0) {
  2168. int entry = dirty_tx % TX_RING_SIZE;
  2169. #if 1 /* AKPM: the latter is faster, but cyclone-only */
  2170. if (ioread32(ioaddr + DownListPtr) ==
  2171. vp->tx_ring_dma + entry * sizeof(struct boom_tx_desc))
  2172. break; /* It still hasn't been processed. */
  2173. #else
  2174. if ((vp->tx_ring[entry].status & DN_COMPLETE) == 0)
  2175. break; /* It still hasn't been processed. */
  2176. #endif
  2177. if (vp->tx_skbuff[entry]) {
  2178. struct sk_buff *skb = vp->tx_skbuff[entry];
  2179. #if DO_ZEROCOPY
  2180. int i;
  2181. for (i=0; i<=skb_shinfo(skb)->nr_frags; i++)
  2182. pci_unmap_single(VORTEX_PCI(vp),
  2183. le32_to_cpu(vp->tx_ring[entry].frag[i].addr),
  2184. le32_to_cpu(vp->tx_ring[entry].frag[i].length)&0xFFF,
  2185. PCI_DMA_TODEVICE);
  2186. #else
  2187. pci_unmap_single(VORTEX_PCI(vp),
  2188. le32_to_cpu(vp->tx_ring[entry].addr), skb->len, PCI_DMA_TODEVICE);
  2189. #endif
  2190. dev_kfree_skb_irq(skb);
  2191. vp->tx_skbuff[entry] = NULL;
  2192. } else {
  2193. printk(KERN_DEBUG "boomerang_interrupt: no skb!\n");
  2194. }
  2195. /* vp->stats.tx_packets++; Counted below. */
  2196. dirty_tx++;
  2197. }
  2198. vp->dirty_tx = dirty_tx;
  2199. if (vp->cur_tx - dirty_tx <= TX_RING_SIZE - 1) {
  2200. if (vortex_debug > 6)
  2201. printk(KERN_DEBUG "boomerang_interrupt: wake queue\n");
  2202. netif_wake_queue (dev);
  2203. }
  2204. }
  2205. /* Check for all uncommon interrupts at once. */
  2206. if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq))
  2207. vortex_error(dev, status);
  2208. if (--work_done < 0) {
  2209. printk(KERN_WARNING "%s: Too much work in interrupt, status "
  2210. "%4.4x.\n", dev->name, status);
  2211. /* Disable all pending interrupts. */
  2212. do {
  2213. vp->deferred |= status;
  2214. iowrite16(SetStatusEnb | (~vp->deferred & vp->status_enable),
  2215. ioaddr + EL3_CMD);
  2216. iowrite16(AckIntr | (vp->deferred & 0x7ff), ioaddr + EL3_CMD);
  2217. } while ((status = ioread16(ioaddr + EL3_CMD)) & IntLatch);
  2218. /* The timer will reenable interrupts. */
  2219. mod_timer(&vp->timer, jiffies + 1*HZ);
  2220. break;
  2221. }
  2222. /* Acknowledge the IRQ. */
  2223. iowrite16(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
  2224. if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
  2225. iowrite32(0x8000, vp->cb_fn_base + 4);
  2226. } while ((status = ioread16(ioaddr + EL3_STATUS)) & IntLatch);
  2227. if (vortex_debug > 4)
  2228. printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
  2229. dev->name, status);
  2230. handler_exit:
  2231. spin_unlock(&vp->lock);
  2232. return IRQ_HANDLED;
  2233. }
  2234. static int vortex_rx(struct net_device *dev)
  2235. {
  2236. struct vortex_private *vp = netdev_priv(dev);
  2237. void __iomem *ioaddr = vp->ioaddr;
  2238. int i;
  2239. short rx_status;
  2240. if (vortex_debug > 5)
  2241. printk(KERN_DEBUG "vortex_rx(): status %4.4x, rx_status %4.4x.\n",
  2242. ioread16(ioaddr+EL3_STATUS), ioread16(ioaddr+RxStatus));
  2243. while ((rx_status = ioread16(ioaddr + RxStatus)) > 0) {
  2244. if (rx_status & 0x4000) { /* Error, update stats. */
  2245. unsigned char rx_error = ioread8(ioaddr + RxErrors);
  2246. if (vortex_debug > 2)
  2247. printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
  2248. vp->stats.rx_errors++;
  2249. if (rx_error & 0x01) vp->stats.rx_over_errors++;
  2250. if (rx_error & 0x02) vp->stats.rx_length_errors++;
  2251. if (rx_error & 0x04) vp->stats.rx_frame_errors++;
  2252. if (rx_error & 0x08) vp->stats.rx_crc_errors++;
  2253. if (rx_error & 0x10) vp->stats.rx_length_errors++;
  2254. } else {
  2255. /* The packet length: up to 4.5K!. */
  2256. int pkt_len = rx_status & 0x1fff;
  2257. struct sk_buff *skb;
  2258. skb = dev_alloc_skb(pkt_len + 5);
  2259. if (vortex_debug > 4)
  2260. printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
  2261. pkt_len, rx_status);
  2262. if (skb != NULL) {
  2263. skb->dev = dev;
  2264. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  2265. /* 'skb_put()' points to the start of sk_buff data area. */
  2266. if (vp->bus_master &&
  2267. ! (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)) {
  2268. dma_addr_t dma = pci_map_single(VORTEX_PCI(vp), skb_put(skb, pkt_len),
  2269. pkt_len, PCI_DMA_FROMDEVICE);
  2270. iowrite32(dma, ioaddr + Wn7_MasterAddr);
  2271. iowrite16((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
  2272. iowrite16(StartDMAUp, ioaddr + EL3_CMD);
  2273. while (ioread16(ioaddr + Wn7_MasterStatus) & 0x8000)
  2274. ;
  2275. pci_unmap_single(VORTEX_PCI(vp), dma, pkt_len, PCI_DMA_FROMDEVICE);
  2276. } else {
  2277. ioread32_rep(ioaddr + RX_FIFO,
  2278. skb_put(skb, pkt_len),
  2279. (pkt_len + 3) >> 2);
  2280. }
  2281. iowrite16(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
  2282. skb->protocol = eth_type_trans(skb, dev);
  2283. netif_rx(skb);
  2284. dev->last_rx = jiffies;
  2285. vp->stats.rx_packets++;
  2286. /* Wait a limited time to go to next packet. */
  2287. for (i = 200; i >= 0; i--)
  2288. if ( ! (ioread16(ioaddr + EL3_STATUS) & CmdInProgress))
  2289. break;
  2290. continue;
  2291. } else if (vortex_debug > 0)
  2292. printk(KERN_NOTICE "%s: No memory to allocate a sk_buff of "
  2293. "size %d.\n", dev->name, pkt_len);
  2294. vp->stats.rx_dropped++;
  2295. }
  2296. issue_and_wait(dev, RxDiscard);
  2297. }
  2298. return 0;
  2299. }
  2300. static int
  2301. boomerang_rx(struct net_device *dev)
  2302. {
  2303. struct vortex_private *vp = netdev_priv(dev);
  2304. int entry = vp->cur_rx % RX_RING_SIZE;
  2305. void __iomem *ioaddr = vp->ioaddr;
  2306. int rx_status;
  2307. int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx;
  2308. if (vortex_debug > 5)
  2309. printk(KERN_DEBUG "boomerang_rx(): status %4.4x\n", ioread16(ioaddr+EL3_STATUS));
  2310. while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){
  2311. if (--rx_work_limit < 0)
  2312. break;
  2313. if (rx_status & RxDError) { /* Error, update stats. */
  2314. unsigned char rx_error = rx_status >> 16;
  2315. if (vortex_debug > 2)
  2316. printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
  2317. vp->stats.rx_errors++;
  2318. if (rx_error & 0x01) vp->stats.rx_over_errors++;
  2319. if (rx_error & 0x02) vp->stats.rx_length_errors++;
  2320. if (rx_error & 0x04) vp->stats.rx_frame_errors++;
  2321. if (rx_error & 0x08) vp->stats.rx_crc_errors++;
  2322. if (rx_error & 0x10) vp->stats.rx_length_errors++;
  2323. } else {
  2324. /* The packet length: up to 4.5K!. */
  2325. int pkt_len = rx_status & 0x1fff;
  2326. struct sk_buff *skb;
  2327. dma_addr_t dma = le32_to_cpu(vp->rx_ring[entry].addr);
  2328. if (vortex_debug > 4)
  2329. printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
  2330. pkt_len, rx_status);
  2331. /* Check if the packet is long enough to just accept without
  2332. copying to a properly sized skbuff. */
  2333. if (pkt_len < rx_copybreak && (skb = dev_alloc_skb(pkt_len + 2)) != 0) {
  2334. skb->dev = dev;
  2335. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  2336. pci_dma_sync_single_for_cpu(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  2337. /* 'skb_put()' points to the start of sk_buff data area. */
  2338. memcpy(skb_put(skb, pkt_len),
  2339. vp->rx_skbuff[entry]->data,
  2340. pkt_len);
  2341. pci_dma_sync_single_for_device(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  2342. vp->rx_copy++;
  2343. } else {
  2344. /* Pass up the skbuff already on the Rx ring. */
  2345. skb = vp->rx_skbuff[entry];
  2346. vp->rx_skbuff[entry] = NULL;
  2347. skb_put(skb, pkt_len);
  2348. pci_unmap_single(VORTEX_PCI(vp), dma, PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  2349. vp->rx_nocopy++;
  2350. }
  2351. skb->protocol = eth_type_trans(skb, dev);
  2352. { /* Use hardware checksum info. */
  2353. int csum_bits = rx_status & 0xee000000;
  2354. if (csum_bits &&
  2355. (csum_bits == (IPChksumValid | TCPChksumValid) ||
  2356. csum_bits == (IPChksumValid | UDPChksumValid))) {
  2357. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2358. vp->rx_csumhits++;
  2359. }
  2360. }
  2361. netif_rx(skb);
  2362. dev->last_rx = jiffies;
  2363. vp->stats.rx_packets++;
  2364. }
  2365. entry = (++vp->cur_rx) % RX_RING_SIZE;
  2366. }
  2367. /* Refill the Rx ring buffers. */
  2368. for (; vp->cur_rx - vp->dirty_rx > 0; vp->dirty_rx++) {
  2369. struct sk_buff *skb;
  2370. entry = vp->dirty_rx % RX_RING_SIZE;
  2371. if (vp->rx_skbuff[entry] == NULL) {
  2372. skb = dev_alloc_skb(PKT_BUF_SZ);
  2373. if (skb == NULL) {
  2374. static unsigned long last_jif;
  2375. if (time_after(jiffies, last_jif + 10 * HZ)) {
  2376. printk(KERN_WARNING "%s: memory shortage\n", dev->name);
  2377. last_jif = jiffies;
  2378. }
  2379. if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE)
  2380. mod_timer(&vp->rx_oom_timer, RUN_AT(HZ * 1));
  2381. break; /* Bad news! */
  2382. }
  2383. skb->dev = dev; /* Mark as being used by this device. */
  2384. skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
  2385. vp->rx_ring[entry].addr = cpu_to_le32(pci_map_single(VORTEX_PCI(vp), skb->data, PKT_BUF_SZ, PCI_DMA_FROMDEVICE));
  2386. vp->rx_skbuff[entry] = skb;
  2387. }
  2388. vp->rx_ring[entry].status = 0; /* Clear complete bit. */
  2389. iowrite16(UpUnstall, ioaddr + EL3_CMD);
  2390. }
  2391. return 0;
  2392. }
  2393. /*
  2394. * If we've hit a total OOM refilling the Rx ring we poll once a second
  2395. * for some memory. Otherwise there is no way to restart the rx process.
  2396. */
  2397. static void
  2398. rx_oom_timer(unsigned long arg)
  2399. {
  2400. struct net_device *dev = (struct net_device *)arg;
  2401. struct vortex_private *vp = netdev_priv(dev);
  2402. spin_lock_irq(&vp->lock);
  2403. if ((vp->cur_rx - vp->dirty_rx) == RX_RING_SIZE) /* This test is redundant, but makes me feel good */
  2404. boomerang_rx(dev);
  2405. if (vortex_debug > 1) {
  2406. printk(KERN_DEBUG "%s: rx_oom_timer %s\n", dev->name,
  2407. ((vp->cur_rx - vp->dirty_rx) != RX_RING_SIZE) ? "succeeded" : "retrying");
  2408. }
  2409. spin_unlock_irq(&vp->lock);
  2410. }
  2411. static void
  2412. vortex_down(struct net_device *dev, int final_down)
  2413. {
  2414. struct vortex_private *vp = netdev_priv(dev);
  2415. void __iomem *ioaddr = vp->ioaddr;
  2416. netif_stop_queue (dev);
  2417. del_timer_sync(&vp->rx_oom_timer);
  2418. del_timer_sync(&vp->timer);
  2419. /* Turn off statistics ASAP. We update vp->stats below. */
  2420. iowrite16(StatsDisable, ioaddr + EL3_CMD);
  2421. /* Disable the receiver and transmitter. */
  2422. iowrite16(RxDisable, ioaddr + EL3_CMD);
  2423. iowrite16(TxDisable, ioaddr + EL3_CMD);
  2424. /* Disable receiving 802.1q tagged frames */
  2425. set_8021q_mode(dev, 0);
  2426. if (dev->if_port == XCVR_10base2)
  2427. /* Turn off thinnet power. Green! */
  2428. iowrite16(StopCoax, ioaddr + EL3_CMD);
  2429. iowrite16(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
  2430. update_stats(ioaddr, dev);
  2431. if (vp->full_bus_master_rx)
  2432. iowrite32(0, ioaddr + UpListPtr);
  2433. if (vp->full_bus_master_tx)
  2434. iowrite32(0, ioaddr + DownListPtr);
  2435. if (final_down && VORTEX_PCI(vp)) {
  2436. vp->pm_state_valid = 1;
  2437. pci_save_state(VORTEX_PCI(vp));
  2438. acpi_set_WOL(dev);
  2439. }
  2440. }
  2441. static int
  2442. vortex_close(struct net_device *dev)
  2443. {
  2444. struct vortex_private *vp = netdev_priv(dev);
  2445. void __iomem *ioaddr = vp->ioaddr;
  2446. int i;
  2447. if (netif_device_present(dev))
  2448. vortex_down(dev, 1);
  2449. if (vortex_debug > 1) {
  2450. printk(KERN_DEBUG"%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
  2451. dev->name, ioread16(ioaddr + EL3_STATUS), ioread8(ioaddr + TxStatus));
  2452. printk(KERN_DEBUG "%s: vortex close stats: rx_nocopy %d rx_copy %d"
  2453. " tx_queued %d Rx pre-checksummed %d.\n",
  2454. dev->name, vp->rx_nocopy, vp->rx_copy, vp->queued_packet, vp->rx_csumhits);
  2455. }
  2456. #if DO_ZEROCOPY
  2457. if (vp->rx_csumhits &&
  2458. (vp->drv_flags & HAS_HWCKSM) == 0 &&
  2459. (vp->card_idx >= MAX_UNITS || hw_checksums[vp->card_idx] == -1)) {
  2460. printk(KERN_WARNING "%s supports hardware checksums, and we're "
  2461. "not using them!\n", dev->name);
  2462. }
  2463. #endif
  2464. free_irq(dev->irq, dev);
  2465. if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
  2466. for (i = 0; i < RX_RING_SIZE; i++)
  2467. if (vp->rx_skbuff[i]) {
  2468. pci_unmap_single( VORTEX_PCI(vp), le32_to_cpu(vp->rx_ring[i].addr),
  2469. PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
  2470. dev_kfree_skb(vp->rx_skbuff[i]);
  2471. vp->rx_skbuff[i] = NULL;
  2472. }
  2473. }
  2474. if (vp->full_bus_master_tx) { /* Free Boomerang bus master Tx buffers. */
  2475. for (i = 0; i < TX_RING_SIZE; i++) {
  2476. if (vp->tx_skbuff[i]) {
  2477. struct sk_buff *skb = vp->tx_skbuff[i];
  2478. #if DO_ZEROCOPY
  2479. int k;
  2480. for (k=0; k<=skb_shinfo(skb)->nr_frags; k++)
  2481. pci_unmap_single(VORTEX_PCI(vp),
  2482. le32_to_cpu(vp->tx_ring[i].frag[k].addr),
  2483. le32_to_cpu(vp->tx_ring[i].frag[k].length)&0xFFF,
  2484. PCI_DMA_TODEVICE);
  2485. #else
  2486. pci_unmap_single(VORTEX_PCI(vp), le32_to_cpu(vp->tx_ring[i].addr), skb->len, PCI_DMA_TODEVICE);
  2487. #endif
  2488. dev_kfree_skb(skb);
  2489. vp->tx_skbuff[i] = NULL;
  2490. }
  2491. }
  2492. }
  2493. return 0;
  2494. }
  2495. static void
  2496. dump_tx_ring(struct net_device *dev)
  2497. {
  2498. if (vortex_debug > 0) {
  2499. struct vortex_private *vp = netdev_priv(dev);
  2500. void __iomem *ioaddr = vp->ioaddr;
  2501. if (vp->full_bus_master_tx) {
  2502. int i;
  2503. int stalled = ioread32(ioaddr + PktStatus) & 0x04; /* Possible racy. But it's only debug stuff */
  2504. printk(KERN_ERR " Flags; bus-master %d, dirty %d(%d) current %d(%d)\n",
  2505. vp->full_bus_master_tx,
  2506. vp->dirty_tx, vp->dirty_tx % TX_RING_SIZE,
  2507. vp->cur_tx, vp->cur_tx % TX_RING_SIZE);
  2508. printk(KERN_ERR " Transmit list %8.8x vs. %p.\n",
  2509. ioread32(ioaddr + DownListPtr),
  2510. &vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]);
  2511. issue_and_wait(dev, DownStall);
  2512. for (i = 0; i < TX_RING_SIZE; i++) {
  2513. printk(KERN_ERR " %d: @%p length %8.8x status %8.8x\n", i,
  2514. &vp->tx_ring[i],
  2515. #if DO_ZEROCOPY
  2516. le32_to_cpu(vp->tx_ring[i].frag[0].length),
  2517. #else
  2518. le32_to_cpu(vp->tx_ring[i].length),
  2519. #endif
  2520. le32_to_cpu(vp->tx_ring[i].status));
  2521. }
  2522. if (!stalled)
  2523. iowrite16(DownUnstall, ioaddr + EL3_CMD);
  2524. }
  2525. }
  2526. }
  2527. static struct net_device_stats *vortex_get_stats(struct net_device *dev)
  2528. {
  2529. struct vortex_private *vp = netdev_priv(dev);
  2530. void __iomem *ioaddr = vp->ioaddr;
  2531. unsigned long flags;
  2532. if (netif_device_present(dev)) { /* AKPM: Used to be netif_running */
  2533. spin_lock_irqsave (&vp->lock, flags);
  2534. update_stats(ioaddr, dev);
  2535. spin_unlock_irqrestore (&vp->lock, flags);
  2536. }
  2537. return &vp->stats;
  2538. }
  2539. /* Update statistics.
  2540. Unlike with the EL3 we need not worry about interrupts changing
  2541. the window setting from underneath us, but we must still guard
  2542. against a race condition with a StatsUpdate interrupt updating the
  2543. table. This is done by checking that the ASM (!) code generated uses
  2544. atomic updates with '+='.
  2545. */
  2546. static void update_stats(void __iomem *ioaddr, struct net_device *dev)
  2547. {
  2548. struct vortex_private *vp = netdev_priv(dev);
  2549. int old_window = ioread16(ioaddr + EL3_CMD);
  2550. if (old_window == 0xffff) /* Chip suspended or ejected. */
  2551. return;
  2552. /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
  2553. /* Switch to the stats window, and read everything. */
  2554. EL3WINDOW(6);
  2555. vp->stats.tx_carrier_errors += ioread8(ioaddr + 0);
  2556. vp->stats.tx_heartbeat_errors += ioread8(ioaddr + 1);
  2557. vp->stats.tx_window_errors += ioread8(ioaddr + 4);
  2558. vp->stats.rx_fifo_errors += ioread8(ioaddr + 5);
  2559. vp->stats.tx_packets += ioread8(ioaddr + 6);
  2560. vp->stats.tx_packets += (ioread8(ioaddr + 9)&0x30) << 4;
  2561. /* Rx packets */ ioread8(ioaddr + 7); /* Must read to clear */
  2562. /* Don't bother with register 9, an extension of registers 6&7.
  2563. If we do use the 6&7 values the atomic update assumption above
  2564. is invalid. */
  2565. vp->stats.rx_bytes += ioread16(ioaddr + 10);
  2566. vp->stats.tx_bytes += ioread16(ioaddr + 12);
  2567. /* Extra stats for get_ethtool_stats() */
  2568. vp->xstats.tx_multiple_collisions += ioread8(ioaddr + 2);
  2569. vp->xstats.tx_single_collisions += ioread8(ioaddr + 3);
  2570. vp->xstats.tx_deferred += ioread8(ioaddr + 8);
  2571. EL3WINDOW(4);
  2572. vp->xstats.rx_bad_ssd += ioread8(ioaddr + 12);
  2573. vp->stats.collisions = vp->xstats.tx_multiple_collisions
  2574. + vp->xstats.tx_single_collisions
  2575. + vp->xstats.tx_max_collisions;
  2576. {
  2577. u8 up = ioread8(ioaddr + 13);
  2578. vp->stats.rx_bytes += (up & 0x0f) << 16;
  2579. vp->stats.tx_bytes += (up & 0xf0) << 12;
  2580. }
  2581. EL3WINDOW(old_window >> 13);
  2582. return;
  2583. }
  2584. static int vortex_nway_reset(struct net_device *dev)
  2585. {
  2586. struct vortex_private *vp = netdev_priv(dev);
  2587. void __iomem *ioaddr = vp->ioaddr;
  2588. unsigned long flags;
  2589. int rc;
  2590. spin_lock_irqsave(&vp->lock, flags);
  2591. EL3WINDOW(4);
  2592. rc = mii_nway_restart(&vp->mii);
  2593. spin_unlock_irqrestore(&vp->lock, flags);
  2594. return rc;
  2595. }
  2596. static int vortex_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  2597. {
  2598. struct vortex_private *vp = netdev_priv(dev);
  2599. void __iomem *ioaddr = vp->ioaddr;
  2600. unsigned long flags;
  2601. int rc;
  2602. spin_lock_irqsave(&vp->lock, flags);
  2603. EL3WINDOW(4);
  2604. rc = mii_ethtool_gset(&vp->mii, cmd);
  2605. spin_unlock_irqrestore(&vp->lock, flags);
  2606. return rc;
  2607. }
  2608. static int vortex_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  2609. {
  2610. struct vortex_private *vp = netdev_priv(dev);
  2611. void __iomem *ioaddr = vp->ioaddr;
  2612. unsigned long flags;
  2613. int rc;
  2614. spin_lock_irqsave(&vp->lock, flags);
  2615. EL3WINDOW(4);
  2616. rc = mii_ethtool_sset(&vp->mii, cmd);
  2617. spin_unlock_irqrestore(&vp->lock, flags);
  2618. return rc;
  2619. }
  2620. static u32 vortex_get_msglevel(struct net_device *dev)
  2621. {
  2622. return vortex_debug;
  2623. }
  2624. static void vortex_set_msglevel(struct net_device *dev, u32 dbg)
  2625. {
  2626. vortex_debug = dbg;
  2627. }
  2628. static int vortex_get_stats_count(struct net_device *dev)
  2629. {
  2630. return VORTEX_NUM_STATS;
  2631. }
  2632. static void vortex_get_ethtool_stats(struct net_device *dev,
  2633. struct ethtool_stats *stats, u64 *data)
  2634. {
  2635. struct vortex_private *vp = netdev_priv(dev);
  2636. void __iomem *ioaddr = vp->ioaddr;
  2637. unsigned long flags;
  2638. spin_lock_irqsave(&vp->lock, flags);
  2639. update_stats(ioaddr, dev);
  2640. spin_unlock_irqrestore(&vp->lock, flags);
  2641. data[0] = vp->xstats.tx_deferred;
  2642. data[1] = vp->xstats.tx_max_collisions;
  2643. data[2] = vp->xstats.tx_multiple_collisions;
  2644. data[3] = vp->xstats.tx_single_collisions;
  2645. data[4] = vp->xstats.rx_bad_ssd;
  2646. }
  2647. static void vortex_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  2648. {
  2649. switch (stringset) {
  2650. case ETH_SS_STATS:
  2651. memcpy(data, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
  2652. break;
  2653. default:
  2654. WARN_ON(1);
  2655. break;
  2656. }
  2657. }
  2658. static void vortex_get_drvinfo(struct net_device *dev,
  2659. struct ethtool_drvinfo *info)
  2660. {
  2661. struct vortex_private *vp = netdev_priv(dev);
  2662. strcpy(info->driver, DRV_NAME);
  2663. if (VORTEX_PCI(vp)) {
  2664. strcpy(info->bus_info, pci_name(VORTEX_PCI(vp)));
  2665. } else {
  2666. if (VORTEX_EISA(vp))
  2667. sprintf(info->bus_info, vp->gendev->bus_id);
  2668. else
  2669. sprintf(info->bus_info, "EISA 0x%lx %d",
  2670. dev->base_addr, dev->irq);
  2671. }
  2672. }
  2673. static struct ethtool_ops vortex_ethtool_ops = {
  2674. .get_drvinfo = vortex_get_drvinfo,
  2675. .get_strings = vortex_get_strings,
  2676. .get_msglevel = vortex_get_msglevel,
  2677. .set_msglevel = vortex_set_msglevel,
  2678. .get_ethtool_stats = vortex_get_ethtool_stats,
  2679. .get_stats_count = vortex_get_stats_count,
  2680. .get_settings = vortex_get_settings,
  2681. .set_settings = vortex_set_settings,
  2682. .get_link = ethtool_op_get_link,
  2683. .nway_reset = vortex_nway_reset,
  2684. .get_perm_addr = ethtool_op_get_perm_addr,
  2685. };
  2686. #ifdef CONFIG_PCI
  2687. /*
  2688. * Must power the device up to do MDIO operations
  2689. */
  2690. static int vortex_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2691. {
  2692. int err;
  2693. struct vortex_private *vp = netdev_priv(dev);
  2694. void __iomem *ioaddr = vp->ioaddr;
  2695. unsigned long flags;
  2696. int state = 0;
  2697. if(VORTEX_PCI(vp))
  2698. state = VORTEX_PCI(vp)->current_state;
  2699. /* The kernel core really should have pci_get_power_state() */
  2700. if(state != 0)
  2701. pci_set_power_state(VORTEX_PCI(vp), PCI_D0);
  2702. spin_lock_irqsave(&vp->lock, flags);
  2703. EL3WINDOW(4);
  2704. err = generic_mii_ioctl(&vp->mii, if_mii(rq), cmd, NULL);
  2705. spin_unlock_irqrestore(&vp->lock, flags);
  2706. if(state != 0)
  2707. pci_set_power_state(VORTEX_PCI(vp), state);
  2708. return err;
  2709. }
  2710. #endif
  2711. /* Pre-Cyclone chips have no documented multicast filter, so the only
  2712. multicast setting is to receive all multicast frames. At least
  2713. the chip has a very clean way to set the mode, unlike many others. */
  2714. static void set_rx_mode(struct net_device *dev)
  2715. {
  2716. struct vortex_private *vp = netdev_priv(dev);
  2717. void __iomem *ioaddr = vp->ioaddr;
  2718. int new_mode;
  2719. if (dev->flags & IFF_PROMISC) {
  2720. if (vortex_debug > 0)
  2721. printk(KERN_NOTICE "%s: Setting promiscuous mode.\n", dev->name);
  2722. new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast|RxProm;
  2723. } else if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
  2724. new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast;
  2725. } else
  2726. new_mode = SetRxFilter | RxStation | RxBroadcast;
  2727. iowrite16(new_mode, ioaddr + EL3_CMD);
  2728. }
  2729. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  2730. /* Setup the card so that it can receive frames with an 802.1q VLAN tag.
  2731. Note that this must be done after each RxReset due to some backwards
  2732. compatibility logic in the Cyclone and Tornado ASICs */
  2733. /* The Ethernet Type used for 802.1q tagged frames */
  2734. #define VLAN_ETHER_TYPE 0x8100
  2735. static void set_8021q_mode(struct net_device *dev, int enable)
  2736. {
  2737. struct vortex_private *vp = netdev_priv(dev);
  2738. void __iomem *ioaddr = vp->ioaddr;
  2739. int old_window = ioread16(ioaddr + EL3_CMD);
  2740. int mac_ctrl;
  2741. if ((vp->drv_flags&IS_CYCLONE) || (vp->drv_flags&IS_TORNADO)) {
  2742. /* cyclone and tornado chipsets can recognize 802.1q
  2743. * tagged frames and treat them correctly */
  2744. int max_pkt_size = dev->mtu+14; /* MTU+Ethernet header */
  2745. if (enable)
  2746. max_pkt_size += 4; /* 802.1Q VLAN tag */
  2747. EL3WINDOW(3);
  2748. iowrite16(max_pkt_size, ioaddr+Wn3_MaxPktSize);
  2749. /* set VlanEtherType to let the hardware checksumming
  2750. treat tagged frames correctly */
  2751. EL3WINDOW(7);
  2752. iowrite16(VLAN_ETHER_TYPE, ioaddr+Wn7_VlanEtherType);
  2753. } else {
  2754. /* on older cards we have to enable large frames */
  2755. vp->large_frames = dev->mtu > 1500 || enable;
  2756. EL3WINDOW(3);
  2757. mac_ctrl = ioread16(ioaddr+Wn3_MAC_Ctrl);
  2758. if (vp->large_frames)
  2759. mac_ctrl |= 0x40;
  2760. else
  2761. mac_ctrl &= ~0x40;
  2762. iowrite16(mac_ctrl, ioaddr+Wn3_MAC_Ctrl);
  2763. }
  2764. EL3WINDOW(old_window);
  2765. }
  2766. #else
  2767. static void set_8021q_mode(struct net_device *dev, int enable)
  2768. {
  2769. }
  2770. #endif
  2771. /* MII transceiver control section.
  2772. Read and write the MII registers using software-generated serial
  2773. MDIO protocol. See the MII specifications or DP83840A data sheet
  2774. for details. */
  2775. /* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
  2776. met by back-to-back PCI I/O cycles, but we insert a delay to avoid
  2777. "overclocking" issues. */
  2778. #define mdio_delay() ioread32(mdio_addr)
  2779. #define MDIO_SHIFT_CLK 0x01
  2780. #define MDIO_DIR_WRITE 0x04
  2781. #define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
  2782. #define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
  2783. #define MDIO_DATA_READ 0x02
  2784. #define MDIO_ENB_IN 0x00
  2785. /* Generate the preamble required for initial synchronization and
  2786. a few older transceivers. */
  2787. static void mdio_sync(void __iomem *ioaddr, int bits)
  2788. {
  2789. void __iomem *mdio_addr = ioaddr + Wn4_PhysicalMgmt;
  2790. /* Establish sync by sending at least 32 logic ones. */
  2791. while (-- bits >= 0) {
  2792. iowrite16(MDIO_DATA_WRITE1, mdio_addr);
  2793. mdio_delay();
  2794. iowrite16(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
  2795. mdio_delay();
  2796. }
  2797. }
  2798. static int mdio_read(struct net_device *dev, int phy_id, int location)
  2799. {
  2800. int i;
  2801. struct vortex_private *vp = netdev_priv(dev);
  2802. void __iomem *ioaddr = vp->ioaddr;
  2803. int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
  2804. unsigned int retval = 0;
  2805. void __iomem *mdio_addr = ioaddr + Wn4_PhysicalMgmt;
  2806. if (mii_preamble_required)
  2807. mdio_sync(ioaddr, 32);
  2808. /* Shift the read command bits out. */
  2809. for (i = 14; i >= 0; i--) {
  2810. int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  2811. iowrite16(dataval, mdio_addr);
  2812. mdio_delay();
  2813. iowrite16(dataval | MDIO_SHIFT_CLK, mdio_addr);
  2814. mdio_delay();
  2815. }
  2816. /* Read the two transition, 16 data, and wire-idle bits. */
  2817. for (i = 19; i > 0; i--) {
  2818. iowrite16(MDIO_ENB_IN, mdio_addr);
  2819. mdio_delay();
  2820. retval = (retval << 1) | ((ioread16(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
  2821. iowrite16(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
  2822. mdio_delay();
  2823. }
  2824. return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff;
  2825. }
  2826. static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
  2827. {
  2828. struct vortex_private *vp = netdev_priv(dev);
  2829. void __iomem *ioaddr = vp->ioaddr;
  2830. int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
  2831. void __iomem *mdio_addr = ioaddr + Wn4_PhysicalMgmt;
  2832. int i;
  2833. if (mii_preamble_required)
  2834. mdio_sync(ioaddr, 32);
  2835. /* Shift the command bits out. */
  2836. for (i = 31; i >= 0; i--) {
  2837. int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
  2838. iowrite16(dataval, mdio_addr);
  2839. mdio_delay();
  2840. iowrite16(dataval | MDIO_SHIFT_CLK, mdio_addr);
  2841. mdio_delay();
  2842. }
  2843. /* Leave the interface idle. */
  2844. for (i = 1; i >= 0; i--) {
  2845. iowrite16(MDIO_ENB_IN, mdio_addr);
  2846. mdio_delay();
  2847. iowrite16(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
  2848. mdio_delay();
  2849. }
  2850. return;
  2851. }
  2852. /* ACPI: Advanced Configuration and Power Interface. */
  2853. /* Set Wake-On-LAN mode and put the board into D3 (power-down) state. */
  2854. static void acpi_set_WOL(struct net_device *dev)
  2855. {
  2856. struct vortex_private *vp = netdev_priv(dev);
  2857. void __iomem *ioaddr = vp->ioaddr;
  2858. if (vp->enable_wol) {
  2859. /* Power up on: 1==Downloaded Filter, 2==Magic Packets, 4==Link Status. */
  2860. EL3WINDOW(7);
  2861. iowrite16(2, ioaddr + 0x0c);
  2862. /* The RxFilter must accept the WOL frames. */
  2863. iowrite16(SetRxFilter|RxStation|RxMulticast|RxBroadcast, ioaddr + EL3_CMD);
  2864. iowrite16(RxEnable, ioaddr + EL3_CMD);
  2865. pci_enable_wake(VORTEX_PCI(vp), 0, 1);
  2866. /* Change the power state to D3; RxEnable doesn't take effect. */
  2867. pci_set_power_state(VORTEX_PCI(vp), PCI_D3hot);
  2868. }
  2869. }
  2870. static void __devexit vortex_remove_one(struct pci_dev *pdev)
  2871. {
  2872. struct net_device *dev = pci_get_drvdata(pdev);
  2873. struct vortex_private *vp;
  2874. if (!dev) {
  2875. printk("vortex_remove_one called for Compaq device!\n");
  2876. BUG();
  2877. }
  2878. vp = netdev_priv(dev);
  2879. if (vp->cb_fn_base)
  2880. pci_iounmap(VORTEX_PCI(vp), vp->cb_fn_base);
  2881. unregister_netdev(dev);
  2882. if (VORTEX_PCI(vp)) {
  2883. pci_set_power_state(VORTEX_PCI(vp), PCI_D0); /* Go active */
  2884. if (vp->pm_state_valid)
  2885. pci_restore_state(VORTEX_PCI(vp));
  2886. pci_disable_device(VORTEX_PCI(vp));
  2887. }
  2888. /* Should really use issue_and_wait() here */
  2889. iowrite16(TotalReset | ((vp->drv_flags & EEPROM_RESET) ? 0x04 : 0x14),
  2890. vp->ioaddr + EL3_CMD);
  2891. pci_iounmap(VORTEX_PCI(vp), vp->ioaddr);
  2892. pci_free_consistent(pdev,
  2893. sizeof(struct boom_rx_desc) * RX_RING_SIZE
  2894. + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
  2895. vp->rx_ring,
  2896. vp->rx_ring_dma);
  2897. if (vp->must_free_region)
  2898. release_region(dev->base_addr, vp->io_size);
  2899. free_netdev(dev);
  2900. }
  2901. static struct pci_driver vortex_driver = {
  2902. .name = "3c59x",
  2903. .probe = vortex_init_one,
  2904. .remove = __devexit_p(vortex_remove_one),
  2905. .id_table = vortex_pci_tbl,
  2906. #ifdef CONFIG_PM
  2907. .suspend = vortex_suspend,
  2908. .resume = vortex_resume,
  2909. #endif
  2910. };
  2911. static int vortex_have_pci;
  2912. static int vortex_have_eisa;
  2913. static int __init vortex_init(void)
  2914. {
  2915. int pci_rc, eisa_rc;
  2916. pci_rc = pci_module_init(&vortex_driver);
  2917. eisa_rc = vortex_eisa_init();
  2918. if (pci_rc == 0)
  2919. vortex_have_pci = 1;
  2920. if (eisa_rc > 0)
  2921. vortex_have_eisa = 1;
  2922. return (vortex_have_pci + vortex_have_eisa) ? 0 : -ENODEV;
  2923. }
  2924. static void __exit vortex_eisa_cleanup(void)
  2925. {
  2926. struct vortex_private *vp;
  2927. void __iomem *ioaddr;
  2928. #ifdef CONFIG_EISA
  2929. /* Take care of the EISA devices */
  2930. eisa_driver_unregister(&vortex_eisa_driver);
  2931. #endif
  2932. if (compaq_net_device) {
  2933. vp = compaq_net_device->priv;
  2934. ioaddr = ioport_map(compaq_net_device->base_addr,
  2935. VORTEX_TOTAL_SIZE);
  2936. unregister_netdev(compaq_net_device);
  2937. iowrite16(TotalReset, ioaddr + EL3_CMD);
  2938. release_region(compaq_net_device->base_addr,
  2939. VORTEX_TOTAL_SIZE);
  2940. free_netdev(compaq_net_device);
  2941. }
  2942. }
  2943. static void __exit vortex_cleanup(void)
  2944. {
  2945. if (vortex_have_pci)
  2946. pci_unregister_driver(&vortex_driver);
  2947. if (vortex_have_eisa)
  2948. vortex_eisa_cleanup();
  2949. }
  2950. module_init(vortex_init);
  2951. module_exit(vortex_cleanup);