tlan.c 94 KB

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