tlan.c 95 KB

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