smt.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047
  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) 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. #ifdef AM29K
  1570. int smt_ifconfig(int argc, char *argv[])
  1571. {
  1572. if (argc >= 2 && !strcmp(argv[0],"opt_bypass") &&
  1573. !strcmp(argv[1],"yes")) {
  1574. smc->mib.fddiSMTBypassPresent = 1 ;
  1575. return 0;
  1576. }
  1577. return amdfddi_config(0, argc, argv);
  1578. }
  1579. #endif
  1580. /*
  1581. * return static mac index
  1582. */
  1583. static int mac_index(struct s_smc *smc, int mac)
  1584. {
  1585. SK_UNUSED(mac) ;
  1586. #ifdef CONCENTRATOR
  1587. SK_UNUSED(smc) ;
  1588. return NUMPHYS + 1;
  1589. #else
  1590. return (smc->s.sas == SMT_SAS) ? 2 : 3;
  1591. #endif
  1592. }
  1593. /*
  1594. * return static phy index
  1595. */
  1596. static int phy_index(struct s_smc *smc, int phy)
  1597. {
  1598. SK_UNUSED(smc) ;
  1599. return phy + 1;
  1600. }
  1601. /*
  1602. * return dynamic mac connection resource index
  1603. */
  1604. static int mac_con_resource_index(struct s_smc *smc, int mac)
  1605. {
  1606. #ifdef CONCENTRATOR
  1607. SK_UNUSED(smc) ;
  1608. SK_UNUSED(mac) ;
  1609. return entity_to_index(smc, cem_get_downstream(smc, ENTITY_MAC));
  1610. #else
  1611. SK_UNUSED(mac) ;
  1612. switch (smc->mib.fddiSMTCF_State) {
  1613. case SC9_C_WRAP_A :
  1614. case SC5_THRU_B :
  1615. case SC11_C_WRAP_S :
  1616. return 1;
  1617. case SC10_C_WRAP_B :
  1618. case SC4_THRU_A :
  1619. return 2;
  1620. }
  1621. return smc->s.sas == SMT_SAS ? 2 : 3;
  1622. #endif
  1623. }
  1624. /*
  1625. * return dynamic phy connection resource index
  1626. */
  1627. static int phy_con_resource_index(struct s_smc *smc, int phy)
  1628. {
  1629. #ifdef CONCENTRATOR
  1630. return entity_to_index(smc, cem_get_downstream(smc, ENTITY_PHY(phy))) ;
  1631. #else
  1632. switch (smc->mib.fddiSMTCF_State) {
  1633. case SC9_C_WRAP_A :
  1634. return phy == PA ? 3 : 2;
  1635. case SC10_C_WRAP_B :
  1636. return phy == PA ? 1 : 3;
  1637. case SC4_THRU_A :
  1638. return phy == PA ? 3 : 1;
  1639. case SC5_THRU_B :
  1640. return phy == PA ? 2 : 3;
  1641. case SC11_C_WRAP_S :
  1642. return 2;
  1643. }
  1644. return phy;
  1645. #endif
  1646. }
  1647. #ifdef CONCENTRATOR
  1648. static int entity_to_index(struct s_smc *smc, int e)
  1649. {
  1650. if (e == ENTITY_MAC)
  1651. return mac_index(smc, 1);
  1652. else
  1653. return phy_index(smc, e - ENTITY_PHY(0));
  1654. }
  1655. #endif
  1656. #ifdef LITTLE_ENDIAN
  1657. static int smt_swap_short(u_short s)
  1658. {
  1659. return ((s>>8)&0xff) | ((s&0xff)<<8);
  1660. }
  1661. void smt_swap_para(struct smt_header *sm, int len, int direction)
  1662. /* int direction; 0 encode 1 decode */
  1663. {
  1664. struct smt_para *pa ;
  1665. const struct smt_pdef *pd ;
  1666. char *p ;
  1667. int plen ;
  1668. int type ;
  1669. int i ;
  1670. /* printf("smt_swap_para sm %x len %d dir %d\n",
  1671. sm,len,direction) ;
  1672. */
  1673. smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
  1674. /* swap args */
  1675. len -= sizeof(struct smt_header) ;
  1676. p = (char *) (sm + 1) ;
  1677. while (len > 0) {
  1678. pa = (struct smt_para *) p ;
  1679. plen = pa->p_len ;
  1680. type = pa->p_type ;
  1681. pa->p_type = smt_swap_short(pa->p_type) ;
  1682. pa->p_len = smt_swap_short(pa->p_len) ;
  1683. if (direction) {
  1684. plen = pa->p_len ;
  1685. type = pa->p_type ;
  1686. }
  1687. /*
  1688. * note: paras can have 0 length !
  1689. */
  1690. if (plen < 0)
  1691. break ;
  1692. plen += PARA_LEN ;
  1693. for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
  1694. if (pd->ptype == type)
  1695. break ;
  1696. }
  1697. if (i && pd->pswap) {
  1698. smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
  1699. }
  1700. len -= plen ;
  1701. p += plen ;
  1702. }
  1703. }
  1704. static void smt_string_swap(char *data, const char *format, int len)
  1705. {
  1706. const char *open_paren = NULL ;
  1707. int x ;
  1708. while (len > 0 && *format) {
  1709. switch (*format) {
  1710. case '[' :
  1711. open_paren = format ;
  1712. break ;
  1713. case ']' :
  1714. format = open_paren ;
  1715. break ;
  1716. case '1' :
  1717. case '2' :
  1718. case '3' :
  1719. case '4' :
  1720. case '5' :
  1721. case '6' :
  1722. case '7' :
  1723. case '8' :
  1724. case '9' :
  1725. data += *format - '0' ;
  1726. len -= *format - '0' ;
  1727. break ;
  1728. case 'c':
  1729. data++ ;
  1730. len-- ;
  1731. break ;
  1732. case 's' :
  1733. x = data[0] ;
  1734. data[0] = data[1] ;
  1735. data[1] = x ;
  1736. data += 2 ;
  1737. len -= 2 ;
  1738. break ;
  1739. case 'l' :
  1740. x = data[0] ;
  1741. data[0] = data[3] ;
  1742. data[3] = x ;
  1743. x = data[1] ;
  1744. data[1] = data[2] ;
  1745. data[2] = x ;
  1746. data += 4 ;
  1747. len -= 4 ;
  1748. break ;
  1749. }
  1750. format++ ;
  1751. }
  1752. }
  1753. #else
  1754. void smt_swap_para(struct smt_header *sm, int len, int direction)
  1755. /* int direction; 0 encode 1 decode */
  1756. {
  1757. SK_UNUSED(sm) ;
  1758. SK_UNUSED(len) ;
  1759. SK_UNUSED(direction) ;
  1760. }
  1761. #endif
  1762. /*
  1763. * PMF actions
  1764. */
  1765. int smt_action(struct s_smc *smc, int class, int code, int index)
  1766. {
  1767. int event ;
  1768. int port ;
  1769. DB_SMT("SMT: action %d code %d\n",class,code) ;
  1770. switch(class) {
  1771. case SMT_STATION_ACTION :
  1772. switch(code) {
  1773. case SMT_STATION_ACTION_CONNECT :
  1774. smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
  1775. queue_event(smc,EVENT_ECM,EC_CONNECT) ;
  1776. break ;
  1777. case SMT_STATION_ACTION_DISCONNECT :
  1778. queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
  1779. smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
  1780. RS_SET(smc,RS_DISCONNECT) ;
  1781. AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
  1782. FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
  1783. smt_get_event_word(smc));
  1784. break ;
  1785. case SMT_STATION_ACTION_PATHTEST :
  1786. AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
  1787. FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
  1788. smt_get_event_word(smc));
  1789. break ;
  1790. case SMT_STATION_ACTION_SELFTEST :
  1791. AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
  1792. FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
  1793. smt_get_event_word(smc));
  1794. break ;
  1795. case SMT_STATION_ACTION_DISABLE_A :
  1796. if (smc->y[PA].pc_mode == PM_PEER) {
  1797. RS_SET(smc,RS_EVENT) ;
  1798. queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
  1799. }
  1800. break ;
  1801. case SMT_STATION_ACTION_DISABLE_B :
  1802. if (smc->y[PB].pc_mode == PM_PEER) {
  1803. RS_SET(smc,RS_EVENT) ;
  1804. queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
  1805. }
  1806. break ;
  1807. case SMT_STATION_ACTION_DISABLE_M :
  1808. for (port = 0 ; port < NUMPHYS ; port++) {
  1809. if (smc->mib.p[port].fddiPORTMy_Type != TM)
  1810. continue ;
  1811. RS_SET(smc,RS_EVENT) ;
  1812. queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
  1813. }
  1814. break ;
  1815. default :
  1816. return 1;
  1817. }
  1818. break ;
  1819. case SMT_PORT_ACTION :
  1820. switch(code) {
  1821. case SMT_PORT_ACTION_ENABLE :
  1822. event = PC_ENABLE ;
  1823. break ;
  1824. case SMT_PORT_ACTION_DISABLE :
  1825. event = PC_DISABLE ;
  1826. break ;
  1827. case SMT_PORT_ACTION_MAINT :
  1828. event = PC_MAINT ;
  1829. break ;
  1830. case SMT_PORT_ACTION_START :
  1831. event = PC_START ;
  1832. break ;
  1833. case SMT_PORT_ACTION_STOP :
  1834. event = PC_STOP ;
  1835. break ;
  1836. default :
  1837. return 1;
  1838. }
  1839. queue_event(smc,EVENT_PCM+index,event) ;
  1840. break ;
  1841. default :
  1842. return 1;
  1843. }
  1844. return 0;
  1845. }
  1846. /*
  1847. * canonical conversion of <len> bytes beginning form *data
  1848. */
  1849. #ifdef USE_CAN_ADDR
  1850. static void hwm_conv_can(struct s_smc *smc, char *data, int len)
  1851. {
  1852. int i ;
  1853. SK_UNUSED(smc) ;
  1854. for (i = len; i ; i--, data++)
  1855. *data = bitrev8(*data);
  1856. }
  1857. #endif
  1858. #endif /* no SLIM_SMT */