smt.c 50 KB

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