drvfbi.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  1. /******************************************************************************
  2. *
  3. * (C)Copyright 1998,1999 SysKonnect,
  4. * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
  5. *
  6. * See the file "skfddi.c" for further information.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * The information in this file is provided "AS IS" without warranty.
  14. *
  15. ******************************************************************************/
  16. /*
  17. * FBI board dependent Driver for SMT and LLC
  18. */
  19. #include "h/types.h"
  20. #include "h/fddi.h"
  21. #include "h/smc.h"
  22. #include "h/supern_2.h"
  23. #include "h/skfbiinc.h"
  24. #ifndef lint
  25. static const char ID_sccs[] = "@(#)drvfbi.c 1.63 99/02/11 (C) SK " ;
  26. #endif
  27. /*
  28. * PCM active state
  29. */
  30. #define PC8_ACTIVE 8
  31. #define LED_Y_ON 0x11 /* Used for ring up/down indication */
  32. #define LED_Y_OFF 0x10
  33. #define MS2BCLK(x) ((x)*12500L)
  34. /*
  35. * valid configuration values are:
  36. */
  37. #ifdef ISA
  38. const int opt_ints[] = {8, 3, 4, 5, 9, 10, 11, 12, 15} ;
  39. const int opt_iops[] = {8,
  40. 0x100, 0x120, 0x180, 0x1a0, 0x220, 0x240, 0x320, 0x340};
  41. const int opt_dmas[] = {4, 3, 5, 6, 7} ;
  42. const int opt_eproms[] = {15, 0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce,
  43. 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc} ;
  44. #endif
  45. #ifdef EISA
  46. const int opt_ints[] = {5, 9, 10, 11} ;
  47. const int opt_dmas[] = {0, 5, 6, 7} ;
  48. const int opt_eproms[] = {0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce,
  49. 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc} ;
  50. #endif
  51. #ifdef MCA
  52. int opt_ints[] = {3, 11, 10, 9} ; /* FM1 */
  53. int opt_eproms[] = {0, 0xc4, 0xc8, 0xcc, 0xd0, 0xd4, 0xd8, 0xdc} ;
  54. #endif /* MCA */
  55. /*
  56. * xPOS_ID:xxxx
  57. * | \ /
  58. * | \/
  59. * | --------------------- the patched POS_ID of the Adapter
  60. * | xxxx = (Vendor ID low byte,
  61. * | Vendor ID high byte,
  62. * | Device ID low byte,
  63. * | Device ID high byte)
  64. * +------------------------------ the patched oem_id must be
  65. * 'S' for SK or 'I' for IBM
  66. * this is a short id for the driver.
  67. */
  68. #ifndef MULT_OEM
  69. #ifndef OEM_CONCEPT
  70. #ifndef MCA
  71. const u_char oem_id[] = "xPOS_ID:xxxx" ;
  72. #else
  73. const u_char oem_id[] = "xPOSID1:xxxx" ; /* FM1 card id. */
  74. #endif
  75. #else /* OEM_CONCEPT */
  76. #ifndef MCA
  77. const u_char oem_id[] = OEM_ID ;
  78. #else
  79. const u_char oem_id[] = OEM_ID1 ; /* FM1 card id. */
  80. #endif /* MCA */
  81. #endif /* OEM_CONCEPT */
  82. #define ID_BYTE0 8
  83. #define OEMID(smc,i) oem_id[ID_BYTE0 + i]
  84. #else /* MULT_OEM */
  85. const struct s_oem_ids oem_ids[] = {
  86. #include "oemids.h"
  87. {0}
  88. };
  89. #define OEMID(smc,i) smc->hw.oem_id->oi_id[i]
  90. #endif /* MULT_OEM */
  91. /* Prototypes of external functions */
  92. #ifdef AIX
  93. extern int AIX_vpdReadByte() ;
  94. #endif
  95. /* Prototypes of local functions. */
  96. void smt_stop_watchdog(struct s_smc *smc);
  97. #ifdef MCA
  98. static int read_card_id() ;
  99. static void DisableSlotAccess() ;
  100. static void EnableSlotAccess() ;
  101. #ifdef AIX
  102. extern int attach_POS_addr() ;
  103. extern int detach_POS_addr() ;
  104. extern u_char read_POS() ;
  105. extern void write_POS() ;
  106. extern int AIX_vpdReadByte() ;
  107. #else
  108. #define read_POS(smc,a1,a2) ((u_char) inp(a1))
  109. #define write_POS(smc,a1,a2,a3) outp((a1),(a3))
  110. #endif
  111. #endif /* MCA */
  112. /*
  113. * FDDI card reset
  114. */
  115. static void card_start(struct s_smc *smc)
  116. {
  117. int i ;
  118. #ifdef PCI
  119. u_char rev_id ;
  120. u_short word;
  121. #endif
  122. smt_stop_watchdog(smc) ;
  123. #ifdef ISA
  124. outpw(CSR_A,0) ; /* reset for all chips */
  125. for (i = 10 ; i ; i--) /* delay for PLC's */
  126. (void)inpw(ISR_A) ;
  127. OUT_82c54_TIMER(3,COUNT(2) | RW_OP(3) | TMODE(2)) ;
  128. /* counter 2, mode 2 */
  129. OUT_82c54_TIMER(2,97) ; /* LSB */
  130. OUT_82c54_TIMER(2,0) ; /* MSB ( 15.6 us ) */
  131. outpw(CSR_A,CS_CRESET) ;
  132. #endif
  133. #ifdef EISA
  134. outpw(CSR_A,0) ; /* reset for all chips */
  135. for (i = 10 ; i ; i--) /* delay for PLC's */
  136. (void)inpw(ISR_A) ;
  137. outpw(CSR_A,CS_CRESET) ;
  138. smc->hw.led = (2<<6) ;
  139. outpw(CSR_A,CS_CRESET | smc->hw.led) ;
  140. #endif
  141. #ifdef MCA
  142. outp(ADDR(CARD_DIS),0) ; /* reset for all chips */
  143. for (i = 10 ; i ; i--) /* delay for PLC's */
  144. (void)inpw(ISR_A) ;
  145. outp(ADDR(CARD_EN),0) ;
  146. /* first I/O after reset must not be a access to FORMAC or PLC */
  147. /*
  148. * bus timeout (MCA)
  149. */
  150. OUT_82c54_TIMER(3,COUNT(2) | RW_OP(3) | TMODE(3)) ;
  151. /* counter 2, mode 3 */
  152. OUT_82c54_TIMER(2,(2*24)) ; /* 3.9 us * 2 square wave */
  153. OUT_82c54_TIMER(2,0) ; /* MSB */
  154. /* POS 102 indicated an activ Check Line or Buss Error monitoring */
  155. if (inpw(CSA_A) & (POS_EN_CHKINT | POS_EN_BUS_ERR)) {
  156. outp(ADDR(IRQ_CHCK_EN),0) ;
  157. }
  158. if (!((i = inpw(CSR_A)) & CS_SAS)) {
  159. if (!(i & CS_BYSTAT)) {
  160. outp(ADDR(BYPASS(STAT_INS)),0) ;/* insert station */
  161. }
  162. }
  163. outpw(LEDR_A,LED_1) ; /* yellow */
  164. #endif /* MCA */
  165. #ifdef PCI
  166. /*
  167. * make sure no transfer activity is pending
  168. */
  169. outpw(FM_A(FM_MDREG1),FM_MINIT) ;
  170. outp(ADDR(B0_CTRL), CTRL_HPI_SET) ;
  171. hwt_wait_time(smc,hwt_quick_read(smc),MS2BCLK(10)) ;
  172. /*
  173. * now reset everything
  174. */
  175. outp(ADDR(B0_CTRL),CTRL_RST_SET) ; /* reset for all chips */
  176. i = (int) inp(ADDR(B0_CTRL)) ; /* do dummy read */
  177. SK_UNUSED(i) ; /* Make LINT happy. */
  178. outp(ADDR(B0_CTRL), CTRL_RST_CLR) ;
  179. /*
  180. * Reset all bits in the PCI STATUS register
  181. */
  182. outp(ADDR(B0_TST_CTRL), TST_CFG_WRITE_ON) ; /* enable for writes */
  183. word = inpw(PCI_C(PCI_STATUS)) ;
  184. outpw(PCI_C(PCI_STATUS), word | PCI_ERRBITS) ;
  185. outp(ADDR(B0_TST_CTRL), TST_CFG_WRITE_OFF) ; /* disable writes */
  186. /*
  187. * Release the reset of all the State machines
  188. * Release Master_Reset
  189. * Release HPI_SM_Reset
  190. */
  191. outp(ADDR(B0_CTRL), CTRL_MRST_CLR|CTRL_HPI_CLR) ;
  192. /*
  193. * determine the adapter type
  194. * Note: Do it here, because some drivers may call card_start() once
  195. * at very first before any other initialization functions is
  196. * executed.
  197. */
  198. rev_id = inp(PCI_C(PCI_REV_ID)) ;
  199. if ((rev_id & 0xf0) == SK_ML_ID_1 || (rev_id & 0xf0) == SK_ML_ID_2) {
  200. smc->hw.hw_is_64bit = TRUE ;
  201. } else {
  202. smc->hw.hw_is_64bit = FALSE ;
  203. }
  204. /*
  205. * Watermark initialization
  206. */
  207. if (!smc->hw.hw_is_64bit) {
  208. outpd(ADDR(B4_R1_F), RX_WATERMARK) ;
  209. outpd(ADDR(B5_XA_F), TX_WATERMARK) ;
  210. outpd(ADDR(B5_XS_F), TX_WATERMARK) ;
  211. }
  212. outp(ADDR(B0_CTRL),CTRL_RST_CLR) ; /* clear the reset chips */
  213. outp(ADDR(B0_LED),LED_GA_OFF|LED_MY_ON|LED_GB_OFF) ; /* ye LED on */
  214. /* init the timer value for the watch dog 2,5 minutes */
  215. outpd(ADDR(B2_WDOG_INI),0x6FC23AC0) ;
  216. /* initialize the ISR mask */
  217. smc->hw.is_imask = ISR_MASK ;
  218. smc->hw.hw_state = STOPPED ;
  219. #endif
  220. GET_PAGE(0) ; /* necessary for BOOT */
  221. }
  222. void card_stop(struct s_smc *smc)
  223. {
  224. smt_stop_watchdog(smc) ;
  225. smc->hw.mac_ring_is_up = 0 ; /* ring down */
  226. #ifdef ISA
  227. outpw(CSR_A,0) ; /* reset for all chips */
  228. #endif
  229. #ifdef EISA
  230. outpw(CSR_A,0) ; /* reset for all chips */
  231. #endif
  232. #ifdef MCA
  233. outp(ADDR(CARD_DIS),0) ; /* reset for all chips */
  234. #endif
  235. #ifdef PCI
  236. /*
  237. * make sure no transfer activity is pending
  238. */
  239. outpw(FM_A(FM_MDREG1),FM_MINIT) ;
  240. outp(ADDR(B0_CTRL), CTRL_HPI_SET) ;
  241. hwt_wait_time(smc,hwt_quick_read(smc),MS2BCLK(10)) ;
  242. /*
  243. * now reset everything
  244. */
  245. outp(ADDR(B0_CTRL),CTRL_RST_SET) ; /* reset for all chips */
  246. outp(ADDR(B0_CTRL),CTRL_RST_CLR) ; /* reset for all chips */
  247. outp(ADDR(B0_LED),LED_GA_OFF|LED_MY_OFF|LED_GB_OFF) ; /* all LEDs off */
  248. smc->hw.hw_state = STOPPED ;
  249. #endif
  250. }
  251. /*--------------------------- ISR handling ----------------------------------*/
  252. void mac1_irq(struct s_smc *smc, u_short stu, u_short stl)
  253. {
  254. int restart_tx = 0 ;
  255. again:
  256. #ifndef PCI
  257. #ifndef ISA
  258. /*
  259. * FORMAC+ bug modified the queue pointer if many read/write accesses happens!?
  260. */
  261. if (stl & (FM_SPCEPDS | /* parit/coding err. syn.q.*/
  262. FM_SPCEPDA0 | /* parit/coding err. a.q.0 */
  263. FM_SPCEPDA1 | /* parit/coding err. a.q.1 */
  264. FM_SPCEPDA2)) { /* parit/coding err. a.q.2 */
  265. SMT_PANIC(smc,SMT_E0132, SMT_E0132_MSG) ;
  266. }
  267. if (stl & (FM_STBURS | /* tx buffer underrun syn.q.*/
  268. FM_STBURA0 | /* tx buffer underrun a.q.0 */
  269. FM_STBURA1 | /* tx buffer underrun a.q.1 */
  270. FM_STBURA2)) { /* tx buffer underrun a.q.2 */
  271. SMT_PANIC(smc,SMT_E0133, SMT_E0133_MSG) ;
  272. }
  273. #endif
  274. if ( (stu & (FM_SXMTABT | /* transmit abort */
  275. #ifdef SYNC
  276. FM_STXABRS | /* syn. tx abort */
  277. #endif /* SYNC */
  278. FM_STXABRA0)) || /* asyn. tx abort */
  279. (stl & (FM_SQLCKS | /* lock for syn. q. */
  280. FM_SQLCKA0)) ) { /* lock for asyn. q. */
  281. formac_tx_restart(smc) ; /* init tx */
  282. restart_tx = 1 ;
  283. stu = inpw(FM_A(FM_ST1U)) ;
  284. stl = inpw(FM_A(FM_ST1L)) ;
  285. stu &= ~ (FM_STECFRMA0 | FM_STEFRMA0 | FM_STEFRMS) ;
  286. if (stu || stl)
  287. goto again ;
  288. }
  289. #ifndef SYNC
  290. if (stu & (FM_STECFRMA0 | /* end of chain asyn tx */
  291. FM_STEFRMA0)) { /* end of frame asyn tx */
  292. /* free tx_queue */
  293. smc->hw.n_a_send = 0 ;
  294. if (++smc->hw.fp.tx_free < smc->hw.fp.tx_max) {
  295. start_next_send(smc);
  296. }
  297. restart_tx = 1 ;
  298. }
  299. #else /* SYNC */
  300. if (stu & (FM_STEFRMA0 | /* end of asyn tx */
  301. FM_STEFRMS)) { /* end of sync tx */
  302. restart_tx = 1 ;
  303. }
  304. #endif /* SYNC */
  305. if (restart_tx)
  306. llc_restart_tx(smc) ;
  307. }
  308. #else /* PCI */
  309. /*
  310. * parity error: note encoding error is not possible in tag mode
  311. */
  312. if (stl & (FM_SPCEPDS | /* parity err. syn.q.*/
  313. FM_SPCEPDA0 | /* parity err. a.q.0 */
  314. FM_SPCEPDA1)) { /* parity err. a.q.1 */
  315. SMT_PANIC(smc,SMT_E0134, SMT_E0134_MSG) ;
  316. }
  317. /*
  318. * buffer underrun: can only occur if a tx threshold is specified
  319. */
  320. if (stl & (FM_STBURS | /* tx buffer underrun syn.q.*/
  321. FM_STBURA0 | /* tx buffer underrun a.q.0 */
  322. FM_STBURA1)) { /* tx buffer underrun a.q.2 */
  323. SMT_PANIC(smc,SMT_E0133, SMT_E0133_MSG) ;
  324. }
  325. if ( (stu & (FM_SXMTABT | /* transmit abort */
  326. FM_STXABRS | /* syn. tx abort */
  327. FM_STXABRA0)) || /* asyn. tx abort */
  328. (stl & (FM_SQLCKS | /* lock for syn. q. */
  329. FM_SQLCKA0)) ) { /* lock for asyn. q. */
  330. formac_tx_restart(smc) ; /* init tx */
  331. restart_tx = 1 ;
  332. stu = inpw(FM_A(FM_ST1U)) ;
  333. stl = inpw(FM_A(FM_ST1L)) ;
  334. stu &= ~ (FM_STECFRMA0 | FM_STEFRMA0 | FM_STEFRMS) ;
  335. if (stu || stl)
  336. goto again ;
  337. }
  338. if (stu & (FM_STEFRMA0 | /* end of asyn tx */
  339. FM_STEFRMS)) { /* end of sync tx */
  340. restart_tx = 1 ;
  341. }
  342. if (restart_tx)
  343. llc_restart_tx(smc) ;
  344. }
  345. #endif /* PCI */
  346. /*
  347. * interrupt source= plc1
  348. * this function is called in nwfbisr.asm
  349. */
  350. void plc1_irq(struct s_smc *smc)
  351. {
  352. u_short st = inpw(PLC(PB,PL_INTR_EVENT)) ;
  353. #if (defined(ISA) || defined(EISA))
  354. /* reset PLC Int. bits */
  355. outpw(PLC1_I,inpw(PLC1_I)) ;
  356. #endif
  357. plc_irq(smc,PB,st) ;
  358. }
  359. /*
  360. * interrupt source= plc2
  361. * this function is called in nwfbisr.asm
  362. */
  363. void plc2_irq(struct s_smc *smc)
  364. {
  365. u_short st = inpw(PLC(PA,PL_INTR_EVENT)) ;
  366. #if (defined(ISA) || defined(EISA))
  367. /* reset PLC Int. bits */
  368. outpw(PLC2_I,inpw(PLC2_I)) ;
  369. #endif
  370. plc_irq(smc,PA,st) ;
  371. }
  372. /*
  373. * interrupt source= timer
  374. */
  375. void timer_irq(struct s_smc *smc)
  376. {
  377. hwt_restart(smc);
  378. smc->hw.t_stop = smc->hw.t_start;
  379. smt_timer_done(smc) ;
  380. }
  381. /*
  382. * return S-port (PA or PB)
  383. */
  384. int pcm_get_s_port(struct s_smc *smc)
  385. {
  386. SK_UNUSED(smc) ;
  387. return(PS) ;
  388. }
  389. /*
  390. * Station Label = "FDDI-XYZ" where
  391. *
  392. * X = connector type
  393. * Y = PMD type
  394. * Z = port type
  395. */
  396. #define STATION_LABEL_CONNECTOR_OFFSET 5
  397. #define STATION_LABEL_PMD_OFFSET 6
  398. #define STATION_LABEL_PORT_OFFSET 7
  399. void read_address(struct s_smc *smc, u_char *mac_addr)
  400. {
  401. char ConnectorType ;
  402. char PmdType ;
  403. int i ;
  404. extern const u_char canonical[256] ;
  405. #if (defined(ISA) || defined(MCA))
  406. for (i = 0; i < 4 ;i++) { /* read mac address from board */
  407. smc->hw.fddi_phys_addr.a[i] =
  408. canonical[(inpw(PR_A(i+SA_MAC))&0xff)] ;
  409. }
  410. for (i = 4; i < 6; i++) {
  411. smc->hw.fddi_phys_addr.a[i] =
  412. canonical[(inpw(PR_A(i+SA_MAC+PRA_OFF))&0xff)] ;
  413. }
  414. #endif
  415. #ifdef EISA
  416. /*
  417. * Note: We get trouble on an Alpha machine if we make a inpw()
  418. * instead of inp()
  419. */
  420. for (i = 0; i < 4 ;i++) { /* read mac address from board */
  421. smc->hw.fddi_phys_addr.a[i] =
  422. canonical[inp(PR_A(i+SA_MAC))] ;
  423. }
  424. for (i = 4; i < 6; i++) {
  425. smc->hw.fddi_phys_addr.a[i] =
  426. canonical[inp(PR_A(i+SA_MAC+PRA_OFF))] ;
  427. }
  428. #endif
  429. #ifdef PCI
  430. for (i = 0; i < 6; i++) { /* read mac address from board */
  431. smc->hw.fddi_phys_addr.a[i] =
  432. canonical[inp(ADDR(B2_MAC_0+i))] ;
  433. }
  434. #endif
  435. #ifndef PCI
  436. ConnectorType = inpw(PR_A(SA_PMD_TYPE)) & 0xff ;
  437. PmdType = inpw(PR_A(SA_PMD_TYPE+1)) & 0xff ;
  438. #else
  439. ConnectorType = inp(ADDR(B2_CONN_TYP)) ;
  440. PmdType = inp(ADDR(B2_PMD_TYP)) ;
  441. #endif
  442. smc->y[PA].pmd_type[PMD_SK_CONN] =
  443. smc->y[PB].pmd_type[PMD_SK_CONN] = ConnectorType ;
  444. smc->y[PA].pmd_type[PMD_SK_PMD ] =
  445. smc->y[PB].pmd_type[PMD_SK_PMD ] = PmdType ;
  446. if (mac_addr) {
  447. for (i = 0; i < 6 ;i++) {
  448. smc->hw.fddi_canon_addr.a[i] = mac_addr[i] ;
  449. smc->hw.fddi_home_addr.a[i] = canonical[mac_addr[i]] ;
  450. }
  451. return ;
  452. }
  453. smc->hw.fddi_home_addr = smc->hw.fddi_phys_addr ;
  454. for (i = 0; i < 6 ;i++) {
  455. smc->hw.fddi_canon_addr.a[i] =
  456. canonical[smc->hw.fddi_phys_addr.a[i]] ;
  457. }
  458. }
  459. /*
  460. * FDDI card soft reset
  461. */
  462. void init_board(struct s_smc *smc, u_char *mac_addr)
  463. {
  464. card_start(smc) ;
  465. read_address(smc,mac_addr) ;
  466. #ifndef PCI
  467. if (inpw(CSR_A) & CS_SAS)
  468. #else
  469. if (!(inp(ADDR(B0_DAS)) & DAS_AVAIL))
  470. #endif
  471. smc->s.sas = SMT_SAS ; /* Single att. station */
  472. else
  473. smc->s.sas = SMT_DAS ; /* Dual att. station */
  474. #ifndef PCI
  475. if (inpw(CSR_A) & CS_BYSTAT)
  476. #else
  477. if (!(inp(ADDR(B0_DAS)) & DAS_BYP_ST))
  478. #endif
  479. smc->mib.fddiSMTBypassPresent = 0 ;
  480. /* without opt. bypass */
  481. else
  482. smc->mib.fddiSMTBypassPresent = 1 ;
  483. /* with opt. bypass */
  484. }
  485. /*
  486. * insert or deinsert optical bypass (called by ECM)
  487. */
  488. void sm_pm_bypass_req(struct s_smc *smc, int mode)
  489. {
  490. #if (defined(ISA) || defined(EISA))
  491. int csra_v ;
  492. #endif
  493. DB_ECMN(1,"ECM : sm_pm_bypass_req(%s)\n",(mode == BP_INSERT) ?
  494. "BP_INSERT" : "BP_DEINSERT",0) ;
  495. if (smc->s.sas != SMT_DAS)
  496. return ;
  497. #if (defined(ISA) || defined(EISA))
  498. csra_v = inpw(CSR_A) & ~CS_BYPASS ;
  499. #ifdef EISA
  500. csra_v |= smc->hw.led ;
  501. #endif
  502. switch(mode) {
  503. case BP_INSERT :
  504. outpw(CSR_A,csra_v | CS_BYPASS) ;
  505. break ;
  506. case BP_DEINSERT :
  507. outpw(CSR_A,csra_v) ;
  508. break ;
  509. }
  510. #endif /* ISA / EISA */
  511. #ifdef MCA
  512. switch(mode) {
  513. case BP_INSERT :
  514. outp(ADDR(BYPASS(STAT_INS)),0) ;/* insert station */
  515. break ;
  516. case BP_DEINSERT :
  517. outp(ADDR(BYPASS(STAT_BYP)),0) ; /* bypass station */
  518. break ;
  519. }
  520. #endif
  521. #ifdef PCI
  522. switch(mode) {
  523. case BP_INSERT :
  524. outp(ADDR(B0_DAS),DAS_BYP_INS) ; /* insert station */
  525. break ;
  526. case BP_DEINSERT :
  527. outp(ADDR(B0_DAS),DAS_BYP_RMV) ; /* bypass station */
  528. break ;
  529. }
  530. #endif
  531. }
  532. /*
  533. * check if bypass connected
  534. */
  535. int sm_pm_bypass_present(struct s_smc *smc)
  536. {
  537. #ifndef PCI
  538. return( (inpw(CSR_A) & CS_BYSTAT) ? FALSE : TRUE ) ;
  539. #else
  540. return( (inp(ADDR(B0_DAS)) & DAS_BYP_ST) ? TRUE: FALSE) ;
  541. #endif
  542. }
  543. void plc_clear_irq(struct s_smc *smc, int p)
  544. {
  545. SK_UNUSED(p) ;
  546. #if (defined(ISA) || defined(EISA))
  547. switch (p) {
  548. case PA :
  549. /* reset PLC Int. bits */
  550. outpw(PLC2_I,inpw(PLC2_I)) ;
  551. break ;
  552. case PB :
  553. /* reset PLC Int. bits */
  554. outpw(PLC1_I,inpw(PLC1_I)) ;
  555. break ;
  556. }
  557. #else
  558. SK_UNUSED(smc) ;
  559. #endif
  560. }
  561. /*
  562. * led_indication called by rmt_indication() and
  563. * pcm_state_change()
  564. *
  565. * Input:
  566. * smc: SMT context
  567. * led_event:
  568. * 0 Only switch green LEDs according to their respective PCM state
  569. * LED_Y_OFF just switch yellow LED off
  570. * LED_Y_ON just switch yello LED on
  571. */
  572. void led_indication(struct s_smc *smc, int led_event)
  573. {
  574. /* use smc->hw.mac_ring_is_up == TRUE
  575. * as indication for Ring Operational
  576. */
  577. u_short led_state ;
  578. struct s_phy *phy ;
  579. struct fddi_mib_p *mib_a ;
  580. struct fddi_mib_p *mib_b ;
  581. phy = &smc->y[PA] ;
  582. mib_a = phy->mib ;
  583. phy = &smc->y[PB] ;
  584. mib_b = phy->mib ;
  585. #ifdef EISA
  586. /* Ring up = yellow led OFF*/
  587. if (led_event == LED_Y_ON) {
  588. smc->hw.led |= CS_LED_1 ;
  589. }
  590. else if (led_event == LED_Y_OFF) {
  591. smc->hw.led &= ~CS_LED_1 ;
  592. }
  593. else {
  594. /* Link at Port A or B = green led ON */
  595. if (mib_a->fddiPORTPCMState == PC8_ACTIVE ||
  596. mib_b->fddiPORTPCMState == PC8_ACTIVE) {
  597. smc->hw.led |= CS_LED_0 ;
  598. }
  599. else {
  600. smc->hw.led &= ~CS_LED_0 ;
  601. }
  602. }
  603. #endif
  604. #ifdef MCA
  605. led_state = inpw(LEDR_A) ;
  606. /* Ring up = yellow led OFF*/
  607. if (led_event == LED_Y_ON) {
  608. led_state |= LED_1 ;
  609. }
  610. else if (led_event == LED_Y_OFF) {
  611. led_state &= ~LED_1 ;
  612. }
  613. else {
  614. led_state &= ~(LED_2|LED_0) ;
  615. /* Link at Port A = green led A ON */
  616. if (mib_a->fddiPORTPCMState == PC8_ACTIVE) {
  617. led_state |= LED_2 ;
  618. }
  619. /* Link at Port B/S = green led B ON */
  620. if (mib_b->fddiPORTPCMState == PC8_ACTIVE) {
  621. led_state |= LED_0 ;
  622. }
  623. }
  624. outpw(LEDR_A, led_state) ;
  625. #endif /* MCA */
  626. #ifdef PCI
  627. led_state = 0 ;
  628. /* Ring up = yellow led OFF*/
  629. if (led_event == LED_Y_ON) {
  630. led_state |= LED_MY_ON ;
  631. }
  632. else if (led_event == LED_Y_OFF) {
  633. led_state |= LED_MY_OFF ;
  634. }
  635. else { /* PCM state changed */
  636. /* Link at Port A/S = green led A ON */
  637. if (mib_a->fddiPORTPCMState == PC8_ACTIVE) {
  638. led_state |= LED_GA_ON ;
  639. }
  640. else {
  641. led_state |= LED_GA_OFF ;
  642. }
  643. /* Link at Port B = green led B ON */
  644. if (mib_b->fddiPORTPCMState == PC8_ACTIVE) {
  645. led_state |= LED_GB_ON ;
  646. }
  647. else {
  648. led_state |= LED_GB_OFF ;
  649. }
  650. }
  651. outp(ADDR(B0_LED), led_state) ;
  652. #endif /* PCI */
  653. }
  654. void pcm_state_change(struct s_smc *smc, int plc, int p_state)
  655. {
  656. /*
  657. * the current implementation of pcm_state_change() in the driver
  658. * parts must be renamed to drv_pcm_state_change() which will be called
  659. * now after led_indication.
  660. */
  661. DRV_PCM_STATE_CHANGE(smc,plc,p_state) ;
  662. led_indication(smc,0) ;
  663. }
  664. void rmt_indication(struct s_smc *smc, int i)
  665. {
  666. /* Call a driver special function if defined */
  667. DRV_RMT_INDICATION(smc,i) ;
  668. led_indication(smc, i ? LED_Y_OFF : LED_Y_ON) ;
  669. }
  670. /*
  671. * llc_recover_tx called by init_tx (fplus.c)
  672. */
  673. void llc_recover_tx(struct s_smc *smc)
  674. {
  675. #ifdef LOAD_GEN
  676. extern int load_gen_flag ;
  677. load_gen_flag = 0 ;
  678. #endif
  679. #ifndef SYNC
  680. smc->hw.n_a_send= 0 ;
  681. #else
  682. SK_UNUSED(smc) ;
  683. #endif
  684. }
  685. /*--------------------------- DMA init ----------------------------*/
  686. #ifdef ISA
  687. /*
  688. * init DMA
  689. */
  690. void init_dma(struct s_smc *smc, int dma)
  691. {
  692. SK_UNUSED(smc) ;
  693. /*
  694. * set cascade mode,
  695. * clear mask bit (enable DMA cannal)
  696. */
  697. if (dma > 3) {
  698. outp(0xd6,(dma & 0x03) | 0xc0) ;
  699. outp(0xd4, dma & 0x03) ;
  700. }
  701. else {
  702. outp(0x0b,(dma & 0x03) | 0xc0) ;
  703. outp(0x0a,dma & 0x03) ;
  704. }
  705. }
  706. /*
  707. * disable DMA
  708. */
  709. void dis_dma(struct s_smc *smc, int dma)
  710. {
  711. SK_UNUSED(smc) ;
  712. /*
  713. * set mask bit (disable DMA cannal)
  714. */
  715. if (dma > 3) {
  716. outp(0xd4,(dma & 0x03) | 0x04) ;
  717. }
  718. else {
  719. outp(0x0a,(dma & 0x03) | 0x04) ;
  720. }
  721. }
  722. #endif /* ISA */
  723. #ifdef EISA
  724. /*arrays with io addresses of dma controller length and address registers*/
  725. static const int cntr[8] = { 0x001,0x003,0x005,0x007,0,0x0c6,0x0ca,0x0ce } ;
  726. static const int base[8] = { 0x000,0x002,0x004,0x006,0,0x0c4,0x0c8,0x0cc } ;
  727. static const int page[8] = { 0x087,0x083,0x081,0x082,0,0x08b,0x089,0x08a } ;
  728. void init_dma(struct s_smc *smc, int dma)
  729. {
  730. /*
  731. * extended mode register
  732. * 32 bit IO
  733. * type c
  734. * TC output
  735. * disable stop
  736. */
  737. /* mode read (write) demand */
  738. smc->hw.dma_rmode = (dma & 3) | 0x08 | 0x0 ;
  739. smc->hw.dma_wmode = (dma & 3) | 0x04 | 0x0 ;
  740. /* 32 bit IO's, burst DMA mode (type "C") */
  741. smc->hw.dma_emode = (dma & 3) | 0x08 | 0x30 ;
  742. outp((dma < 4) ? 0x40b : 0x4d6,smc->hw.dma_emode) ;
  743. /* disable chaining */
  744. outp((dma < 4) ? 0x40a : 0x4d4,(dma&3)) ;
  745. /*load dma controller addresses for fast access during set dma*/
  746. smc->hw.dma_base_word_count = cntr[smc->hw.dma];
  747. smc->hw.dma_base_address = base[smc->hw.dma];
  748. smc->hw.dma_base_address_page = page[smc->hw.dma];
  749. }
  750. void dis_dma(struct s_smc *smc, int dma)
  751. {
  752. SK_UNUSED(smc) ;
  753. outp((dma < 4) ? 0x0a : 0xd4,(dma&3)|4) ;/* mask bit */
  754. }
  755. #endif /* EISA */
  756. #ifdef MCA
  757. void init_dma(struct s_smc *smc, int dma)
  758. {
  759. SK_UNUSED(smc) ;
  760. SK_UNUSED(dma) ;
  761. }
  762. void dis_dma(struct s_smc *smc, int dma)
  763. {
  764. SK_UNUSED(smc) ;
  765. SK_UNUSED(dma) ;
  766. }
  767. #endif
  768. #ifdef PCI
  769. void init_dma(struct s_smc *smc, int dma)
  770. {
  771. SK_UNUSED(smc) ;
  772. SK_UNUSED(dma) ;
  773. }
  774. void dis_dma(struct s_smc *smc, int dma)
  775. {
  776. SK_UNUSED(smc) ;
  777. SK_UNUSED(dma) ;
  778. }
  779. #endif
  780. #ifdef MULT_OEM
  781. static int is_equal_num(char comp1[], char comp2[], int num)
  782. {
  783. int i ;
  784. for (i = 0 ; i < num ; i++) {
  785. if (comp1[i] != comp2[i])
  786. return (0) ;
  787. }
  788. return (1) ;
  789. } /* is_equal_num */
  790. /*
  791. * set the OEM ID defaults, and test the contents of the OEM data base
  792. * The default OEM is the first ACTIVE entry in the OEM data base
  793. *
  794. * returns: 0 success
  795. * 1 error in data base
  796. * 2 data base empty
  797. * 3 no active entry
  798. */
  799. int set_oi_id_def(struct s_smc *smc)
  800. {
  801. int sel_id ;
  802. int i ;
  803. int act_entries ;
  804. i = 0 ;
  805. sel_id = -1 ;
  806. act_entries = FALSE ;
  807. smc->hw.oem_id = 0 ;
  808. smc->hw.oem_min_status = OI_STAT_ACTIVE ;
  809. /* check OEM data base */
  810. while (oem_ids[i].oi_status) {
  811. switch (oem_ids[i].oi_status) {
  812. case OI_STAT_ACTIVE:
  813. act_entries = TRUE ; /* we have active IDs */
  814. if (sel_id == -1)
  815. sel_id = i ; /* save the first active ID */
  816. case OI_STAT_VALID:
  817. case OI_STAT_PRESENT:
  818. i++ ;
  819. break ; /* entry ok */
  820. default:
  821. return (1) ; /* invalid oi_status */
  822. }
  823. }
  824. if (i == 0)
  825. return (2) ;
  826. if (!act_entries)
  827. return (3) ;
  828. /* ok, we have a valid OEM data base with an active entry */
  829. smc->hw.oem_id = (struct s_oem_ids *) &oem_ids[sel_id] ;
  830. return (0) ;
  831. }
  832. #endif /* MULT_OEM */
  833. #ifdef MCA
  834. /************************
  835. *
  836. * BEGIN_MANUAL_ENTRY()
  837. *
  838. * exist_board
  839. *
  840. * Check if an MCA board is present in the specified slot.
  841. *
  842. * int exist_board(
  843. * struct s_smc *smc,
  844. * int slot) ;
  845. * In
  846. * smc - A pointer to the SMT Context struct.
  847. *
  848. * slot - The number of the slot to inspect.
  849. * Out
  850. * 0 = No adapter present.
  851. * 1 = Found FM1 adapter.
  852. *
  853. * Pseudo
  854. * Read MCA ID
  855. * for all valid OEM_IDs
  856. * compare with ID read
  857. * if equal, return 1
  858. * return(0
  859. *
  860. * Note
  861. * The smc pointer must be valid now.
  862. *
  863. * END_MANUAL_ENTRY()
  864. *
  865. ************************/
  866. #define LONG_CARD_ID(lo, hi) ((((hi) & 0xff) << 8) | ((lo) & 0xff))
  867. int exist_board(struct s_smc *smc, int slot)
  868. {
  869. #ifdef MULT_OEM
  870. SK_LOC_DECL(u_char,id[2]) ;
  871. int idi ;
  872. #endif /* MULT_OEM */
  873. /* No longer valid. */
  874. if (smc == NULL)
  875. return(0) ;
  876. #ifndef MULT_OEM
  877. if (read_card_id(smc, slot)
  878. == LONG_CARD_ID(OEMID(smc,0), OEMID(smc,1)))
  879. return (1) ; /* Found FM adapter. */
  880. #else /* MULT_OEM */
  881. idi = read_card_id(smc, slot) ;
  882. id[0] = idi & 0xff ;
  883. id[1] = idi >> 8 ;
  884. smc->hw.oem_id = (struct s_oem_ids *) &oem_ids[0] ;
  885. for (; smc->hw.oem_id->oi_status != OI_STAT_LAST; smc->hw.oem_id++) {
  886. if (smc->hw.oem_id->oi_status < smc->hw.oem_min_status)
  887. continue ;
  888. if (is_equal_num(&id[0],&OEMID(smc,0),2))
  889. return (1) ;
  890. }
  891. #endif /* MULT_OEM */
  892. return (0) ; /* No adapter found. */
  893. }
  894. /************************
  895. *
  896. * read_card_id
  897. *
  898. * Read the MCA card id from the specified slot.
  899. * In
  900. * smc - A pointer to the SMT Context struct.
  901. * CAVEAT: This pointer may be NULL and *must not* be used within this
  902. * function. It's only purpose is for drivers that need some information
  903. * for the inp() and outp() macros.
  904. *
  905. * slot - The number of the slot for which the card id is returned.
  906. * Out
  907. * Returns the card id read from the specified slot. If an illegal slot
  908. * number is specified, the function returns zero.
  909. *
  910. ************************/
  911. static int read_card_id(struct s_smc *smc, int slot)
  912. /* struct s_smc *smc ; Do not use. */
  913. {
  914. int card_id ;
  915. SK_UNUSED(smc) ; /* Make LINT happy. */
  916. if ((slot < 1) || (slot > 15)) /* max 16 slots, 0 = motherboard */
  917. return (0) ; /* Illegal slot number specified. */
  918. EnableSlotAccess(smc, slot) ;
  919. card_id = ((read_POS(smc,POS_ID_HIGH,slot - 1) & 0xff) << 8) |
  920. (read_POS(smc,POS_ID_LOW,slot - 1) & 0xff) ;
  921. DisableSlotAccess(smc) ;
  922. return (card_id) ;
  923. }
  924. /************************
  925. *
  926. * BEGIN_MANUAL_ENTRY()
  927. *
  928. * get_board_para
  929. *
  930. * Get adapter configuration information. Fill all board specific
  931. * parameters within the 'smc' structure.
  932. *
  933. * int get_board_para(
  934. * struct s_smc *smc,
  935. * int slot) ;
  936. * In
  937. * smc - A pointer to the SMT Context struct, to which this function will
  938. * write some adapter configuration data.
  939. *
  940. * slot - The number of the slot, in which the adapter is installed.
  941. * Out
  942. * 0 = No adapter present.
  943. * 1 = Ok.
  944. * 2 = Adapter present, but card enable bit not set.
  945. *
  946. * END_MANUAL_ENTRY()
  947. *
  948. ************************/
  949. int get_board_para(struct s_smc *smc, int slot)
  950. {
  951. int val ;
  952. int i ;
  953. /* Check if adapter present & get type of adapter. */
  954. switch (exist_board(smc, slot)) {
  955. case 0: /* Adapter not present. */
  956. return (0) ;
  957. case 1: /* FM Rev. 1 */
  958. smc->hw.rev = FM1_REV ;
  959. smc->hw.VFullRead = 0x0a ;
  960. smc->hw.VFullWrite = 0x05 ;
  961. smc->hw.DmaWriteExtraBytes = 8 ; /* 2 extra words. */
  962. break ;
  963. }
  964. smc->hw.slot = slot ;
  965. EnableSlotAccess(smc, slot) ;
  966. if (!(read_POS(smc,POS_102, slot - 1) & POS_CARD_EN)) {
  967. DisableSlotAccess(smc) ;
  968. return (2) ; /* Card enable bit not set. */
  969. }
  970. val = read_POS(smc,POS_104, slot - 1) ; /* I/O, IRQ */
  971. #ifndef MEM_MAPPED_IO /* is defined by the operating system */
  972. i = val & POS_IOSEL ; /* I/O base addr. (0x0200 .. 0xfe00) */
  973. smc->hw.iop = (i + 1) * 0x0400 - 0x200 ;
  974. #endif
  975. i = ((val & POS_IRQSEL) >> 6) & 0x03 ; /* IRQ <0, 1> */
  976. smc->hw.irq = opt_ints[i] ;
  977. /* FPROM base addr. */
  978. i = ((read_POS(smc,POS_103, slot - 1) & POS_MSEL) >> 4) & 0x07 ;
  979. smc->hw.eprom = opt_eproms[i] ;
  980. DisableSlotAccess(smc) ;
  981. /* before this, the smc->hw.iop must be set !!! */
  982. smc->hw.slot_32 = inpw(CSF_A) & SLOT_32 ;
  983. return (1) ;
  984. }
  985. /* Enable access to specified MCA slot. */
  986. static void EnableSlotAccess(struct s_smc *smc, int slot)
  987. {
  988. SK_UNUSED(slot) ;
  989. #ifndef AIX
  990. SK_UNUSED(smc) ;
  991. /* System mode. */
  992. outp(POS_SYS_SETUP, POS_SYSTEM) ;
  993. /* Select slot. */
  994. outp(POS_CHANNEL_POS, POS_CHANNEL_BIT | (slot-1)) ;
  995. #else
  996. attach_POS_addr (smc) ;
  997. #endif
  998. }
  999. /* Disable access to MCA slot formerly enabled via EnableSlotAccess(). */
  1000. static void DisableSlotAccess(struct s_smc *smc)
  1001. {
  1002. #ifndef AIX
  1003. SK_UNUSED(smc) ;
  1004. outp(POS_CHANNEL_POS, 0) ;
  1005. #else
  1006. detach_POS_addr (smc) ;
  1007. #endif
  1008. }
  1009. #endif /* MCA */
  1010. #ifdef EISA
  1011. #ifndef MEM_MAPPED_IO
  1012. #define SADDR(slot) (((slot)<<12)&0xf000)
  1013. #else /* MEM_MAPPED_IO */
  1014. #define SADDR(slot) (smc->hw.iop)
  1015. #endif /* MEM_MAPPED_IO */
  1016. /************************
  1017. *
  1018. * BEGIN_MANUAL_ENTRY()
  1019. *
  1020. * exist_board
  1021. *
  1022. * Check if an EISA board is present in the specified slot.
  1023. *
  1024. * int exist_board(
  1025. * struct s_smc *smc,
  1026. * int slot) ;
  1027. * In
  1028. * smc - A pointer to the SMT Context struct.
  1029. *
  1030. * slot - The number of the slot to inspect.
  1031. * Out
  1032. * 0 = No adapter present.
  1033. * 1 = Found adapter.
  1034. *
  1035. * Pseudo
  1036. * Read EISA ID
  1037. * for all valid OEM_IDs
  1038. * compare with ID read
  1039. * if equal, return 1
  1040. * return(0
  1041. *
  1042. * Note
  1043. * The smc pointer must be valid now.
  1044. *
  1045. ************************/
  1046. int exist_board(struct s_smc *smc, int slot)
  1047. {
  1048. int i ;
  1049. #ifdef MULT_OEM
  1050. SK_LOC_DECL(u_char,id[4]) ;
  1051. #endif /* MULT_OEM */
  1052. /* No longer valid. */
  1053. if (smc == NULL)
  1054. return(0);
  1055. SK_UNUSED(slot) ;
  1056. #ifndef MULT_OEM
  1057. for (i = 0 ; i < 4 ; i++) {
  1058. if (inp(SADDR(slot)+PRA(i)) != OEMID(smc,i))
  1059. return(0) ;
  1060. }
  1061. return(1) ;
  1062. #else /* MULT_OEM */
  1063. for (i = 0 ; i < 4 ; i++)
  1064. id[i] = inp(SADDR(slot)+PRA(i)) ;
  1065. smc->hw.oem_id = (struct s_oem_ids *) &oem_ids[0] ;
  1066. for (; smc->hw.oem_id->oi_status != OI_STAT_LAST; smc->hw.oem_id++) {
  1067. if (smc->hw.oem_id->oi_status < smc->hw.oem_min_status)
  1068. continue ;
  1069. if (is_equal_num(&id[0],&OEMID(smc,0),4))
  1070. return (1) ;
  1071. }
  1072. return (0) ; /* No adapter found. */
  1073. #endif /* MULT_OEM */
  1074. }
  1075. int get_board_para(struct s_smc *smc, int slot)
  1076. {
  1077. int i ;
  1078. if (!exist_board(smc,slot))
  1079. return(0) ;
  1080. smc->hw.slot = slot ;
  1081. #ifndef MEM_MAPPED_IO /* if defined by the operating system */
  1082. smc->hw.iop = SADDR(slot) ;
  1083. #endif
  1084. if (!(inp(C0_A(0))&CFG_CARD_EN)) {
  1085. return(2) ; /* CFG_CARD_EN bit not set! */
  1086. }
  1087. smc->hw.irq = opt_ints[(inp(C1_A(0)) & CFG_IRQ_SEL)] ;
  1088. smc->hw.dma = opt_dmas[((inp(C1_A(0)) & CFG_DRQ_SEL)>>3)] ;
  1089. if ((i = inp(C2_A(0)) & CFG_EPROM_SEL) != 0x0f)
  1090. smc->hw.eprom = opt_eproms[i] ;
  1091. else
  1092. smc->hw.eprom = 0 ;
  1093. smc->hw.DmaWriteExtraBytes = 8 ;
  1094. return(1) ;
  1095. }
  1096. #endif /* EISA */
  1097. #ifdef ISA
  1098. #ifndef MULT_OEM
  1099. const u_char sklogo[6] = SKLOGO_STR ;
  1100. #define SIZE_SKLOGO(smc) sizeof(sklogo)
  1101. #define SKLOGO(smc,i) sklogo[i]
  1102. #else /* MULT_OEM */
  1103. #define SIZE_SKLOGO(smc) smc->hw.oem_id->oi_logo_len
  1104. #define SKLOGO(smc,i) smc->hw.oem_id->oi_logo[i]
  1105. #endif /* MULT_OEM */
  1106. int exist_board(struct s_smc *smc, HW_PTR port)
  1107. {
  1108. int i ;
  1109. #ifdef MULT_OEM
  1110. int bytes_read ;
  1111. u_char board_logo[15] ;
  1112. SK_LOC_DECL(u_char,id[4]) ;
  1113. #endif /* MULT_OEM */
  1114. /* No longer valid. */
  1115. if (smc == NULL)
  1116. return(0);
  1117. SK_UNUSED(smc) ;
  1118. #ifndef MULT_OEM
  1119. for (i = SADDRL ; i < (signed) (SADDRL+SIZE_SKLOGO(smc)) ; i++) {
  1120. if ((u_char)inpw((PRA(i)+port)) != SKLOGO(smc,i-SADDRL)) {
  1121. return(0) ;
  1122. }
  1123. }
  1124. /* check MAC address (S&K or other) */
  1125. for (i = 0 ; i < 3 ; i++) {
  1126. if ((u_char)inpw((PRA(i)+port)) != OEMID(smc,i))
  1127. return(0) ;
  1128. }
  1129. return(1) ;
  1130. #else /* MULT_OEM */
  1131. smc->hw.oem_id = (struct s_oem_ids *) &oem_ids[0] ;
  1132. board_logo[0] = (u_char)inpw((PRA(SADDRL)+port)) ;
  1133. bytes_read = 1 ;
  1134. for (; smc->hw.oem_id->oi_status != OI_STAT_LAST; smc->hw.oem_id++) {
  1135. if (smc->hw.oem_id->oi_status < smc->hw.oem_min_status)
  1136. continue ;
  1137. /* Test all read bytes with current OEM_entry */
  1138. /* for (i=0; (i<bytes_read) && (i < SIZE_SKLOGO(smc)); i++) { */
  1139. for (i = 0; i < bytes_read; i++) {
  1140. if (board_logo[i] != SKLOGO(smc,i))
  1141. break ;
  1142. }
  1143. /* If mismatch, switch to next OEM entry */
  1144. if ((board_logo[i] != SKLOGO(smc,i)) && (i < bytes_read))
  1145. continue ;
  1146. --i ;
  1147. while (bytes_read < SIZE_SKLOGO(smc)) {
  1148. // inpw next byte SK_Logo
  1149. i++ ;
  1150. board_logo[i] = (u_char)inpw((PRA(SADDRL+i)+port)) ;
  1151. bytes_read++ ;
  1152. if (board_logo[i] != SKLOGO(smc,i))
  1153. break ;
  1154. }
  1155. for (i = 0 ; i < 3 ; i++)
  1156. id[i] = (u_char)inpw((PRA(i)+port)) ;
  1157. if ((board_logo[i] == SKLOGO(smc,i))
  1158. && (bytes_read == SIZE_SKLOGO(smc))) {
  1159. if (is_equal_num(&id[0],&OEMID(smc,0),3))
  1160. return(1);
  1161. }
  1162. } /* for */
  1163. return(0) ;
  1164. #endif /* MULT_OEM */
  1165. }
  1166. int get_board_para(struct s_smc *smc, int slot)
  1167. {
  1168. SK_UNUSED(smc) ;
  1169. SK_UNUSED(slot) ;
  1170. return(0) ; /* for ISA not supported */
  1171. }
  1172. #endif /* ISA */
  1173. #ifdef PCI
  1174. #ifdef USE_BIOS_FUN
  1175. int exist_board(struct s_smc *smc, int slot)
  1176. {
  1177. u_short dev_id ;
  1178. u_short ven_id ;
  1179. int found ;
  1180. int i ;
  1181. found = FALSE ; /* make sure we returned with adatper not found*/
  1182. /* if an empty oemids.h was included */
  1183. #ifdef MULT_OEM
  1184. smc->hw.oem_id = (struct s_oem_ids *) &oem_ids[0] ;
  1185. for (; smc->hw.oem_id->oi_status != OI_STAT_LAST; smc->hw.oem_id++) {
  1186. if (smc->hw.oem_id->oi_status < smc->hw.oem_min_status)
  1187. continue ;
  1188. #endif
  1189. ven_id = OEMID(smc,0) + (OEMID(smc,1) << 8) ;
  1190. dev_id = OEMID(smc,2) + (OEMID(smc,3) << 8) ;
  1191. for (i = 0; i < slot; i++) {
  1192. if (pci_find_device(i,&smc->hw.pci_handle,
  1193. dev_id,ven_id) != 0) {
  1194. found = FALSE ;
  1195. } else {
  1196. found = TRUE ;
  1197. }
  1198. }
  1199. if (found) {
  1200. return(1) ; /* adapter was found */
  1201. }
  1202. #ifdef MULT_OEM
  1203. }
  1204. #endif
  1205. return(0) ; /* adapter was not found */
  1206. }
  1207. #endif /* PCI */
  1208. #endif /* USE_BIOS_FUNC */
  1209. void driver_get_bia(struct s_smc *smc, struct fddi_addr *bia_addr)
  1210. {
  1211. int i ;
  1212. extern const u_char canonical[256] ;
  1213. for (i = 0 ; i < 6 ; i++) {
  1214. bia_addr->a[i] = canonical[smc->hw.fddi_phys_addr.a[i]] ;
  1215. }
  1216. }
  1217. void smt_start_watchdog(struct s_smc *smc)
  1218. {
  1219. SK_UNUSED(smc) ; /* Make LINT happy. */
  1220. #ifndef DEBUG
  1221. #ifdef PCI
  1222. if (smc->hw.wdog_used) {
  1223. outpw(ADDR(B2_WDOG_CRTL),TIM_START) ; /* Start timer. */
  1224. }
  1225. #endif
  1226. #endif /* DEBUG */
  1227. }
  1228. void smt_stop_watchdog(struct s_smc *smc)
  1229. {
  1230. SK_UNUSED(smc) ; /* Make LINT happy. */
  1231. #ifndef DEBUG
  1232. #ifdef PCI
  1233. if (smc->hw.wdog_used) {
  1234. outpw(ADDR(B2_WDOG_CRTL),TIM_STOP) ; /* Stop timer. */
  1235. }
  1236. #endif
  1237. #endif /* DEBUG */
  1238. }
  1239. #ifdef PCI
  1240. static char get_rom_byte(struct s_smc *smc, u_short addr)
  1241. {
  1242. GET_PAGE(addr) ;
  1243. return (READ_PROM(ADDR(B2_FDP))) ;
  1244. }
  1245. /*
  1246. * ROM image defines
  1247. */
  1248. #define ROM_SIG_1 0
  1249. #define ROM_SIG_2 1
  1250. #define PCI_DATA_1 0x18
  1251. #define PCI_DATA_2 0x19
  1252. /*
  1253. * PCI data structure defines
  1254. */
  1255. #define VPD_DATA_1 0x08
  1256. #define VPD_DATA_2 0x09
  1257. #define IMAGE_LEN_1 0x10
  1258. #define IMAGE_LEN_2 0x11
  1259. #define CODE_TYPE 0x14
  1260. #define INDICATOR 0x15
  1261. /*
  1262. * BEGIN_MANUAL_ENTRY(mac_drv_vpd_read)
  1263. * mac_drv_vpd_read(smc,buf,size,image)
  1264. *
  1265. * function DOWNCALL (FDDIWARE)
  1266. * reads the VPD data of the FPROM and writes it into the
  1267. * buffer
  1268. *
  1269. * para buf points to the buffer for the VPD data
  1270. * size size of the VPD data buffer
  1271. * image boot image; code type of the boot image
  1272. * image = 0 Intel x86, PC-AT compatible
  1273. * 1 OPENBOOT standard for PCI
  1274. * 2-FF reserved
  1275. *
  1276. * returns len number of VPD data bytes read form the FPROM
  1277. * <0 number of read bytes
  1278. * >0 error: data invalid
  1279. *
  1280. * END_MANUAL_ENTRY
  1281. */
  1282. int mac_drv_vpd_read(struct s_smc *smc, char *buf, int size, char image)
  1283. {
  1284. u_short ibase ;
  1285. u_short pci_base ;
  1286. u_short vpd ;
  1287. int len ;
  1288. len = 0 ;
  1289. ibase = 0 ;
  1290. /*
  1291. * as long images defined
  1292. */
  1293. while (get_rom_byte(smc,ibase+ROM_SIG_1) == 0x55 &&
  1294. (u_char) get_rom_byte(smc,ibase+ROM_SIG_2) == 0xaa) {
  1295. /*
  1296. * get the pointer to the PCI data structure
  1297. */
  1298. pci_base = ibase + get_rom_byte(smc,ibase+PCI_DATA_1) +
  1299. (get_rom_byte(smc,ibase+PCI_DATA_2) << 8) ;
  1300. if (image == get_rom_byte(smc,pci_base+CODE_TYPE)) {
  1301. /*
  1302. * we have the right image, read the VPD data
  1303. */
  1304. vpd = ibase + get_rom_byte(smc,pci_base+VPD_DATA_1) +
  1305. (get_rom_byte(smc,pci_base+VPD_DATA_2) << 8) ;
  1306. if (vpd == ibase) {
  1307. break ; /* no VPD data */
  1308. }
  1309. for (len = 0; len < size; len++,buf++,vpd++) {
  1310. *buf = get_rom_byte(smc,vpd) ;
  1311. }
  1312. break ;
  1313. }
  1314. else {
  1315. /*
  1316. * try the next image
  1317. */
  1318. if (get_rom_byte(smc,pci_base+INDICATOR) & 0x80) {
  1319. break ; /* this was the last image */
  1320. }
  1321. ibase = ibase + get_rom_byte(smc,ibase+IMAGE_LEN_1) +
  1322. (get_rom_byte(smc,ibase+IMAGE_LEN_2) << 8) ;
  1323. }
  1324. }
  1325. return(len) ;
  1326. }
  1327. void mac_drv_pci_fix(struct s_smc *smc, u_long fix_value)
  1328. {
  1329. smc->hw.pci_fix_value = fix_value ;
  1330. }
  1331. void mac_do_pci_fix(struct s_smc *smc)
  1332. {
  1333. SK_UNUSED(smc) ;
  1334. }
  1335. #endif /* PCI */