smt.c 51 KB

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