smt.c 51 KB

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