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