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(char *data
, const char *format
, int len
);
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 static 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 static 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_broadcast(const struct fddi_addr
*addr
)
140 return(*(u_short
*)(&addr
->a
[0]) == 0xffff &&
141 *(u_short
*)(&addr
->a
[2]) == 0xffff &&
142 *(u_short
*)(&addr
->a
[4]) == 0xffff ) ;
145 static inline int is_individual(const struct fddi_addr
*addr
)
147 return(!(addr
->a
[0] & GROUP_ADDR
)) ;
150 static inline int is_equal(const struct fddi_addr
*addr1
,
151 const struct fddi_addr
*addr2
)
153 return(*(u_short
*)(&addr1
->a
[0]) == *(u_short
*)(&addr2
->a
[0]) &&
154 *(u_short
*)(&addr1
->a
[2]) == *(u_short
*)(&addr2
->a
[2]) &&
155 *(u_short
*)(&addr1
->a
[4]) == *(u_short
*)(&addr2
->a
[4]) ) ;
159 * list of mandatory paras in frames
161 static const u_short plist_nif
[] = { SMT_P_UNA
,SMT_P_SDE
,SMT_P_STATE
,0 } ;
166 void smt_agent_init(struct s_smc
*smc
)
173 smc
->mib
.m
[MAC0
].fddiMACSMTAddress
= smc
->hw
.fddi_home_addr
;
176 * get OUI address from driver (bia == built-in-address)
178 smc
->mib
.fddiSMTStationId
.sid_oem
[0] = 0 ;
179 smc
->mib
.fddiSMTStationId
.sid_oem
[1] = 0 ;
180 driver_get_bia(smc
,&smc
->mib
.fddiSMTStationId
.sid_node
) ;
181 for (i
= 0 ; i
< 6 ; i
++) {
182 smc
->mib
.fddiSMTStationId
.sid_node
.a
[i
] =
183 canonical
[smc
->mib
.fddiSMTStationId
.sid_node
.a
[i
]] ;
185 smc
->mib
.fddiSMTManufacturerData
[0] =
186 smc
->mib
.fddiSMTStationId
.sid_node
.a
[0] ;
187 smc
->mib
.fddiSMTManufacturerData
[1] =
188 smc
->mib
.fddiSMTStationId
.sid_node
.a
[1] ;
189 smc
->mib
.fddiSMTManufacturerData
[2] =
190 smc
->mib
.fddiSMTStationId
.sid_node
.a
[2] ;
191 smc
->sm
.smt_tid
= 0 ;
192 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
= DA_NONE
;
193 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
= FALSE
;
195 smt_clear_una_dna(smc
) ;
196 smt_clear_old_una_dna(smc
) ;
198 for (i
= 0 ; i
< SMT_MAX_TEST
; i
++)
199 smc
->sm
.pend
[i
] = 0 ;
200 smc
->sm
.please_reconnect
= 0 ;
201 smc
->sm
.uniq_ticks
= 0 ;
212 void smt_agent_task(struct s_smc
*smc
)
214 smt_timer_start(smc
,&smc
->sm
.smt_timer
, (u_long
)1000000L,
215 EV_TOKEN(EVENT_SMT
,SM_TIMER
)) ;
216 DB_SMT("SMT agent task\n",0,0) ;
219 #ifndef SMT_REAL_TOKEN_CT
220 void smt_emulate_token_ct(struct s_smc
*smc
, int mac_index
)
226 time
= smt_get_time();
227 count
= ((time
- smc
->sm
.last_tok_time
[mac_index
]) *
228 100)/TICKS_PER_SECOND
;
231 * Only when ring is up we will have a token count. The
232 * flag is unfortunatly a single instance value. This
233 * doesn't matter now, because we currently have only
236 if (smc
->hw
.mac_ring_is_up
){
237 smc
->mib
.m
[mac_index
].fddiMACToken_Ct
+= count
;
240 /* Remember current time */
241 smc
->sm
.last_tok_time
[mac_index
] = time
;
247 void smt_event(struct s_smc
*smc
, int event
)
250 #ifndef SMT_REAL_TOKEN_CT
255 if (smc
->sm
.please_reconnect
) {
256 smc
->sm
.please_reconnect
-- ;
257 if (smc
->sm
.please_reconnect
== 0) {
259 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
263 if (event
== SM_FAST
)
267 * timer for periodic cleanup in driver
268 * reset and start the watchdog (FM2)
272 smt_timer_poll(smc
) ;
273 smt_start_watchdog(smc
) ;
277 ess_timer_poll(smc
) ;
281 sba_timer_poll(smc
) ;
284 smt_srf_event(smc
,0,0,0) ;
286 #endif /* no SLIM_SMT */
288 time
= smt_get_time() ;
290 if (time
- smc
->sm
.smt_last_lem
>= TICKS_PER_SECOND
*8) {
292 * Use 8 sec. for the time intervall, it simplifies the
295 struct fddi_mib_m
*mib
;
302 * calculate LEM bit error rate
304 sm_lem_evaluate(smc
) ;
305 smc
->sm
.smt_last_lem
= time
;
311 mac_update_counter(smc
) ;
314 (mib
->fddiMACLost_Ct
- mib
->fddiMACOld_Lost_Ct
) +
315 (mib
->fddiMACError_Ct
- mib
->fddiMACOld_Error_Ct
) ;
317 (mib
->fddiMACFrame_Ct
- mib
->fddiMACOld_Frame_Ct
) +
318 (mib
->fddiMACLost_Ct
- mib
->fddiMACOld_Lost_Ct
) ;
319 mib
->fddiMACFrameErrorRatio
= div_ratio(upper
,lower
) ;
322 ((!mib
->fddiMACFrameErrorThreshold
&&
323 mib
->fddiMACError_Ct
!= mib
->fddiMACOld_Error_Ct
) ||
324 (mib
->fddiMACFrameErrorRatio
>
325 mib
->fddiMACFrameErrorThreshold
)) ;
327 if (cond
!= mib
->fddiMACFrameErrorFlag
)
328 smt_srf_event(smc
,SMT_COND_MAC_FRAME_ERROR
,
332 (mib
->fddiMACNotCopied_Ct
- mib
->fddiMACOld_NotCopied_Ct
) ;
335 (mib
->fddiMACCopied_Ct
- mib
->fddiMACOld_Copied_Ct
) ;
336 mib
->fddiMACNotCopiedRatio
= div_ratio(upper
,lower
) ;
339 ((!mib
->fddiMACNotCopiedThreshold
&&
340 mib
->fddiMACNotCopied_Ct
!=
341 mib
->fddiMACOld_NotCopied_Ct
)||
342 (mib
->fddiMACNotCopiedRatio
>
343 mib
->fddiMACNotCopiedThreshold
)) ;
345 if (cond
!= mib
->fddiMACNotCopiedFlag
)
346 smt_srf_event(smc
,SMT_COND_MAC_NOT_COPIED
,
352 mib
->fddiMACOld_Frame_Ct
= mib
->fddiMACFrame_Ct
;
353 mib
->fddiMACOld_Copied_Ct
= mib
->fddiMACCopied_Ct
;
354 mib
->fddiMACOld_Error_Ct
= mib
->fddiMACError_Ct
;
355 mib
->fddiMACOld_Lost_Ct
= mib
->fddiMACLost_Ct
;
356 mib
->fddiMACOld_NotCopied_Ct
= mib
->fddiMACNotCopied_Ct
;
359 * Check port EBError Condition
361 for (port
= 0; port
< NUMPHYS
; port
++) {
362 phy
= &smc
->y
[port
] ;
364 if (!phy
->mib
->fddiPORTHardwarePresent
) {
368 cond
= (phy
->mib
->fddiPORTEBError_Ct
-
369 phy
->mib
->fddiPORTOldEBError_Ct
> 5) ;
371 /* If ratio is more than 5 in 8 seconds
374 smt_srf_event(smc
,SMT_COND_PORT_EB_ERROR
,
375 (int) (INDEX_PORT
+ phy
->np
) ,cond
) ;
380 phy
->mib
->fddiPORTOldEBError_Ct
=
381 phy
->mib
->fddiPORTEBError_Ct
;
384 #endif /* no SLIM_SMT */
389 if (time
- smc
->sm
.smt_last_notify
>= (u_long
)
390 (smc
->mib
.fddiSMTTT_Notify
* TICKS_PER_SECOND
) ) {
392 * we can either send an announcement or a request
393 * a request will trigger a reply so that we can update
395 * note: same tid must be used until reply is received
397 if (!smc
->sm
.pend
[SMT_TID_NIF
])
398 smc
->sm
.pend
[SMT_TID_NIF
] = smt_get_tid(smc
) ;
399 smt_send_nif(smc
,&fddi_broadcast
, FC_SMT_NSA
,
400 smc
->sm
.pend
[SMT_TID_NIF
], SMT_REQUEST
,0) ;
401 smc
->sm
.smt_last_notify
= time
;
407 if (smc
->sm
.smt_tvu
&&
408 time
- smc
->sm
.smt_tvu
> 228*TICKS_PER_SECOND
) {
409 DB_SMT("SMT : UNA expired\n",0,0) ;
410 smc
->sm
.smt_tvu
= 0 ;
412 if (!is_equal(&smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
414 /* Do not update unknown address */
415 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
=
416 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
418 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
= SMT_Unknown
;
419 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
= FALSE
;
421 * Make sure the fddiMACUNDA_Flag = FALSE is
422 * included in the SRF so we don't generate
423 * a separate SRF for the deassertion of this
427 smt_srf_event(smc
, SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
430 if (smc
->sm
.smt_tvd
&&
431 time
- smc
->sm
.smt_tvd
> 228*TICKS_PER_SECOND
) {
432 DB_SMT("SMT : DNA expired\n",0,0) ;
433 smc
->sm
.smt_tvd
= 0 ;
434 if (!is_equal(&smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
,
436 /* Do not update unknown address */
437 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
=
438 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
440 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
= SMT_Unknown
;
441 smt_srf_event(smc
, SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
445 #endif /* no SLIM_SMT */
447 #ifndef SMT_REAL_TOKEN_CT
449 * Token counter emulation section. If hardware supports the token
450 * count, the token counter will be updated in mac_update_counter.
452 for (i
= MAC0
; i
< NUMMACS
; i
++ ){
453 if (time
- smc
->sm
.last_tok_time
[i
] > 2*TICKS_PER_SECOND
){
454 smt_emulate_token_ct( smc
, i
);
459 smt_timer_start(smc
,&smc
->sm
.smt_timer
, (u_long
)1000000L,
460 EV_TOKEN(EVENT_SMT
,SM_TIMER
)) ;
463 static int div_ratio(u_long upper
, u_long lower
)
465 if ((upper
<<16L) < upper
)
466 upper
= 0xffff0000L
;
471 return((int)(upper
/lower
)) ;
477 * receive packet handler
479 void smt_received_pack(struct s_smc
*smc
, SMbuf
*mb
, int fs
)
480 /* int fs; frame status */
482 struct smt_header
*sm
;
489 case FC_SMT_LAN_LOC
:
494 smt_free_mbuf(smc
,mb
) ;
498 smc
->mib
.m
[MAC0
].fddiMACSMTCopied_Ct
++ ;
499 sm
= smtod(mb
,struct smt_header
*) ;
500 local
= ((fs
& L_INDICATOR
) != 0) ;
501 hwm_conv_can(smc
,(char *)sm
,12) ;
503 /* check destination address */
504 if (is_individual(&sm
->smt_dest
) && !is_my_addr(smc
,&sm
->smt_dest
)) {
505 smt_free_mbuf(smc
,mb
) ;
508 #if 0 /* for DUP recognition, do NOT filter them */
509 /* ignore loop back packets */
510 if (is_my_addr(smc
,&sm
->smt_source
) && !local
) {
511 smt_free_mbuf(smc
,mb
) ;
516 smt_swap_para(sm
,(int) mb
->sm_len
,1) ;
517 DB_SMT("SMT : received packet [%s] at 0x%x\n",
518 smt_type_name
[m_fc(mb
) & 0xf],sm
) ;
519 DB_SMT("SMT : version %d, class %s\n",sm
->smt_version
,
520 smt_class_name
[(sm
->smt_class
>LAST_CLASS
)?0 : sm
->smt_class
]) ;
526 if (m_fc(mb
) == FC_SMT_NSA
&& sm
->smt_class
== SMT_NIF
&&
527 (sm
->smt_type
== SMT_ANNOUNCE
|| sm
->smt_type
== SMT_REQUEST
)) {
534 * ignore any packet with NSA and A-indicator set
536 if ( (fs
& A_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
) {
537 DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
538 addr_to_string(&sm
->smt_source
),0) ;
539 smt_free_mbuf(smc
,mb
) ;
544 * ignore frames with illegal length
546 if (((sm
->smt_class
== SMT_ECF
) && (sm
->smt_len
> SMT_MAX_ECHO_LEN
)) ||
547 ((sm
->smt_class
!= SMT_ECF
) && (sm
->smt_len
> SMT_MAX_INFO_LEN
))) {
548 smt_free_mbuf(smc
,mb
) ;
555 switch (sm
->smt_class
) {
557 case SMT_SIF_CONFIG
:
560 if (sm
->smt_version
!= SMT_VID
)
564 if (sm
->smt_version
!= SMT_VID_2
)
569 DB_SMT("SMT : version = %d, dest = %s\n",
570 sm
->smt_version
,addr_to_string(&sm
->smt_source
)) ;
571 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_VERSION
,local
) ;
572 smt_free_mbuf(smc
,mb
) ;
575 if ((sm
->smt_len
> mb
->sm_len
- sizeof(struct smt_header
)) ||
576 ((sm
->smt_len
& 3) && (sm
->smt_class
!= SMT_ECF
))) {
577 DB_SMT("SMT: info length error, len = %d\n",sm
->smt_len
,0) ;
578 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_LENGTH
,local
) ;
579 smt_free_mbuf(smc
,mb
) ;
582 switch (sm
->smt_class
) {
584 if (smt_check_para(smc
,sm
,plist_nif
)) {
585 DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
588 switch (sm
->smt_type
) {
591 if (!(fs
& C_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
592 && is_broadcast(&sm
->smt_dest
)) {
593 struct smt_p_state
*st
;
597 &smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
599 DB_SMT("SMT : updated my UNA = %s\n",
600 addr_to_string(&sm
->smt_source
),0) ;
601 if (!is_equal(&smc
->mib
.m
[MAC0
].
602 fddiMACUpstreamNbr
,&SMT_Unknown
)){
603 /* Do not update unknown address */
604 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
=
605 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
608 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
=
611 SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
613 smt_echo_test(smc
,0) ;
615 smc
->sm
.smt_tvu
= smt_get_time() ;
616 st
= (struct smt_p_state
*)
617 sm_to_para(smc
,sm
,SMT_P_STATE
) ;
619 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
=
620 (st
->st_dupl_addr
& SMT_ST_MY_DUPA
) ?
625 if ((sm
->smt_type
== SMT_REQUEST
) &&
626 is_individual(&sm
->smt_source
) &&
627 ((!(fs
& A_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
) ||
628 (m_fc(mb
) != FC_SMT_NSA
))) {
629 DB_SMT("SMT : replying to NIF request %s\n",
630 addr_to_string(&sm
->smt_source
),0) ;
631 smt_send_nif(smc
,&sm
->smt_source
,
638 DB_SMT("SMT : received NIF response from %s\n",
639 addr_to_string(&sm
->smt_source
),0) ;
640 if (fs
& A_INDICATOR
) {
641 smc
->sm
.pend
[SMT_TID_NIF
] = 0 ;
642 DB_SMT("SMT : duplicate address\n",0,0) ;
643 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
=
645 smc
->r
.dup_addr_test
= DA_FAILED
;
646 queue_event(smc
,EVENT_RMT
,RM_DUP_ADDR
) ;
647 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
= TRUE
;
651 if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_NIF
]) {
652 smc
->sm
.pend
[SMT_TID_NIF
] = 0 ;
655 &smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
,
657 DB_SMT("SMT : updated my DNA\n",0,0) ;
658 if (!is_equal(&smc
->mib
.m
[MAC0
].
659 fddiMACDownstreamNbr
, &SMT_Unknown
)){
660 /* Do not update unknown address */
661 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
=
662 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
665 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
=
668 SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
670 smt_echo_test(smc
,1) ;
672 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
= FALSE
;
674 smc
->sm
.smt_tvd
= smt_get_time() ;
675 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
=
677 if (smc
->r
.dup_addr_test
!= DA_PASSED
) {
678 smc
->r
.dup_addr_test
= DA_PASSED
;
679 queue_event(smc
,EVENT_RMT
,RM_DUP_ADDR
) ;
682 else if (sm
->smt_tid
==
683 smc
->sm
.pend
[SMT_TID_NIF_TEST
]) {
684 DB_SMT("SMT : NIF test TID ok\n",0,0) ;
687 DB_SMT("SMT : expected TID %lx, got %lx\n",
688 smc
->sm
.pend
[SMT_TID_NIF
],sm
->smt_tid
) ;
696 case SMT_SIF_CONFIG
: /* station information */
697 if (sm
->smt_type
!= SMT_REQUEST
)
699 DB_SMT("SMT : replying to SIF Config request from %s\n",
700 addr_to_string(&sm
->smt_source
),0) ;
701 smt_send_sif_config(smc
,&sm
->smt_source
,sm
->smt_tid
,local
) ;
703 case SMT_SIF_OPER
: /* station information */
704 if (sm
->smt_type
!= SMT_REQUEST
)
706 DB_SMT("SMT : replying to SIF Operation request from %s\n",
707 addr_to_string(&sm
->smt_source
),0) ;
708 smt_send_sif_operation(smc
,&sm
->smt_source
,sm
->smt_tid
,local
) ;
710 case SMT_ECF
: /* echo frame */
711 switch (sm
->smt_type
) {
713 smc
->mib
.priv
.fddiPRIVECF_Reply_Rx
++ ;
714 DB_SMT("SMT: received ECF reply from %s\n",
715 addr_to_string(&sm
->smt_source
),0) ;
716 if (sm_to_para(smc
,sm
,SMT_P_ECHODATA
) == 0) {
717 DB_SMT("SMT: ECHODATA missing\n",0,0) ;
720 if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF
]) {
721 DB_SMT("SMT : ECF test TID ok\n",0,0) ;
723 else if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF_UNA
]) {
724 DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
726 else if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF_DNA
]) {
727 DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
730 DB_SMT("SMT : expected TID %lx, got %lx\n",
731 smc
->sm
.pend
[SMT_TID_ECF
],
736 smc
->mib
.priv
.fddiPRIVECF_Req_Rx
++ ;
738 if (sm
->smt_len
&& !sm_to_para(smc
,sm
,SMT_P_ECHODATA
)) {
739 DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
740 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_LENGTH
,
744 DB_SMT("SMT - sending ECF reply to %s\n",
745 addr_to_string(&sm
->smt_source
),0) ;
747 /* set destination addr. & reply */
748 sm
->smt_dest
= sm
->smt_source
;
749 sm
->smt_type
= SMT_REPLY
;
750 dump_smt(smc
,sm
,"ECF REPLY") ;
751 smc
->mib
.priv
.fddiPRIVECF_Reply_Tx
++ ;
752 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
753 return ; /* DON'T free mbuf */
761 case SMT_RAF
: /* resource allocation */
763 DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
764 fs
= ess_raf_received_pack(smc
,mb
,sm
,fs
) ;
768 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
769 sba_raf_received_pack(smc
,sm
,fs
) ;
772 case SMT_RDF
: /* request denied */
773 smc
->mib
.priv
.fddiPRIVRDF_Rx
++ ;
775 case SMT_ESF
: /* extended service - not supported */
776 if (sm
->smt_type
== SMT_REQUEST
) {
777 DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
778 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_CLASS
,local
) ;
783 if (sm
->smt_type
!= SMT_REQUEST
)
785 /* update statistics */
786 if (sm
->smt_class
== SMT_PMF_GET
)
787 smc
->mib
.priv
.fddiPRIVPMF_Get_Rx
++ ;
789 smc
->mib
.priv
.fddiPRIVPMF_Set_Rx
++ ;
791 * ignore PMF SET with I/G set
793 if ((sm
->smt_class
== SMT_PMF_SET
) &&
794 !is_individual(&sm
->smt_dest
)) {
795 DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
798 smt_pmf_received_pack(smc
,mb
, local
) ;
801 dump_smt(smc
,sm
,"SRF received") ;
804 if (sm
->smt_type
!= SMT_REQUEST
)
807 * For frames with unknown class:
808 * we need to send a RDF frame according to 8.1.3.1.1,
809 * only if it is a REQUEST.
811 DB_SMT("SMT : class = %d, send RDF to %s\n",
812 sm
->smt_class
, addr_to_string(&sm
->smt_source
)) ;
814 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_CLASS
,local
) ;
819 DB_SMT("SMT: discarding invalid frame, reason = %d\n",
822 smt_free_mbuf(smc
,mb
) ;
825 static void update_dac(struct s_smc
*smc
, int report
)
829 cond
= ( smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
|
830 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
) != 0 ;
831 if (report
&& (cond
!= smc
->mib
.m
[MAC0
].fddiMACDuplicateAddressCond
))
832 smt_srf_event(smc
, SMT_COND_MAC_DUP_ADDR
,INDEX_MAC
,cond
) ;
834 smc
->mib
.m
[MAC0
].fddiMACDuplicateAddressCond
= cond
;
843 void smt_send_frame(struct s_smc
*smc
, SMbuf
*mb
, int fc
, int local
)
844 /* SMbuf *mb; buffer to send */
845 /* int fc; FC value */
847 struct smt_header
*sm
;
849 if (!smc
->r
.sm_ma_avail
&& !local
) {
850 smt_free_mbuf(smc
,mb
) ;
853 sm
= smtod(mb
,struct smt_header
*) ;
854 sm
->smt_source
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
855 sm
->smt_sid
= smc
->mib
.fddiSMTStationId
;
857 smt_swap_para(sm
,(int) mb
->sm_len
,0) ; /* swap para & header */
858 hwm_conv_can(smc
,(char *)sm
,12) ; /* convert SA and DA */
859 smc
->mib
.m
[MAC0
].fddiMACSMTTransmit_Ct
++ ;
860 smt_send_mbuf(smc
,mb
,local
? FC_SMT_LOC
: fc
) ;
864 * generate and send RDF
866 static void smt_send_rdf(struct s_smc
*smc
, SMbuf
*rej
, int fc
, int reason
,
868 /* SMbuf *rej; mbuf of offending frame */
869 /* int fc; FC of denied frame */
870 /* int reason; reason code */
873 struct smt_header
*sm
; /* header of offending frame */
874 struct smt_rdf
*rdf
;
878 sm
= smtod(rej
,struct smt_header
*) ;
879 if (sm
->smt_type
!= SMT_REQUEST
)
882 DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
883 addr_to_string(&sm
->smt_source
),reason
) ;
887 * note: get framelength from MAC length, NOT from SMT header
888 * smt header length is included in sm_len
890 frame_len
= rej
->sm_len
;
892 if (!(mb
=smt_build_frame(smc
,SMT_RDF
,SMT_REPLY
,sizeof(struct smt_rdf
))))
894 rdf
= smtod(mb
,struct smt_rdf
*) ;
895 rdf
->smt
.smt_tid
= sm
->smt_tid
; /* use TID from sm */
896 rdf
->smt
.smt_dest
= sm
->smt_source
; /* set dest = source */
899 rdf
->reason
.para
.p_type
= SMT_P_REASON
;
900 rdf
->reason
.para
.p_len
= sizeof(struct smt_p_reason
) - PARA_LEN
;
901 rdf
->reason
.rdf_reason
= reason
;
904 rdf
->version
.para
.p_type
= SMT_P_VERSION
;
905 rdf
->version
.para
.p_len
= sizeof(struct smt_p_version
) - PARA_LEN
;
906 rdf
->version
.v_pad
= 0 ;
907 rdf
->version
.v_n
= 1 ;
908 rdf
->version
.v_index
= 1 ;
909 rdf
->version
.v_version
[0] = SMT_VID_2
;
910 rdf
->version
.v_pad2
= 0 ;
913 if ((unsigned) frame_len
<= SMT_MAX_INFO_LEN
- sizeof(*rdf
) +
914 2*sizeof(struct smt_header
))
917 len
= SMT_MAX_INFO_LEN
- sizeof(*rdf
) +
918 2*sizeof(struct smt_header
) ;
919 /* make length multiple of 4 */
921 rdf
->refused
.para
.p_type
= SMT_P_REFUSED
;
922 /* length of para is smt_frame + ref_fc */
923 rdf
->refused
.para
.p_len
= len
+ 4 ;
924 rdf
->refused
.ref_fc
= fc
;
927 smt_swap_para(sm
,frame_len
,0) ;
929 memcpy((char *) &rdf
->refused
.ref_header
,(char *) sm
,len
) ;
931 len
-= sizeof(struct smt_header
) ;
933 rdf
->smt
.smt_len
+= len
;
935 dump_smt(smc
,(struct smt_header
*)rdf
,"RDF") ;
936 smc
->mib
.priv
.fddiPRIVRDF_Tx
++ ;
937 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
941 * generate and send NIF
943 static void smt_send_nif(struct s_smc
*smc
, const struct fddi_addr
*dest
,
944 int fc
, u_long tid
, int type
, int local
)
945 /* struct fddi_addr *dest; dest address */
946 /* int fc; frame control */
947 /* u_long tid; transaction id */
948 /* int type; frame type */
950 struct smt_nif
*nif
;
953 if (!(mb
= smt_build_frame(smc
,SMT_NIF
,type
,sizeof(struct smt_nif
))))
955 nif
= smtod(mb
, struct smt_nif
*) ;
956 smt_fill_una(smc
,&nif
->una
) ; /* set UNA */
957 smt_fill_sde(smc
,&nif
->sde
) ; /* set station descriptor */
958 smt_fill_state(smc
,&nif
->state
) ; /* set state information */
960 smt_fill_fsc(smc
,&nif
->fsc
) ; /* set frame status cap. */
962 nif
->smt
.smt_dest
= *dest
; /* destination address */
963 nif
->smt
.smt_tid
= tid
; /* transaction ID */
964 dump_smt(smc
,(struct smt_header
*)nif
,"NIF") ;
965 smt_send_frame(smc
,mb
,fc
,local
) ;
970 * send NIF request (test purpose)
972 static void smt_send_nif_request(struct s_smc
*smc
, struct fddi_addr
*dest
)
974 smc
->sm
.pend
[SMT_TID_NIF_TEST
] = smt_get_tid(smc
) ;
975 smt_send_nif(smc
,dest
, FC_SMT_INFO
, smc
->sm
.pend
[SMT_TID_NIF_TEST
],
980 * send ECF request (test purpose)
982 static void smt_send_ecf_request(struct s_smc
*smc
, struct fddi_addr
*dest
,
985 smc
->sm
.pend
[SMT_TID_ECF
] = smt_get_tid(smc
) ;
986 smt_send_ecf(smc
,dest
, FC_SMT_INFO
, smc
->sm
.pend
[SMT_TID_ECF
],
994 static void smt_echo_test(struct s_smc
*smc
, int dna
)
998 smc
->sm
.pend
[dna
? SMT_TID_ECF_DNA
: SMT_TID_ECF_UNA
] =
999 tid
= smt_get_tid(smc
) ;
1000 smt_send_ecf(smc
, dna
?
1001 &smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
:
1002 &smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
1003 FC_SMT_INFO
,tid
, SMT_REQUEST
, (SMT_TEST_ECHO_LEN
& ~3)-8) ;
1007 * generate and send ECF
1009 static void smt_send_ecf(struct s_smc
*smc
, struct fddi_addr
*dest
, int fc
,
1010 u_long tid
, int type
, int len
)
1011 /* struct fddi_addr *dest; dest address */
1012 /* int fc; frame control */
1013 /* u_long tid; transaction id */
1014 /* int type; frame type */
1015 /* int len; frame length */
1017 struct smt_ecf
*ecf
;
1020 if (!(mb
= smt_build_frame(smc
,SMT_ECF
,type
,SMT_ECF_LEN
+ len
)))
1022 ecf
= smtod(mb
, struct smt_ecf
*) ;
1024 smt_fill_echo(smc
,&ecf
->ec_echo
,tid
,len
) ; /* set ECHO */
1025 ecf
->smt
.smt_dest
= *dest
; /* destination address */
1026 ecf
->smt
.smt_tid
= tid
; /* transaction ID */
1027 smc
->mib
.priv
.fddiPRIVECF_Req_Tx
++ ;
1028 smt_send_frame(smc
,mb
,fc
,0) ;
1032 * generate and send SIF config response
1035 static void smt_send_sif_config(struct s_smc
*smc
, struct fddi_addr
*dest
,
1036 u_long tid
, int local
)
1037 /* struct fddi_addr *dest; dest address */
1038 /* u_long tid; transaction id */
1040 struct smt_sif_config
*sif
;
1043 if (!(mb
= smt_build_frame(smc
,SMT_SIF_CONFIG
,SMT_REPLY
,
1044 SIZEOF_SMT_SIF_CONFIG
)))
1047 sif
= smtod(mb
, struct smt_sif_config
*) ;
1048 smt_fill_timestamp(smc
,&sif
->ts
) ; /* set time stamp */
1049 smt_fill_sde(smc
,&sif
->sde
) ; /* set station descriptor */
1050 smt_fill_version(smc
,&sif
->version
) ; /* set version information */
1051 smt_fill_state(smc
,&sif
->state
) ; /* set state information */
1052 smt_fill_policy(smc
,&sif
->policy
) ; /* set station policy */
1053 smt_fill_latency(smc
,&sif
->latency
); /* set station latency */
1054 smt_fill_neighbor(smc
,&sif
->neighbor
); /* set station neighbor */
1055 smt_fill_setcount(smc
,&sif
->setcount
) ; /* set count */
1056 len
= smt_fill_path(smc
,&sif
->path
); /* set station path descriptor*/
1057 sif
->smt
.smt_dest
= *dest
; /* destination address */
1058 sif
->smt
.smt_tid
= tid
; /* transaction ID */
1059 smt_add_frame_len(mb
,len
) ; /* adjust length fields */
1060 dump_smt(smc
,(struct smt_header
*)sif
,"SIF Configuration Reply") ;
1061 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
1065 * generate and send SIF operation response
1068 static void smt_send_sif_operation(struct s_smc
*smc
, struct fddi_addr
*dest
,
1069 u_long tid
, int local
)
1070 /* struct fddi_addr *dest; dest address */
1071 /* u_long tid; transaction id */
1073 struct smt_sif_operation
*sif
;
1079 #ifndef CONCENTRATOR
1080 if (smc
->s
.sas
== SMT_SAS
)
1084 if (!(mb
= smt_build_frame(smc
,SMT_SIF_OPER
,SMT_REPLY
,
1085 SIZEOF_SMT_SIF_OPERATION
+ports
*sizeof(struct smt_p_lem
))))
1087 sif
= smtod(mb
, struct smt_sif_operation
*) ;
1088 smt_fill_timestamp(smc
,&sif
->ts
) ; /* set time stamp */
1089 smt_fill_mac_status(smc
,&sif
->status
) ; /* set mac status */
1090 smt_fill_mac_counter(smc
,&sif
->mc
) ; /* set mac counter field */
1091 smt_fill_mac_fnc(smc
,&sif
->fnc
) ; /* set frame not copied counter */
1092 smt_fill_manufacturer(smc
,&sif
->man
) ; /* set manufacturer field */
1093 smt_fill_user(smc
,&sif
->user
) ; /* set user field */
1094 smt_fill_setcount(smc
,&sif
->setcount
) ; /* set count */
1096 * set link error mon information
1099 smt_fill_lem(smc
,sif
->lem
,PS
) ;
1102 for (i
= 0 ; i
< ports
; i
++) {
1103 smt_fill_lem(smc
,&sif
->lem
[i
],i
) ;
1107 sif
->smt
.smt_dest
= *dest
; /* destination address */
1108 sif
->smt
.smt_tid
= tid
; /* transaction ID */
1109 dump_smt(smc
,(struct smt_header
*)sif
,"SIF Operation Reply") ;
1110 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
1114 * get and initialize SMT frame
1116 SMbuf
*smt_build_frame(struct s_smc
*smc
, int class, int type
,
1120 struct smt_header
*smt
;
1123 if (!smc
->r
.sm_ma_avail
) {
1127 if (!(mb
= smt_get_mbuf(smc
)))
1130 mb
->sm_len
= length
;
1131 smt
= smtod(mb
, struct smt_header
*) ;
1132 smt
->smt_dest
= fddi_broadcast
; /* set dest = broadcast */
1133 smt
->smt_class
= class ;
1134 smt
->smt_type
= type
;
1137 case SMT_SIF_CONFIG
:
1140 smt
->smt_version
= SMT_VID
;
1143 smt
->smt_version
= SMT_VID_2
;
1146 smt
->smt_tid
= smt_get_tid(smc
) ; /* set transaction ID */
1148 smt
->smt_len
= length
- sizeof(struct smt_header
) ;
1152 static void smt_add_frame_len(SMbuf
*mb
, int len
)
1154 struct smt_header
*smt
;
1156 smt
= smtod(mb
, struct smt_header
*) ;
1157 smt
->smt_len
+= len
;
1164 * fill values in UNA parameter
1166 static void smt_fill_una(struct s_smc
*smc
, struct smt_p_una
*una
)
1168 SMTSETPARA(una
,SMT_P_UNA
) ;
1170 una
->una_node
= smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
1174 * fill values in SDE parameter
1176 static void smt_fill_sde(struct s_smc
*smc
, struct smt_p_sde
*sde
)
1178 SMTSETPARA(sde
,SMT_P_SDE
) ;
1179 sde
->sde_non_master
= smc
->mib
.fddiSMTNonMaster_Ct
;
1180 sde
->sde_master
= smc
->mib
.fddiSMTMaster_Ct
;
1181 sde
->sde_mac_count
= NUMMACS
; /* only 1 MAC */
1183 sde
->sde_type
= SMT_SDE_CONCENTRATOR
;
1185 sde
->sde_type
= SMT_SDE_STATION
;
1190 * fill in values in station state parameter
1192 static void smt_fill_state(struct s_smc
*smc
, struct smt_p_state
*state
)
1197 SMTSETPARA(state
,SMT_P_STATE
) ;
1200 /* determine topology */
1202 if (smc
->mib
.fddiSMTPeerWrapFlag
) {
1203 top
|= SMT_ST_WRAPPED
; /* state wrapped */
1206 if (cfm_status_unattached(smc
)) {
1207 top
|= SMT_ST_UNATTACHED
; /* unattached concentrator */
1210 if ((twist
= pcm_status_twisted(smc
)) & 1) {
1211 top
|= SMT_ST_TWISTED_A
; /* twisted cable */
1214 top
|= SMT_ST_TWISTED_B
; /* twisted cable */
1219 if (pcm_rooted_station(smc
))
1220 top
|= SMT_ST_ROOTED_S
;
1221 if (smc
->mib
.a
[0].fddiPATHSbaPayload
!= 0)
1222 top
|= SMT_ST_SYNC_SERVICE
;
1223 state
->st_topology
= top
;
1224 state
->st_dupl_addr
=
1225 ((smc
->mib
.m
[MAC0
].fddiMACDA_Flag
? SMT_ST_MY_DUPA
: 0 ) |
1226 (smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
? SMT_ST_UNA_DUPA
: 0)) ;
1230 * fill values in timestamp parameter
1232 static void smt_fill_timestamp(struct s_smc
*smc
, struct smt_p_timestamp
*ts
)
1235 SMTSETPARA(ts
,SMT_P_TIMESTAMP
) ;
1236 smt_set_timestamp(smc
,ts
->ts_time
) ;
1239 void smt_set_timestamp(struct s_smc
*smc
, u_char
*p
)
1245 * timestamp is 64 bits long ; resolution is 80 nS
1246 * our clock resolution is 10mS
1247 * 10mS/80ns = 125000 ~ 2^17 = 131072
1249 utime
= smt_get_time() ;
1250 time
= utime
* 100 ;
1251 time
/= TICKS_PER_SECOND
;
1253 p
[1] = (u_char
)((time
>>(8+8+8+8-1)) & 1) ;
1254 p
[2] = (u_char
)(time
>>(8+8+8-1)) ;
1255 p
[3] = (u_char
)(time
>>(8+8-1)) ;
1256 p
[4] = (u_char
)(time
>>(8-1)) ;
1257 p
[5] = (u_char
)(time
<<1) ;
1258 p
[6] = (u_char
)(smc
->sm
.uniq_ticks
>>8) ;
1259 p
[7] = (u_char
)smc
->sm
.uniq_ticks
;
1261 * make sure we don't wrap: restart whenever the upper digits change
1263 if (utime
!= smc
->sm
.uniq_time
) {
1264 smc
->sm
.uniq_ticks
= 0 ;
1266 smc
->sm
.uniq_ticks
++ ;
1267 smc
->sm
.uniq_time
= utime
;
1271 * fill values in station policy parameter
1273 static void smt_fill_policy(struct s_smc
*smc
, struct smt_p_policy
*policy
)
1281 * MIB para 101b (fddiSMTConnectionPolicy) coding
1282 * is different from 0005 coding
1284 static u_char ansi_weirdness
[16] = {
1285 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1287 SMTSETPARA(policy
,SMT_P_POLICY
) ;
1290 in
= smc
->mib
.fddiSMTConnectionPolicy
;
1291 for (i
= 0, map
= ansi_weirdness
; i
< 16 ; i
++) {
1297 policy
->pl_config
= smc
->mib
.fddiSMTConfigPolicy
;
1298 policy
->pl_connect
= out
;
1302 * fill values in latency equivalent parameter
1304 static void smt_fill_latency(struct s_smc
*smc
, struct smt_p_latency
*latency
)
1306 SMTSETPARA(latency
,SMT_P_LATENCY
) ;
1308 latency
->lt_phyout_idx1
= phy_index(smc
,0) ;
1309 latency
->lt_latency1
= 10 ; /* in octets (byte clock) */
1311 * note: latency has two phy entries by definition
1312 * for a SAS, the 2nd one is null
1314 if (smc
->s
.sas
== SMT_DAS
) {
1315 latency
->lt_phyout_idx2
= phy_index(smc
,1) ;
1316 latency
->lt_latency2
= 10 ; /* in octets (byte clock) */
1319 latency
->lt_phyout_idx2
= 0 ;
1320 latency
->lt_latency2
= 0 ;
1325 * fill values in MAC neighbors parameter
1327 static void smt_fill_neighbor(struct s_smc
*smc
, struct smt_p_neighbor
*neighbor
)
1329 SMTSETPARA(neighbor
,SMT_P_NEIGHBORS
) ;
1331 neighbor
->nb_mib_index
= INDEX_MAC
;
1332 neighbor
->nb_mac_index
= mac_index(smc
,1) ;
1333 neighbor
->nb_una
= smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
1334 neighbor
->nb_dna
= smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
1338 * fill values in path descriptor
1341 #define ALLPHYS NUMPHYS
1343 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1346 static int smt_fill_path(struct s_smc
*smc
, struct smt_p_path
*path
)
1348 SK_LOC_DECL(int,type
) ;
1349 SK_LOC_DECL(int,state
) ;
1350 SK_LOC_DECL(int,remote
) ;
1351 SK_LOC_DECL(int,mac
) ;
1355 struct smt_phy_rec
*phy
;
1356 struct smt_mac_rec
*pd_mac
;
1359 sizeof(struct smt_mac_rec
) * NUMMACS
+
1360 sizeof(struct smt_phy_rec
) * ALLPHYS
;
1361 path
->para
.p_type
= SMT_P_PATH
;
1362 path
->para
.p_len
= len
- PARA_LEN
;
1365 for (p
= 0,phy
= path
->pd_phy
; p
< ALLPHYS
; p
++, phy
++) {
1367 #ifndef CONCENTRATOR
1368 if (smc
->s
.sas
== SMT_SAS
)
1371 pcm_status_state(smc
,physp
,&type
,&state
,&remote
,&mac
) ;
1372 #ifdef LITTLE_ENDIAN
1373 phy
->phy_mib_index
= smt_swap_short((u_short
)p
+INDEX_PORT
) ;
1375 phy
->phy_mib_index
= p
+INDEX_PORT
;
1377 phy
->phy_type
= type
;
1378 phy
->phy_connect_state
= state
;
1379 phy
->phy_remote_type
= remote
;
1380 phy
->phy_remote_mac
= mac
;
1381 phy
->phy_resource_idx
= phy_con_resource_index(smc
,p
) ;
1385 pd_mac
= (struct smt_mac_rec
*) phy
;
1386 pd_mac
->mac_addr
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
1387 pd_mac
->mac_resource_idx
= mac_con_resource_index(smc
,1) ;
1392 * fill values in mac status
1394 static void smt_fill_mac_status(struct s_smc
*smc
, struct smt_p_mac_status
*st
)
1396 SMTSETPARA(st
,SMT_P_MAC_STATUS
) ;
1398 st
->st_mib_index
= INDEX_MAC
;
1399 st
->st_mac_index
= mac_index(smc
,1) ;
1401 mac_update_counter(smc
) ;
1403 * timer values are represented in SMT as 2's complement numbers
1404 * units : internal : 2's complement BCLK
1406 st
->st_t_req
= smc
->mib
.m
[MAC0
].fddiMACT_Req
;
1407 st
->st_t_neg
= smc
->mib
.m
[MAC0
].fddiMACT_Neg
;
1408 st
->st_t_max
= smc
->mib
.m
[MAC0
].fddiMACT_Max
;
1409 st
->st_tvx_value
= smc
->mib
.m
[MAC0
].fddiMACTvxValue
;
1410 st
->st_t_min
= smc
->mib
.m
[MAC0
].fddiMACT_Min
;
1412 st
->st_sba
= smc
->mib
.a
[PATH0
].fddiPATHSbaPayload
;
1413 st
->st_frame_ct
= smc
->mib
.m
[MAC0
].fddiMACFrame_Ct
;
1414 st
->st_error_ct
= smc
->mib
.m
[MAC0
].fddiMACError_Ct
;
1415 st
->st_lost_ct
= smc
->mib
.m
[MAC0
].fddiMACLost_Ct
;
1419 * fill values in LEM status
1421 static void smt_fill_lem(struct s_smc
*smc
, struct smt_p_lem
*lem
, int phy
)
1423 struct fddi_mib_p
*mib
;
1425 mib
= smc
->y
[phy
].mib
;
1427 SMTSETPARA(lem
,SMT_P_LEM
) ;
1428 lem
->lem_mib_index
= phy
+INDEX_PORT
;
1429 lem
->lem_phy_index
= phy_index(smc
,phy
) ;
1431 lem
->lem_cutoff
= mib
->fddiPORTLer_Cutoff
;
1432 lem
->lem_alarm
= mib
->fddiPORTLer_Alarm
;
1433 /* long term bit error rate */
1434 lem
->lem_estimate
= mib
->fddiPORTLer_Estimate
;
1435 /* # of rejected connections */
1436 lem
->lem_reject_ct
= mib
->fddiPORTLem_Reject_Ct
;
1437 lem
->lem_ct
= mib
->fddiPORTLem_Ct
; /* total number of errors */
1441 * fill version parameter
1443 static void smt_fill_version(struct s_smc
*smc
, struct smt_p_version
*vers
)
1446 SMTSETPARA(vers
,SMT_P_VERSION
) ;
1448 vers
->v_n
= 1 ; /* one version is enough .. */
1450 vers
->v_version
[0] = SMT_VID_2
;
1456 * fill frame status capabilities
1459 * note: this para 200B is NOT in swap table, because it's also set in
1462 static void smt_fill_fsc(struct s_smc
*smc
, struct smt_p_fsc
*fsc
)
1465 SMTSETPARA(fsc
,SMT_P_FSC
) ;
1467 fsc
->fsc_mac_index
= INDEX_MAC
; /* this is MIB ; MIB is NOT
1471 fsc
->fsc_value
= FSC_TYPE0
; /* "normal" node */
1472 #ifdef LITTLE_ENDIAN
1473 fsc
->fsc_mac_index
= smt_swap_short(INDEX_MAC
) ;
1474 fsc
->fsc_value
= smt_swap_short(FSC_TYPE0
) ;
1480 * fill mac counter field
1482 static void smt_fill_mac_counter(struct s_smc
*smc
, struct smt_p_mac_counter
*mc
)
1484 SMTSETPARA(mc
,SMT_P_MAC_COUNTER
) ;
1485 mc
->mc_mib_index
= INDEX_MAC
;
1486 mc
->mc_index
= mac_index(smc
,1) ;
1487 mc
->mc_receive_ct
= smc
->mib
.m
[MAC0
].fddiMACCopied_Ct
;
1488 mc
->mc_transmit_ct
= smc
->mib
.m
[MAC0
].fddiMACTransmit_Ct
;
1492 * fill mac frame not copied counter
1494 static void smt_fill_mac_fnc(struct s_smc
*smc
, struct smt_p_mac_fnc
*fnc
)
1496 SMTSETPARA(fnc
,SMT_P_MAC_FNC
) ;
1497 fnc
->nc_mib_index
= INDEX_MAC
;
1498 fnc
->nc_index
= mac_index(smc
,1) ;
1499 fnc
->nc_counter
= smc
->mib
.m
[MAC0
].fddiMACNotCopied_Ct
;
1504 * fill manufacturer field
1506 static void smt_fill_manufacturer(struct s_smc
*smc
,
1507 struct smp_p_manufacturer
*man
)
1509 SMTSETPARA(man
,SMT_P_MANUFACTURER
) ;
1510 memcpy((char *) man
->mf_data
,
1511 (char *) smc
->mib
.fddiSMTManufacturerData
,
1512 sizeof(man
->mf_data
)) ;
1518 static void smt_fill_user(struct s_smc
*smc
, struct smp_p_user
*user
)
1520 SMTSETPARA(user
,SMT_P_USER
) ;
1521 memcpy((char *) user
->us_data
,
1522 (char *) smc
->mib
.fddiSMTUserData
,
1523 sizeof(user
->us_data
)) ;
1529 static void smt_fill_setcount(struct s_smc
*smc
, struct smt_p_setcount
*setcount
)
1532 SMTSETPARA(setcount
,SMT_P_SETCOUNT
) ;
1533 setcount
->count
= smc
->mib
.fddiSMTSetCount
.count
;
1534 memcpy((char *)setcount
->timestamp
,
1535 (char *)smc
->mib
.fddiSMTSetCount
.timestamp
,8) ;
1541 static void smt_fill_echo(struct s_smc
*smc
, struct smt_p_echo
*echo
, u_long seed
,
1547 SMTSETPARA(echo
,SMT_P_ECHODATA
) ;
1548 echo
->para
.p_len
= len
;
1549 for (p
= echo
->ec_data
; len
; len
--) {
1550 *p
++ = (u_char
) seed
;
1557 * called from CFM if configuration changes
1559 static void smt_clear_una_dna(struct s_smc
*smc
)
1561 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
= SMT_Unknown
;
1562 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
= SMT_Unknown
;
1565 static void smt_clear_old_una_dna(struct s_smc
*smc
)
1567 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
= SMT_Unknown
;
1568 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
= SMT_Unknown
;
1571 u_long
smt_get_tid(struct s_smc
*smc
)
1574 while ((tid
= ++(smc
->sm
.smt_tid
) ^ SMT_TID_MAGIC
) == 0)
1576 return(tid
& 0x3fffffffL
) ;
1581 * table of parameter lengths
1583 static const struct smt_pdef
{
1588 { SMT_P_UNA
, sizeof(struct smt_p_una
) ,
1590 { SMT_P_SDE
, sizeof(struct smt_p_sde
) ,
1592 { SMT_P_STATE
, sizeof(struct smt_p_state
) ,
1593 SWAP_SMT_P_STATE
} ,
1594 { SMT_P_TIMESTAMP
,sizeof(struct smt_p_timestamp
) ,
1595 SWAP_SMT_P_TIMESTAMP
} ,
1596 { SMT_P_POLICY
, sizeof(struct smt_p_policy
) ,
1597 SWAP_SMT_P_POLICY
} ,
1598 { SMT_P_LATENCY
, sizeof(struct smt_p_latency
) ,
1599 SWAP_SMT_P_LATENCY
} ,
1600 { SMT_P_NEIGHBORS
,sizeof(struct smt_p_neighbor
) ,
1601 SWAP_SMT_P_NEIGHBORS
} ,
1602 { SMT_P_PATH
, sizeof(struct smt_p_path
) ,
1604 { SMT_P_MAC_STATUS
,sizeof(struct smt_p_mac_status
) ,
1605 SWAP_SMT_P_MAC_STATUS
} ,
1606 { SMT_P_LEM
, sizeof(struct smt_p_lem
) ,
1608 { SMT_P_MAC_COUNTER
,sizeof(struct smt_p_mac_counter
) ,
1609 SWAP_SMT_P_MAC_COUNTER
} ,
1610 { SMT_P_MAC_FNC
,sizeof(struct smt_p_mac_fnc
) ,
1611 SWAP_SMT_P_MAC_FNC
} ,
1612 { SMT_P_PRIORITY
,sizeof(struct smt_p_priority
) ,
1613 SWAP_SMT_P_PRIORITY
} ,
1614 { SMT_P_EB
,sizeof(struct smt_p_eb
) ,
1616 { SMT_P_MANUFACTURER
,sizeof(struct smp_p_manufacturer
) ,
1617 SWAP_SMT_P_MANUFACTURER
} ,
1618 { SMT_P_REASON
, sizeof(struct smt_p_reason
) ,
1619 SWAP_SMT_P_REASON
} ,
1620 { SMT_P_REFUSED
, sizeof(struct smt_p_refused
) ,
1621 SWAP_SMT_P_REFUSED
} ,
1622 { SMT_P_VERSION
, sizeof(struct smt_p_version
) ,
1623 SWAP_SMT_P_VERSION
} ,
1625 { SMT_P0015
, sizeof(struct smt_p_0015
) , SWAP_SMT_P0015
} ,
1626 { SMT_P0016
, sizeof(struct smt_p_0016
) , SWAP_SMT_P0016
} ,
1627 { SMT_P0017
, sizeof(struct smt_p_0017
) , SWAP_SMT_P0017
} ,
1628 { SMT_P0018
, sizeof(struct smt_p_0018
) , SWAP_SMT_P0018
} ,
1629 { SMT_P0019
, sizeof(struct smt_p_0019
) , SWAP_SMT_P0019
} ,
1630 { SMT_P001A
, sizeof(struct smt_p_001a
) , SWAP_SMT_P001A
} ,
1631 { SMT_P001B
, sizeof(struct smt_p_001b
) , SWAP_SMT_P001B
} ,
1632 { SMT_P001C
, sizeof(struct smt_p_001c
) , SWAP_SMT_P001C
} ,
1633 { SMT_P001D
, sizeof(struct smt_p_001d
) , SWAP_SMT_P001D
} ,
1636 { SMT_P_FSC
, sizeof(struct smt_p_fsc
) ,
1640 { SMT_P_SETCOUNT
,0, SWAP_SMT_P_SETCOUNT
} ,
1641 { SMT_P1048
, 0, SWAP_SMT_P1048
} ,
1642 { SMT_P208C
, 0, SWAP_SMT_P208C
} ,
1643 { SMT_P208D
, 0, SWAP_SMT_P208D
} ,
1644 { SMT_P208E
, 0, SWAP_SMT_P208E
} ,
1645 { SMT_P208F
, 0, SWAP_SMT_P208F
} ,
1646 { SMT_P2090
, 0, SWAP_SMT_P2090
} ,
1648 { SMT_P320B
, sizeof(struct smt_p_320b
) , SWAP_SMT_P320B
} ,
1649 { SMT_P320F
, sizeof(struct smt_p_320f
) , SWAP_SMT_P320F
} ,
1650 { SMT_P3210
, sizeof(struct smt_p_3210
) , SWAP_SMT_P3210
} ,
1652 { SMT_P4050
, 0, SWAP_SMT_P4050
} ,
1653 { SMT_P4051
, 0, SWAP_SMT_P4051
} ,
1654 { SMT_P4052
, 0, SWAP_SMT_P4052
} ,
1655 { SMT_P4053
, 0, SWAP_SMT_P4053
} ,
1658 #define N_SMT_PLEN (sizeof(smt_pdef)/sizeof(smt_pdef[0]))
1660 int smt_check_para(struct s_smc
*smc
, struct smt_header
*sm
,
1661 const u_short list
[])
1663 const u_short
*p
= list
;
1665 if (!sm_to_para(smc
,sm
,(int) *p
)) {
1666 DB_SMT("SMT: smt_check_para - missing para %x\n",*p
,0);
1674 void *sm_to_para(struct s_smc
*smc
, struct smt_header
*sm
, int para
)
1684 p
= (char *)(sm
+1) ; /* pointer to info */
1686 if (((struct smt_para
*)p
)->p_type
== para
)
1687 found
= (void *) p
;
1688 plen
= ((struct smt_para
*)p
)->p_len
+ PARA_LEN
;
1692 DB_SMT("SMT : sm_to_para - length error %d\n",plen
,0) ;
1695 if ((plen
& 3) && (para
!= SMT_P_ECHODATA
)) {
1696 DB_SMT("SMT : sm_to_para - odd length %d\n",plen
,0) ;
1707 * send ANTC data test frame
1709 void fddi_send_antc(struct s_smc
*smc
, struct fddi_addr
*dest
)
1715 struct smt_header
*smt
;
1719 mb
= smt_get_mbuf() ;
1720 mb
->sm_len
= 3000+12 ;
1721 p
= smtod(mb
, char *) + 12 ;
1722 for (i
= 0 ; i
< 3000 ; i
++)
1725 smt
= smtod(mb
, struct smt_header
*) ;
1726 smt
->smt_dest
= *dest
;
1727 smt
->smt_source
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
1728 smt_send_mbuf(smc
,mb
,FC_ASYNC_LLC
) ;
1734 #define hextoasc(x) "0123456789abcdef"[x]
1736 char *addr_to_string(struct fddi_addr
*addr
)
1739 static char string
[6*3] = "****" ;
1741 for (i
= 0 ; i
< 6 ; i
++) {
1742 string
[i
*3] = hextoasc((addr
->a
[i
]>>4)&0xf) ;
1743 string
[i
*3+1] = hextoasc((addr
->a
[i
])&0xf) ;
1744 string
[i
*3+2] = ':' ;
1752 smt_ifconfig(int argc
, char *argv
[])
1754 if (argc
>= 2 && !strcmp(argv
[0],"opt_bypass") &&
1755 !strcmp(argv
[1],"yes")) {
1756 smc
->mib
.fddiSMTBypassPresent
= 1 ;
1759 return(amdfddi_config(0,argc
,argv
)) ;
1764 * return static mac index
1766 static int mac_index(struct s_smc
*smc
, int mac
)
1773 return((smc
->s
.sas
== SMT_SAS
) ? 2 : 3) ;
1778 * return static phy index
1780 static int phy_index(struct s_smc
*smc
, int phy
)
1787 * return dynamic mac connection resource index
1789 static int mac_con_resource_index(struct s_smc
*smc
, int mac
)
1794 return(entity_to_index(smc
,cem_get_downstream(smc
,ENTITY_MAC
))) ;
1797 switch (smc
->mib
.fddiSMTCF_State
) {
1800 case SC11_C_WRAP_S
:
1802 case SC10_C_WRAP_B
:
1806 return(smc
->s
.sas
== SMT_SAS
? 2 : 3) ;
1811 * return dynamic phy connection resource index
1813 static int phy_con_resource_index(struct s_smc
*smc
, int phy
)
1816 return(entity_to_index(smc
,cem_get_downstream(smc
,ENTITY_PHY(phy
)))) ;
1818 switch (smc
->mib
.fddiSMTCF_State
) {
1820 return(phy
== PA
? 3 : 2) ;
1821 case SC10_C_WRAP_B
:
1822 return(phy
== PA
? 1 : 3) ;
1824 return(phy
== PA
? 3 : 1) ;
1826 return(phy
== PA
? 2 : 3) ;
1827 case SC11_C_WRAP_S
:
1835 static int entity_to_index(struct s_smc
*smc
, int e
)
1837 if (e
== ENTITY_MAC
)
1838 return(mac_index(smc
,1)) ;
1840 return(phy_index(smc
,e
- ENTITY_PHY(0))) ;
1844 #ifdef LITTLE_ENDIAN
1845 static int smt_swap_short(u_short s
)
1847 return(((s
>>8)&0xff)|((s
&0xff)<<8)) ;
1850 void smt_swap_para(struct smt_header
*sm
, int len
, int direction
)
1851 /* int direction; 0 encode 1 decode */
1853 struct smt_para
*pa
;
1854 const struct smt_pdef
*pd
;
1860 /* printf("smt_swap_para sm %x len %d dir %d\n",
1863 smt_string_swap((char *)sm
,SWAP_SMTHEADER
,len
) ;
1866 len
-= sizeof(struct smt_header
) ;
1868 p
= (char *) (sm
+ 1) ;
1870 pa
= (struct smt_para
*) p
;
1873 pa
->p_type
= smt_swap_short(pa
->p_type
) ;
1874 pa
->p_len
= smt_swap_short(pa
->p_len
) ;
1880 * note: paras can have 0 length !
1885 for (i
= N_SMT_PLEN
, pd
= smt_pdef
; i
; i
--,pd
++) {
1886 if (pd
->ptype
== type
)
1889 if (i
&& pd
->pswap
) {
1890 smt_string_swap(p
+PARA_LEN
,pd
->pswap
,len
) ;
1897 static void smt_string_swap(char *data
, const char *format
, int len
)
1899 const char *open_paren
= NULL
;
1902 while (len
> 0 && *format
) {
1905 open_paren
= format
;
1908 format
= open_paren
;
1919 data
+= *format
- '0' ;
1920 len
-= *format
- '0' ;
1948 void smt_swap_para(struct smt_header
*sm
, int len
, int direction
)
1949 /* int direction; 0 encode 1 decode */
1953 SK_UNUSED(direction
) ;
1960 int smt_action(struct s_smc
*smc
, int class, int code
, int index
)
1964 DB_SMT("SMT: action %d code %d\n",class,code
) ;
1966 case SMT_STATION_ACTION
:
1968 case SMT_STATION_ACTION_CONNECT
:
1969 smc
->mib
.fddiSMTRemoteDisconnectFlag
= FALSE
;
1970 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
1972 case SMT_STATION_ACTION_DISCONNECT
:
1973 queue_event(smc
,EVENT_ECM
,EC_DISCONNECT
) ;
1974 smc
->mib
.fddiSMTRemoteDisconnectFlag
= TRUE
;
1975 RS_SET(smc
,RS_DISCONNECT
) ;
1976 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1977 FDDI_SMT_EVENT
, (u_long
) FDDI_REMOTE_DISCONNECT
,
1978 smt_get_event_word(smc
));
1980 case SMT_STATION_ACTION_PATHTEST
:
1981 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1982 FDDI_SMT_EVENT
, (u_long
) FDDI_PATH_TEST
,
1983 smt_get_event_word(smc
));
1985 case SMT_STATION_ACTION_SELFTEST
:
1986 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1987 FDDI_SMT_EVENT
, (u_long
) FDDI_REMOTE_SELF_TEST
,
1988 smt_get_event_word(smc
));
1990 case SMT_STATION_ACTION_DISABLE_A
:
1991 if (smc
->y
[PA
].pc_mode
== PM_PEER
) {
1992 RS_SET(smc
,RS_EVENT
) ;
1993 queue_event(smc
,EVENT_PCM
+PA
,PC_DISABLE
) ;
1996 case SMT_STATION_ACTION_DISABLE_B
:
1997 if (smc
->y
[PB
].pc_mode
== PM_PEER
) {
1998 RS_SET(smc
,RS_EVENT
) ;
1999 queue_event(smc
,EVENT_PCM
+PB
,PC_DISABLE
) ;
2002 case SMT_STATION_ACTION_DISABLE_M
:
2003 for (port
= 0 ; port
< NUMPHYS
; port
++) {
2004 if (smc
->mib
.p
[port
].fddiPORTMy_Type
!= TM
)
2006 RS_SET(smc
,RS_EVENT
) ;
2007 queue_event(smc
,EVENT_PCM
+port
,PC_DISABLE
) ;
2014 case SMT_PORT_ACTION
:
2016 case SMT_PORT_ACTION_ENABLE
:
2019 case SMT_PORT_ACTION_DISABLE
:
2020 event
= PC_DISABLE
;
2022 case SMT_PORT_ACTION_MAINT
:
2025 case SMT_PORT_ACTION_START
:
2028 case SMT_PORT_ACTION_STOP
:
2034 queue_event(smc
,EVENT_PCM
+index
,event
) ;
2043 * canonical conversion of <len> bytes beginning form *data
2046 static void hwm_conv_can(struct s_smc
*smc
, char *data
, int len
)
2052 for (i
= len
; i
; i
--, data
++) {
2053 *data
= canonical
[*(u_char
*)data
] ;
2058 #endif /* no SLIM_SMT */