tlan.c 95 KB

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