smt.c 51 KB

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