skgeinit.c 68 KB

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