tlan.c 92 KB

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