skgeinit.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367
  1. /******************************************************************************
  2. *
  3. * Name: skgeinit.c
  4. * Project: GEnesis, PCI Gigabit Ethernet Adapter
  5. * Version: $Revision: 1.85 $
  6. * Date: $Date: 2003/02/05 15:30:33 $
  7. * Purpose: Contains functions to initialize the GE HW
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2003 SysKonnect GmbH.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * The information in this file is provided "AS IS" without warranty.
  20. *
  21. ******************************************************************************/
  22. /******************************************************************************
  23. *
  24. * History:
  25. *
  26. * $Log: skgeinit.c,v $
  27. * Revision 1.85 2003/02/05 15:30:33 rschmidt
  28. * Corrected setting of GIHstClkFact (Host Clock Factor) and
  29. * GIPollTimerVal (Descr. Poll Timer Init Value) for YUKON.
  30. * Editorial changes.
  31. *
  32. * Revision 1.84 2003/01/28 09:57:25 rschmidt
  33. * Added detection of YUKON-Lite Rev. A0 (stored in GIYukonLite).
  34. * Disabled Rx GMAC FIFO Flush for YUKON-Lite Rev. A0.
  35. * Added support for CLK_RUN (YUKON-Lite).
  36. * Added additional check of PME from D3cold for setting GIVauxAvail.
  37. * Editorial changes.
  38. *
  39. * Revision 1.83 2002/12/17 16:15:41 rschmidt
  40. * Added default setting of PhyType (Copper) for YUKON.
  41. * Added define around check for HW self test results.
  42. * Editorial changes.
  43. *
  44. * Revision 1.82 2002/12/05 13:40:21 rschmidt
  45. * Added setting of Rx GMAC FIFO Flush Mask register.
  46. * Corrected PhyType with new define SK_PHY_MARV_FIBER when
  47. * YUKON Fiber board was found.
  48. * Editorial changes.
  49. *
  50. * Revision 1.81 2002/11/15 12:48:35 rschmidt
  51. * Replaced message SKERR_HWI_E018 with SKERR_HWI_E024 for Rx queue error
  52. * in SkGeStopPort().
  53. * Added init for pAC->GIni.GIGenesis with SK_FALSE in YUKON-branch.
  54. * Editorial changes.
  55. *
  56. * Revision 1.80 2002/11/12 17:28:30 rschmidt
  57. * Initialized GIPciSlot64 and GIPciClock66 in SkGeInit1().
  58. * Reduced PCI FIFO watermarks for 32bit/33MHz bus in SkGeInitBmu().
  59. * Editorial changes.
  60. *
  61. * Revision 1.79 2002/10/21 09:31:02 mkarl
  62. * Changed SkGeInitAssignRamToQueues(), removed call to
  63. * SkGeInitAssignRamToQueues in SkGeInit1 and fixed compiler warning in
  64. * SkGeInit1.
  65. *
  66. * Revision 1.78 2002/10/16 15:55:07 mkarl
  67. * Fixed a bug in SkGeInitAssignRamToQueues.
  68. *
  69. * Revision 1.77 2002/10/14 15:07:22 rschmidt
  70. * Corrected timeout handling for Rx queue in SkGeStopPort() (#10748)
  71. * Editorial changes.
  72. *
  73. * Revision 1.76 2002/10/11 09:24:38 mkarl
  74. * Added check for HW self test results.
  75. *
  76. * Revision 1.75 2002/10/09 16:56:44 mkarl
  77. * Now call SkGeInitAssignRamToQueues() in Init Level 1 in order to assign
  78. * the adapter memory to the queues. This default assignment is not suitable
  79. * for dual net mode.
  80. *
  81. * Revision 1.74 2002/09/12 08:45:06 rwahl
  82. * Set defaults for PMSCap, PLinkSpeed & PLinkSpeedCap dependent on PHY.
  83. *
  84. * Revision 1.73 2002/08/16 15:19:45 rschmidt
  85. * Corrected check for Tx queues in SkGeCheckQSize().
  86. * Added init for new entry GIGenesis and GICopperType
  87. * Replaced all if(GIChipId == CHIP_ID_GENESIS) with new entry GIGenesis.
  88. * Replaced wrong 1st para pAC with IoC in SK_IN/OUT macros.
  89. *
  90. * Revision 1.72 2002/08/12 13:38:55 rschmidt
  91. * Added check if VAUX is available (stored in GIVauxAvail)
  92. * Initialized PLinkSpeedCap in Port struct with SK_LSPEED_CAP_1000MBPS
  93. * Editorial changes.
  94. *
  95. * Revision 1.71 2002/08/08 16:32:58 rschmidt
  96. * Added check for Tx queues in SkGeCheckQSize().
  97. * Added start of Time Stamp Timer (YUKON) in SkGeInit2().
  98. * Editorial changes.
  99. *
  100. * Revision 1.70 2002/07/23 16:04:26 rschmidt
  101. * Added init for GIWolOffs (HW-Bug in YUKON 1st rev.)
  102. * Minor changes
  103. *
  104. * Revision 1.69 2002/07/17 17:07:08 rwahl
  105. * - SkGeInit1(): fixed PHY type debug output; corrected init of GIFunc
  106. * table & GIMacType.
  107. * - Editorial changes.
  108. *
  109. * Revision 1.68 2002/07/15 18:38:31 rwahl
  110. * Added initialization for MAC type dependent function table.
  111. *
  112. * Revision 1.67 2002/07/15 15:45:39 rschmidt
  113. * Added Tx Store & Forward for YUKON (GMAC Tx FIFO is only 1 kB)
  114. * Replaced SK_PHY_MARV by SK_PHY_MARV_COPPER
  115. * Editorial changes
  116. *
  117. * Revision 1.66 2002/06/10 09:35:08 rschmidt
  118. * Replaced C++ comments (//)
  119. * Editorial changes
  120. *
  121. * Revision 1.65 2002/06/05 08:33:37 rschmidt
  122. * Changed GIRamSize and Reset sequence for YUKON.
  123. * SkMacInit() replaced by SkXmInitMac() resp. SkGmInitMac()
  124. *
  125. * Revision 1.64 2002/04/25 13:03:20 rschmidt
  126. * Changes for handling YUKON.
  127. * Removed reference to xmac_ii.h (not necessary).
  128. * Moved all defines into header file.
  129. * Replaced all SkXm...() functions with SkMac...() to handle also
  130. * YUKON's GMAC.
  131. * Added handling for GMAC FIFO in SkGeInitMacFifo(), SkGeStopPort().
  132. * Removed 'goto'-directive from SkGeCfgSync(), SkGeCheckQSize().
  133. * Replaced all XMAC-access macros by functions: SkMacRxTxDisable(),
  134. * SkMacFlushTxFifo().
  135. * Optimized timeout handling in SkGeStopPort().
  136. * Initialized PLinkSpeed in Port struct with SK_LSPEED_AUTO.
  137. * Release of GMAC Link Control reset in SkGeInit1().
  138. * Initialized GIChipId and GIChipRev in GE Init structure.
  139. * Added GIRamSize and PhyType values for YUKON.
  140. * Removed use of PRxCmd to setup XMAC.
  141. * Moved setting of XM_RX_DIS_CEXT to SkXmInitMac().
  142. * Use of SkGeXmitLED() only for GENESIS.
  143. * Changes for V-CPU support.
  144. * Editorial changes.
  145. *
  146. * Revision 1.63 2001/04/05 11:02:09 rassmann
  147. * Stop Port check of the STOP bit did not take 2/18 sec as wanted.
  148. *
  149. * Revision 1.62 2001/02/07 07:54:21 rassmann
  150. * Corrected copyright.
  151. *
  152. * Revision 1.61 2001/01/31 15:31:40 gklug
  153. * fix: problem with autosensing an SR8800 switch
  154. *
  155. * Revision 1.60 2000/10/18 12:22:21 cgoos
  156. * Added workaround for half duplex hangup.
  157. *
  158. * Revision 1.59 2000/10/10 11:22:06 gklug
  159. * add: in manual half duplex mode ignore carrier extension errors
  160. *
  161. * Revision 1.58 2000/10/02 14:10:27 rassmann
  162. * Reading BCOM PHY after releasing reset until it returns a valid value.
  163. *
  164. * Revision 1.57 2000/08/03 14:55:28 rassmann
  165. * Waiting for I2C to be ready before de-initializing adapter
  166. * (prevents sensors from hanging up).
  167. *
  168. * Revision 1.56 2000/07/27 12:16:48 gklug
  169. * fix: Stop Port check of the STOP bit does now take 2/18 sec as wanted
  170. *
  171. * Revision 1.55 1999/11/22 13:32:26 cgoos
  172. * Changed license header to GPL.
  173. *
  174. * Revision 1.54 1999/10/26 07:32:54 malthoff
  175. * Initialize PHWLinkUp with SK_FALSE. Required for Diagnostics.
  176. *
  177. * Revision 1.53 1999/08/12 19:13:50 malthoff
  178. * Fix for 1000BT. Do not owerwrite XM_MMU_CMD when
  179. * disabling receiver and transmitter. Other bits
  180. * may be lost.
  181. *
  182. * Revision 1.52 1999/07/01 09:29:54 gklug
  183. * fix: DoInitRamQueue needs pAC
  184. *
  185. * Revision 1.51 1999/07/01 08:42:21 gklug
  186. * chg: use Store & forward for RAM buffer when Jumbos are used
  187. *
  188. * Revision 1.50 1999/05/27 13:19:38 cgoos
  189. * Added Tx PCI watermark initialization.
  190. * Removed Tx RAM queue Store & Forward setting.
  191. *
  192. * Revision 1.49 1999/05/20 14:32:45 malthoff
  193. * SkGeLinkLED() is completly removed now.
  194. *
  195. * Revision 1.48 1999/05/19 07:28:24 cgoos
  196. * SkGeLinkLED no more available for drivers.
  197. * Changes for 1000Base-T.
  198. *
  199. * Revision 1.47 1999/04/08 13:57:45 gklug
  200. * add: Init of new port struct fiels PLinkResCt
  201. * chg: StopPort Timer check
  202. *
  203. * Revision 1.46 1999/03/25 07:42:15 malthoff
  204. * SkGeStopPort(): Add workaround for cache incoherency.
  205. * Create error log entry, disable port, and
  206. * exit loop if it does not terminate.
  207. * Add XM_RX_LENERR_OK to the default value for the
  208. * XMAC receive command register.
  209. *
  210. * Revision 1.45 1999/03/12 16:24:47 malthoff
  211. * Remove PPollRxD and PPollTxD.
  212. * Add check for GIPollTimerVal.
  213. *
  214. * Revision 1.44 1999/03/12 13:40:23 malthoff
  215. * Fix: SkGeXmitLED(), SK_LED_TST mode does not work.
  216. * Add: Jumbo frame support.
  217. * Chg: Resolution of parameter IntTime in SkGeCfgSync().
  218. *
  219. * Revision 1.43 1999/02/09 10:29:46 malthoff
  220. * Bugfix: The previous modification again also for the second location.
  221. *
  222. * Revision 1.42 1999/02/09 09:35:16 malthoff
  223. * Bugfix: The bits '66 MHz Capable' and 'NEWCAP are reset while
  224. * clearing the error bits in the PCI status register.
  225. *
  226. * Revision 1.41 1999/01/18 13:07:02 malthoff
  227. * Bugfix: Do not use CFG cycles after during Init- or Runtime, because
  228. * they may not be available after Boottime.
  229. *
  230. * Revision 1.40 1999/01/11 12:40:49 malthoff
  231. * Bug fix: PCI_STATUS: clearing error bits sets the UDF bit.
  232. *
  233. * Revision 1.39 1998/12/11 15:17:33 gklug
  234. * chg: Init LipaAutoNeg with Unknown
  235. *
  236. * Revision 1.38 1998/12/10 11:02:57 malthoff
  237. * Disable Error Log Message when calling SkGeInit(level 2)
  238. * more than once.
  239. *
  240. * Revision 1.37 1998/12/07 12:18:25 gklug
  241. * add: refinement of autosense mode: take into account the autoneg cap of LiPa
  242. *
  243. * Revision 1.36 1998/12/07 07:10:39 gklug
  244. * fix: init values of LinkBroken/ Capabilities for management
  245. *
  246. * Revision 1.35 1998/12/02 10:56:20 gklug
  247. * fix: do NOT init LoinkSync Counter.
  248. *
  249. * Revision 1.34 1998/12/01 10:53:21 gklug
  250. * add: init of additional Counters for workaround
  251. *
  252. * Revision 1.33 1998/12/01 10:00:49 gklug
  253. * add: init PIsave var in Port struct
  254. *
  255. * Revision 1.32 1998/11/26 14:50:40 gklug
  256. * chg: Default is autosensing with AUTOFULL mode
  257. *
  258. * Revision 1.31 1998/11/25 15:36:16 gklug
  259. * fix: do NOT stop LED Timer when port should be stopped
  260. *
  261. * Revision 1.30 1998/11/24 13:15:28 gklug
  262. * add: Init PCkeckPar struct member
  263. *
  264. * Revision 1.29 1998/11/18 13:19:27 malthoff
  265. * Disable packet arbiter timeouts on receive side.
  266. * Use maximum timeout value for packet arbiter
  267. * transmit timeouts.
  268. * Add TestStopBit() function to handle stop RX/TX
  269. * problem with active descriptor poll timers.
  270. * Bug Fix: Descriptor Poll Timer not started, because
  271. * GIPollTimerVal was initialized with 0.
  272. *
  273. * Revision 1.28 1998/11/13 14:24:26 malthoff
  274. * Bug Fix: SkGeStopPort() may hang if a Packet Arbiter Timout
  275. * is pending or occurs while waiting for TX_STOP and RX_STOP.
  276. * The PA timeout is cleared now while waiting for TX- or RX_STOP.
  277. *
  278. * Revision 1.27 1998/11/02 11:04:36 malthoff
  279. * fix the last fix
  280. *
  281. * Revision 1.26 1998/11/02 10:37:03 malthoff
  282. * Fix: SkGePollTxD() enables always the synchronounous poll timer.
  283. *
  284. * Revision 1.25 1998/10/28 07:12:43 cgoos
  285. * Fixed "LED_STOP" in SkGeLnkSyncCnt, "== SK_INIT_IO" in SkGeInit.
  286. * Removed: Reset of RAM Interface in SkGeStopPort.
  287. *
  288. * Revision 1.24 1998/10/27 08:13:12 malthoff
  289. * Remove temporary code.
  290. *
  291. * Revision 1.23 1998/10/26 07:45:03 malthoff
  292. * Add Address Calculation Workaround: If the EPROM byte
  293. * Id is 3, the address offset is 512 kB.
  294. * Initialize default values for PLinkMode and PFlowCtrlMode.
  295. *
  296. * Revision 1.22 1998/10/22 09:46:47 gklug
  297. * fix SysKonnectFileId typo
  298. *
  299. * Revision 1.21 1998/10/20 12:11:56 malthoff
  300. * Don't dendy the Queue config if the size of the unused
  301. * Rx qeueu is zero.
  302. *
  303. * Revision 1.20 1998/10/19 07:27:58 malthoff
  304. * SkGeInitRamIface() is public to be called by diagnostics.
  305. *
  306. * Revision 1.19 1998/10/16 13:33:45 malthoff
  307. * Fix: enabling descriptor polling is not allowed until
  308. * the descriptor addresses are set. Descriptor polling
  309. * must be handled by the driver.
  310. *
  311. * Revision 1.18 1998/10/16 10:58:27 malthoff
  312. * Remove temp. code for Diag prototype.
  313. * Remove lint warning for dummy reads.
  314. * Call SkGeLoadLnkSyncCnt() during SkGeInitPort().
  315. *
  316. * Revision 1.17 1998/10/14 09:16:06 malthoff
  317. * Change parameter LimCount and programming of
  318. * the limit counter in SkGeCfgSync().
  319. *
  320. * Revision 1.16 1998/10/13 09:21:16 malthoff
  321. * Don't set XM_RX_SELF_RX in RxCmd Reg, because it's
  322. * like a Loopback Mode in half duplex.
  323. *
  324. * Revision 1.15 1998/10/09 06:47:40 malthoff
  325. * SkGeInitMacArb(): set recovery counters init value
  326. * to zero although this counters are not uesd.
  327. * Bug fix in Rx Upper/Lower Pause Threshold calculation.
  328. * Add XM_RX_SELF_RX to RxCmd.
  329. *
  330. * Revision 1.14 1998/10/06 15:15:53 malthoff
  331. * Make sure no pending IRQ is cleared in SkGeLoadLnkSyncCnt().
  332. *
  333. * Revision 1.13 1998/10/06 14:09:36 malthoff
  334. * Add SkGeLoadLnkSyncCnt(). Modify
  335. * the 'port stopped' condition according
  336. * to the current problem report.
  337. *
  338. * Revision 1.12 1998/10/05 08:17:21 malthoff
  339. * Add functions: SkGePollRxD(), SkGePollTxD(),
  340. * DoCalcAddr(), SkGeCheckQSize(),
  341. * DoInitRamQueue(), and SkGeCfgSync().
  342. * Add coding for SkGeInitMacArb(), SkGeInitPktArb(),
  343. * SkGeInitMacFifo(), SkGeInitRamBufs(),
  344. * SkGeInitRamIface(), and SkGeInitBmu().
  345. *
  346. * Revision 1.11 1998/09/29 08:26:29 malthoff
  347. * bug fix: SkGeInit0() 'i' should be increment.
  348. *
  349. * Revision 1.10 1998/09/28 13:19:01 malthoff
  350. * Coding time: Save the done work.
  351. * Modify SkGeLinkLED(), add SkGeXmitLED(),
  352. * define SkGeCheckQSize(), SkGeInitMacArb(),
  353. * SkGeInitPktArb(), SkGeInitMacFifo(),
  354. * SkGeInitRamBufs(), SkGeInitRamIface(),
  355. * and SkGeInitBmu(). Do coding for SkGeStopPort(),
  356. * SkGeInit1(), SkGeInit2(), and SkGeInit3().
  357. * Do coding for SkGeDinit() and SkGeInitPort().
  358. *
  359. * Revision 1.9 1998/09/16 14:29:05 malthoff
  360. * Some minor changes.
  361. *
  362. * Revision 1.8 1998/09/11 05:29:14 gklug
  363. * add: init state of a port
  364. *
  365. * Revision 1.7 1998/09/04 09:26:25 malthoff
  366. * Short temporary modification.
  367. *
  368. * Revision 1.6 1998/09/04 08:27:59 malthoff
  369. * Remark the do-while in StopPort() because it never ends
  370. * without a GE adapter.
  371. *
  372. * Revision 1.5 1998/09/03 14:05:45 malthoff
  373. * Change comment for SkGeInitPort(). Do not
  374. * repair the queue sizes if invalid.
  375. *
  376. * Revision 1.4 1998/09/03 10:03:19 malthoff
  377. * Implement the new interface according to the
  378. * reviewed interface specification.
  379. *
  380. * Revision 1.3 1998/08/19 09:11:25 gklug
  381. * fix: struct are removed from c-source (see CCC)
  382. *
  383. * Revision 1.2 1998/07/28 12:33:58 malthoff
  384. * Add 'IoC' parameter in function declaration and SK IO macros.
  385. *
  386. * Revision 1.1 1998/07/23 09:48:57 malthoff
  387. * Creation. First dummy 'C' file.
  388. * SkGeInit(Level 0) is card_start for GE.
  389. * SkGeDeInit() is card_stop for GE.
  390. *
  391. *
  392. ******************************************************************************/
  393. #include <config.h>
  394. #include "h/skdrv1st.h"
  395. #include "h/skdrv2nd.h"
  396. /* global variables ***********************************************************/
  397. /* local variables ************************************************************/
  398. static const char SysKonnectFileId[] =
  399. "@(#)$Id: skgeinit.c,v 1.85 2003/02/05 15:30:33 rschmidt Exp $ (C) SK ";
  400. struct s_QOffTab {
  401. int RxQOff; /* Receive Queue Address Offset */
  402. int XsQOff; /* Sync Tx Queue Address Offset */
  403. int XaQOff; /* Async Tx Queue Address Offset */
  404. };
  405. static struct s_QOffTab QOffTab[] = {
  406. {Q_R1, Q_XS1, Q_XA1}, {Q_R2, Q_XS2, Q_XA2}
  407. };
  408. /******************************************************************************
  409. *
  410. * SkGePollRxD() - Enable / Disable Descriptor Polling of RxD Ring
  411. *
  412. * Description:
  413. * Enable or disable the descriptor polling of the receive descriptor
  414. * ring (RxD) for port 'Port'.
  415. * The new configuration is *not* saved over any SkGeStopPort() and
  416. * SkGeInitPort() calls.
  417. *
  418. * Returns:
  419. * nothing
  420. */
  421. void SkGePollRxD(
  422. SK_AC *pAC, /* adapter context */
  423. SK_IOC IoC, /* IO context */
  424. int Port, /* Port Index (MAC_1 + n) */
  425. SK_BOOL PollRxD) /* SK_TRUE (enable pol.), SK_FALSE (disable pol.) */
  426. {
  427. SK_GEPORT *pPrt;
  428. pPrt = &pAC->GIni.GP[Port];
  429. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), (PollRxD) ?
  430. CSR_ENA_POL : CSR_DIS_POL);
  431. } /* SkGePollRxD */
  432. /******************************************************************************
  433. *
  434. * SkGePollTxD() - Enable / Disable Descriptor Polling of TxD Rings
  435. *
  436. * Description:
  437. * Enable or disable the descriptor polling of the transmit descriptor
  438. * ring(s) (TxD) for port 'Port'.
  439. * The new configuration is *not* saved over any SkGeStopPort() and
  440. * SkGeInitPort() calls.
  441. *
  442. * Returns:
  443. * nothing
  444. */
  445. void SkGePollTxD(
  446. SK_AC *pAC, /* adapter context */
  447. SK_IOC IoC, /* IO context */
  448. int Port, /* Port Index (MAC_1 + n) */
  449. SK_BOOL PollTxD) /* SK_TRUE (enable pol.), SK_FALSE (disable pol.) */
  450. {
  451. SK_GEPORT *pPrt;
  452. SK_U32 DWord;
  453. pPrt = &pAC->GIni.GP[Port];
  454. DWord = (PollTxD) ? CSR_ENA_POL : CSR_DIS_POL;
  455. if (pPrt->PXSQSize != 0) {
  456. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), DWord);
  457. }
  458. if (pPrt->PXAQSize != 0) {
  459. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), DWord);
  460. }
  461. } /* SkGePollTxD */
  462. /******************************************************************************
  463. *
  464. * SkGeYellowLED() - Switch the yellow LED on or off.
  465. *
  466. * Description:
  467. * Switch the yellow LED on or off.
  468. *
  469. * Note:
  470. * This function may be called any time after SkGeInit(Level 1).
  471. *
  472. * Returns:
  473. * nothing
  474. */
  475. void SkGeYellowLED(
  476. SK_AC *pAC, /* adapter context */
  477. SK_IOC IoC, /* IO context */
  478. int State) /* yellow LED state, 0 = OFF, 0 != ON */
  479. {
  480. if (State == 0) {
  481. /* Switch yellow LED OFF */
  482. SK_OUT8(IoC, B0_LED, LED_STAT_OFF);
  483. }
  484. else {
  485. /* Switch yellow LED ON */
  486. SK_OUT8(IoC, B0_LED, LED_STAT_ON);
  487. }
  488. } /* SkGeYellowLED */
  489. /******************************************************************************
  490. *
  491. * SkGeXmitLED() - Modify the Operational Mode of a transmission LED.
  492. *
  493. * Description:
  494. * The Rx or Tx LED which is specified by 'Led' will be
  495. * enabled, disabled or switched on in test mode.
  496. *
  497. * Note:
  498. * 'Led' must contain the address offset of the LEDs INI register.
  499. *
  500. * Usage:
  501. * SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_ENA);
  502. *
  503. * Returns:
  504. * nothing
  505. */
  506. void SkGeXmitLED(
  507. SK_AC *pAC, /* adapter context */
  508. SK_IOC IoC, /* IO context */
  509. int Led, /* offset to the LED Init Value register */
  510. int Mode) /* Mode may be SK_LED_DIS, SK_LED_ENA, SK_LED_TST */
  511. {
  512. SK_U32 LedIni;
  513. switch (Mode) {
  514. case SK_LED_ENA:
  515. LedIni = SK_XMIT_DUR * (SK_U32)pAC->GIni.GIHstClkFact / 100;
  516. SK_OUT32(IoC, Led + XMIT_LED_INI, LedIni);
  517. SK_OUT8(IoC, Led + XMIT_LED_CTRL, LED_START);
  518. break;
  519. case SK_LED_TST:
  520. SK_OUT8(IoC, Led + XMIT_LED_TST, LED_T_ON);
  521. SK_OUT32(IoC, Led + XMIT_LED_CNT, 100);
  522. SK_OUT8(IoC, Led + XMIT_LED_CTRL, LED_START);
  523. break;
  524. case SK_LED_DIS:
  525. default:
  526. /*
  527. * Do NOT stop the LED Timer here. The LED might be
  528. * in on state. But it needs to go off.
  529. */
  530. SK_OUT32(IoC, Led + XMIT_LED_CNT, 0);
  531. SK_OUT8(IoC, Led + XMIT_LED_TST, LED_T_OFF);
  532. break;
  533. }
  534. /*
  535. * 1000BT: The Transmit LED is driven by the PHY.
  536. * But the default LED configuration is used for
  537. * Level One and Broadcom PHYs.
  538. * (Broadcom: It may be that PHY_B_PEC_EN_LTR has to be set.)
  539. * (In this case it has to be added here. But we will see. XXX)
  540. */
  541. } /* SkGeXmitLED */
  542. /******************************************************************************
  543. *
  544. * DoCalcAddr() - Calculates the start and the end address of a queue.
  545. *
  546. * Description:
  547. * This function calculates the start and the end address of a queue.
  548. * Afterwards the 'StartVal' is incremented to the next start position.
  549. * If the port is already initialized the calculated values
  550. * will be checked against the configured values and an
  551. * error will be returned, if they are not equal.
  552. * If the port is not initialized the values will be written to
  553. * *StartAdr and *EndAddr.
  554. *
  555. * Returns:
  556. * 0: success
  557. * 1: configuration error
  558. */
  559. static int DoCalcAddr(
  560. SK_AC *pAC, /* adapter context */
  561. SK_GEPORT *pPrt, /* port index */
  562. int QuSize, /* size of the queue to configure in kB */
  563. SK_U32 *StartVal, /* start value for address calculation */
  564. SK_U32 *QuStartAddr, /* start addr to calculate */
  565. SK_U32 *QuEndAddr) /* end address to calculate */
  566. {
  567. SK_U32 EndVal;
  568. SK_U32 NextStart;
  569. int Rtv;
  570. Rtv = 0;
  571. if (QuSize == 0) {
  572. EndVal = *StartVal;
  573. NextStart = EndVal;
  574. }
  575. else {
  576. EndVal = *StartVal + ((SK_U32)QuSize * 1024) - 1;
  577. NextStart = EndVal + 1;
  578. }
  579. if (pPrt->PState >= SK_PRT_INIT) {
  580. if (*StartVal != *QuStartAddr || EndVal != *QuEndAddr) {
  581. Rtv = 1;
  582. }
  583. }
  584. else {
  585. *QuStartAddr = *StartVal;
  586. *QuEndAddr = EndVal;
  587. }
  588. *StartVal = NextStart;
  589. return(Rtv);
  590. } /* DoCalcAddr */
  591. /******************************************************************************
  592. *
  593. * SkGeInitAssignRamToQueues() - allocate default queue sizes
  594. *
  595. * Description:
  596. * This function assigns the memory to the different queues and ports.
  597. * When DualNet is set to SK_TRUE all ports get the same amount of memory.
  598. * Otherwise the first port gets most of the memory and all the
  599. * other ports just the required minimum.
  600. * This function can only be called when pAC->GIni.GIRamSize and
  601. * pAC->GIni.GIMacsFound have been initialized, usually this happens
  602. * at init level 1
  603. *
  604. * Returns:
  605. * 0 - ok
  606. * 1 - invalid input values
  607. * 2 - not enough memory
  608. */
  609. int SkGeInitAssignRamToQueues(
  610. SK_AC *pAC, /* Adapter context */
  611. int ActivePort, /* Active Port in RLMT mode */
  612. SK_BOOL DualNet) /* adapter context */
  613. {
  614. int i;
  615. int UsedKilobytes; /* memory already assigned */
  616. int ActivePortKilobytes; /* memory available for active port */
  617. SK_GEPORT *pGePort;
  618. UsedKilobytes = 0;
  619. if (ActivePort >= pAC->GIni.GIMacsFound) {
  620. SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
  621. ("SkGeInitAssignRamToQueues: ActivePort (%d) invalid\n",
  622. ActivePort));
  623. return(1);
  624. }
  625. if (((pAC->GIni.GIMacsFound * (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE)) +
  626. ((RAM_QUOTA_SYNC == 0) ? 0 : SK_MIN_TXQ_SIZE)) > pAC->GIni.GIRamSize) {
  627. SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
  628. ("SkGeInitAssignRamToQueues: Not enough memory (%d)\n",
  629. pAC->GIni.GIRamSize));
  630. return(2);
  631. }
  632. if (DualNet) {
  633. /* every port gets the same amount of memory */
  634. ActivePortKilobytes = pAC->GIni.GIRamSize / pAC->GIni.GIMacsFound;
  635. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  636. pGePort = &pAC->GIni.GP[i];
  637. /* take away the minimum memory for active queues */
  638. ActivePortKilobytes -= (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE);
  639. /* receive queue gets the minimum + 80% of the rest */
  640. pGePort->PRxQSize = (int) (ROUND_QUEUE_SIZE_KB((
  641. ActivePortKilobytes * (unsigned long) RAM_QUOTA_RX) / 100))
  642. + SK_MIN_RXQ_SIZE;
  643. ActivePortKilobytes -= (pGePort->PRxQSize - SK_MIN_RXQ_SIZE);
  644. /* synchronous transmit queue */
  645. pGePort->PXSQSize = 0;
  646. /* asynchronous transmit queue */
  647. pGePort->PXAQSize = (int) ROUND_QUEUE_SIZE_KB(ActivePortKilobytes +
  648. SK_MIN_TXQ_SIZE);
  649. }
  650. }
  651. else {
  652. /* Rlmt Mode or single link adapter */
  653. /* Set standby queue size defaults for all standby ports */
  654. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  655. if (i != ActivePort) {
  656. pGePort = &pAC->GIni.GP[i];
  657. pGePort->PRxQSize = SK_MIN_RXQ_SIZE;
  658. pGePort->PXAQSize = SK_MIN_TXQ_SIZE;
  659. pGePort->PXSQSize = 0;
  660. /* Count used RAM */
  661. UsedKilobytes += pGePort->PRxQSize + pGePort->PXAQSize;
  662. }
  663. }
  664. /* what's left? */
  665. ActivePortKilobytes = pAC->GIni.GIRamSize - UsedKilobytes;
  666. /* assign it to the active port */
  667. /* first take away the minimum memory */
  668. ActivePortKilobytes -= (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE);
  669. pGePort = &pAC->GIni.GP[ActivePort];
  670. /* receive queue get's the minimum + 80% of the rest */
  671. pGePort->PRxQSize = (int) (ROUND_QUEUE_SIZE_KB((ActivePortKilobytes *
  672. (unsigned long) RAM_QUOTA_RX) / 100)) + SK_MIN_RXQ_SIZE;
  673. ActivePortKilobytes -= (pGePort->PRxQSize - SK_MIN_RXQ_SIZE);
  674. /* synchronous transmit queue */
  675. pGePort->PXSQSize = 0;
  676. /* asynchronous transmit queue */
  677. pGePort->PXAQSize = (int) ROUND_QUEUE_SIZE_KB(ActivePortKilobytes) +
  678. SK_MIN_TXQ_SIZE;
  679. }
  680. #ifdef VCPU
  681. VCPUprintf(0, "PRxQSize=%u, PXSQSize=%u, PXAQSize=%u\n",
  682. pGePort->PRxQSize, pGePort->PXSQSize, pGePort->PXAQSize);
  683. #endif /* VCPU */
  684. return(0);
  685. } /* SkGeInitAssignRamToQueues */
  686. /******************************************************************************
  687. *
  688. * SkGeCheckQSize() - Checks the Adapters Queue Size Configuration
  689. *
  690. * Description:
  691. * This function verifies the Queue Size Configuration specified
  692. * in the variables PRxQSize, PXSQSize, and PXAQSize of all
  693. * used ports.
  694. * This requirements must be fullfilled to have a valid configuration:
  695. * - The size of all queues must not exceed GIRamSize.
  696. * - The queue sizes must be specified in units of 8 kB.
  697. * - The size of Rx queues of available ports must not be
  698. * smaller than 16 kB.
  699. * - The size of at least one Tx queue (synch. or asynch.)
  700. * of available ports must not be smaller than 16 kB
  701. * when Jumbo Frames are used.
  702. * - The RAM start and end addresses must not be changed
  703. * for ports which are already initialized.
  704. * Furthermore SkGeCheckQSize() defines the Start and End Addresses
  705. * of all ports and stores them into the HWAC port structure.
  706. *
  707. * Returns:
  708. * 0: Queue Size Configuration valid
  709. * 1: Queue Size Configuration invalid
  710. */
  711. static int SkGeCheckQSize(
  712. SK_AC *pAC, /* adapter context */
  713. int Port) /* port index */
  714. {
  715. SK_GEPORT *pPrt;
  716. int UsedMem; /* total memory used (max. found ports) */
  717. int i;
  718. int Rtv;
  719. int Rtv2;
  720. SK_U32 StartAddr;
  721. UsedMem = 0;
  722. Rtv = 0;
  723. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  724. pPrt = &pAC->GIni.GP[i];
  725. if ((pPrt->PRxQSize & QZ_UNITS) != 0 ||
  726. (pPrt->PXSQSize & QZ_UNITS) != 0 ||
  727. (pPrt->PXAQSize & QZ_UNITS) != 0) {
  728. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E012, SKERR_HWI_E012MSG);
  729. return(1);
  730. }
  731. if (i == Port && pPrt->PRxQSize < SK_MIN_RXQ_SIZE) {
  732. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E011, SKERR_HWI_E011MSG);
  733. return(1);
  734. }
  735. /*
  736. * the size of at least one Tx queue (synch. or asynch.) has to be > 0.
  737. * if Jumbo Frames are used, this size has to be >= 16 kB.
  738. */
  739. if ((i == Port && pPrt->PXSQSize == 0 && pPrt->PXAQSize == 0) ||
  740. (pAC->GIni.GIPortUsage == SK_JUMBO_LINK &&
  741. ((pPrt->PXSQSize > 0 && pPrt->PXSQSize < SK_MIN_TXQ_SIZE) ||
  742. (pPrt->PXAQSize > 0 && pPrt->PXAQSize < SK_MIN_TXQ_SIZE)))) {
  743. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E023, SKERR_HWI_E023MSG);
  744. return(1);
  745. }
  746. UsedMem += pPrt->PRxQSize + pPrt->PXSQSize + pPrt->PXAQSize;
  747. }
  748. if (UsedMem > pAC->GIni.GIRamSize) {
  749. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E012, SKERR_HWI_E012MSG);
  750. return(1);
  751. }
  752. /* Now start address calculation */
  753. StartAddr = pAC->GIni.GIRamOffs;
  754. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  755. pPrt = &pAC->GIni.GP[i];
  756. /* Calculate/Check values for the receive queue */
  757. Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PRxQSize, &StartAddr,
  758. &pPrt->PRxQRamStart, &pPrt->PRxQRamEnd);
  759. Rtv |= Rtv2;
  760. /* Calculate/Check values for the synchronous Tx queue */
  761. Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PXSQSize, &StartAddr,
  762. &pPrt->PXsQRamStart, &pPrt->PXsQRamEnd);
  763. Rtv |= Rtv2;
  764. /* Calculate/Check values for the asynchronous Tx queue */
  765. Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PXAQSize, &StartAddr,
  766. &pPrt->PXaQRamStart, &pPrt->PXaQRamEnd);
  767. Rtv |= Rtv2;
  768. if (Rtv) {
  769. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E013, SKERR_HWI_E013MSG);
  770. return(1);
  771. }
  772. }
  773. return(0);
  774. } /* SkGeCheckQSize */
  775. /******************************************************************************
  776. *
  777. * SkGeInitMacArb() - Initialize the MAC Arbiter
  778. *
  779. * Description:
  780. * This function initializes the MAC Arbiter.
  781. * It must not be called if there is still an
  782. * initialized or active port.
  783. *
  784. * Returns:
  785. * nothing
  786. */
  787. static void SkGeInitMacArb(
  788. SK_AC *pAC, /* adapter context */
  789. SK_IOC IoC) /* IO context */
  790. {
  791. /* release local reset */
  792. SK_OUT16(IoC, B3_MA_TO_CTRL, MA_RST_CLR);
  793. /* configure timeout values */
  794. SK_OUT8(IoC, B3_MA_TOINI_RX1, SK_MAC_TO_53);
  795. SK_OUT8(IoC, B3_MA_TOINI_RX2, SK_MAC_TO_53);
  796. SK_OUT8(IoC, B3_MA_TOINI_TX1, SK_MAC_TO_53);
  797. SK_OUT8(IoC, B3_MA_TOINI_TX2, SK_MAC_TO_53);
  798. SK_OUT8(IoC, B3_MA_RCINI_RX1, 0);
  799. SK_OUT8(IoC, B3_MA_RCINI_RX2, 0);
  800. SK_OUT8(IoC, B3_MA_RCINI_TX1, 0);
  801. SK_OUT8(IoC, B3_MA_RCINI_TX2, 0);
  802. /* recovery values are needed for XMAC II Rev. B2 only */
  803. /* Fast Output Enable Mode was intended to use with Rev. B2, but now? */
  804. /*
  805. * There is no start or enable button to push, therefore
  806. * the MAC arbiter is configured and enabled now.
  807. */
  808. } /* SkGeInitMacArb */
  809. /******************************************************************************
  810. *
  811. * SkGeInitPktArb() - Initialize the Packet Arbiter
  812. *
  813. * Description:
  814. * This function initializes the Packet Arbiter.
  815. * It must not be called if there is still an
  816. * initialized or active port.
  817. *
  818. * Returns:
  819. * nothing
  820. */
  821. static void SkGeInitPktArb(
  822. SK_AC *pAC, /* adapter context */
  823. SK_IOC IoC) /* IO context */
  824. {
  825. /* release local reset */
  826. SK_OUT16(IoC, B3_PA_CTRL, PA_RST_CLR);
  827. /* configure timeout values */
  828. SK_OUT16(IoC, B3_PA_TOINI_RX1, SK_PKT_TO_MAX);
  829. SK_OUT16(IoC, B3_PA_TOINI_RX2, SK_PKT_TO_MAX);
  830. SK_OUT16(IoC, B3_PA_TOINI_TX1, SK_PKT_TO_MAX);
  831. SK_OUT16(IoC, B3_PA_TOINI_TX2, SK_PKT_TO_MAX);
  832. /*
  833. * enable timeout timers if jumbo frames not used
  834. * NOTE: the packet arbiter timeout interrupt is needed for
  835. * half duplex hangup workaround
  836. */
  837. if (pAC->GIni.GIPortUsage != SK_JUMBO_LINK) {
  838. if (pAC->GIni.GIMacsFound == 1) {
  839. SK_OUT16(IoC, B3_PA_CTRL, PA_ENA_TO_TX1);
  840. }
  841. else {
  842. SK_OUT16(IoC, B3_PA_CTRL, PA_ENA_TO_TX1 | PA_ENA_TO_TX2);
  843. }
  844. }
  845. } /* SkGeInitPktArb */
  846. /******************************************************************************
  847. *
  848. * SkGeInitMacFifo() - Initialize the MAC FIFOs
  849. *
  850. * Description:
  851. * Initialize all MAC FIFOs of the specified port
  852. *
  853. * Returns:
  854. * nothing
  855. */
  856. static void SkGeInitMacFifo(
  857. SK_AC *pAC, /* adapter context */
  858. SK_IOC IoC, /* IO context */
  859. int Port) /* Port Index (MAC_1 + n) */
  860. {
  861. SK_U16 Word;
  862. #ifdef VCPU
  863. SK_U32 DWord;
  864. #endif /* VCPU */
  865. /*
  866. * For each FIFO:
  867. * - release local reset
  868. * - use default value for MAC FIFO size
  869. * - setup defaults for the control register
  870. * - enable the FIFO
  871. */
  872. Word = GMF_RX_CTRL_DEF;
  873. if (pAC->GIni.GIGenesis) {
  874. /* Configure Rx MAC FIFO */
  875. SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_RST_CLR);
  876. SK_OUT16(IoC, MR_ADDR(Port, RX_MFF_CTRL1), MFF_RX_CTRL_DEF);
  877. SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
  878. /* Configure Tx MAC FIFO */
  879. SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_RST_CLR);
  880. SK_OUT16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
  881. SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
  882. /* Enable frame flushing if jumbo frames used */
  883. if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK) {
  884. SK_OUT16(IoC, MR_ADDR(Port, RX_MFF_CTRL1), MFF_ENA_FLUSH);
  885. }
  886. }
  887. else {
  888. /* set Rx GMAC FIFO Flush Mask */
  889. SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_FL_MSK), (SK_U16)RX_FF_FL_DEF_MSK);
  890. if (pAC->GIni.GIYukonLite && pAC->GIni.GIChipId == CHIP_ID_YUKON) {
  891. Word &= ~GMF_RX_F_FL_ON;
  892. }
  893. /* Configure Rx MAC FIFO */
  894. SK_OUT8(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), (SK_U8)GMF_RST_CLR);
  895. SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), Word);
  896. /* set Rx GMAC FIFO Flush Threshold (default: 0x0a -> 56 bytes) */
  897. SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF);
  898. /* Configure Tx MAC FIFO */
  899. SK_OUT8(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U8)GMF_RST_CLR);
  900. SK_OUT16(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U16)GMF_TX_CTRL_DEF);
  901. #ifdef VCPU
  902. SK_IN32(IoC, MR_ADDR(Port, RX_GMF_AF_THR), &DWord);
  903. SK_IN32(IoC, MR_ADDR(Port, TX_GMF_AE_THR), &DWord);
  904. #endif /* VCPU */
  905. /* set Tx GMAC FIFO Almost Empty Threshold */
  906. /* SK_OUT32(IoC, MR_ADDR(Port, TX_GMF_AE_THR), 0); */
  907. }
  908. } /* SkGeInitMacFifo */
  909. /******************************************************************************
  910. *
  911. * SkGeLoadLnkSyncCnt() - Load the Link Sync Counter and starts counting
  912. *
  913. * Description:
  914. * This function starts the Link Sync Counter of the specified
  915. * port and enables the generation of an Link Sync IRQ.
  916. * The Link Sync Counter may be used to detect an active link,
  917. * if autonegotiation is not used.
  918. *
  919. * Note:
  920. * o To ensure receiving the Link Sync Event the LinkSyncCounter
  921. * should be initialized BEFORE clearing the XMAC's reset!
  922. * o Enable IS_LNK_SYNC_M1 and IS_LNK_SYNC_M2 after calling this
  923. * function.
  924. *
  925. * Returns:
  926. * nothing
  927. */
  928. void SkGeLoadLnkSyncCnt(
  929. SK_AC *pAC, /* adapter context */
  930. SK_IOC IoC, /* IO context */
  931. int Port, /* Port Index (MAC_1 + n) */
  932. SK_U32 CntVal) /* Counter value */
  933. {
  934. SK_U32 OrgIMsk;
  935. SK_U32 NewIMsk;
  936. SK_U32 ISrc;
  937. SK_BOOL IrqPend;
  938. /* stop counter */
  939. SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_STOP);
  940. /*
  941. * ASIC problem:
  942. * Each time starting the Link Sync Counter an IRQ is generated
  943. * by the adapter. See problem report entry from 21.07.98
  944. *
  945. * Workaround: Disable Link Sync IRQ and clear the unexpeced IRQ
  946. * if no IRQ is already pending.
  947. */
  948. IrqPend = SK_FALSE;
  949. SK_IN32(IoC, B0_ISRC, &ISrc);
  950. SK_IN32(IoC, B0_IMSK, &OrgIMsk);
  951. if (Port == MAC_1) {
  952. NewIMsk = OrgIMsk & ~IS_LNK_SYNC_M1;
  953. if ((ISrc & IS_LNK_SYNC_M1) != 0) {
  954. IrqPend = SK_TRUE;
  955. }
  956. }
  957. else {
  958. NewIMsk = OrgIMsk & ~IS_LNK_SYNC_M2;
  959. if ((ISrc & IS_LNK_SYNC_M2) != 0) {
  960. IrqPend = SK_TRUE;
  961. }
  962. }
  963. if (!IrqPend) {
  964. SK_OUT32(IoC, B0_IMSK, NewIMsk);
  965. }
  966. /* load counter */
  967. SK_OUT32(IoC, MR_ADDR(Port, LNK_SYNC_INI), CntVal);
  968. /* start counter */
  969. SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_START);
  970. if (!IrqPend) {
  971. /* clear the unexpected IRQ, and restore the interrupt mask */
  972. SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_CLR_IRQ);
  973. SK_OUT32(IoC, B0_IMSK, OrgIMsk);
  974. }
  975. } /* SkGeLoadLnkSyncCnt*/
  976. /******************************************************************************
  977. *
  978. * SkGeCfgSync() - Configure synchronous bandwidth for this port.
  979. *
  980. * Description:
  981. * This function may be used to configure synchronous bandwidth
  982. * to the specified port. This may be done any time after
  983. * initializing the port. The configuration values are NOT saved
  984. * in the HWAC port structure and will be overwritten any
  985. * time when stopping and starting the port.
  986. * Any values for the synchronous configuration will be ignored
  987. * if the size of the synchronous queue is zero!
  988. *
  989. * The default configuration for the synchronous service is
  990. * TXA_ENA_FSYNC. This means if the size of
  991. * the synchronous queue is unequal zero but no specific
  992. * synchronous bandwidth is configured, the synchronous queue
  993. * will always have the 'unlimited' transmit priority!
  994. *
  995. * This mode will be restored if the synchronous bandwidth is
  996. * deallocated ('IntTime' = 0 and 'LimCount' = 0).
  997. *
  998. * Returns:
  999. * 0: success
  1000. * 1: parameter configuration error
  1001. * 2: try to configure quality of service although no
  1002. * synchronous queue is configured
  1003. */
  1004. int SkGeCfgSync(
  1005. SK_AC *pAC, /* adapter context */
  1006. SK_IOC IoC, /* IO context */
  1007. int Port, /* Port Index (MAC_1 + n) */
  1008. SK_U32 IntTime, /* Interval Timer Value in units of 8ns */
  1009. SK_U32 LimCount, /* Number of bytes to transfer during IntTime */
  1010. int SyncMode) /* Sync Mode: TXA_ENA_ALLOC | TXA_DIS_ALLOC | 0 */
  1011. {
  1012. int Rtv;
  1013. Rtv = 0;
  1014. /* check the parameters */
  1015. if (LimCount > IntTime ||
  1016. (LimCount == 0 && IntTime != 0) ||
  1017. (LimCount != 0 && IntTime == 0)) {
  1018. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E010, SKERR_HWI_E010MSG);
  1019. return(1);
  1020. }
  1021. if (pAC->GIni.GP[Port].PXSQSize == 0) {
  1022. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E009, SKERR_HWI_E009MSG);
  1023. return(2);
  1024. }
  1025. /* calculate register values */
  1026. IntTime = (IntTime / 2) * pAC->GIni.GIHstClkFact / 100;
  1027. LimCount = LimCount / 8;
  1028. if (IntTime > TXA_MAX_VAL || LimCount > TXA_MAX_VAL) {
  1029. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E010, SKERR_HWI_E010MSG);
  1030. return(1);
  1031. }
  1032. /*
  1033. * - Enable 'Force Sync' to ensure the synchronous queue
  1034. * has the priority while configuring the new values.
  1035. * - Also 'disable alloc' to ensure the settings complies
  1036. * to the SyncMode parameter.
  1037. * - Disable 'Rate Control' to configure the new values.
  1038. * - write IntTime and LimCount
  1039. * - start 'Rate Control' and disable 'Force Sync'
  1040. * if Interval Timer or Limit Counter not zero.
  1041. */
  1042. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
  1043. TXA_ENA_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
  1044. SK_OUT32(IoC, MR_ADDR(Port, TXA_ITI_INI), IntTime);
  1045. SK_OUT32(IoC, MR_ADDR(Port, TXA_LIM_INI), LimCount);
  1046. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
  1047. (SK_U8)(SyncMode & (TXA_ENA_ALLOC | TXA_DIS_ALLOC)));
  1048. if (IntTime != 0 || LimCount != 0) {
  1049. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL), TXA_DIS_FSYNC | TXA_START_RC);
  1050. }
  1051. return(0);
  1052. } /* SkGeCfgSync */
  1053. /******************************************************************************
  1054. *
  1055. * DoInitRamQueue() - Initialize the RAM Buffer Address of a single Queue
  1056. *
  1057. * Desccription:
  1058. * If the queue is used, enable and initialize it.
  1059. * Make sure the queue is still reset, if it is not used.
  1060. *
  1061. * Returns:
  1062. * nothing
  1063. */
  1064. static void DoInitRamQueue(
  1065. SK_AC *pAC, /* adapter context */
  1066. SK_IOC IoC, /* IO context */
  1067. int QuIoOffs, /* Queue IO Address Offset */
  1068. SK_U32 QuStartAddr, /* Queue Start Address */
  1069. SK_U32 QuEndAddr, /* Queue End Address */
  1070. int QuType) /* Queue Type (SK_RX_SRAM_Q|SK_RX_BRAM_Q|SK_TX_RAM_Q) */
  1071. {
  1072. SK_U32 RxUpThresVal;
  1073. SK_U32 RxLoThresVal;
  1074. if (QuStartAddr != QuEndAddr) {
  1075. /* calculate thresholds, assume we have a big Rx queue */
  1076. RxUpThresVal = (QuEndAddr + 1 - QuStartAddr - SK_RB_ULPP) / 8;
  1077. RxLoThresVal = (QuEndAddr + 1 - QuStartAddr - SK_RB_LLPP_B)/8;
  1078. /* build HW address format */
  1079. QuStartAddr = QuStartAddr / 8;
  1080. QuEndAddr = QuEndAddr / 8;
  1081. /* release local reset */
  1082. SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_RST_CLR);
  1083. /* configure addresses */
  1084. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_START), QuStartAddr);
  1085. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_END), QuEndAddr);
  1086. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_WP), QuStartAddr);
  1087. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RP), QuStartAddr);
  1088. switch (QuType) {
  1089. case SK_RX_SRAM_Q:
  1090. /* configure threshold for small Rx Queue */
  1091. RxLoThresVal += (SK_RB_LLPP_B - SK_RB_LLPP_S) / 8;
  1092. /* continue with SK_RX_BRAM_Q */
  1093. case SK_RX_BRAM_Q:
  1094. /* write threshold for Rx Queue */
  1095. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RX_UTPP), RxUpThresVal);
  1096. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RX_LTPP), RxLoThresVal);
  1097. /* the high priority threshold not used */
  1098. break;
  1099. case SK_TX_RAM_Q:
  1100. /*
  1101. * Do NOT use Store & Forward under normal operation due to
  1102. * performance optimization (GENESIS only).
  1103. * But if Jumbo Frames are configured (XMAC Tx FIFO is only 4 kB)
  1104. * or YUKON is used ((GMAC Tx FIFO is only 1 kB)
  1105. * we NEED Store & Forward of the RAM buffer.
  1106. */
  1107. if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK ||
  1108. !pAC->GIni.GIGenesis) {
  1109. /* enable Store & Forward Mode for the Tx Side */
  1110. SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_ENA_STFWD);
  1111. }
  1112. break;
  1113. }
  1114. /* set queue operational */
  1115. SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_ENA_OP_MD);
  1116. }
  1117. else {
  1118. /* ensure the queue is still disabled */
  1119. SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_RST_SET);
  1120. }
  1121. } /* DoInitRamQueue */
  1122. /******************************************************************************
  1123. *
  1124. * SkGeInitRamBufs() - Initialize the RAM Buffer Queues
  1125. *
  1126. * Description:
  1127. * Initialize all RAM Buffer Queues of the specified port
  1128. *
  1129. * Returns:
  1130. * nothing
  1131. */
  1132. static void SkGeInitRamBufs(
  1133. SK_AC *pAC, /* adapter context */
  1134. SK_IOC IoC, /* IO context */
  1135. int Port) /* Port Index (MAC_1 + n) */
  1136. {
  1137. SK_GEPORT *pPrt;
  1138. int RxQType;
  1139. pPrt = &pAC->GIni.GP[Port];
  1140. if (pPrt->PRxQSize == SK_MIN_RXQ_SIZE) {
  1141. RxQType = SK_RX_SRAM_Q; /* small Rx Queue */
  1142. } else {
  1143. RxQType = SK_RX_BRAM_Q; /* big Rx Queue */
  1144. }
  1145. DoInitRamQueue(pAC, IoC, pPrt->PRxQOff, pPrt->PRxQRamStart,
  1146. pPrt->PRxQRamEnd, RxQType);
  1147. DoInitRamQueue(pAC, IoC, pPrt->PXsQOff, pPrt->PXsQRamStart,
  1148. pPrt->PXsQRamEnd, SK_TX_RAM_Q);
  1149. DoInitRamQueue(pAC, IoC, pPrt->PXaQOff, pPrt->PXaQRamStart,
  1150. pPrt->PXaQRamEnd, SK_TX_RAM_Q);
  1151. } /* SkGeInitRamBufs */
  1152. /******************************************************************************
  1153. *
  1154. * SkGeInitRamIface() - Initialize the RAM Interface
  1155. *
  1156. * Description:
  1157. * This function initializes the Adapters RAM Interface.
  1158. *
  1159. * Note:
  1160. * This function is used in the diagnostics.
  1161. *
  1162. * Returns:
  1163. * nothing
  1164. */
  1165. void SkGeInitRamIface(
  1166. SK_AC *pAC, /* adapter context */
  1167. SK_IOC IoC) /* IO context */
  1168. {
  1169. /* release local reset */
  1170. SK_OUT16(IoC, B3_RI_CTRL, RI_RST_CLR);
  1171. /* configure timeout values */
  1172. SK_OUT8(IoC, B3_RI_WTO_R1, SK_RI_TO_53);
  1173. SK_OUT8(IoC, B3_RI_WTO_XA1, SK_RI_TO_53);
  1174. SK_OUT8(IoC, B3_RI_WTO_XS1, SK_RI_TO_53);
  1175. SK_OUT8(IoC, B3_RI_RTO_R1, SK_RI_TO_53);
  1176. SK_OUT8(IoC, B3_RI_RTO_XA1, SK_RI_TO_53);
  1177. SK_OUT8(IoC, B3_RI_RTO_XS1, SK_RI_TO_53);
  1178. SK_OUT8(IoC, B3_RI_WTO_R2, SK_RI_TO_53);
  1179. SK_OUT8(IoC, B3_RI_WTO_XA2, SK_RI_TO_53);
  1180. SK_OUT8(IoC, B3_RI_WTO_XS2, SK_RI_TO_53);
  1181. SK_OUT8(IoC, B3_RI_RTO_R2, SK_RI_TO_53);
  1182. SK_OUT8(IoC, B3_RI_RTO_XA2, SK_RI_TO_53);
  1183. SK_OUT8(IoC, B3_RI_RTO_XS2, SK_RI_TO_53);
  1184. } /* SkGeInitRamIface */
  1185. /******************************************************************************
  1186. *
  1187. * SkGeInitBmu() - Initialize the BMU state machines
  1188. *
  1189. * Description:
  1190. * Initialize all BMU state machines of the specified port
  1191. *
  1192. * Returns:
  1193. * nothing
  1194. */
  1195. static void SkGeInitBmu(
  1196. SK_AC *pAC, /* adapter context */
  1197. SK_IOC IoC, /* IO context */
  1198. int Port) /* Port Index (MAC_1 + n) */
  1199. {
  1200. SK_GEPORT *pPrt;
  1201. SK_U32 RxWm;
  1202. SK_U32 TxWm;
  1203. pPrt = &pAC->GIni.GP[Port];
  1204. RxWm = SK_BMU_RX_WM;
  1205. TxWm = SK_BMU_TX_WM;
  1206. if (!pAC->GIni.GIPciSlot64 && !pAC->GIni.GIPciClock66) {
  1207. /* for better performance */
  1208. RxWm /= 2;
  1209. TxWm /= 2;
  1210. }
  1211. /* Rx Queue: Release all local resets and set the watermark */
  1212. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_CLR_RESET);
  1213. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_F), RxWm);
  1214. /*
  1215. * Tx Queue: Release all local resets if the queue is used !
  1216. * set watermark
  1217. */
  1218. if (pPrt->PXSQSize != 0) {
  1219. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_CLR_RESET);
  1220. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_F), TxWm);
  1221. }
  1222. if (pPrt->PXAQSize != 0) {
  1223. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_CLR_RESET);
  1224. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_F), TxWm);
  1225. }
  1226. /*
  1227. * Do NOT enable the descriptor poll timers here, because
  1228. * the descriptor addresses are not specified yet.
  1229. */
  1230. } /* SkGeInitBmu */
  1231. /******************************************************************************
  1232. *
  1233. * TestStopBit() - Test the stop bit of the queue
  1234. *
  1235. * Description:
  1236. * Stopping a queue is not as simple as it seems to be.
  1237. * If descriptor polling is enabled, it may happen
  1238. * that RX/TX stop is done and SV idle is NOT set.
  1239. * In this case we have to issue another stop command.
  1240. *
  1241. * Returns:
  1242. * The queues control status register
  1243. */
  1244. static SK_U32 TestStopBit(
  1245. SK_AC *pAC, /* Adapter Context */
  1246. SK_IOC IoC, /* IO Context */
  1247. int QuIoOffs) /* Queue IO Address Offset */
  1248. {
  1249. SK_U32 QuCsr; /* CSR contents */
  1250. SK_IN32(IoC, Q_ADDR(QuIoOffs, Q_CSR), &QuCsr);
  1251. if ((QuCsr & (CSR_STOP | CSR_SV_IDLE)) == 0) {
  1252. /* Stop Descriptor overridden by start command */
  1253. SK_OUT32(IoC, Q_ADDR(QuIoOffs, Q_CSR), CSR_STOP);
  1254. SK_IN32(IoC, Q_ADDR(QuIoOffs, Q_CSR), &QuCsr);
  1255. }
  1256. return(QuCsr);
  1257. } /* TestStopBit */
  1258. /******************************************************************************
  1259. *
  1260. * SkGeStopPort() - Stop the Rx/Tx activity of the port 'Port'.
  1261. *
  1262. * Description:
  1263. * After calling this function the descriptor rings and Rx and Tx
  1264. * queues of this port may be reconfigured.
  1265. *
  1266. * It is possible to stop the receive and transmit path separate or
  1267. * both together.
  1268. *
  1269. * Dir = SK_STOP_TX Stops the transmit path only and resets the MAC.
  1270. * The receive queue is still active and
  1271. * the pending Rx frames may be still transferred
  1272. * into the RxD.
  1273. * SK_STOP_RX Stop the receive path. The tansmit path
  1274. * has to be stopped once before.
  1275. * SK_STOP_ALL SK_STOP_TX + SK_STOP_RX
  1276. *
  1277. * RstMode = SK_SOFT_RST Resets the MAC. The PHY is still alive.
  1278. * SK_HARD_RST Resets the MAC and the PHY.
  1279. *
  1280. * Example:
  1281. * 1) A Link Down event was signaled for a port. Therefore the activity
  1282. * of this port should be stopped and a hardware reset should be issued
  1283. * to enable the workaround of XMAC errata #2. But the received frames
  1284. * should not be discarded.
  1285. * ...
  1286. * SkGeStopPort(pAC, IoC, Port, SK_STOP_TX, SK_HARD_RST);
  1287. * (transfer all pending Rx frames)
  1288. * SkGeStopPort(pAC, IoC, Port, SK_STOP_RX, SK_HARD_RST);
  1289. * ...
  1290. *
  1291. * 2) An event was issued which request the driver to switch
  1292. * the 'virtual active' link to an other already active port
  1293. * as soon as possible. The frames in the receive queue of this
  1294. * port may be lost. But the PHY must not be reset during this
  1295. * event.
  1296. * ...
  1297. * SkGeStopPort(pAC, IoC, Port, SK_STOP_ALL, SK_SOFT_RST);
  1298. * ...
  1299. *
  1300. * Extended Description:
  1301. * If SK_STOP_TX is set,
  1302. * o disable the MAC's receive and transmitter to prevent
  1303. * from sending incomplete frames
  1304. * o stop the port's transmit queues before terminating the
  1305. * BMUs to prevent from performing incomplete PCI cycles
  1306. * on the PCI bus
  1307. * - The network Rx and Tx activity and PCI Tx transfer is
  1308. * disabled now.
  1309. * o reset the MAC depending on the RstMode
  1310. * o Stop Interval Timer and Limit Counter of Tx Arbiter,
  1311. * also disable Force Sync bit and Enable Alloc bit.
  1312. * o perform a local reset of the port's Tx path
  1313. * - reset the PCI FIFO of the async Tx queue
  1314. * - reset the PCI FIFO of the sync Tx queue
  1315. * - reset the RAM Buffer async Tx queue
  1316. * - reset the RAM Buffer sync Tx queue
  1317. * - reset the MAC Tx FIFO
  1318. * o switch Link and Tx LED off, stop the LED counters
  1319. *
  1320. * If SK_STOP_RX is set,
  1321. * o stop the port's receive queue
  1322. * - The path data transfer activity is fully stopped now.
  1323. * o perform a local reset of the port's Rx path
  1324. * - reset the PCI FIFO of the Rx queue
  1325. * - reset the RAM Buffer receive queue
  1326. * - reset the MAC Rx FIFO
  1327. * o switch Rx LED off, stop the LED counter
  1328. *
  1329. * If all ports are stopped,
  1330. * o reset the RAM Interface.
  1331. *
  1332. * Notes:
  1333. * o This function may be called during the driver states RESET_PORT and
  1334. * SWITCH_PORT.
  1335. */
  1336. void SkGeStopPort(
  1337. SK_AC *pAC, /* adapter context */
  1338. SK_IOC IoC, /* I/O context */
  1339. int Port, /* port to stop (MAC_1 + n) */
  1340. int Dir, /* Direction to Stop (SK_STOP_RX, SK_STOP_TX, SK_STOP_ALL) */
  1341. int RstMode)/* Reset Mode (SK_SOFT_RST, SK_HARD_RST) */
  1342. {
  1343. #ifndef SK_DIAG
  1344. SK_EVPARA Para;
  1345. #endif /* !SK_DIAG */
  1346. SK_GEPORT *pPrt;
  1347. SK_U32 DWord;
  1348. SK_U32 XsCsr;
  1349. SK_U32 XaCsr;
  1350. SK_U64 ToutStart;
  1351. int i;
  1352. int ToutCnt;
  1353. pPrt = &pAC->GIni.GP[Port];
  1354. if ((Dir & SK_STOP_TX) != 0) {
  1355. /* disable receiver and transmitter */
  1356. SkMacRxTxDisable(pAC, IoC, Port);
  1357. /* stop both transmit queues */
  1358. /*
  1359. * If the BMU is in the reset state CSR_STOP will terminate
  1360. * immediately.
  1361. */
  1362. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_STOP);
  1363. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_STOP);
  1364. ToutStart = SkOsGetTime(pAC);
  1365. ToutCnt = 0;
  1366. do {
  1367. /*
  1368. * Clear packet arbiter timeout to make sure
  1369. * this loop will terminate.
  1370. */
  1371. SK_OUT16(IoC, B3_PA_CTRL, (Port == MAC_1) ? PA_CLR_TO_TX1 :
  1372. PA_CLR_TO_TX2);
  1373. /*
  1374. * If the transfer stucks at the MAC the STOP command will not
  1375. * terminate if we don't flush the XMAC's transmit FIFO !
  1376. */
  1377. SkMacFlushTxFifo(pAC, IoC, Port);
  1378. XsCsr = TestStopBit(pAC, IoC, pPrt->PXsQOff);
  1379. XaCsr = TestStopBit(pAC, IoC, pPrt->PXaQOff);
  1380. if (SkOsGetTime(pAC) - ToutStart > (SK_TICKS_PER_SEC / 18)) {
  1381. /*
  1382. * Timeout of 1/18 second reached.
  1383. * This needs to be checked at 1/18 sec only.
  1384. */
  1385. ToutCnt++;
  1386. if (ToutCnt > 1) {
  1387. /* Might be a problem when the driver event handler
  1388. * calls StopPort again. XXX.
  1389. */
  1390. /* Fatal Error, Loop aborted */
  1391. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_HWI_E018,
  1392. SKERR_HWI_E018MSG);
  1393. #ifndef SK_DIAG
  1394. Para.Para64 = Port;
  1395. SkEventQueue(pAC, SKGE_DRV, SK_DRV_PORT_FAIL, Para);
  1396. #endif /* !SK_DIAG */
  1397. return;
  1398. }
  1399. /*
  1400. * Cache incoherency workaround: Assume a start command
  1401. * has been lost while sending the frame.
  1402. */
  1403. ToutStart = SkOsGetTime(pAC);
  1404. if ((XsCsr & CSR_STOP) != 0) {
  1405. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_START);
  1406. }
  1407. if ((XaCsr & CSR_STOP) != 0) {
  1408. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_START);
  1409. }
  1410. }
  1411. /*
  1412. * Because of the ASIC problem report entry from 21.08.1998 it is
  1413. * required to wait until CSR_STOP is reset and CSR_SV_IDLE is set.
  1414. */
  1415. } while ((XsCsr & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE ||
  1416. (XaCsr & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE);
  1417. /* Reset the MAC depending on the RstMode */
  1418. if (RstMode == SK_SOFT_RST) {
  1419. SkMacSoftRst(pAC, IoC, Port);
  1420. }
  1421. else {
  1422. SkMacHardRst(pAC, IoC, Port);
  1423. }
  1424. /* Disable Force Sync bit and Enable Alloc bit */
  1425. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
  1426. TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
  1427. /* Stop Interval Timer and Limit Counter of Tx Arbiter */
  1428. SK_OUT32(IoC, MR_ADDR(Port, TXA_ITI_INI), 0L);
  1429. SK_OUT32(IoC, MR_ADDR(Port, TXA_LIM_INI), 0L);
  1430. /* Perform a local reset of the port's Tx path */
  1431. /* Reset the PCI FIFO of the async Tx queue */
  1432. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_SET_RESET);
  1433. /* Reset the PCI FIFO of the sync Tx queue */
  1434. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_SET_RESET);
  1435. /* Reset the RAM Buffer async Tx queue */
  1436. SK_OUT8(IoC, RB_ADDR(pPrt->PXaQOff, RB_CTRL), RB_RST_SET);
  1437. /* Reset the RAM Buffer sync Tx queue */
  1438. SK_OUT8(IoC, RB_ADDR(pPrt->PXsQOff, RB_CTRL), RB_RST_SET);
  1439. /* Reset Tx MAC FIFO */
  1440. if (pAC->GIni.GIGenesis) {
  1441. /* Note: MFF_RST_SET does NOT reset the XMAC ! */
  1442. SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_RST_SET);
  1443. /* switch Link and Tx LED off, stop the LED counters */
  1444. /* Link LED is switched off by the RLMT and the Diag itself */
  1445. SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_DIS);
  1446. }
  1447. else {
  1448. /* Reset TX MAC FIFO */
  1449. SK_OUT8(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U8)GMF_RST_SET);
  1450. }
  1451. }
  1452. if ((Dir & SK_STOP_RX) != 0) {
  1453. /*
  1454. * The RX Stop Command will not terminate if no buffers
  1455. * are queued in the RxD ring. But it will always reach
  1456. * the Idle state. Therefore we can use this feature to
  1457. * stop the transfer of received packets.
  1458. */
  1459. /* stop the port's receive queue */
  1460. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_STOP);
  1461. i = 100;
  1462. do {
  1463. /*
  1464. * Clear packet arbiter timeout to make sure
  1465. * this loop will terminate
  1466. */
  1467. SK_OUT16(IoC, B3_PA_CTRL, (Port == MAC_1) ? PA_CLR_TO_RX1 :
  1468. PA_CLR_TO_RX2);
  1469. DWord = TestStopBit(pAC, IoC, pPrt->PRxQOff);
  1470. /* timeout if i==0 (bug fix for #10748) */
  1471. if (--i == 0) {
  1472. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_HWI_E024,
  1473. SKERR_HWI_E024MSG);
  1474. break;
  1475. }
  1476. /*
  1477. * because of the ASIC problem report entry from 21.08.98
  1478. * it is required to wait until CSR_STOP is reset and
  1479. * CSR_SV_IDLE is set.
  1480. */
  1481. } while ((DWord & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE);
  1482. /* The path data transfer activity is fully stopped now */
  1483. /* Perform a local reset of the port's Rx path */
  1484. /* Reset the PCI FIFO of the Rx queue */
  1485. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_SET_RESET);
  1486. /* Reset the RAM Buffer receive queue */
  1487. SK_OUT8(IoC, RB_ADDR(pPrt->PRxQOff, RB_CTRL), RB_RST_SET);
  1488. /* Reset Rx MAC FIFO */
  1489. if (pAC->GIni.GIGenesis) {
  1490. SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_RST_SET);
  1491. /* switch Rx LED off, stop the LED counter */
  1492. SkGeXmitLED(pAC, IoC, MR_ADDR(Port, RX_LED_INI), SK_LED_DIS);
  1493. }
  1494. else {
  1495. /* Reset Rx MAC FIFO */
  1496. SK_OUT8(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), (SK_U8)GMF_RST_SET);
  1497. }
  1498. }
  1499. } /* SkGeStopPort */
  1500. /******************************************************************************
  1501. *
  1502. * SkGeInit0() - Level 0 Initialization
  1503. *
  1504. * Description:
  1505. * - Initialize the BMU address offsets
  1506. *
  1507. * Returns:
  1508. * nothing
  1509. */
  1510. static void SkGeInit0(
  1511. SK_AC *pAC, /* adapter context */
  1512. SK_IOC IoC) /* IO context */
  1513. {
  1514. int i;
  1515. SK_GEPORT *pPrt;
  1516. for (i = 0; i < SK_MAX_MACS; i++) {
  1517. pPrt = &pAC->GIni.GP[i];
  1518. pPrt->PState = SK_PRT_RESET;
  1519. pPrt->PRxQOff = QOffTab[i].RxQOff;
  1520. pPrt->PXsQOff = QOffTab[i].XsQOff;
  1521. pPrt->PXaQOff = QOffTab[i].XaQOff;
  1522. pPrt->PCheckPar = SK_FALSE;
  1523. pPrt->PIsave = 0;
  1524. pPrt->PPrevShorts = 0;
  1525. pPrt->PLinkResCt = 0;
  1526. pPrt->PAutoNegTOCt = 0;
  1527. pPrt->PPrevRx = 0;
  1528. pPrt->PPrevFcs = 0;
  1529. pPrt->PRxLim = SK_DEF_RX_WA_LIM;
  1530. pPrt->PLinkMode = SK_LMODE_AUTOFULL;
  1531. pPrt->PLinkSpeedCap = SK_LSPEED_CAP_1000MBPS;
  1532. pPrt->PLinkSpeed = SK_LSPEED_1000MBPS;
  1533. pPrt->PLinkSpeedUsed = SK_LSPEED_STAT_UNKNOWN;
  1534. pPrt->PLinkModeConf = SK_LMODE_AUTOSENSE;
  1535. pPrt->PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
  1536. pPrt->PLinkBroken = SK_TRUE; /* See WA code */
  1537. pPrt->PLinkCap = (SK_LMODE_CAP_HALF | SK_LMODE_CAP_FULL |
  1538. SK_LMODE_CAP_AUTOHALF | SK_LMODE_CAP_AUTOFULL);
  1539. pPrt->PLinkModeStatus = SK_LMODE_STAT_UNKNOWN;
  1540. pPrt->PFlowCtrlCap = SK_FLOW_MODE_SYM_OR_REM;
  1541. pPrt->PFlowCtrlStatus = SK_FLOW_STAT_NONE;
  1542. pPrt->PMSCap = 0;
  1543. pPrt->PMSMode = SK_MS_MODE_AUTO;
  1544. pPrt->PMSStatus = SK_MS_STAT_UNSET;
  1545. pPrt->PAutoNegFail = SK_FALSE;
  1546. pPrt->PLipaAutoNeg = SK_LIPA_UNKNOWN;
  1547. pPrt->PHWLinkUp = SK_FALSE;
  1548. }
  1549. pAC->GIni.GIPortUsage = SK_RED_LINK;
  1550. } /* SkGeInit0*/
  1551. #ifdef SK_PCI_RESET
  1552. /******************************************************************************
  1553. *
  1554. * SkGePciReset() - Reset PCI interface
  1555. *
  1556. * Description:
  1557. * o Read PCI configuration.
  1558. * o Change power state to 3.
  1559. * o Change power state to 0.
  1560. * o Restore PCI configuration.
  1561. *
  1562. * Returns:
  1563. * 0: Success.
  1564. * 1: Power state could not be changed to 3.
  1565. */
  1566. static int SkGePciReset(
  1567. SK_AC *pAC, /* adapter context */
  1568. SK_IOC IoC) /* IO context */
  1569. {
  1570. int i;
  1571. SK_U16 PmCtlSts;
  1572. SK_U32 Bp1;
  1573. SK_U32 Bp2;
  1574. SK_U16 PciCmd;
  1575. SK_U8 Cls;
  1576. SK_U8 Lat;
  1577. SK_U8 ConfigSpace[PCI_CFG_SIZE];
  1578. /*
  1579. * Note: Switching to D3 state is like a software reset.
  1580. * Switching from D3 to D0 is a hardware reset.
  1581. * We have to save and restore the configuration space.
  1582. */
  1583. for (i = 0; i < PCI_CFG_SIZE; i++) {
  1584. SkPciReadCfgDWord(pAC, i*4, &ConfigSpace[i]);
  1585. }
  1586. /* We know the RAM Interface Arbiter is enabled. */
  1587. SkPciWriteCfgWord(pAC, PCI_PM_CTL_STS, PCI_PM_STATE_D3);
  1588. SkPciReadCfgWord(pAC, PCI_PM_CTL_STS, &PmCtlSts);
  1589. if ((PmCtlSts & PCI_PM_STATE_MSK) != PCI_PM_STATE_D3) {
  1590. return(1);
  1591. }
  1592. /* Return to D0 state. */
  1593. SkPciWriteCfgWord(pAC, PCI_PM_CTL_STS, PCI_PM_STATE_D0);
  1594. /* Check for D0 state. */
  1595. SkPciReadCfgWord(pAC, PCI_PM_CTL_STS, &PmCtlSts);
  1596. if ((PmCtlSts & PCI_PM_STATE_MSK) != PCI_PM_STATE_D0) {
  1597. return(1);
  1598. }
  1599. /* Check PCI Config Registers. */
  1600. SkPciReadCfgWord(pAC, PCI_COMMAND, &PciCmd);
  1601. SkPciReadCfgByte(pAC, PCI_CACHE_LSZ, &Cls);
  1602. SkPciReadCfgDWord(pAC, PCI_BASE_1ST, &Bp1);
  1603. SkPciReadCfgDWord(pAC, PCI_BASE_2ND, &Bp2);
  1604. SkPciReadCfgByte(pAC, PCI_LAT_TIM, &Lat);
  1605. if (PciCmd != 0 || Cls != 0 || (Bp1 & 0xfffffff0L) != 0 || Bp2 != 1 ||
  1606. Lat != 0) {
  1607. return(1);
  1608. }
  1609. /* Restore PCI Config Space. */
  1610. for (i = 0; i < PCI_CFG_SIZE; i++) {
  1611. SkPciWriteCfgDWord(pAC, i*4, ConfigSpace[i]);
  1612. }
  1613. return(0);
  1614. } /* SkGePciReset */
  1615. #endif /* SK_PCI_RESET */
  1616. /******************************************************************************
  1617. *
  1618. * SkGeInit1() - Level 1 Initialization
  1619. *
  1620. * Description:
  1621. * o Do a software reset.
  1622. * o Clear all reset bits.
  1623. * o Verify that the detected hardware is present.
  1624. * Return an error if not.
  1625. * o Get the hardware configuration
  1626. * + Read the number of MACs/Ports.
  1627. * + Read the RAM size.
  1628. * + Read the PCI Revision Id.
  1629. * + Find out the adapters host clock speed
  1630. * + Read and check the PHY type
  1631. *
  1632. * Returns:
  1633. * 0: success
  1634. * 5: Unexpected PHY type detected
  1635. * 6: HW self test failed
  1636. */
  1637. static int SkGeInit1(
  1638. SK_AC *pAC, /* adapter context */
  1639. SK_IOC IoC) /* IO context */
  1640. {
  1641. SK_U8 Byte;
  1642. SK_U16 Word;
  1643. SK_U16 CtrlStat;
  1644. SK_U32 FlashAddr;
  1645. int RetVal;
  1646. int i;
  1647. RetVal = 0;
  1648. /* save CLK_RUN bits (YUKON-Lite) */
  1649. SK_IN16(IoC, B0_CTST, &CtrlStat);
  1650. #ifdef SK_PCI_RESET
  1651. (void)SkGePciReset(pAC, IoC);
  1652. #endif /* SK_PCI_RESET */
  1653. /* do the SW-reset */
  1654. SK_OUT8(IoC, B0_CTST, CS_RST_SET);
  1655. /* release the SW-reset */
  1656. SK_OUT8(IoC, B0_CTST, CS_RST_CLR);
  1657. /* reset all error bits in the PCI STATUS register */
  1658. /*
  1659. * Note: PCI Cfg cycles cannot be used, because they are not
  1660. * available on some platforms after 'boot time'.
  1661. */
  1662. SK_IN16(IoC, PCI_C(PCI_STATUS), &Word);
  1663. SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  1664. SK_OUT16(IoC, PCI_C(PCI_STATUS), Word | PCI_ERRBITS);
  1665. SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  1666. /* release Master Reset */
  1667. SK_OUT8(IoC, B0_CTST, CS_MRST_CLR);
  1668. #ifdef CLK_RUN
  1669. CtrlStat |= CS_CLK_RUN_ENA;
  1670. #endif /* CLK_RUN */
  1671. /* restore CLK_RUN bits */
  1672. SK_OUT16(IoC, B0_CTST, CtrlStat &
  1673. (CS_CLK_RUN_HOT | CS_CLK_RUN_RST | CS_CLK_RUN_ENA));
  1674. /* read Chip Identification Number */
  1675. SK_IN8(IoC, B2_CHIP_ID, &Byte);
  1676. pAC->GIni.GIChipId = Byte;
  1677. /* read number of MACs */
  1678. SK_IN8(IoC, B2_MAC_CFG, &Byte);
  1679. pAC->GIni.GIMacsFound = (Byte & CONFIG_SYS_SNG_MAC) ? 1 : 2;
  1680. /* get Chip Revision Number */
  1681. pAC->GIni.GIChipRev = (SK_U8)((Byte & CONFIG_SYS_CHIP_R_MSK) >> 4);
  1682. /* get diff. PCI parameters */
  1683. SK_IN16(IoC, B0_CTST, &CtrlStat);
  1684. /* read the adapters RAM size */
  1685. SK_IN8(IoC, B2_E_0, &Byte);
  1686. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1687. pAC->GIni.GIGenesis = SK_TRUE;
  1688. if (Byte == 3) {
  1689. /* special case: 4 x 64k x 36, offset = 0x80000 */
  1690. pAC->GIni.GIRamSize = 1024;
  1691. pAC->GIni.GIRamOffs = (SK_U32)512 * 1024;
  1692. }
  1693. else {
  1694. pAC->GIni.GIRamSize = (int)Byte * 512;
  1695. pAC->GIni.GIRamOffs = 0;
  1696. }
  1697. /* all GE adapters work with 53.125 MHz host clock */
  1698. pAC->GIni.GIHstClkFact = SK_FACT_53;
  1699. /* set Descr. Poll Timer Init Value to 250 ms */
  1700. pAC->GIni.GIPollTimerVal =
  1701. SK_DPOLL_DEF * (SK_U32)pAC->GIni.GIHstClkFact / 100;
  1702. }
  1703. else {
  1704. pAC->GIni.GIGenesis = SK_FALSE;
  1705. #ifndef VCPU
  1706. pAC->GIni.GIRamSize = (Byte == 0) ? 128 : (int)Byte * 4;
  1707. #else
  1708. pAC->GIni.GIRamSize = 128;
  1709. #endif
  1710. pAC->GIni.GIRamOffs = 0;
  1711. /* WA for chip Rev. A */
  1712. pAC->GIni.GIWolOffs = (pAC->GIni.GIChipRev == 0) ? WOL_REG_OFFS : 0;
  1713. /* get PM Capabilities of PCI config space */
  1714. SK_IN16(IoC, PCI_C(PCI_PM_CAP_REG), &Word);
  1715. /* check if VAUX is available */
  1716. if (((CtrlStat & CS_VAUX_AVAIL) != 0) &&
  1717. /* check also if PME from D3cold is set */
  1718. ((Word & PCI_PME_D3C_SUP) != 0)) {
  1719. /* set entry in GE init struct */
  1720. pAC->GIni.GIVauxAvail = SK_TRUE;
  1721. }
  1722. /* save Flash-Address Register */
  1723. SK_IN32(IoC, B2_FAR, &FlashAddr);
  1724. /* test Flash-Address Register */
  1725. SK_OUT8(IoC, B2_FAR + 3, 0xff);
  1726. SK_IN8(IoC, B2_FAR + 3, &Byte);
  1727. pAC->GIni.GIYukonLite = (SK_BOOL)(Byte != 0);
  1728. /* restore Flash-Address Register */
  1729. SK_OUT32(IoC, B2_FAR, FlashAddr);
  1730. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  1731. /* set GMAC Link Control reset */
  1732. SK_OUT16(IoC, MR_ADDR(i, GMAC_LINK_CTRL), GMLC_RST_SET);
  1733. /* clear GMAC Link Control reset */
  1734. SK_OUT16(IoC, MR_ADDR(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
  1735. }
  1736. /* all YU chips work with 78.125 MHz host clock */
  1737. pAC->GIni.GIHstClkFact = SK_FACT_78;
  1738. pAC->GIni.GIPollTimerVal = SK_DPOLL_MAX; /* 215 ms */
  1739. }
  1740. /* check if 64-bit PCI Slot is present */
  1741. pAC->GIni.GIPciSlot64 = (SK_BOOL)((CtrlStat & CS_BUS_SLOT_SZ) != 0);
  1742. /* check if 66 MHz PCI Clock is active */
  1743. pAC->GIni.GIPciClock66 = (SK_BOOL)((CtrlStat & CS_BUS_CLOCK) != 0);
  1744. /* read PCI HW Revision Id. */
  1745. SK_IN8(IoC, PCI_C(PCI_REV_ID), &Byte);
  1746. pAC->GIni.GIPciHwRev = Byte;
  1747. /* read the PMD type */
  1748. SK_IN8(IoC, B2_PMD_TYP, &Byte);
  1749. pAC->GIni.GICopperType = (SK_U8)(Byte == 'T');
  1750. /* read the PHY type */
  1751. SK_IN8(IoC, B2_E_1, &Byte);
  1752. Byte &= 0x0f; /* the PHY type is stored in the lower nibble */
  1753. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  1754. if (pAC->GIni.GIGenesis) {
  1755. switch (Byte) {
  1756. case SK_PHY_XMAC:
  1757. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_XMAC;
  1758. break;
  1759. case SK_PHY_BCOM:
  1760. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_BCOM;
  1761. pAC->GIni.GP[i].PMSCap =
  1762. SK_MS_CAP_AUTO | SK_MS_CAP_MASTER | SK_MS_CAP_SLAVE;
  1763. break;
  1764. #ifdef OTHER_PHY
  1765. case SK_PHY_LONE:
  1766. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_LONE;
  1767. break;
  1768. case SK_PHY_NAT:
  1769. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_NAT;
  1770. break;
  1771. #endif /* OTHER_PHY */
  1772. default:
  1773. /* ERROR: unexpected PHY type detected */
  1774. RetVal = 5;
  1775. break;
  1776. }
  1777. }
  1778. else {
  1779. if (Byte == 0) {
  1780. /* if this field is not initialized */
  1781. Byte = SK_PHY_MARV_COPPER;
  1782. pAC->GIni.GICopperType = SK_TRUE;
  1783. }
  1784. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_MARV;
  1785. if (pAC->GIni.GICopperType) {
  1786. pAC->GIni.GP[i].PLinkSpeedCap = SK_LSPEED_CAP_AUTO |
  1787. SK_LSPEED_CAP_10MBPS | SK_LSPEED_CAP_100MBPS |
  1788. SK_LSPEED_CAP_1000MBPS;
  1789. pAC->GIni.GP[i].PLinkSpeed = SK_LSPEED_AUTO;
  1790. pAC->GIni.GP[i].PMSCap =
  1791. SK_MS_CAP_AUTO | SK_MS_CAP_MASTER | SK_MS_CAP_SLAVE;
  1792. }
  1793. else {
  1794. Byte = SK_PHY_MARV_FIBER;
  1795. }
  1796. }
  1797. pAC->GIni.GP[i].PhyType = Byte;
  1798. SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
  1799. ("PHY type: %d PHY addr: %04x\n", Byte,
  1800. pAC->GIni.GP[i].PhyAddr));
  1801. }
  1802. /* get Mac Type & set function pointers dependent on */
  1803. if (pAC->GIni.GIGenesis) {
  1804. pAC->GIni.GIMacType = SK_MAC_XMAC;
  1805. pAC->GIni.GIFunc.pFnMacUpdateStats = SkXmUpdateStats;
  1806. pAC->GIni.GIFunc.pFnMacStatistic = SkXmMacStatistic;
  1807. pAC->GIni.GIFunc.pFnMacResetCounter = SkXmResetCounter;
  1808. pAC->GIni.GIFunc.pFnMacOverflow = SkXmOverflowStatus;
  1809. }
  1810. else {
  1811. pAC->GIni.GIMacType = SK_MAC_GMAC;
  1812. pAC->GIni.GIFunc.pFnMacUpdateStats = SkGmUpdateStats;
  1813. pAC->GIni.GIFunc.pFnMacStatistic = SkGmMacStatistic;
  1814. pAC->GIni.GIFunc.pFnMacResetCounter = SkGmResetCounter;
  1815. pAC->GIni.GIFunc.pFnMacOverflow = SkGmOverflowStatus;
  1816. #ifdef SPECIAL_HANDLING
  1817. if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
  1818. /* check HW self test result */
  1819. SK_IN8(IoC, B2_E_3, &Byte);
  1820. if ((Byte & B2_E3_RES_MASK) != 0) {
  1821. RetVal = 6;
  1822. }
  1823. }
  1824. #endif
  1825. }
  1826. return(RetVal);
  1827. } /* SkGeInit1 */
  1828. /******************************************************************************
  1829. *
  1830. * SkGeInit2() - Level 2 Initialization
  1831. *
  1832. * Description:
  1833. * - start the Blink Source Counter
  1834. * - start the Descriptor Poll Timer
  1835. * - configure the MAC-Arbiter
  1836. * - configure the Packet-Arbiter
  1837. * - enable the Tx Arbiters
  1838. * - enable the RAM Interface Arbiter
  1839. *
  1840. * Returns:
  1841. * nothing
  1842. */
  1843. static void SkGeInit2(
  1844. SK_AC *pAC, /* adapter context */
  1845. SK_IOC IoC) /* IO context */
  1846. {
  1847. SK_U32 DWord;
  1848. int i;
  1849. /* start the Descriptor Poll Timer */
  1850. if (pAC->GIni.GIPollTimerVal != 0) {
  1851. if (pAC->GIni.GIPollTimerVal > SK_DPOLL_MAX) {
  1852. pAC->GIni.GIPollTimerVal = SK_DPOLL_MAX;
  1853. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E017, SKERR_HWI_E017MSG);
  1854. }
  1855. SK_OUT32(IoC, B28_DPT_INI, pAC->GIni.GIPollTimerVal);
  1856. SK_OUT8(IoC, B28_DPT_CTRL, DPT_START);
  1857. }
  1858. if (pAC->GIni.GIGenesis) {
  1859. /* start the Blink Source Counter */
  1860. DWord = SK_BLK_DUR * (SK_U32)pAC->GIni.GIHstClkFact / 100;
  1861. SK_OUT32(IoC, B2_BSC_INI, DWord);
  1862. SK_OUT8(IoC, B2_BSC_CTRL, BSC_START);
  1863. /*
  1864. * Configure the MAC Arbiter and the Packet Arbiter.
  1865. * They will be started once and never be stopped.
  1866. */
  1867. SkGeInitMacArb(pAC, IoC);
  1868. SkGeInitPktArb(pAC, IoC);
  1869. }
  1870. else {
  1871. /* start Time Stamp Timer */
  1872. SK_OUT8(IoC, GMAC_TI_ST_CTRL, (SK_U8)GMT_ST_START);
  1873. }
  1874. /* enable the Tx Arbiters */
  1875. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  1876. SK_OUT8(IoC, MR_ADDR(i, TXA_CTRL), TXA_ENA_ARB);
  1877. }
  1878. /* enable the RAM Interface Arbiter */
  1879. SkGeInitRamIface(pAC, IoC);
  1880. } /* SkGeInit2 */
  1881. /******************************************************************************
  1882. *
  1883. * SkGeInit() - Initialize the GE Adapter with the specified level.
  1884. *
  1885. * Description:
  1886. * Level 0: Initialize the Module structures.
  1887. * Level 1: Generic Hardware Initialization. The IOP/MemBase pointer has
  1888. * to be set before calling this level.
  1889. *
  1890. * o Do a software reset.
  1891. * o Clear all reset bits.
  1892. * o Verify that the detected hardware is present.
  1893. * Return an error if not.
  1894. * o Get the hardware configuration
  1895. * + Set GIMacsFound with the number of MACs.
  1896. * + Store the RAM size in GIRamSize.
  1897. * + Save the PCI Revision ID in GIPciHwRev.
  1898. * o return an error
  1899. * if Number of MACs > SK_MAX_MACS
  1900. *
  1901. * After returning from Level 0 the adapter
  1902. * may be accessed with IO operations.
  1903. *
  1904. * Level 2: start the Blink Source Counter
  1905. *
  1906. * Returns:
  1907. * 0: success
  1908. * 1: Number of MACs exceeds SK_MAX_MACS (after level 1)
  1909. * 2: Adapter not present or not accessible
  1910. * 3: Illegal initialization level
  1911. * 4: Initialization Level 1 Call missing
  1912. * 5: Unexpected PHY type detected
  1913. * 6: HW self test failed
  1914. */
  1915. int SkGeInit(
  1916. SK_AC *pAC, /* adapter context */
  1917. SK_IOC IoC, /* IO context */
  1918. int Level) /* initialization level */
  1919. {
  1920. int RetVal; /* return value */
  1921. SK_U32 DWord;
  1922. RetVal = 0;
  1923. SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
  1924. ("SkGeInit(Level %d)\n", Level));
  1925. switch (Level) {
  1926. case SK_INIT_DATA:
  1927. /* Initialization Level 0 */
  1928. SkGeInit0(pAC, IoC);
  1929. pAC->GIni.GILevel = SK_INIT_DATA;
  1930. break;
  1931. case SK_INIT_IO:
  1932. /* Initialization Level 1 */
  1933. RetVal = SkGeInit1(pAC, IoC);
  1934. if (RetVal != 0) {
  1935. break;
  1936. }
  1937. /* check if the adapter seems to be accessible */
  1938. SK_OUT32(IoC, B2_IRQM_INI, 0x11335577L);
  1939. SK_IN32(IoC, B2_IRQM_INI, &DWord);
  1940. SK_OUT32(IoC, B2_IRQM_INI, 0L);
  1941. if (DWord != 0x11335577L) {
  1942. RetVal = 2;
  1943. break;
  1944. }
  1945. /* check if the number of GIMacsFound matches SK_MAX_MACS */
  1946. if (pAC->GIni.GIMacsFound > SK_MAX_MACS) {
  1947. RetVal = 1;
  1948. break;
  1949. }
  1950. /* Level 1 successfully passed */
  1951. pAC->GIni.GILevel = SK_INIT_IO;
  1952. break;
  1953. case SK_INIT_RUN:
  1954. /* Initialization Level 2 */
  1955. if (pAC->GIni.GILevel != SK_INIT_IO) {
  1956. #ifndef SK_DIAG
  1957. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E002, SKERR_HWI_E002MSG);
  1958. #endif /* !SK_DIAG */
  1959. RetVal = 4;
  1960. break;
  1961. }
  1962. SkGeInit2(pAC, IoC);
  1963. /* Level 2 successfully passed */
  1964. pAC->GIni.GILevel = SK_INIT_RUN;
  1965. break;
  1966. default:
  1967. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E003, SKERR_HWI_E003MSG);
  1968. RetVal = 3;
  1969. break;
  1970. }
  1971. return(RetVal);
  1972. } /* SkGeInit */
  1973. /******************************************************************************
  1974. *
  1975. * SkGeDeInit() - Deinitialize the adapter
  1976. *
  1977. * Description:
  1978. * All ports of the adapter will be stopped if not already done.
  1979. * Do a software reset and switch off all LEDs.
  1980. *
  1981. * Returns:
  1982. * nothing
  1983. */
  1984. void SkGeDeInit(
  1985. SK_AC *pAC, /* adapter context */
  1986. SK_IOC IoC) /* IO context */
  1987. {
  1988. int i;
  1989. SK_U16 Word;
  1990. #ifndef VCPU
  1991. /* ensure I2C is ready */
  1992. SkI2cWaitIrq(pAC, IoC);
  1993. #endif
  1994. /* stop all current transfer activity */
  1995. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  1996. if (pAC->GIni.GP[i].PState != SK_PRT_STOP &&
  1997. pAC->GIni.GP[i].PState != SK_PRT_RESET) {
  1998. SkGeStopPort(pAC, IoC, i, SK_STOP_ALL, SK_HARD_RST);
  1999. }
  2000. }
  2001. /* Reset all bits in the PCI STATUS register */
  2002. /*
  2003. * Note: PCI Cfg cycles cannot be used, because they are not
  2004. * available on some platforms after 'boot time'.
  2005. */
  2006. SK_IN16(IoC, PCI_C(PCI_STATUS), &Word);
  2007. SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  2008. SK_OUT16(IoC, PCI_C(PCI_STATUS), Word | PCI_ERRBITS);
  2009. SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  2010. /* do the reset, all LEDs are switched off now */
  2011. SK_OUT8(IoC, B0_CTST, CS_RST_SET);
  2012. } /* SkGeDeInit */
  2013. /******************************************************************************
  2014. *
  2015. * SkGeInitPort() Initialize the specified port.
  2016. *
  2017. * Description:
  2018. * PRxQSize, PXSQSize, and PXAQSize has to be
  2019. * configured for the specified port before calling this function.
  2020. * The descriptor rings has to be initialized too.
  2021. *
  2022. * o (Re)configure queues of the specified port.
  2023. * o configure the MAC of the specified port.
  2024. * o put ASIC and MAC(s) in operational mode.
  2025. * o initialize Rx/Tx and Sync LED
  2026. * o initialize RAM Buffers and MAC FIFOs
  2027. *
  2028. * The port is ready to connect when returning.
  2029. *
  2030. * Note:
  2031. * The MAC's Rx and Tx state machine is still disabled when returning.
  2032. *
  2033. * Returns:
  2034. * 0: success
  2035. * 1: Queue size initialization error. The configured values
  2036. * for PRxQSize, PXSQSize, or PXAQSize are invalid for one
  2037. * or more queues. The specified port was NOT initialized.
  2038. * An error log entry was generated.
  2039. * 2: The port has to be stopped before it can be initialized again.
  2040. */
  2041. int SkGeInitPort(
  2042. SK_AC *pAC, /* adapter context */
  2043. SK_IOC IoC, /* IO context */
  2044. int Port) /* Port to configure */
  2045. {
  2046. SK_GEPORT *pPrt;
  2047. pPrt = &pAC->GIni.GP[Port];
  2048. if (SkGeCheckQSize(pAC, Port) != 0) {
  2049. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E004, SKERR_HWI_E004MSG);
  2050. return(1);
  2051. }
  2052. if (pPrt->PState == SK_PRT_INIT || pPrt->PState == SK_PRT_RUN) {
  2053. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E005, SKERR_HWI_E005MSG);
  2054. return(2);
  2055. }
  2056. /* configuration ok, initialize the Port now */
  2057. if (pAC->GIni.GIGenesis) {
  2058. /* initialize Rx, Tx and Link LED */
  2059. /*
  2060. * If 1000BT Phy needs LED initialization than swap
  2061. * LED and XMAC initialization order
  2062. */
  2063. SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_ENA);
  2064. SkGeXmitLED(pAC, IoC, MR_ADDR(Port, RX_LED_INI), SK_LED_ENA);
  2065. /* The Link LED is initialized by RLMT or Diagnostics itself */
  2066. SkXmInitMac(pAC, IoC, Port);
  2067. }
  2068. else {
  2069. SkGmInitMac(pAC, IoC, Port);
  2070. }
  2071. /* do NOT initialize the Link Sync Counter */
  2072. SkGeInitMacFifo(pAC, IoC, Port);
  2073. SkGeInitRamBufs(pAC, IoC, Port);
  2074. if (pPrt->PXSQSize != 0) {
  2075. /* enable Force Sync bit if synchronous queue available */
  2076. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL), TXA_ENA_FSYNC);
  2077. }
  2078. SkGeInitBmu(pAC, IoC, Port);
  2079. /* mark port as initialized */
  2080. pPrt->PState = SK_PRT_INIT;
  2081. return(0);
  2082. } /* SkGeInitPort */