skgeinit.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005
  1. /******************************************************************************
  2. *
  3. * Name: skgeinit.c
  4. * Project: Gigabit Ethernet Adapters, Common Modules
  5. * Version: $Revision: 1.97 $
  6. * Date: $Date: 2003/10/02 16:45:31 $
  7. * Purpose: Contains functions to initialize the adapter
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2002 SysKonnect.
  13. * (C)Copyright 2002-2003 Marvell.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * The information in this file is provided "AS IS" without warranty.
  21. *
  22. ******************************************************************************/
  23. #include "h/skdrv1st.h"
  24. #include "h/skdrv2nd.h"
  25. /* global variables ***********************************************************/
  26. /* local variables ************************************************************/
  27. #if (defined(DEBUG) || ((!defined(LINT)) && (!defined(SK_SLIM))))
  28. static const char SysKonnectFileId[] =
  29. "@(#) $Id: skgeinit.c,v 1.97 2003/10/02 16:45:31 rschmidt Exp $ (C) Marvell.";
  30. #endif
  31. struct s_QOffTab {
  32. int RxQOff; /* Receive Queue Address Offset */
  33. int XsQOff; /* Sync Tx Queue Address Offset */
  34. int XaQOff; /* Async Tx Queue Address Offset */
  35. };
  36. static struct s_QOffTab QOffTab[] = {
  37. {Q_R1, Q_XS1, Q_XA1}, {Q_R2, Q_XS2, Q_XA2}
  38. };
  39. struct s_Config {
  40. char ScanString[8];
  41. SK_U32 Value;
  42. };
  43. static struct s_Config OemConfig = {
  44. {'O','E','M','_','C','o','n','f'},
  45. #ifdef SK_OEM_CONFIG
  46. OEM_CONFIG_VALUE,
  47. #else
  48. 0,
  49. #endif
  50. };
  51. /******************************************************************************
  52. *
  53. * SkGePollTxD() - Enable / Disable Descriptor Polling of TxD Rings
  54. *
  55. * Description:
  56. * Enable or disable the descriptor polling of the transmit descriptor
  57. * ring(s) (TxD) for port 'Port'.
  58. * The new configuration is *not* saved over any SkGeStopPort() and
  59. * SkGeInitPort() calls.
  60. *
  61. * Returns:
  62. * nothing
  63. */
  64. void SkGePollTxD(
  65. SK_AC *pAC, /* adapter context */
  66. SK_IOC IoC, /* IO context */
  67. int Port, /* Port Index (MAC_1 + n) */
  68. SK_BOOL PollTxD) /* SK_TRUE (enable pol.), SK_FALSE (disable pol.) */
  69. {
  70. SK_GEPORT *pPrt;
  71. SK_U32 DWord;
  72. pPrt = &pAC->GIni.GP[Port];
  73. DWord = (SK_U32)(PollTxD ? CSR_ENA_POL : CSR_DIS_POL);
  74. if (pPrt->PXSQSize != 0) {
  75. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), DWord);
  76. }
  77. if (pPrt->PXAQSize != 0) {
  78. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), DWord);
  79. }
  80. } /* SkGePollTxD */
  81. /******************************************************************************
  82. *
  83. * SkGeYellowLED() - Switch the yellow LED on or off.
  84. *
  85. * Description:
  86. * Switch the yellow LED on or off.
  87. *
  88. * Note:
  89. * This function may be called any time after SkGeInit(Level 1).
  90. *
  91. * Returns:
  92. * nothing
  93. */
  94. void SkGeYellowLED(
  95. SK_AC *pAC, /* adapter context */
  96. SK_IOC IoC, /* IO context */
  97. int State) /* yellow LED state, 0 = OFF, 0 != ON */
  98. {
  99. if (State == 0) {
  100. /* Switch yellow LED OFF */
  101. SK_OUT8(IoC, B0_LED, LED_STAT_OFF);
  102. }
  103. else {
  104. /* Switch yellow LED ON */
  105. SK_OUT8(IoC, B0_LED, LED_STAT_ON);
  106. }
  107. } /* SkGeYellowLED */
  108. #if (!defined(SK_SLIM) || defined(GENESIS))
  109. /******************************************************************************
  110. *
  111. * SkGeXmitLED() - Modify the Operational Mode of a transmission LED.
  112. *
  113. * Description:
  114. * The Rx or Tx LED which is specified by 'Led' will be
  115. * enabled, disabled or switched on in test mode.
  116. *
  117. * Note:
  118. * 'Led' must contain the address offset of the LEDs INI register.
  119. *
  120. * Usage:
  121. * SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_ENA);
  122. *
  123. * Returns:
  124. * nothing
  125. */
  126. void SkGeXmitLED(
  127. SK_AC *pAC, /* adapter context */
  128. SK_IOC IoC, /* IO context */
  129. int Led, /* offset to the LED Init Value register */
  130. int Mode) /* Mode may be SK_LED_DIS, SK_LED_ENA, SK_LED_TST */
  131. {
  132. SK_U32 LedIni;
  133. switch (Mode) {
  134. case SK_LED_ENA:
  135. LedIni = SK_XMIT_DUR * (SK_U32)pAC->GIni.GIHstClkFact / 100;
  136. SK_OUT32(IoC, Led + XMIT_LED_INI, LedIni);
  137. SK_OUT8(IoC, Led + XMIT_LED_CTRL, LED_START);
  138. break;
  139. case SK_LED_TST:
  140. SK_OUT8(IoC, Led + XMIT_LED_TST, LED_T_ON);
  141. SK_OUT32(IoC, Led + XMIT_LED_CNT, 100);
  142. SK_OUT8(IoC, Led + XMIT_LED_CTRL, LED_START);
  143. break;
  144. case SK_LED_DIS:
  145. default:
  146. /*
  147. * Do NOT stop the LED Timer here. The LED might be
  148. * in on state. But it needs to go off.
  149. */
  150. SK_OUT32(IoC, Led + XMIT_LED_CNT, 0);
  151. SK_OUT8(IoC, Led + XMIT_LED_TST, LED_T_OFF);
  152. break;
  153. }
  154. /*
  155. * 1000BT: The Transmit LED is driven by the PHY.
  156. * But the default LED configuration is used for
  157. * Level One and Broadcom PHYs.
  158. * (Broadcom: It may be that PHY_B_PEC_EN_LTR has to be set.)
  159. * (In this case it has to be added here. But we will see. XXX)
  160. */
  161. } /* SkGeXmitLED */
  162. #endif /* !SK_SLIM || GENESIS */
  163. /******************************************************************************
  164. *
  165. * DoCalcAddr() - Calculates the start and the end address of a queue.
  166. *
  167. * Description:
  168. * This function calculates the start and the end address of a queue.
  169. * Afterwards the 'StartVal' is incremented to the next start position.
  170. * If the port is already initialized the calculated values
  171. * will be checked against the configured values and an
  172. * error will be returned, if they are not equal.
  173. * If the port is not initialized the values will be written to
  174. * *StartAdr and *EndAddr.
  175. *
  176. * Returns:
  177. * 0: success
  178. * 1: configuration error
  179. */
  180. static int DoCalcAddr(
  181. SK_AC *pAC, /* adapter context */
  182. SK_GEPORT SK_FAR *pPrt, /* port index */
  183. int QuSize, /* size of the queue to configure in kB */
  184. SK_U32 SK_FAR *StartVal, /* start value for address calculation */
  185. SK_U32 SK_FAR *QuStartAddr,/* start addr to calculate */
  186. SK_U32 SK_FAR *QuEndAddr) /* end address to calculate */
  187. {
  188. SK_U32 EndVal;
  189. SK_U32 NextStart;
  190. int Rtv;
  191. Rtv = 0;
  192. if (QuSize == 0) {
  193. EndVal = *StartVal;
  194. NextStart = EndVal;
  195. }
  196. else {
  197. EndVal = *StartVal + ((SK_U32)QuSize * 1024) - 1;
  198. NextStart = EndVal + 1;
  199. }
  200. if (pPrt->PState >= SK_PRT_INIT) {
  201. if (*StartVal != *QuStartAddr || EndVal != *QuEndAddr) {
  202. Rtv = 1;
  203. }
  204. }
  205. else {
  206. *QuStartAddr = *StartVal;
  207. *QuEndAddr = EndVal;
  208. }
  209. *StartVal = NextStart;
  210. return(Rtv);
  211. } /* DoCalcAddr */
  212. /******************************************************************************
  213. *
  214. * SkGeInitAssignRamToQueues() - allocate default queue sizes
  215. *
  216. * Description:
  217. * This function assigns the memory to the different queues and ports.
  218. * When DualNet is set to SK_TRUE all ports get the same amount of memory.
  219. * Otherwise the first port gets most of the memory and all the
  220. * other ports just the required minimum.
  221. * This function can only be called when pAC->GIni.GIRamSize and
  222. * pAC->GIni.GIMacsFound have been initialized, usually this happens
  223. * at init level 1
  224. *
  225. * Returns:
  226. * 0 - ok
  227. * 1 - invalid input values
  228. * 2 - not enough memory
  229. */
  230. int SkGeInitAssignRamToQueues(
  231. SK_AC *pAC, /* Adapter context */
  232. int ActivePort, /* Active Port in RLMT mode */
  233. SK_BOOL DualNet) /* adapter context */
  234. {
  235. int i;
  236. int UsedKilobytes; /* memory already assigned */
  237. int ActivePortKilobytes; /* memory available for active port */
  238. SK_GEPORT *pGePort;
  239. UsedKilobytes = 0;
  240. if (ActivePort >= pAC->GIni.GIMacsFound) {
  241. SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
  242. ("SkGeInitAssignRamToQueues: ActivePort (%d) invalid\n",
  243. ActivePort));
  244. return(1);
  245. }
  246. if (((pAC->GIni.GIMacsFound * (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE)) +
  247. ((RAM_QUOTA_SYNC == 0) ? 0 : SK_MIN_TXQ_SIZE)) > pAC->GIni.GIRamSize) {
  248. SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
  249. ("SkGeInitAssignRamToQueues: Not enough memory (%d)\n",
  250. pAC->GIni.GIRamSize));
  251. return(2);
  252. }
  253. if (DualNet) {
  254. /* every port gets the same amount of memory */
  255. ActivePortKilobytes = pAC->GIni.GIRamSize / pAC->GIni.GIMacsFound;
  256. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  257. pGePort = &pAC->GIni.GP[i];
  258. /* take away the minimum memory for active queues */
  259. ActivePortKilobytes -= (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE);
  260. /* receive queue gets the minimum + 80% of the rest */
  261. pGePort->PRxQSize = (int) (ROUND_QUEUE_SIZE_KB((
  262. ActivePortKilobytes * (unsigned long) RAM_QUOTA_RX) / 100))
  263. + SK_MIN_RXQ_SIZE;
  264. ActivePortKilobytes -= (pGePort->PRxQSize - SK_MIN_RXQ_SIZE);
  265. /* synchronous transmit queue */
  266. pGePort->PXSQSize = 0;
  267. /* asynchronous transmit queue */
  268. pGePort->PXAQSize = (int) ROUND_QUEUE_SIZE_KB(ActivePortKilobytes +
  269. SK_MIN_TXQ_SIZE);
  270. }
  271. }
  272. else {
  273. /* Rlmt Mode or single link adapter */
  274. /* Set standby queue size defaults for all standby ports */
  275. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  276. if (i != ActivePort) {
  277. pGePort = &pAC->GIni.GP[i];
  278. pGePort->PRxQSize = SK_MIN_RXQ_SIZE;
  279. pGePort->PXAQSize = SK_MIN_TXQ_SIZE;
  280. pGePort->PXSQSize = 0;
  281. /* Count used RAM */
  282. UsedKilobytes += pGePort->PRxQSize + pGePort->PXAQSize;
  283. }
  284. }
  285. /* what's left? */
  286. ActivePortKilobytes = pAC->GIni.GIRamSize - UsedKilobytes;
  287. /* assign it to the active port */
  288. /* first take away the minimum memory */
  289. ActivePortKilobytes -= (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE);
  290. pGePort = &pAC->GIni.GP[ActivePort];
  291. /* receive queue get's the minimum + 80% of the rest */
  292. pGePort->PRxQSize = (int) (ROUND_QUEUE_SIZE_KB((ActivePortKilobytes *
  293. (unsigned long) RAM_QUOTA_RX) / 100)) + SK_MIN_RXQ_SIZE;
  294. ActivePortKilobytes -= (pGePort->PRxQSize - SK_MIN_RXQ_SIZE);
  295. /* synchronous transmit queue */
  296. pGePort->PXSQSize = 0;
  297. /* asynchronous transmit queue */
  298. pGePort->PXAQSize = (int) ROUND_QUEUE_SIZE_KB(ActivePortKilobytes) +
  299. SK_MIN_TXQ_SIZE;
  300. }
  301. #ifdef VCPU
  302. VCPUprintf(0, "PRxQSize=%u, PXSQSize=%u, PXAQSize=%u\n",
  303. pGePort->PRxQSize, pGePort->PXSQSize, pGePort->PXAQSize);
  304. #endif /* VCPU */
  305. return(0);
  306. } /* SkGeInitAssignRamToQueues */
  307. /******************************************************************************
  308. *
  309. * SkGeCheckQSize() - Checks the Adapters Queue Size Configuration
  310. *
  311. * Description:
  312. * This function verifies the Queue Size Configuration specified
  313. * in the variables PRxQSize, PXSQSize, and PXAQSize of all
  314. * used ports.
  315. * This requirements must be fullfilled to have a valid configuration:
  316. * - The size of all queues must not exceed GIRamSize.
  317. * - The queue sizes must be specified in units of 8 kB.
  318. * - The size of Rx queues of available ports must not be
  319. * smaller than 16 kB.
  320. * - The size of at least one Tx queue (synch. or asynch.)
  321. * of available ports must not be smaller than 16 kB
  322. * when Jumbo Frames are used.
  323. * - The RAM start and end addresses must not be changed
  324. * for ports which are already initialized.
  325. * Furthermore SkGeCheckQSize() defines the Start and End Addresses
  326. * of all ports and stores them into the HWAC port structure.
  327. *
  328. * Returns:
  329. * 0: Queue Size Configuration valid
  330. * 1: Queue Size Configuration invalid
  331. */
  332. static int SkGeCheckQSize(
  333. SK_AC *pAC, /* adapter context */
  334. int Port) /* port index */
  335. {
  336. SK_GEPORT *pPrt;
  337. int i;
  338. int Rtv;
  339. int Rtv2;
  340. SK_U32 StartAddr;
  341. #ifndef SK_SLIM
  342. int UsedMem; /* total memory used (max. found ports) */
  343. #endif
  344. Rtv = 0;
  345. #ifndef SK_SLIM
  346. UsedMem = 0;
  347. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  348. pPrt = &pAC->GIni.GP[i];
  349. if ((pPrt->PRxQSize & QZ_UNITS) != 0 ||
  350. (pPrt->PXSQSize & QZ_UNITS) != 0 ||
  351. (pPrt->PXAQSize & QZ_UNITS) != 0) {
  352. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E012, SKERR_HWI_E012MSG);
  353. return(1);
  354. }
  355. if (i == Port && pPrt->PRxQSize < SK_MIN_RXQ_SIZE) {
  356. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E011, SKERR_HWI_E011MSG);
  357. return(1);
  358. }
  359. /*
  360. * the size of at least one Tx queue (synch. or asynch.) has to be > 0.
  361. * if Jumbo Frames are used, this size has to be >= 16 kB.
  362. */
  363. if ((i == Port && pPrt->PXSQSize == 0 && pPrt->PXAQSize == 0) ||
  364. (pAC->GIni.GIPortUsage == SK_JUMBO_LINK &&
  365. ((pPrt->PXSQSize > 0 && pPrt->PXSQSize < SK_MIN_TXQ_SIZE) ||
  366. (pPrt->PXAQSize > 0 && pPrt->PXAQSize < SK_MIN_TXQ_SIZE)))) {
  367. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E023, SKERR_HWI_E023MSG);
  368. return(1);
  369. }
  370. UsedMem += pPrt->PRxQSize + pPrt->PXSQSize + pPrt->PXAQSize;
  371. }
  372. if (UsedMem > pAC->GIni.GIRamSize) {
  373. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E012, SKERR_HWI_E012MSG);
  374. return(1);
  375. }
  376. #endif /* !SK_SLIM */
  377. /* Now start address calculation */
  378. StartAddr = pAC->GIni.GIRamOffs;
  379. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  380. pPrt = &pAC->GIni.GP[i];
  381. /* Calculate/Check values for the receive queue */
  382. Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PRxQSize, &StartAddr,
  383. &pPrt->PRxQRamStart, &pPrt->PRxQRamEnd);
  384. Rtv |= Rtv2;
  385. /* Calculate/Check values for the synchronous Tx queue */
  386. Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PXSQSize, &StartAddr,
  387. &pPrt->PXsQRamStart, &pPrt->PXsQRamEnd);
  388. Rtv |= Rtv2;
  389. /* Calculate/Check values for the asynchronous Tx queue */
  390. Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PXAQSize, &StartAddr,
  391. &pPrt->PXaQRamStart, &pPrt->PXaQRamEnd);
  392. Rtv |= Rtv2;
  393. if (Rtv) {
  394. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E013, SKERR_HWI_E013MSG);
  395. return(1);
  396. }
  397. }
  398. return(0);
  399. } /* SkGeCheckQSize */
  400. #ifdef GENESIS
  401. /******************************************************************************
  402. *
  403. * SkGeInitMacArb() - Initialize the MAC Arbiter
  404. *
  405. * Description:
  406. * This function initializes the MAC Arbiter.
  407. * It must not be called if there is still an
  408. * initialized or active port.
  409. *
  410. * Returns:
  411. * nothing
  412. */
  413. static void SkGeInitMacArb(
  414. SK_AC *pAC, /* adapter context */
  415. SK_IOC IoC) /* IO context */
  416. {
  417. /* release local reset */
  418. SK_OUT16(IoC, B3_MA_TO_CTRL, MA_RST_CLR);
  419. /* configure timeout values */
  420. SK_OUT8(IoC, B3_MA_TOINI_RX1, SK_MAC_TO_53);
  421. SK_OUT8(IoC, B3_MA_TOINI_RX2, SK_MAC_TO_53);
  422. SK_OUT8(IoC, B3_MA_TOINI_TX1, SK_MAC_TO_53);
  423. SK_OUT8(IoC, B3_MA_TOINI_TX2, SK_MAC_TO_53);
  424. SK_OUT8(IoC, B3_MA_RCINI_RX1, 0);
  425. SK_OUT8(IoC, B3_MA_RCINI_RX2, 0);
  426. SK_OUT8(IoC, B3_MA_RCINI_TX1, 0);
  427. SK_OUT8(IoC, B3_MA_RCINI_TX2, 0);
  428. /* recovery values are needed for XMAC II Rev. B2 only */
  429. /* Fast Output Enable Mode was intended to use with Rev. B2, but now? */
  430. /*
  431. * There is no start or enable button to push, therefore
  432. * the MAC arbiter is configured and enabled now.
  433. */
  434. } /* SkGeInitMacArb */
  435. /******************************************************************************
  436. *
  437. * SkGeInitPktArb() - Initialize the Packet Arbiter
  438. *
  439. * Description:
  440. * This function initializes the Packet Arbiter.
  441. * It must not be called if there is still an
  442. * initialized or active port.
  443. *
  444. * Returns:
  445. * nothing
  446. */
  447. static void SkGeInitPktArb(
  448. SK_AC *pAC, /* adapter context */
  449. SK_IOC IoC) /* IO context */
  450. {
  451. /* release local reset */
  452. SK_OUT16(IoC, B3_PA_CTRL, PA_RST_CLR);
  453. /* configure timeout values */
  454. SK_OUT16(IoC, B3_PA_TOINI_RX1, SK_PKT_TO_MAX);
  455. SK_OUT16(IoC, B3_PA_TOINI_RX2, SK_PKT_TO_MAX);
  456. SK_OUT16(IoC, B3_PA_TOINI_TX1, SK_PKT_TO_MAX);
  457. SK_OUT16(IoC, B3_PA_TOINI_TX2, SK_PKT_TO_MAX);
  458. /*
  459. * enable timeout timers if jumbo frames not used
  460. * NOTE: the packet arbiter timeout interrupt is needed for
  461. * half duplex hangup workaround
  462. */
  463. if (pAC->GIni.GIPortUsage != SK_JUMBO_LINK) {
  464. if (pAC->GIni.GIMacsFound == 1) {
  465. SK_OUT16(IoC, B3_PA_CTRL, PA_ENA_TO_TX1);
  466. }
  467. else {
  468. SK_OUT16(IoC, B3_PA_CTRL, PA_ENA_TO_TX1 | PA_ENA_TO_TX2);
  469. }
  470. }
  471. } /* SkGeInitPktArb */
  472. #endif /* GENESIS */
  473. /******************************************************************************
  474. *
  475. * SkGeInitMacFifo() - Initialize the MAC FIFOs
  476. *
  477. * Description:
  478. * Initialize all MAC FIFOs of the specified port
  479. *
  480. * Returns:
  481. * nothing
  482. */
  483. static void SkGeInitMacFifo(
  484. SK_AC *pAC, /* adapter context */
  485. SK_IOC IoC, /* IO context */
  486. int Port) /* Port Index (MAC_1 + n) */
  487. {
  488. SK_U16 Word;
  489. #ifdef VCPU
  490. SK_U32 DWord;
  491. #endif /* VCPU */
  492. /*
  493. * For each FIFO:
  494. * - release local reset
  495. * - use default value for MAC FIFO size
  496. * - setup defaults for the control register
  497. * - enable the FIFO
  498. */
  499. #ifdef GENESIS
  500. if (pAC->GIni.GIGenesis) {
  501. /* Configure Rx MAC FIFO */
  502. SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_RST_CLR);
  503. SK_OUT16(IoC, MR_ADDR(Port, RX_MFF_CTRL1), MFF_RX_CTRL_DEF);
  504. SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
  505. /* Configure Tx MAC FIFO */
  506. SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_RST_CLR);
  507. SK_OUT16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
  508. SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
  509. /* Enable frame flushing if jumbo frames used */
  510. if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK) {
  511. SK_OUT16(IoC, MR_ADDR(Port, RX_MFF_CTRL1), MFF_ENA_FLUSH);
  512. }
  513. }
  514. #endif /* GENESIS */
  515. #ifdef YUKON
  516. if (pAC->GIni.GIYukon) {
  517. /* set Rx GMAC FIFO Flush Mask */
  518. SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_FL_MSK), (SK_U16)RX_FF_FL_DEF_MSK);
  519. Word = (SK_U16)GMF_RX_CTRL_DEF;
  520. /* disable Rx GMAC FIFO Flush for YUKON-Lite Rev. A0 only */
  521. if (pAC->GIni.GIYukonLite && pAC->GIni.GIChipId == CHIP_ID_YUKON) {
  522. Word &= ~GMF_RX_F_FL_ON;
  523. }
  524. /* Configure Rx MAC FIFO */
  525. SK_OUT8(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), (SK_U8)GMF_RST_CLR);
  526. SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), Word);
  527. /* set Rx GMAC FIFO Flush Threshold (default: 0x0a -> 56 bytes) */
  528. SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF);
  529. /* Configure Tx MAC FIFO */
  530. SK_OUT8(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U8)GMF_RST_CLR);
  531. SK_OUT16(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U16)GMF_TX_CTRL_DEF);
  532. #ifdef VCPU
  533. SK_IN32(IoC, MR_ADDR(Port, RX_GMF_AF_THR), &DWord);
  534. SK_IN32(IoC, MR_ADDR(Port, TX_GMF_AE_THR), &DWord);
  535. #endif /* VCPU */
  536. /* set Tx GMAC FIFO Almost Empty Threshold */
  537. /* SK_OUT32(IoC, MR_ADDR(Port, TX_GMF_AE_THR), 0); */
  538. }
  539. #endif /* YUKON */
  540. } /* SkGeInitMacFifo */
  541. #ifdef SK_LNK_SYNC_CNT
  542. /******************************************************************************
  543. *
  544. * SkGeLoadLnkSyncCnt() - Load the Link Sync Counter and starts counting
  545. *
  546. * Description:
  547. * This function starts the Link Sync Counter of the specified
  548. * port and enables the generation of an Link Sync IRQ.
  549. * The Link Sync Counter may be used to detect an active link,
  550. * if autonegotiation is not used.
  551. *
  552. * Note:
  553. * o To ensure receiving the Link Sync Event the LinkSyncCounter
  554. * should be initialized BEFORE clearing the XMAC's reset!
  555. * o Enable IS_LNK_SYNC_M1 and IS_LNK_SYNC_M2 after calling this
  556. * function.
  557. *
  558. * Returns:
  559. * nothing
  560. */
  561. void SkGeLoadLnkSyncCnt(
  562. SK_AC *pAC, /* adapter context */
  563. SK_IOC IoC, /* IO context */
  564. int Port, /* Port Index (MAC_1 + n) */
  565. SK_U32 CntVal) /* Counter value */
  566. {
  567. SK_U32 OrgIMsk;
  568. SK_U32 NewIMsk;
  569. SK_U32 ISrc;
  570. SK_BOOL IrqPend;
  571. /* stop counter */
  572. SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_STOP);
  573. /*
  574. * ASIC problem:
  575. * Each time starting the Link Sync Counter an IRQ is generated
  576. * by the adapter. See problem report entry from 21.07.98
  577. *
  578. * Workaround: Disable Link Sync IRQ and clear the unexpeced IRQ
  579. * if no IRQ is already pending.
  580. */
  581. IrqPend = SK_FALSE;
  582. SK_IN32(IoC, B0_ISRC, &ISrc);
  583. SK_IN32(IoC, B0_IMSK, &OrgIMsk);
  584. if (Port == MAC_1) {
  585. NewIMsk = OrgIMsk & ~IS_LNK_SYNC_M1;
  586. if ((ISrc & IS_LNK_SYNC_M1) != 0) {
  587. IrqPend = SK_TRUE;
  588. }
  589. }
  590. else {
  591. NewIMsk = OrgIMsk & ~IS_LNK_SYNC_M2;
  592. if ((ISrc & IS_LNK_SYNC_M2) != 0) {
  593. IrqPend = SK_TRUE;
  594. }
  595. }
  596. if (!IrqPend) {
  597. SK_OUT32(IoC, B0_IMSK, NewIMsk);
  598. }
  599. /* load counter */
  600. SK_OUT32(IoC, MR_ADDR(Port, LNK_SYNC_INI), CntVal);
  601. /* start counter */
  602. SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_START);
  603. if (!IrqPend) {
  604. /* clear the unexpected IRQ, and restore the interrupt mask */
  605. SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_CLR_IRQ);
  606. SK_OUT32(IoC, B0_IMSK, OrgIMsk);
  607. }
  608. } /* SkGeLoadLnkSyncCnt*/
  609. #endif /* SK_LNK_SYNC_CNT */
  610. #if defined(SK_DIAG) || defined(SK_CFG_SYNC)
  611. /******************************************************************************
  612. *
  613. * SkGeCfgSync() - Configure synchronous bandwidth for this port.
  614. *
  615. * Description:
  616. * This function may be used to configure synchronous bandwidth
  617. * to the specified port. This may be done any time after
  618. * initializing the port. The configuration values are NOT saved
  619. * in the HWAC port structure and will be overwritten any
  620. * time when stopping and starting the port.
  621. * Any values for the synchronous configuration will be ignored
  622. * if the size of the synchronous queue is zero!
  623. *
  624. * The default configuration for the synchronous service is
  625. * TXA_ENA_FSYNC. This means if the size of
  626. * the synchronous queue is unequal zero but no specific
  627. * synchronous bandwidth is configured, the synchronous queue
  628. * will always have the 'unlimited' transmit priority!
  629. *
  630. * This mode will be restored if the synchronous bandwidth is
  631. * deallocated ('IntTime' = 0 and 'LimCount' = 0).
  632. *
  633. * Returns:
  634. * 0: success
  635. * 1: parameter configuration error
  636. * 2: try to configure quality of service although no
  637. * synchronous queue is configured
  638. */
  639. int SkGeCfgSync(
  640. SK_AC *pAC, /* adapter context */
  641. SK_IOC IoC, /* IO context */
  642. int Port, /* Port Index (MAC_1 + n) */
  643. SK_U32 IntTime, /* Interval Timer Value in units of 8ns */
  644. SK_U32 LimCount, /* Number of bytes to transfer during IntTime */
  645. int SyncMode) /* Sync Mode: TXA_ENA_ALLOC | TXA_DIS_ALLOC | 0 */
  646. {
  647. int Rtv;
  648. Rtv = 0;
  649. /* check the parameters */
  650. if (LimCount > IntTime ||
  651. (LimCount == 0 && IntTime != 0) ||
  652. (LimCount != 0 && IntTime == 0)) {
  653. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E010, SKERR_HWI_E010MSG);
  654. return(1);
  655. }
  656. if (pAC->GIni.GP[Port].PXSQSize == 0) {
  657. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E009, SKERR_HWI_E009MSG);
  658. return(2);
  659. }
  660. /* calculate register values */
  661. IntTime = (IntTime / 2) * pAC->GIni.GIHstClkFact / 100;
  662. LimCount = LimCount / 8;
  663. if (IntTime > TXA_MAX_VAL || LimCount > TXA_MAX_VAL) {
  664. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E010, SKERR_HWI_E010MSG);
  665. return(1);
  666. }
  667. /*
  668. * - Enable 'Force Sync' to ensure the synchronous queue
  669. * has the priority while configuring the new values.
  670. * - Also 'disable alloc' to ensure the settings complies
  671. * to the SyncMode parameter.
  672. * - Disable 'Rate Control' to configure the new values.
  673. * - write IntTime and LimCount
  674. * - start 'Rate Control' and disable 'Force Sync'
  675. * if Interval Timer or Limit Counter not zero.
  676. */
  677. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
  678. TXA_ENA_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
  679. SK_OUT32(IoC, MR_ADDR(Port, TXA_ITI_INI), IntTime);
  680. SK_OUT32(IoC, MR_ADDR(Port, TXA_LIM_INI), LimCount);
  681. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
  682. (SK_U8)(SyncMode & (TXA_ENA_ALLOC | TXA_DIS_ALLOC)));
  683. if (IntTime != 0 || LimCount != 0) {
  684. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL), TXA_DIS_FSYNC | TXA_START_RC);
  685. }
  686. return(0);
  687. } /* SkGeCfgSync */
  688. #endif /* SK_DIAG || SK_CFG_SYNC*/
  689. /******************************************************************************
  690. *
  691. * DoInitRamQueue() - Initialize the RAM Buffer Address of a single Queue
  692. *
  693. * Desccription:
  694. * If the queue is used, enable and initialize it.
  695. * Make sure the queue is still reset, if it is not used.
  696. *
  697. * Returns:
  698. * nothing
  699. */
  700. static void DoInitRamQueue(
  701. SK_AC *pAC, /* adapter context */
  702. SK_IOC IoC, /* IO context */
  703. int QuIoOffs, /* Queue IO Address Offset */
  704. SK_U32 QuStartAddr, /* Queue Start Address */
  705. SK_U32 QuEndAddr, /* Queue End Address */
  706. int QuType) /* Queue Type (SK_RX_SRAM_Q|SK_RX_BRAM_Q|SK_TX_RAM_Q) */
  707. {
  708. SK_U32 RxUpThresVal;
  709. SK_U32 RxLoThresVal;
  710. if (QuStartAddr != QuEndAddr) {
  711. /* calculate thresholds, assume we have a big Rx queue */
  712. RxUpThresVal = (QuEndAddr + 1 - QuStartAddr - SK_RB_ULPP) / 8;
  713. RxLoThresVal = (QuEndAddr + 1 - QuStartAddr - SK_RB_LLPP_B)/8;
  714. /* build HW address format */
  715. QuStartAddr = QuStartAddr / 8;
  716. QuEndAddr = QuEndAddr / 8;
  717. /* release local reset */
  718. SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_RST_CLR);
  719. /* configure addresses */
  720. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_START), QuStartAddr);
  721. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_END), QuEndAddr);
  722. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_WP), QuStartAddr);
  723. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RP), QuStartAddr);
  724. switch (QuType) {
  725. case SK_RX_SRAM_Q:
  726. /* configure threshold for small Rx Queue */
  727. RxLoThresVal += (SK_RB_LLPP_B - SK_RB_LLPP_S) / 8;
  728. /* continue with SK_RX_BRAM_Q */
  729. case SK_RX_BRAM_Q:
  730. /* write threshold for Rx Queue */
  731. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RX_UTPP), RxUpThresVal);
  732. SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RX_LTPP), RxLoThresVal);
  733. /* the high priority threshold not used */
  734. break;
  735. case SK_TX_RAM_Q:
  736. /*
  737. * Do NOT use Store & Forward under normal operation due to
  738. * performance optimization (GENESIS only).
  739. * But if Jumbo Frames are configured (XMAC Tx FIFO is only 4 kB)
  740. * or YUKON is used ((GMAC Tx FIFO is only 1 kB)
  741. * we NEED Store & Forward of the RAM buffer.
  742. */
  743. if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK ||
  744. pAC->GIni.GIYukon) {
  745. /* enable Store & Forward Mode for the Tx Side */
  746. SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_ENA_STFWD);
  747. }
  748. break;
  749. }
  750. /* set queue operational */
  751. SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_ENA_OP_MD);
  752. }
  753. else {
  754. /* ensure the queue is still disabled */
  755. SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_RST_SET);
  756. }
  757. } /* DoInitRamQueue */
  758. /******************************************************************************
  759. *
  760. * SkGeInitRamBufs() - Initialize the RAM Buffer Queues
  761. *
  762. * Description:
  763. * Initialize all RAM Buffer Queues of the specified port
  764. *
  765. * Returns:
  766. * nothing
  767. */
  768. static void SkGeInitRamBufs(
  769. SK_AC *pAC, /* adapter context */
  770. SK_IOC IoC, /* IO context */
  771. int Port) /* Port Index (MAC_1 + n) */
  772. {
  773. SK_GEPORT *pPrt;
  774. int RxQType;
  775. pPrt = &pAC->GIni.GP[Port];
  776. if (pPrt->PRxQSize == SK_MIN_RXQ_SIZE) {
  777. RxQType = SK_RX_SRAM_Q; /* small Rx Queue */
  778. }
  779. else {
  780. RxQType = SK_RX_BRAM_Q; /* big Rx Queue */
  781. }
  782. DoInitRamQueue(pAC, IoC, pPrt->PRxQOff, pPrt->PRxQRamStart,
  783. pPrt->PRxQRamEnd, RxQType);
  784. DoInitRamQueue(pAC, IoC, pPrt->PXsQOff, pPrt->PXsQRamStart,
  785. pPrt->PXsQRamEnd, SK_TX_RAM_Q);
  786. DoInitRamQueue(pAC, IoC, pPrt->PXaQOff, pPrt->PXaQRamStart,
  787. pPrt->PXaQRamEnd, SK_TX_RAM_Q);
  788. } /* SkGeInitRamBufs */
  789. /******************************************************************************
  790. *
  791. * SkGeInitRamIface() - Initialize the RAM Interface
  792. *
  793. * Description:
  794. * This function initializes the Adapters RAM Interface.
  795. *
  796. * Note:
  797. * This function is used in the diagnostics.
  798. *
  799. * Returns:
  800. * nothing
  801. */
  802. static void SkGeInitRamIface(
  803. SK_AC *pAC, /* adapter context */
  804. SK_IOC IoC) /* IO context */
  805. {
  806. /* release local reset */
  807. SK_OUT16(IoC, B3_RI_CTRL, RI_RST_CLR);
  808. /* configure timeout values */
  809. SK_OUT8(IoC, B3_RI_WTO_R1, SK_RI_TO_53);
  810. SK_OUT8(IoC, B3_RI_WTO_XA1, SK_RI_TO_53);
  811. SK_OUT8(IoC, B3_RI_WTO_XS1, SK_RI_TO_53);
  812. SK_OUT8(IoC, B3_RI_RTO_R1, SK_RI_TO_53);
  813. SK_OUT8(IoC, B3_RI_RTO_XA1, SK_RI_TO_53);
  814. SK_OUT8(IoC, B3_RI_RTO_XS1, SK_RI_TO_53);
  815. SK_OUT8(IoC, B3_RI_WTO_R2, SK_RI_TO_53);
  816. SK_OUT8(IoC, B3_RI_WTO_XA2, SK_RI_TO_53);
  817. SK_OUT8(IoC, B3_RI_WTO_XS2, SK_RI_TO_53);
  818. SK_OUT8(IoC, B3_RI_RTO_R2, SK_RI_TO_53);
  819. SK_OUT8(IoC, B3_RI_RTO_XA2, SK_RI_TO_53);
  820. SK_OUT8(IoC, B3_RI_RTO_XS2, SK_RI_TO_53);
  821. } /* SkGeInitRamIface */
  822. /******************************************************************************
  823. *
  824. * SkGeInitBmu() - Initialize the BMU state machines
  825. *
  826. * Description:
  827. * Initialize all BMU state machines of the specified port
  828. *
  829. * Returns:
  830. * nothing
  831. */
  832. static void SkGeInitBmu(
  833. SK_AC *pAC, /* adapter context */
  834. SK_IOC IoC, /* IO context */
  835. int Port) /* Port Index (MAC_1 + n) */
  836. {
  837. SK_GEPORT *pPrt;
  838. SK_U32 RxWm;
  839. SK_U32 TxWm;
  840. pPrt = &pAC->GIni.GP[Port];
  841. RxWm = SK_BMU_RX_WM;
  842. TxWm = SK_BMU_TX_WM;
  843. if (!pAC->GIni.GIPciSlot64 && !pAC->GIni.GIPciClock66) {
  844. /* for better performance */
  845. RxWm /= 2;
  846. TxWm /= 2;
  847. }
  848. /* Rx Queue: Release all local resets and set the watermark */
  849. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_CLR_RESET);
  850. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_F), RxWm);
  851. /*
  852. * Tx Queue: Release all local resets if the queue is used !
  853. * set watermark
  854. */
  855. if (pPrt->PXSQSize != 0) {
  856. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_CLR_RESET);
  857. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_F), TxWm);
  858. }
  859. if (pPrt->PXAQSize != 0) {
  860. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_CLR_RESET);
  861. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_F), TxWm);
  862. }
  863. /*
  864. * Do NOT enable the descriptor poll timers here, because
  865. * the descriptor addresses are not specified yet.
  866. */
  867. } /* SkGeInitBmu */
  868. /******************************************************************************
  869. *
  870. * TestStopBit() - Test the stop bit of the queue
  871. *
  872. * Description:
  873. * Stopping a queue is not as simple as it seems to be.
  874. * If descriptor polling is enabled, it may happen
  875. * that RX/TX stop is done and SV idle is NOT set.
  876. * In this case we have to issue another stop command.
  877. *
  878. * Returns:
  879. * The queues control status register
  880. */
  881. static SK_U32 TestStopBit(
  882. SK_AC *pAC, /* Adapter Context */
  883. SK_IOC IoC, /* IO Context */
  884. int QuIoOffs) /* Queue IO Address Offset */
  885. {
  886. SK_U32 QuCsr; /* CSR contents */
  887. SK_IN32(IoC, Q_ADDR(QuIoOffs, Q_CSR), &QuCsr);
  888. if ((QuCsr & (CSR_STOP | CSR_SV_IDLE)) == 0) {
  889. /* Stop Descriptor overridden by start command */
  890. SK_OUT32(IoC, Q_ADDR(QuIoOffs, Q_CSR), CSR_STOP);
  891. SK_IN32(IoC, Q_ADDR(QuIoOffs, Q_CSR), &QuCsr);
  892. }
  893. return(QuCsr);
  894. } /* TestStopBit */
  895. /******************************************************************************
  896. *
  897. * SkGeStopPort() - Stop the Rx/Tx activity of the port 'Port'.
  898. *
  899. * Description:
  900. * After calling this function the descriptor rings and Rx and Tx
  901. * queues of this port may be reconfigured.
  902. *
  903. * It is possible to stop the receive and transmit path separate or
  904. * both together.
  905. *
  906. * Dir = SK_STOP_TX Stops the transmit path only and resets the MAC.
  907. * The receive queue is still active and
  908. * the pending Rx frames may be still transferred
  909. * into the RxD.
  910. * SK_STOP_RX Stop the receive path. The tansmit path
  911. * has to be stopped once before.
  912. * SK_STOP_ALL SK_STOP_TX + SK_STOP_RX
  913. *
  914. * RstMode = SK_SOFT_RST Resets the MAC. The PHY is still alive.
  915. * SK_HARD_RST Resets the MAC and the PHY.
  916. *
  917. * Example:
  918. * 1) A Link Down event was signaled for a port. Therefore the activity
  919. * of this port should be stopped and a hardware reset should be issued
  920. * to enable the workaround of XMAC Errata #2. But the received frames
  921. * should not be discarded.
  922. * ...
  923. * SkGeStopPort(pAC, IoC, Port, SK_STOP_TX, SK_HARD_RST);
  924. * (transfer all pending Rx frames)
  925. * SkGeStopPort(pAC, IoC, Port, SK_STOP_RX, SK_HARD_RST);
  926. * ...
  927. *
  928. * 2) An event was issued which request the driver to switch
  929. * the 'virtual active' link to an other already active port
  930. * as soon as possible. The frames in the receive queue of this
  931. * port may be lost. But the PHY must not be reset during this
  932. * event.
  933. * ...
  934. * SkGeStopPort(pAC, IoC, Port, SK_STOP_ALL, SK_SOFT_RST);
  935. * ...
  936. *
  937. * Extended Description:
  938. * If SK_STOP_TX is set,
  939. * o disable the MAC's receive and transmitter to prevent
  940. * from sending incomplete frames
  941. * o stop the port's transmit queues before terminating the
  942. * BMUs to prevent from performing incomplete PCI cycles
  943. * on the PCI bus
  944. * - The network Rx and Tx activity and PCI Tx transfer is
  945. * disabled now.
  946. * o reset the MAC depending on the RstMode
  947. * o Stop Interval Timer and Limit Counter of Tx Arbiter,
  948. * also disable Force Sync bit and Enable Alloc bit.
  949. * o perform a local reset of the port's Tx path
  950. * - reset the PCI FIFO of the async Tx queue
  951. * - reset the PCI FIFO of the sync Tx queue
  952. * - reset the RAM Buffer async Tx queue
  953. * - reset the RAM Buffer sync Tx queue
  954. * - reset the MAC Tx FIFO
  955. * o switch Link and Tx LED off, stop the LED counters
  956. *
  957. * If SK_STOP_RX is set,
  958. * o stop the port's receive queue
  959. * - The path data transfer activity is fully stopped now.
  960. * o perform a local reset of the port's Rx path
  961. * - reset the PCI FIFO of the Rx queue
  962. * - reset the RAM Buffer receive queue
  963. * - reset the MAC Rx FIFO
  964. * o switch Rx LED off, stop the LED counter
  965. *
  966. * If all ports are stopped,
  967. * o reset the RAM Interface.
  968. *
  969. * Notes:
  970. * o This function may be called during the driver states RESET_PORT and
  971. * SWITCH_PORT.
  972. */
  973. void SkGeStopPort(
  974. SK_AC *pAC, /* adapter context */
  975. SK_IOC IoC, /* I/O context */
  976. int Port, /* port to stop (MAC_1 + n) */
  977. int Dir, /* Direction to Stop (SK_STOP_RX, SK_STOP_TX, SK_STOP_ALL) */
  978. int RstMode)/* Reset Mode (SK_SOFT_RST, SK_HARD_RST) */
  979. {
  980. #ifndef SK_DIAG
  981. SK_EVPARA Para;
  982. #endif /* !SK_DIAG */
  983. SK_GEPORT *pPrt;
  984. SK_U32 DWord;
  985. SK_U32 XsCsr;
  986. SK_U32 XaCsr;
  987. SK_U64 ToutStart;
  988. int i;
  989. int ToutCnt;
  990. pPrt = &pAC->GIni.GP[Port];
  991. if ((Dir & SK_STOP_TX) != 0) {
  992. /* disable receiver and transmitter */
  993. SkMacRxTxDisable(pAC, IoC, Port);
  994. /* stop both transmit queues */
  995. /*
  996. * If the BMU is in the reset state CSR_STOP will terminate
  997. * immediately.
  998. */
  999. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_STOP);
  1000. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_STOP);
  1001. ToutStart = SkOsGetTime(pAC);
  1002. ToutCnt = 0;
  1003. do {
  1004. /*
  1005. * Clear packet arbiter timeout to make sure
  1006. * this loop will terminate.
  1007. */
  1008. SK_OUT16(IoC, B3_PA_CTRL, (SK_U16)((Port == MAC_1) ?
  1009. PA_CLR_TO_TX1 : PA_CLR_TO_TX2));
  1010. /*
  1011. * If the transfer stucks at the MAC the STOP command will not
  1012. * terminate if we don't flush the XMAC's transmit FIFO !
  1013. */
  1014. SkMacFlushTxFifo(pAC, IoC, Port);
  1015. XsCsr = TestStopBit(pAC, IoC, pPrt->PXsQOff);
  1016. XaCsr = TestStopBit(pAC, IoC, pPrt->PXaQOff);
  1017. if (SkOsGetTime(pAC) - ToutStart > (SK_TICKS_PER_SEC / 18)) {
  1018. /*
  1019. * Timeout of 1/18 second reached.
  1020. * This needs to be checked at 1/18 sec only.
  1021. */
  1022. ToutCnt++;
  1023. if (ToutCnt > 1) {
  1024. /* Might be a problem when the driver event handler
  1025. * calls StopPort again. XXX.
  1026. */
  1027. /* Fatal Error, Loop aborted */
  1028. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_HWI_E018,
  1029. SKERR_HWI_E018MSG);
  1030. #ifndef SK_DIAG
  1031. Para.Para64 = Port;
  1032. SkEventQueue(pAC, SKGE_DRV, SK_DRV_PORT_FAIL, Para);
  1033. #endif /* !SK_DIAG */
  1034. return;
  1035. }
  1036. /*
  1037. * Cache incoherency workaround: Assume a start command
  1038. * has been lost while sending the frame.
  1039. */
  1040. ToutStart = SkOsGetTime(pAC);
  1041. if ((XsCsr & CSR_STOP) != 0) {
  1042. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_START);
  1043. }
  1044. if ((XaCsr & CSR_STOP) != 0) {
  1045. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_START);
  1046. }
  1047. }
  1048. /*
  1049. * Because of the ASIC problem report entry from 21.08.1998 it is
  1050. * required to wait until CSR_STOP is reset and CSR_SV_IDLE is set.
  1051. */
  1052. } while ((XsCsr & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE ||
  1053. (XaCsr & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE);
  1054. /* Reset the MAC depending on the RstMode */
  1055. if (RstMode == SK_SOFT_RST) {
  1056. SkMacSoftRst(pAC, IoC, Port);
  1057. }
  1058. else {
  1059. SkMacHardRst(pAC, IoC, Port);
  1060. }
  1061. /* Disable Force Sync bit and Enable Alloc bit */
  1062. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
  1063. TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
  1064. /* Stop Interval Timer and Limit Counter of Tx Arbiter */
  1065. SK_OUT32(IoC, MR_ADDR(Port, TXA_ITI_INI), 0L);
  1066. SK_OUT32(IoC, MR_ADDR(Port, TXA_LIM_INI), 0L);
  1067. /* Perform a local reset of the port's Tx path */
  1068. /* Reset the PCI FIFO of the async Tx queue */
  1069. SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_SET_RESET);
  1070. /* Reset the PCI FIFO of the sync Tx queue */
  1071. SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_SET_RESET);
  1072. /* Reset the RAM Buffer async Tx queue */
  1073. SK_OUT8(IoC, RB_ADDR(pPrt->PXaQOff, RB_CTRL), RB_RST_SET);
  1074. /* Reset the RAM Buffer sync Tx queue */
  1075. SK_OUT8(IoC, RB_ADDR(pPrt->PXsQOff, RB_CTRL), RB_RST_SET);
  1076. /* Reset Tx MAC FIFO */
  1077. #ifdef GENESIS
  1078. if (pAC->GIni.GIGenesis) {
  1079. /* Note: MFF_RST_SET does NOT reset the XMAC ! */
  1080. SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_RST_SET);
  1081. /* switch Link and Tx LED off, stop the LED counters */
  1082. /* Link LED is switched off by the RLMT and the Diag itself */
  1083. SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_DIS);
  1084. }
  1085. #endif /* GENESIS */
  1086. #ifdef YUKON
  1087. if (pAC->GIni.GIYukon) {
  1088. /* Reset TX MAC FIFO */
  1089. SK_OUT8(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U8)GMF_RST_SET);
  1090. }
  1091. #endif /* YUKON */
  1092. }
  1093. if ((Dir & SK_STOP_RX) != 0) {
  1094. /*
  1095. * The RX Stop Command will not terminate if no buffers
  1096. * are queued in the RxD ring. But it will always reach
  1097. * the Idle state. Therefore we can use this feature to
  1098. * stop the transfer of received packets.
  1099. */
  1100. /* stop the port's receive queue */
  1101. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_STOP);
  1102. i = 100;
  1103. do {
  1104. /*
  1105. * Clear packet arbiter timeout to make sure
  1106. * this loop will terminate
  1107. */
  1108. SK_OUT16(IoC, B3_PA_CTRL, (SK_U16)((Port == MAC_1) ?
  1109. PA_CLR_TO_RX1 : PA_CLR_TO_RX2));
  1110. DWord = TestStopBit(pAC, IoC, pPrt->PRxQOff);
  1111. /* timeout if i==0 (bug fix for #10748) */
  1112. if (--i == 0) {
  1113. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_HWI_E024,
  1114. SKERR_HWI_E024MSG);
  1115. break;
  1116. }
  1117. /*
  1118. * because of the ASIC problem report entry from 21.08.98
  1119. * it is required to wait until CSR_STOP is reset and
  1120. * CSR_SV_IDLE is set.
  1121. */
  1122. } while ((DWord & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE);
  1123. /* The path data transfer activity is fully stopped now */
  1124. /* Perform a local reset of the port's Rx path */
  1125. /* Reset the PCI FIFO of the Rx queue */
  1126. SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_SET_RESET);
  1127. /* Reset the RAM Buffer receive queue */
  1128. SK_OUT8(IoC, RB_ADDR(pPrt->PRxQOff, RB_CTRL), RB_RST_SET);
  1129. /* Reset Rx MAC FIFO */
  1130. #ifdef GENESIS
  1131. if (pAC->GIni.GIGenesis) {
  1132. SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_RST_SET);
  1133. /* switch Rx LED off, stop the LED counter */
  1134. SkGeXmitLED(pAC, IoC, MR_ADDR(Port, RX_LED_INI), SK_LED_DIS);
  1135. }
  1136. #endif /* GENESIS */
  1137. #ifdef YUKON
  1138. if (pAC->GIni.GIYukon) {
  1139. /* Reset Rx MAC FIFO */
  1140. SK_OUT8(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), (SK_U8)GMF_RST_SET);
  1141. }
  1142. #endif /* YUKON */
  1143. }
  1144. } /* SkGeStopPort */
  1145. /******************************************************************************
  1146. *
  1147. * SkGeInit0() - Level 0 Initialization
  1148. *
  1149. * Description:
  1150. * - Initialize the BMU address offsets
  1151. *
  1152. * Returns:
  1153. * nothing
  1154. */
  1155. static void SkGeInit0(
  1156. SK_AC *pAC, /* adapter context */
  1157. SK_IOC IoC) /* IO context */
  1158. {
  1159. int i;
  1160. SK_GEPORT *pPrt;
  1161. for (i = 0; i < SK_MAX_MACS; i++) {
  1162. pPrt = &pAC->GIni.GP[i];
  1163. pPrt->PState = SK_PRT_RESET;
  1164. pPrt->PRxQOff = QOffTab[i].RxQOff;
  1165. pPrt->PXsQOff = QOffTab[i].XsQOff;
  1166. pPrt->PXaQOff = QOffTab[i].XaQOff;
  1167. pPrt->PCheckPar = SK_FALSE;
  1168. pPrt->PIsave = 0;
  1169. pPrt->PPrevShorts = 0;
  1170. pPrt->PLinkResCt = 0;
  1171. pPrt->PAutoNegTOCt = 0;
  1172. pPrt->PPrevRx = 0;
  1173. pPrt->PPrevFcs = 0;
  1174. pPrt->PRxLim = SK_DEF_RX_WA_LIM;
  1175. pPrt->PLinkMode = (SK_U8)SK_LMODE_AUTOFULL;
  1176. pPrt->PLinkSpeedCap = (SK_U8)SK_LSPEED_CAP_1000MBPS;
  1177. pPrt->PLinkSpeed = (SK_U8)SK_LSPEED_1000MBPS;
  1178. pPrt->PLinkSpeedUsed = (SK_U8)SK_LSPEED_STAT_UNKNOWN;
  1179. pPrt->PLinkModeConf = (SK_U8)SK_LMODE_AUTOSENSE;
  1180. pPrt->PFlowCtrlMode = (SK_U8)SK_FLOW_MODE_SYM_OR_REM;
  1181. pPrt->PLinkCap = (SK_U8)(SK_LMODE_CAP_HALF | SK_LMODE_CAP_FULL |
  1182. SK_LMODE_CAP_AUTOHALF | SK_LMODE_CAP_AUTOFULL);
  1183. pPrt->PLinkModeStatus = (SK_U8)SK_LMODE_STAT_UNKNOWN;
  1184. pPrt->PFlowCtrlCap = (SK_U8)SK_FLOW_MODE_SYM_OR_REM;
  1185. pPrt->PFlowCtrlStatus = (SK_U8)SK_FLOW_STAT_NONE;
  1186. pPrt->PMSCap = 0;
  1187. pPrt->PMSMode = (SK_U8)SK_MS_MODE_AUTO;
  1188. pPrt->PMSStatus = (SK_U8)SK_MS_STAT_UNSET;
  1189. pPrt->PLipaAutoNeg = (SK_U8)SK_LIPA_UNKNOWN;
  1190. pPrt->PAutoNegFail = SK_FALSE;
  1191. pPrt->PHWLinkUp = SK_FALSE;
  1192. pPrt->PLinkBroken = SK_TRUE; /* See WA code */
  1193. pPrt->PPhyPowerState = PHY_PM_OPERATIONAL_MODE;
  1194. pPrt->PMacColThres = TX_COL_DEF;
  1195. pPrt->PMacJamLen = TX_JAM_LEN_DEF;
  1196. pPrt->PMacJamIpgVal = TX_JAM_IPG_DEF;
  1197. pPrt->PMacJamIpgData = TX_IPG_JAM_DEF;
  1198. pPrt->PMacIpgData = IPG_DATA_DEF;
  1199. pPrt->PMacLimit4 = SK_FALSE;
  1200. }
  1201. pAC->GIni.GIPortUsage = SK_RED_LINK;
  1202. pAC->GIni.GILedBlinkCtrl = (SK_U16)OemConfig.Value;
  1203. pAC->GIni.GIValIrqMask = IS_ALL_MSK;
  1204. } /* SkGeInit0*/
  1205. /******************************************************************************
  1206. *
  1207. * SkGeInit1() - Level 1 Initialization
  1208. *
  1209. * Description:
  1210. * o Do a software reset.
  1211. * o Clear all reset bits.
  1212. * o Verify that the detected hardware is present.
  1213. * Return an error if not.
  1214. * o Get the hardware configuration
  1215. * + Read the number of MACs/Ports.
  1216. * + Read the RAM size.
  1217. * + Read the PCI Revision Id.
  1218. * + Find out the adapters host clock speed
  1219. * + Read and check the PHY type
  1220. *
  1221. * Returns:
  1222. * 0: success
  1223. * 5: Unexpected PHY type detected
  1224. * 6: HW self test failed
  1225. */
  1226. static int SkGeInit1(
  1227. SK_AC *pAC, /* adapter context */
  1228. SK_IOC IoC) /* IO context */
  1229. {
  1230. SK_U8 Byte;
  1231. SK_U16 Word;
  1232. SK_U16 CtrlStat;
  1233. SK_U32 DWord;
  1234. int RetVal;
  1235. int i;
  1236. RetVal = 0;
  1237. /* save CLK_RUN bits (YUKON-Lite) */
  1238. SK_IN16(IoC, B0_CTST, &CtrlStat);
  1239. /* do the SW-reset */
  1240. SK_OUT8(IoC, B0_CTST, CS_RST_SET);
  1241. /* release the SW-reset */
  1242. SK_OUT8(IoC, B0_CTST, CS_RST_CLR);
  1243. /* reset all error bits in the PCI STATUS register */
  1244. /*
  1245. * Note: PCI Cfg cycles cannot be used, because they are not
  1246. * available on some platforms after 'boot time'.
  1247. */
  1248. SK_IN16(IoC, PCI_C(PCI_STATUS), &Word);
  1249. SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  1250. SK_OUT16(IoC, PCI_C(PCI_STATUS), (SK_U16)(Word | PCI_ERRBITS));
  1251. SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  1252. /* release Master Reset */
  1253. SK_OUT8(IoC, B0_CTST, CS_MRST_CLR);
  1254. #ifdef CLK_RUN
  1255. CtrlStat |= CS_CLK_RUN_ENA;
  1256. #endif /* CLK_RUN */
  1257. /* restore CLK_RUN bits */
  1258. SK_OUT16(IoC, B0_CTST, (SK_U16)(CtrlStat &
  1259. (CS_CLK_RUN_HOT | CS_CLK_RUN_RST | CS_CLK_RUN_ENA)));
  1260. /* read Chip Identification Number */
  1261. SK_IN8(IoC, B2_CHIP_ID, &Byte);
  1262. pAC->GIni.GIChipId = Byte;
  1263. /* read number of MACs */
  1264. SK_IN8(IoC, B2_MAC_CFG, &Byte);
  1265. pAC->GIni.GIMacsFound = (Byte & CFG_SNG_MAC) ? 1 : 2;
  1266. /* get Chip Revision Number */
  1267. pAC->GIni.GIChipRev = (SK_U8)((Byte & CFG_CHIP_R_MSK) >> 4);
  1268. /* get diff. PCI parameters */
  1269. SK_IN16(IoC, B0_CTST, &CtrlStat);
  1270. /* read the adapters RAM size */
  1271. SK_IN8(IoC, B2_E_0, &Byte);
  1272. pAC->GIni.GIGenesis = SK_FALSE;
  1273. pAC->GIni.GIYukon = SK_FALSE;
  1274. pAC->GIni.GIYukonLite = SK_FALSE;
  1275. #ifdef GENESIS
  1276. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1277. pAC->GIni.GIGenesis = SK_TRUE;
  1278. if (Byte == (SK_U8)3) {
  1279. /* special case: 4 x 64k x 36, offset = 0x80000 */
  1280. pAC->GIni.GIRamSize = 1024;
  1281. pAC->GIni.GIRamOffs = (SK_U32)512 * 1024;
  1282. }
  1283. else {
  1284. pAC->GIni.GIRamSize = (int)Byte * 512;
  1285. pAC->GIni.GIRamOffs = 0;
  1286. }
  1287. /* all GE adapters work with 53.125 MHz host clock */
  1288. pAC->GIni.GIHstClkFact = SK_FACT_53;
  1289. /* set Descr. Poll Timer Init Value to 250 ms */
  1290. pAC->GIni.GIPollTimerVal =
  1291. SK_DPOLL_DEF * (SK_U32)pAC->GIni.GIHstClkFact / 100;
  1292. }
  1293. #endif /* GENESIS */
  1294. #ifdef YUKON
  1295. if (pAC->GIni.GIChipId != CHIP_ID_GENESIS) {
  1296. pAC->GIni.GIYukon = SK_TRUE;
  1297. pAC->GIni.GIRamSize = (Byte == (SK_U8)0) ? 128 : (int)Byte * 4;
  1298. pAC->GIni.GIRamOffs = 0;
  1299. /* WA for chip Rev. A */
  1300. pAC->GIni.GIWolOffs = (pAC->GIni.GIChipId == CHIP_ID_YUKON &&
  1301. pAC->GIni.GIChipRev == 0) ? WOL_REG_OFFS : 0;
  1302. /* get PM Capabilities of PCI config space */
  1303. SK_IN16(IoC, PCI_C(PCI_PM_CAP_REG), &Word);
  1304. /* check if VAUX is available */
  1305. if (((CtrlStat & CS_VAUX_AVAIL) != 0) &&
  1306. /* check also if PME from D3cold is set */
  1307. ((Word & PCI_PME_D3C_SUP) != 0)) {
  1308. /* set entry in GE init struct */
  1309. pAC->GIni.GIVauxAvail = SK_TRUE;
  1310. }
  1311. if (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE) {
  1312. /* this is Rev. A1 */
  1313. pAC->GIni.GIYukonLite = SK_TRUE;
  1314. }
  1315. else {
  1316. /* save Flash-Address Register */
  1317. SK_IN32(IoC, B2_FAR, &DWord);
  1318. /* test Flash-Address Register */
  1319. SK_OUT8(IoC, B2_FAR + 3, 0xff);
  1320. SK_IN8(IoC, B2_FAR + 3, &Byte);
  1321. if (Byte != 0) {
  1322. /* this is Rev. A0 */
  1323. pAC->GIni.GIYukonLite = SK_TRUE;
  1324. /* restore Flash-Address Register */
  1325. SK_OUT32(IoC, B2_FAR, DWord);
  1326. }
  1327. }
  1328. /* switch power to VCC (WA for VAUX problem) */
  1329. SK_OUT8(IoC, B0_POWER_CTRL, (SK_U8)(PC_VAUX_ENA | PC_VCC_ENA |
  1330. PC_VAUX_OFF | PC_VCC_ON));
  1331. /* read the Interrupt source */
  1332. SK_IN32(IoC, B0_ISRC, &DWord);
  1333. if ((DWord & IS_HW_ERR) != 0) {
  1334. /* read the HW Error Interrupt source */
  1335. SK_IN32(IoC, B0_HWE_ISRC, &DWord);
  1336. if ((DWord & IS_IRQ_SENSOR) != 0) {
  1337. /* disable HW Error IRQ */
  1338. pAC->GIni.GIValIrqMask &= ~IS_HW_ERR;
  1339. }
  1340. }
  1341. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  1342. /* set GMAC Link Control reset */
  1343. SK_OUT16(IoC, MR_ADDR(i, GMAC_LINK_CTRL), GMLC_RST_SET);
  1344. /* clear GMAC Link Control reset */
  1345. SK_OUT16(IoC, MR_ADDR(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
  1346. }
  1347. /* all YU chips work with 78.125 MHz host clock */
  1348. pAC->GIni.GIHstClkFact = SK_FACT_78;
  1349. pAC->GIni.GIPollTimerVal = SK_DPOLL_MAX; /* 215 ms */
  1350. }
  1351. #endif /* YUKON */
  1352. /* check if 64-bit PCI Slot is present */
  1353. pAC->GIni.GIPciSlot64 = (SK_BOOL)((CtrlStat & CS_BUS_SLOT_SZ) != 0);
  1354. /* check if 66 MHz PCI Clock is active */
  1355. pAC->GIni.GIPciClock66 = (SK_BOOL)((CtrlStat & CS_BUS_CLOCK) != 0);
  1356. /* read PCI HW Revision Id. */
  1357. SK_IN8(IoC, PCI_C(PCI_REV_ID), &Byte);
  1358. pAC->GIni.GIPciHwRev = Byte;
  1359. /* read the PMD type */
  1360. SK_IN8(IoC, B2_PMD_TYP, &Byte);
  1361. pAC->GIni.GICopperType = (SK_U8)(Byte == 'T');
  1362. /* read the PHY type */
  1363. SK_IN8(IoC, B2_E_1, &Byte);
  1364. Byte &= 0x0f; /* the PHY type is stored in the lower nibble */
  1365. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  1366. #ifdef GENESIS
  1367. if (pAC->GIni.GIGenesis) {
  1368. switch (Byte) {
  1369. case SK_PHY_XMAC:
  1370. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_XMAC;
  1371. break;
  1372. case SK_PHY_BCOM:
  1373. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_BCOM;
  1374. pAC->GIni.GP[i].PMSCap = (SK_U8)(SK_MS_CAP_AUTO |
  1375. SK_MS_CAP_MASTER | SK_MS_CAP_SLAVE);
  1376. break;
  1377. #ifdef OTHER_PHY
  1378. case SK_PHY_LONE:
  1379. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_LONE;
  1380. break;
  1381. case SK_PHY_NAT:
  1382. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_NAT;
  1383. break;
  1384. #endif /* OTHER_PHY */
  1385. default:
  1386. /* ERROR: unexpected PHY type detected */
  1387. RetVal = 5;
  1388. break;
  1389. }
  1390. }
  1391. #endif /* GENESIS */
  1392. #ifdef YUKON
  1393. if (pAC->GIni.GIYukon) {
  1394. if (Byte < (SK_U8)SK_PHY_MARV_COPPER) {
  1395. /* if this field is not initialized */
  1396. Byte = (SK_U8)SK_PHY_MARV_COPPER;
  1397. pAC->GIni.GICopperType = SK_TRUE;
  1398. }
  1399. pAC->GIni.GP[i].PhyAddr = PHY_ADDR_MARV;
  1400. if (pAC->GIni.GICopperType) {
  1401. pAC->GIni.GP[i].PLinkSpeedCap = (SK_U8)(SK_LSPEED_CAP_AUTO |
  1402. SK_LSPEED_CAP_10MBPS | SK_LSPEED_CAP_100MBPS |
  1403. SK_LSPEED_CAP_1000MBPS);
  1404. pAC->GIni.GP[i].PLinkSpeed = (SK_U8)SK_LSPEED_AUTO;
  1405. pAC->GIni.GP[i].PMSCap = (SK_U8)(SK_MS_CAP_AUTO |
  1406. SK_MS_CAP_MASTER | SK_MS_CAP_SLAVE);
  1407. }
  1408. else {
  1409. Byte = (SK_U8)SK_PHY_MARV_FIBER;
  1410. }
  1411. }
  1412. #endif /* YUKON */
  1413. pAC->GIni.GP[i].PhyType = (int)Byte;
  1414. SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
  1415. ("PHY type: %d PHY addr: %04x\n", Byte,
  1416. pAC->GIni.GP[i].PhyAddr));
  1417. }
  1418. /* get MAC Type & set function pointers dependent on */
  1419. #ifdef GENESIS
  1420. if (pAC->GIni.GIGenesis) {
  1421. pAC->GIni.GIMacType = SK_MAC_XMAC;
  1422. pAC->GIni.GIFunc.pFnMacUpdateStats = SkXmUpdateStats;
  1423. pAC->GIni.GIFunc.pFnMacStatistic = SkXmMacStatistic;
  1424. pAC->GIni.GIFunc.pFnMacResetCounter = SkXmResetCounter;
  1425. pAC->GIni.GIFunc.pFnMacOverflow = SkXmOverflowStatus;
  1426. }
  1427. #endif /* GENESIS */
  1428. #ifdef YUKON
  1429. if (pAC->GIni.GIYukon) {
  1430. pAC->GIni.GIMacType = SK_MAC_GMAC;
  1431. pAC->GIni.GIFunc.pFnMacUpdateStats = SkGmUpdateStats;
  1432. pAC->GIni.GIFunc.pFnMacStatistic = SkGmMacStatistic;
  1433. pAC->GIni.GIFunc.pFnMacResetCounter = SkGmResetCounter;
  1434. pAC->GIni.GIFunc.pFnMacOverflow = SkGmOverflowStatus;
  1435. #ifdef SPECIAL_HANDLING
  1436. if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
  1437. /* check HW self test result */
  1438. SK_IN8(IoC, B2_E_3, &Byte);
  1439. if (Byte & B2_E3_RES_MASK) {
  1440. RetVal = 6;
  1441. }
  1442. }
  1443. #endif
  1444. }
  1445. #endif /* YUKON */
  1446. return(RetVal);
  1447. } /* SkGeInit1 */
  1448. /******************************************************************************
  1449. *
  1450. * SkGeInit2() - Level 2 Initialization
  1451. *
  1452. * Description:
  1453. * - start the Blink Source Counter
  1454. * - start the Descriptor Poll Timer
  1455. * - configure the MAC-Arbiter
  1456. * - configure the Packet-Arbiter
  1457. * - enable the Tx Arbiters
  1458. * - enable the RAM Interface Arbiter
  1459. *
  1460. * Returns:
  1461. * nothing
  1462. */
  1463. static void SkGeInit2(
  1464. SK_AC *pAC, /* adapter context */
  1465. SK_IOC IoC) /* IO context */
  1466. {
  1467. #ifdef GENESIS
  1468. SK_U32 DWord;
  1469. #endif /* GENESIS */
  1470. int i;
  1471. /* start the Descriptor Poll Timer */
  1472. if (pAC->GIni.GIPollTimerVal != 0) {
  1473. if (pAC->GIni.GIPollTimerVal > SK_DPOLL_MAX) {
  1474. pAC->GIni.GIPollTimerVal = SK_DPOLL_MAX;
  1475. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E017, SKERR_HWI_E017MSG);
  1476. }
  1477. SK_OUT32(IoC, B28_DPT_INI, pAC->GIni.GIPollTimerVal);
  1478. SK_OUT8(IoC, B28_DPT_CTRL, DPT_START);
  1479. }
  1480. #ifdef GENESIS
  1481. if (pAC->GIni.GIGenesis) {
  1482. /* start the Blink Source Counter */
  1483. DWord = SK_BLK_DUR * (SK_U32)pAC->GIni.GIHstClkFact / 100;
  1484. SK_OUT32(IoC, B2_BSC_INI, DWord);
  1485. SK_OUT8(IoC, B2_BSC_CTRL, BSC_START);
  1486. /*
  1487. * Configure the MAC Arbiter and the Packet Arbiter.
  1488. * They will be started once and never be stopped.
  1489. */
  1490. SkGeInitMacArb(pAC, IoC);
  1491. SkGeInitPktArb(pAC, IoC);
  1492. }
  1493. #endif /* GENESIS */
  1494. #ifdef YUKON
  1495. if (pAC->GIni.GIYukon) {
  1496. /* start Time Stamp Timer */
  1497. SK_OUT8(IoC, GMAC_TI_ST_CTRL, (SK_U8)GMT_ST_START);
  1498. }
  1499. #endif /* YUKON */
  1500. /* enable the Tx Arbiters */
  1501. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  1502. SK_OUT8(IoC, MR_ADDR(i, TXA_CTRL), TXA_ENA_ARB);
  1503. }
  1504. /* enable the RAM Interface Arbiter */
  1505. SkGeInitRamIface(pAC, IoC);
  1506. } /* SkGeInit2 */
  1507. /******************************************************************************
  1508. *
  1509. * SkGeInit() - Initialize the GE Adapter with the specified level.
  1510. *
  1511. * Description:
  1512. * Level 0: Initialize the Module structures.
  1513. * Level 1: Generic Hardware Initialization. The IOP/MemBase pointer has
  1514. * to be set before calling this level.
  1515. *
  1516. * o Do a software reset.
  1517. * o Clear all reset bits.
  1518. * o Verify that the detected hardware is present.
  1519. * Return an error if not.
  1520. * o Get the hardware configuration
  1521. * + Set GIMacsFound with the number of MACs.
  1522. * + Store the RAM size in GIRamSize.
  1523. * + Save the PCI Revision ID in GIPciHwRev.
  1524. * o return an error
  1525. * if Number of MACs > SK_MAX_MACS
  1526. *
  1527. * After returning from Level 0 the adapter
  1528. * may be accessed with IO operations.
  1529. *
  1530. * Level 2: start the Blink Source Counter
  1531. *
  1532. * Returns:
  1533. * 0: success
  1534. * 1: Number of MACs exceeds SK_MAX_MACS (after level 1)
  1535. * 2: Adapter not present or not accessible
  1536. * 3: Illegal initialization level
  1537. * 4: Initialization Level 1 Call missing
  1538. * 5: Unexpected PHY type detected
  1539. * 6: HW self test failed
  1540. */
  1541. int SkGeInit(
  1542. SK_AC *pAC, /* adapter context */
  1543. SK_IOC IoC, /* IO context */
  1544. int Level) /* initialization level */
  1545. {
  1546. int RetVal; /* return value */
  1547. SK_U32 DWord;
  1548. RetVal = 0;
  1549. SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
  1550. ("SkGeInit(Level %d)\n", Level));
  1551. switch (Level) {
  1552. case SK_INIT_DATA:
  1553. /* Initialization Level 0 */
  1554. SkGeInit0(pAC, IoC);
  1555. pAC->GIni.GILevel = SK_INIT_DATA;
  1556. break;
  1557. case SK_INIT_IO:
  1558. /* Initialization Level 1 */
  1559. RetVal = SkGeInit1(pAC, IoC);
  1560. if (RetVal != 0) {
  1561. break;
  1562. }
  1563. /* check if the adapter seems to be accessible */
  1564. SK_OUT32(IoC, B2_IRQM_INI, SK_TEST_VAL);
  1565. SK_IN32(IoC, B2_IRQM_INI, &DWord);
  1566. SK_OUT32(IoC, B2_IRQM_INI, 0L);
  1567. if (DWord != SK_TEST_VAL) {
  1568. RetVal = 2;
  1569. break;
  1570. }
  1571. /* check if the number of GIMacsFound matches SK_MAX_MACS */
  1572. if (pAC->GIni.GIMacsFound > SK_MAX_MACS) {
  1573. RetVal = 1;
  1574. break;
  1575. }
  1576. /* Level 1 successfully passed */
  1577. pAC->GIni.GILevel = SK_INIT_IO;
  1578. break;
  1579. case SK_INIT_RUN:
  1580. /* Initialization Level 2 */
  1581. if (pAC->GIni.GILevel != SK_INIT_IO) {
  1582. #ifndef SK_DIAG
  1583. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E002, SKERR_HWI_E002MSG);
  1584. #endif /* !SK_DIAG */
  1585. RetVal = 4;
  1586. break;
  1587. }
  1588. SkGeInit2(pAC, IoC);
  1589. /* Level 2 successfully passed */
  1590. pAC->GIni.GILevel = SK_INIT_RUN;
  1591. break;
  1592. default:
  1593. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E003, SKERR_HWI_E003MSG);
  1594. RetVal = 3;
  1595. break;
  1596. }
  1597. return(RetVal);
  1598. } /* SkGeInit */
  1599. /******************************************************************************
  1600. *
  1601. * SkGeDeInit() - Deinitialize the adapter
  1602. *
  1603. * Description:
  1604. * All ports of the adapter will be stopped if not already done.
  1605. * Do a software reset and switch off all LEDs.
  1606. *
  1607. * Returns:
  1608. * nothing
  1609. */
  1610. void SkGeDeInit(
  1611. SK_AC *pAC, /* adapter context */
  1612. SK_IOC IoC) /* IO context */
  1613. {
  1614. int i;
  1615. SK_U16 Word;
  1616. #if (!defined(SK_SLIM) && !defined(VCPU))
  1617. /* ensure I2C is ready */
  1618. SkI2cWaitIrq(pAC, IoC);
  1619. #endif
  1620. /* stop all current transfer activity */
  1621. for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
  1622. if (pAC->GIni.GP[i].PState != SK_PRT_STOP &&
  1623. pAC->GIni.GP[i].PState != SK_PRT_RESET) {
  1624. SkGeStopPort(pAC, IoC, i, SK_STOP_ALL, SK_HARD_RST);
  1625. }
  1626. }
  1627. /* Reset all bits in the PCI STATUS register */
  1628. /*
  1629. * Note: PCI Cfg cycles cannot be used, because they are not
  1630. * available on some platforms after 'boot time'.
  1631. */
  1632. SK_IN16(IoC, PCI_C(PCI_STATUS), &Word);
  1633. SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_ON);
  1634. SK_OUT16(IoC, PCI_C(PCI_STATUS), (SK_U16)(Word | PCI_ERRBITS));
  1635. SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
  1636. /* do the reset, all LEDs are switched off now */
  1637. SK_OUT8(IoC, B0_CTST, CS_RST_SET);
  1638. pAC->GIni.GILevel = SK_INIT_DATA;
  1639. } /* SkGeDeInit */
  1640. /******************************************************************************
  1641. *
  1642. * SkGeInitPort() Initialize the specified port.
  1643. *
  1644. * Description:
  1645. * PRxQSize, PXSQSize, and PXAQSize has to be
  1646. * configured for the specified port before calling this function.
  1647. * The descriptor rings has to be initialized too.
  1648. *
  1649. * o (Re)configure queues of the specified port.
  1650. * o configure the MAC of the specified port.
  1651. * o put ASIC and MAC(s) in operational mode.
  1652. * o initialize Rx/Tx and Sync LED
  1653. * o initialize RAM Buffers and MAC FIFOs
  1654. *
  1655. * The port is ready to connect when returning.
  1656. *
  1657. * Note:
  1658. * The MAC's Rx and Tx state machine is still disabled when returning.
  1659. *
  1660. * Returns:
  1661. * 0: success
  1662. * 1: Queue size initialization error. The configured values
  1663. * for PRxQSize, PXSQSize, or PXAQSize are invalid for one
  1664. * or more queues. The specified port was NOT initialized.
  1665. * An error log entry was generated.
  1666. * 2: The port has to be stopped before it can be initialized again.
  1667. */
  1668. int SkGeInitPort(
  1669. SK_AC *pAC, /* adapter context */
  1670. SK_IOC IoC, /* IO context */
  1671. int Port) /* Port to configure */
  1672. {
  1673. SK_GEPORT *pPrt;
  1674. pPrt = &pAC->GIni.GP[Port];
  1675. if (SkGeCheckQSize(pAC, Port) != 0) {
  1676. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E004, SKERR_HWI_E004MSG);
  1677. return(1);
  1678. }
  1679. if (pPrt->PState == SK_PRT_INIT || pPrt->PState == SK_PRT_RUN) {
  1680. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E005, SKERR_HWI_E005MSG);
  1681. return(2);
  1682. }
  1683. /* configuration ok, initialize the Port now */
  1684. #ifdef GENESIS
  1685. if (pAC->GIni.GIGenesis) {
  1686. /* initialize Rx, Tx and Link LED */
  1687. /*
  1688. * If 1000BT Phy needs LED initialization than swap
  1689. * LED and XMAC initialization order
  1690. */
  1691. SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_ENA);
  1692. SkGeXmitLED(pAC, IoC, MR_ADDR(Port, RX_LED_INI), SK_LED_ENA);
  1693. /* The Link LED is initialized by RLMT or Diagnostics itself */
  1694. SkXmInitMac(pAC, IoC, Port);
  1695. }
  1696. #endif /* GENESIS */
  1697. #ifdef YUKON
  1698. if (pAC->GIni.GIYukon) {
  1699. SkGmInitMac(pAC, IoC, Port);
  1700. }
  1701. #endif /* YUKON */
  1702. /* do NOT initialize the Link Sync Counter */
  1703. SkGeInitMacFifo(pAC, IoC, Port);
  1704. SkGeInitRamBufs(pAC, IoC, Port);
  1705. if (pPrt->PXSQSize != 0) {
  1706. /* enable Force Sync bit if synchronous queue available */
  1707. SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL), TXA_ENA_FSYNC);
  1708. }
  1709. SkGeInitBmu(pAC, IoC, Port);
  1710. /* mark port as initialized */
  1711. pPrt->PState = SK_PRT_INIT;
  1712. return(0);
  1713. } /* SkGeInitPort */