fplustm.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  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. * FORMAC+ Driver for tag mode
  18. */
  19. #include "h/types.h"
  20. #include "h/fddi.h"
  21. #include "h/smc.h"
  22. #include "h/supern_2.h"
  23. #include <linux/bitrev.h>
  24. #ifndef lint
  25. static const char ID_sccs[] = "@(#)fplustm.c 1.32 99/02/23 (C) SK " ;
  26. #endif
  27. #ifndef UNUSED
  28. #ifdef lint
  29. #define UNUSED(x) (x) = (x)
  30. #else
  31. #define UNUSED(x)
  32. #endif
  33. #endif
  34. #define FM_ADDRX (FM_ADDET|FM_EXGPA0|FM_EXGPA1)
  35. #define MS2BCLK(x) ((x)*12500L)
  36. #define US2BCLK(x) ((x)*1250L)
  37. /*
  38. * prototypes for static function
  39. */
  40. static void build_claim_beacon(struct s_smc *smc, u_long t_request);
  41. static int init_mac(struct s_smc *smc, int all);
  42. static void rtm_init(struct s_smc *smc);
  43. static void smt_split_up_fifo(struct s_smc *smc);
  44. #if (!defined(NO_SMT_PANIC) || defined(DEBUG))
  45. static char write_mdr_warning [] = "E350 write_mdr() FM_SNPPND is set\n";
  46. static char cam_warning [] = "E_SMT_004: CAM still busy\n";
  47. #endif
  48. #define DUMMY_READ() smc->hw.mc_dummy = (u_short) inp(ADDR(B0_RAP))
  49. #define CHECK_NPP() { unsigned k = 10000 ;\
  50. while ((inpw(FM_A(FM_STMCHN)) & FM_SNPPND) && k) k--;\
  51. if (!k) { \
  52. SMT_PANIC(smc,SMT_E0130, SMT_E0130_MSG) ; \
  53. } \
  54. }
  55. #define CHECK_CAM() { unsigned k = 10 ;\
  56. while (!(inpw(FM_A(FM_AFSTAT)) & FM_DONE) && k) k--;\
  57. if (!k) { \
  58. SMT_PANIC(smc,SMT_E0131, SMT_E0131_MSG) ; \
  59. } \
  60. }
  61. const struct fddi_addr fddi_broadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
  62. static const struct fddi_addr null_addr = {{0,0,0,0,0,0}};
  63. static const struct fddi_addr dbeacon_multi = {{0x01,0x80,0xc2,0x00,0x01,0x00}};
  64. static const u_short my_said = 0xffff ; /* short address (n.u.) */
  65. static const u_short my_sagp = 0xffff ; /* short group address (n.u.) */
  66. /*
  67. * define my address
  68. */
  69. #ifdef USE_CAN_ADDR
  70. #define MA smc->hw.fddi_canon_addr
  71. #else
  72. #define MA smc->hw.fddi_home_addr
  73. #endif
  74. /*
  75. * useful interrupt bits
  76. */
  77. static const int mac_imsk1u = FM_STXABRS | FM_STXABRA0 | FM_SXMTABT ;
  78. static const int mac_imsk1l = FM_SQLCKS | FM_SQLCKA0 | FM_SPCEPDS | FM_SPCEPDA0|
  79. FM_STBURS | FM_STBURA0 ;
  80. /* delete FM_SRBFL after tests */
  81. static const int mac_imsk2u = FM_SERRSF | FM_SNFSLD | FM_SRCVOVR | FM_SRBFL |
  82. FM_SMYCLM ;
  83. static const int mac_imsk2l = FM_STRTEXR | FM_SDUPCLM | FM_SFRMCTR |
  84. FM_SERRCTR | FM_SLSTCTR |
  85. FM_STRTEXP | FM_SMULTDA | FM_SRNGOP ;
  86. static const int mac_imsk3u = FM_SRCVOVR2 | FM_SRBFL2 ;
  87. static const int mac_imsk3l = FM_SRPERRQ2 | FM_SRPERRQ1 ;
  88. static const int mac_beacon_imsk2u = FM_SOTRBEC | FM_SMYBEC | FM_SBEC |
  89. FM_SLOCLM | FM_SHICLM | FM_SMYCLM | FM_SCLM ;
  90. static u_long mac_get_tneg(struct s_smc *smc)
  91. {
  92. u_long tneg ;
  93. tneg = (u_long)((long)inpw(FM_A(FM_TNEG))<<5) ;
  94. return (u_long)((tneg + ((inpw(FM_A(FM_TMRS))>>10)&0x1f)) |
  95. 0xffe00000L) ;
  96. }
  97. void mac_update_counter(struct s_smc *smc)
  98. {
  99. smc->mib.m[MAC0].fddiMACFrame_Ct =
  100. (smc->mib.m[MAC0].fddiMACFrame_Ct & 0xffff0000L)
  101. + (u_short) inpw(FM_A(FM_FCNTR)) ;
  102. smc->mib.m[MAC0].fddiMACLost_Ct =
  103. (smc->mib.m[MAC0].fddiMACLost_Ct & 0xffff0000L)
  104. + (u_short) inpw(FM_A(FM_LCNTR)) ;
  105. smc->mib.m[MAC0].fddiMACError_Ct =
  106. (smc->mib.m[MAC0].fddiMACError_Ct & 0xffff0000L)
  107. + (u_short) inpw(FM_A(FM_ECNTR)) ;
  108. smc->mib.m[MAC0].fddiMACT_Neg = mac_get_tneg(smc) ;
  109. #ifdef SMT_REAL_TOKEN_CT
  110. /*
  111. * If the token counter is emulated it is updated in smt_event.
  112. */
  113. TBD
  114. #else
  115. smt_emulate_token_ct( smc, MAC0 );
  116. #endif
  117. }
  118. /*
  119. * write long value into buffer memory over memory data register (MDR),
  120. */
  121. static void write_mdr(struct s_smc *smc, u_long val)
  122. {
  123. CHECK_NPP() ;
  124. MDRW(val) ;
  125. }
  126. #if 0
  127. /*
  128. * read long value from buffer memory over memory data register (MDR),
  129. */
  130. static u_long read_mdr(struct s_smc *smc, unsigned int addr)
  131. {
  132. long p ;
  133. CHECK_NPP() ;
  134. MARR(addr) ;
  135. outpw(FM_A(FM_CMDREG1),FM_IRMEMWO) ;
  136. CHECK_NPP() ; /* needed for PCI to prevent from timeing violations */
  137. /* p = MDRR() ; */ /* bad read values if the workaround */
  138. /* smc->hw.mc_dummy = *((short volatile far *)(addr)))*/
  139. /* is used */
  140. p = (u_long)inpw(FM_A(FM_MDRU))<<16 ;
  141. p += (u_long)inpw(FM_A(FM_MDRL)) ;
  142. return p;
  143. }
  144. #endif
  145. /*
  146. * clear buffer memory
  147. */
  148. static void init_ram(struct s_smc *smc)
  149. {
  150. u_short i ;
  151. smc->hw.fp.fifo.rbc_ram_start = 0 ;
  152. smc->hw.fp.fifo.rbc_ram_end =
  153. smc->hw.fp.fifo.rbc_ram_start + RBC_MEM_SIZE ;
  154. CHECK_NPP() ;
  155. MARW(smc->hw.fp.fifo.rbc_ram_start) ;
  156. for (i = smc->hw.fp.fifo.rbc_ram_start;
  157. i < (u_short) (smc->hw.fp.fifo.rbc_ram_end-1); i++)
  158. write_mdr(smc,0L) ;
  159. /* Erase the last byte too */
  160. write_mdr(smc,0L) ;
  161. }
  162. /*
  163. * set receive FIFO pointer
  164. */
  165. static void set_recvptr(struct s_smc *smc)
  166. {
  167. /*
  168. * initialize the pointer for receive queue 1
  169. */
  170. outpw(FM_A(FM_RPR1),smc->hw.fp.fifo.rx1_fifo_start) ; /* RPR1 */
  171. outpw(FM_A(FM_SWPR1),smc->hw.fp.fifo.rx1_fifo_start) ; /* SWPR1 */
  172. outpw(FM_A(FM_WPR1),smc->hw.fp.fifo.rx1_fifo_start) ; /* WPR1 */
  173. outpw(FM_A(FM_EARV1),smc->hw.fp.fifo.tx_s_start-1) ; /* EARV1 */
  174. /*
  175. * initialize the pointer for receive queue 2
  176. */
  177. if (smc->hw.fp.fifo.rx2_fifo_size) {
  178. outpw(FM_A(FM_RPR2),smc->hw.fp.fifo.rx2_fifo_start) ;
  179. outpw(FM_A(FM_SWPR2),smc->hw.fp.fifo.rx2_fifo_start) ;
  180. outpw(FM_A(FM_WPR2),smc->hw.fp.fifo.rx2_fifo_start) ;
  181. outpw(FM_A(FM_EARV2),smc->hw.fp.fifo.rbc_ram_end-1) ;
  182. }
  183. else {
  184. outpw(FM_A(FM_RPR2),smc->hw.fp.fifo.rbc_ram_end-1) ;
  185. outpw(FM_A(FM_SWPR2),smc->hw.fp.fifo.rbc_ram_end-1) ;
  186. outpw(FM_A(FM_WPR2),smc->hw.fp.fifo.rbc_ram_end-1) ;
  187. outpw(FM_A(FM_EARV2),smc->hw.fp.fifo.rbc_ram_end-1) ;
  188. }
  189. }
  190. /*
  191. * set transmit FIFO pointer
  192. */
  193. static void set_txptr(struct s_smc *smc)
  194. {
  195. outpw(FM_A(FM_CMDREG2),FM_IRSTQ) ; /* reset transmit queues */
  196. /*
  197. * initialize the pointer for asynchronous transmit queue
  198. */
  199. outpw(FM_A(FM_RPXA0),smc->hw.fp.fifo.tx_a0_start) ; /* RPXA0 */
  200. outpw(FM_A(FM_SWPXA0),smc->hw.fp.fifo.tx_a0_start) ; /* SWPXA0 */
  201. outpw(FM_A(FM_WPXA0),smc->hw.fp.fifo.tx_a0_start) ; /* WPXA0 */
  202. outpw(FM_A(FM_EAA0),smc->hw.fp.fifo.rx2_fifo_start-1) ; /* EAA0 */
  203. /*
  204. * initialize the pointer for synchronous transmit queue
  205. */
  206. if (smc->hw.fp.fifo.tx_s_size) {
  207. outpw(FM_A(FM_RPXS),smc->hw.fp.fifo.tx_s_start) ;
  208. outpw(FM_A(FM_SWPXS),smc->hw.fp.fifo.tx_s_start) ;
  209. outpw(FM_A(FM_WPXS),smc->hw.fp.fifo.tx_s_start) ;
  210. outpw(FM_A(FM_EAS),smc->hw.fp.fifo.tx_a0_start-1) ;
  211. }
  212. else {
  213. outpw(FM_A(FM_RPXS),smc->hw.fp.fifo.tx_a0_start-1) ;
  214. outpw(FM_A(FM_SWPXS),smc->hw.fp.fifo.tx_a0_start-1) ;
  215. outpw(FM_A(FM_WPXS),smc->hw.fp.fifo.tx_a0_start-1) ;
  216. outpw(FM_A(FM_EAS),smc->hw.fp.fifo.tx_a0_start-1) ;
  217. }
  218. }
  219. /*
  220. * init memory buffer management registers
  221. */
  222. static void init_rbc(struct s_smc *smc)
  223. {
  224. u_short rbc_ram_addr ;
  225. /*
  226. * set unused pointers or permanent pointers
  227. */
  228. rbc_ram_addr = smc->hw.fp.fifo.rx2_fifo_start - 1 ;
  229. outpw(FM_A(FM_RPXA1),rbc_ram_addr) ; /* a1-send pointer */
  230. outpw(FM_A(FM_WPXA1),rbc_ram_addr) ;
  231. outpw(FM_A(FM_SWPXA1),rbc_ram_addr) ;
  232. outpw(FM_A(FM_EAA1),rbc_ram_addr) ;
  233. set_recvptr(smc) ;
  234. set_txptr(smc) ;
  235. }
  236. /*
  237. * init rx pointer
  238. */
  239. static void init_rx(struct s_smc *smc)
  240. {
  241. struct s_smt_rx_queue *queue ;
  242. /*
  243. * init all tx data structures for receive queue 1
  244. */
  245. smc->hw.fp.rx[QUEUE_R1] = queue = &smc->hw.fp.rx_q[QUEUE_R1] ;
  246. queue->rx_bmu_ctl = (HW_PTR) ADDR(B0_R1_CSR) ;
  247. queue->rx_bmu_dsc = (HW_PTR) ADDR(B4_R1_DA) ;
  248. /*
  249. * init all tx data structures for receive queue 2
  250. */
  251. smc->hw.fp.rx[QUEUE_R2] = queue = &smc->hw.fp.rx_q[QUEUE_R2] ;
  252. queue->rx_bmu_ctl = (HW_PTR) ADDR(B0_R2_CSR) ;
  253. queue->rx_bmu_dsc = (HW_PTR) ADDR(B4_R2_DA) ;
  254. }
  255. /*
  256. * set the TSYNC register of the FORMAC to regulate synchronous transmission
  257. */
  258. void set_formac_tsync(struct s_smc *smc, long sync_bw)
  259. {
  260. outpw(FM_A(FM_TSYNC),(unsigned int) (((-sync_bw) >> 5) & 0xffff) ) ;
  261. }
  262. /*
  263. * init all tx data structures
  264. */
  265. static void init_tx(struct s_smc *smc)
  266. {
  267. struct s_smt_tx_queue *queue ;
  268. /*
  269. * init all tx data structures for the synchronous queue
  270. */
  271. smc->hw.fp.tx[QUEUE_S] = queue = &smc->hw.fp.tx_q[QUEUE_S] ;
  272. queue->tx_bmu_ctl = (HW_PTR) ADDR(B0_XS_CSR) ;
  273. queue->tx_bmu_dsc = (HW_PTR) ADDR(B5_XS_DA) ;
  274. #ifdef ESS
  275. set_formac_tsync(smc,smc->ess.sync_bw) ;
  276. #endif
  277. /*
  278. * init all tx data structures for the asynchronous queue 0
  279. */
  280. smc->hw.fp.tx[QUEUE_A0] = queue = &smc->hw.fp.tx_q[QUEUE_A0] ;
  281. queue->tx_bmu_ctl = (HW_PTR) ADDR(B0_XA_CSR) ;
  282. queue->tx_bmu_dsc = (HW_PTR) ADDR(B5_XA_DA) ;
  283. llc_recover_tx(smc) ;
  284. }
  285. static void mac_counter_init(struct s_smc *smc)
  286. {
  287. int i ;
  288. u_long *ec ;
  289. /*
  290. * clear FORMAC+ frame-, lost- and error counter
  291. */
  292. outpw(FM_A(FM_FCNTR),0) ;
  293. outpw(FM_A(FM_LCNTR),0) ;
  294. outpw(FM_A(FM_ECNTR),0) ;
  295. /*
  296. * clear internal error counter structure
  297. */
  298. ec = (u_long *)&smc->hw.fp.err_stats ;
  299. for (i = (sizeof(struct err_st)/sizeof(long)) ; i ; i--)
  300. *ec++ = 0L ;
  301. smc->mib.m[MAC0].fddiMACRingOp_Ct = 0 ;
  302. }
  303. /*
  304. * set FORMAC address, and t_request
  305. */
  306. static void set_formac_addr(struct s_smc *smc)
  307. {
  308. long t_requ = smc->mib.m[MAC0].fddiMACT_Req ;
  309. outpw(FM_A(FM_SAID),my_said) ; /* set short address */
  310. outpw(FM_A(FM_LAIL),(unsigned)((smc->hw.fddi_home_addr.a[4]<<8) +
  311. smc->hw.fddi_home_addr.a[5])) ;
  312. outpw(FM_A(FM_LAIC),(unsigned)((smc->hw.fddi_home_addr.a[2]<<8) +
  313. smc->hw.fddi_home_addr.a[3])) ;
  314. outpw(FM_A(FM_LAIM),(unsigned)((smc->hw.fddi_home_addr.a[0]<<8) +
  315. smc->hw.fddi_home_addr.a[1])) ;
  316. outpw(FM_A(FM_SAGP),my_sagp) ; /* set short group address */
  317. outpw(FM_A(FM_LAGL),(unsigned)((smc->hw.fp.group_addr.a[4]<<8) +
  318. smc->hw.fp.group_addr.a[5])) ;
  319. outpw(FM_A(FM_LAGC),(unsigned)((smc->hw.fp.group_addr.a[2]<<8) +
  320. smc->hw.fp.group_addr.a[3])) ;
  321. outpw(FM_A(FM_LAGM),(unsigned)((smc->hw.fp.group_addr.a[0]<<8) +
  322. smc->hw.fp.group_addr.a[1])) ;
  323. /* set r_request regs. (MSW & LSW of TRT ) */
  324. outpw(FM_A(FM_TREQ1),(unsigned)(t_requ>>16)) ;
  325. outpw(FM_A(FM_TREQ0),(unsigned)t_requ) ;
  326. }
  327. static void set_int(char *p, int l)
  328. {
  329. p[0] = (char)(l >> 24) ;
  330. p[1] = (char)(l >> 16) ;
  331. p[2] = (char)(l >> 8) ;
  332. p[3] = (char)(l >> 0) ;
  333. }
  334. /*
  335. * copy TX descriptor to buffer mem
  336. * append FC field and MAC frame
  337. * if more bit is set in descr
  338. * append pointer to descriptor (endless loop)
  339. * else
  340. * append 'end of chain' pointer
  341. */
  342. static void copy_tx_mac(struct s_smc *smc, u_long td, struct fddi_mac *mac,
  343. unsigned off, int len)
  344. /* u_long td; transmit descriptor */
  345. /* struct fddi_mac *mac; mac frame pointer */
  346. /* unsigned off; start address within buffer memory */
  347. /* int len ; length of the frame including the FC */
  348. {
  349. int i ;
  350. __le32 *p ;
  351. CHECK_NPP() ;
  352. MARW(off) ; /* set memory address reg for writes */
  353. p = (__le32 *) mac ;
  354. for (i = (len + 3)/4 ; i ; i--) {
  355. if (i == 1) {
  356. /* last word, set the tag bit */
  357. outpw(FM_A(FM_CMDREG2),FM_ISTTB) ;
  358. }
  359. write_mdr(smc,le32_to_cpu(*p)) ;
  360. p++ ;
  361. }
  362. outpw(FM_A(FM_CMDREG2),FM_ISTTB) ; /* set the tag bit */
  363. write_mdr(smc,td) ; /* write over memory data reg to buffer */
  364. }
  365. /*
  366. BEGIN_MANUAL_ENTRY(module;tests;3)
  367. How to test directed beacon frames
  368. ----------------------------------------------------------------
  369. o Insert a break point in the function build_claim_beacon()
  370. before calling copy_tx_mac() for building the claim frame.
  371. o Modify the RM3_DETECT case so that the RM6_DETECT state
  372. will always entered from the RM3_DETECT state (function rmt_fsm(),
  373. rmt.c)
  374. o Compile the driver.
  375. o Set the parameter TREQ in the protocol.ini or net.cfg to a
  376. small value to make sure your station will win the claim
  377. process.
  378. o Start the driver.
  379. o When you reach the break point, modify the SA and DA address
  380. of the claim frame (e.g. SA = DA = 10005affffff).
  381. o When you see RM3_DETECT and RM6_DETECT, observe the direct
  382. beacon frames on the UPPSLANA.
  383. END_MANUAL_ENTRY
  384. */
  385. static void directed_beacon(struct s_smc *smc)
  386. {
  387. SK_LOC_DECL(__le32,a[2]) ;
  388. /*
  389. * set UNA in frame
  390. * enable FORMAC to send endless queue of directed beacon
  391. * important: the UNA starts at byte 1 (not at byte 0)
  392. */
  393. * (char *) a = (char) ((long)DBEACON_INFO<<24L) ;
  394. a[1] = 0 ;
  395. memcpy((char *)a+1,(char *) &smc->mib.m[MAC0].fddiMACUpstreamNbr,6) ;
  396. CHECK_NPP() ;
  397. /* set memory address reg for writes */
  398. MARW(smc->hw.fp.fifo.rbc_ram_start+DBEACON_FRAME_OFF+4) ;
  399. write_mdr(smc,le32_to_cpu(a[0])) ;
  400. outpw(FM_A(FM_CMDREG2),FM_ISTTB) ; /* set the tag bit */
  401. write_mdr(smc,le32_to_cpu(a[1])) ;
  402. outpw(FM_A(FM_SABC),smc->hw.fp.fifo.rbc_ram_start + DBEACON_FRAME_OFF) ;
  403. }
  404. /*
  405. setup claim & beacon pointer
  406. NOTE :
  407. special frame packets end with a pointer to their own
  408. descriptor, and the MORE bit is set in the descriptor
  409. */
  410. static void build_claim_beacon(struct s_smc *smc, u_long t_request)
  411. {
  412. u_int td ;
  413. int len ;
  414. struct fddi_mac_sf *mac ;
  415. /*
  416. * build claim packet
  417. */
  418. len = 17 ;
  419. td = TX_DESCRIPTOR | ((((u_int)len-1)&3)<<27) ;
  420. mac = &smc->hw.fp.mac_sfb ;
  421. mac->mac_fc = FC_CLAIM ;
  422. /* DA == SA in claim frame */
  423. mac->mac_source = mac->mac_dest = MA ;
  424. /* 2's complement */
  425. set_int((char *)mac->mac_info,(int)t_request) ;
  426. copy_tx_mac(smc,td,(struct fddi_mac *)mac,
  427. smc->hw.fp.fifo.rbc_ram_start + CLAIM_FRAME_OFF,len) ;
  428. /* set CLAIM start pointer */
  429. outpw(FM_A(FM_SACL),smc->hw.fp.fifo.rbc_ram_start + CLAIM_FRAME_OFF) ;
  430. /*
  431. * build beacon packet
  432. */
  433. len = 17 ;
  434. td = TX_DESCRIPTOR | ((((u_int)len-1)&3)<<27) ;
  435. mac->mac_fc = FC_BEACON ;
  436. mac->mac_source = MA ;
  437. mac->mac_dest = null_addr ; /* DA == 0 in beacon frame */
  438. set_int((char *) mac->mac_info,((int)BEACON_INFO<<24) + 0 ) ;
  439. copy_tx_mac(smc,td,(struct fddi_mac *)mac,
  440. smc->hw.fp.fifo.rbc_ram_start + BEACON_FRAME_OFF,len) ;
  441. /* set beacon start pointer */
  442. outpw(FM_A(FM_SABC),smc->hw.fp.fifo.rbc_ram_start + BEACON_FRAME_OFF) ;
  443. /*
  444. * build directed beacon packet
  445. * contains optional UNA
  446. */
  447. len = 23 ;
  448. td = TX_DESCRIPTOR | ((((u_int)len-1)&3)<<27) ;
  449. mac->mac_fc = FC_BEACON ;
  450. mac->mac_source = MA ;
  451. mac->mac_dest = dbeacon_multi ; /* multicast */
  452. set_int((char *) mac->mac_info,((int)DBEACON_INFO<<24) + 0 ) ;
  453. set_int((char *) mac->mac_info+4,0) ;
  454. set_int((char *) mac->mac_info+8,0) ;
  455. copy_tx_mac(smc,td,(struct fddi_mac *)mac,
  456. smc->hw.fp.fifo.rbc_ram_start + DBEACON_FRAME_OFF,len) ;
  457. /* end of claim/beacon queue */
  458. outpw(FM_A(FM_EACB),smc->hw.fp.fifo.rx1_fifo_start-1) ;
  459. outpw(FM_A(FM_WPXSF),0) ;
  460. outpw(FM_A(FM_RPXSF),0) ;
  461. }
  462. static void formac_rcv_restart(struct s_smc *smc)
  463. {
  464. /* enable receive function */
  465. SETMASK(FM_A(FM_MDREG1),smc->hw.fp.rx_mode,FM_ADDRX) ;
  466. outpw(FM_A(FM_CMDREG1),FM_ICLLR) ; /* clear receive lock */
  467. }
  468. void formac_tx_restart(struct s_smc *smc)
  469. {
  470. outpw(FM_A(FM_CMDREG1),FM_ICLLS) ; /* clear s-frame lock */
  471. outpw(FM_A(FM_CMDREG1),FM_ICLLA0) ; /* clear a-frame lock */
  472. }
  473. static void enable_formac(struct s_smc *smc)
  474. {
  475. /* set formac IMSK : 0 enables irq */
  476. outpw(FM_A(FM_IMSK1U),(unsigned short)~mac_imsk1u);
  477. outpw(FM_A(FM_IMSK1L),(unsigned short)~mac_imsk1l);
  478. outpw(FM_A(FM_IMSK2U),(unsigned short)~mac_imsk2u);
  479. outpw(FM_A(FM_IMSK2L),(unsigned short)~mac_imsk2l);
  480. outpw(FM_A(FM_IMSK3U),(unsigned short)~mac_imsk3u);
  481. outpw(FM_A(FM_IMSK3L),(unsigned short)~mac_imsk3l);
  482. }
  483. #if 0 /* Removed because the driver should use the ASICs TX complete IRQ. */
  484. /* The FORMACs tx complete IRQ should be used any longer */
  485. /*
  486. BEGIN_MANUAL_ENTRY(if,func;others;4)
  487. void enable_tx_irq(smc, queue)
  488. struct s_smc *smc ;
  489. u_short queue ;
  490. Function DOWNCALL (SMT, fplustm.c)
  491. enable_tx_irq() enables the FORMACs transmit complete
  492. interrupt of the queue.
  493. Para queue = QUEUE_S: synchronous queue
  494. = QUEUE_A0: asynchronous queue
  495. Note After any ring operational change the transmit complete
  496. interrupts are disabled.
  497. The operating system dependent module must enable
  498. the transmit complete interrupt of a queue,
  499. - when it queues the first frame,
  500. because of no transmit resources are beeing
  501. available and
  502. - when it escapes from the function llc_restart_tx
  503. while some frames are still queued.
  504. END_MANUAL_ENTRY
  505. */
  506. void enable_tx_irq(struct s_smc *smc, u_short queue)
  507. /* u_short queue; 0 = synchronous queue, 1 = asynchronous queue 0 */
  508. {
  509. u_short imask ;
  510. imask = ~(inpw(FM_A(FM_IMSK1U))) ;
  511. if (queue == 0) {
  512. outpw(FM_A(FM_IMSK1U),~(imask|FM_STEFRMS)) ;
  513. }
  514. if (queue == 1) {
  515. outpw(FM_A(FM_IMSK1U),~(imask|FM_STEFRMA0)) ;
  516. }
  517. }
  518. /*
  519. BEGIN_MANUAL_ENTRY(if,func;others;4)
  520. void disable_tx_irq(smc, queue)
  521. struct s_smc *smc ;
  522. u_short queue ;
  523. Function DOWNCALL (SMT, fplustm.c)
  524. disable_tx_irq disables the FORMACs transmit complete
  525. interrupt of the queue
  526. Para queue = QUEUE_S: synchronous queue
  527. = QUEUE_A0: asynchronous queue
  528. Note The operating system dependent module should disable
  529. the transmit complete interrupts if it escapes from the
  530. function llc_restart_tx and no frames are queued.
  531. END_MANUAL_ENTRY
  532. */
  533. void disable_tx_irq(struct s_smc *smc, u_short queue)
  534. /* u_short queue; 0 = synchronous queue, 1 = asynchronous queue 0 */
  535. {
  536. u_short imask ;
  537. imask = ~(inpw(FM_A(FM_IMSK1U))) ;
  538. if (queue == 0) {
  539. outpw(FM_A(FM_IMSK1U),~(imask&~FM_STEFRMS)) ;
  540. }
  541. if (queue == 1) {
  542. outpw(FM_A(FM_IMSK1U),~(imask&~FM_STEFRMA0)) ;
  543. }
  544. }
  545. #endif
  546. static void disable_formac(struct s_smc *smc)
  547. {
  548. /* clear formac IMSK : 1 disables irq */
  549. outpw(FM_A(FM_IMSK1U),MW) ;
  550. outpw(FM_A(FM_IMSK1L),MW) ;
  551. outpw(FM_A(FM_IMSK2U),MW) ;
  552. outpw(FM_A(FM_IMSK2L),MW) ;
  553. outpw(FM_A(FM_IMSK3U),MW) ;
  554. outpw(FM_A(FM_IMSK3L),MW) ;
  555. }
  556. static void mac_ring_up(struct s_smc *smc, int up)
  557. {
  558. if (up) {
  559. formac_rcv_restart(smc) ; /* enable receive function */
  560. smc->hw.mac_ring_is_up = TRUE ;
  561. llc_restart_tx(smc) ; /* TX queue */
  562. }
  563. else {
  564. /* disable receive function */
  565. SETMASK(FM_A(FM_MDREG1),FM_MDISRCV,FM_ADDET) ;
  566. /* abort current transmit activity */
  567. outpw(FM_A(FM_CMDREG2),FM_IACTR) ;
  568. smc->hw.mac_ring_is_up = FALSE ;
  569. }
  570. }
  571. /*--------------------------- ISR handling ----------------------------------*/
  572. /*
  573. * mac1_irq is in drvfbi.c
  574. */
  575. /*
  576. * mac2_irq: status bits for the receive queue 1, and ring status
  577. * ring status indication bits
  578. */
  579. void mac2_irq(struct s_smc *smc, u_short code_s2u, u_short code_s2l)
  580. {
  581. u_short change_s2l ;
  582. u_short change_s2u ;
  583. /* (jd) 22-Feb-1999
  584. * Restart 2_DMax Timer after end of claiming or beaconing
  585. */
  586. if (code_s2u & (FM_SCLM|FM_SHICLM|FM_SBEC|FM_SOTRBEC)) {
  587. queue_event(smc,EVENT_RMT,RM_TX_STATE_CHANGE) ;
  588. }
  589. else if (code_s2l & (FM_STKISS)) {
  590. queue_event(smc,EVENT_RMT,RM_TX_STATE_CHANGE) ;
  591. }
  592. /*
  593. * XOR current st bits with the last to avoid useless RMT event queuing
  594. */
  595. change_s2l = smc->hw.fp.s2l ^ code_s2l ;
  596. change_s2u = smc->hw.fp.s2u ^ code_s2u ;
  597. if ((change_s2l & FM_SRNGOP) ||
  598. (!smc->hw.mac_ring_is_up && ((code_s2l & FM_SRNGOP)))) {
  599. if (code_s2l & FM_SRNGOP) {
  600. mac_ring_up(smc,1) ;
  601. queue_event(smc,EVENT_RMT,RM_RING_OP) ;
  602. smc->mib.m[MAC0].fddiMACRingOp_Ct++ ;
  603. }
  604. else {
  605. mac_ring_up(smc,0) ;
  606. queue_event(smc,EVENT_RMT,RM_RING_NON_OP) ;
  607. }
  608. goto mac2_end ;
  609. }
  610. if (code_s2l & FM_SMISFRM) { /* missed frame */
  611. smc->mib.m[MAC0].fddiMACNotCopied_Ct++ ;
  612. }
  613. if (code_s2u & (FM_SRCVOVR | /* recv. FIFO overflow */
  614. FM_SRBFL)) { /* recv. buffer full */
  615. smc->hw.mac_ct.mac_r_restart_counter++ ;
  616. /* formac_rcv_restart(smc) ; */
  617. smt_stat_counter(smc,1) ;
  618. /* goto mac2_end ; */
  619. }
  620. if (code_s2u & FM_SOTRBEC)
  621. queue_event(smc,EVENT_RMT,RM_OTHER_BEACON) ;
  622. if (code_s2u & FM_SMYBEC)
  623. queue_event(smc,EVENT_RMT,RM_MY_BEACON) ;
  624. if (change_s2u & code_s2u & FM_SLOCLM) {
  625. DB_RMTN(2,"RMT : lower claim received\n",0,0) ;
  626. }
  627. if ((code_s2u & FM_SMYCLM) && !(code_s2l & FM_SDUPCLM)) {
  628. /*
  629. * This is my claim and that claim is not detected as a
  630. * duplicate one.
  631. */
  632. queue_event(smc,EVENT_RMT,RM_MY_CLAIM) ;
  633. }
  634. if (code_s2l & FM_SDUPCLM) {
  635. /*
  636. * If a duplicate claim frame (same SA but T_Bid != T_Req)
  637. * this flag will be set.
  638. * In the RMT state machine we need a RM_VALID_CLAIM event
  639. * to do the appropriate state change.
  640. * RM(34c)
  641. */
  642. queue_event(smc,EVENT_RMT,RM_VALID_CLAIM) ;
  643. }
  644. if (change_s2u & code_s2u & FM_SHICLM) {
  645. DB_RMTN(2,"RMT : higher claim received\n",0,0) ;
  646. }
  647. if ( (code_s2l & FM_STRTEXP) ||
  648. (code_s2l & FM_STRTEXR) )
  649. queue_event(smc,EVENT_RMT,RM_TRT_EXP) ;
  650. if (code_s2l & FM_SMULTDA) {
  651. /*
  652. * The MAC has found a 2. MAC with the same address.
  653. * Signal dup_addr_test = failed to RMT state machine.
  654. * RM(25)
  655. */
  656. smc->r.dup_addr_test = DA_FAILED ;
  657. queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
  658. }
  659. if (code_s2u & FM_SBEC)
  660. smc->hw.fp.err_stats.err_bec_stat++ ;
  661. if (code_s2u & FM_SCLM)
  662. smc->hw.fp.err_stats.err_clm_stat++ ;
  663. if (code_s2l & FM_STVXEXP)
  664. smc->mib.m[MAC0].fddiMACTvxExpired_Ct++ ;
  665. if ((code_s2u & (FM_SBEC|FM_SCLM))) {
  666. if (!(change_s2l & FM_SRNGOP) && (smc->hw.fp.s2l & FM_SRNGOP)) {
  667. mac_ring_up(smc,0) ;
  668. queue_event(smc,EVENT_RMT,RM_RING_NON_OP) ;
  669. mac_ring_up(smc,1) ;
  670. queue_event(smc,EVENT_RMT,RM_RING_OP) ;
  671. smc->mib.m[MAC0].fddiMACRingOp_Ct++ ;
  672. }
  673. }
  674. if (code_s2l & FM_SPHINV)
  675. smc->hw.fp.err_stats.err_phinv++ ;
  676. if (code_s2l & FM_SSIFG)
  677. smc->hw.fp.err_stats.err_sifg_det++ ;
  678. if (code_s2l & FM_STKISS)
  679. smc->hw.fp.err_stats.err_tkiss++ ;
  680. if (code_s2l & FM_STKERR)
  681. smc->hw.fp.err_stats.err_tkerr++ ;
  682. if (code_s2l & FM_SFRMCTR)
  683. smc->mib.m[MAC0].fddiMACFrame_Ct += 0x10000L ;
  684. if (code_s2l & FM_SERRCTR)
  685. smc->mib.m[MAC0].fddiMACError_Ct += 0x10000L ;
  686. if (code_s2l & FM_SLSTCTR)
  687. smc->mib.m[MAC0].fddiMACLost_Ct += 0x10000L ;
  688. if (code_s2u & FM_SERRSF) {
  689. SMT_PANIC(smc,SMT_E0114, SMT_E0114_MSG) ;
  690. }
  691. mac2_end:
  692. /* notice old status */
  693. smc->hw.fp.s2l = code_s2l ;
  694. smc->hw.fp.s2u = code_s2u ;
  695. outpw(FM_A(FM_IMSK2U),~mac_imsk2u) ;
  696. }
  697. /*
  698. * mac3_irq: receive queue 2 bits and address detection bits
  699. */
  700. void mac3_irq(struct s_smc *smc, u_short code_s3u, u_short code_s3l)
  701. {
  702. UNUSED(code_s3l) ;
  703. if (code_s3u & (FM_SRCVOVR2 | /* recv. FIFO overflow */
  704. FM_SRBFL2)) { /* recv. buffer full */
  705. smc->hw.mac_ct.mac_r_restart_counter++ ;
  706. smt_stat_counter(smc,1);
  707. }
  708. if (code_s3u & FM_SRPERRQ2) { /* parity error receive queue 2 */
  709. SMT_PANIC(smc,SMT_E0115, SMT_E0115_MSG) ;
  710. }
  711. if (code_s3u & FM_SRPERRQ1) { /* parity error receive queue 2 */
  712. SMT_PANIC(smc,SMT_E0116, SMT_E0116_MSG) ;
  713. }
  714. }
  715. /*
  716. * take formac offline
  717. */
  718. static void formac_offline(struct s_smc *smc)
  719. {
  720. outpw(FM_A(FM_CMDREG2),FM_IACTR) ;/* abort current transmit activity */
  721. /* disable receive function */
  722. SETMASK(FM_A(FM_MDREG1),FM_MDISRCV,FM_ADDET) ;
  723. /* FORMAC+ 'Initialize Mode' */
  724. SETMASK(FM_A(FM_MDREG1),FM_MINIT,FM_MMODE) ;
  725. disable_formac(smc) ;
  726. smc->hw.mac_ring_is_up = FALSE ;
  727. smc->hw.hw_state = STOPPED ;
  728. }
  729. /*
  730. * bring formac online
  731. */
  732. static void formac_online(struct s_smc *smc)
  733. {
  734. enable_formac(smc) ;
  735. SETMASK(FM_A(FM_MDREG1),FM_MONLINE | FM_SELRA | MDR1INIT |
  736. smc->hw.fp.rx_mode, FM_MMODE | FM_SELRA | FM_ADDRX) ;
  737. }
  738. /*
  739. * FORMAC+ full init. (tx, rx, timer, counter, claim & beacon)
  740. */
  741. int init_fplus(struct s_smc *smc)
  742. {
  743. smc->hw.fp.nsa_mode = FM_MRNNSAFNMA ;
  744. smc->hw.fp.rx_mode = FM_MDAMA ;
  745. smc->hw.fp.group_addr = fddi_broadcast ;
  746. smc->hw.fp.func_addr = 0 ;
  747. smc->hw.fp.frselreg_init = 0 ;
  748. init_driver_fplus(smc) ;
  749. if (smc->s.sas == SMT_DAS)
  750. smc->hw.fp.mdr3init |= FM_MENDAS ;
  751. smc->hw.mac_ct.mac_nobuf_counter = 0 ;
  752. smc->hw.mac_ct.mac_r_restart_counter = 0 ;
  753. smc->hw.fp.fm_st1u = (HW_PTR) ADDR(B0_ST1U) ;
  754. smc->hw.fp.fm_st1l = (HW_PTR) ADDR(B0_ST1L) ;
  755. smc->hw.fp.fm_st2u = (HW_PTR) ADDR(B0_ST2U) ;
  756. smc->hw.fp.fm_st2l = (HW_PTR) ADDR(B0_ST2L) ;
  757. smc->hw.fp.fm_st3u = (HW_PTR) ADDR(B0_ST3U) ;
  758. smc->hw.fp.fm_st3l = (HW_PTR) ADDR(B0_ST3L) ;
  759. smc->hw.fp.s2l = smc->hw.fp.s2u = 0 ;
  760. smc->hw.mac_ring_is_up = 0 ;
  761. mac_counter_init(smc) ;
  762. /* convert BCKL units to symbol time */
  763. smc->hw.mac_pa.t_neg = (u_long)0 ;
  764. smc->hw.mac_pa.t_pri = (u_long)0 ;
  765. /* make sure all PCI settings are correct */
  766. mac_do_pci_fix(smc) ;
  767. return init_mac(smc, 1);
  768. /* enable_formac(smc) ; */
  769. }
  770. static int init_mac(struct s_smc *smc, int all)
  771. {
  772. u_short t_max,x ;
  773. u_long time=0 ;
  774. /*
  775. * clear memory
  776. */
  777. outpw(FM_A(FM_MDREG1),FM_MINIT) ; /* FORMAC+ init mode */
  778. set_formac_addr(smc) ;
  779. outpw(FM_A(FM_MDREG1),FM_MMEMACT) ; /* FORMAC+ memory activ mode */
  780. /* Note: Mode register 2 is set here, incase parity is enabled. */
  781. outpw(FM_A(FM_MDREG2),smc->hw.fp.mdr2init) ;
  782. if (all) {
  783. init_ram(smc) ;
  784. }
  785. else {
  786. /*
  787. * reset the HPI, the Master and the BMUs
  788. */
  789. outp(ADDR(B0_CTRL), CTRL_HPI_SET) ;
  790. time = hwt_quick_read(smc) ;
  791. }
  792. /*
  793. * set all pointers, frames etc
  794. */
  795. smt_split_up_fifo(smc) ;
  796. init_tx(smc) ;
  797. init_rx(smc) ;
  798. init_rbc(smc) ;
  799. build_claim_beacon(smc,smc->mib.m[MAC0].fddiMACT_Req) ;
  800. /* set RX threshold */
  801. /* see Errata #SN2 Phantom receive overflow */
  802. outpw(FM_A(FM_FRMTHR),14<<12) ; /* switch on */
  803. /* set formac work mode */
  804. outpw(FM_A(FM_MDREG1),MDR1INIT | FM_SELRA | smc->hw.fp.rx_mode) ;
  805. outpw(FM_A(FM_MDREG2),smc->hw.fp.mdr2init) ;
  806. outpw(FM_A(FM_MDREG3),smc->hw.fp.mdr3init) ;
  807. outpw(FM_A(FM_FRSELREG),smc->hw.fp.frselreg_init) ;
  808. /* set timer */
  809. /*
  810. * errata #22 fplus:
  811. * T_MAX must not be FFFE
  812. * or one of FFDF, FFB8, FF91 (-0x27 etc..)
  813. */
  814. t_max = (u_short)(smc->mib.m[MAC0].fddiMACT_Max/32) ;
  815. x = t_max/0x27 ;
  816. x *= 0x27 ;
  817. if ((t_max == 0xfffe) || (t_max - x == 0x16))
  818. t_max-- ;
  819. outpw(FM_A(FM_TMAX),(u_short)t_max) ;
  820. /* BugFix for report #10204 */
  821. if (smc->mib.m[MAC0].fddiMACTvxValue < (u_long) (- US2BCLK(52))) {
  822. outpw(FM_A(FM_TVX), (u_short) (- US2BCLK(52))/255 & MB) ;
  823. } else {
  824. outpw(FM_A(FM_TVX),
  825. (u_short)((smc->mib.m[MAC0].fddiMACTvxValue/255) & MB)) ;
  826. }
  827. outpw(FM_A(FM_CMDREG1),FM_ICLLS) ; /* clear s-frame lock */
  828. outpw(FM_A(FM_CMDREG1),FM_ICLLA0) ; /* clear a-frame lock */
  829. outpw(FM_A(FM_CMDREG1),FM_ICLLR); /* clear receive lock */
  830. /* Auto unlock receice threshold for receive queue 1 and 2 */
  831. outpw(FM_A(FM_UNLCKDLY),(0xff|(0xff<<8))) ;
  832. rtm_init(smc) ; /* RT-Monitor */
  833. if (!all) {
  834. /*
  835. * after 10ms, reset the BMUs and repair the rings
  836. */
  837. hwt_wait_time(smc,time,MS2BCLK(10)) ;
  838. outpd(ADDR(B0_R1_CSR),CSR_SET_RESET) ;
  839. outpd(ADDR(B0_XA_CSR),CSR_SET_RESET) ;
  840. outpd(ADDR(B0_XS_CSR),CSR_SET_RESET) ;
  841. outp(ADDR(B0_CTRL), CTRL_HPI_CLR) ;
  842. outpd(ADDR(B0_R1_CSR),CSR_CLR_RESET) ;
  843. outpd(ADDR(B0_XA_CSR),CSR_CLR_RESET) ;
  844. outpd(ADDR(B0_XS_CSR),CSR_CLR_RESET) ;
  845. if (!smc->hw.hw_is_64bit) {
  846. outpd(ADDR(B4_R1_F), RX_WATERMARK) ;
  847. outpd(ADDR(B5_XA_F), TX_WATERMARK) ;
  848. outpd(ADDR(B5_XS_F), TX_WATERMARK) ;
  849. }
  850. smc->hw.hw_state = STOPPED ;
  851. mac_drv_repair_descr(smc) ;
  852. }
  853. smc->hw.hw_state = STARTED ;
  854. return 0;
  855. }
  856. /*
  857. * called by CFM
  858. */
  859. void config_mux(struct s_smc *smc, int mux)
  860. {
  861. plc_config_mux(smc,mux) ;
  862. SETMASK(FM_A(FM_MDREG1),FM_SELRA,FM_SELRA) ;
  863. }
  864. /*
  865. * called by RMT
  866. * enable CLAIM/BEACON interrupts
  867. * (only called if these events are of interest, e.g. in DETECT state
  868. * the interrupt must not be permanently enabled
  869. * RMT calls this function periodically (timer driven polling)
  870. */
  871. void sm_mac_check_beacon_claim(struct s_smc *smc)
  872. {
  873. /* set formac IMSK : 0 enables irq */
  874. outpw(FM_A(FM_IMSK2U),~(mac_imsk2u | mac_beacon_imsk2u)) ;
  875. /* the driver must receive the directed beacons */
  876. formac_rcv_restart(smc) ;
  877. process_receive(smc) ;
  878. }
  879. /*-------------------------- interface functions ----------------------------*/
  880. /*
  881. * control MAC layer (called by RMT)
  882. */
  883. void sm_ma_control(struct s_smc *smc, int mode)
  884. {
  885. switch(mode) {
  886. case MA_OFFLINE :
  887. /* Add to make the MAC offline in RM0_ISOLATED state */
  888. formac_offline(smc) ;
  889. break ;
  890. case MA_RESET :
  891. (void)init_mac(smc,0) ;
  892. break ;
  893. case MA_BEACON :
  894. formac_online(smc) ;
  895. break ;
  896. case MA_DIRECTED :
  897. directed_beacon(smc) ;
  898. break ;
  899. case MA_TREQ :
  900. /*
  901. * no actions necessary, TREQ is already set
  902. */
  903. break ;
  904. }
  905. }
  906. int sm_mac_get_tx_state(struct s_smc *smc)
  907. {
  908. return (inpw(FM_A(FM_STMCHN))>>4) & 7;
  909. }
  910. /*
  911. * multicast functions
  912. */
  913. static struct s_fpmc* mac_get_mc_table(struct s_smc *smc,
  914. struct fddi_addr *user,
  915. struct fddi_addr *own,
  916. int del, int can)
  917. {
  918. struct s_fpmc *tb ;
  919. struct s_fpmc *slot ;
  920. u_char *p ;
  921. int i ;
  922. /*
  923. * set own = can(user)
  924. */
  925. *own = *user ;
  926. if (can) {
  927. p = own->a ;
  928. for (i = 0 ; i < 6 ; i++, p++)
  929. *p = bitrev8(*p);
  930. }
  931. slot = NULL;
  932. for (i = 0, tb = smc->hw.fp.mc.table ; i < FPMAX_MULTICAST ; i++, tb++){
  933. if (!tb->n) { /* not used */
  934. if (!del && !slot) /* if !del save first free */
  935. slot = tb ;
  936. continue ;
  937. }
  938. if (memcmp((char *)&tb->a,(char *)own,6))
  939. continue ;
  940. return tb;
  941. }
  942. return slot; /* return first free or NULL */
  943. }
  944. /*
  945. BEGIN_MANUAL_ENTRY(if,func;others;2)
  946. void mac_clear_multicast(smc)
  947. struct s_smc *smc ;
  948. Function DOWNCALL (SMT, fplustm.c)
  949. Clear all multicast entries
  950. END_MANUAL_ENTRY()
  951. */
  952. void mac_clear_multicast(struct s_smc *smc)
  953. {
  954. struct s_fpmc *tb ;
  955. int i ;
  956. smc->hw.fp.os_slots_used = 0 ; /* note the SMT addresses */
  957. /* will not be deleted */
  958. for (i = 0, tb = smc->hw.fp.mc.table ; i < FPMAX_MULTICAST ; i++, tb++){
  959. if (!tb->perm) {
  960. tb->n = 0 ;
  961. }
  962. }
  963. }
  964. /*
  965. BEGIN_MANUAL_ENTRY(if,func;others;2)
  966. int mac_add_multicast(smc,addr,can)
  967. struct s_smc *smc ;
  968. struct fddi_addr *addr ;
  969. int can ;
  970. Function DOWNCALL (SMC, fplustm.c)
  971. Add an entry to the multicast table
  972. Para addr pointer to a multicast address
  973. can = 0: the multicast address has the physical format
  974. = 1: the multicast address has the canonical format
  975. | 0x80 permanent
  976. Returns 0: success
  977. 1: address table full
  978. Note After a 'driver reset' or a 'station set address' all
  979. entries of the multicast table are cleared.
  980. In this case the driver has to fill the multicast table again.
  981. After the operating system dependent module filled
  982. the multicast table it must call mac_update_multicast
  983. to activate the new multicast addresses!
  984. END_MANUAL_ENTRY()
  985. */
  986. int mac_add_multicast(struct s_smc *smc, struct fddi_addr *addr, int can)
  987. {
  988. SK_LOC_DECL(struct fddi_addr,own) ;
  989. struct s_fpmc *tb ;
  990. /*
  991. * check if there are free table entries
  992. */
  993. if (can & 0x80) {
  994. if (smc->hw.fp.smt_slots_used >= SMT_MAX_MULTI) {
  995. return 1;
  996. }
  997. }
  998. else {
  999. if (smc->hw.fp.os_slots_used >= FPMAX_MULTICAST-SMT_MAX_MULTI) {
  1000. return 1;
  1001. }
  1002. }
  1003. /*
  1004. * find empty slot
  1005. */
  1006. if (!(tb = mac_get_mc_table(smc,addr,&own,0,can & ~0x80)))
  1007. return 1;
  1008. tb->n++ ;
  1009. tb->a = own ;
  1010. tb->perm = (can & 0x80) ? 1 : 0 ;
  1011. if (can & 0x80)
  1012. smc->hw.fp.smt_slots_used++ ;
  1013. else
  1014. smc->hw.fp.os_slots_used++ ;
  1015. return 0;
  1016. }
  1017. /*
  1018. * mode
  1019. */
  1020. #define RX_MODE_PROM 0x1
  1021. #define RX_MODE_ALL_MULTI 0x2
  1022. /*
  1023. BEGIN_MANUAL_ENTRY(if,func;others;2)
  1024. void mac_update_multicast(smc)
  1025. struct s_smc *smc ;
  1026. Function DOWNCALL (SMT, fplustm.c)
  1027. Update FORMAC multicast registers
  1028. END_MANUAL_ENTRY()
  1029. */
  1030. void mac_update_multicast(struct s_smc *smc)
  1031. {
  1032. struct s_fpmc *tb ;
  1033. u_char *fu ;
  1034. int i ;
  1035. /*
  1036. * invalidate the CAM
  1037. */
  1038. outpw(FM_A(FM_AFCMD),FM_IINV_CAM) ;
  1039. /*
  1040. * set the functional address
  1041. */
  1042. if (smc->hw.fp.func_addr) {
  1043. fu = (u_char *) &smc->hw.fp.func_addr ;
  1044. outpw(FM_A(FM_AFMASK2),0xffff) ;
  1045. outpw(FM_A(FM_AFMASK1),(u_short) ~((fu[0] << 8) + fu[1])) ;
  1046. outpw(FM_A(FM_AFMASK0),(u_short) ~((fu[2] << 8) + fu[3])) ;
  1047. outpw(FM_A(FM_AFPERS),FM_VALID|FM_DA) ;
  1048. outpw(FM_A(FM_AFCOMP2), 0xc000) ;
  1049. outpw(FM_A(FM_AFCOMP1), 0x0000) ;
  1050. outpw(FM_A(FM_AFCOMP0), 0x0000) ;
  1051. outpw(FM_A(FM_AFCMD),FM_IWRITE_CAM) ;
  1052. }
  1053. /*
  1054. * set the mask and the personality register(s)
  1055. */
  1056. outpw(FM_A(FM_AFMASK0),0xffff) ;
  1057. outpw(FM_A(FM_AFMASK1),0xffff) ;
  1058. outpw(FM_A(FM_AFMASK2),0xffff) ;
  1059. outpw(FM_A(FM_AFPERS),FM_VALID|FM_DA) ;
  1060. for (i = 0, tb = smc->hw.fp.mc.table; i < FPMAX_MULTICAST; i++, tb++) {
  1061. if (tb->n) {
  1062. CHECK_CAM() ;
  1063. /*
  1064. * write the multicast address into the CAM
  1065. */
  1066. outpw(FM_A(FM_AFCOMP2),
  1067. (u_short)((tb->a.a[0]<<8)+tb->a.a[1])) ;
  1068. outpw(FM_A(FM_AFCOMP1),
  1069. (u_short)((tb->a.a[2]<<8)+tb->a.a[3])) ;
  1070. outpw(FM_A(FM_AFCOMP0),
  1071. (u_short)((tb->a.a[4]<<8)+tb->a.a[5])) ;
  1072. outpw(FM_A(FM_AFCMD),FM_IWRITE_CAM) ;
  1073. }
  1074. }
  1075. }
  1076. /*
  1077. BEGIN_MANUAL_ENTRY(if,func;others;3)
  1078. void mac_set_rx_mode(smc,mode)
  1079. struct s_smc *smc ;
  1080. int mode ;
  1081. Function DOWNCALL/INTERN (SMT, fplustm.c)
  1082. This function enables / disables the selected receive.
  1083. Don't call this function if the hardware module is
  1084. used -- use mac_drv_rx_mode() instead of.
  1085. Para mode = 1 RX_ENABLE_ALLMULTI enable all multicasts
  1086. 2 RX_DISABLE_ALLMULTI disable "enable all multicasts"
  1087. 3 RX_ENABLE_PROMISC enable promiscuous
  1088. 4 RX_DISABLE_PROMISC disable promiscuous
  1089. 5 RX_ENABLE_NSA enable reception of NSA frames
  1090. 6 RX_DISABLE_NSA disable reception of NSA frames
  1091. Note The selected receive modes will be lost after 'driver reset'
  1092. or 'set station address'
  1093. END_MANUAL_ENTRY
  1094. */
  1095. void mac_set_rx_mode(struct s_smc *smc, int mode)
  1096. {
  1097. switch (mode) {
  1098. case RX_ENABLE_ALLMULTI :
  1099. smc->hw.fp.rx_prom |= RX_MODE_ALL_MULTI ;
  1100. break ;
  1101. case RX_DISABLE_ALLMULTI :
  1102. smc->hw.fp.rx_prom &= ~RX_MODE_ALL_MULTI ;
  1103. break ;
  1104. case RX_ENABLE_PROMISC :
  1105. smc->hw.fp.rx_prom |= RX_MODE_PROM ;
  1106. break ;
  1107. case RX_DISABLE_PROMISC :
  1108. smc->hw.fp.rx_prom &= ~RX_MODE_PROM ;
  1109. break ;
  1110. case RX_ENABLE_NSA :
  1111. smc->hw.fp.nsa_mode = FM_MDAMA ;
  1112. smc->hw.fp.rx_mode = (smc->hw.fp.rx_mode & ~FM_ADDET) |
  1113. smc->hw.fp.nsa_mode ;
  1114. break ;
  1115. case RX_DISABLE_NSA :
  1116. smc->hw.fp.nsa_mode = FM_MRNNSAFNMA ;
  1117. smc->hw.fp.rx_mode = (smc->hw.fp.rx_mode & ~FM_ADDET) |
  1118. smc->hw.fp.nsa_mode ;
  1119. break ;
  1120. }
  1121. if (smc->hw.fp.rx_prom & RX_MODE_PROM) {
  1122. smc->hw.fp.rx_mode = FM_MLIMPROM ;
  1123. }
  1124. else if (smc->hw.fp.rx_prom & RX_MODE_ALL_MULTI) {
  1125. smc->hw.fp.rx_mode = smc->hw.fp.nsa_mode | FM_EXGPA0 ;
  1126. }
  1127. else
  1128. smc->hw.fp.rx_mode = smc->hw.fp.nsa_mode ;
  1129. SETMASK(FM_A(FM_MDREG1),smc->hw.fp.rx_mode,FM_ADDRX) ;
  1130. mac_update_multicast(smc) ;
  1131. }
  1132. /*
  1133. BEGIN_MANUAL_ENTRY(module;tests;3)
  1134. How to test the Restricted Token Monitor
  1135. ----------------------------------------------------------------
  1136. o Insert a break point in the function rtm_irq()
  1137. o Remove all stations with a restricted token monitor from the
  1138. network.
  1139. o Connect a UPPS ISA or EISA station to the network.
  1140. o Give the FORMAC of UPPS station the command to send
  1141. restricted tokens until the ring becomes instable.
  1142. o Now connect your test test client.
  1143. o The restricted token monitor should detect the restricted token,
  1144. and your break point will be reached.
  1145. o You can ovserve how the station will clean the ring.
  1146. END_MANUAL_ENTRY
  1147. */
  1148. void rtm_irq(struct s_smc *smc)
  1149. {
  1150. outpw(ADDR(B2_RTM_CRTL),TIM_CL_IRQ) ; /* clear IRQ */
  1151. if (inpw(ADDR(B2_RTM_CRTL)) & TIM_RES_TOK) {
  1152. outpw(FM_A(FM_CMDREG1),FM_ICL) ; /* force claim */
  1153. DB_RMT("RMT: fddiPATHT_Rmode expired\n",0,0) ;
  1154. AIX_EVENT(smc, (u_long) FDDI_RING_STATUS,
  1155. (u_long) FDDI_SMT_EVENT,
  1156. (u_long) FDDI_RTT, smt_get_event_word(smc));
  1157. }
  1158. outpw(ADDR(B2_RTM_CRTL),TIM_START) ; /* enable RTM monitoring */
  1159. }
  1160. static void rtm_init(struct s_smc *smc)
  1161. {
  1162. outpd(ADDR(B2_RTM_INI),0) ; /* timer = 0 */
  1163. outpw(ADDR(B2_RTM_CRTL),TIM_START) ; /* enable IRQ */
  1164. }
  1165. void rtm_set_timer(struct s_smc *smc)
  1166. {
  1167. /*
  1168. * MIB timer and hardware timer have the same resolution of 80nS
  1169. */
  1170. DB_RMT("RMT: setting new fddiPATHT_Rmode, t = %d ns\n",
  1171. (int) smc->mib.a[PATH0].fddiPATHT_Rmode,0) ;
  1172. outpd(ADDR(B2_RTM_INI),smc->mib.a[PATH0].fddiPATHT_Rmode) ;
  1173. }
  1174. static void smt_split_up_fifo(struct s_smc *smc)
  1175. {
  1176. /*
  1177. BEGIN_MANUAL_ENTRY(module;mem;1)
  1178. -------------------------------------------------------------
  1179. RECEIVE BUFFER MEMORY DIVERSION
  1180. -------------------------------------------------------------
  1181. R1_RxD == SMT_R1_RXD_COUNT
  1182. R2_RxD == SMT_R2_RXD_COUNT
  1183. SMT_R1_RXD_COUNT must be unequal zero
  1184. | R1_RxD R2_RxD |R1_RxD R2_RxD | R1_RxD R2_RxD
  1185. | x 0 | x 1-3 | x < 3
  1186. ----------------------------------------------------------------------
  1187. | 63,75 kB | 54,75 | R1_RxD
  1188. rx queue 1 | RX_FIFO_SPACE | RX_LARGE_FIFO| ------------- * 63,75 kB
  1189. | | | R1_RxD+R2_RxD
  1190. ----------------------------------------------------------------------
  1191. | | 9 kB | R2_RxD
  1192. rx queue 2 | 0 kB | RX_SMALL_FIFO| ------------- * 63,75 kB
  1193. | (not used) | | R1_RxD+R2_RxD
  1194. END_MANUAL_ENTRY
  1195. */
  1196. if (SMT_R1_RXD_COUNT == 0) {
  1197. SMT_PANIC(smc,SMT_E0117, SMT_E0117_MSG) ;
  1198. }
  1199. switch(SMT_R2_RXD_COUNT) {
  1200. case 0:
  1201. smc->hw.fp.fifo.rx1_fifo_size = RX_FIFO_SPACE ;
  1202. smc->hw.fp.fifo.rx2_fifo_size = 0 ;
  1203. break ;
  1204. case 1:
  1205. case 2:
  1206. case 3:
  1207. smc->hw.fp.fifo.rx1_fifo_size = RX_LARGE_FIFO ;
  1208. smc->hw.fp.fifo.rx2_fifo_size = RX_SMALL_FIFO ;
  1209. break ;
  1210. default: /* this is not the real defaule */
  1211. smc->hw.fp.fifo.rx1_fifo_size = RX_FIFO_SPACE *
  1212. SMT_R1_RXD_COUNT/(SMT_R1_RXD_COUNT+SMT_R2_RXD_COUNT) ;
  1213. smc->hw.fp.fifo.rx2_fifo_size = RX_FIFO_SPACE *
  1214. SMT_R2_RXD_COUNT/(SMT_R1_RXD_COUNT+SMT_R2_RXD_COUNT) ;
  1215. break ;
  1216. }
  1217. /*
  1218. BEGIN_MANUAL_ENTRY(module;mem;1)
  1219. -------------------------------------------------------------
  1220. TRANSMIT BUFFER MEMORY DIVERSION
  1221. -------------------------------------------------------------
  1222. | no sync bw | sync bw available and | sync bw available and
  1223. | available | SynchTxMode = SPLIT | SynchTxMode = ALL
  1224. -----------------------------------------------------------------------
  1225. sync tx | 0 kB | 32 kB | 55 kB
  1226. queue | | TX_MEDIUM_FIFO | TX_LARGE_FIFO
  1227. -----------------------------------------------------------------------
  1228. async tx | 64 kB | 32 kB | 9 k
  1229. queue | TX_FIFO_SPACE| TX_MEDIUM_FIFO | TX_SMALL_FIFO
  1230. END_MANUAL_ENTRY
  1231. */
  1232. /*
  1233. * set the tx mode bits
  1234. */
  1235. if (smc->mib.a[PATH0].fddiPATHSbaPayload) {
  1236. #ifdef ESS
  1237. smc->hw.fp.fifo.fifo_config_mode |=
  1238. smc->mib.fddiESSSynchTxMode | SYNC_TRAFFIC_ON ;
  1239. #endif
  1240. }
  1241. else {
  1242. smc->hw.fp.fifo.fifo_config_mode &=
  1243. ~(SEND_ASYNC_AS_SYNC|SYNC_TRAFFIC_ON) ;
  1244. }
  1245. /*
  1246. * split up the FIFO
  1247. */
  1248. if (smc->hw.fp.fifo.fifo_config_mode & SYNC_TRAFFIC_ON) {
  1249. if (smc->hw.fp.fifo.fifo_config_mode & SEND_ASYNC_AS_SYNC) {
  1250. smc->hw.fp.fifo.tx_s_size = TX_LARGE_FIFO ;
  1251. smc->hw.fp.fifo.tx_a0_size = TX_SMALL_FIFO ;
  1252. }
  1253. else {
  1254. smc->hw.fp.fifo.tx_s_size = TX_MEDIUM_FIFO ;
  1255. smc->hw.fp.fifo.tx_a0_size = TX_MEDIUM_FIFO ;
  1256. }
  1257. }
  1258. else {
  1259. smc->hw.fp.fifo.tx_s_size = 0 ;
  1260. smc->hw.fp.fifo.tx_a0_size = TX_FIFO_SPACE ;
  1261. }
  1262. smc->hw.fp.fifo.rx1_fifo_start = smc->hw.fp.fifo.rbc_ram_start +
  1263. RX_FIFO_OFF ;
  1264. smc->hw.fp.fifo.tx_s_start = smc->hw.fp.fifo.rx1_fifo_start +
  1265. smc->hw.fp.fifo.rx1_fifo_size ;
  1266. smc->hw.fp.fifo.tx_a0_start = smc->hw.fp.fifo.tx_s_start +
  1267. smc->hw.fp.fifo.tx_s_size ;
  1268. smc->hw.fp.fifo.rx2_fifo_start = smc->hw.fp.fifo.tx_a0_start +
  1269. smc->hw.fp.fifo.tx_a0_size ;
  1270. DB_SMT("FIFO split: mode = %x\n",smc->hw.fp.fifo.fifo_config_mode,0) ;
  1271. DB_SMT("rbc_ram_start = %x rbc_ram_end = %x\n",
  1272. smc->hw.fp.fifo.rbc_ram_start, smc->hw.fp.fifo.rbc_ram_end) ;
  1273. DB_SMT("rx1_fifo_start = %x tx_s_start = %x\n",
  1274. smc->hw.fp.fifo.rx1_fifo_start, smc->hw.fp.fifo.tx_s_start) ;
  1275. DB_SMT("tx_a0_start = %x rx2_fifo_start = %x\n",
  1276. smc->hw.fp.fifo.tx_a0_start, smc->hw.fp.fifo.rx2_fifo_start) ;
  1277. }
  1278. void formac_reinit_tx(struct s_smc *smc)
  1279. {
  1280. /*
  1281. * Split up the FIFO and reinitialize the MAC if synchronous
  1282. * bandwidth becomes available but no synchronous queue is
  1283. * configured.
  1284. */
  1285. if (!smc->hw.fp.fifo.tx_s_size && smc->mib.a[PATH0].fddiPATHSbaPayload){
  1286. (void)init_mac(smc,0) ;
  1287. }
  1288. }