1 /******************************************************************************
3 * (C)Copyright 1998,1999 SysKonnect,
4 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
6 * See the file "skfddi.c" for further information.
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.
13 * The information in this file is provided "AS IS" without warranty.
15 ******************************************************************************/
23 #include "h/smtstate.h"
26 static const char ID_sccs[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
29 extern const u_char canonical[256] ;
34 #define m_fc(mb) ((mb)->sm_data[0])
36 #define SMT_TID_MAGIC 0x1f0a7b3c
39 static const char *const smt_type_name[] = {
40 "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
41 "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
42 "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
43 "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
46 static const char *const smt_class_name[] = {
47 "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
48 "SRF","PMF_GET","PMF_SET","ESF"
51 #define LAST_CLASS (SMT_PMF_SET)
53 static const struct fddi_addr SMT_Unknown = {
60 extern const struct fddi_addr fddi_broadcast ;
65 int pcm_status_twisted(struct s_smc *smc);
71 static int smt_swap_short(u_short s);
73 static int mac_index(struct s_smc *smc, int mac);
74 static int phy_index(struct s_smc *smc, int phy);
75 static int mac_con_resource_index(struct s_smc *smc, int mac);
76 static int phy_con_resource_index(struct s_smc *smc, int phy);
77 static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
79 static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
80 int fc, u_long tid, int type, int local);
81 static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
82 u_long tid, int type, int len);
83 static void smt_echo_test(struct s_smc *smc, int dna);
84 static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
85 u_long tid, int local);
86 static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
87 u_long tid, int local);
89 static void smt_string_swap(void);
91 static void smt_add_frame_len(SMbuf *mb, int len);
92 static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
93 static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde);
94 static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state);
95 static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts);
96 static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy);
97 static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency);
98 static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor);
99 static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path);
100 static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st);
101 static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy);
102 static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers);
103 static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc);
104 static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc);
105 static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc);
106 static void smt_fill_manufacturer(struct s_smc *smc,
107 struct smp_p_manufacturer *man);
108 static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user);
109 static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount);
110 static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
113 void smt_clear_una_dna(struct s_smc *smc);
114 static void smt_clear_old_una_dna(struct s_smc *smc);
116 static int entity_to_index(void);
118 static void update_dac(struct s_smc *smc, int report);
119 static int div_ratio(u_long upper, u_long lower);
121 void hwm_conv_can(struct s_smc *smc, char *data, int len);
123 #define hwm_conv_can(smc,data,len)
127 static inline int is_my_addr(const struct s_smc *smc,
128 const struct fddi_addr *addr)
130 return(*(short *)(&addr->a[0]) ==
131 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[0])
132 && *(short *)(&addr->a[2]) ==
133 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[2])
134 && *(short *)(&addr->a[4]) ==
135 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[4])) ;
138 static inline int is_zero(const struct fddi_addr *addr)
140 return(*(short *)(&addr->a[0]) == 0 &&
141 *(short *)(&addr->a[2]) == 0 &&
142 *(short *)(&addr->a[4]) == 0 ) ;
145 static inline int is_broadcast(const struct fddi_addr *addr)
147 return(*(u_short *)(&addr->a[0]) == 0xffff &&
148 *(u_short *)(&addr->a[2]) == 0xffff &&
149 *(u_short *)(&addr->a[4]) == 0xffff ) ;
152 static inline int is_individual(const struct fddi_addr *addr)
154 return(!(addr->a[0] & GROUP_ADDR)) ;
157 static inline int is_equal(const struct fddi_addr *addr1,
158 const struct fddi_addr *addr2)
160 return(*(u_short *)(&addr1->a[0]) == *(u_short *)(&addr2->a[0]) &&
161 *(u_short *)(&addr1->a[2]) == *(u_short *)(&addr2->a[2]) &&
162 *(u_short *)(&addr1->a[4]) == *(u_short *)(&addr2->a[4]) ) ;
166 * list of mandatory paras in frames
168 static const u_short plist_nif[] = { SMT_P_UNA,SMT_P_SDE,SMT_P_STATE,0 } ;
173 void smt_agent_init(struct s_smc *smc)
180 smc->mib.m[MAC0].fddiMACSMTAddress = smc->hw.fddi_home_addr ;
183 * get OUI address from driver (bia == built-in-address)
185 smc->mib.fddiSMTStationId.sid_oem[0] = 0 ;
186 smc->mib.fddiSMTStationId.sid_oem[1] = 0 ;
187 driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
188 for (i = 0 ; i < 6 ; i ++) {
189 smc->mib.fddiSMTStationId.sid_node.a[i] =
190 canonical[smc->mib.fddiSMTStationId.sid_node.a[i]] ;
192 smc->mib.fddiSMTManufacturerData[0] =
193 smc->mib.fddiSMTStationId.sid_node.a[0] ;
194 smc->mib.fddiSMTManufacturerData[1] =
195 smc->mib.fddiSMTStationId.sid_node.a[1] ;
196 smc->mib.fddiSMTManufacturerData[2] =
197 smc->mib.fddiSMTStationId.sid_node.a[2] ;
198 smc->sm.smt_tid = 0 ;
199 smc->mib.m[MAC0].fddiMACDupAddressTest = DA_NONE ;
200 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
202 smt_clear_una_dna(smc) ;
203 smt_clear_old_una_dna(smc) ;
205 for (i = 0 ; i < SMT_MAX_TEST ; i++)
206 smc->sm.pend[i] = 0 ;
207 smc->sm.please_reconnect = 0 ;
208 smc->sm.uniq_ticks = 0 ;
219 void smt_agent_task(struct s_smc *smc)
221 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
222 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
223 DB_SMT("SMT agent task\n",0,0) ;
226 void smt_please_reconnect(struct s_smc *smc, int reconn_time)
227 /* struct s_smc *smc; Pointer to SMT context */
228 /* int reconn_time; Wait for reconnect time in seconds */
231 * The please reconnect variable is used as a timer.
232 * It is decremented each time smt_event is called.
233 * This happens every second or when smt_force_irq is called.
234 * Note: smt_force_irq () is called on some packet receives and
235 * when a multicast address is changed. Since nothing
236 * is received during the disconnect and the multicast
237 * address changes can be viewed as not very often and
238 * the timer runs out close to its given value
241 smc->sm.please_reconnect = reconn_time ;
244 #ifndef SMT_REAL_TOKEN_CT
245 void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
251 time = smt_get_time();
252 count = ((time - smc->sm.last_tok_time[mac_index]) *
253 100)/TICKS_PER_SECOND;
256 * Only when ring is up we will have a token count. The
257 * flag is unfortunatly a single instance value. This
258 * doesn't matter now, because we currently have only
261 if (smc->hw.mac_ring_is_up){
262 smc->mib.m[mac_index].fddiMACToken_Ct += count;
265 /* Remember current time */
266 smc->sm.last_tok_time[mac_index] = time;
272 void smt_event(struct s_smc *smc, int event)
275 #ifndef SMT_REAL_TOKEN_CT
280 if (smc->sm.please_reconnect) {
281 smc->sm.please_reconnect -- ;
282 if (smc->sm.please_reconnect == 0) {
284 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
288 if (event == SM_FAST)
292 * timer for periodic cleanup in driver
293 * reset and start the watchdog (FM2)
297 smt_timer_poll(smc) ;
298 smt_start_watchdog(smc) ;
302 ess_timer_poll(smc) ;
306 sba_timer_poll(smc) ;
309 smt_srf_event(smc,0,0,0) ;
311 #endif /* no SLIM_SMT */
313 time = smt_get_time() ;
315 if (time - smc->sm.smt_last_lem >= TICKS_PER_SECOND*8) {
317 * Use 8 sec. for the time intervall, it simplifies the
320 struct fddi_mib_m *mib ;
327 * calculate LEM bit error rate
329 sm_lem_evaluate(smc) ;
330 smc->sm.smt_last_lem = time ;
336 mac_update_counter(smc) ;
339 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) +
340 (mib->fddiMACError_Ct - mib->fddiMACOld_Error_Ct) ;
342 (mib->fddiMACFrame_Ct - mib->fddiMACOld_Frame_Ct) +
343 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) ;
344 mib->fddiMACFrameErrorRatio = div_ratio(upper,lower) ;
347 ((!mib->fddiMACFrameErrorThreshold &&
348 mib->fddiMACError_Ct != mib->fddiMACOld_Error_Ct) ||
349 (mib->fddiMACFrameErrorRatio >
350 mib->fddiMACFrameErrorThreshold)) ;
352 if (cond != mib->fddiMACFrameErrorFlag)
353 smt_srf_event(smc,SMT_COND_MAC_FRAME_ERROR,
357 (mib->fddiMACNotCopied_Ct - mib->fddiMACOld_NotCopied_Ct) ;
360 (mib->fddiMACCopied_Ct - mib->fddiMACOld_Copied_Ct) ;
361 mib->fddiMACNotCopiedRatio = div_ratio(upper,lower) ;
364 ((!mib->fddiMACNotCopiedThreshold &&
365 mib->fddiMACNotCopied_Ct !=
366 mib->fddiMACOld_NotCopied_Ct)||
367 (mib->fddiMACNotCopiedRatio >
368 mib->fddiMACNotCopiedThreshold)) ;
370 if (cond != mib->fddiMACNotCopiedFlag)
371 smt_srf_event(smc,SMT_COND_MAC_NOT_COPIED,
377 mib->fddiMACOld_Frame_Ct = mib->fddiMACFrame_Ct ;
378 mib->fddiMACOld_Copied_Ct = mib->fddiMACCopied_Ct ;
379 mib->fddiMACOld_Error_Ct = mib->fddiMACError_Ct ;
380 mib->fddiMACOld_Lost_Ct = mib->fddiMACLost_Ct ;
381 mib->fddiMACOld_NotCopied_Ct = mib->fddiMACNotCopied_Ct ;
384 * Check port EBError Condition
386 for (port = 0; port < NUMPHYS; port ++) {
387 phy = &smc->y[port] ;
389 if (!phy->mib->fddiPORTHardwarePresent) {
393 cond = (phy->mib->fddiPORTEBError_Ct -
394 phy->mib->fddiPORTOldEBError_Ct > 5) ;
396 /* If ratio is more than 5 in 8 seconds
399 smt_srf_event(smc,SMT_COND_PORT_EB_ERROR,
400 (int) (INDEX_PORT+ phy->np) ,cond) ;
405 phy->mib->fddiPORTOldEBError_Ct =
406 phy->mib->fddiPORTEBError_Ct ;
409 #endif /* no SLIM_SMT */
414 if (time - smc->sm.smt_last_notify >= (u_long)
415 (smc->mib.fddiSMTTT_Notify * TICKS_PER_SECOND) ) {
417 * we can either send an announcement or a request
418 * a request will trigger a reply so that we can update
420 * note: same tid must be used until reply is received
422 if (!smc->sm.pend[SMT_TID_NIF])
423 smc->sm.pend[SMT_TID_NIF] = smt_get_tid(smc) ;
424 smt_send_nif(smc,&fddi_broadcast, FC_SMT_NSA,
425 smc->sm.pend[SMT_TID_NIF], SMT_REQUEST,0) ;
426 smc->sm.smt_last_notify = time ;
432 if (smc->sm.smt_tvu &&
433 time - smc->sm.smt_tvu > 228*TICKS_PER_SECOND) {
434 DB_SMT("SMT : UNA expired\n",0,0) ;
435 smc->sm.smt_tvu = 0 ;
437 if (!is_equal(&smc->mib.m[MAC0].fddiMACUpstreamNbr,
439 /* Do not update unknown address */
440 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
441 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
443 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
444 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
446 * Make sure the fddiMACUNDA_Flag = FALSE is
447 * included in the SRF so we don't generate
448 * a separate SRF for the deassertion of this
452 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
455 if (smc->sm.smt_tvd &&
456 time - smc->sm.smt_tvd > 228*TICKS_PER_SECOND) {
457 DB_SMT("SMT : DNA expired\n",0,0) ;
458 smc->sm.smt_tvd = 0 ;
459 if (!is_equal(&smc->mib.m[MAC0].fddiMACDownstreamNbr,
461 /* Do not update unknown address */
462 smc->mib.m[MAC0].fddiMACOldDownstreamNbr=
463 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
465 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
466 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
470 #endif /* no SLIM_SMT */
472 #ifndef SMT_REAL_TOKEN_CT
474 * Token counter emulation section. If hardware supports the token
475 * count, the token counter will be updated in mac_update_counter.
477 for (i = MAC0; i < NUMMACS; i++ ){
478 if (time - smc->sm.last_tok_time[i] > 2*TICKS_PER_SECOND ){
479 smt_emulate_token_ct( smc, i );
484 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
485 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
488 static int div_ratio(u_long upper, u_long lower)
490 if ((upper<<16L) < upper)
491 upper = 0xffff0000L ;
496 return((int)(upper/lower)) ;
502 * receive packet handler
504 void smt_received_pack(struct s_smc *smc, SMbuf *mb, int fs)
505 /* int fs; frame status */
507 struct smt_header *sm ;
514 case FC_SMT_LAN_LOC :
519 smt_free_mbuf(smc,mb) ;
523 smc->mib.m[MAC0].fddiMACSMTCopied_Ct++ ;
524 sm = smtod(mb,struct smt_header *) ;
525 local = ((fs & L_INDICATOR) != 0) ;
526 hwm_conv_can(smc,(char *)sm,12) ;
528 /* check destination address */
529 if (is_individual(&sm->smt_dest) && !is_my_addr(smc,&sm->smt_dest)) {
530 smt_free_mbuf(smc,mb) ;
533 #if 0 /* for DUP recognition, do NOT filter them */
534 /* ignore loop back packets */
535 if (is_my_addr(smc,&sm->smt_source) && !local) {
536 smt_free_mbuf(smc,mb) ;
541 smt_swap_para(sm,(int) mb->sm_len,1) ;
542 DB_SMT("SMT : received packet [%s] at 0x%x\n",
543 smt_type_name[m_fc(mb) & 0xf],sm) ;
544 DB_SMT("SMT : version %d, class %s\n",sm->smt_version,
545 smt_class_name[(sm->smt_class>LAST_CLASS)?0 : sm->smt_class]) ;
551 if (m_fc(mb) == FC_SMT_NSA && sm->smt_class == SMT_NIF &&
552 (sm->smt_type == SMT_ANNOUNCE || sm->smt_type == SMT_REQUEST)) {
559 * ignore any packet with NSA and A-indicator set
561 if ( (fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) {
562 DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
563 addr_to_string(&sm->smt_source),0) ;
564 smt_free_mbuf(smc,mb) ;
569 * ignore frames with illegal length
571 if (((sm->smt_class == SMT_ECF) && (sm->smt_len > SMT_MAX_ECHO_LEN)) ||
572 ((sm->smt_class != SMT_ECF) && (sm->smt_len > SMT_MAX_INFO_LEN))) {
573 smt_free_mbuf(smc,mb) ;
580 switch (sm->smt_class) {
582 case SMT_SIF_CONFIG :
585 if (sm->smt_version != SMT_VID)
589 if (sm->smt_version != SMT_VID_2)
594 DB_SMT("SMT : version = %d, dest = %s\n",
595 sm->smt_version,addr_to_string(&sm->smt_source)) ;
596 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_VERSION,local) ;
597 smt_free_mbuf(smc,mb) ;
600 if ((sm->smt_len > mb->sm_len - sizeof(struct smt_header)) ||
601 ((sm->smt_len & 3) && (sm->smt_class != SMT_ECF))) {
602 DB_SMT("SMT: info length error, len = %d\n",sm->smt_len,0) ;
603 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,local) ;
604 smt_free_mbuf(smc,mb) ;
607 switch (sm->smt_class) {
609 if (smt_check_para(smc,sm,plist_nif)) {
610 DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
613 switch (sm->smt_type) {
616 if (!(fs & C_INDICATOR) && m_fc(mb) == FC_SMT_NSA
617 && is_broadcast(&sm->smt_dest)) {
618 struct smt_p_state *st ;
622 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
624 DB_SMT("SMT : updated my UNA = %s\n",
625 addr_to_string(&sm->smt_source),0) ;
626 if (!is_equal(&smc->mib.m[MAC0].
627 fddiMACUpstreamNbr,&SMT_Unknown)){
628 /* Do not update unknown address */
629 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
630 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
633 smc->mib.m[MAC0].fddiMACUpstreamNbr =
636 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
638 smt_echo_test(smc,0) ;
640 smc->sm.smt_tvu = smt_get_time() ;
641 st = (struct smt_p_state *)
642 sm_to_para(smc,sm,SMT_P_STATE) ;
644 smc->mib.m[MAC0].fddiMACUNDA_Flag =
645 (st->st_dupl_addr & SMT_ST_MY_DUPA) ?
650 if ((sm->smt_type == SMT_REQUEST) &&
651 is_individual(&sm->smt_source) &&
652 ((!(fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) ||
653 (m_fc(mb) != FC_SMT_NSA))) {
654 DB_SMT("SMT : replying to NIF request %s\n",
655 addr_to_string(&sm->smt_source),0) ;
656 smt_send_nif(smc,&sm->smt_source,
663 DB_SMT("SMT : received NIF response from %s\n",
664 addr_to_string(&sm->smt_source),0) ;
665 if (fs & A_INDICATOR) {
666 smc->sm.pend[SMT_TID_NIF] = 0 ;
667 DB_SMT("SMT : duplicate address\n",0,0) ;
668 smc->mib.m[MAC0].fddiMACDupAddressTest =
670 smc->r.dup_addr_test = DA_FAILED ;
671 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
672 smc->mib.m[MAC0].fddiMACDA_Flag = TRUE ;
676 if (sm->smt_tid == smc->sm.pend[SMT_TID_NIF]) {
677 smc->sm.pend[SMT_TID_NIF] = 0 ;
680 &smc->mib.m[MAC0].fddiMACDownstreamNbr,
682 DB_SMT("SMT : updated my DNA\n",0,0) ;
683 if (!is_equal(&smc->mib.m[MAC0].
684 fddiMACDownstreamNbr, &SMT_Unknown)){
685 /* Do not update unknown address */
686 smc->mib.m[MAC0].fddiMACOldDownstreamNbr =
687 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
690 smc->mib.m[MAC0].fddiMACDownstreamNbr =
693 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
695 smt_echo_test(smc,1) ;
697 smc->mib.m[MAC0].fddiMACDA_Flag = FALSE ;
699 smc->sm.smt_tvd = smt_get_time() ;
700 smc->mib.m[MAC0].fddiMACDupAddressTest =
702 if (smc->r.dup_addr_test != DA_PASSED) {
703 smc->r.dup_addr_test = DA_PASSED ;
704 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
707 else if (sm->smt_tid ==
708 smc->sm.pend[SMT_TID_NIF_TEST]) {
709 DB_SMT("SMT : NIF test TID ok\n",0,0) ;
712 DB_SMT("SMT : expected TID %lx, got %lx\n",
713 smc->sm.pend[SMT_TID_NIF],sm->smt_tid) ;
721 case SMT_SIF_CONFIG : /* station information */
722 if (sm->smt_type != SMT_REQUEST)
724 DB_SMT("SMT : replying to SIF Config request from %s\n",
725 addr_to_string(&sm->smt_source),0) ;
726 smt_send_sif_config(smc,&sm->smt_source,sm->smt_tid,local) ;
728 case SMT_SIF_OPER : /* station information */
729 if (sm->smt_type != SMT_REQUEST)
731 DB_SMT("SMT : replying to SIF Operation request from %s\n",
732 addr_to_string(&sm->smt_source),0) ;
733 smt_send_sif_operation(smc,&sm->smt_source,sm->smt_tid,local) ;
735 case SMT_ECF : /* echo frame */
736 switch (sm->smt_type) {
738 smc->mib.priv.fddiPRIVECF_Reply_Rx++ ;
739 DB_SMT("SMT: received ECF reply from %s\n",
740 addr_to_string(&sm->smt_source),0) ;
741 if (sm_to_para(smc,sm,SMT_P_ECHODATA) == 0) {
742 DB_SMT("SMT: ECHODATA missing\n",0,0) ;
745 if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF]) {
746 DB_SMT("SMT : ECF test TID ok\n",0,0) ;
748 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_UNA]) {
749 DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
751 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_DNA]) {
752 DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
755 DB_SMT("SMT : expected TID %lx, got %lx\n",
756 smc->sm.pend[SMT_TID_ECF],
761 smc->mib.priv.fddiPRIVECF_Req_Rx++ ;
763 if (sm->smt_len && !sm_to_para(smc,sm,SMT_P_ECHODATA)) {
764 DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
765 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,
769 DB_SMT("SMT - sending ECF reply to %s\n",
770 addr_to_string(&sm->smt_source),0) ;
772 /* set destination addr. & reply */
773 sm->smt_dest = sm->smt_source ;
774 sm->smt_type = SMT_REPLY ;
775 dump_smt(smc,sm,"ECF REPLY") ;
776 smc->mib.priv.fddiPRIVECF_Reply_Tx++ ;
777 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
778 return ; /* DON'T free mbuf */
786 case SMT_RAF : /* resource allocation */
788 DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
789 fs = ess_raf_received_pack(smc,mb,sm,fs) ;
793 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
794 sba_raf_received_pack(smc,sm,fs) ;
797 case SMT_RDF : /* request denied */
798 smc->mib.priv.fddiPRIVRDF_Rx++ ;
800 case SMT_ESF : /* extended service - not supported */
801 if (sm->smt_type == SMT_REQUEST) {
802 DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
803 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
808 if (sm->smt_type != SMT_REQUEST)
810 /* update statistics */
811 if (sm->smt_class == SMT_PMF_GET)
812 smc->mib.priv.fddiPRIVPMF_Get_Rx++ ;
814 smc->mib.priv.fddiPRIVPMF_Set_Rx++ ;
816 * ignore PMF SET with I/G set
818 if ((sm->smt_class == SMT_PMF_SET) &&
819 !is_individual(&sm->smt_dest)) {
820 DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
823 smt_pmf_received_pack(smc,mb, local) ;
826 dump_smt(smc,sm,"SRF received") ;
829 if (sm->smt_type != SMT_REQUEST)
832 * For frames with unknown class:
833 * we need to send a RDF frame according to 8.1.3.1.1,
834 * only if it is a REQUEST.
836 DB_SMT("SMT : class = %d, send RDF to %s\n",
837 sm->smt_class, addr_to_string(&sm->smt_source)) ;
839 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
844 DB_SMT("SMT: discarding invalid frame, reason = %d\n",
847 smt_free_mbuf(smc,mb) ;
850 static void update_dac(struct s_smc *smc, int report)
854 cond = ( smc->mib.m[MAC0].fddiMACUNDA_Flag |
855 smc->mib.m[MAC0].fddiMACDA_Flag) != 0 ;
856 if (report && (cond != smc->mib.m[MAC0].fddiMACDuplicateAddressCond))
857 smt_srf_event(smc, SMT_COND_MAC_DUP_ADDR,INDEX_MAC,cond) ;
859 smc->mib.m[MAC0].fddiMACDuplicateAddressCond = cond ;
868 void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local)
869 /* SMbuf *mb; buffer to send */
870 /* int fc; FC value */
872 struct smt_header *sm ;
874 if (!smc->r.sm_ma_avail && !local) {
875 smt_free_mbuf(smc,mb) ;
878 sm = smtod(mb,struct smt_header *) ;
879 sm->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
880 sm->smt_sid = smc->mib.fddiSMTStationId ;
882 smt_swap_para(sm,(int) mb->sm_len,0) ; /* swap para & header */
883 hwm_conv_can(smc,(char *)sm,12) ; /* convert SA and DA */
884 smc->mib.m[MAC0].fddiMACSMTTransmit_Ct++ ;
885 smt_send_mbuf(smc,mb,local ? FC_SMT_LOC : fc) ;
889 * generate and send RDF
891 static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
893 /* SMbuf *rej; mbuf of offending frame */
894 /* int fc; FC of denied frame */
895 /* int reason; reason code */
898 struct smt_header *sm ; /* header of offending frame */
899 struct smt_rdf *rdf ;
903 sm = smtod(rej,struct smt_header *) ;
904 if (sm->smt_type != SMT_REQUEST)
907 DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
908 addr_to_string(&sm->smt_source),reason) ;
912 * note: get framelength from MAC length, NOT from SMT header
913 * smt header length is included in sm_len
915 frame_len = rej->sm_len ;
917 if (!(mb=smt_build_frame(smc,SMT_RDF,SMT_REPLY,sizeof(struct smt_rdf))))
919 rdf = smtod(mb,struct smt_rdf *) ;
920 rdf->smt.smt_tid = sm->smt_tid ; /* use TID from sm */
921 rdf->smt.smt_dest = sm->smt_source ; /* set dest = source */
924 rdf->reason.para.p_type = SMT_P_REASON ;
925 rdf->reason.para.p_len = sizeof(struct smt_p_reason) - PARA_LEN ;
926 rdf->reason.rdf_reason = reason ;
929 rdf->version.para.p_type = SMT_P_VERSION ;
930 rdf->version.para.p_len = sizeof(struct smt_p_version) - PARA_LEN ;
931 rdf->version.v_pad = 0 ;
932 rdf->version.v_n = 1 ;
933 rdf->version.v_index = 1 ;
934 rdf->version.v_version[0] = SMT_VID_2 ;
935 rdf->version.v_pad2 = 0 ;
938 if ((unsigned) frame_len <= SMT_MAX_INFO_LEN - sizeof(*rdf) +
939 2*sizeof(struct smt_header))
942 len = SMT_MAX_INFO_LEN - sizeof(*rdf) +
943 2*sizeof(struct smt_header) ;
944 /* make length multiple of 4 */
946 rdf->refused.para.p_type = SMT_P_REFUSED ;
947 /* length of para is smt_frame + ref_fc */
948 rdf->refused.para.p_len = len + 4 ;
949 rdf->refused.ref_fc = fc ;
952 smt_swap_para(sm,frame_len,0) ;
954 memcpy((char *) &rdf->refused.ref_header,(char *) sm,len) ;
956 len -= sizeof(struct smt_header) ;
958 rdf->smt.smt_len += len ;
960 dump_smt(smc,(struct smt_header *)rdf,"RDF") ;
961 smc->mib.priv.fddiPRIVRDF_Tx++ ;
962 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
966 * generate and send NIF
968 static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
969 int fc, u_long tid, int type, int local)
970 /* struct fddi_addr *dest; dest address */
971 /* int fc; frame control */
972 /* u_long tid; transaction id */
973 /* int type; frame type */
975 struct smt_nif *nif ;
978 if (!(mb = smt_build_frame(smc,SMT_NIF,type,sizeof(struct smt_nif))))
980 nif = smtod(mb, struct smt_nif *) ;
981 smt_fill_una(smc,&nif->una) ; /* set UNA */
982 smt_fill_sde(smc,&nif->sde) ; /* set station descriptor */
983 smt_fill_state(smc,&nif->state) ; /* set state information */
985 smt_fill_fsc(smc,&nif->fsc) ; /* set frame status cap. */
987 nif->smt.smt_dest = *dest ; /* destination address */
988 nif->smt.smt_tid = tid ; /* transaction ID */
989 dump_smt(smc,(struct smt_header *)nif,"NIF") ;
990 smt_send_frame(smc,mb,fc,local) ;
995 * send NIF request (test purpose)
997 static void smt_send_nif_request(struct s_smc *smc, struct fddi_addr *dest)
999 smc->sm.pend[SMT_TID_NIF_TEST] = smt_get_tid(smc) ;
1000 smt_send_nif(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_NIF_TEST],
1005 * send ECF request (test purpose)
1007 static void smt_send_ecf_request(struct s_smc *smc, struct fddi_addr *dest,
1010 smc->sm.pend[SMT_TID_ECF] = smt_get_tid(smc) ;
1011 smt_send_ecf(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_ECF],
1019 static void smt_echo_test(struct s_smc *smc, int dna)
1023 smc->sm.pend[dna ? SMT_TID_ECF_DNA : SMT_TID_ECF_UNA] =
1024 tid = smt_get_tid(smc) ;
1025 smt_send_ecf(smc, dna ?
1026 &smc->mib.m[MAC0].fddiMACDownstreamNbr :
1027 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
1028 FC_SMT_INFO,tid, SMT_REQUEST, (SMT_TEST_ECHO_LEN & ~3)-8) ;
1032 * generate and send ECF
1034 static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
1035 u_long tid, int type, int len)
1036 /* struct fddi_addr *dest; dest address */
1037 /* int fc; frame control */
1038 /* u_long tid; transaction id */
1039 /* int type; frame type */
1040 /* int len; frame length */
1042 struct smt_ecf *ecf ;
1045 if (!(mb = smt_build_frame(smc,SMT_ECF,type,SMT_ECF_LEN + len)))
1047 ecf = smtod(mb, struct smt_ecf *) ;
1049 smt_fill_echo(smc,&ecf->ec_echo,tid,len) ; /* set ECHO */
1050 ecf->smt.smt_dest = *dest ; /* destination address */
1051 ecf->smt.smt_tid = tid ; /* transaction ID */
1052 smc->mib.priv.fddiPRIVECF_Req_Tx++ ;
1053 smt_send_frame(smc,mb,fc,0) ;
1057 * generate and send SIF config response
1060 static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
1061 u_long tid, int local)
1062 /* struct fddi_addr *dest; dest address */
1063 /* u_long tid; transaction id */
1065 struct smt_sif_config *sif ;
1068 if (!(mb = smt_build_frame(smc,SMT_SIF_CONFIG,SMT_REPLY,
1069 SIZEOF_SMT_SIF_CONFIG)))
1072 sif = smtod(mb, struct smt_sif_config *) ;
1073 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1074 smt_fill_sde(smc,&sif->sde) ; /* set station descriptor */
1075 smt_fill_version(smc,&sif->version) ; /* set version information */
1076 smt_fill_state(smc,&sif->state) ; /* set state information */
1077 smt_fill_policy(smc,&sif->policy) ; /* set station policy */
1078 smt_fill_latency(smc,&sif->latency); /* set station latency */
1079 smt_fill_neighbor(smc,&sif->neighbor); /* set station neighbor */
1080 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1081 len = smt_fill_path(smc,&sif->path); /* set station path descriptor*/
1082 sif->smt.smt_dest = *dest ; /* destination address */
1083 sif->smt.smt_tid = tid ; /* transaction ID */
1084 smt_add_frame_len(mb,len) ; /* adjust length fields */
1085 dump_smt(smc,(struct smt_header *)sif,"SIF Configuration Reply") ;
1086 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1090 * generate and send SIF operation response
1093 static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
1094 u_long tid, int local)
1095 /* struct fddi_addr *dest; dest address */
1096 /* u_long tid; transaction id */
1098 struct smt_sif_operation *sif ;
1104 #ifndef CONCENTRATOR
1105 if (smc->s.sas == SMT_SAS)
1109 if (!(mb = smt_build_frame(smc,SMT_SIF_OPER,SMT_REPLY,
1110 SIZEOF_SMT_SIF_OPERATION+ports*sizeof(struct smt_p_lem))))
1112 sif = smtod(mb, struct smt_sif_operation *) ;
1113 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1114 smt_fill_mac_status(smc,&sif->status) ; /* set mac status */
1115 smt_fill_mac_counter(smc,&sif->mc) ; /* set mac counter field */
1116 smt_fill_mac_fnc(smc,&sif->fnc) ; /* set frame not copied counter */
1117 smt_fill_manufacturer(smc,&sif->man) ; /* set manufacturer field */
1118 smt_fill_user(smc,&sif->user) ; /* set user field */
1119 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1121 * set link error mon information
1124 smt_fill_lem(smc,sif->lem,PS) ;
1127 for (i = 0 ; i < ports ; i++) {
1128 smt_fill_lem(smc,&sif->lem[i],i) ;
1132 sif->smt.smt_dest = *dest ; /* destination address */
1133 sif->smt.smt_tid = tid ; /* transaction ID */
1134 dump_smt(smc,(struct smt_header *)sif,"SIF Operation Reply") ;
1135 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1139 * get and initialize SMT frame
1141 SMbuf *smt_build_frame(struct s_smc *smc, int class, int type,
1145 struct smt_header *smt ;
1148 if (!smc->r.sm_ma_avail) {
1152 if (!(mb = smt_get_mbuf(smc)))
1155 mb->sm_len = length ;
1156 smt = smtod(mb, struct smt_header *) ;
1157 smt->smt_dest = fddi_broadcast ; /* set dest = broadcast */
1158 smt->smt_class = class ;
1159 smt->smt_type = type ;
1162 case SMT_SIF_CONFIG :
1165 smt->smt_version = SMT_VID ;
1168 smt->smt_version = SMT_VID_2 ;
1171 smt->smt_tid = smt_get_tid(smc) ; /* set transaction ID */
1173 smt->smt_len = length - sizeof(struct smt_header) ;
1177 static void smt_add_frame_len(SMbuf *mb, int len)
1179 struct smt_header *smt ;
1181 smt = smtod(mb, struct smt_header *) ;
1182 smt->smt_len += len ;
1189 * fill values in UNA parameter
1191 static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una)
1193 SMTSETPARA(una,SMT_P_UNA) ;
1195 una->una_node = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1199 * fill values in SDE parameter
1201 static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde)
1203 SMTSETPARA(sde,SMT_P_SDE) ;
1204 sde->sde_non_master = smc->mib.fddiSMTNonMaster_Ct ;
1205 sde->sde_master = smc->mib.fddiSMTMaster_Ct ;
1206 sde->sde_mac_count = NUMMACS ; /* only 1 MAC */
1208 sde->sde_type = SMT_SDE_CONCENTRATOR ;
1210 sde->sde_type = SMT_SDE_STATION ;
1215 * fill in values in station state parameter
1217 static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state)
1222 SMTSETPARA(state,SMT_P_STATE) ;
1225 /* determine topology */
1227 if (smc->mib.fddiSMTPeerWrapFlag) {
1228 top |= SMT_ST_WRAPPED ; /* state wrapped */
1231 if (cfm_status_unattached(smc)) {
1232 top |= SMT_ST_UNATTACHED ; /* unattached concentrator */
1235 if ((twist = pcm_status_twisted(smc)) & 1) {
1236 top |= SMT_ST_TWISTED_A ; /* twisted cable */
1239 top |= SMT_ST_TWISTED_B ; /* twisted cable */
1244 if (pcm_rooted_station(smc))
1245 top |= SMT_ST_ROOTED_S ;
1246 if (smc->mib.a[0].fddiPATHSbaPayload != 0)
1247 top |= SMT_ST_SYNC_SERVICE ;
1248 state->st_topology = top ;
1249 state->st_dupl_addr =
1250 ((smc->mib.m[MAC0].fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0 ) |
1251 (smc->mib.m[MAC0].fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0)) ;
1255 * fill values in timestamp parameter
1257 static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts)
1260 SMTSETPARA(ts,SMT_P_TIMESTAMP) ;
1261 smt_set_timestamp(smc,ts->ts_time) ;
1264 void smt_set_timestamp(struct s_smc *smc, u_char *p)
1270 * timestamp is 64 bits long ; resolution is 80 nS
1271 * our clock resolution is 10mS
1272 * 10mS/80ns = 125000 ~ 2^17 = 131072
1274 utime = smt_get_time() ;
1275 time = utime * 100 ;
1276 time /= TICKS_PER_SECOND ;
1278 p[1] = (u_char)((time>>(8+8+8+8-1)) & 1) ;
1279 p[2] = (u_char)(time>>(8+8+8-1)) ;
1280 p[3] = (u_char)(time>>(8+8-1)) ;
1281 p[4] = (u_char)(time>>(8-1)) ;
1282 p[5] = (u_char)(time<<1) ;
1283 p[6] = (u_char)(smc->sm.uniq_ticks>>8) ;
1284 p[7] = (u_char)smc->sm.uniq_ticks ;
1286 * make sure we don't wrap: restart whenever the upper digits change
1288 if (utime != smc->sm.uniq_time) {
1289 smc->sm.uniq_ticks = 0 ;
1291 smc->sm.uniq_ticks++ ;
1292 smc->sm.uniq_time = utime ;
1296 * fill values in station policy parameter
1298 static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy)
1306 * MIB para 101b (fddiSMTConnectionPolicy) coding
1307 * is different from 0005 coding
1309 static u_char ansi_weirdness[16] = {
1310 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1312 SMTSETPARA(policy,SMT_P_POLICY) ;
1315 in = smc->mib.fddiSMTConnectionPolicy ;
1316 for (i = 0, map = ansi_weirdness ; i < 16 ; i++) {
1322 policy->pl_config = smc->mib.fddiSMTConfigPolicy ;
1323 policy->pl_connect = out ;
1327 * fill values in latency equivalent parameter
1329 static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency)
1331 SMTSETPARA(latency,SMT_P_LATENCY) ;
1333 latency->lt_phyout_idx1 = phy_index(smc,0) ;
1334 latency->lt_latency1 = 10 ; /* in octets (byte clock) */
1336 * note: latency has two phy entries by definition
1337 * for a SAS, the 2nd one is null
1339 if (smc->s.sas == SMT_DAS) {
1340 latency->lt_phyout_idx2 = phy_index(smc,1) ;
1341 latency->lt_latency2 = 10 ; /* in octets (byte clock) */
1344 latency->lt_phyout_idx2 = 0 ;
1345 latency->lt_latency2 = 0 ;
1350 * fill values in MAC neighbors parameter
1352 static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor)
1354 SMTSETPARA(neighbor,SMT_P_NEIGHBORS) ;
1356 neighbor->nb_mib_index = INDEX_MAC ;
1357 neighbor->nb_mac_index = mac_index(smc,1) ;
1358 neighbor->nb_una = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1359 neighbor->nb_dna = smc->mib.m[MAC0].fddiMACDownstreamNbr ;
1363 * fill values in path descriptor
1366 #define ALLPHYS NUMPHYS
1368 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1371 static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path)
1373 SK_LOC_DECL(int,type) ;
1374 SK_LOC_DECL(int,state) ;
1375 SK_LOC_DECL(int,remote) ;
1376 SK_LOC_DECL(int,mac) ;
1380 struct smt_phy_rec *phy ;
1381 struct smt_mac_rec *pd_mac ;
1384 sizeof(struct smt_mac_rec) * NUMMACS +
1385 sizeof(struct smt_phy_rec) * ALLPHYS ;
1386 path->para.p_type = SMT_P_PATH ;
1387 path->para.p_len = len - PARA_LEN ;
1390 for (p = 0,phy = path->pd_phy ; p < ALLPHYS ; p++, phy++) {
1392 #ifndef CONCENTRATOR
1393 if (smc->s.sas == SMT_SAS)
1396 pcm_status_state(smc,physp,&type,&state,&remote,&mac) ;
1397 #ifdef LITTLE_ENDIAN
1398 phy->phy_mib_index = smt_swap_short((u_short)p+INDEX_PORT) ;
1400 phy->phy_mib_index = p+INDEX_PORT ;
1402 phy->phy_type = type ;
1403 phy->phy_connect_state = state ;
1404 phy->phy_remote_type = remote ;
1405 phy->phy_remote_mac = mac ;
1406 phy->phy_resource_idx = phy_con_resource_index(smc,p) ;
1410 pd_mac = (struct smt_mac_rec *) phy ;
1411 pd_mac->mac_addr = smc->mib.m[MAC0].fddiMACSMTAddress ;
1412 pd_mac->mac_resource_idx = mac_con_resource_index(smc,1) ;
1417 * fill values in mac status
1419 static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st)
1421 SMTSETPARA(st,SMT_P_MAC_STATUS) ;
1423 st->st_mib_index = INDEX_MAC ;
1424 st->st_mac_index = mac_index(smc,1) ;
1426 mac_update_counter(smc) ;
1428 * timer values are represented in SMT as 2's complement numbers
1429 * units : internal : 2's complement BCLK
1431 st->st_t_req = smc->mib.m[MAC0].fddiMACT_Req ;
1432 st->st_t_neg = smc->mib.m[MAC0].fddiMACT_Neg ;
1433 st->st_t_max = smc->mib.m[MAC0].fddiMACT_Max ;
1434 st->st_tvx_value = smc->mib.m[MAC0].fddiMACTvxValue ;
1435 st->st_t_min = smc->mib.m[MAC0].fddiMACT_Min ;
1437 st->st_sba = smc->mib.a[PATH0].fddiPATHSbaPayload ;
1438 st->st_frame_ct = smc->mib.m[MAC0].fddiMACFrame_Ct ;
1439 st->st_error_ct = smc->mib.m[MAC0].fddiMACError_Ct ;
1440 st->st_lost_ct = smc->mib.m[MAC0].fddiMACLost_Ct ;
1444 * fill values in LEM status
1446 static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy)
1448 struct fddi_mib_p *mib ;
1450 mib = smc->y[phy].mib ;
1452 SMTSETPARA(lem,SMT_P_LEM) ;
1453 lem->lem_mib_index = phy+INDEX_PORT ;
1454 lem->lem_phy_index = phy_index(smc,phy) ;
1456 lem->lem_cutoff = mib->fddiPORTLer_Cutoff ;
1457 lem->lem_alarm = mib->fddiPORTLer_Alarm ;
1458 /* long term bit error rate */
1459 lem->lem_estimate = mib->fddiPORTLer_Estimate ;
1460 /* # of rejected connections */
1461 lem->lem_reject_ct = mib->fddiPORTLem_Reject_Ct ;
1462 lem->lem_ct = mib->fddiPORTLem_Ct ; /* total number of errors */
1466 * fill version parameter
1468 static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers)
1471 SMTSETPARA(vers,SMT_P_VERSION) ;
1473 vers->v_n = 1 ; /* one version is enough .. */
1475 vers->v_version[0] = SMT_VID_2 ;
1481 * fill frame status capabilities
1484 * note: this para 200B is NOT in swap table, because it's also set in
1487 static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc)
1490 SMTSETPARA(fsc,SMT_P_FSC) ;
1492 fsc->fsc_mac_index = INDEX_MAC ; /* this is MIB ; MIB is NOT
1496 fsc->fsc_value = FSC_TYPE0 ; /* "normal" node */
1497 #ifdef LITTLE_ENDIAN
1498 fsc->fsc_mac_index = smt_swap_short(INDEX_MAC) ;
1499 fsc->fsc_value = smt_swap_short(FSC_TYPE0) ;
1505 * fill mac counter field
1507 static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc)
1509 SMTSETPARA(mc,SMT_P_MAC_COUNTER) ;
1510 mc->mc_mib_index = INDEX_MAC ;
1511 mc->mc_index = mac_index(smc,1) ;
1512 mc->mc_receive_ct = smc->mib.m[MAC0].fddiMACCopied_Ct ;
1513 mc->mc_transmit_ct = smc->mib.m[MAC0].fddiMACTransmit_Ct ;
1517 * fill mac frame not copied counter
1519 static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc)
1521 SMTSETPARA(fnc,SMT_P_MAC_FNC) ;
1522 fnc->nc_mib_index = INDEX_MAC ;
1523 fnc->nc_index = mac_index(smc,1) ;
1524 fnc->nc_counter = smc->mib.m[MAC0].fddiMACNotCopied_Ct ;
1529 * fill manufacturer field
1531 static void smt_fill_manufacturer(struct s_smc *smc,
1532 struct smp_p_manufacturer *man)
1534 SMTSETPARA(man,SMT_P_MANUFACTURER) ;
1535 memcpy((char *) man->mf_data,
1536 (char *) smc->mib.fddiSMTManufacturerData,
1537 sizeof(man->mf_data)) ;
1543 static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user)
1545 SMTSETPARA(user,SMT_P_USER) ;
1546 memcpy((char *) user->us_data,
1547 (char *) smc->mib.fddiSMTUserData,
1548 sizeof(user->us_data)) ;
1554 static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount)
1557 SMTSETPARA(setcount,SMT_P_SETCOUNT) ;
1558 setcount->count = smc->mib.fddiSMTSetCount.count ;
1559 memcpy((char *)setcount->timestamp,
1560 (char *)smc->mib.fddiSMTSetCount.timestamp,8) ;
1566 static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
1572 SMTSETPARA(echo,SMT_P_ECHODATA) ;
1573 echo->para.p_len = len ;
1574 for (p = echo->ec_data ; len ; len--) {
1575 *p++ = (u_char) seed ;
1582 * called from CFM if configuration changes
1584 void smt_clear_una_dna(struct s_smc *smc)
1586 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1587 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
1590 static void smt_clear_old_una_dna(struct s_smc *smc)
1592 smc->mib.m[MAC0].fddiMACOldUpstreamNbr = SMT_Unknown ;
1593 smc->mib.m[MAC0].fddiMACOldDownstreamNbr = SMT_Unknown ;
1596 u_long smt_get_tid(struct s_smc *smc)
1599 while ((tid = ++(smc->sm.smt_tid) ^ SMT_TID_MAGIC) == 0)
1601 return(tid & 0x3fffffffL) ;
1606 * table of parameter lengths
1608 static const struct smt_pdef {
1613 { SMT_P_UNA, sizeof(struct smt_p_una) ,
1615 { SMT_P_SDE, sizeof(struct smt_p_sde) ,
1617 { SMT_P_STATE, sizeof(struct smt_p_state) ,
1618 SWAP_SMT_P_STATE } ,
1619 { SMT_P_TIMESTAMP,sizeof(struct smt_p_timestamp) ,
1620 SWAP_SMT_P_TIMESTAMP } ,
1621 { SMT_P_POLICY, sizeof(struct smt_p_policy) ,
1622 SWAP_SMT_P_POLICY } ,
1623 { SMT_P_LATENCY, sizeof(struct smt_p_latency) ,
1624 SWAP_SMT_P_LATENCY } ,
1625 { SMT_P_NEIGHBORS,sizeof(struct smt_p_neighbor) ,
1626 SWAP_SMT_P_NEIGHBORS } ,
1627 { SMT_P_PATH, sizeof(struct smt_p_path) ,
1629 { SMT_P_MAC_STATUS,sizeof(struct smt_p_mac_status) ,
1630 SWAP_SMT_P_MAC_STATUS } ,
1631 { SMT_P_LEM, sizeof(struct smt_p_lem) ,
1633 { SMT_P_MAC_COUNTER,sizeof(struct smt_p_mac_counter) ,
1634 SWAP_SMT_P_MAC_COUNTER } ,
1635 { SMT_P_MAC_FNC,sizeof(struct smt_p_mac_fnc) ,
1636 SWAP_SMT_P_MAC_FNC } ,
1637 { SMT_P_PRIORITY,sizeof(struct smt_p_priority) ,
1638 SWAP_SMT_P_PRIORITY } ,
1639 { SMT_P_EB,sizeof(struct smt_p_eb) ,
1641 { SMT_P_MANUFACTURER,sizeof(struct smp_p_manufacturer) ,
1642 SWAP_SMT_P_MANUFACTURER } ,
1643 { SMT_P_REASON, sizeof(struct smt_p_reason) ,
1644 SWAP_SMT_P_REASON } ,
1645 { SMT_P_REFUSED, sizeof(struct smt_p_refused) ,
1646 SWAP_SMT_P_REFUSED } ,
1647 { SMT_P_VERSION, sizeof(struct smt_p_version) ,
1648 SWAP_SMT_P_VERSION } ,
1650 { SMT_P0015, sizeof(struct smt_p_0015) , SWAP_SMT_P0015 } ,
1651 { SMT_P0016, sizeof(struct smt_p_0016) , SWAP_SMT_P0016 } ,
1652 { SMT_P0017, sizeof(struct smt_p_0017) , SWAP_SMT_P0017 } ,
1653 { SMT_P0018, sizeof(struct smt_p_0018) , SWAP_SMT_P0018 } ,
1654 { SMT_P0019, sizeof(struct smt_p_0019) , SWAP_SMT_P0019 } ,
1655 { SMT_P001A, sizeof(struct smt_p_001a) , SWAP_SMT_P001A } ,
1656 { SMT_P001B, sizeof(struct smt_p_001b) , SWAP_SMT_P001B } ,
1657 { SMT_P001C, sizeof(struct smt_p_001c) , SWAP_SMT_P001C } ,
1658 { SMT_P001D, sizeof(struct smt_p_001d) , SWAP_SMT_P001D } ,
1661 { SMT_P_FSC, sizeof(struct smt_p_fsc) ,
1665 { SMT_P_SETCOUNT,0, SWAP_SMT_P_SETCOUNT } ,
1666 { SMT_P1048, 0, SWAP_SMT_P1048 } ,
1667 { SMT_P208C, 0, SWAP_SMT_P208C } ,
1668 { SMT_P208D, 0, SWAP_SMT_P208D } ,
1669 { SMT_P208E, 0, SWAP_SMT_P208E } ,
1670 { SMT_P208F, 0, SWAP_SMT_P208F } ,
1671 { SMT_P2090, 0, SWAP_SMT_P2090 } ,
1673 { SMT_P320B, sizeof(struct smt_p_320b) , SWAP_SMT_P320B } ,
1674 { SMT_P320F, sizeof(struct smt_p_320f) , SWAP_SMT_P320F } ,
1675 { SMT_P3210, sizeof(struct smt_p_3210) , SWAP_SMT_P3210 } ,
1677 { SMT_P4050, 0, SWAP_SMT_P4050 } ,
1678 { SMT_P4051, 0, SWAP_SMT_P4051 } ,
1679 { SMT_P4052, 0, SWAP_SMT_P4052 } ,
1680 { SMT_P4053, 0, SWAP_SMT_P4053 } ,
1683 #define N_SMT_PLEN (sizeof(smt_pdef)/sizeof(smt_pdef[0]))
1685 int smt_check_para(struct s_smc *smc, struct smt_header *sm,
1686 const u_short list[])
1688 const u_short *p = list ;
1690 if (!sm_to_para(smc,sm,(int) *p)) {
1691 DB_SMT("SMT: smt_check_para - missing para %x\n",*p,0);
1699 void *sm_to_para(struct s_smc *smc, struct smt_header *sm, int para)
1709 p = (char *)(sm+1) ; /* pointer to info */
1711 if (((struct smt_para *)p)->p_type == para)
1712 found = (void *) p ;
1713 plen = ((struct smt_para *)p)->p_len + PARA_LEN ;
1717 DB_SMT("SMT : sm_to_para - length error %d\n",plen,0) ;
1720 if ((plen & 3) && (para != SMT_P_ECHODATA)) {
1721 DB_SMT("SMT : sm_to_para - odd length %d\n",plen,0) ;
1732 * send ANTC data test frame
1734 void fddi_send_antc(struct s_smc *smc, struct fddi_addr *dest)
1740 struct smt_header *smt ;
1744 mb = smt_get_mbuf() ;
1745 mb->sm_len = 3000+12 ;
1746 p = smtod(mb, char *) + 12 ;
1747 for (i = 0 ; i < 3000 ; i++)
1750 smt = smtod(mb, struct smt_header *) ;
1751 smt->smt_dest = *dest ;
1752 smt->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
1753 smt_send_mbuf(smc,mb,FC_ASYNC_LLC) ;
1759 #define hextoasc(x) "0123456789abcdef"[x]
1761 char *addr_to_string(struct fddi_addr *addr)
1764 static char string[6*3] = "****" ;
1766 for (i = 0 ; i < 6 ; i++) {
1767 string[i*3] = hextoasc((addr->a[i]>>4)&0xf) ;
1768 string[i*3+1] = hextoasc((addr->a[i])&0xf) ;
1769 string[i*3+2] = ':' ;
1777 smt_ifconfig(int argc, char *argv[])
1779 if (argc >= 2 && !strcmp(argv[0],"opt_bypass") &&
1780 !strcmp(argv[1],"yes")) {
1781 smc->mib.fddiSMTBypassPresent = 1 ;
1784 return(amdfddi_config(0,argc,argv)) ;
1789 * return static mac index
1791 static int mac_index(struct s_smc *smc, int mac)
1798 return((smc->s.sas == SMT_SAS) ? 2 : 3) ;
1803 * return static phy index
1805 static int phy_index(struct s_smc *smc, int phy)
1812 * return dynamic mac connection resource index
1814 static int mac_con_resource_index(struct s_smc *smc, int mac)
1819 return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_MAC))) ;
1822 switch (smc->mib.fddiSMTCF_State) {
1825 case SC11_C_WRAP_S :
1827 case SC10_C_WRAP_B :
1831 return(smc->s.sas == SMT_SAS ? 2 : 3) ;
1836 * return dynamic phy connection resource index
1838 static int phy_con_resource_index(struct s_smc *smc, int phy)
1841 return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_PHY(phy)))) ;
1843 switch (smc->mib.fddiSMTCF_State) {
1845 return(phy == PA ? 3 : 2) ;
1846 case SC10_C_WRAP_B :
1847 return(phy == PA ? 1 : 3) ;
1849 return(phy == PA ? 3 : 1) ;
1851 return(phy == PA ? 2 : 3) ;
1852 case SC11_C_WRAP_S :
1860 static int entity_to_index(struct s_smc *smc, int e)
1862 if (e == ENTITY_MAC)
1863 return(mac_index(smc,1)) ;
1865 return(phy_index(smc,e - ENTITY_PHY(0))) ;
1869 #ifdef LITTLE_ENDIAN
1870 static int smt_swap_short(u_short s)
1872 return(((s>>8)&0xff)|((s&0xff)<<8)) ;
1875 void smt_swap_para(struct smt_header *sm, int len, int direction)
1876 /* int direction; 0 encode 1 decode */
1878 struct smt_para *pa ;
1879 const struct smt_pdef *pd ;
1885 /* printf("smt_swap_para sm %x len %d dir %d\n",
1888 smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
1891 len -= sizeof(struct smt_header) ;
1893 p = (char *) (sm + 1) ;
1895 pa = (struct smt_para *) p ;
1898 pa->p_type = smt_swap_short(pa->p_type) ;
1899 pa->p_len = smt_swap_short(pa->p_len) ;
1905 * note: paras can have 0 length !
1910 for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
1911 if (pd->ptype == type)
1914 if (i && pd->pswap) {
1915 smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
1922 static void smt_string_swap(char *data, const char *format, int len)
1924 const char *open_paren = 0 ;
1927 while (len > 0 && *format) {
1930 open_paren = format ;
1933 format = open_paren ;
1944 data += *format - '0' ;
1945 len -= *format - '0' ;
1973 void smt_swap_para(struct smt_header *sm, int len, int direction)
1974 /* int direction; 0 encode 1 decode */
1978 SK_UNUSED(direction) ;
1985 int smt_action(struct s_smc *smc, int class, int code, int index)
1989 DB_SMT("SMT: action %d code %d\n",class,code) ;
1991 case SMT_STATION_ACTION :
1993 case SMT_STATION_ACTION_CONNECT :
1994 smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
1995 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
1997 case SMT_STATION_ACTION_DISCONNECT :
1998 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
1999 smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
2000 RS_SET(smc,RS_DISCONNECT) ;
2001 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
2002 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
2003 smt_get_event_word(smc));
2005 case SMT_STATION_ACTION_PATHTEST :
2006 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
2007 FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
2008 smt_get_event_word(smc));
2010 case SMT_STATION_ACTION_SELFTEST :
2011 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
2012 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
2013 smt_get_event_word(smc));
2015 case SMT_STATION_ACTION_DISABLE_A :
2016 if (smc->y[PA].pc_mode == PM_PEER) {
2017 RS_SET(smc,RS_EVENT) ;
2018 queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
2021 case SMT_STATION_ACTION_DISABLE_B :
2022 if (smc->y[PB].pc_mode == PM_PEER) {
2023 RS_SET(smc,RS_EVENT) ;
2024 queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
2027 case SMT_STATION_ACTION_DISABLE_M :
2028 for (port = 0 ; port < NUMPHYS ; port++) {
2029 if (smc->mib.p[port].fddiPORTMy_Type != TM)
2031 RS_SET(smc,RS_EVENT) ;
2032 queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
2039 case SMT_PORT_ACTION :
2041 case SMT_PORT_ACTION_ENABLE :
2044 case SMT_PORT_ACTION_DISABLE :
2045 event = PC_DISABLE ;
2047 case SMT_PORT_ACTION_MAINT :
2050 case SMT_PORT_ACTION_START :
2053 case SMT_PORT_ACTION_STOP :
2059 queue_event(smc,EVENT_PCM+index,event) ;
2069 * set T_Req in MIB (Path Attribute)
2070 * calculate new values for MAC
2071 * if change required
2076 void smt_change_t_neg(struct s_smc *smc, u_long tneg)
2078 smc->mib.a[PATH0].fddiPATHMaxT_Req = tneg ;
2080 if (smt_set_mac_opvalues(smc)) {
2081 RS_SET(smc,RS_EVENT) ;
2082 smc->sm.please_reconnect = 1 ;
2083 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
2088 * canonical conversion of <len> bytes beginning form *data
2091 void hwm_conv_can(struct s_smc *smc, char *data, int len)
2097 for (i = len; i ; i--, data++) {
2098 *data = canonical[*(u_char *)data] ;
2103 #endif /* no SLIM_SMT */