tlan.c 111 KB

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