tlan.c 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366
  1. /*******************************************************************************
  2. *
  3. * Linux ThunderLAN Driver
  4. *
  5. * tlan.c
  6. * by James Banks
  7. *
  8. * (C) 1997-1998 Caldera, Inc.
  9. * (C) 1998 James Banks
  10. * (C) 1999-2001 Torben Mathiasen
  11. * (C) 2002 Samuel Chessman
  12. *
  13. * This software may be used and distributed according to the terms
  14. * of the GNU General Public License, incorporated herein by reference.
  15. *
  16. ** Useful (if not required) reading:
  17. *
  18. * Texas Instruments, ThunderLAN Programmer's Guide,
  19. * TI Literature Number SPWU013A
  20. * available in PDF format from www.ti.com
  21. * Level One, LXT901 and LXT970 Data Sheets
  22. * available in PDF format from www.level1.com
  23. * National Semiconductor, DP83840A Data Sheet
  24. * available in PDF format from www.national.com
  25. * Microchip Technology, 24C01A/02A/04A Data Sheet
  26. * available in PDF format from www.microchip.com
  27. *
  28. * Change History
  29. *
  30. * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses
  31. * new PCI BIOS interface.
  32. * Alan Cox <alan@redhat.com>: Fixed the out of memory
  33. * handling.
  34. *
  35. * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer!
  36. *
  37. * v1.1 Dec 20, 1999 - Removed linux version checking
  38. * Patch from Tigran Aivazian.
  39. * - v1.1 includes Alan's SMP updates.
  40. * - We still have problems on SMP though,
  41. * but I'm looking into that.
  42. *
  43. * v1.2 Jan 02, 2000 - Hopefully fixed the SMP deadlock.
  44. * - Removed dependency of HZ being 100.
  45. * - We now allow higher priority timers to
  46. * overwrite timers like TLAN_TIMER_ACTIVITY
  47. * Patch from John Cagle <john.cagle@compaq.com>.
  48. * - Fixed a few compiler warnings.
  49. *
  50. * v1.3 Feb 04, 2000 - Fixed the remaining HZ issues.
  51. * - Removed call to pci_present().
  52. * - Removed SA_INTERRUPT flag from irq handler.
  53. * - Added __init and __initdata to reduce resisdent
  54. * code size.
  55. * - Driver now uses module_init/module_exit.
  56. * - Rewrote init_module and tlan_probe to
  57. * share a lot more code. We now use tlan_probe
  58. * with builtin and module driver.
  59. * - Driver ported to new net API.
  60. * - tlan.txt has been reworked to reflect current
  61. * driver (almost)
  62. * - Other minor stuff
  63. *
  64. * v1.4 Feb 10, 2000 - Updated with more changes required after Dave's
  65. * network cleanup in 2.3.43pre7 (Tigran & myself)
  66. * - Minor stuff.
  67. *
  68. * v1.5 March 22, 2000 - Fixed another timer bug that would hang the driver
  69. * if no cable/link were present.
  70. * - Cosmetic changes.
  71. * - TODO: Port completely to new PCI/DMA API
  72. * Auto-Neg fallback.
  73. *
  74. * v1.6 April 04, 2000 - Fixed driver support for kernel-parameters. Haven't
  75. * tested it though, as the kernel support is currently
  76. * broken (2.3.99p4p3).
  77. * - Updated tlan.txt accordingly.
  78. * - Adjusted minimum/maximum frame length.
  79. * - There is now a TLAN website up at
  80. * http://tlan.kernel.dk
  81. *
  82. * v1.7 April 07, 2000 - Started to implement custom ioctls. Driver now
  83. * reports PHY information when used with Donald
  84. * Beckers userspace MII diagnostics utility.
  85. *
  86. * v1.8 April 23, 2000 - Fixed support for forced speed/duplex settings.
  87. * - Added link information to Auto-Neg and forced
  88. * modes. When NIC operates with auto-neg the driver
  89. * will report Link speed & duplex modes as well as
  90. * link partner abilities. When forced link is used,
  91. * the driver will report status of the established
  92. * link.
  93. * Please read tlan.txt for additional information.
  94. * - Removed call to check_region(), and used
  95. * return value of request_region() instead.
  96. *
  97. * v1.8a May 28, 2000 - Minor updates.
  98. *
  99. * v1.9 July 25, 2000 - Fixed a few remaining Full-Duplex issues.
  100. * - Updated with timer fixes from Andrew Morton.
  101. * - Fixed module race in TLan_Open.
  102. * - Added routine to monitor PHY status.
  103. * - Added activity led support for Proliant devices.
  104. *
  105. * v1.10 Aug 30, 2000 - Added support for EISA based tlan controllers
  106. * like the Compaq NetFlex3/E.
  107. * - Rewrote tlan_probe to better handle multiple
  108. * bus probes. Probing and device setup is now
  109. * done through TLan_Probe and TLan_init_one. Actual
  110. * hardware probe is done with kernel API and
  111. * TLan_EisaProbe.
  112. * - Adjusted debug information for probing.
  113. * - Fixed bug that would cause general debug information
  114. * to be printed after driver removal.
  115. * - Added transmit timeout handling.
  116. * - Fixed OOM return values in tlan_probe.
  117. * - Fixed possible mem leak in tlan_exit
  118. * (now tlan_remove_one).
  119. * - Fixed timer bug in TLan_phyMonitor.
  120. * - This driver version is alpha quality, please
  121. * send me any bug issues you may encounter.
  122. *
  123. * v1.11 Aug 31, 2000 - Do not try to register irq 0 if no irq line was
  124. * set for EISA cards.
  125. * - Added support for NetFlex3/E with nibble-rate
  126. * 10Base-T PHY. This is untestet as I haven't got
  127. * one of these cards.
  128. * - Fixed timer being added twice.
  129. * - Disabled PhyMonitoring by default as this is
  130. * work in progress. Define MONITOR to enable it.
  131. * - Now we don't display link info with PHYs that
  132. * doesn't support it (level1).
  133. * - Incresed tx_timeout beacuse of auto-neg.
  134. * - Adjusted timers for forced speeds.
  135. *
  136. * v1.12 Oct 12, 2000 - Minor fixes (memleak, init, etc.)
  137. *
  138. * v1.13 Nov 28, 2000 - Stop flooding console with auto-neg issues
  139. * when link can't be established.
  140. * - Added the bbuf option as a kernel parameter.
  141. * - Fixed ioaddr probe bug.
  142. * - Fixed stupid deadlock with MII interrupts.
  143. * - Added support for speed/duplex selection with
  144. * multiple nics.
  145. * - Added partly fix for TX Channel lockup with
  146. * TLAN v1.0 silicon. This needs to be investigated
  147. * further.
  148. *
  149. * v1.14 Dec 16, 2000 - Added support for servicing multiple frames per.
  150. * interrupt. Thanks goes to
  151. * Adam Keys <adam@ti.com>
  152. * Denis Beaudoin <dbeaudoin@ti.com>
  153. * for providing the patch.
  154. * - Fixed auto-neg output when using multiple
  155. * adapters.
  156. * - Converted to use new taskq interface.
  157. *
  158. * v1.14a Jan 6, 2001 - Minor adjustments (spinlocks, etc.)
  159. *
  160. * Samuel Chessman <chessman@tux.org> New Maintainer!
  161. *
  162. * v1.15 Apr 4, 2002 - Correct operation when aui=1 to be
  163. * 10T half duplex no loopback
  164. * Thanks to Gunnar Eikman
  165. *******************************************************************************/
  166. #include <linux/module.h>
  167. #include <linux/init.h>
  168. #include <linux/ioport.h>
  169. #include <linux/eisa.h>
  170. #include <linux/pci.h>
  171. #include <linux/dma-mapping.h>
  172. #include <linux/netdevice.h>
  173. #include <linux/etherdevice.h>
  174. #include <linux/delay.h>
  175. #include <linux/spinlock.h>
  176. #include <linux/workqueue.h>
  177. #include <linux/mii.h>
  178. #include "tlan.h"
  179. typedef u32 (TLanIntVectorFunc)( struct net_device *, u16 );
  180. /* For removing EISA devices */
  181. static struct net_device *TLan_Eisa_Devices;
  182. static int TLanDevicesInstalled;
  183. /* Set speed, duplex and aui settings */
  184. static int aui[MAX_TLAN_BOARDS];
  185. static int duplex[MAX_TLAN_BOARDS];
  186. static int speed[MAX_TLAN_BOARDS];
  187. static int boards_found;
  188. module_param_array(aui, int, NULL, 0);
  189. module_param_array(duplex, int, NULL, 0);
  190. module_param_array(speed, int, NULL, 0);
  191. MODULE_PARM_DESC(aui, "ThunderLAN use AUI port(s) (0-1)");
  192. MODULE_PARM_DESC(duplex, "ThunderLAN duplex setting(s) (0-default, 1-half, 2-full)");
  193. MODULE_PARM_DESC(speed, "ThunderLAN port speen setting(s) (0,10,100)");
  194. MODULE_AUTHOR("Maintainer: Samuel Chessman <chessman@tux.org>");
  195. MODULE_DESCRIPTION("Driver for TI ThunderLAN based ethernet PCI adapters");
  196. MODULE_LICENSE("GPL");
  197. /* Define this to enable Link beat monitoring */
  198. #undef MONITOR
  199. /* Turn on debugging. See Documentation/networking/tlan.txt for details */
  200. static int debug;
  201. module_param(debug, int, 0);
  202. MODULE_PARM_DESC(debug, "ThunderLAN debug mask");
  203. static int bbuf;
  204. module_param(bbuf, int, 0);
  205. MODULE_PARM_DESC(bbuf, "ThunderLAN use big buffer (0-1)");
  206. static const char TLanSignature[] = "TLAN";
  207. static const char tlan_banner[] = "ThunderLAN driver v1.15\n";
  208. static int tlan_have_pci;
  209. static int tlan_have_eisa;
  210. static const char *media[] = {
  211. "10BaseT-HD ", "10BaseT-FD ","100baseTx-HD ",
  212. "100baseTx-FD", "100baseT4", NULL
  213. };
  214. static struct board {
  215. const char *deviceLabel;
  216. u32 flags;
  217. u16 addrOfs;
  218. } board_info[] = {
  219. { "Compaq Netelligent 10 T PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  220. { "Compaq Netelligent 10/100 TX PCI UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  221. { "Compaq Integrated NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
  222. { "Compaq NetFlex-3/P",
  223. TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
  224. { "Compaq NetFlex-3/P", TLAN_ADAPTER_NONE, 0x83 },
  225. { "Compaq Netelligent Integrated 10/100 TX UTP",
  226. TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  227. { "Compaq Netelligent Dual 10/100 TX PCI UTP", TLAN_ADAPTER_NONE, 0x83 },
  228. { "Compaq Netelligent 10/100 TX Embedded UTP", TLAN_ADAPTER_NONE, 0x83 },
  229. { "Olicom OC-2183/2185", TLAN_ADAPTER_USE_INTERN_10, 0x83 },
  230. { "Olicom OC-2325", TLAN_ADAPTER_UNMANAGED_PHY, 0xF8 },
  231. { "Olicom OC-2326", TLAN_ADAPTER_USE_INTERN_10, 0xF8 },
  232. { "Compaq Netelligent 10/100 TX UTP", TLAN_ADAPTER_ACTIVITY_LED, 0x83 },
  233. { "Compaq Netelligent 10 T/2 PCI UTP/Coax", TLAN_ADAPTER_NONE, 0x83 },
  234. { "Compaq NetFlex-3/E",
  235. TLAN_ADAPTER_ACTIVITY_LED | /* EISA card */
  236. TLAN_ADAPTER_UNMANAGED_PHY | TLAN_ADAPTER_BIT_RATE_PHY, 0x83 },
  237. { "Compaq NetFlex-3/E", TLAN_ADAPTER_ACTIVITY_LED, 0x83 }, /* EISA card */
  238. };
  239. static struct pci_device_id tlan_pci_tbl[] = {
  240. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL10,
  241. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  242. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100,
  243. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
  244. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3I,
  245. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
  246. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_THUNDER,
  247. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
  248. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETFLEX3B,
  249. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
  250. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100PI,
  251. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
  252. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100D,
  253. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
  254. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_NETEL100I,
  255. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
  256. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2183,
  257. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
  258. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2325,
  259. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
  260. { PCI_VENDOR_ID_OLICOM, PCI_DEVICE_ID_OLICOM_OC2326,
  261. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
  262. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_100_WS_5100,
  263. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
  264. { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_NETELLIGENT_10_T2,
  265. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
  266. { 0,}
  267. };
  268. MODULE_DEVICE_TABLE(pci, tlan_pci_tbl);
  269. static void TLan_EisaProbe( void );
  270. static void TLan_Eisa_Cleanup( void );
  271. static int TLan_Init( struct net_device * );
  272. static int TLan_Open( struct net_device *dev );
  273. static int TLan_StartTx( struct sk_buff *, struct net_device *);
  274. static irqreturn_t TLan_HandleInterrupt( int, void *);
  275. static int TLan_Close( struct net_device *);
  276. static struct net_device_stats *TLan_GetStats( struct net_device *);
  277. static void TLan_SetMulticastList( struct net_device *);
  278. static int TLan_ioctl( struct net_device *dev, struct ifreq *rq, int cmd);
  279. static int TLan_probe1( struct pci_dev *pdev, long ioaddr,
  280. int irq, int rev, const struct pci_device_id *ent);
  281. static void TLan_tx_timeout( struct net_device *dev);
  282. static void TLan_tx_timeout_work(struct work_struct *work);
  283. static int tlan_init_one( struct pci_dev *pdev, const struct pci_device_id *ent);
  284. static u32 TLan_HandleTxEOF( struct net_device *, u16 );
  285. static u32 TLan_HandleStatOverflow( struct net_device *, u16 );
  286. static u32 TLan_HandleRxEOF( struct net_device *, u16 );
  287. static u32 TLan_HandleDummy( struct net_device *, u16 );
  288. static u32 TLan_HandleTxEOC( struct net_device *, u16 );
  289. static u32 TLan_HandleStatusCheck( struct net_device *, u16 );
  290. static u32 TLan_HandleRxEOC( struct net_device *, u16 );
  291. static void TLan_Timer( unsigned long );
  292. static void TLan_ResetLists( struct net_device * );
  293. static void TLan_FreeLists( struct net_device * );
  294. static void TLan_PrintDio( u16 );
  295. static void TLan_PrintList( TLanList *, char *, int );
  296. static void TLan_ReadAndClearStats( struct net_device *, int );
  297. static void TLan_ResetAdapter( struct net_device * );
  298. static void TLan_FinishReset( struct net_device * );
  299. static void TLan_SetMac( struct net_device *, int areg, char *mac );
  300. static void TLan_PhyPrint( struct net_device * );
  301. static void TLan_PhyDetect( struct net_device * );
  302. static void TLan_PhyPowerDown( struct net_device * );
  303. static void TLan_PhyPowerUp( struct net_device * );
  304. static void TLan_PhyReset( struct net_device * );
  305. static void TLan_PhyStartLink( struct net_device * );
  306. static void TLan_PhyFinishAutoNeg( struct net_device * );
  307. #ifdef MONITOR
  308. static void TLan_PhyMonitor( struct net_device * );
  309. #endif
  310. /*
  311. static int TLan_PhyNop( struct net_device * );
  312. static int TLan_PhyInternalCheck( struct net_device * );
  313. static int TLan_PhyInternalService( struct net_device * );
  314. static int TLan_PhyDp83840aCheck( struct net_device * );
  315. */
  316. static int TLan_MiiReadReg( struct net_device *, u16, u16, u16 * );
  317. static void TLan_MiiSendData( u16, u32, unsigned );
  318. static void TLan_MiiSync( u16 );
  319. static void TLan_MiiWriteReg( struct net_device *, u16, u16, u16 );
  320. static void TLan_EeSendStart( u16 );
  321. static int TLan_EeSendByte( u16, u8, int );
  322. static void TLan_EeReceiveByte( u16, u8 *, int );
  323. static int TLan_EeReadByte( struct net_device *, u8, u8 * );
  324. static inline void
  325. TLan_StoreSKB( struct tlan_list_tag *tag, struct sk_buff *skb)
  326. {
  327. unsigned long addr = (unsigned long)skb;
  328. tag->buffer[9].address = addr;
  329. tag->buffer[8].address = upper_32_bits(addr);
  330. }
  331. static inline struct sk_buff *
  332. TLan_GetSKB( const struct tlan_list_tag *tag)
  333. {
  334. unsigned long addr;
  335. addr = tag->buffer[9].address;
  336. addr |= (tag->buffer[8].address << 16) << 16;
  337. return (struct sk_buff *) addr;
  338. }
  339. static TLanIntVectorFunc *TLanIntVector[TLAN_INT_NUMBER_OF_INTS] = {
  340. NULL,
  341. TLan_HandleTxEOF,
  342. TLan_HandleStatOverflow,
  343. TLan_HandleRxEOF,
  344. TLan_HandleDummy,
  345. TLan_HandleTxEOC,
  346. TLan_HandleStatusCheck,
  347. TLan_HandleRxEOC
  348. };
  349. static inline void
  350. TLan_SetTimer( struct net_device *dev, u32 ticks, u32 type )
  351. {
  352. TLanPrivateInfo *priv = netdev_priv(dev);
  353. unsigned long flags = 0;
  354. if (!in_irq())
  355. spin_lock_irqsave(&priv->lock, flags);
  356. if ( priv->timer.function != NULL &&
  357. priv->timerType != TLAN_TIMER_ACTIVITY ) {
  358. if (!in_irq())
  359. spin_unlock_irqrestore(&priv->lock, flags);
  360. return;
  361. }
  362. priv->timer.function = &TLan_Timer;
  363. if (!in_irq())
  364. spin_unlock_irqrestore(&priv->lock, flags);
  365. priv->timer.data = (unsigned long) dev;
  366. priv->timerSetAt = jiffies;
  367. priv->timerType = type;
  368. mod_timer(&priv->timer, jiffies + ticks);
  369. } /* TLan_SetTimer */
  370. /*****************************************************************************
  371. ******************************************************************************
  372. ThunderLAN Driver Primary Functions
  373. These functions are more or less common to all Linux network drivers.
  374. ******************************************************************************
  375. *****************************************************************************/
  376. /***************************************************************
  377. * tlan_remove_one
  378. *
  379. * Returns:
  380. * Nothing
  381. * Parms:
  382. * None
  383. *
  384. * Goes through the TLanDevices list and frees the device
  385. * structs and memory associated with each device (lists
  386. * and buffers). It also ureserves the IO port regions
  387. * associated with this device.
  388. *
  389. **************************************************************/
  390. static void __devexit tlan_remove_one( struct pci_dev *pdev)
  391. {
  392. struct net_device *dev = pci_get_drvdata( pdev );
  393. TLanPrivateInfo *priv = netdev_priv(dev);
  394. unregister_netdev( dev );
  395. if ( priv->dmaStorage ) {
  396. pci_free_consistent(priv->pciDev,
  397. priv->dmaSize, priv->dmaStorage,
  398. priv->dmaStorageDMA );
  399. }
  400. #ifdef CONFIG_PCI
  401. pci_release_regions(pdev);
  402. #endif
  403. free_netdev( dev );
  404. pci_set_drvdata( pdev, NULL );
  405. }
  406. static struct pci_driver tlan_driver = {
  407. .name = "tlan",
  408. .id_table = tlan_pci_tbl,
  409. .probe = tlan_init_one,
  410. .remove = __devexit_p(tlan_remove_one),
  411. };
  412. static int __init tlan_probe(void)
  413. {
  414. int rc = -ENODEV;
  415. printk(KERN_INFO "%s", tlan_banner);
  416. TLAN_DBG(TLAN_DEBUG_PROBE, "Starting PCI Probe....\n");
  417. /* Use new style PCI probing. Now the kernel will
  418. do most of this for us */
  419. rc = pci_register_driver(&tlan_driver);
  420. if (rc != 0) {
  421. printk(KERN_ERR "TLAN: Could not register pci driver.\n");
  422. goto err_out_pci_free;
  423. }
  424. TLAN_DBG(TLAN_DEBUG_PROBE, "Starting EISA Probe....\n");
  425. TLan_EisaProbe();
  426. printk(KERN_INFO "TLAN: %d device%s installed, PCI: %d EISA: %d\n",
  427. TLanDevicesInstalled, TLanDevicesInstalled == 1 ? "" : "s",
  428. tlan_have_pci, tlan_have_eisa);
  429. if (TLanDevicesInstalled == 0) {
  430. rc = -ENODEV;
  431. goto err_out_pci_unreg;
  432. }
  433. return 0;
  434. err_out_pci_unreg:
  435. pci_unregister_driver(&tlan_driver);
  436. err_out_pci_free:
  437. return rc;
  438. }
  439. static int __devinit tlan_init_one( struct pci_dev *pdev,
  440. const struct pci_device_id *ent)
  441. {
  442. return TLan_probe1( pdev, -1, -1, 0, ent);
  443. }
  444. /*
  445. ***************************************************************
  446. * tlan_probe1
  447. *
  448. * Returns:
  449. * 0 on success, error code on error
  450. * Parms:
  451. * none
  452. *
  453. * The name is lower case to fit in with all the rest of
  454. * the netcard_probe names. This function looks for
  455. * another TLan based adapter, setting it up with the
  456. * allocated device struct if one is found.
  457. * tlan_probe has been ported to the new net API and
  458. * now allocates its own device structure. This function
  459. * is also used by modules.
  460. *
  461. **************************************************************/
  462. static int __devinit TLan_probe1(struct pci_dev *pdev,
  463. long ioaddr, int irq, int rev,
  464. const struct pci_device_id *ent )
  465. {
  466. struct net_device *dev;
  467. TLanPrivateInfo *priv;
  468. u16 device_id;
  469. int reg, rc = -ENODEV;
  470. #ifdef CONFIG_PCI
  471. if (pdev) {
  472. rc = pci_enable_device(pdev);
  473. if (rc)
  474. return rc;
  475. rc = pci_request_regions(pdev, TLanSignature);
  476. if (rc) {
  477. printk(KERN_ERR "TLAN: Could not reserve IO regions\n");
  478. goto err_out;
  479. }
  480. }
  481. #endif /* CONFIG_PCI */
  482. dev = alloc_etherdev(sizeof(TLanPrivateInfo));
  483. if (dev == NULL) {
  484. printk(KERN_ERR "TLAN: Could not allocate memory for device.\n");
  485. rc = -ENOMEM;
  486. goto err_out_regions;
  487. }
  488. SET_NETDEV_DEV(dev, &pdev->dev);
  489. priv = netdev_priv(dev);
  490. priv->pciDev = pdev;
  491. priv->dev = dev;
  492. /* Is this a PCI device? */
  493. if (pdev) {
  494. u32 pci_io_base = 0;
  495. priv->adapter = &board_info[ent->driver_data];
  496. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  497. if (rc) {
  498. printk(KERN_ERR "TLAN: No suitable PCI mapping available.\n");
  499. goto err_out_free_dev;
  500. }
  501. for ( reg= 0; reg <= 5; reg ++ ) {
  502. if (pci_resource_flags(pdev, reg) & IORESOURCE_IO) {
  503. pci_io_base = pci_resource_start(pdev, reg);
  504. TLAN_DBG( TLAN_DEBUG_GNRL, "IO mapping is available at %x.\n",
  505. pci_io_base);
  506. break;
  507. }
  508. }
  509. if (!pci_io_base) {
  510. printk(KERN_ERR "TLAN: No IO mappings available\n");
  511. rc = -EIO;
  512. goto err_out_free_dev;
  513. }
  514. dev->base_addr = pci_io_base;
  515. dev->irq = pdev->irq;
  516. priv->adapterRev = pdev->revision;
  517. pci_set_master(pdev);
  518. pci_set_drvdata(pdev, dev);
  519. } else { /* EISA card */
  520. /* This is a hack. We need to know which board structure
  521. * is suited for this adapter */
  522. device_id = inw(ioaddr + EISA_ID2);
  523. priv->is_eisa = 1;
  524. if (device_id == 0x20F1) {
  525. priv->adapter = &board_info[13]; /* NetFlex-3/E */
  526. priv->adapterRev = 23; /* TLAN 2.3 */
  527. } else {
  528. priv->adapter = &board_info[14];
  529. priv->adapterRev = 10; /* TLAN 1.0 */
  530. }
  531. dev->base_addr = ioaddr;
  532. dev->irq = irq;
  533. }
  534. /* Kernel parameters */
  535. if (dev->mem_start) {
  536. priv->aui = dev->mem_start & 0x01;
  537. priv->duplex = ((dev->mem_start & 0x06) == 0x06) ? 0
  538. : (dev->mem_start & 0x06) >> 1;
  539. priv->speed = ((dev->mem_start & 0x18) == 0x18) ? 0
  540. : (dev->mem_start & 0x18) >> 3;
  541. if (priv->speed == 0x1) {
  542. priv->speed = TLAN_SPEED_10;
  543. } else if (priv->speed == 0x2) {
  544. priv->speed = TLAN_SPEED_100;
  545. }
  546. debug = priv->debug = dev->mem_end;
  547. } else {
  548. priv->aui = aui[boards_found];
  549. priv->speed = speed[boards_found];
  550. priv->duplex = duplex[boards_found];
  551. priv->debug = debug;
  552. }
  553. /* This will be used when we get an adapter error from
  554. * within our irq handler */
  555. INIT_WORK(&priv->tlan_tqueue, TLan_tx_timeout_work);
  556. spin_lock_init(&priv->lock);
  557. rc = TLan_Init(dev);
  558. if (rc) {
  559. printk(KERN_ERR "TLAN: Could not set up device.\n");
  560. goto err_out_free_dev;
  561. }
  562. rc = register_netdev(dev);
  563. if (rc) {
  564. printk(KERN_ERR "TLAN: Could not register device.\n");
  565. goto err_out_uninit;
  566. }
  567. TLanDevicesInstalled++;
  568. boards_found++;
  569. /* pdev is NULL if this is an EISA device */
  570. if (pdev)
  571. tlan_have_pci++;
  572. else {
  573. priv->nextDevice = TLan_Eisa_Devices;
  574. TLan_Eisa_Devices = dev;
  575. tlan_have_eisa++;
  576. }
  577. printk(KERN_INFO "TLAN: %s irq=%2d, io=%04x, %s, Rev. %d\n",
  578. dev->name,
  579. (int) dev->irq,
  580. (int) dev->base_addr,
  581. priv->adapter->deviceLabel,
  582. priv->adapterRev);
  583. return 0;
  584. err_out_uninit:
  585. pci_free_consistent(priv->pciDev, priv->dmaSize, priv->dmaStorage,
  586. priv->dmaStorageDMA );
  587. err_out_free_dev:
  588. free_netdev(dev);
  589. err_out_regions:
  590. #ifdef CONFIG_PCI
  591. if (pdev)
  592. pci_release_regions(pdev);
  593. #endif
  594. err_out:
  595. if (pdev)
  596. pci_disable_device(pdev);
  597. return rc;
  598. }
  599. static void TLan_Eisa_Cleanup(void)
  600. {
  601. struct net_device *dev;
  602. TLanPrivateInfo *priv;
  603. while( tlan_have_eisa ) {
  604. dev = TLan_Eisa_Devices;
  605. priv = netdev_priv(dev);
  606. if (priv->dmaStorage) {
  607. pci_free_consistent(priv->pciDev, priv->dmaSize,
  608. priv->dmaStorage, priv->dmaStorageDMA );
  609. }
  610. release_region( dev->base_addr, 0x10);
  611. unregister_netdev( dev );
  612. TLan_Eisa_Devices = priv->nextDevice;
  613. free_netdev( dev );
  614. tlan_have_eisa--;
  615. }
  616. }
  617. static void __exit tlan_exit(void)
  618. {
  619. pci_unregister_driver(&tlan_driver);
  620. if (tlan_have_eisa)
  621. TLan_Eisa_Cleanup();
  622. }
  623. /* Module loading/unloading */
  624. module_init(tlan_probe);
  625. module_exit(tlan_exit);
  626. /**************************************************************
  627. * TLan_EisaProbe
  628. *
  629. * Returns: 0 on success, 1 otherwise
  630. *
  631. * Parms: None
  632. *
  633. *
  634. * This functions probes for EISA devices and calls
  635. * TLan_probe1 when one is found.
  636. *
  637. *************************************************************/
  638. static void __init TLan_EisaProbe (void)
  639. {
  640. long ioaddr;
  641. int rc = -ENODEV;
  642. int irq;
  643. u16 device_id;
  644. if (!EISA_bus) {
  645. TLAN_DBG(TLAN_DEBUG_PROBE, "No EISA bus present\n");
  646. return;
  647. }
  648. /* Loop through all slots of the EISA bus */
  649. for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
  650. TLAN_DBG(TLAN_DEBUG_PROBE,"EISA_ID 0x%4x: 0x%4x\n",
  651. (int) ioaddr + 0xC80, inw(ioaddr + EISA_ID));
  652. TLAN_DBG(TLAN_DEBUG_PROBE,"EISA_ID 0x%4x: 0x%4x\n",
  653. (int) ioaddr + 0xC82, inw(ioaddr + EISA_ID2));
  654. TLAN_DBG(TLAN_DEBUG_PROBE, "Probing for EISA adapter at IO: 0x%4x : ",
  655. (int) ioaddr);
  656. if (request_region(ioaddr, 0x10, TLanSignature) == NULL)
  657. goto out;
  658. if (inw(ioaddr + EISA_ID) != 0x110E) {
  659. release_region(ioaddr, 0x10);
  660. goto out;
  661. }
  662. device_id = inw(ioaddr + EISA_ID2);
  663. if (device_id != 0x20F1 && device_id != 0x40F1) {
  664. release_region (ioaddr, 0x10);
  665. goto out;
  666. }
  667. if (inb(ioaddr + EISA_CR) != 0x1) { /* Check if adapter is enabled */
  668. release_region (ioaddr, 0x10);
  669. goto out2;
  670. }
  671. if (debug == 0x10)
  672. printk("Found one\n");
  673. /* Get irq from board */
  674. switch (inb(ioaddr + 0xCC0)) {
  675. case(0x10):
  676. irq=5;
  677. break;
  678. case(0x20):
  679. irq=9;
  680. break;
  681. case(0x40):
  682. irq=10;
  683. break;
  684. case(0x80):
  685. irq=11;
  686. break;
  687. default:
  688. goto out;
  689. }
  690. /* Setup the newly found eisa adapter */
  691. rc = TLan_probe1( NULL, ioaddr, irq,
  692. 12, NULL);
  693. continue;
  694. out:
  695. if (debug == 0x10)
  696. printk("None found\n");
  697. continue;
  698. out2: if (debug == 0x10)
  699. printk("Card found but it is not enabled, skipping\n");
  700. continue;
  701. }
  702. } /* TLan_EisaProbe */
  703. #ifdef CONFIG_NET_POLL_CONTROLLER
  704. static void TLan_Poll(struct net_device *dev)
  705. {
  706. disable_irq(dev->irq);
  707. TLan_HandleInterrupt(dev->irq, dev);
  708. enable_irq(dev->irq);
  709. }
  710. #endif
  711. /***************************************************************
  712. * TLan_Init
  713. *
  714. * Returns:
  715. * 0 on success, error code otherwise.
  716. * Parms:
  717. * dev The structure of the device to be
  718. * init'ed.
  719. *
  720. * This function completes the initialization of the
  721. * device structure and driver. It reserves the IO
  722. * addresses, allocates memory for the lists and bounce
  723. * buffers, retrieves the MAC address from the eeprom
  724. * and assignes the device's methods.
  725. *
  726. **************************************************************/
  727. static int TLan_Init( struct net_device *dev )
  728. {
  729. int dma_size;
  730. int err;
  731. int i;
  732. TLanPrivateInfo *priv;
  733. priv = netdev_priv(dev);
  734. if ( bbuf ) {
  735. dma_size = ( TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS )
  736. * ( sizeof(TLanList) + TLAN_MAX_FRAME_SIZE );
  737. } else {
  738. dma_size = ( TLAN_NUM_RX_LISTS + TLAN_NUM_TX_LISTS )
  739. * ( sizeof(TLanList) );
  740. }
  741. priv->dmaStorage = pci_alloc_consistent(priv->pciDev,
  742. dma_size, &priv->dmaStorageDMA);
  743. priv->dmaSize = dma_size;
  744. if ( priv->dmaStorage == NULL ) {
  745. printk(KERN_ERR "TLAN: Could not allocate lists and buffers for %s.\n",
  746. dev->name );
  747. return -ENOMEM;
  748. }
  749. memset( priv->dmaStorage, 0, dma_size );
  750. priv->rxList = (TLanList *) ALIGN((unsigned long)priv->dmaStorage, 8);
  751. priv->rxListDMA = ALIGN(priv->dmaStorageDMA, 8);
  752. priv->txList = priv->rxList + TLAN_NUM_RX_LISTS;
  753. priv->txListDMA = priv->rxListDMA + sizeof(TLanList) * TLAN_NUM_RX_LISTS;
  754. if ( bbuf ) {
  755. priv->rxBuffer = (u8 *) ( priv->txList + TLAN_NUM_TX_LISTS );
  756. priv->rxBufferDMA =priv->txListDMA
  757. + sizeof(TLanList) * TLAN_NUM_TX_LISTS;
  758. priv->txBuffer = priv->rxBuffer
  759. + ( TLAN_NUM_RX_LISTS * TLAN_MAX_FRAME_SIZE );
  760. priv->txBufferDMA = priv->rxBufferDMA
  761. + ( TLAN_NUM_RX_LISTS * TLAN_MAX_FRAME_SIZE );
  762. }
  763. err = 0;
  764. for ( i = 0; i < 6 ; i++ )
  765. err |= TLan_EeReadByte( dev,
  766. (u8) priv->adapter->addrOfs + i,
  767. (u8 *) &dev->dev_addr[i] );
  768. if ( err ) {
  769. printk(KERN_ERR "TLAN: %s: Error reading MAC from eeprom: %d\n",
  770. dev->name,
  771. err );
  772. }
  773. dev->addr_len = 6;
  774. netif_carrier_off(dev);
  775. /* Device methods */
  776. dev->open = &TLan_Open;
  777. dev->hard_start_xmit = &TLan_StartTx;
  778. dev->stop = &TLan_Close;
  779. dev->get_stats = &TLan_GetStats;
  780. dev->set_multicast_list = &TLan_SetMulticastList;
  781. dev->do_ioctl = &TLan_ioctl;
  782. #ifdef CONFIG_NET_POLL_CONTROLLER
  783. dev->poll_controller = &TLan_Poll;
  784. #endif
  785. dev->tx_timeout = &TLan_tx_timeout;
  786. dev->watchdog_timeo = TX_TIMEOUT;
  787. return 0;
  788. } /* TLan_Init */
  789. /***************************************************************
  790. * TLan_Open
  791. *
  792. * Returns:
  793. * 0 on success, error code otherwise.
  794. * Parms:
  795. * dev Structure of device to be opened.
  796. *
  797. * This routine puts the driver and TLAN adapter in a
  798. * state where it is ready to send and receive packets.
  799. * It allocates the IRQ, resets and brings the adapter
  800. * out of reset, and allows interrupts. It also delays
  801. * the startup for autonegotiation or sends a Rx GO
  802. * command to the adapter, as appropriate.
  803. *
  804. **************************************************************/
  805. static int TLan_Open( struct net_device *dev )
  806. {
  807. TLanPrivateInfo *priv = netdev_priv(dev);
  808. int err;
  809. priv->tlanRev = TLan_DioRead8( dev->base_addr, TLAN_DEF_REVISION );
  810. err = request_irq( dev->irq, TLan_HandleInterrupt, IRQF_SHARED,
  811. dev->name, dev );
  812. if ( err ) {
  813. pr_err("TLAN: Cannot open %s because IRQ %d is already in use.\n",
  814. dev->name, dev->irq );
  815. return err;
  816. }
  817. init_timer(&priv->timer);
  818. netif_start_queue(dev);
  819. /* NOTE: It might not be necessary to read the stats before a
  820. reset if you don't care what the values are.
  821. */
  822. TLan_ResetLists( dev );
  823. TLan_ReadAndClearStats( dev, TLAN_IGNORE );
  824. TLan_ResetAdapter( dev );
  825. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Opened. TLAN Chip Rev: %x\n",
  826. dev->name, priv->tlanRev );
  827. return 0;
  828. } /* TLan_Open */
  829. /**************************************************************
  830. * TLan_ioctl
  831. *
  832. * Returns:
  833. * 0 on success, error code otherwise
  834. * Params:
  835. * dev structure of device to receive ioctl.
  836. *
  837. * rq ifreq structure to hold userspace data.
  838. *
  839. * cmd ioctl command.
  840. *
  841. *
  842. *************************************************************/
  843. static int TLan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  844. {
  845. TLanPrivateInfo *priv = netdev_priv(dev);
  846. struct mii_ioctl_data *data = if_mii(rq);
  847. u32 phy = priv->phy[priv->phyNum];
  848. if (!priv->phyOnline)
  849. return -EAGAIN;
  850. switch(cmd) {
  851. case SIOCGMIIPHY: /* Get address of MII PHY in use. */
  852. data->phy_id = phy;
  853. case SIOCGMIIREG: /* Read MII PHY register. */
  854. TLan_MiiReadReg(dev, data->phy_id & 0x1f,
  855. data->reg_num & 0x1f, &data->val_out);
  856. return 0;
  857. case SIOCSMIIREG: /* Write MII PHY register. */
  858. if (!capable(CAP_NET_ADMIN))
  859. return -EPERM;
  860. TLan_MiiWriteReg(dev, data->phy_id & 0x1f,
  861. data->reg_num & 0x1f, data->val_in);
  862. return 0;
  863. default:
  864. return -EOPNOTSUPP;
  865. }
  866. } /* tlan_ioctl */
  867. /***************************************************************
  868. * TLan_tx_timeout
  869. *
  870. * Returns: nothing
  871. *
  872. * Params:
  873. * dev structure of device which timed out
  874. * during transmit.
  875. *
  876. **************************************************************/
  877. static void TLan_tx_timeout(struct net_device *dev)
  878. {
  879. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Transmit timed out.\n", dev->name);
  880. /* Ok so we timed out, lets see what we can do about it...*/
  881. TLan_FreeLists( dev );
  882. TLan_ResetLists( dev );
  883. TLan_ReadAndClearStats( dev, TLAN_IGNORE );
  884. TLan_ResetAdapter( dev );
  885. dev->trans_start = jiffies;
  886. netif_wake_queue( dev );
  887. }
  888. /***************************************************************
  889. * TLan_tx_timeout_work
  890. *
  891. * Returns: nothing
  892. *
  893. * Params:
  894. * work work item of device which timed out
  895. *
  896. **************************************************************/
  897. static void TLan_tx_timeout_work(struct work_struct *work)
  898. {
  899. TLanPrivateInfo *priv =
  900. container_of(work, TLanPrivateInfo, tlan_tqueue);
  901. TLan_tx_timeout(priv->dev);
  902. }
  903. /***************************************************************
  904. * TLan_StartTx
  905. *
  906. * Returns:
  907. * 0 on success, non-zero on failure.
  908. * Parms:
  909. * skb A pointer to the sk_buff containing the
  910. * frame to be sent.
  911. * dev The device to send the data on.
  912. *
  913. * This function adds a frame to the Tx list to be sent
  914. * ASAP. First it verifies that the adapter is ready and
  915. * there is room in the queue. Then it sets up the next
  916. * available list, copies the frame to the corresponding
  917. * buffer. If the adapter Tx channel is idle, it gives
  918. * the adapter a Tx Go command on the list, otherwise it
  919. * sets the forward address of the previous list to point
  920. * to this one. Then it frees the sk_buff.
  921. *
  922. **************************************************************/
  923. static int TLan_StartTx( struct sk_buff *skb, struct net_device *dev )
  924. {
  925. TLanPrivateInfo *priv = netdev_priv(dev);
  926. TLanList *tail_list;
  927. dma_addr_t tail_list_phys;
  928. u8 *tail_buffer;
  929. unsigned long flags;
  930. if ( ! priv->phyOnline ) {
  931. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s PHY is not ready\n",
  932. dev->name );
  933. dev_kfree_skb_any(skb);
  934. return 0;
  935. }
  936. if (skb_padto(skb, TLAN_MIN_FRAME_SIZE))
  937. return 0;
  938. tail_list = priv->txList + priv->txTail;
  939. tail_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txTail;
  940. if ( tail_list->cStat != TLAN_CSTAT_UNUSED ) {
  941. TLAN_DBG( TLAN_DEBUG_TX,
  942. "TRANSMIT: %s is busy (Head=%d Tail=%d)\n",
  943. dev->name, priv->txHead, priv->txTail );
  944. netif_stop_queue(dev);
  945. priv->txBusyCount++;
  946. return 1;
  947. }
  948. tail_list->forward = 0;
  949. if ( bbuf ) {
  950. tail_buffer = priv->txBuffer + ( priv->txTail * TLAN_MAX_FRAME_SIZE );
  951. skb_copy_from_linear_data(skb, tail_buffer, skb->len);
  952. } else {
  953. tail_list->buffer[0].address = pci_map_single(priv->pciDev,
  954. skb->data, skb->len,
  955. PCI_DMA_TODEVICE);
  956. TLan_StoreSKB(tail_list, skb);
  957. }
  958. tail_list->frameSize = (u16) skb->len;
  959. tail_list->buffer[0].count = TLAN_LAST_BUFFER | (u32) skb->len;
  960. tail_list->buffer[1].count = 0;
  961. tail_list->buffer[1].address = 0;
  962. spin_lock_irqsave(&priv->lock, flags);
  963. tail_list->cStat = TLAN_CSTAT_READY;
  964. if ( ! priv->txInProgress ) {
  965. priv->txInProgress = 1;
  966. TLAN_DBG( TLAN_DEBUG_TX,
  967. "TRANSMIT: Starting TX on buffer %d\n", priv->txTail );
  968. outl( tail_list_phys, dev->base_addr + TLAN_CH_PARM );
  969. outl( TLAN_HC_GO, dev->base_addr + TLAN_HOST_CMD );
  970. } else {
  971. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Adding buffer %d to TX channel\n",
  972. priv->txTail );
  973. if ( priv->txTail == 0 ) {
  974. ( priv->txList + ( TLAN_NUM_TX_LISTS - 1 ) )->forward
  975. = tail_list_phys;
  976. } else {
  977. ( priv->txList + ( priv->txTail - 1 ) )->forward
  978. = tail_list_phys;
  979. }
  980. }
  981. spin_unlock_irqrestore(&priv->lock, flags);
  982. CIRC_INC( priv->txTail, TLAN_NUM_TX_LISTS );
  983. if ( bbuf )
  984. dev_kfree_skb_any(skb);
  985. dev->trans_start = jiffies;
  986. return 0;
  987. } /* TLan_StartTx */
  988. /***************************************************************
  989. * TLan_HandleInterrupt
  990. *
  991. * Returns:
  992. * Nothing
  993. * Parms:
  994. * irq The line on which the interrupt
  995. * occurred.
  996. * dev_id A pointer to the device assigned to
  997. * this irq line.
  998. *
  999. * This function handles an interrupt generated by its
  1000. * assigned TLAN adapter. The function deactivates
  1001. * interrupts on its adapter, records the type of
  1002. * interrupt, executes the appropriate subhandler, and
  1003. * acknowdges the interrupt to the adapter (thus
  1004. * re-enabling adapter interrupts.
  1005. *
  1006. **************************************************************/
  1007. static irqreturn_t TLan_HandleInterrupt(int irq, void *dev_id)
  1008. {
  1009. struct net_device *dev = dev_id;
  1010. TLanPrivateInfo *priv = netdev_priv(dev);
  1011. u16 host_int;
  1012. u16 type;
  1013. spin_lock(&priv->lock);
  1014. host_int = inw( dev->base_addr + TLAN_HOST_INT );
  1015. type = ( host_int & TLAN_HI_IT_MASK ) >> 2;
  1016. if ( type ) {
  1017. u32 ack;
  1018. u32 host_cmd;
  1019. outw( host_int, dev->base_addr + TLAN_HOST_INT );
  1020. ack = TLanIntVector[type]( dev, host_int );
  1021. if ( ack ) {
  1022. host_cmd = TLAN_HC_ACK | ack | ( type << 18 );
  1023. outl( host_cmd, dev->base_addr + TLAN_HOST_CMD );
  1024. }
  1025. }
  1026. spin_unlock(&priv->lock);
  1027. return IRQ_RETVAL(type);
  1028. } /* TLan_HandleInterrupts */
  1029. /***************************************************************
  1030. * TLan_Close
  1031. *
  1032. * Returns:
  1033. * An error code.
  1034. * Parms:
  1035. * dev The device structure of the device to
  1036. * close.
  1037. *
  1038. * This function shuts down the adapter. It records any
  1039. * stats, puts the adapter into reset state, deactivates
  1040. * its time as needed, and frees the irq it is using.
  1041. *
  1042. **************************************************************/
  1043. static int TLan_Close(struct net_device *dev)
  1044. {
  1045. TLanPrivateInfo *priv = netdev_priv(dev);
  1046. netif_stop_queue(dev);
  1047. priv->neg_be_verbose = 0;
  1048. TLan_ReadAndClearStats( dev, TLAN_RECORD );
  1049. outl( TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD );
  1050. if ( priv->timer.function != NULL ) {
  1051. del_timer_sync( &priv->timer );
  1052. priv->timer.function = NULL;
  1053. }
  1054. free_irq( dev->irq, dev );
  1055. TLan_FreeLists( dev );
  1056. TLAN_DBG( TLAN_DEBUG_GNRL, "Device %s closed.\n", dev->name );
  1057. return 0;
  1058. } /* TLan_Close */
  1059. /***************************************************************
  1060. * TLan_GetStats
  1061. *
  1062. * Returns:
  1063. * A pointer to the device's statistics structure.
  1064. * Parms:
  1065. * dev The device structure to return the
  1066. * stats for.
  1067. *
  1068. * This function updates the devices statistics by reading
  1069. * the TLAN chip's onboard registers. Then it returns the
  1070. * address of the statistics structure.
  1071. *
  1072. **************************************************************/
  1073. static struct net_device_stats *TLan_GetStats( struct net_device *dev )
  1074. {
  1075. TLanPrivateInfo *priv = netdev_priv(dev);
  1076. int i;
  1077. /* Should only read stats if open ? */
  1078. TLan_ReadAndClearStats( dev, TLAN_RECORD );
  1079. TLAN_DBG( TLAN_DEBUG_RX, "RECEIVE: %s EOC count = %d\n", dev->name,
  1080. priv->rxEocCount );
  1081. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: %s Busy count = %d\n", dev->name,
  1082. priv->txBusyCount );
  1083. if ( debug & TLAN_DEBUG_GNRL ) {
  1084. TLan_PrintDio( dev->base_addr );
  1085. TLan_PhyPrint( dev );
  1086. }
  1087. if ( debug & TLAN_DEBUG_LIST ) {
  1088. for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ )
  1089. TLan_PrintList( priv->rxList + i, "RX", i );
  1090. for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ )
  1091. TLan_PrintList( priv->txList + i, "TX", i );
  1092. }
  1093. return &dev->stats;
  1094. } /* TLan_GetStats */
  1095. /***************************************************************
  1096. * TLan_SetMulticastList
  1097. *
  1098. * Returns:
  1099. * Nothing
  1100. * Parms:
  1101. * dev The device structure to set the
  1102. * multicast list for.
  1103. *
  1104. * This function sets the TLAN adaptor to various receive
  1105. * modes. If the IFF_PROMISC flag is set, promiscuous
  1106. * mode is acitviated. Otherwise, promiscuous mode is
  1107. * turned off. If the IFF_ALLMULTI flag is set, then
  1108. * the hash table is set to receive all group addresses.
  1109. * Otherwise, the first three multicast addresses are
  1110. * stored in AREG_1-3, and the rest are selected via the
  1111. * hash table, as necessary.
  1112. *
  1113. **************************************************************/
  1114. static void TLan_SetMulticastList( struct net_device *dev )
  1115. {
  1116. struct dev_mc_list *dmi = dev->mc_list;
  1117. u32 hash1 = 0;
  1118. u32 hash2 = 0;
  1119. int i;
  1120. u32 offset;
  1121. u8 tmp;
  1122. if ( dev->flags & IFF_PROMISC ) {
  1123. tmp = TLan_DioRead8( dev->base_addr, TLAN_NET_CMD );
  1124. TLan_DioWrite8( dev->base_addr,
  1125. TLAN_NET_CMD, tmp | TLAN_NET_CMD_CAF );
  1126. } else {
  1127. tmp = TLan_DioRead8( dev->base_addr, TLAN_NET_CMD );
  1128. TLan_DioWrite8( dev->base_addr,
  1129. TLAN_NET_CMD, tmp & ~TLAN_NET_CMD_CAF );
  1130. if ( dev->flags & IFF_ALLMULTI ) {
  1131. for ( i = 0; i < 3; i++ )
  1132. TLan_SetMac( dev, i + 1, NULL );
  1133. TLan_DioWrite32( dev->base_addr, TLAN_HASH_1, 0xFFFFFFFF );
  1134. TLan_DioWrite32( dev->base_addr, TLAN_HASH_2, 0xFFFFFFFF );
  1135. } else {
  1136. for ( i = 0; i < dev->mc_count; i++ ) {
  1137. if ( i < 3 ) {
  1138. TLan_SetMac( dev, i + 1,
  1139. (char *) &dmi->dmi_addr );
  1140. } else {
  1141. offset = TLan_HashFunc( (u8 *) &dmi->dmi_addr );
  1142. if ( offset < 32 )
  1143. hash1 |= ( 1 << offset );
  1144. else
  1145. hash2 |= ( 1 << ( offset - 32 ) );
  1146. }
  1147. dmi = dmi->next;
  1148. }
  1149. for ( ; i < 3; i++ )
  1150. TLan_SetMac( dev, i + 1, NULL );
  1151. TLan_DioWrite32( dev->base_addr, TLAN_HASH_1, hash1 );
  1152. TLan_DioWrite32( dev->base_addr, TLAN_HASH_2, hash2 );
  1153. }
  1154. }
  1155. } /* TLan_SetMulticastList */
  1156. /*****************************************************************************
  1157. ******************************************************************************
  1158. ThunderLAN Driver Interrupt Vectors and Table
  1159. Please see Chap. 4, "Interrupt Handling" of the "ThunderLAN
  1160. Programmer's Guide" for more informations on handling interrupts
  1161. generated by TLAN based adapters.
  1162. ******************************************************************************
  1163. *****************************************************************************/
  1164. /***************************************************************
  1165. * TLan_HandleTxEOF
  1166. *
  1167. * Returns:
  1168. * 1
  1169. * Parms:
  1170. * dev Device assigned the IRQ that was
  1171. * raised.
  1172. * host_int The contents of the HOST_INT
  1173. * port.
  1174. *
  1175. * This function handles Tx EOF interrupts which are raised
  1176. * by the adapter when it has completed sending the
  1177. * contents of a buffer. If detemines which list/buffer
  1178. * was completed and resets it. If the buffer was the last
  1179. * in the channel (EOC), then the function checks to see if
  1180. * another buffer is ready to send, and if so, sends a Tx
  1181. * Go command. Finally, the driver activates/continues the
  1182. * activity LED.
  1183. *
  1184. **************************************************************/
  1185. static u32 TLan_HandleTxEOF( struct net_device *dev, u16 host_int )
  1186. {
  1187. TLanPrivateInfo *priv = netdev_priv(dev);
  1188. int eoc = 0;
  1189. TLanList *head_list;
  1190. dma_addr_t head_list_phys;
  1191. u32 ack = 0;
  1192. u16 tmpCStat;
  1193. TLAN_DBG( TLAN_DEBUG_TX, "TRANSMIT: Handling TX EOF (Head=%d Tail=%d)\n",
  1194. priv->txHead, priv->txTail );
  1195. head_list = priv->txList + priv->txHead;
  1196. while (((tmpCStat = head_list->cStat ) & TLAN_CSTAT_FRM_CMP) && (ack < 255)) {
  1197. ack++;
  1198. if ( ! bbuf ) {
  1199. struct sk_buff *skb = TLan_GetSKB(head_list);
  1200. pci_unmap_single(priv->pciDev, head_list->buffer[0].address,
  1201. skb->len, PCI_DMA_TODEVICE);
  1202. dev_kfree_skb_any(skb);
  1203. head_list->buffer[8].address = 0;
  1204. head_list->buffer[9].address = 0;
  1205. }
  1206. if ( tmpCStat & TLAN_CSTAT_EOC )
  1207. eoc = 1;
  1208. dev->stats.tx_bytes += head_list->frameSize;
  1209. head_list->cStat = TLAN_CSTAT_UNUSED;
  1210. netif_start_queue(dev);
  1211. CIRC_INC( priv->txHead, TLAN_NUM_TX_LISTS );
  1212. head_list = priv->txList + priv->txHead;
  1213. }
  1214. if (!ack)
  1215. printk(KERN_INFO "TLAN: Received interrupt for uncompleted TX frame.\n");
  1216. if ( eoc ) {
  1217. TLAN_DBG( TLAN_DEBUG_TX,
  1218. "TRANSMIT: Handling TX EOC (Head=%d Tail=%d)\n",
  1219. priv->txHead, priv->txTail );
  1220. head_list = priv->txList + priv->txHead;
  1221. head_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txHead;
  1222. if ( ( head_list->cStat & TLAN_CSTAT_READY ) == TLAN_CSTAT_READY ) {
  1223. outl(head_list_phys, dev->base_addr + TLAN_CH_PARM );
  1224. ack |= TLAN_HC_GO;
  1225. } else {
  1226. priv->txInProgress = 0;
  1227. }
  1228. }
  1229. if ( priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED ) {
  1230. TLan_DioWrite8( dev->base_addr,
  1231. TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT );
  1232. if ( priv->timer.function == NULL ) {
  1233. priv->timer.function = &TLan_Timer;
  1234. priv->timer.data = (unsigned long) dev;
  1235. priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
  1236. priv->timerSetAt = jiffies;
  1237. priv->timerType = TLAN_TIMER_ACTIVITY;
  1238. add_timer(&priv->timer);
  1239. } else if ( priv->timerType == TLAN_TIMER_ACTIVITY ) {
  1240. priv->timerSetAt = jiffies;
  1241. }
  1242. }
  1243. return ack;
  1244. } /* TLan_HandleTxEOF */
  1245. /***************************************************************
  1246. * TLan_HandleStatOverflow
  1247. *
  1248. * Returns:
  1249. * 1
  1250. * Parms:
  1251. * dev Device assigned the IRQ that was
  1252. * raised.
  1253. * host_int The contents of the HOST_INT
  1254. * port.
  1255. *
  1256. * This function handles the Statistics Overflow interrupt
  1257. * which means that one or more of the TLAN statistics
  1258. * registers has reached 1/2 capacity and needs to be read.
  1259. *
  1260. **************************************************************/
  1261. static u32 TLan_HandleStatOverflow( struct net_device *dev, u16 host_int )
  1262. {
  1263. TLan_ReadAndClearStats( dev, TLAN_RECORD );
  1264. return 1;
  1265. } /* TLan_HandleStatOverflow */
  1266. /***************************************************************
  1267. * TLan_HandleRxEOF
  1268. *
  1269. * Returns:
  1270. * 1
  1271. * Parms:
  1272. * dev Device assigned the IRQ that was
  1273. * raised.
  1274. * host_int The contents of the HOST_INT
  1275. * port.
  1276. *
  1277. * This function handles the Rx EOF interrupt which
  1278. * indicates a frame has been received by the adapter from
  1279. * the net and the frame has been transferred to memory.
  1280. * The function determines the bounce buffer the frame has
  1281. * been loaded into, creates a new sk_buff big enough to
  1282. * hold the frame, and sends it to protocol stack. It
  1283. * then resets the used buffer and appends it to the end
  1284. * of the list. If the frame was the last in the Rx
  1285. * channel (EOC), the function restarts the receive channel
  1286. * by sending an Rx Go command to the adapter. Then it
  1287. * activates/continues the activity LED.
  1288. *
  1289. **************************************************************/
  1290. static u32 TLan_HandleRxEOF( struct net_device *dev, u16 host_int )
  1291. {
  1292. TLanPrivateInfo *priv = netdev_priv(dev);
  1293. u32 ack = 0;
  1294. int eoc = 0;
  1295. u8 *head_buffer;
  1296. TLanList *head_list;
  1297. struct sk_buff *skb;
  1298. TLanList *tail_list;
  1299. u16 tmpCStat;
  1300. dma_addr_t head_list_phys;
  1301. TLAN_DBG( TLAN_DEBUG_RX, "RECEIVE: Handling RX EOF (Head=%d Tail=%d)\n",
  1302. priv->rxHead, priv->rxTail );
  1303. head_list = priv->rxList + priv->rxHead;
  1304. head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
  1305. while (((tmpCStat = head_list->cStat) & TLAN_CSTAT_FRM_CMP) && (ack < 255)) {
  1306. dma_addr_t frameDma = head_list->buffer[0].address;
  1307. u32 frameSize = head_list->frameSize;
  1308. ack++;
  1309. if (tmpCStat & TLAN_CSTAT_EOC)
  1310. eoc = 1;
  1311. if (bbuf) {
  1312. skb = netdev_alloc_skb(dev, frameSize + 7);
  1313. if ( !skb )
  1314. goto drop_and_reuse;
  1315. head_buffer = priv->rxBuffer
  1316. + (priv->rxHead * TLAN_MAX_FRAME_SIZE);
  1317. skb_reserve(skb, 2);
  1318. pci_dma_sync_single_for_cpu(priv->pciDev,
  1319. frameDma, frameSize,
  1320. PCI_DMA_FROMDEVICE);
  1321. skb_copy_from_linear_data(skb, head_buffer, frameSize);
  1322. skb_put(skb, frameSize);
  1323. dev->stats.rx_bytes += frameSize;
  1324. skb->protocol = eth_type_trans( skb, dev );
  1325. netif_rx( skb );
  1326. } else {
  1327. struct sk_buff *new_skb;
  1328. new_skb = netdev_alloc_skb(dev, TLAN_MAX_FRAME_SIZE + 7 );
  1329. if ( !new_skb )
  1330. goto drop_and_reuse;
  1331. skb = TLan_GetSKB(head_list);
  1332. pci_unmap_single(priv->pciDev, frameDma,
  1333. TLAN_MAX_FRAME_SIZE, PCI_DMA_FROMDEVICE);
  1334. skb_put( skb, frameSize );
  1335. dev->stats.rx_bytes += frameSize;
  1336. skb->protocol = eth_type_trans( skb, dev );
  1337. netif_rx( skb );
  1338. skb_reserve( new_skb, NET_IP_ALIGN );
  1339. head_list->buffer[0].address = pci_map_single(priv->pciDev,
  1340. new_skb->data,
  1341. TLAN_MAX_FRAME_SIZE,
  1342. PCI_DMA_FROMDEVICE);
  1343. TLan_StoreSKB(head_list, new_skb);
  1344. }
  1345. drop_and_reuse:
  1346. head_list->forward = 0;
  1347. head_list->cStat = 0;
  1348. tail_list = priv->rxList + priv->rxTail;
  1349. tail_list->forward = head_list_phys;
  1350. CIRC_INC( priv->rxHead, TLAN_NUM_RX_LISTS );
  1351. CIRC_INC( priv->rxTail, TLAN_NUM_RX_LISTS );
  1352. head_list = priv->rxList + priv->rxHead;
  1353. head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
  1354. }
  1355. if (!ack)
  1356. printk(KERN_INFO "TLAN: Received interrupt for uncompleted RX frame.\n");
  1357. if ( eoc ) {
  1358. TLAN_DBG( TLAN_DEBUG_RX,
  1359. "RECEIVE: Handling RX EOC (Head=%d Tail=%d)\n",
  1360. priv->rxHead, priv->rxTail );
  1361. head_list = priv->rxList + priv->rxHead;
  1362. head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
  1363. outl(head_list_phys, dev->base_addr + TLAN_CH_PARM );
  1364. ack |= TLAN_HC_GO | TLAN_HC_RT;
  1365. priv->rxEocCount++;
  1366. }
  1367. if ( priv->adapter->flags & TLAN_ADAPTER_ACTIVITY_LED ) {
  1368. TLan_DioWrite8( dev->base_addr,
  1369. TLAN_LED_REG, TLAN_LED_LINK | TLAN_LED_ACT );
  1370. if ( priv->timer.function == NULL ) {
  1371. priv->timer.function = &TLan_Timer;
  1372. priv->timer.data = (unsigned long) dev;
  1373. priv->timer.expires = jiffies + TLAN_TIMER_ACT_DELAY;
  1374. priv->timerSetAt = jiffies;
  1375. priv->timerType = TLAN_TIMER_ACTIVITY;
  1376. add_timer(&priv->timer);
  1377. } else if ( priv->timerType == TLAN_TIMER_ACTIVITY ) {
  1378. priv->timerSetAt = jiffies;
  1379. }
  1380. }
  1381. dev->last_rx = jiffies;
  1382. return ack;
  1383. } /* TLan_HandleRxEOF */
  1384. /***************************************************************
  1385. * TLan_HandleDummy
  1386. *
  1387. * Returns:
  1388. * 1
  1389. * Parms:
  1390. * dev Device assigned the IRQ that was
  1391. * raised.
  1392. * host_int The contents of the HOST_INT
  1393. * port.
  1394. *
  1395. * This function handles the Dummy interrupt, which is
  1396. * raised whenever a test interrupt is generated by setting
  1397. * the Req_Int bit of HOST_CMD to 1.
  1398. *
  1399. **************************************************************/
  1400. static u32 TLan_HandleDummy( struct net_device *dev, u16 host_int )
  1401. {
  1402. printk( "TLAN: Test interrupt on %s.\n", dev->name );
  1403. return 1;
  1404. } /* TLan_HandleDummy */
  1405. /***************************************************************
  1406. * TLan_HandleTxEOC
  1407. *
  1408. * Returns:
  1409. * 1
  1410. * Parms:
  1411. * dev Device assigned the IRQ that was
  1412. * raised.
  1413. * host_int The contents of the HOST_INT
  1414. * port.
  1415. *
  1416. * This driver is structured to determine EOC occurrences by
  1417. * reading the CSTAT member of the list structure. Tx EOC
  1418. * interrupts are disabled via the DIO INTDIS register.
  1419. * However, TLAN chips before revision 3.0 didn't have this
  1420. * functionality, so process EOC events if this is the
  1421. * case.
  1422. *
  1423. **************************************************************/
  1424. static u32 TLan_HandleTxEOC( struct net_device *dev, u16 host_int )
  1425. {
  1426. TLanPrivateInfo *priv = netdev_priv(dev);
  1427. TLanList *head_list;
  1428. dma_addr_t head_list_phys;
  1429. u32 ack = 1;
  1430. host_int = 0;
  1431. if ( priv->tlanRev < 0x30 ) {
  1432. TLAN_DBG( TLAN_DEBUG_TX,
  1433. "TRANSMIT: Handling TX EOC (Head=%d Tail=%d) -- IRQ\n",
  1434. priv->txHead, priv->txTail );
  1435. head_list = priv->txList + priv->txHead;
  1436. head_list_phys = priv->txListDMA + sizeof(TLanList) * priv->txHead;
  1437. if ( ( head_list->cStat & TLAN_CSTAT_READY ) == TLAN_CSTAT_READY ) {
  1438. netif_stop_queue(dev);
  1439. outl( head_list_phys, dev->base_addr + TLAN_CH_PARM );
  1440. ack |= TLAN_HC_GO;
  1441. } else {
  1442. priv->txInProgress = 0;
  1443. }
  1444. }
  1445. return ack;
  1446. } /* TLan_HandleTxEOC */
  1447. /***************************************************************
  1448. * TLan_HandleStatusCheck
  1449. *
  1450. * Returns:
  1451. * 0 if Adapter check, 1 if Network Status check.
  1452. * Parms:
  1453. * dev Device assigned the IRQ that was
  1454. * raised.
  1455. * host_int The contents of the HOST_INT
  1456. * port.
  1457. *
  1458. * This function handles Adapter Check/Network Status
  1459. * interrupts generated by the adapter. It checks the
  1460. * vector in the HOST_INT register to determine if it is
  1461. * an Adapter Check interrupt. If so, it resets the
  1462. * adapter. Otherwise it clears the status registers
  1463. * and services the PHY.
  1464. *
  1465. **************************************************************/
  1466. static u32 TLan_HandleStatusCheck( struct net_device *dev, u16 host_int )
  1467. {
  1468. TLanPrivateInfo *priv = netdev_priv(dev);
  1469. u32 ack;
  1470. u32 error;
  1471. u8 net_sts;
  1472. u32 phy;
  1473. u16 tlphy_ctl;
  1474. u16 tlphy_sts;
  1475. ack = 1;
  1476. if ( host_int & TLAN_HI_IV_MASK ) {
  1477. netif_stop_queue( dev );
  1478. error = inl( dev->base_addr + TLAN_CH_PARM );
  1479. printk( "TLAN: %s: Adaptor Error = 0x%x\n", dev->name, error );
  1480. TLan_ReadAndClearStats( dev, TLAN_RECORD );
  1481. outl( TLAN_HC_AD_RST, dev->base_addr + TLAN_HOST_CMD );
  1482. schedule_work(&priv->tlan_tqueue);
  1483. netif_wake_queue(dev);
  1484. ack = 0;
  1485. } else {
  1486. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Status Check\n", dev->name );
  1487. phy = priv->phy[priv->phyNum];
  1488. net_sts = TLan_DioRead8( dev->base_addr, TLAN_NET_STS );
  1489. if ( net_sts ) {
  1490. TLan_DioWrite8( dev->base_addr, TLAN_NET_STS, net_sts );
  1491. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Net_Sts = %x\n",
  1492. dev->name, (unsigned) net_sts );
  1493. }
  1494. if ( ( net_sts & TLAN_NET_STS_MIRQ ) && ( priv->phyNum == 0 ) ) {
  1495. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_STS, &tlphy_sts );
  1496. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl );
  1497. if ( ! ( tlphy_sts & TLAN_TS_POLOK ) &&
  1498. ! ( tlphy_ctl & TLAN_TC_SWAPOL ) ) {
  1499. tlphy_ctl |= TLAN_TC_SWAPOL;
  1500. TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
  1501. } else if ( ( tlphy_sts & TLAN_TS_POLOK )
  1502. && ( tlphy_ctl & TLAN_TC_SWAPOL ) ) {
  1503. tlphy_ctl &= ~TLAN_TC_SWAPOL;
  1504. TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl);
  1505. }
  1506. if (debug) {
  1507. TLan_PhyPrint( dev );
  1508. }
  1509. }
  1510. }
  1511. return ack;
  1512. } /* TLan_HandleStatusCheck */
  1513. /***************************************************************
  1514. * TLan_HandleRxEOC
  1515. *
  1516. * Returns:
  1517. * 1
  1518. * Parms:
  1519. * dev Device assigned the IRQ that was
  1520. * raised.
  1521. * host_int The contents of the HOST_INT
  1522. * port.
  1523. *
  1524. * This driver is structured to determine EOC occurrences by
  1525. * reading the CSTAT member of the list structure. Rx EOC
  1526. * interrupts are disabled via the DIO INTDIS register.
  1527. * However, TLAN chips before revision 3.0 didn't have this
  1528. * CSTAT member or a INTDIS register, so if this chip is
  1529. * pre-3.0, process EOC interrupts normally.
  1530. *
  1531. **************************************************************/
  1532. static u32 TLan_HandleRxEOC( struct net_device *dev, u16 host_int )
  1533. {
  1534. TLanPrivateInfo *priv = netdev_priv(dev);
  1535. dma_addr_t head_list_phys;
  1536. u32 ack = 1;
  1537. if ( priv->tlanRev < 0x30 ) {
  1538. TLAN_DBG( TLAN_DEBUG_RX,
  1539. "RECEIVE: Handling RX EOC (Head=%d Tail=%d) -- IRQ\n",
  1540. priv->rxHead, priv->rxTail );
  1541. head_list_phys = priv->rxListDMA + sizeof(TLanList) * priv->rxHead;
  1542. outl( head_list_phys, dev->base_addr + TLAN_CH_PARM );
  1543. ack |= TLAN_HC_GO | TLAN_HC_RT;
  1544. priv->rxEocCount++;
  1545. }
  1546. return ack;
  1547. } /* TLan_HandleRxEOC */
  1548. /*****************************************************************************
  1549. ******************************************************************************
  1550. ThunderLAN Driver Timer Function
  1551. ******************************************************************************
  1552. *****************************************************************************/
  1553. /***************************************************************
  1554. * TLan_Timer
  1555. *
  1556. * Returns:
  1557. * Nothing
  1558. * Parms:
  1559. * data A value given to add timer when
  1560. * add_timer was called.
  1561. *
  1562. * This function handles timed functionality for the
  1563. * TLAN driver. The two current timer uses are for
  1564. * delaying for autonegotionation and driving the ACT LED.
  1565. * - Autonegotiation requires being allowed about
  1566. * 2 1/2 seconds before attempting to transmit a
  1567. * packet. It would be a very bad thing to hang
  1568. * the kernel this long, so the driver doesn't
  1569. * allow transmission 'til after this time, for
  1570. * certain PHYs. It would be much nicer if all
  1571. * PHYs were interrupt-capable like the internal
  1572. * PHY.
  1573. * - The ACT LED, which shows adapter activity, is
  1574. * driven by the driver, and so must be left on
  1575. * for a short period to power up the LED so it
  1576. * can be seen. This delay can be changed by
  1577. * changing the TLAN_TIMER_ACT_DELAY in tlan.h,
  1578. * if desired. 100 ms produces a slightly
  1579. * sluggish response.
  1580. *
  1581. **************************************************************/
  1582. static void TLan_Timer( unsigned long data )
  1583. {
  1584. struct net_device *dev = (struct net_device *) data;
  1585. TLanPrivateInfo *priv = netdev_priv(dev);
  1586. u32 elapsed;
  1587. unsigned long flags = 0;
  1588. priv->timer.function = NULL;
  1589. switch ( priv->timerType ) {
  1590. #ifdef MONITOR
  1591. case TLAN_TIMER_LINK_BEAT:
  1592. TLan_PhyMonitor( dev );
  1593. break;
  1594. #endif
  1595. case TLAN_TIMER_PHY_PDOWN:
  1596. TLan_PhyPowerDown( dev );
  1597. break;
  1598. case TLAN_TIMER_PHY_PUP:
  1599. TLan_PhyPowerUp( dev );
  1600. break;
  1601. case TLAN_TIMER_PHY_RESET:
  1602. TLan_PhyReset( dev );
  1603. break;
  1604. case TLAN_TIMER_PHY_START_LINK:
  1605. TLan_PhyStartLink( dev );
  1606. break;
  1607. case TLAN_TIMER_PHY_FINISH_AN:
  1608. TLan_PhyFinishAutoNeg( dev );
  1609. break;
  1610. case TLAN_TIMER_FINISH_RESET:
  1611. TLan_FinishReset( dev );
  1612. break;
  1613. case TLAN_TIMER_ACTIVITY:
  1614. spin_lock_irqsave(&priv->lock, flags);
  1615. if ( priv->timer.function == NULL ) {
  1616. elapsed = jiffies - priv->timerSetAt;
  1617. if ( elapsed >= TLAN_TIMER_ACT_DELAY ) {
  1618. TLan_DioWrite8( dev->base_addr,
  1619. TLAN_LED_REG, TLAN_LED_LINK );
  1620. } else {
  1621. priv->timer.function = &TLan_Timer;
  1622. priv->timer.expires = priv->timerSetAt
  1623. + TLAN_TIMER_ACT_DELAY;
  1624. spin_unlock_irqrestore(&priv->lock, flags);
  1625. add_timer( &priv->timer );
  1626. break;
  1627. }
  1628. }
  1629. spin_unlock_irqrestore(&priv->lock, flags);
  1630. break;
  1631. default:
  1632. break;
  1633. }
  1634. } /* TLan_Timer */
  1635. /*****************************************************************************
  1636. ******************************************************************************
  1637. ThunderLAN Driver Adapter Related Routines
  1638. ******************************************************************************
  1639. *****************************************************************************/
  1640. /***************************************************************
  1641. * TLan_ResetLists
  1642. *
  1643. * Returns:
  1644. * Nothing
  1645. * Parms:
  1646. * dev The device structure with the list
  1647. * stuctures to be reset.
  1648. *
  1649. * This routine sets the variables associated with managing
  1650. * the TLAN lists to their initial values.
  1651. *
  1652. **************************************************************/
  1653. static void TLan_ResetLists( struct net_device *dev )
  1654. {
  1655. TLanPrivateInfo *priv = netdev_priv(dev);
  1656. int i;
  1657. TLanList *list;
  1658. dma_addr_t list_phys;
  1659. struct sk_buff *skb;
  1660. priv->txHead = 0;
  1661. priv->txTail = 0;
  1662. for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ ) {
  1663. list = priv->txList + i;
  1664. list->cStat = TLAN_CSTAT_UNUSED;
  1665. if ( bbuf ) {
  1666. list->buffer[0].address = priv->txBufferDMA
  1667. + ( i * TLAN_MAX_FRAME_SIZE );
  1668. } else {
  1669. list->buffer[0].address = 0;
  1670. }
  1671. list->buffer[2].count = 0;
  1672. list->buffer[2].address = 0;
  1673. list->buffer[8].address = 0;
  1674. list->buffer[9].address = 0;
  1675. }
  1676. priv->rxHead = 0;
  1677. priv->rxTail = TLAN_NUM_RX_LISTS - 1;
  1678. for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ ) {
  1679. list = priv->rxList + i;
  1680. list_phys = priv->rxListDMA + sizeof(TLanList) * i;
  1681. list->cStat = TLAN_CSTAT_READY;
  1682. list->frameSize = TLAN_MAX_FRAME_SIZE;
  1683. list->buffer[0].count = TLAN_MAX_FRAME_SIZE | TLAN_LAST_BUFFER;
  1684. if ( bbuf ) {
  1685. list->buffer[0].address = priv->rxBufferDMA
  1686. + ( i * TLAN_MAX_FRAME_SIZE );
  1687. } else {
  1688. skb = netdev_alloc_skb(dev, TLAN_MAX_FRAME_SIZE + 7 );
  1689. if ( !skb ) {
  1690. pr_err("TLAN: out of memory for received data.\n" );
  1691. break;
  1692. }
  1693. skb_reserve( skb, NET_IP_ALIGN );
  1694. list->buffer[0].address = pci_map_single(priv->pciDev,
  1695. skb->data,
  1696. TLAN_MAX_FRAME_SIZE,
  1697. PCI_DMA_FROMDEVICE);
  1698. TLan_StoreSKB(list, skb);
  1699. }
  1700. list->buffer[1].count = 0;
  1701. list->buffer[1].address = 0;
  1702. list->forward = list_phys + sizeof(TLanList);
  1703. }
  1704. /* in case ran out of memory early, clear bits */
  1705. while (i < TLAN_NUM_RX_LISTS) {
  1706. TLan_StoreSKB(priv->rxList + i, NULL);
  1707. ++i;
  1708. }
  1709. list->forward = 0;
  1710. } /* TLan_ResetLists */
  1711. static void TLan_FreeLists( struct net_device *dev )
  1712. {
  1713. TLanPrivateInfo *priv = netdev_priv(dev);
  1714. int i;
  1715. TLanList *list;
  1716. struct sk_buff *skb;
  1717. if ( ! bbuf ) {
  1718. for ( i = 0; i < TLAN_NUM_TX_LISTS; i++ ) {
  1719. list = priv->txList + i;
  1720. skb = TLan_GetSKB(list);
  1721. if ( skb ) {
  1722. pci_unmap_single(priv->pciDev,
  1723. list->buffer[0].address, skb->len,
  1724. PCI_DMA_TODEVICE);
  1725. dev_kfree_skb_any( skb );
  1726. list->buffer[8].address = 0;
  1727. list->buffer[9].address = 0;
  1728. }
  1729. }
  1730. for ( i = 0; i < TLAN_NUM_RX_LISTS; i++ ) {
  1731. list = priv->rxList + i;
  1732. skb = TLan_GetSKB(list);
  1733. if ( skb ) {
  1734. pci_unmap_single(priv->pciDev,
  1735. list->buffer[0].address,
  1736. TLAN_MAX_FRAME_SIZE,
  1737. PCI_DMA_FROMDEVICE);
  1738. dev_kfree_skb_any( skb );
  1739. list->buffer[8].address = 0;
  1740. list->buffer[9].address = 0;
  1741. }
  1742. }
  1743. }
  1744. } /* TLan_FreeLists */
  1745. /***************************************************************
  1746. * TLan_PrintDio
  1747. *
  1748. * Returns:
  1749. * Nothing
  1750. * Parms:
  1751. * io_base Base IO port of the device of
  1752. * which to print DIO registers.
  1753. *
  1754. * This function prints out all the internal (DIO)
  1755. * registers of a TLAN chip.
  1756. *
  1757. **************************************************************/
  1758. static void TLan_PrintDio( u16 io_base )
  1759. {
  1760. u32 data0, data1;
  1761. int i;
  1762. printk( "TLAN: Contents of internal registers for io base 0x%04hx.\n",
  1763. io_base );
  1764. printk( "TLAN: Off. +0 +4\n" );
  1765. for ( i = 0; i < 0x4C; i+= 8 ) {
  1766. data0 = TLan_DioRead32( io_base, i );
  1767. data1 = TLan_DioRead32( io_base, i + 0x4 );
  1768. printk( "TLAN: 0x%02x 0x%08x 0x%08x\n", i, data0, data1 );
  1769. }
  1770. } /* TLan_PrintDio */
  1771. /***************************************************************
  1772. * TLan_PrintList
  1773. *
  1774. * Returns:
  1775. * Nothing
  1776. * Parms:
  1777. * list A pointer to the TLanList structure to
  1778. * be printed.
  1779. * type A string to designate type of list,
  1780. * "Rx" or "Tx".
  1781. * num The index of the list.
  1782. *
  1783. * This function prints out the contents of the list
  1784. * pointed to by the list parameter.
  1785. *
  1786. **************************************************************/
  1787. static void TLan_PrintList( TLanList *list, char *type, int num)
  1788. {
  1789. int i;
  1790. printk( "TLAN: %s List %d at %p\n", type, num, list );
  1791. printk( "TLAN: Forward = 0x%08x\n", list->forward );
  1792. printk( "TLAN: CSTAT = 0x%04hx\n", list->cStat );
  1793. printk( "TLAN: Frame Size = 0x%04hx\n", list->frameSize );
  1794. /* for ( i = 0; i < 10; i++ ) { */
  1795. for ( i = 0; i < 2; i++ ) {
  1796. printk( "TLAN: Buffer[%d].count, addr = 0x%08x, 0x%08x\n",
  1797. i, list->buffer[i].count, list->buffer[i].address );
  1798. }
  1799. } /* TLan_PrintList */
  1800. /***************************************************************
  1801. * TLan_ReadAndClearStats
  1802. *
  1803. * Returns:
  1804. * Nothing
  1805. * Parms:
  1806. * dev Pointer to device structure of adapter
  1807. * to which to read stats.
  1808. * record Flag indicating whether to add
  1809. *
  1810. * This functions reads all the internal status registers
  1811. * of the TLAN chip, which clears them as a side effect.
  1812. * It then either adds the values to the device's status
  1813. * struct, or discards them, depending on whether record
  1814. * is TLAN_RECORD (!=0) or TLAN_IGNORE (==0).
  1815. *
  1816. **************************************************************/
  1817. static void TLan_ReadAndClearStats( struct net_device *dev, int record )
  1818. {
  1819. u32 tx_good, tx_under;
  1820. u32 rx_good, rx_over;
  1821. u32 def_tx, crc, code;
  1822. u32 multi_col, single_col;
  1823. u32 excess_col, late_col, loss;
  1824. outw( TLAN_GOOD_TX_FRMS, dev->base_addr + TLAN_DIO_ADR );
  1825. tx_good = inb( dev->base_addr + TLAN_DIO_DATA );
  1826. tx_good += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
  1827. tx_good += inb( dev->base_addr + TLAN_DIO_DATA + 2 ) << 16;
  1828. tx_under = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
  1829. outw( TLAN_GOOD_RX_FRMS, dev->base_addr + TLAN_DIO_ADR );
  1830. rx_good = inb( dev->base_addr + TLAN_DIO_DATA );
  1831. rx_good += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
  1832. rx_good += inb( dev->base_addr + TLAN_DIO_DATA + 2 ) << 16;
  1833. rx_over = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
  1834. outw( TLAN_DEFERRED_TX, dev->base_addr + TLAN_DIO_ADR );
  1835. def_tx = inb( dev->base_addr + TLAN_DIO_DATA );
  1836. def_tx += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
  1837. crc = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
  1838. code = inb( dev->base_addr + TLAN_DIO_DATA + 3 );
  1839. outw( TLAN_MULTICOL_FRMS, dev->base_addr + TLAN_DIO_ADR );
  1840. multi_col = inb( dev->base_addr + TLAN_DIO_DATA );
  1841. multi_col += inb( dev->base_addr + TLAN_DIO_DATA + 1 ) << 8;
  1842. single_col = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
  1843. single_col += inb( dev->base_addr + TLAN_DIO_DATA + 3 ) << 8;
  1844. outw( TLAN_EXCESSCOL_FRMS, dev->base_addr + TLAN_DIO_ADR );
  1845. excess_col = inb( dev->base_addr + TLAN_DIO_DATA );
  1846. late_col = inb( dev->base_addr + TLAN_DIO_DATA + 1 );
  1847. loss = inb( dev->base_addr + TLAN_DIO_DATA + 2 );
  1848. if ( record ) {
  1849. dev->stats.rx_packets += rx_good;
  1850. dev->stats.rx_errors += rx_over + crc + code;
  1851. dev->stats.tx_packets += tx_good;
  1852. dev->stats.tx_errors += tx_under + loss;
  1853. dev->stats.collisions += multi_col + single_col + excess_col + late_col;
  1854. dev->stats.rx_over_errors += rx_over;
  1855. dev->stats.rx_crc_errors += crc;
  1856. dev->stats.rx_frame_errors += code;
  1857. dev->stats.tx_aborted_errors += tx_under;
  1858. dev->stats.tx_carrier_errors += loss;
  1859. }
  1860. } /* TLan_ReadAndClearStats */
  1861. /***************************************************************
  1862. * TLan_Reset
  1863. *
  1864. * Returns:
  1865. * 0
  1866. * Parms:
  1867. * dev Pointer to device structure of adapter
  1868. * to be reset.
  1869. *
  1870. * This function resets the adapter and it's physical
  1871. * device. See Chap. 3, pp. 9-10 of the "ThunderLAN
  1872. * Programmer's Guide" for details. The routine tries to
  1873. * implement what is detailed there, though adjustments
  1874. * have been made.
  1875. *
  1876. **************************************************************/
  1877. static void
  1878. TLan_ResetAdapter( struct net_device *dev )
  1879. {
  1880. TLanPrivateInfo *priv = netdev_priv(dev);
  1881. int i;
  1882. u32 addr;
  1883. u32 data;
  1884. u8 data8;
  1885. priv->tlanFullDuplex = FALSE;
  1886. priv->phyOnline=0;
  1887. netif_carrier_off(dev);
  1888. /* 1. Assert reset bit. */
  1889. data = inl(dev->base_addr + TLAN_HOST_CMD);
  1890. data |= TLAN_HC_AD_RST;
  1891. outl(data, dev->base_addr + TLAN_HOST_CMD);
  1892. udelay(1000);
  1893. /* 2. Turn off interrupts. ( Probably isn't necessary ) */
  1894. data = inl(dev->base_addr + TLAN_HOST_CMD);
  1895. data |= TLAN_HC_INT_OFF;
  1896. outl(data, dev->base_addr + TLAN_HOST_CMD);
  1897. /* 3. Clear AREGs and HASHs. */
  1898. for ( i = TLAN_AREG_0; i <= TLAN_HASH_2; i += 4 ) {
  1899. TLan_DioWrite32( dev->base_addr, (u16) i, 0 );
  1900. }
  1901. /* 4. Setup NetConfig register. */
  1902. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
  1903. TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, (u16) data );
  1904. /* 5. Load Ld_Tmr and Ld_Thr in HOST_CMD. */
  1905. outl( TLAN_HC_LD_TMR | 0x3f, dev->base_addr + TLAN_HOST_CMD );
  1906. outl( TLAN_HC_LD_THR | 0x9, dev->base_addr + TLAN_HOST_CMD );
  1907. /* 6. Unreset the MII by setting NMRST (in NetSio) to 1. */
  1908. outw( TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR );
  1909. addr = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  1910. TLan_SetBit( TLAN_NET_SIO_NMRST, addr );
  1911. /* 7. Setup the remaining registers. */
  1912. if ( priv->tlanRev >= 0x30 ) {
  1913. data8 = TLAN_ID_TX_EOC | TLAN_ID_RX_EOC;
  1914. TLan_DioWrite8( dev->base_addr, TLAN_INT_DIS, data8 );
  1915. }
  1916. TLan_PhyDetect( dev );
  1917. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN;
  1918. if ( priv->adapter->flags & TLAN_ADAPTER_BIT_RATE_PHY ) {
  1919. data |= TLAN_NET_CFG_BIT;
  1920. if ( priv->aui == 1 ) {
  1921. TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x0a );
  1922. } else if ( priv->duplex == TLAN_DUPLEX_FULL ) {
  1923. TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x00 );
  1924. priv->tlanFullDuplex = TRUE;
  1925. } else {
  1926. TLan_DioWrite8( dev->base_addr, TLAN_ACOMMIT, 0x08 );
  1927. }
  1928. }
  1929. if ( priv->phyNum == 0 ) {
  1930. data |= TLAN_NET_CFG_PHY_EN;
  1931. }
  1932. TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, (u16) data );
  1933. if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
  1934. TLan_FinishReset( dev );
  1935. } else {
  1936. TLan_PhyPowerDown( dev );
  1937. }
  1938. } /* TLan_ResetAdapter */
  1939. static void
  1940. TLan_FinishReset( struct net_device *dev )
  1941. {
  1942. TLanPrivateInfo *priv = netdev_priv(dev);
  1943. u8 data;
  1944. u32 phy;
  1945. u8 sio;
  1946. u16 status;
  1947. u16 partner;
  1948. u16 tlphy_ctl;
  1949. u16 tlphy_par;
  1950. u16 tlphy_id1, tlphy_id2;
  1951. int i;
  1952. phy = priv->phy[priv->phyNum];
  1953. data = TLAN_NET_CMD_NRESET | TLAN_NET_CMD_NWRAP;
  1954. if ( priv->tlanFullDuplex ) {
  1955. data |= TLAN_NET_CMD_DUPLEX;
  1956. }
  1957. TLan_DioWrite8( dev->base_addr, TLAN_NET_CMD, data );
  1958. data = TLAN_NET_MASK_MASK4 | TLAN_NET_MASK_MASK5;
  1959. if ( priv->phyNum == 0 ) {
  1960. data |= TLAN_NET_MASK_MASK7;
  1961. }
  1962. TLan_DioWrite8( dev->base_addr, TLAN_NET_MASK, data );
  1963. TLan_DioWrite16( dev->base_addr, TLAN_MAX_RX, ((1536)+7)&~7 );
  1964. TLan_MiiReadReg( dev, phy, MII_GEN_ID_HI, &tlphy_id1 );
  1965. TLan_MiiReadReg( dev, phy, MII_GEN_ID_LO, &tlphy_id2 );
  1966. if ( ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) ||
  1967. ( priv->aui ) ) {
  1968. status = MII_GS_LINK;
  1969. printk( "TLAN: %s: Link forced.\n", dev->name );
  1970. } else {
  1971. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  1972. udelay( 1000 );
  1973. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  1974. if ( (status & MII_GS_LINK) &&
  1975. /* We only support link info on Nat.Sem. PHY's */
  1976. (tlphy_id1 == NAT_SEM_ID1) &&
  1977. (tlphy_id2 == NAT_SEM_ID2) ) {
  1978. TLan_MiiReadReg( dev, phy, MII_AN_LPA, &partner );
  1979. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_PAR, &tlphy_par );
  1980. printk( "TLAN: %s: Link active with ", dev->name );
  1981. if (!(tlphy_par & TLAN_PHY_AN_EN_STAT)) {
  1982. printk( "forced 10%sMbps %s-Duplex\n",
  1983. tlphy_par & TLAN_PHY_SPEED_100 ? "" : "0",
  1984. tlphy_par & TLAN_PHY_DUPLEX_FULL ? "Full" : "Half");
  1985. } else {
  1986. printk( "AutoNegotiation enabled, at 10%sMbps %s-Duplex\n",
  1987. tlphy_par & TLAN_PHY_SPEED_100 ? "" : "0",
  1988. tlphy_par & TLAN_PHY_DUPLEX_FULL ? "Full" : "Half");
  1989. printk("TLAN: Partner capability: ");
  1990. for (i = 5; i <= 10; i++)
  1991. if (partner & (1<<i))
  1992. printk("%s",media[i-5]);
  1993. printk("\n");
  1994. }
  1995. TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
  1996. #ifdef MONITOR
  1997. /* We have link beat..for now anyway */
  1998. priv->link = 1;
  1999. /*Enabling link beat monitoring */
  2000. TLan_SetTimer( dev, (10*HZ), TLAN_TIMER_LINK_BEAT );
  2001. #endif
  2002. } else if (status & MII_GS_LINK) {
  2003. printk( "TLAN: %s: Link active\n", dev->name );
  2004. TLan_DioWrite8( dev->base_addr, TLAN_LED_REG, TLAN_LED_LINK );
  2005. }
  2006. }
  2007. if ( priv->phyNum == 0 ) {
  2008. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tlphy_ctl );
  2009. tlphy_ctl |= TLAN_TC_INTEN;
  2010. TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tlphy_ctl );
  2011. sio = TLan_DioRead8( dev->base_addr, TLAN_NET_SIO );
  2012. sio |= TLAN_NET_SIO_MINTEN;
  2013. TLan_DioWrite8( dev->base_addr, TLAN_NET_SIO, sio );
  2014. }
  2015. if ( status & MII_GS_LINK ) {
  2016. TLan_SetMac( dev, 0, dev->dev_addr );
  2017. priv->phyOnline = 1;
  2018. outb( ( TLAN_HC_INT_ON >> 8 ), dev->base_addr + TLAN_HOST_CMD + 1 );
  2019. if ( debug >= 1 && debug != TLAN_DEBUG_PROBE ) {
  2020. outb( ( TLAN_HC_REQ_INT >> 8 ), dev->base_addr + TLAN_HOST_CMD + 1 );
  2021. }
  2022. outl( priv->rxListDMA, dev->base_addr + TLAN_CH_PARM );
  2023. outl( TLAN_HC_GO | TLAN_HC_RT, dev->base_addr + TLAN_HOST_CMD );
  2024. netif_carrier_on(dev);
  2025. } else {
  2026. printk( "TLAN: %s: Link inactive, will retry in 10 secs...\n",
  2027. dev->name );
  2028. TLan_SetTimer( dev, (10*HZ), TLAN_TIMER_FINISH_RESET );
  2029. return;
  2030. }
  2031. TLan_SetMulticastList(dev);
  2032. } /* TLan_FinishReset */
  2033. /***************************************************************
  2034. * TLan_SetMac
  2035. *
  2036. * Returns:
  2037. * Nothing
  2038. * Parms:
  2039. * dev Pointer to device structure of adapter
  2040. * on which to change the AREG.
  2041. * areg The AREG to set the address in (0 - 3).
  2042. * mac A pointer to an array of chars. Each
  2043. * element stores one byte of the address.
  2044. * IE, it isn't in ascii.
  2045. *
  2046. * This function transfers a MAC address to one of the
  2047. * TLAN AREGs (address registers). The TLAN chip locks
  2048. * the register on writing to offset 0 and unlocks the
  2049. * register after writing to offset 5. If NULL is passed
  2050. * in mac, then the AREG is filled with 0's.
  2051. *
  2052. **************************************************************/
  2053. static void TLan_SetMac( struct net_device *dev, int areg, char *mac )
  2054. {
  2055. int i;
  2056. areg *= 6;
  2057. if ( mac != NULL ) {
  2058. for ( i = 0; i < 6; i++ )
  2059. TLan_DioWrite8( dev->base_addr,
  2060. TLAN_AREG_0 + areg + i, mac[i] );
  2061. } else {
  2062. for ( i = 0; i < 6; i++ )
  2063. TLan_DioWrite8( dev->base_addr,
  2064. TLAN_AREG_0 + areg + i, 0 );
  2065. }
  2066. } /* TLan_SetMac */
  2067. /*****************************************************************************
  2068. ******************************************************************************
  2069. ThunderLAN Driver PHY Layer Routines
  2070. ******************************************************************************
  2071. *****************************************************************************/
  2072. /*********************************************************************
  2073. * TLan_PhyPrint
  2074. *
  2075. * Returns:
  2076. * Nothing
  2077. * Parms:
  2078. * dev A pointer to the device structure of the
  2079. * TLAN device having the PHYs to be detailed.
  2080. *
  2081. * This function prints the registers a PHY (aka transceiver).
  2082. *
  2083. ********************************************************************/
  2084. static void TLan_PhyPrint( struct net_device *dev )
  2085. {
  2086. TLanPrivateInfo *priv = netdev_priv(dev);
  2087. u16 i, data0, data1, data2, data3, phy;
  2088. phy = priv->phy[priv->phyNum];
  2089. if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
  2090. printk( "TLAN: Device %s, Unmanaged PHY.\n", dev->name );
  2091. } else if ( phy <= TLAN_PHY_MAX_ADDR ) {
  2092. printk( "TLAN: Device %s, PHY 0x%02x.\n", dev->name, phy );
  2093. printk( "TLAN: Off. +0 +1 +2 +3 \n" );
  2094. for ( i = 0; i < 0x20; i+= 4 ) {
  2095. printk( "TLAN: 0x%02x", i );
  2096. TLan_MiiReadReg( dev, phy, i, &data0 );
  2097. printk( " 0x%04hx", data0 );
  2098. TLan_MiiReadReg( dev, phy, i + 1, &data1 );
  2099. printk( " 0x%04hx", data1 );
  2100. TLan_MiiReadReg( dev, phy, i + 2, &data2 );
  2101. printk( " 0x%04hx", data2 );
  2102. TLan_MiiReadReg( dev, phy, i + 3, &data3 );
  2103. printk( " 0x%04hx\n", data3 );
  2104. }
  2105. } else {
  2106. printk( "TLAN: Device %s, Invalid PHY.\n", dev->name );
  2107. }
  2108. } /* TLan_PhyPrint */
  2109. /*********************************************************************
  2110. * TLan_PhyDetect
  2111. *
  2112. * Returns:
  2113. * Nothing
  2114. * Parms:
  2115. * dev A pointer to the device structure of the adapter
  2116. * for which the PHY needs determined.
  2117. *
  2118. * So far I've found that adapters which have external PHYs
  2119. * may also use the internal PHY for part of the functionality.
  2120. * (eg, AUI/Thinnet). This function finds out if this TLAN
  2121. * chip has an internal PHY, and then finds the first external
  2122. * PHY (starting from address 0) if it exists).
  2123. *
  2124. ********************************************************************/
  2125. static void TLan_PhyDetect( struct net_device *dev )
  2126. {
  2127. TLanPrivateInfo *priv = netdev_priv(dev);
  2128. u16 control;
  2129. u16 hi;
  2130. u16 lo;
  2131. u32 phy;
  2132. if ( priv->adapter->flags & TLAN_ADAPTER_UNMANAGED_PHY ) {
  2133. priv->phyNum = 0xFFFF;
  2134. return;
  2135. }
  2136. TLan_MiiReadReg( dev, TLAN_PHY_MAX_ADDR, MII_GEN_ID_HI, &hi );
  2137. if ( hi != 0xFFFF ) {
  2138. priv->phy[0] = TLAN_PHY_MAX_ADDR;
  2139. } else {
  2140. priv->phy[0] = TLAN_PHY_NONE;
  2141. }
  2142. priv->phy[1] = TLAN_PHY_NONE;
  2143. for ( phy = 0; phy <= TLAN_PHY_MAX_ADDR; phy++ ) {
  2144. TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &control );
  2145. TLan_MiiReadReg( dev, phy, MII_GEN_ID_HI, &hi );
  2146. TLan_MiiReadReg( dev, phy, MII_GEN_ID_LO, &lo );
  2147. if ( ( control != 0xFFFF ) ||
  2148. ( hi != 0xFFFF ) || ( lo != 0xFFFF ) ) {
  2149. TLAN_DBG( TLAN_DEBUG_GNRL,
  2150. "PHY found at %02x %04x %04x %04x\n",
  2151. phy, control, hi, lo );
  2152. if ( ( priv->phy[1] == TLAN_PHY_NONE ) &&
  2153. ( phy != TLAN_PHY_MAX_ADDR ) ) {
  2154. priv->phy[1] = phy;
  2155. }
  2156. }
  2157. }
  2158. if ( priv->phy[1] != TLAN_PHY_NONE ) {
  2159. priv->phyNum = 1;
  2160. } else if ( priv->phy[0] != TLAN_PHY_NONE ) {
  2161. priv->phyNum = 0;
  2162. } else {
  2163. printk( "TLAN: Cannot initialize device, no PHY was found!\n" );
  2164. }
  2165. } /* TLan_PhyDetect */
  2166. static void TLan_PhyPowerDown( struct net_device *dev )
  2167. {
  2168. TLanPrivateInfo *priv = netdev_priv(dev);
  2169. u16 value;
  2170. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Powering down PHY(s).\n", dev->name );
  2171. value = MII_GC_PDOWN | MII_GC_LOOPBK | MII_GC_ISOLATE;
  2172. TLan_MiiSync( dev->base_addr );
  2173. TLan_MiiWriteReg( dev, priv->phy[priv->phyNum], MII_GEN_CTL, value );
  2174. if ( ( priv->phyNum == 0 ) &&
  2175. ( priv->phy[1] != TLAN_PHY_NONE ) &&
  2176. ( ! ( priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10 ) ) ) {
  2177. TLan_MiiSync( dev->base_addr );
  2178. TLan_MiiWriteReg( dev, priv->phy[1], MII_GEN_CTL, value );
  2179. }
  2180. /* Wait for 50 ms and powerup
  2181. * This is abitrary. It is intended to make sure the
  2182. * transceiver settles.
  2183. */
  2184. TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_PUP );
  2185. } /* TLan_PhyPowerDown */
  2186. static void TLan_PhyPowerUp( struct net_device *dev )
  2187. {
  2188. TLanPrivateInfo *priv = netdev_priv(dev);
  2189. u16 value;
  2190. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Powering up PHY.\n", dev->name );
  2191. TLan_MiiSync( dev->base_addr );
  2192. value = MII_GC_LOOPBK;
  2193. TLan_MiiWriteReg( dev, priv->phy[priv->phyNum], MII_GEN_CTL, value );
  2194. TLan_MiiSync(dev->base_addr);
  2195. /* Wait for 500 ms and reset the
  2196. * transceiver. The TLAN docs say both 50 ms and
  2197. * 500 ms, so do the longer, just in case.
  2198. */
  2199. TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_RESET );
  2200. } /* TLan_PhyPowerUp */
  2201. static void TLan_PhyReset( struct net_device *dev )
  2202. {
  2203. TLanPrivateInfo *priv = netdev_priv(dev);
  2204. u16 phy;
  2205. u16 value;
  2206. phy = priv->phy[priv->phyNum];
  2207. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Reseting PHY.\n", dev->name );
  2208. TLan_MiiSync( dev->base_addr );
  2209. value = MII_GC_LOOPBK | MII_GC_RESET;
  2210. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, value );
  2211. TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &value );
  2212. while ( value & MII_GC_RESET ) {
  2213. TLan_MiiReadReg( dev, phy, MII_GEN_CTL, &value );
  2214. }
  2215. /* Wait for 500 ms and initialize.
  2216. * I don't remember why I wait this long.
  2217. * I've changed this to 50ms, as it seems long enough.
  2218. */
  2219. TLan_SetTimer( dev, (HZ/20), TLAN_TIMER_PHY_START_LINK );
  2220. } /* TLan_PhyReset */
  2221. static void TLan_PhyStartLink( struct net_device *dev )
  2222. {
  2223. TLanPrivateInfo *priv = netdev_priv(dev);
  2224. u16 ability;
  2225. u16 control;
  2226. u16 data;
  2227. u16 phy;
  2228. u16 status;
  2229. u16 tctl;
  2230. phy = priv->phy[priv->phyNum];
  2231. TLAN_DBG( TLAN_DEBUG_GNRL, "%s: Trying to activate link.\n", dev->name );
  2232. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  2233. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &ability );
  2234. if ( ( status & MII_GS_AUTONEG ) &&
  2235. ( ! priv->aui ) ) {
  2236. ability = status >> 11;
  2237. if ( priv->speed == TLAN_SPEED_10 &&
  2238. priv->duplex == TLAN_DUPLEX_HALF) {
  2239. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x0000);
  2240. } else if ( priv->speed == TLAN_SPEED_10 &&
  2241. priv->duplex == TLAN_DUPLEX_FULL) {
  2242. priv->tlanFullDuplex = TRUE;
  2243. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x0100);
  2244. } else if ( priv->speed == TLAN_SPEED_100 &&
  2245. priv->duplex == TLAN_DUPLEX_HALF) {
  2246. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x2000);
  2247. } else if ( priv->speed == TLAN_SPEED_100 &&
  2248. priv->duplex == TLAN_DUPLEX_FULL) {
  2249. priv->tlanFullDuplex = TRUE;
  2250. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x2100);
  2251. } else {
  2252. /* Set Auto-Neg advertisement */
  2253. TLan_MiiWriteReg( dev, phy, MII_AN_ADV, (ability << 5) | 1);
  2254. /* Enablee Auto-Neg */
  2255. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x1000 );
  2256. /* Restart Auto-Neg */
  2257. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, 0x1200 );
  2258. /* Wait for 4 sec for autonegotiation
  2259. * to complete. The max spec time is less than this
  2260. * but the card need additional time to start AN.
  2261. * .5 sec should be plenty extra.
  2262. */
  2263. printk( "TLAN: %s: Starting autonegotiation.\n", dev->name );
  2264. TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_PHY_FINISH_AN );
  2265. return;
  2266. }
  2267. }
  2268. if ( ( priv->aui ) && ( priv->phyNum != 0 ) ) {
  2269. priv->phyNum = 0;
  2270. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
  2271. TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, data );
  2272. TLan_SetTimer( dev, (40*HZ/1000), TLAN_TIMER_PHY_PDOWN );
  2273. return;
  2274. } else if ( priv->phyNum == 0 ) {
  2275. control = 0;
  2276. TLan_MiiReadReg( dev, phy, TLAN_TLPHY_CTL, &tctl );
  2277. if ( priv->aui ) {
  2278. tctl |= TLAN_TC_AUISEL;
  2279. } else {
  2280. tctl &= ~TLAN_TC_AUISEL;
  2281. if ( priv->duplex == TLAN_DUPLEX_FULL ) {
  2282. control |= MII_GC_DUPLEX;
  2283. priv->tlanFullDuplex = TRUE;
  2284. }
  2285. if ( priv->speed == TLAN_SPEED_100 ) {
  2286. control |= MII_GC_SPEEDSEL;
  2287. }
  2288. }
  2289. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, control );
  2290. TLan_MiiWriteReg( dev, phy, TLAN_TLPHY_CTL, tctl );
  2291. }
  2292. /* Wait for 2 sec to give the transceiver time
  2293. * to establish link.
  2294. */
  2295. TLan_SetTimer( dev, (4*HZ), TLAN_TIMER_FINISH_RESET );
  2296. } /* TLan_PhyStartLink */
  2297. static void TLan_PhyFinishAutoNeg( struct net_device *dev )
  2298. {
  2299. TLanPrivateInfo *priv = netdev_priv(dev);
  2300. u16 an_adv;
  2301. u16 an_lpa;
  2302. u16 data;
  2303. u16 mode;
  2304. u16 phy;
  2305. u16 status;
  2306. phy = priv->phy[priv->phyNum];
  2307. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  2308. udelay( 1000 );
  2309. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &status );
  2310. if ( ! ( status & MII_GS_AUTOCMPLT ) ) {
  2311. /* Wait for 8 sec to give the process
  2312. * more time. Perhaps we should fail after a while.
  2313. */
  2314. if (!priv->neg_be_verbose++) {
  2315. pr_info("TLAN: Giving autonegotiation more time.\n");
  2316. pr_info("TLAN: Please check that your adapter has\n");
  2317. pr_info("TLAN: been properly connected to a HUB or Switch.\n");
  2318. pr_info("TLAN: Trying to establish link in the background...\n");
  2319. }
  2320. TLan_SetTimer( dev, (8*HZ), TLAN_TIMER_PHY_FINISH_AN );
  2321. return;
  2322. }
  2323. printk( "TLAN: %s: Autonegotiation complete.\n", dev->name );
  2324. TLan_MiiReadReg( dev, phy, MII_AN_ADV, &an_adv );
  2325. TLan_MiiReadReg( dev, phy, MII_AN_LPA, &an_lpa );
  2326. mode = an_adv & an_lpa & 0x03E0;
  2327. if ( mode & 0x0100 ) {
  2328. priv->tlanFullDuplex = TRUE;
  2329. } else if ( ! ( mode & 0x0080 ) && ( mode & 0x0040 ) ) {
  2330. priv->tlanFullDuplex = TRUE;
  2331. }
  2332. if ( ( ! ( mode & 0x0180 ) ) &&
  2333. ( priv->adapter->flags & TLAN_ADAPTER_USE_INTERN_10 ) &&
  2334. ( priv->phyNum != 0 ) ) {
  2335. priv->phyNum = 0;
  2336. data = TLAN_NET_CFG_1FRAG | TLAN_NET_CFG_1CHAN | TLAN_NET_CFG_PHY_EN;
  2337. TLan_DioWrite16( dev->base_addr, TLAN_NET_CONFIG, data );
  2338. TLan_SetTimer( dev, (400*HZ/1000), TLAN_TIMER_PHY_PDOWN );
  2339. return;
  2340. }
  2341. if ( priv->phyNum == 0 ) {
  2342. if ( ( priv->duplex == TLAN_DUPLEX_FULL ) ||
  2343. ( an_adv & an_lpa & 0x0040 ) ) {
  2344. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL,
  2345. MII_GC_AUTOENB | MII_GC_DUPLEX );
  2346. pr_info("TLAN: Starting internal PHY with FULL-DUPLEX\n" );
  2347. } else {
  2348. TLan_MiiWriteReg( dev, phy, MII_GEN_CTL, MII_GC_AUTOENB );
  2349. pr_info( "TLAN: Starting internal PHY with HALF-DUPLEX\n" );
  2350. }
  2351. }
  2352. /* Wait for 100 ms. No reason in partiticular.
  2353. */
  2354. TLan_SetTimer( dev, (HZ/10), TLAN_TIMER_FINISH_RESET );
  2355. } /* TLan_PhyFinishAutoNeg */
  2356. #ifdef MONITOR
  2357. /*********************************************************************
  2358. *
  2359. * TLan_phyMonitor
  2360. *
  2361. * Returns:
  2362. * None
  2363. *
  2364. * Params:
  2365. * dev The device structure of this device.
  2366. *
  2367. *
  2368. * This function monitors PHY condition by reading the status
  2369. * register via the MII bus. This can be used to give info
  2370. * about link changes (up/down), and possible switch to alternate
  2371. * media.
  2372. *
  2373. * ******************************************************************/
  2374. void TLan_PhyMonitor( struct net_device *dev )
  2375. {
  2376. TLanPrivateInfo *priv = netdev_priv(dev);
  2377. u16 phy;
  2378. u16 phy_status;
  2379. phy = priv->phy[priv->phyNum];
  2380. /* Get PHY status register */
  2381. TLan_MiiReadReg( dev, phy, MII_GEN_STS, &phy_status );
  2382. /* Check if link has been lost */
  2383. if (!(phy_status & MII_GS_LINK)) {
  2384. if (priv->link) {
  2385. priv->link = 0;
  2386. printk(KERN_DEBUG "TLAN: %s has lost link\n", dev->name);
  2387. netif_carrier_off(dev);
  2388. TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT );
  2389. return;
  2390. }
  2391. }
  2392. /* Link restablished? */
  2393. if ((phy_status & MII_GS_LINK) && !priv->link) {
  2394. priv->link = 1;
  2395. printk(KERN_DEBUG "TLAN: %s has reestablished link\n", dev->name);
  2396. netif_carrier_on(dev);
  2397. }
  2398. /* Setup a new monitor */
  2399. TLan_SetTimer( dev, (2*HZ), TLAN_TIMER_LINK_BEAT );
  2400. }
  2401. #endif /* MONITOR */
  2402. /*****************************************************************************
  2403. ******************************************************************************
  2404. ThunderLAN Driver MII Routines
  2405. These routines are based on the information in Chap. 2 of the
  2406. "ThunderLAN Programmer's Guide", pp. 15-24.
  2407. ******************************************************************************
  2408. *****************************************************************************/
  2409. /***************************************************************
  2410. * TLan_MiiReadReg
  2411. *
  2412. * Returns:
  2413. * 0 if ack received ok
  2414. * 1 otherwise.
  2415. *
  2416. * Parms:
  2417. * dev The device structure containing
  2418. * The io address and interrupt count
  2419. * for this device.
  2420. * phy The address of the PHY to be queried.
  2421. * reg The register whose contents are to be
  2422. * retrieved.
  2423. * val A pointer to a variable to store the
  2424. * retrieved value.
  2425. *
  2426. * This function uses the TLAN's MII bus to retrieve the contents
  2427. * of a given register on a PHY. It sends the appropriate info
  2428. * and then reads the 16-bit register value from the MII bus via
  2429. * the TLAN SIO register.
  2430. *
  2431. **************************************************************/
  2432. static int TLan_MiiReadReg( struct net_device *dev, u16 phy, u16 reg, u16 *val )
  2433. {
  2434. u8 nack;
  2435. u16 sio, tmp;
  2436. u32 i;
  2437. int err;
  2438. int minten;
  2439. TLanPrivateInfo *priv = netdev_priv(dev);
  2440. unsigned long flags = 0;
  2441. err = FALSE;
  2442. outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
  2443. sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  2444. if (!in_irq())
  2445. spin_lock_irqsave(&priv->lock, flags);
  2446. TLan_MiiSync(dev->base_addr);
  2447. minten = TLan_GetBit( TLAN_NET_SIO_MINTEN, sio );
  2448. if ( minten )
  2449. TLan_ClearBit(TLAN_NET_SIO_MINTEN, sio);
  2450. TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Start ( 01b ) */
  2451. TLan_MiiSendData( dev->base_addr, 0x2, 2 ); /* Read ( 10b ) */
  2452. TLan_MiiSendData( dev->base_addr, phy, 5 ); /* Device # */
  2453. TLan_MiiSendData( dev->base_addr, reg, 5 ); /* Register # */
  2454. TLan_ClearBit(TLAN_NET_SIO_MTXEN, sio); /* Change direction */
  2455. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Clock Idle bit */
  2456. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  2457. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Wait 300ns */
  2458. nack = TLan_GetBit(TLAN_NET_SIO_MDATA, sio); /* Check for ACK */
  2459. TLan_SetBit(TLAN_NET_SIO_MCLK, sio); /* Finish ACK */
  2460. if (nack) { /* No ACK, so fake it */
  2461. for (i = 0; i < 16; i++) {
  2462. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
  2463. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  2464. }
  2465. tmp = 0xffff;
  2466. err = TRUE;
  2467. } else { /* ACK, so read data */
  2468. for (tmp = 0, i = 0x8000; i; i >>= 1) {
  2469. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio);
  2470. if (TLan_GetBit(TLAN_NET_SIO_MDATA, sio))
  2471. tmp |= i;
  2472. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  2473. }
  2474. }
  2475. TLan_ClearBit(TLAN_NET_SIO_MCLK, sio); /* Idle cycle */
  2476. TLan_SetBit(TLAN_NET_SIO_MCLK, sio);
  2477. if ( minten )
  2478. TLan_SetBit(TLAN_NET_SIO_MINTEN, sio);
  2479. *val = tmp;
  2480. if (!in_irq())
  2481. spin_unlock_irqrestore(&priv->lock, flags);
  2482. return err;
  2483. } /* TLan_MiiReadReg */
  2484. /***************************************************************
  2485. * TLan_MiiSendData
  2486. *
  2487. * Returns:
  2488. * Nothing
  2489. * Parms:
  2490. * base_port The base IO port of the adapter in
  2491. * question.
  2492. * dev The address of the PHY to be queried.
  2493. * data The value to be placed on the MII bus.
  2494. * num_bits The number of bits in data that are to
  2495. * be placed on the MII bus.
  2496. *
  2497. * This function sends on sequence of bits on the MII
  2498. * configuration bus.
  2499. *
  2500. **************************************************************/
  2501. static void TLan_MiiSendData( u16 base_port, u32 data, unsigned num_bits )
  2502. {
  2503. u16 sio;
  2504. u32 i;
  2505. if ( num_bits == 0 )
  2506. return;
  2507. outw( TLAN_NET_SIO, base_port + TLAN_DIO_ADR );
  2508. sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
  2509. TLan_SetBit( TLAN_NET_SIO_MTXEN, sio );
  2510. for ( i = ( 0x1 << ( num_bits - 1 ) ); i; i >>= 1 ) {
  2511. TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
  2512. (void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
  2513. if ( data & i )
  2514. TLan_SetBit( TLAN_NET_SIO_MDATA, sio );
  2515. else
  2516. TLan_ClearBit( TLAN_NET_SIO_MDATA, sio );
  2517. TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
  2518. (void) TLan_GetBit( TLAN_NET_SIO_MCLK, sio );
  2519. }
  2520. } /* TLan_MiiSendData */
  2521. /***************************************************************
  2522. * TLan_MiiSync
  2523. *
  2524. * Returns:
  2525. * Nothing
  2526. * Parms:
  2527. * base_port The base IO port of the adapter in
  2528. * question.
  2529. *
  2530. * This functions syncs all PHYs in terms of the MII configuration
  2531. * bus.
  2532. *
  2533. **************************************************************/
  2534. static void TLan_MiiSync( u16 base_port )
  2535. {
  2536. int i;
  2537. u16 sio;
  2538. outw( TLAN_NET_SIO, base_port + TLAN_DIO_ADR );
  2539. sio = base_port + TLAN_DIO_DATA + TLAN_NET_SIO;
  2540. TLan_ClearBit( TLAN_NET_SIO_MTXEN, sio );
  2541. for ( i = 0; i < 32; i++ ) {
  2542. TLan_ClearBit( TLAN_NET_SIO_MCLK, sio );
  2543. TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
  2544. }
  2545. } /* TLan_MiiSync */
  2546. /***************************************************************
  2547. * TLan_MiiWriteReg
  2548. *
  2549. * Returns:
  2550. * Nothing
  2551. * Parms:
  2552. * dev The device structure for the device
  2553. * to write to.
  2554. * phy The address of the PHY to be written to.
  2555. * reg The register whose contents are to be
  2556. * written.
  2557. * val The value to be written to the register.
  2558. *
  2559. * This function uses the TLAN's MII bus to write the contents of a
  2560. * given register on a PHY. It sends the appropriate info and then
  2561. * writes the 16-bit register value from the MII configuration bus
  2562. * via the TLAN SIO register.
  2563. *
  2564. **************************************************************/
  2565. static void TLan_MiiWriteReg( struct net_device *dev, u16 phy, u16 reg, u16 val )
  2566. {
  2567. u16 sio;
  2568. int minten;
  2569. unsigned long flags = 0;
  2570. TLanPrivateInfo *priv = netdev_priv(dev);
  2571. outw(TLAN_NET_SIO, dev->base_addr + TLAN_DIO_ADR);
  2572. sio = dev->base_addr + TLAN_DIO_DATA + TLAN_NET_SIO;
  2573. if (!in_irq())
  2574. spin_lock_irqsave(&priv->lock, flags);
  2575. TLan_MiiSync( dev->base_addr );
  2576. minten = TLan_GetBit( TLAN_NET_SIO_MINTEN, sio );
  2577. if ( minten )
  2578. TLan_ClearBit( TLAN_NET_SIO_MINTEN, sio );
  2579. TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Start ( 01b ) */
  2580. TLan_MiiSendData( dev->base_addr, 0x1, 2 ); /* Write ( 01b ) */
  2581. TLan_MiiSendData( dev->base_addr, phy, 5 ); /* Device # */
  2582. TLan_MiiSendData( dev->base_addr, reg, 5 ); /* Register # */
  2583. TLan_MiiSendData( dev->base_addr, 0x2, 2 ); /* Send ACK */
  2584. TLan_MiiSendData( dev->base_addr, val, 16 ); /* Send Data */
  2585. TLan_ClearBit( TLAN_NET_SIO_MCLK, sio ); /* Idle cycle */
  2586. TLan_SetBit( TLAN_NET_SIO_MCLK, sio );
  2587. if ( minten )
  2588. TLan_SetBit( TLAN_NET_SIO_MINTEN, sio );
  2589. if (!in_irq())
  2590. spin_unlock_irqrestore(&priv->lock, flags);
  2591. } /* TLan_MiiWriteReg */
  2592. /*****************************************************************************
  2593. ******************************************************************************
  2594. ThunderLAN Driver Eeprom routines
  2595. The Compaq Netelligent 10 and 10/100 cards use a Microchip 24C02A
  2596. EEPROM. These functions are based on information in Microchip's
  2597. data sheet. I don't know how well this functions will work with
  2598. other EEPROMs.
  2599. ******************************************************************************
  2600. *****************************************************************************/
  2601. /***************************************************************
  2602. * TLan_EeSendStart
  2603. *
  2604. * Returns:
  2605. * Nothing
  2606. * Parms:
  2607. * io_base The IO port base address for the
  2608. * TLAN device with the EEPROM to
  2609. * use.
  2610. *
  2611. * This function sends a start cycle to an EEPROM attached
  2612. * to a TLAN chip.
  2613. *
  2614. **************************************************************/
  2615. static void TLan_EeSendStart( u16 io_base )
  2616. {
  2617. u16 sio;
  2618. outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
  2619. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2620. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2621. TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
  2622. TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
  2623. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
  2624. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2625. } /* TLan_EeSendStart */
  2626. /***************************************************************
  2627. * TLan_EeSendByte
  2628. *
  2629. * Returns:
  2630. * If the correct ack was received, 0, otherwise 1
  2631. * Parms: io_base The IO port base address for the
  2632. * TLAN device with the EEPROM to
  2633. * use.
  2634. * data The 8 bits of information to
  2635. * send to the EEPROM.
  2636. * stop If TLAN_EEPROM_STOP is passed, a
  2637. * stop cycle is sent after the
  2638. * byte is sent after the ack is
  2639. * read.
  2640. *
  2641. * This function sends a byte on the serial EEPROM line,
  2642. * driving the clock to send each bit. The function then
  2643. * reverses transmission direction and reads an acknowledge
  2644. * bit.
  2645. *
  2646. **************************************************************/
  2647. static int TLan_EeSendByte( u16 io_base, u8 data, int stop )
  2648. {
  2649. int err;
  2650. u8 place;
  2651. u16 sio;
  2652. outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
  2653. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2654. /* Assume clock is low, tx is enabled; */
  2655. for ( place = 0x80; place != 0; place >>= 1 ) {
  2656. if ( place & data )
  2657. TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
  2658. else
  2659. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
  2660. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2661. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2662. }
  2663. TLan_ClearBit( TLAN_NET_SIO_ETXEN, sio );
  2664. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2665. err = TLan_GetBit( TLAN_NET_SIO_EDATA, sio );
  2666. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2667. TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
  2668. if ( ( ! err ) && stop ) {
  2669. /* STOP, raise data while clock is high */
  2670. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
  2671. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2672. TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
  2673. }
  2674. return ( err );
  2675. } /* TLan_EeSendByte */
  2676. /***************************************************************
  2677. * TLan_EeReceiveByte
  2678. *
  2679. * Returns:
  2680. * Nothing
  2681. * Parms:
  2682. * io_base The IO port base address for the
  2683. * TLAN device with the EEPROM to
  2684. * use.
  2685. * data An address to a char to hold the
  2686. * data sent from the EEPROM.
  2687. * stop If TLAN_EEPROM_STOP is passed, a
  2688. * stop cycle is sent after the
  2689. * byte is received, and no ack is
  2690. * sent.
  2691. *
  2692. * This function receives 8 bits of data from the EEPROM
  2693. * over the serial link. It then sends and ack bit, or no
  2694. * ack and a stop bit. This function is used to retrieve
  2695. * data after the address of a byte in the EEPROM has been
  2696. * sent.
  2697. *
  2698. **************************************************************/
  2699. static void TLan_EeReceiveByte( u16 io_base, u8 *data, int stop )
  2700. {
  2701. u8 place;
  2702. u16 sio;
  2703. outw( TLAN_NET_SIO, io_base + TLAN_DIO_ADR );
  2704. sio = io_base + TLAN_DIO_DATA + TLAN_NET_SIO;
  2705. *data = 0;
  2706. /* Assume clock is low, tx is enabled; */
  2707. TLan_ClearBit( TLAN_NET_SIO_ETXEN, sio );
  2708. for ( place = 0x80; place; place >>= 1 ) {
  2709. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2710. if ( TLan_GetBit( TLAN_NET_SIO_EDATA, sio ) )
  2711. *data |= place;
  2712. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2713. }
  2714. TLan_SetBit( TLAN_NET_SIO_ETXEN, sio );
  2715. if ( ! stop ) {
  2716. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio ); /* Ack = 0 */
  2717. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2718. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2719. } else {
  2720. TLan_SetBit( TLAN_NET_SIO_EDATA, sio ); /* No ack = 1 (?) */
  2721. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2722. TLan_ClearBit( TLAN_NET_SIO_ECLOK, sio );
  2723. /* STOP, raise data while clock is high */
  2724. TLan_ClearBit( TLAN_NET_SIO_EDATA, sio );
  2725. TLan_SetBit( TLAN_NET_SIO_ECLOK, sio );
  2726. TLan_SetBit( TLAN_NET_SIO_EDATA, sio );
  2727. }
  2728. } /* TLan_EeReceiveByte */
  2729. /***************************************************************
  2730. * TLan_EeReadByte
  2731. *
  2732. * Returns:
  2733. * No error = 0, else, the stage at which the error
  2734. * occurred.
  2735. * Parms:
  2736. * io_base The IO port base address for the
  2737. * TLAN device with the EEPROM to
  2738. * use.
  2739. * ee_addr The address of the byte in the
  2740. * EEPROM whose contents are to be
  2741. * retrieved.
  2742. * data An address to a char to hold the
  2743. * data obtained from the EEPROM.
  2744. *
  2745. * This function reads a byte of information from an byte
  2746. * cell in the EEPROM.
  2747. *
  2748. **************************************************************/
  2749. static int TLan_EeReadByte( struct net_device *dev, u8 ee_addr, u8 *data )
  2750. {
  2751. int err;
  2752. TLanPrivateInfo *priv = netdev_priv(dev);
  2753. unsigned long flags = 0;
  2754. int ret=0;
  2755. spin_lock_irqsave(&priv->lock, flags);
  2756. TLan_EeSendStart( dev->base_addr );
  2757. err = TLan_EeSendByte( dev->base_addr, 0xA0, TLAN_EEPROM_ACK );
  2758. if (err)
  2759. {
  2760. ret=1;
  2761. goto fail;
  2762. }
  2763. err = TLan_EeSendByte( dev->base_addr, ee_addr, TLAN_EEPROM_ACK );
  2764. if (err)
  2765. {
  2766. ret=2;
  2767. goto fail;
  2768. }
  2769. TLan_EeSendStart( dev->base_addr );
  2770. err = TLan_EeSendByte( dev->base_addr, 0xA1, TLAN_EEPROM_ACK );
  2771. if (err)
  2772. {
  2773. ret=3;
  2774. goto fail;
  2775. }
  2776. TLan_EeReceiveByte( dev->base_addr, data, TLAN_EEPROM_STOP );
  2777. fail:
  2778. spin_unlock_irqrestore(&priv->lock, flags);
  2779. return ret;
  2780. } /* TLan_EeReadByte */