smt.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  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. #include "h/types.h"
  17. #include "h/fddi.h"
  18. #include "h/smc.h"
  19. #include "h/smt_p.h"
  20. #include <linux/bitrev.h>
  21. #define KERNEL
  22. #include "h/smtstate.h"
  23. #ifndef lint
  24. static const char ID_sccs[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
  25. #endif
  26. /*
  27. * FC in SMbuf
  28. */
  29. #define m_fc(mb) ((mb)->sm_data[0])
  30. #define SMT_TID_MAGIC 0x1f0a7b3c
  31. #ifdef DEBUG
  32. static const char *const smt_type_name[] = {
  33. "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
  34. "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
  35. "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
  36. "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
  37. } ;
  38. static const char *const smt_class_name[] = {
  39. "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
  40. "SRF","PMF_GET","PMF_SET","ESF"
  41. } ;
  42. #endif
  43. #define LAST_CLASS (SMT_PMF_SET)
  44. static const struct fddi_addr SMT_Unknown = {
  45. { 0,0,0x1f,0,0,0 }
  46. } ;
  47. /*
  48. * external variables
  49. */
  50. extern const struct fddi_addr fddi_broadcast ;
  51. /*
  52. * external functions
  53. */
  54. int pcm_status_twisted(struct s_smc *smc);
  55. /*
  56. * function prototypes
  57. */
  58. #ifdef LITTLE_ENDIAN
  59. static int smt_swap_short(u_short s);
  60. #endif
  61. static int mac_index(struct s_smc *smc, int mac);
  62. static int phy_index(struct s_smc *smc, int phy);
  63. static int mac_con_resource_index(struct s_smc *smc, int mac);
  64. static int phy_con_resource_index(struct s_smc *smc, int phy);
  65. static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
  66. int local);
  67. static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
  68. int fc, u_long tid, int type, int local);
  69. static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
  70. u_long tid, int type, int len);
  71. static void smt_echo_test(struct s_smc *smc, int dna);
  72. static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
  73. u_long tid, int local);
  74. static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
  75. u_long tid, int local);
  76. #ifdef LITTLE_ENDIAN
  77. static void smt_string_swap(char *data, const char *format, int len);
  78. #endif
  79. static void smt_add_frame_len(SMbuf *mb, int len);
  80. static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
  81. static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde);
  82. static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state);
  83. static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts);
  84. static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy);
  85. static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency);
  86. static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor);
  87. static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path);
  88. static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st);
  89. static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy);
  90. static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers);
  91. static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc);
  92. static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc);
  93. static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc);
  94. static void smt_fill_manufacturer(struct s_smc *smc,
  95. struct smp_p_manufacturer *man);
  96. static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user);
  97. static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount);
  98. static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
  99. int len);
  100. static void smt_clear_una_dna(struct s_smc *smc);
  101. static void smt_clear_old_una_dna(struct s_smc *smc);
  102. #ifdef CONCENTRATOR
  103. static int entity_to_index(void);
  104. #endif
  105. static void update_dac(struct s_smc *smc, int report);
  106. static int div_ratio(u_long upper, u_long lower);
  107. #ifdef USE_CAN_ADDR
  108. static void hwm_conv_can(struct s_smc *smc, char *data, int len);
  109. #else
  110. #define hwm_conv_can(smc,data,len)
  111. #endif
  112. static inline int is_my_addr(const struct s_smc *smc,
  113. const struct fddi_addr *addr)
  114. {
  115. return(*(short *)(&addr->a[0]) ==
  116. *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[0])
  117. && *(short *)(&addr->a[2]) ==
  118. *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[2])
  119. && *(short *)(&addr->a[4]) ==
  120. *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[4])) ;
  121. }
  122. static inline int is_broadcast(const struct fddi_addr *addr)
  123. {
  124. return(*(u_short *)(&addr->a[0]) == 0xffff &&
  125. *(u_short *)(&addr->a[2]) == 0xffff &&
  126. *(u_short *)(&addr->a[4]) == 0xffff ) ;
  127. }
  128. static inline int is_individual(const struct fddi_addr *addr)
  129. {
  130. return(!(addr->a[0] & GROUP_ADDR)) ;
  131. }
  132. static inline int is_equal(const struct fddi_addr *addr1,
  133. const struct fddi_addr *addr2)
  134. {
  135. return(*(u_short *)(&addr1->a[0]) == *(u_short *)(&addr2->a[0]) &&
  136. *(u_short *)(&addr1->a[2]) == *(u_short *)(&addr2->a[2]) &&
  137. *(u_short *)(&addr1->a[4]) == *(u_short *)(&addr2->a[4]) ) ;
  138. }
  139. /*
  140. * list of mandatory paras in frames
  141. */
  142. static const u_short plist_nif[] = { SMT_P_UNA,SMT_P_SDE,SMT_P_STATE,0 } ;
  143. /*
  144. * init SMT agent
  145. */
  146. void smt_agent_init(struct s_smc *smc)
  147. {
  148. int i ;
  149. /*
  150. * get MAC address
  151. */
  152. smc->mib.m[MAC0].fddiMACSMTAddress = smc->hw.fddi_home_addr ;
  153. /*
  154. * get OUI address from driver (bia == built-in-address)
  155. */
  156. smc->mib.fddiSMTStationId.sid_oem[0] = 0 ;
  157. smc->mib.fddiSMTStationId.sid_oem[1] = 0 ;
  158. driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
  159. for (i = 0 ; i < 6 ; i ++) {
  160. smc->mib.fddiSMTStationId.sid_node.a[i] =
  161. bitrev8(smc->mib.fddiSMTStationId.sid_node.a[i]);
  162. }
  163. smc->mib.fddiSMTManufacturerData[0] =
  164. smc->mib.fddiSMTStationId.sid_node.a[0] ;
  165. smc->mib.fddiSMTManufacturerData[1] =
  166. smc->mib.fddiSMTStationId.sid_node.a[1] ;
  167. smc->mib.fddiSMTManufacturerData[2] =
  168. smc->mib.fddiSMTStationId.sid_node.a[2] ;
  169. smc->sm.smt_tid = 0 ;
  170. smc->mib.m[MAC0].fddiMACDupAddressTest = DA_NONE ;
  171. smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
  172. #ifndef SLIM_SMT
  173. smt_clear_una_dna(smc) ;
  174. smt_clear_old_una_dna(smc) ;
  175. #endif
  176. for (i = 0 ; i < SMT_MAX_TEST ; i++)
  177. smc->sm.pend[i] = 0 ;
  178. smc->sm.please_reconnect = 0 ;
  179. smc->sm.uniq_ticks = 0 ;
  180. }
  181. /*
  182. * SMT task
  183. * forever
  184. * delay 30 seconds
  185. * send NIF
  186. * check tvu & tvd
  187. * end
  188. */
  189. void smt_agent_task(struct s_smc *smc)
  190. {
  191. smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
  192. EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
  193. DB_SMT("SMT agent task\n",0,0) ;
  194. }
  195. #ifndef SMT_REAL_TOKEN_CT
  196. void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
  197. {
  198. u_long count;
  199. u_long time;
  200. time = smt_get_time();
  201. count = ((time - smc->sm.last_tok_time[mac_index]) *
  202. 100)/TICKS_PER_SECOND;
  203. /*
  204. * Only when ring is up we will have a token count. The
  205. * flag is unfortunatly a single instance value. This
  206. * doesn't matter now, because we currently have only
  207. * one MAC instance.
  208. */
  209. if (smc->hw.mac_ring_is_up){
  210. smc->mib.m[mac_index].fddiMACToken_Ct += count;
  211. }
  212. /* Remember current time */
  213. smc->sm.last_tok_time[mac_index] = time;
  214. }
  215. #endif
  216. /*ARGSUSED1*/
  217. void smt_event(struct s_smc *smc, int event)
  218. {
  219. u_long time ;
  220. #ifndef SMT_REAL_TOKEN_CT
  221. int i ;
  222. #endif
  223. if (smc->sm.please_reconnect) {
  224. smc->sm.please_reconnect -- ;
  225. if (smc->sm.please_reconnect == 0) {
  226. /* Counted down */
  227. queue_event(smc,EVENT_ECM,EC_CONNECT) ;
  228. }
  229. }
  230. if (event == SM_FAST)
  231. return ;
  232. /*
  233. * timer for periodic cleanup in driver
  234. * reset and start the watchdog (FM2)
  235. * ESS timer
  236. * SBA timer
  237. */
  238. smt_timer_poll(smc) ;
  239. smt_start_watchdog(smc) ;
  240. #ifndef SLIM_SMT
  241. #ifndef BOOT
  242. #ifdef ESS
  243. ess_timer_poll(smc) ;
  244. #endif
  245. #endif
  246. #ifdef SBA
  247. sba_timer_poll(smc) ;
  248. #endif
  249. smt_srf_event(smc,0,0,0) ;
  250. #endif /* no SLIM_SMT */
  251. time = smt_get_time() ;
  252. if (time - smc->sm.smt_last_lem >= TICKS_PER_SECOND*8) {
  253. /*
  254. * Use 8 sec. for the time intervall, it simplifies the
  255. * LER estimation.
  256. */
  257. struct fddi_mib_m *mib ;
  258. u_long upper ;
  259. u_long lower ;
  260. int cond ;
  261. int port;
  262. struct s_phy *phy ;
  263. /*
  264. * calculate LEM bit error rate
  265. */
  266. sm_lem_evaluate(smc) ;
  267. smc->sm.smt_last_lem = time ;
  268. /*
  269. * check conditions
  270. */
  271. #ifndef SLIM_SMT
  272. mac_update_counter(smc) ;
  273. mib = smc->mib.m ;
  274. upper =
  275. (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) +
  276. (mib->fddiMACError_Ct - mib->fddiMACOld_Error_Ct) ;
  277. lower =
  278. (mib->fddiMACFrame_Ct - mib->fddiMACOld_Frame_Ct) +
  279. (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) ;
  280. mib->fddiMACFrameErrorRatio = div_ratio(upper,lower) ;
  281. cond =
  282. ((!mib->fddiMACFrameErrorThreshold &&
  283. mib->fddiMACError_Ct != mib->fddiMACOld_Error_Ct) ||
  284. (mib->fddiMACFrameErrorRatio >
  285. mib->fddiMACFrameErrorThreshold)) ;
  286. if (cond != mib->fddiMACFrameErrorFlag)
  287. smt_srf_event(smc,SMT_COND_MAC_FRAME_ERROR,
  288. INDEX_MAC,cond) ;
  289. upper =
  290. (mib->fddiMACNotCopied_Ct - mib->fddiMACOld_NotCopied_Ct) ;
  291. lower =
  292. upper +
  293. (mib->fddiMACCopied_Ct - mib->fddiMACOld_Copied_Ct) ;
  294. mib->fddiMACNotCopiedRatio = div_ratio(upper,lower) ;
  295. cond =
  296. ((!mib->fddiMACNotCopiedThreshold &&
  297. mib->fddiMACNotCopied_Ct !=
  298. mib->fddiMACOld_NotCopied_Ct)||
  299. (mib->fddiMACNotCopiedRatio >
  300. mib->fddiMACNotCopiedThreshold)) ;
  301. if (cond != mib->fddiMACNotCopiedFlag)
  302. smt_srf_event(smc,SMT_COND_MAC_NOT_COPIED,
  303. INDEX_MAC,cond) ;
  304. /*
  305. * set old values
  306. */
  307. mib->fddiMACOld_Frame_Ct = mib->fddiMACFrame_Ct ;
  308. mib->fddiMACOld_Copied_Ct = mib->fddiMACCopied_Ct ;
  309. mib->fddiMACOld_Error_Ct = mib->fddiMACError_Ct ;
  310. mib->fddiMACOld_Lost_Ct = mib->fddiMACLost_Ct ;
  311. mib->fddiMACOld_NotCopied_Ct = mib->fddiMACNotCopied_Ct ;
  312. /*
  313. * Check port EBError Condition
  314. */
  315. for (port = 0; port < NUMPHYS; port ++) {
  316. phy = &smc->y[port] ;
  317. if (!phy->mib->fddiPORTHardwarePresent) {
  318. continue;
  319. }
  320. cond = (phy->mib->fddiPORTEBError_Ct -
  321. phy->mib->fddiPORTOldEBError_Ct > 5) ;
  322. /* If ratio is more than 5 in 8 seconds
  323. * Set the condition.
  324. */
  325. smt_srf_event(smc,SMT_COND_PORT_EB_ERROR,
  326. (int) (INDEX_PORT+ phy->np) ,cond) ;
  327. /*
  328. * set old values
  329. */
  330. phy->mib->fddiPORTOldEBError_Ct =
  331. phy->mib->fddiPORTEBError_Ct ;
  332. }
  333. #endif /* no SLIM_SMT */
  334. }
  335. #ifndef SLIM_SMT
  336. if (time - smc->sm.smt_last_notify >= (u_long)
  337. (smc->mib.fddiSMTTT_Notify * TICKS_PER_SECOND) ) {
  338. /*
  339. * we can either send an announcement or a request
  340. * a request will trigger a reply so that we can update
  341. * our dna
  342. * note: same tid must be used until reply is received
  343. */
  344. if (!smc->sm.pend[SMT_TID_NIF])
  345. smc->sm.pend[SMT_TID_NIF] = smt_get_tid(smc) ;
  346. smt_send_nif(smc,&fddi_broadcast, FC_SMT_NSA,
  347. smc->sm.pend[SMT_TID_NIF], SMT_REQUEST,0) ;
  348. smc->sm.smt_last_notify = time ;
  349. }
  350. /*
  351. * check timer
  352. */
  353. if (smc->sm.smt_tvu &&
  354. time - smc->sm.smt_tvu > 228*TICKS_PER_SECOND) {
  355. DB_SMT("SMT : UNA expired\n",0,0) ;
  356. smc->sm.smt_tvu = 0 ;
  357. if (!is_equal(&smc->mib.m[MAC0].fddiMACUpstreamNbr,
  358. &SMT_Unknown)){
  359. /* Do not update unknown address */
  360. smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
  361. smc->mib.m[MAC0].fddiMACUpstreamNbr ;
  362. }
  363. smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
  364. smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
  365. /*
  366. * Make sure the fddiMACUNDA_Flag = FALSE is
  367. * included in the SRF so we don't generate
  368. * a separate SRF for the deassertion of this
  369. * condition
  370. */
  371. update_dac(smc,0) ;
  372. smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
  373. INDEX_MAC,0) ;
  374. }
  375. if (smc->sm.smt_tvd &&
  376. time - smc->sm.smt_tvd > 228*TICKS_PER_SECOND) {
  377. DB_SMT("SMT : DNA expired\n",0,0) ;
  378. smc->sm.smt_tvd = 0 ;
  379. if (!is_equal(&smc->mib.m[MAC0].fddiMACDownstreamNbr,
  380. &SMT_Unknown)){
  381. /* Do not update unknown address */
  382. smc->mib.m[MAC0].fddiMACOldDownstreamNbr=
  383. smc->mib.m[MAC0].fddiMACDownstreamNbr ;
  384. }
  385. smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
  386. smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
  387. INDEX_MAC,0) ;
  388. }
  389. #endif /* no SLIM_SMT */
  390. #ifndef SMT_REAL_TOKEN_CT
  391. /*
  392. * Token counter emulation section. If hardware supports the token
  393. * count, the token counter will be updated in mac_update_counter.
  394. */
  395. for (i = MAC0; i < NUMMACS; i++ ){
  396. if (time - smc->sm.last_tok_time[i] > 2*TICKS_PER_SECOND ){
  397. smt_emulate_token_ct( smc, i );
  398. }
  399. }
  400. #endif
  401. smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
  402. EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
  403. }
  404. static int div_ratio(u_long upper, u_long lower)
  405. {
  406. if ((upper<<16L) < upper)
  407. upper = 0xffff0000L ;
  408. else
  409. upper <<= 16L ;
  410. if (!lower)
  411. return(0) ;
  412. return((int)(upper/lower)) ;
  413. }
  414. #ifndef SLIM_SMT
  415. /*
  416. * receive packet handler
  417. */
  418. void smt_received_pack(struct s_smc *smc, SMbuf *mb, int fs)
  419. /* int fs; frame status */
  420. {
  421. struct smt_header *sm ;
  422. int local ;
  423. int illegal = 0 ;
  424. switch (m_fc(mb)) {
  425. case FC_SMT_INFO :
  426. case FC_SMT_LAN_LOC :
  427. case FC_SMT_LOC :
  428. case FC_SMT_NSA :
  429. break ;
  430. default :
  431. smt_free_mbuf(smc,mb) ;
  432. return ;
  433. }
  434. smc->mib.m[MAC0].fddiMACSMTCopied_Ct++ ;
  435. sm = smtod(mb,struct smt_header *) ;
  436. local = ((fs & L_INDICATOR) != 0) ;
  437. hwm_conv_can(smc,(char *)sm,12) ;
  438. /* check destination address */
  439. if (is_individual(&sm->smt_dest) && !is_my_addr(smc,&sm->smt_dest)) {
  440. smt_free_mbuf(smc,mb) ;
  441. return ;
  442. }
  443. #if 0 /* for DUP recognition, do NOT filter them */
  444. /* ignore loop back packets */
  445. if (is_my_addr(smc,&sm->smt_source) && !local) {
  446. smt_free_mbuf(smc,mb) ;
  447. return ;
  448. }
  449. #endif
  450. smt_swap_para(sm,(int) mb->sm_len,1) ;
  451. DB_SMT("SMT : received packet [%s] at 0x%x\n",
  452. smt_type_name[m_fc(mb) & 0xf],sm) ;
  453. DB_SMT("SMT : version %d, class %s\n",sm->smt_version,
  454. smt_class_name[(sm->smt_class>LAST_CLASS)?0 : sm->smt_class]) ;
  455. #ifdef SBA
  456. /*
  457. * check if NSA frame
  458. */
  459. if (m_fc(mb) == FC_SMT_NSA && sm->smt_class == SMT_NIF &&
  460. (sm->smt_type == SMT_ANNOUNCE || sm->smt_type == SMT_REQUEST)) {
  461. smc->sba.sm = sm ;
  462. sba(smc,NIF) ;
  463. }
  464. #endif
  465. /*
  466. * ignore any packet with NSA and A-indicator set
  467. */
  468. if ( (fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) {
  469. DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
  470. addr_to_string(&sm->smt_source),0) ;
  471. smt_free_mbuf(smc,mb) ;
  472. return ;
  473. }
  474. /*
  475. * ignore frames with illegal length
  476. */
  477. if (((sm->smt_class == SMT_ECF) && (sm->smt_len > SMT_MAX_ECHO_LEN)) ||
  478. ((sm->smt_class != SMT_ECF) && (sm->smt_len > SMT_MAX_INFO_LEN))) {
  479. smt_free_mbuf(smc,mb) ;
  480. return ;
  481. }
  482. /*
  483. * check SMT version
  484. */
  485. switch (sm->smt_class) {
  486. case SMT_NIF :
  487. case SMT_SIF_CONFIG :
  488. case SMT_SIF_OPER :
  489. case SMT_ECF :
  490. if (sm->smt_version != SMT_VID)
  491. illegal = 1;
  492. break ;
  493. default :
  494. if (sm->smt_version != SMT_VID_2)
  495. illegal = 1;
  496. break ;
  497. }
  498. if (illegal) {
  499. DB_SMT("SMT : version = %d, dest = %s\n",
  500. sm->smt_version,addr_to_string(&sm->smt_source)) ;
  501. smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_VERSION,local) ;
  502. smt_free_mbuf(smc,mb) ;
  503. return ;
  504. }
  505. if ((sm->smt_len > mb->sm_len - sizeof(struct smt_header)) ||
  506. ((sm->smt_len & 3) && (sm->smt_class != SMT_ECF))) {
  507. DB_SMT("SMT: info length error, len = %d\n",sm->smt_len,0) ;
  508. smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,local) ;
  509. smt_free_mbuf(smc,mb) ;
  510. return ;
  511. }
  512. switch (sm->smt_class) {
  513. case SMT_NIF :
  514. if (smt_check_para(smc,sm,plist_nif)) {
  515. DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
  516. break ;
  517. } ;
  518. switch (sm->smt_type) {
  519. case SMT_ANNOUNCE :
  520. case SMT_REQUEST :
  521. if (!(fs & C_INDICATOR) && m_fc(mb) == FC_SMT_NSA
  522. && is_broadcast(&sm->smt_dest)) {
  523. struct smt_p_state *st ;
  524. /* set my UNA */
  525. if (!is_equal(
  526. &smc->mib.m[MAC0].fddiMACUpstreamNbr,
  527. &sm->smt_source)) {
  528. DB_SMT("SMT : updated my UNA = %s\n",
  529. addr_to_string(&sm->smt_source),0) ;
  530. if (!is_equal(&smc->mib.m[MAC0].
  531. fddiMACUpstreamNbr,&SMT_Unknown)){
  532. /* Do not update unknown address */
  533. smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
  534. smc->mib.m[MAC0].fddiMACUpstreamNbr ;
  535. }
  536. smc->mib.m[MAC0].fddiMACUpstreamNbr =
  537. sm->smt_source ;
  538. smt_srf_event(smc,
  539. SMT_EVENT_MAC_NEIGHBOR_CHANGE,
  540. INDEX_MAC,0) ;
  541. smt_echo_test(smc,0) ;
  542. }
  543. smc->sm.smt_tvu = smt_get_time() ;
  544. st = (struct smt_p_state *)
  545. sm_to_para(smc,sm,SMT_P_STATE) ;
  546. if (st) {
  547. smc->mib.m[MAC0].fddiMACUNDA_Flag =
  548. (st->st_dupl_addr & SMT_ST_MY_DUPA) ?
  549. TRUE : FALSE ;
  550. update_dac(smc,1) ;
  551. }
  552. }
  553. if ((sm->smt_type == SMT_REQUEST) &&
  554. is_individual(&sm->smt_source) &&
  555. ((!(fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) ||
  556. (m_fc(mb) != FC_SMT_NSA))) {
  557. DB_SMT("SMT : replying to NIF request %s\n",
  558. addr_to_string(&sm->smt_source),0) ;
  559. smt_send_nif(smc,&sm->smt_source,
  560. FC_SMT_INFO,
  561. sm->smt_tid,
  562. SMT_REPLY,local) ;
  563. }
  564. break ;
  565. case SMT_REPLY :
  566. DB_SMT("SMT : received NIF response from %s\n",
  567. addr_to_string(&sm->smt_source),0) ;
  568. if (fs & A_INDICATOR) {
  569. smc->sm.pend[SMT_TID_NIF] = 0 ;
  570. DB_SMT("SMT : duplicate address\n",0,0) ;
  571. smc->mib.m[MAC0].fddiMACDupAddressTest =
  572. DA_FAILED ;
  573. smc->r.dup_addr_test = DA_FAILED ;
  574. queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
  575. smc->mib.m[MAC0].fddiMACDA_Flag = TRUE ;
  576. update_dac(smc,1) ;
  577. break ;
  578. }
  579. if (sm->smt_tid == smc->sm.pend[SMT_TID_NIF]) {
  580. smc->sm.pend[SMT_TID_NIF] = 0 ;
  581. /* set my DNA */
  582. if (!is_equal(
  583. &smc->mib.m[MAC0].fddiMACDownstreamNbr,
  584. &sm->smt_source)) {
  585. DB_SMT("SMT : updated my DNA\n",0,0) ;
  586. if (!is_equal(&smc->mib.m[MAC0].
  587. fddiMACDownstreamNbr, &SMT_Unknown)){
  588. /* Do not update unknown address */
  589. smc->mib.m[MAC0].fddiMACOldDownstreamNbr =
  590. smc->mib.m[MAC0].fddiMACDownstreamNbr ;
  591. }
  592. smc->mib.m[MAC0].fddiMACDownstreamNbr =
  593. sm->smt_source ;
  594. smt_srf_event(smc,
  595. SMT_EVENT_MAC_NEIGHBOR_CHANGE,
  596. INDEX_MAC,0) ;
  597. smt_echo_test(smc,1) ;
  598. }
  599. smc->mib.m[MAC0].fddiMACDA_Flag = FALSE ;
  600. update_dac(smc,1) ;
  601. smc->sm.smt_tvd = smt_get_time() ;
  602. smc->mib.m[MAC0].fddiMACDupAddressTest =
  603. DA_PASSED ;
  604. if (smc->r.dup_addr_test != DA_PASSED) {
  605. smc->r.dup_addr_test = DA_PASSED ;
  606. queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
  607. }
  608. }
  609. else if (sm->smt_tid ==
  610. smc->sm.pend[SMT_TID_NIF_TEST]) {
  611. DB_SMT("SMT : NIF test TID ok\n",0,0) ;
  612. }
  613. else {
  614. DB_SMT("SMT : expected TID %lx, got %lx\n",
  615. smc->sm.pend[SMT_TID_NIF],sm->smt_tid) ;
  616. }
  617. break ;
  618. default :
  619. illegal = 2 ;
  620. break ;
  621. }
  622. break ;
  623. case SMT_SIF_CONFIG : /* station information */
  624. if (sm->smt_type != SMT_REQUEST)
  625. break ;
  626. DB_SMT("SMT : replying to SIF Config request from %s\n",
  627. addr_to_string(&sm->smt_source),0) ;
  628. smt_send_sif_config(smc,&sm->smt_source,sm->smt_tid,local) ;
  629. break ;
  630. case SMT_SIF_OPER : /* station information */
  631. if (sm->smt_type != SMT_REQUEST)
  632. break ;
  633. DB_SMT("SMT : replying to SIF Operation request from %s\n",
  634. addr_to_string(&sm->smt_source),0) ;
  635. smt_send_sif_operation(smc,&sm->smt_source,sm->smt_tid,local) ;
  636. break ;
  637. case SMT_ECF : /* echo frame */
  638. switch (sm->smt_type) {
  639. case SMT_REPLY :
  640. smc->mib.priv.fddiPRIVECF_Reply_Rx++ ;
  641. DB_SMT("SMT: received ECF reply from %s\n",
  642. addr_to_string(&sm->smt_source),0) ;
  643. if (sm_to_para(smc,sm,SMT_P_ECHODATA) == 0) {
  644. DB_SMT("SMT: ECHODATA missing\n",0,0) ;
  645. break ;
  646. }
  647. if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF]) {
  648. DB_SMT("SMT : ECF test TID ok\n",0,0) ;
  649. }
  650. else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_UNA]) {
  651. DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
  652. }
  653. else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_DNA]) {
  654. DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
  655. }
  656. else {
  657. DB_SMT("SMT : expected TID %lx, got %lx\n",
  658. smc->sm.pend[SMT_TID_ECF],
  659. sm->smt_tid) ;
  660. }
  661. break ;
  662. case SMT_REQUEST :
  663. smc->mib.priv.fddiPRIVECF_Req_Rx++ ;
  664. {
  665. if (sm->smt_len && !sm_to_para(smc,sm,SMT_P_ECHODATA)) {
  666. DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
  667. smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,
  668. local) ;
  669. break ;
  670. }
  671. DB_SMT("SMT - sending ECF reply to %s\n",
  672. addr_to_string(&sm->smt_source),0) ;
  673. /* set destination addr. & reply */
  674. sm->smt_dest = sm->smt_source ;
  675. sm->smt_type = SMT_REPLY ;
  676. dump_smt(smc,sm,"ECF REPLY") ;
  677. smc->mib.priv.fddiPRIVECF_Reply_Tx++ ;
  678. smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
  679. return ; /* DON'T free mbuf */
  680. }
  681. default :
  682. illegal = 1 ;
  683. break ;
  684. }
  685. break ;
  686. #ifndef BOOT
  687. case SMT_RAF : /* resource allocation */
  688. #ifdef ESS
  689. DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
  690. fs = ess_raf_received_pack(smc,mb,sm,fs) ;
  691. #endif
  692. #ifdef SBA
  693. DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
  694. sba_raf_received_pack(smc,sm,fs) ;
  695. #endif
  696. break ;
  697. case SMT_RDF : /* request denied */
  698. smc->mib.priv.fddiPRIVRDF_Rx++ ;
  699. break ;
  700. case SMT_ESF : /* extended service - not supported */
  701. if (sm->smt_type == SMT_REQUEST) {
  702. DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
  703. smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
  704. }
  705. break ;
  706. case SMT_PMF_GET :
  707. case SMT_PMF_SET :
  708. if (sm->smt_type != SMT_REQUEST)
  709. break ;
  710. /* update statistics */
  711. if (sm->smt_class == SMT_PMF_GET)
  712. smc->mib.priv.fddiPRIVPMF_Get_Rx++ ;
  713. else
  714. smc->mib.priv.fddiPRIVPMF_Set_Rx++ ;
  715. /*
  716. * ignore PMF SET with I/G set
  717. */
  718. if ((sm->smt_class == SMT_PMF_SET) &&
  719. !is_individual(&sm->smt_dest)) {
  720. DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
  721. break ;
  722. }
  723. smt_pmf_received_pack(smc,mb, local) ;
  724. break ;
  725. case SMT_SRF :
  726. dump_smt(smc,sm,"SRF received") ;
  727. break ;
  728. default :
  729. if (sm->smt_type != SMT_REQUEST)
  730. break ;
  731. /*
  732. * For frames with unknown class:
  733. * we need to send a RDF frame according to 8.1.3.1.1,
  734. * only if it is a REQUEST.
  735. */
  736. DB_SMT("SMT : class = %d, send RDF to %s\n",
  737. sm->smt_class, addr_to_string(&sm->smt_source)) ;
  738. smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
  739. break ;
  740. #endif
  741. }
  742. if (illegal) {
  743. DB_SMT("SMT: discarding invalid frame, reason = %d\n",
  744. illegal,0) ;
  745. }
  746. smt_free_mbuf(smc,mb) ;
  747. }
  748. static void update_dac(struct s_smc *smc, int report)
  749. {
  750. int cond ;
  751. cond = ( smc->mib.m[MAC0].fddiMACUNDA_Flag |
  752. smc->mib.m[MAC0].fddiMACDA_Flag) != 0 ;
  753. if (report && (cond != smc->mib.m[MAC0].fddiMACDuplicateAddressCond))
  754. smt_srf_event(smc, SMT_COND_MAC_DUP_ADDR,INDEX_MAC,cond) ;
  755. else
  756. smc->mib.m[MAC0].fddiMACDuplicateAddressCond = cond ;
  757. }
  758. /*
  759. * send SMT frame
  760. * set source address
  761. * set station ID
  762. * send frame
  763. */
  764. void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local)
  765. /* SMbuf *mb; buffer to send */
  766. /* int fc; FC value */
  767. {
  768. struct smt_header *sm ;
  769. if (!smc->r.sm_ma_avail && !local) {
  770. smt_free_mbuf(smc,mb) ;
  771. return ;
  772. }
  773. sm = smtod(mb,struct smt_header *) ;
  774. sm->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
  775. sm->smt_sid = smc->mib.fddiSMTStationId ;
  776. smt_swap_para(sm,(int) mb->sm_len,0) ; /* swap para & header */
  777. hwm_conv_can(smc,(char *)sm,12) ; /* convert SA and DA */
  778. smc->mib.m[MAC0].fddiMACSMTTransmit_Ct++ ;
  779. smt_send_mbuf(smc,mb,local ? FC_SMT_LOC : fc) ;
  780. }
  781. /*
  782. * generate and send RDF
  783. */
  784. static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
  785. int local)
  786. /* SMbuf *rej; mbuf of offending frame */
  787. /* int fc; FC of denied frame */
  788. /* int reason; reason code */
  789. {
  790. SMbuf *mb ;
  791. struct smt_header *sm ; /* header of offending frame */
  792. struct smt_rdf *rdf ;
  793. int len ;
  794. int frame_len ;
  795. sm = smtod(rej,struct smt_header *) ;
  796. if (sm->smt_type != SMT_REQUEST)
  797. return ;
  798. DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
  799. addr_to_string(&sm->smt_source),reason) ;
  800. /*
  801. * note: get framelength from MAC length, NOT from SMT header
  802. * smt header length is included in sm_len
  803. */
  804. frame_len = rej->sm_len ;
  805. if (!(mb=smt_build_frame(smc,SMT_RDF,SMT_REPLY,sizeof(struct smt_rdf))))
  806. return ;
  807. rdf = smtod(mb,struct smt_rdf *) ;
  808. rdf->smt.smt_tid = sm->smt_tid ; /* use TID from sm */
  809. rdf->smt.smt_dest = sm->smt_source ; /* set dest = source */
  810. /* set P12 */
  811. rdf->reason.para.p_type = SMT_P_REASON ;
  812. rdf->reason.para.p_len = sizeof(struct smt_p_reason) - PARA_LEN ;
  813. rdf->reason.rdf_reason = reason ;
  814. /* set P14 */
  815. rdf->version.para.p_type = SMT_P_VERSION ;
  816. rdf->version.para.p_len = sizeof(struct smt_p_version) - PARA_LEN ;
  817. rdf->version.v_pad = 0 ;
  818. rdf->version.v_n = 1 ;
  819. rdf->version.v_index = 1 ;
  820. rdf->version.v_version[0] = SMT_VID_2 ;
  821. rdf->version.v_pad2 = 0 ;
  822. /* set P13 */
  823. if ((unsigned) frame_len <= SMT_MAX_INFO_LEN - sizeof(*rdf) +
  824. 2*sizeof(struct smt_header))
  825. len = frame_len ;
  826. else
  827. len = SMT_MAX_INFO_LEN - sizeof(*rdf) +
  828. 2*sizeof(struct smt_header) ;
  829. /* make length multiple of 4 */
  830. len &= ~3 ;
  831. rdf->refused.para.p_type = SMT_P_REFUSED ;
  832. /* length of para is smt_frame + ref_fc */
  833. rdf->refused.para.p_len = len + 4 ;
  834. rdf->refused.ref_fc = fc ;
  835. /* swap it back */
  836. smt_swap_para(sm,frame_len,0) ;
  837. memcpy((char *) &rdf->refused.ref_header,(char *) sm,len) ;
  838. len -= sizeof(struct smt_header) ;
  839. mb->sm_len += len ;
  840. rdf->smt.smt_len += len ;
  841. dump_smt(smc,(struct smt_header *)rdf,"RDF") ;
  842. smc->mib.priv.fddiPRIVRDF_Tx++ ;
  843. smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
  844. }
  845. /*
  846. * generate and send NIF
  847. */
  848. static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
  849. int fc, u_long tid, int type, int local)
  850. /* struct fddi_addr *dest; dest address */
  851. /* int fc; frame control */
  852. /* u_long tid; transaction id */
  853. /* int type; frame type */
  854. {
  855. struct smt_nif *nif ;
  856. SMbuf *mb ;
  857. if (!(mb = smt_build_frame(smc,SMT_NIF,type,sizeof(struct smt_nif))))
  858. return ;
  859. nif = smtod(mb, struct smt_nif *) ;
  860. smt_fill_una(smc,&nif->una) ; /* set UNA */
  861. smt_fill_sde(smc,&nif->sde) ; /* set station descriptor */
  862. smt_fill_state(smc,&nif->state) ; /* set state information */
  863. #ifdef SMT6_10
  864. smt_fill_fsc(smc,&nif->fsc) ; /* set frame status cap. */
  865. #endif
  866. nif->smt.smt_dest = *dest ; /* destination address */
  867. nif->smt.smt_tid = tid ; /* transaction ID */
  868. dump_smt(smc,(struct smt_header *)nif,"NIF") ;
  869. smt_send_frame(smc,mb,fc,local) ;
  870. }
  871. #ifdef DEBUG
  872. /*
  873. * send NIF request (test purpose)
  874. */
  875. static void smt_send_nif_request(struct s_smc *smc, struct fddi_addr *dest)
  876. {
  877. smc->sm.pend[SMT_TID_NIF_TEST] = smt_get_tid(smc) ;
  878. smt_send_nif(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_NIF_TEST],
  879. SMT_REQUEST,0) ;
  880. }
  881. /*
  882. * send ECF request (test purpose)
  883. */
  884. static void smt_send_ecf_request(struct s_smc *smc, struct fddi_addr *dest,
  885. int len)
  886. {
  887. smc->sm.pend[SMT_TID_ECF] = smt_get_tid(smc) ;
  888. smt_send_ecf(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_ECF],
  889. SMT_REQUEST,len) ;
  890. }
  891. #endif
  892. /*
  893. * echo test
  894. */
  895. static void smt_echo_test(struct s_smc *smc, int dna)
  896. {
  897. u_long tid ;
  898. smc->sm.pend[dna ? SMT_TID_ECF_DNA : SMT_TID_ECF_UNA] =
  899. tid = smt_get_tid(smc) ;
  900. smt_send_ecf(smc, dna ?
  901. &smc->mib.m[MAC0].fddiMACDownstreamNbr :
  902. &smc->mib.m[MAC0].fddiMACUpstreamNbr,
  903. FC_SMT_INFO,tid, SMT_REQUEST, (SMT_TEST_ECHO_LEN & ~3)-8) ;
  904. }
  905. /*
  906. * generate and send ECF
  907. */
  908. static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
  909. u_long tid, int type, int len)
  910. /* struct fddi_addr *dest; dest address */
  911. /* int fc; frame control */
  912. /* u_long tid; transaction id */
  913. /* int type; frame type */
  914. /* int len; frame length */
  915. {
  916. struct smt_ecf *ecf ;
  917. SMbuf *mb ;
  918. if (!(mb = smt_build_frame(smc,SMT_ECF,type,SMT_ECF_LEN + len)))
  919. return ;
  920. ecf = smtod(mb, struct smt_ecf *) ;
  921. smt_fill_echo(smc,&ecf->ec_echo,tid,len) ; /* set ECHO */
  922. ecf->smt.smt_dest = *dest ; /* destination address */
  923. ecf->smt.smt_tid = tid ; /* transaction ID */
  924. smc->mib.priv.fddiPRIVECF_Req_Tx++ ;
  925. smt_send_frame(smc,mb,fc,0) ;
  926. }
  927. /*
  928. * generate and send SIF config response
  929. */
  930. static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
  931. u_long tid, int local)
  932. /* struct fddi_addr *dest; dest address */
  933. /* u_long tid; transaction id */
  934. {
  935. struct smt_sif_config *sif ;
  936. SMbuf *mb ;
  937. int len ;
  938. if (!(mb = smt_build_frame(smc,SMT_SIF_CONFIG,SMT_REPLY,
  939. SIZEOF_SMT_SIF_CONFIG)))
  940. return ;
  941. sif = smtod(mb, struct smt_sif_config *) ;
  942. smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
  943. smt_fill_sde(smc,&sif->sde) ; /* set station descriptor */
  944. smt_fill_version(smc,&sif->version) ; /* set version information */
  945. smt_fill_state(smc,&sif->state) ; /* set state information */
  946. smt_fill_policy(smc,&sif->policy) ; /* set station policy */
  947. smt_fill_latency(smc,&sif->latency); /* set station latency */
  948. smt_fill_neighbor(smc,&sif->neighbor); /* set station neighbor */
  949. smt_fill_setcount(smc,&sif->setcount) ; /* set count */
  950. len = smt_fill_path(smc,&sif->path); /* set station path descriptor*/
  951. sif->smt.smt_dest = *dest ; /* destination address */
  952. sif->smt.smt_tid = tid ; /* transaction ID */
  953. smt_add_frame_len(mb,len) ; /* adjust length fields */
  954. dump_smt(smc,(struct smt_header *)sif,"SIF Configuration Reply") ;
  955. smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
  956. }
  957. /*
  958. * generate and send SIF operation response
  959. */
  960. static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
  961. u_long tid, int local)
  962. /* struct fddi_addr *dest; dest address */
  963. /* u_long tid; transaction id */
  964. {
  965. struct smt_sif_operation *sif ;
  966. SMbuf *mb ;
  967. int ports ;
  968. int i ;
  969. ports = NUMPHYS ;
  970. #ifndef CONCENTRATOR
  971. if (smc->s.sas == SMT_SAS)
  972. ports = 1 ;
  973. #endif
  974. if (!(mb = smt_build_frame(smc,SMT_SIF_OPER,SMT_REPLY,
  975. SIZEOF_SMT_SIF_OPERATION+ports*sizeof(struct smt_p_lem))))
  976. return ;
  977. sif = smtod(mb, struct smt_sif_operation *) ;
  978. smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
  979. smt_fill_mac_status(smc,&sif->status) ; /* set mac status */
  980. smt_fill_mac_counter(smc,&sif->mc) ; /* set mac counter field */
  981. smt_fill_mac_fnc(smc,&sif->fnc) ; /* set frame not copied counter */
  982. smt_fill_manufacturer(smc,&sif->man) ; /* set manufacturer field */
  983. smt_fill_user(smc,&sif->user) ; /* set user field */
  984. smt_fill_setcount(smc,&sif->setcount) ; /* set count */
  985. /*
  986. * set link error mon information
  987. */
  988. if (ports == 1) {
  989. smt_fill_lem(smc,sif->lem,PS) ;
  990. }
  991. else {
  992. for (i = 0 ; i < ports ; i++) {
  993. smt_fill_lem(smc,&sif->lem[i],i) ;
  994. }
  995. }
  996. sif->smt.smt_dest = *dest ; /* destination address */
  997. sif->smt.smt_tid = tid ; /* transaction ID */
  998. dump_smt(smc,(struct smt_header *)sif,"SIF Operation Reply") ;
  999. smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
  1000. }
  1001. /*
  1002. * get and initialize SMT frame
  1003. */
  1004. SMbuf *smt_build_frame(struct s_smc *smc, int class, int type,
  1005. int length)
  1006. {
  1007. SMbuf *mb ;
  1008. struct smt_header *smt ;
  1009. #if 0
  1010. if (!smc->r.sm_ma_avail) {
  1011. return(0) ;
  1012. }
  1013. #endif
  1014. if (!(mb = smt_get_mbuf(smc)))
  1015. return(mb) ;
  1016. mb->sm_len = length ;
  1017. smt = smtod(mb, struct smt_header *) ;
  1018. smt->smt_dest = fddi_broadcast ; /* set dest = broadcast */
  1019. smt->smt_class = class ;
  1020. smt->smt_type = type ;
  1021. switch (class) {
  1022. case SMT_NIF :
  1023. case SMT_SIF_CONFIG :
  1024. case SMT_SIF_OPER :
  1025. case SMT_ECF :
  1026. smt->smt_version = SMT_VID ;
  1027. break ;
  1028. default :
  1029. smt->smt_version = SMT_VID_2 ;
  1030. break ;
  1031. }
  1032. smt->smt_tid = smt_get_tid(smc) ; /* set transaction ID */
  1033. smt->smt_pad = 0 ;
  1034. smt->smt_len = length - sizeof(struct smt_header) ;
  1035. return(mb) ;
  1036. }
  1037. static void smt_add_frame_len(SMbuf *mb, int len)
  1038. {
  1039. struct smt_header *smt ;
  1040. smt = smtod(mb, struct smt_header *) ;
  1041. smt->smt_len += len ;
  1042. mb->sm_len += len ;
  1043. }
  1044. /*
  1045. * fill values in UNA parameter
  1046. */
  1047. static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una)
  1048. {
  1049. SMTSETPARA(una,SMT_P_UNA) ;
  1050. una->una_pad = 0 ;
  1051. una->una_node = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
  1052. }
  1053. /*
  1054. * fill values in SDE parameter
  1055. */
  1056. static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde)
  1057. {
  1058. SMTSETPARA(sde,SMT_P_SDE) ;
  1059. sde->sde_non_master = smc->mib.fddiSMTNonMaster_Ct ;
  1060. sde->sde_master = smc->mib.fddiSMTMaster_Ct ;
  1061. sde->sde_mac_count = NUMMACS ; /* only 1 MAC */
  1062. #ifdef CONCENTRATOR
  1063. sde->sde_type = SMT_SDE_CONCENTRATOR ;
  1064. #else
  1065. sde->sde_type = SMT_SDE_STATION ;
  1066. #endif
  1067. }
  1068. /*
  1069. * fill in values in station state parameter
  1070. */
  1071. static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state)
  1072. {
  1073. int top ;
  1074. int twist ;
  1075. SMTSETPARA(state,SMT_P_STATE) ;
  1076. state->st_pad = 0 ;
  1077. /* determine topology */
  1078. top = 0 ;
  1079. if (smc->mib.fddiSMTPeerWrapFlag) {
  1080. top |= SMT_ST_WRAPPED ; /* state wrapped */
  1081. }
  1082. #ifdef CONCENTRATOR
  1083. if (cfm_status_unattached(smc)) {
  1084. top |= SMT_ST_UNATTACHED ; /* unattached concentrator */
  1085. }
  1086. #endif
  1087. if ((twist = pcm_status_twisted(smc)) & 1) {
  1088. top |= SMT_ST_TWISTED_A ; /* twisted cable */
  1089. }
  1090. if (twist & 2) {
  1091. top |= SMT_ST_TWISTED_B ; /* twisted cable */
  1092. }
  1093. #ifdef OPT_SRF
  1094. top |= SMT_ST_SRF ;
  1095. #endif
  1096. if (pcm_rooted_station(smc))
  1097. top |= SMT_ST_ROOTED_S ;
  1098. if (smc->mib.a[0].fddiPATHSbaPayload != 0)
  1099. top |= SMT_ST_SYNC_SERVICE ;
  1100. state->st_topology = top ;
  1101. state->st_dupl_addr =
  1102. ((smc->mib.m[MAC0].fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0 ) |
  1103. (smc->mib.m[MAC0].fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0)) ;
  1104. }
  1105. /*
  1106. * fill values in timestamp parameter
  1107. */
  1108. static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts)
  1109. {
  1110. SMTSETPARA(ts,SMT_P_TIMESTAMP) ;
  1111. smt_set_timestamp(smc,ts->ts_time) ;
  1112. }
  1113. void smt_set_timestamp(struct s_smc *smc, u_char *p)
  1114. {
  1115. u_long time ;
  1116. u_long utime ;
  1117. /*
  1118. * timestamp is 64 bits long ; resolution is 80 nS
  1119. * our clock resolution is 10mS
  1120. * 10mS/80ns = 125000 ~ 2^17 = 131072
  1121. */
  1122. utime = smt_get_time() ;
  1123. time = utime * 100 ;
  1124. time /= TICKS_PER_SECOND ;
  1125. p[0] = 0 ;
  1126. p[1] = (u_char)((time>>(8+8+8+8-1)) & 1) ;
  1127. p[2] = (u_char)(time>>(8+8+8-1)) ;
  1128. p[3] = (u_char)(time>>(8+8-1)) ;
  1129. p[4] = (u_char)(time>>(8-1)) ;
  1130. p[5] = (u_char)(time<<1) ;
  1131. p[6] = (u_char)(smc->sm.uniq_ticks>>8) ;
  1132. p[7] = (u_char)smc->sm.uniq_ticks ;
  1133. /*
  1134. * make sure we don't wrap: restart whenever the upper digits change
  1135. */
  1136. if (utime != smc->sm.uniq_time) {
  1137. smc->sm.uniq_ticks = 0 ;
  1138. }
  1139. smc->sm.uniq_ticks++ ;
  1140. smc->sm.uniq_time = utime ;
  1141. }
  1142. /*
  1143. * fill values in station policy parameter
  1144. */
  1145. static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy)
  1146. {
  1147. int i ;
  1148. u_char *map ;
  1149. u_short in ;
  1150. u_short out ;
  1151. /*
  1152. * MIB para 101b (fddiSMTConnectionPolicy) coding
  1153. * is different from 0005 coding
  1154. */
  1155. static u_char ansi_weirdness[16] = {
  1156. 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
  1157. } ;
  1158. SMTSETPARA(policy,SMT_P_POLICY) ;
  1159. out = 0 ;
  1160. in = smc->mib.fddiSMTConnectionPolicy ;
  1161. for (i = 0, map = ansi_weirdness ; i < 16 ; i++) {
  1162. if (in & 1)
  1163. out |= (1<<*map) ;
  1164. in >>= 1 ;
  1165. map++ ;
  1166. }
  1167. policy->pl_config = smc->mib.fddiSMTConfigPolicy ;
  1168. policy->pl_connect = out ;
  1169. }
  1170. /*
  1171. * fill values in latency equivalent parameter
  1172. */
  1173. static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency)
  1174. {
  1175. SMTSETPARA(latency,SMT_P_LATENCY) ;
  1176. latency->lt_phyout_idx1 = phy_index(smc,0) ;
  1177. latency->lt_latency1 = 10 ; /* in octets (byte clock) */
  1178. /*
  1179. * note: latency has two phy entries by definition
  1180. * for a SAS, the 2nd one is null
  1181. */
  1182. if (smc->s.sas == SMT_DAS) {
  1183. latency->lt_phyout_idx2 = phy_index(smc,1) ;
  1184. latency->lt_latency2 = 10 ; /* in octets (byte clock) */
  1185. }
  1186. else {
  1187. latency->lt_phyout_idx2 = 0 ;
  1188. latency->lt_latency2 = 0 ;
  1189. }
  1190. }
  1191. /*
  1192. * fill values in MAC neighbors parameter
  1193. */
  1194. static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor)
  1195. {
  1196. SMTSETPARA(neighbor,SMT_P_NEIGHBORS) ;
  1197. neighbor->nb_mib_index = INDEX_MAC ;
  1198. neighbor->nb_mac_index = mac_index(smc,1) ;
  1199. neighbor->nb_una = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
  1200. neighbor->nb_dna = smc->mib.m[MAC0].fddiMACDownstreamNbr ;
  1201. }
  1202. /*
  1203. * fill values in path descriptor
  1204. */
  1205. #ifdef CONCENTRATOR
  1206. #define ALLPHYS NUMPHYS
  1207. #else
  1208. #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
  1209. #endif
  1210. static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path)
  1211. {
  1212. SK_LOC_DECL(int,type) ;
  1213. SK_LOC_DECL(int,state) ;
  1214. SK_LOC_DECL(int,remote) ;
  1215. SK_LOC_DECL(int,mac) ;
  1216. int len ;
  1217. int p ;
  1218. int physp ;
  1219. struct smt_phy_rec *phy ;
  1220. struct smt_mac_rec *pd_mac ;
  1221. len = PARA_LEN +
  1222. sizeof(struct smt_mac_rec) * NUMMACS +
  1223. sizeof(struct smt_phy_rec) * ALLPHYS ;
  1224. path->para.p_type = SMT_P_PATH ;
  1225. path->para.p_len = len - PARA_LEN ;
  1226. /* PHYs */
  1227. for (p = 0,phy = path->pd_phy ; p < ALLPHYS ; p++, phy++) {
  1228. physp = p ;
  1229. #ifndef CONCENTRATOR
  1230. if (smc->s.sas == SMT_SAS)
  1231. physp = PS ;
  1232. #endif
  1233. pcm_status_state(smc,physp,&type,&state,&remote,&mac) ;
  1234. #ifdef LITTLE_ENDIAN
  1235. phy->phy_mib_index = smt_swap_short((u_short)p+INDEX_PORT) ;
  1236. #else
  1237. phy->phy_mib_index = p+INDEX_PORT ;
  1238. #endif
  1239. phy->phy_type = type ;
  1240. phy->phy_connect_state = state ;
  1241. phy->phy_remote_type = remote ;
  1242. phy->phy_remote_mac = mac ;
  1243. phy->phy_resource_idx = phy_con_resource_index(smc,p) ;
  1244. }
  1245. /* MAC */
  1246. pd_mac = (struct smt_mac_rec *) phy ;
  1247. pd_mac->mac_addr = smc->mib.m[MAC0].fddiMACSMTAddress ;
  1248. pd_mac->mac_resource_idx = mac_con_resource_index(smc,1) ;
  1249. return(len) ;
  1250. }
  1251. /*
  1252. * fill values in mac status
  1253. */
  1254. static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st)
  1255. {
  1256. SMTSETPARA(st,SMT_P_MAC_STATUS) ;
  1257. st->st_mib_index = INDEX_MAC ;
  1258. st->st_mac_index = mac_index(smc,1) ;
  1259. mac_update_counter(smc) ;
  1260. /*
  1261. * timer values are represented in SMT as 2's complement numbers
  1262. * units : internal : 2's complement BCLK
  1263. */
  1264. st->st_t_req = smc->mib.m[MAC0].fddiMACT_Req ;
  1265. st->st_t_neg = smc->mib.m[MAC0].fddiMACT_Neg ;
  1266. st->st_t_max = smc->mib.m[MAC0].fddiMACT_Max ;
  1267. st->st_tvx_value = smc->mib.m[MAC0].fddiMACTvxValue ;
  1268. st->st_t_min = smc->mib.m[MAC0].fddiMACT_Min ;
  1269. st->st_sba = smc->mib.a[PATH0].fddiPATHSbaPayload ;
  1270. st->st_frame_ct = smc->mib.m[MAC0].fddiMACFrame_Ct ;
  1271. st->st_error_ct = smc->mib.m[MAC0].fddiMACError_Ct ;
  1272. st->st_lost_ct = smc->mib.m[MAC0].fddiMACLost_Ct ;
  1273. }
  1274. /*
  1275. * fill values in LEM status
  1276. */
  1277. static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy)
  1278. {
  1279. struct fddi_mib_p *mib ;
  1280. mib = smc->y[phy].mib ;
  1281. SMTSETPARA(lem,SMT_P_LEM) ;
  1282. lem->lem_mib_index = phy+INDEX_PORT ;
  1283. lem->lem_phy_index = phy_index(smc,phy) ;
  1284. lem->lem_pad2 = 0 ;
  1285. lem->lem_cutoff = mib->fddiPORTLer_Cutoff ;
  1286. lem->lem_alarm = mib->fddiPORTLer_Alarm ;
  1287. /* long term bit error rate */
  1288. lem->lem_estimate = mib->fddiPORTLer_Estimate ;
  1289. /* # of rejected connections */
  1290. lem->lem_reject_ct = mib->fddiPORTLem_Reject_Ct ;
  1291. lem->lem_ct = mib->fddiPORTLem_Ct ; /* total number of errors */
  1292. }
  1293. /*
  1294. * fill version parameter
  1295. */
  1296. static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers)
  1297. {
  1298. SK_UNUSED(smc) ;
  1299. SMTSETPARA(vers,SMT_P_VERSION) ;
  1300. vers->v_pad = 0 ;
  1301. vers->v_n = 1 ; /* one version is enough .. */
  1302. vers->v_index = 1 ;
  1303. vers->v_version[0] = SMT_VID_2 ;
  1304. vers->v_pad2 = 0 ;
  1305. }
  1306. #ifdef SMT6_10
  1307. /*
  1308. * fill frame status capabilities
  1309. */
  1310. /*
  1311. * note: this para 200B is NOT in swap table, because it's also set in
  1312. * PMF add_para
  1313. */
  1314. static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc)
  1315. {
  1316. SK_UNUSED(smc) ;
  1317. SMTSETPARA(fsc,SMT_P_FSC) ;
  1318. fsc->fsc_pad0 = 0 ;
  1319. fsc->fsc_mac_index = INDEX_MAC ; /* this is MIB ; MIB is NOT
  1320. * mac_index ()i !
  1321. */
  1322. fsc->fsc_pad1 = 0 ;
  1323. fsc->fsc_value = FSC_TYPE0 ; /* "normal" node */
  1324. #ifdef LITTLE_ENDIAN
  1325. fsc->fsc_mac_index = smt_swap_short(INDEX_MAC) ;
  1326. fsc->fsc_value = smt_swap_short(FSC_TYPE0) ;
  1327. #endif
  1328. }
  1329. #endif
  1330. /*
  1331. * fill mac counter field
  1332. */
  1333. static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc)
  1334. {
  1335. SMTSETPARA(mc,SMT_P_MAC_COUNTER) ;
  1336. mc->mc_mib_index = INDEX_MAC ;
  1337. mc->mc_index = mac_index(smc,1) ;
  1338. mc->mc_receive_ct = smc->mib.m[MAC0].fddiMACCopied_Ct ;
  1339. mc->mc_transmit_ct = smc->mib.m[MAC0].fddiMACTransmit_Ct ;
  1340. }
  1341. /*
  1342. * fill mac frame not copied counter
  1343. */
  1344. static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc)
  1345. {
  1346. SMTSETPARA(fnc,SMT_P_MAC_FNC) ;
  1347. fnc->nc_mib_index = INDEX_MAC ;
  1348. fnc->nc_index = mac_index(smc,1) ;
  1349. fnc->nc_counter = smc->mib.m[MAC0].fddiMACNotCopied_Ct ;
  1350. }
  1351. /*
  1352. * fill manufacturer field
  1353. */
  1354. static void smt_fill_manufacturer(struct s_smc *smc,
  1355. struct smp_p_manufacturer *man)
  1356. {
  1357. SMTSETPARA(man,SMT_P_MANUFACTURER) ;
  1358. memcpy((char *) man->mf_data,
  1359. (char *) smc->mib.fddiSMTManufacturerData,
  1360. sizeof(man->mf_data)) ;
  1361. }
  1362. /*
  1363. * fill user field
  1364. */
  1365. static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user)
  1366. {
  1367. SMTSETPARA(user,SMT_P_USER) ;
  1368. memcpy((char *) user->us_data,
  1369. (char *) smc->mib.fddiSMTUserData,
  1370. sizeof(user->us_data)) ;
  1371. }
  1372. /*
  1373. * fill set count
  1374. */
  1375. static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount)
  1376. {
  1377. SK_UNUSED(smc) ;
  1378. SMTSETPARA(setcount,SMT_P_SETCOUNT) ;
  1379. setcount->count = smc->mib.fddiSMTSetCount.count ;
  1380. memcpy((char *)setcount->timestamp,
  1381. (char *)smc->mib.fddiSMTSetCount.timestamp,8) ;
  1382. }
  1383. /*
  1384. * fill echo data
  1385. */
  1386. static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
  1387. int len)
  1388. {
  1389. u_char *p ;
  1390. SK_UNUSED(smc) ;
  1391. SMTSETPARA(echo,SMT_P_ECHODATA) ;
  1392. echo->para.p_len = len ;
  1393. for (p = echo->ec_data ; len ; len--) {
  1394. *p++ = (u_char) seed ;
  1395. seed += 13 ;
  1396. }
  1397. }
  1398. /*
  1399. * clear DNA and UNA
  1400. * called from CFM if configuration changes
  1401. */
  1402. static void smt_clear_una_dna(struct s_smc *smc)
  1403. {
  1404. smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
  1405. smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
  1406. }
  1407. static void smt_clear_old_una_dna(struct s_smc *smc)
  1408. {
  1409. smc->mib.m[MAC0].fddiMACOldUpstreamNbr = SMT_Unknown ;
  1410. smc->mib.m[MAC0].fddiMACOldDownstreamNbr = SMT_Unknown ;
  1411. }
  1412. u_long smt_get_tid(struct s_smc *smc)
  1413. {
  1414. u_long tid ;
  1415. while ((tid = ++(smc->sm.smt_tid) ^ SMT_TID_MAGIC) == 0)
  1416. ;
  1417. return(tid & 0x3fffffffL) ;
  1418. }
  1419. /*
  1420. * table of parameter lengths
  1421. */
  1422. static const struct smt_pdef {
  1423. int ptype ;
  1424. int plen ;
  1425. const char *pswap ;
  1426. } smt_pdef[] = {
  1427. { SMT_P_UNA, sizeof(struct smt_p_una) ,
  1428. SWAP_SMT_P_UNA } ,
  1429. { SMT_P_SDE, sizeof(struct smt_p_sde) ,
  1430. SWAP_SMT_P_SDE } ,
  1431. { SMT_P_STATE, sizeof(struct smt_p_state) ,
  1432. SWAP_SMT_P_STATE } ,
  1433. { SMT_P_TIMESTAMP,sizeof(struct smt_p_timestamp) ,
  1434. SWAP_SMT_P_TIMESTAMP } ,
  1435. { SMT_P_POLICY, sizeof(struct smt_p_policy) ,
  1436. SWAP_SMT_P_POLICY } ,
  1437. { SMT_P_LATENCY, sizeof(struct smt_p_latency) ,
  1438. SWAP_SMT_P_LATENCY } ,
  1439. { SMT_P_NEIGHBORS,sizeof(struct smt_p_neighbor) ,
  1440. SWAP_SMT_P_NEIGHBORS } ,
  1441. { SMT_P_PATH, sizeof(struct smt_p_path) ,
  1442. SWAP_SMT_P_PATH } ,
  1443. { SMT_P_MAC_STATUS,sizeof(struct smt_p_mac_status) ,
  1444. SWAP_SMT_P_MAC_STATUS } ,
  1445. { SMT_P_LEM, sizeof(struct smt_p_lem) ,
  1446. SWAP_SMT_P_LEM } ,
  1447. { SMT_P_MAC_COUNTER,sizeof(struct smt_p_mac_counter) ,
  1448. SWAP_SMT_P_MAC_COUNTER } ,
  1449. { SMT_P_MAC_FNC,sizeof(struct smt_p_mac_fnc) ,
  1450. SWAP_SMT_P_MAC_FNC } ,
  1451. { SMT_P_PRIORITY,sizeof(struct smt_p_priority) ,
  1452. SWAP_SMT_P_PRIORITY } ,
  1453. { SMT_P_EB,sizeof(struct smt_p_eb) ,
  1454. SWAP_SMT_P_EB } ,
  1455. { SMT_P_MANUFACTURER,sizeof(struct smp_p_manufacturer) ,
  1456. SWAP_SMT_P_MANUFACTURER } ,
  1457. { SMT_P_REASON, sizeof(struct smt_p_reason) ,
  1458. SWAP_SMT_P_REASON } ,
  1459. { SMT_P_REFUSED, sizeof(struct smt_p_refused) ,
  1460. SWAP_SMT_P_REFUSED } ,
  1461. { SMT_P_VERSION, sizeof(struct smt_p_version) ,
  1462. SWAP_SMT_P_VERSION } ,
  1463. #ifdef ESS
  1464. { SMT_P0015, sizeof(struct smt_p_0015) , SWAP_SMT_P0015 } ,
  1465. { SMT_P0016, sizeof(struct smt_p_0016) , SWAP_SMT_P0016 } ,
  1466. { SMT_P0017, sizeof(struct smt_p_0017) , SWAP_SMT_P0017 } ,
  1467. { SMT_P0018, sizeof(struct smt_p_0018) , SWAP_SMT_P0018 } ,
  1468. { SMT_P0019, sizeof(struct smt_p_0019) , SWAP_SMT_P0019 } ,
  1469. { SMT_P001A, sizeof(struct smt_p_001a) , SWAP_SMT_P001A } ,
  1470. { SMT_P001B, sizeof(struct smt_p_001b) , SWAP_SMT_P001B } ,
  1471. { SMT_P001C, sizeof(struct smt_p_001c) , SWAP_SMT_P001C } ,
  1472. { SMT_P001D, sizeof(struct smt_p_001d) , SWAP_SMT_P001D } ,
  1473. #endif
  1474. #if 0
  1475. { SMT_P_FSC, sizeof(struct smt_p_fsc) ,
  1476. SWAP_SMT_P_FSC } ,
  1477. #endif
  1478. { SMT_P_SETCOUNT,0, SWAP_SMT_P_SETCOUNT } ,
  1479. { SMT_P1048, 0, SWAP_SMT_P1048 } ,
  1480. { SMT_P208C, 0, SWAP_SMT_P208C } ,
  1481. { SMT_P208D, 0, SWAP_SMT_P208D } ,
  1482. { SMT_P208E, 0, SWAP_SMT_P208E } ,
  1483. { SMT_P208F, 0, SWAP_SMT_P208F } ,
  1484. { SMT_P2090, 0, SWAP_SMT_P2090 } ,
  1485. #ifdef ESS
  1486. { SMT_P320B, sizeof(struct smt_p_320b) , SWAP_SMT_P320B } ,
  1487. { SMT_P320F, sizeof(struct smt_p_320f) , SWAP_SMT_P320F } ,
  1488. { SMT_P3210, sizeof(struct smt_p_3210) , SWAP_SMT_P3210 } ,
  1489. #endif
  1490. { SMT_P4050, 0, SWAP_SMT_P4050 } ,
  1491. { SMT_P4051, 0, SWAP_SMT_P4051 } ,
  1492. { SMT_P4052, 0, SWAP_SMT_P4052 } ,
  1493. { SMT_P4053, 0, SWAP_SMT_P4053 } ,
  1494. } ;
  1495. #define N_SMT_PLEN (sizeof(smt_pdef)/sizeof(smt_pdef[0]))
  1496. int smt_check_para(struct s_smc *smc, struct smt_header *sm,
  1497. const u_short list[])
  1498. {
  1499. const u_short *p = list ;
  1500. while (*p) {
  1501. if (!sm_to_para(smc,sm,(int) *p)) {
  1502. DB_SMT("SMT: smt_check_para - missing para %x\n",*p,0);
  1503. return(-1) ;
  1504. }
  1505. p++ ;
  1506. }
  1507. return(0) ;
  1508. }
  1509. void *sm_to_para(struct s_smc *smc, struct smt_header *sm, int para)
  1510. {
  1511. char *p ;
  1512. int len ;
  1513. int plen ;
  1514. void *found = NULL;
  1515. SK_UNUSED(smc) ;
  1516. len = sm->smt_len ;
  1517. p = (char *)(sm+1) ; /* pointer to info */
  1518. while (len > 0 ) {
  1519. if (((struct smt_para *)p)->p_type == para)
  1520. found = (void *) p ;
  1521. plen = ((struct smt_para *)p)->p_len + PARA_LEN ;
  1522. p += plen ;
  1523. len -= plen ;
  1524. if (len < 0) {
  1525. DB_SMT("SMT : sm_to_para - length error %d\n",plen,0) ;
  1526. return NULL;
  1527. }
  1528. if ((plen & 3) && (para != SMT_P_ECHODATA)) {
  1529. DB_SMT("SMT : sm_to_para - odd length %d\n",plen,0) ;
  1530. return NULL;
  1531. }
  1532. if (found)
  1533. return(found) ;
  1534. }
  1535. return NULL;
  1536. }
  1537. #if 0
  1538. /*
  1539. * send ANTC data test frame
  1540. */
  1541. void fddi_send_antc(struct s_smc *smc, struct fddi_addr *dest)
  1542. {
  1543. SK_UNUSED(smc) ;
  1544. SK_UNUSED(dest) ;
  1545. #if 0
  1546. SMbuf *mb ;
  1547. struct smt_header *smt ;
  1548. int i ;
  1549. char *p ;
  1550. mb = smt_get_mbuf() ;
  1551. mb->sm_len = 3000+12 ;
  1552. p = smtod(mb, char *) + 12 ;
  1553. for (i = 0 ; i < 3000 ; i++)
  1554. *p++ = 1 << (i&7) ;
  1555. smt = smtod(mb, struct smt_header *) ;
  1556. smt->smt_dest = *dest ;
  1557. smt->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
  1558. smt_send_mbuf(smc,mb,FC_ASYNC_LLC) ;
  1559. #endif
  1560. }
  1561. #endif
  1562. #ifdef DEBUG
  1563. #define hextoasc(x) "0123456789abcdef"[x]
  1564. char *addr_to_string(struct fddi_addr *addr)
  1565. {
  1566. int i ;
  1567. static char string[6*3] = "****" ;
  1568. for (i = 0 ; i < 6 ; i++) {
  1569. string[i*3] = hextoasc((addr->a[i]>>4)&0xf) ;
  1570. string[i*3+1] = hextoasc((addr->a[i])&0xf) ;
  1571. string[i*3+2] = ':' ;
  1572. }
  1573. string[5*3+2] = 0 ;
  1574. return(string) ;
  1575. }
  1576. #endif
  1577. #ifdef AM29K
  1578. smt_ifconfig(int argc, char *argv[])
  1579. {
  1580. if (argc >= 2 && !strcmp(argv[0],"opt_bypass") &&
  1581. !strcmp(argv[1],"yes")) {
  1582. smc->mib.fddiSMTBypassPresent = 1 ;
  1583. return(0) ;
  1584. }
  1585. return(amdfddi_config(0,argc,argv)) ;
  1586. }
  1587. #endif
  1588. /*
  1589. * return static mac index
  1590. */
  1591. static int mac_index(struct s_smc *smc, int mac)
  1592. {
  1593. SK_UNUSED(mac) ;
  1594. #ifdef CONCENTRATOR
  1595. SK_UNUSED(smc) ;
  1596. return(NUMPHYS+1) ;
  1597. #else
  1598. return((smc->s.sas == SMT_SAS) ? 2 : 3) ;
  1599. #endif
  1600. }
  1601. /*
  1602. * return static phy index
  1603. */
  1604. static int phy_index(struct s_smc *smc, int phy)
  1605. {
  1606. SK_UNUSED(smc) ;
  1607. return(phy+1);
  1608. }
  1609. /*
  1610. * return dynamic mac connection resource index
  1611. */
  1612. static int mac_con_resource_index(struct s_smc *smc, int mac)
  1613. {
  1614. #ifdef CONCENTRATOR
  1615. SK_UNUSED(smc) ;
  1616. SK_UNUSED(mac) ;
  1617. return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_MAC))) ;
  1618. #else
  1619. SK_UNUSED(mac) ;
  1620. switch (smc->mib.fddiSMTCF_State) {
  1621. case SC9_C_WRAP_A :
  1622. case SC5_THRU_B :
  1623. case SC11_C_WRAP_S :
  1624. return(1) ;
  1625. case SC10_C_WRAP_B :
  1626. case SC4_THRU_A :
  1627. return(2) ;
  1628. }
  1629. return(smc->s.sas == SMT_SAS ? 2 : 3) ;
  1630. #endif
  1631. }
  1632. /*
  1633. * return dynamic phy connection resource index
  1634. */
  1635. static int phy_con_resource_index(struct s_smc *smc, int phy)
  1636. {
  1637. #ifdef CONCENTRATOR
  1638. return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_PHY(phy)))) ;
  1639. #else
  1640. switch (smc->mib.fddiSMTCF_State) {
  1641. case SC9_C_WRAP_A :
  1642. return(phy == PA ? 3 : 2) ;
  1643. case SC10_C_WRAP_B :
  1644. return(phy == PA ? 1 : 3) ;
  1645. case SC4_THRU_A :
  1646. return(phy == PA ? 3 : 1) ;
  1647. case SC5_THRU_B :
  1648. return(phy == PA ? 2 : 3) ;
  1649. case SC11_C_WRAP_S :
  1650. return(2) ;
  1651. }
  1652. return(phy) ;
  1653. #endif
  1654. }
  1655. #ifdef CONCENTRATOR
  1656. static int entity_to_index(struct s_smc *smc, int e)
  1657. {
  1658. if (e == ENTITY_MAC)
  1659. return(mac_index(smc,1)) ;
  1660. else
  1661. return(phy_index(smc,e - ENTITY_PHY(0))) ;
  1662. }
  1663. #endif
  1664. #ifdef LITTLE_ENDIAN
  1665. static int smt_swap_short(u_short s)
  1666. {
  1667. return(((s>>8)&0xff)|((s&0xff)<<8)) ;
  1668. }
  1669. void smt_swap_para(struct smt_header *sm, int len, int direction)
  1670. /* int direction; 0 encode 1 decode */
  1671. {
  1672. struct smt_para *pa ;
  1673. const struct smt_pdef *pd ;
  1674. char *p ;
  1675. int plen ;
  1676. int type ;
  1677. int i ;
  1678. /* printf("smt_swap_para sm %x len %d dir %d\n",
  1679. sm,len,direction) ;
  1680. */
  1681. smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
  1682. /* swap args */
  1683. len -= sizeof(struct smt_header) ;
  1684. p = (char *) (sm + 1) ;
  1685. while (len > 0) {
  1686. pa = (struct smt_para *) p ;
  1687. plen = pa->p_len ;
  1688. type = pa->p_type ;
  1689. pa->p_type = smt_swap_short(pa->p_type) ;
  1690. pa->p_len = smt_swap_short(pa->p_len) ;
  1691. if (direction) {
  1692. plen = pa->p_len ;
  1693. type = pa->p_type ;
  1694. }
  1695. /*
  1696. * note: paras can have 0 length !
  1697. */
  1698. if (plen < 0)
  1699. break ;
  1700. plen += PARA_LEN ;
  1701. for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
  1702. if (pd->ptype == type)
  1703. break ;
  1704. }
  1705. if (i && pd->pswap) {
  1706. smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
  1707. }
  1708. len -= plen ;
  1709. p += plen ;
  1710. }
  1711. }
  1712. static void smt_string_swap(char *data, const char *format, int len)
  1713. {
  1714. const char *open_paren = NULL ;
  1715. int x ;
  1716. while (len > 0 && *format) {
  1717. switch (*format) {
  1718. case '[' :
  1719. open_paren = format ;
  1720. break ;
  1721. case ']' :
  1722. format = open_paren ;
  1723. break ;
  1724. case '1' :
  1725. case '2' :
  1726. case '3' :
  1727. case '4' :
  1728. case '5' :
  1729. case '6' :
  1730. case '7' :
  1731. case '8' :
  1732. case '9' :
  1733. data += *format - '0' ;
  1734. len -= *format - '0' ;
  1735. break ;
  1736. case 'c':
  1737. data++ ;
  1738. len-- ;
  1739. break ;
  1740. case 's' :
  1741. x = data[0] ;
  1742. data[0] = data[1] ;
  1743. data[1] = x ;
  1744. data += 2 ;
  1745. len -= 2 ;
  1746. break ;
  1747. case 'l' :
  1748. x = data[0] ;
  1749. data[0] = data[3] ;
  1750. data[3] = x ;
  1751. x = data[1] ;
  1752. data[1] = data[2] ;
  1753. data[2] = x ;
  1754. data += 4 ;
  1755. len -= 4 ;
  1756. break ;
  1757. }
  1758. format++ ;
  1759. }
  1760. }
  1761. #else
  1762. void smt_swap_para(struct smt_header *sm, int len, int direction)
  1763. /* int direction; 0 encode 1 decode */
  1764. {
  1765. SK_UNUSED(sm) ;
  1766. SK_UNUSED(len) ;
  1767. SK_UNUSED(direction) ;
  1768. }
  1769. #endif
  1770. /*
  1771. * PMF actions
  1772. */
  1773. int smt_action(struct s_smc *smc, int class, int code, int index)
  1774. {
  1775. int event ;
  1776. int port ;
  1777. DB_SMT("SMT: action %d code %d\n",class,code) ;
  1778. switch(class) {
  1779. case SMT_STATION_ACTION :
  1780. switch(code) {
  1781. case SMT_STATION_ACTION_CONNECT :
  1782. smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
  1783. queue_event(smc,EVENT_ECM,EC_CONNECT) ;
  1784. break ;
  1785. case SMT_STATION_ACTION_DISCONNECT :
  1786. queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
  1787. smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
  1788. RS_SET(smc,RS_DISCONNECT) ;
  1789. AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
  1790. FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
  1791. smt_get_event_word(smc));
  1792. break ;
  1793. case SMT_STATION_ACTION_PATHTEST :
  1794. AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
  1795. FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
  1796. smt_get_event_word(smc));
  1797. break ;
  1798. case SMT_STATION_ACTION_SELFTEST :
  1799. AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
  1800. FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
  1801. smt_get_event_word(smc));
  1802. break ;
  1803. case SMT_STATION_ACTION_DISABLE_A :
  1804. if (smc->y[PA].pc_mode == PM_PEER) {
  1805. RS_SET(smc,RS_EVENT) ;
  1806. queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
  1807. }
  1808. break ;
  1809. case SMT_STATION_ACTION_DISABLE_B :
  1810. if (smc->y[PB].pc_mode == PM_PEER) {
  1811. RS_SET(smc,RS_EVENT) ;
  1812. queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
  1813. }
  1814. break ;
  1815. case SMT_STATION_ACTION_DISABLE_M :
  1816. for (port = 0 ; port < NUMPHYS ; port++) {
  1817. if (smc->mib.p[port].fddiPORTMy_Type != TM)
  1818. continue ;
  1819. RS_SET(smc,RS_EVENT) ;
  1820. queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
  1821. }
  1822. break ;
  1823. default :
  1824. return(1) ;
  1825. }
  1826. break ;
  1827. case SMT_PORT_ACTION :
  1828. switch(code) {
  1829. case SMT_PORT_ACTION_ENABLE :
  1830. event = PC_ENABLE ;
  1831. break ;
  1832. case SMT_PORT_ACTION_DISABLE :
  1833. event = PC_DISABLE ;
  1834. break ;
  1835. case SMT_PORT_ACTION_MAINT :
  1836. event = PC_MAINT ;
  1837. break ;
  1838. case SMT_PORT_ACTION_START :
  1839. event = PC_START ;
  1840. break ;
  1841. case SMT_PORT_ACTION_STOP :
  1842. event = PC_STOP ;
  1843. break ;
  1844. default :
  1845. return(1) ;
  1846. }
  1847. queue_event(smc,EVENT_PCM+index,event) ;
  1848. break ;
  1849. default :
  1850. return(1) ;
  1851. }
  1852. return(0) ;
  1853. }
  1854. /*
  1855. * canonical conversion of <len> bytes beginning form *data
  1856. */
  1857. #ifdef USE_CAN_ADDR
  1858. static void hwm_conv_can(struct s_smc *smc, char *data, int len)
  1859. {
  1860. int i ;
  1861. SK_UNUSED(smc) ;
  1862. for (i = len; i ; i--, data++)
  1863. *data = bitrev8(*data);
  1864. }
  1865. #endif
  1866. #endif /* no SLIM_SMT */