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 ******************************************************************************/
21 #include <linux/bitrev.h>
24 #include "h/smtstate.h"
27 static const char ID_sccs
[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
33 #define m_fc(mb) ((mb)->sm_data[0])
35 #define SMT_TID_MAGIC 0x1f0a7b3c
38 static const char *const smt_type_name
[] = {
39 "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
40 "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
41 "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
42 "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
45 static const char *const smt_class_name
[] = {
46 "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
47 "SRF","PMF_GET","PMF_SET","ESF"
50 #define LAST_CLASS (SMT_PMF_SET)
52 static const struct fddi_addr SMT_Unknown
= {
59 extern const struct fddi_addr fddi_broadcast
;
64 int pcm_status_twisted(struct s_smc
*smc
);
70 static int smt_swap_short(u_short s
);
72 static int mac_index(struct s_smc
*smc
, int mac
);
73 static int phy_index(struct s_smc
*smc
, int phy
);
74 static int mac_con_resource_index(struct s_smc
*smc
, int mac
);
75 static int phy_con_resource_index(struct s_smc
*smc
, int phy
);
76 static void smt_send_rdf(struct s_smc
*smc
, SMbuf
*rej
, int fc
, int reason
,
78 static void smt_send_nif(struct s_smc
*smc
, const struct fddi_addr
*dest
,
79 int fc
, u_long tid
, int type
, int local
);
80 static void smt_send_ecf(struct s_smc
*smc
, struct fddi_addr
*dest
, int fc
,
81 u_long tid
, int type
, int len
);
82 static void smt_echo_test(struct s_smc
*smc
, int dna
);
83 static void smt_send_sif_config(struct s_smc
*smc
, struct fddi_addr
*dest
,
84 u_long tid
, int local
);
85 static void smt_send_sif_operation(struct s_smc
*smc
, struct fddi_addr
*dest
,
86 u_long tid
, int local
);
88 static void smt_string_swap(char *data
, const char *format
, int len
);
90 static void smt_add_frame_len(SMbuf
*mb
, int len
);
91 static void smt_fill_una(struct s_smc
*smc
, struct smt_p_una
*una
);
92 static void smt_fill_sde(struct s_smc
*smc
, struct smt_p_sde
*sde
);
93 static void smt_fill_state(struct s_smc
*smc
, struct smt_p_state
*state
);
94 static void smt_fill_timestamp(struct s_smc
*smc
, struct smt_p_timestamp
*ts
);
95 static void smt_fill_policy(struct s_smc
*smc
, struct smt_p_policy
*policy
);
96 static void smt_fill_latency(struct s_smc
*smc
, struct smt_p_latency
*latency
);
97 static void smt_fill_neighbor(struct s_smc
*smc
, struct smt_p_neighbor
*neighbor
);
98 static int smt_fill_path(struct s_smc
*smc
, struct smt_p_path
*path
);
99 static void smt_fill_mac_status(struct s_smc
*smc
, struct smt_p_mac_status
*st
);
100 static void smt_fill_lem(struct s_smc
*smc
, struct smt_p_lem
*lem
, int phy
);
101 static void smt_fill_version(struct s_smc
*smc
, struct smt_p_version
*vers
);
102 static void smt_fill_fsc(struct s_smc
*smc
, struct smt_p_fsc
*fsc
);
103 static void smt_fill_mac_counter(struct s_smc
*smc
, struct smt_p_mac_counter
*mc
);
104 static void smt_fill_mac_fnc(struct s_smc
*smc
, struct smt_p_mac_fnc
*fnc
);
105 static void smt_fill_manufacturer(struct s_smc
*smc
,
106 struct smp_p_manufacturer
*man
);
107 static void smt_fill_user(struct s_smc
*smc
, struct smp_p_user
*user
);
108 static void smt_fill_setcount(struct s_smc
*smc
, struct smt_p_setcount
*setcount
);
109 static void smt_fill_echo(struct s_smc
*smc
, struct smt_p_echo
*echo
, u_long seed
,
112 static void smt_clear_una_dna(struct s_smc
*smc
);
113 static void smt_clear_old_una_dna(struct s_smc
*smc
);
115 static int entity_to_index(void);
117 static void update_dac(struct s_smc
*smc
, int report
);
118 static int div_ratio(u_long upper
, u_long lower
);
120 static void hwm_conv_can(struct s_smc
*smc
, char *data
, int len
);
122 #define hwm_conv_can(smc,data,len)
126 static inline int is_my_addr(const struct s_smc
*smc
,
127 const struct fddi_addr
*addr
)
129 return(*(short *)(&addr
->a
[0]) ==
130 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[0])
131 && *(short *)(&addr
->a
[2]) ==
132 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[2])
133 && *(short *)(&addr
->a
[4]) ==
134 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[4])) ;
137 static inline int is_broadcast(const struct fddi_addr
*addr
)
139 return(*(u_short
*)(&addr
->a
[0]) == 0xffff &&
140 *(u_short
*)(&addr
->a
[2]) == 0xffff &&
141 *(u_short
*)(&addr
->a
[4]) == 0xffff ) ;
144 static inline int is_individual(const struct fddi_addr
*addr
)
146 return(!(addr
->a
[0] & GROUP_ADDR
)) ;
149 static inline int is_equal(const struct fddi_addr
*addr1
,
150 const struct fddi_addr
*addr2
)
152 return(*(u_short
*)(&addr1
->a
[0]) == *(u_short
*)(&addr2
->a
[0]) &&
153 *(u_short
*)(&addr1
->a
[2]) == *(u_short
*)(&addr2
->a
[2]) &&
154 *(u_short
*)(&addr1
->a
[4]) == *(u_short
*)(&addr2
->a
[4]) ) ;
158 * list of mandatory paras in frames
160 static const u_short plist_nif
[] = { SMT_P_UNA
,SMT_P_SDE
,SMT_P_STATE
,0 } ;
165 void smt_agent_init(struct s_smc
*smc
)
172 smc
->mib
.m
[MAC0
].fddiMACSMTAddress
= smc
->hw
.fddi_home_addr
;
175 * get OUI address from driver (bia == built-in-address)
177 smc
->mib
.fddiSMTStationId
.sid_oem
[0] = 0 ;
178 smc
->mib
.fddiSMTStationId
.sid_oem
[1] = 0 ;
179 driver_get_bia(smc
,&smc
->mib
.fddiSMTStationId
.sid_node
) ;
180 for (i
= 0 ; i
< 6 ; i
++) {
181 smc
->mib
.fddiSMTStationId
.sid_node
.a
[i
] =
182 bitrev8(smc
->mib
.fddiSMTStationId
.sid_node
.a
[i
]);
184 smc
->mib
.fddiSMTManufacturerData
[0] =
185 smc
->mib
.fddiSMTStationId
.sid_node
.a
[0] ;
186 smc
->mib
.fddiSMTManufacturerData
[1] =
187 smc
->mib
.fddiSMTStationId
.sid_node
.a
[1] ;
188 smc
->mib
.fddiSMTManufacturerData
[2] =
189 smc
->mib
.fddiSMTStationId
.sid_node
.a
[2] ;
190 smc
->sm
.smt_tid
= 0 ;
191 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
= DA_NONE
;
192 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
= FALSE
;
194 smt_clear_una_dna(smc
) ;
195 smt_clear_old_una_dna(smc
) ;
197 for (i
= 0 ; i
< SMT_MAX_TEST
; i
++)
198 smc
->sm
.pend
[i
] = 0 ;
199 smc
->sm
.please_reconnect
= 0 ;
200 smc
->sm
.uniq_ticks
= 0 ;
211 void smt_agent_task(struct s_smc
*smc
)
213 smt_timer_start(smc
,&smc
->sm
.smt_timer
, (u_long
)1000000L,
214 EV_TOKEN(EVENT_SMT
,SM_TIMER
)) ;
215 DB_SMT("SMT agent task\n",0,0) ;
218 #ifndef SMT_REAL_TOKEN_CT
219 void smt_emulate_token_ct(struct s_smc
*smc
, int mac_index
)
225 time
= smt_get_time();
226 count
= ((time
- smc
->sm
.last_tok_time
[mac_index
]) *
227 100)/TICKS_PER_SECOND
;
230 * Only when ring is up we will have a token count. The
231 * flag is unfortunatly a single instance value. This
232 * doesn't matter now, because we currently have only
235 if (smc
->hw
.mac_ring_is_up
){
236 smc
->mib
.m
[mac_index
].fddiMACToken_Ct
+= count
;
239 /* Remember current time */
240 smc
->sm
.last_tok_time
[mac_index
] = time
;
246 void smt_event(struct s_smc
*smc
, int event
)
249 #ifndef SMT_REAL_TOKEN_CT
254 if (smc
->sm
.please_reconnect
) {
255 smc
->sm
.please_reconnect
-- ;
256 if (smc
->sm
.please_reconnect
== 0) {
258 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
262 if (event
== SM_FAST
)
266 * timer for periodic cleanup in driver
267 * reset and start the watchdog (FM2)
271 smt_timer_poll(smc
) ;
272 smt_start_watchdog(smc
) ;
276 ess_timer_poll(smc
) ;
280 sba_timer_poll(smc
) ;
283 smt_srf_event(smc
,0,0,0) ;
285 #endif /* no SLIM_SMT */
287 time
= smt_get_time() ;
289 if (time
- smc
->sm
.smt_last_lem
>= TICKS_PER_SECOND
*8) {
291 * Use 8 sec. for the time intervall, it simplifies the
294 struct fddi_mib_m
*mib
;
301 * calculate LEM bit error rate
303 sm_lem_evaluate(smc
) ;
304 smc
->sm
.smt_last_lem
= time
;
310 mac_update_counter(smc
) ;
313 (mib
->fddiMACLost_Ct
- mib
->fddiMACOld_Lost_Ct
) +
314 (mib
->fddiMACError_Ct
- mib
->fddiMACOld_Error_Ct
) ;
316 (mib
->fddiMACFrame_Ct
- mib
->fddiMACOld_Frame_Ct
) +
317 (mib
->fddiMACLost_Ct
- mib
->fddiMACOld_Lost_Ct
) ;
318 mib
->fddiMACFrameErrorRatio
= div_ratio(upper
,lower
) ;
321 ((!mib
->fddiMACFrameErrorThreshold
&&
322 mib
->fddiMACError_Ct
!= mib
->fddiMACOld_Error_Ct
) ||
323 (mib
->fddiMACFrameErrorRatio
>
324 mib
->fddiMACFrameErrorThreshold
)) ;
326 if (cond
!= mib
->fddiMACFrameErrorFlag
)
327 smt_srf_event(smc
,SMT_COND_MAC_FRAME_ERROR
,
331 (mib
->fddiMACNotCopied_Ct
- mib
->fddiMACOld_NotCopied_Ct
) ;
334 (mib
->fddiMACCopied_Ct
- mib
->fddiMACOld_Copied_Ct
) ;
335 mib
->fddiMACNotCopiedRatio
= div_ratio(upper
,lower
) ;
338 ((!mib
->fddiMACNotCopiedThreshold
&&
339 mib
->fddiMACNotCopied_Ct
!=
340 mib
->fddiMACOld_NotCopied_Ct
)||
341 (mib
->fddiMACNotCopiedRatio
>
342 mib
->fddiMACNotCopiedThreshold
)) ;
344 if (cond
!= mib
->fddiMACNotCopiedFlag
)
345 smt_srf_event(smc
,SMT_COND_MAC_NOT_COPIED
,
351 mib
->fddiMACOld_Frame_Ct
= mib
->fddiMACFrame_Ct
;
352 mib
->fddiMACOld_Copied_Ct
= mib
->fddiMACCopied_Ct
;
353 mib
->fddiMACOld_Error_Ct
= mib
->fddiMACError_Ct
;
354 mib
->fddiMACOld_Lost_Ct
= mib
->fddiMACLost_Ct
;
355 mib
->fddiMACOld_NotCopied_Ct
= mib
->fddiMACNotCopied_Ct
;
358 * Check port EBError Condition
360 for (port
= 0; port
< NUMPHYS
; port
++) {
361 phy
= &smc
->y
[port
] ;
363 if (!phy
->mib
->fddiPORTHardwarePresent
) {
367 cond
= (phy
->mib
->fddiPORTEBError_Ct
-
368 phy
->mib
->fddiPORTOldEBError_Ct
> 5) ;
370 /* If ratio is more than 5 in 8 seconds
373 smt_srf_event(smc
,SMT_COND_PORT_EB_ERROR
,
374 (int) (INDEX_PORT
+ phy
->np
) ,cond
) ;
379 phy
->mib
->fddiPORTOldEBError_Ct
=
380 phy
->mib
->fddiPORTEBError_Ct
;
383 #endif /* no SLIM_SMT */
388 if (time
- smc
->sm
.smt_last_notify
>= (u_long
)
389 (smc
->mib
.fddiSMTTT_Notify
* TICKS_PER_SECOND
) ) {
391 * we can either send an announcement or a request
392 * a request will trigger a reply so that we can update
394 * note: same tid must be used until reply is received
396 if (!smc
->sm
.pend
[SMT_TID_NIF
])
397 smc
->sm
.pend
[SMT_TID_NIF
] = smt_get_tid(smc
) ;
398 smt_send_nif(smc
,&fddi_broadcast
, FC_SMT_NSA
,
399 smc
->sm
.pend
[SMT_TID_NIF
], SMT_REQUEST
,0) ;
400 smc
->sm
.smt_last_notify
= time
;
406 if (smc
->sm
.smt_tvu
&&
407 time
- smc
->sm
.smt_tvu
> 228*TICKS_PER_SECOND
) {
408 DB_SMT("SMT : UNA expired\n",0,0) ;
409 smc
->sm
.smt_tvu
= 0 ;
411 if (!is_equal(&smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
413 /* Do not update unknown address */
414 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
=
415 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
417 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
= SMT_Unknown
;
418 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
= FALSE
;
420 * Make sure the fddiMACUNDA_Flag = FALSE is
421 * included in the SRF so we don't generate
422 * a separate SRF for the deassertion of this
426 smt_srf_event(smc
, SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
429 if (smc
->sm
.smt_tvd
&&
430 time
- smc
->sm
.smt_tvd
> 228*TICKS_PER_SECOND
) {
431 DB_SMT("SMT : DNA expired\n",0,0) ;
432 smc
->sm
.smt_tvd
= 0 ;
433 if (!is_equal(&smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
,
435 /* Do not update unknown address */
436 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
=
437 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
439 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
= SMT_Unknown
;
440 smt_srf_event(smc
, SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
444 #endif /* no SLIM_SMT */
446 #ifndef SMT_REAL_TOKEN_CT
448 * Token counter emulation section. If hardware supports the token
449 * count, the token counter will be updated in mac_update_counter.
451 for (i
= MAC0
; i
< NUMMACS
; i
++ ){
452 if (time
- smc
->sm
.last_tok_time
[i
] > 2*TICKS_PER_SECOND
){
453 smt_emulate_token_ct( smc
, i
);
458 smt_timer_start(smc
,&smc
->sm
.smt_timer
, (u_long
)1000000L,
459 EV_TOKEN(EVENT_SMT
,SM_TIMER
)) ;
462 static int div_ratio(u_long upper
, u_long lower
)
464 if ((upper
<<16L) < upper
)
465 upper
= 0xffff0000L
;
470 return((int)(upper
/lower
)) ;
476 * receive packet handler
478 void smt_received_pack(struct s_smc
*smc
, SMbuf
*mb
, int fs
)
479 /* int fs; frame status */
481 struct smt_header
*sm
;
488 case FC_SMT_LAN_LOC
:
493 smt_free_mbuf(smc
,mb
) ;
497 smc
->mib
.m
[MAC0
].fddiMACSMTCopied_Ct
++ ;
498 sm
= smtod(mb
,struct smt_header
*) ;
499 local
= ((fs
& L_INDICATOR
) != 0) ;
500 hwm_conv_can(smc
,(char *)sm
,12) ;
502 /* check destination address */
503 if (is_individual(&sm
->smt_dest
) && !is_my_addr(smc
,&sm
->smt_dest
)) {
504 smt_free_mbuf(smc
,mb
) ;
507 #if 0 /* for DUP recognition, do NOT filter them */
508 /* ignore loop back packets */
509 if (is_my_addr(smc
,&sm
->smt_source
) && !local
) {
510 smt_free_mbuf(smc
,mb
) ;
515 smt_swap_para(sm
,(int) mb
->sm_len
,1) ;
516 DB_SMT("SMT : received packet [%s] at 0x%x\n",
517 smt_type_name
[m_fc(mb
) & 0xf],sm
) ;
518 DB_SMT("SMT : version %d, class %s\n",sm
->smt_version
,
519 smt_class_name
[(sm
->smt_class
>LAST_CLASS
)?0 : sm
->smt_class
]) ;
525 if (m_fc(mb
) == FC_SMT_NSA
&& sm
->smt_class
== SMT_NIF
&&
526 (sm
->smt_type
== SMT_ANNOUNCE
|| sm
->smt_type
== SMT_REQUEST
)) {
533 * ignore any packet with NSA and A-indicator set
535 if ( (fs
& A_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
) {
536 DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
537 addr_to_string(&sm
->smt_source
),0) ;
538 smt_free_mbuf(smc
,mb
) ;
543 * ignore frames with illegal length
545 if (((sm
->smt_class
== SMT_ECF
) && (sm
->smt_len
> SMT_MAX_ECHO_LEN
)) ||
546 ((sm
->smt_class
!= SMT_ECF
) && (sm
->smt_len
> SMT_MAX_INFO_LEN
))) {
547 smt_free_mbuf(smc
,mb
) ;
554 switch (sm
->smt_class
) {
556 case SMT_SIF_CONFIG
:
559 if (sm
->smt_version
!= SMT_VID
)
563 if (sm
->smt_version
!= SMT_VID_2
)
568 DB_SMT("SMT : version = %d, dest = %s\n",
569 sm
->smt_version
,addr_to_string(&sm
->smt_source
)) ;
570 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_VERSION
,local
) ;
571 smt_free_mbuf(smc
,mb
) ;
574 if ((sm
->smt_len
> mb
->sm_len
- sizeof(struct smt_header
)) ||
575 ((sm
->smt_len
& 3) && (sm
->smt_class
!= SMT_ECF
))) {
576 DB_SMT("SMT: info length error, len = %d\n",sm
->smt_len
,0) ;
577 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_LENGTH
,local
) ;
578 smt_free_mbuf(smc
,mb
) ;
581 switch (sm
->smt_class
) {
583 if (smt_check_para(smc
,sm
,plist_nif
)) {
584 DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
587 switch (sm
->smt_type
) {
590 if (!(fs
& C_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
591 && is_broadcast(&sm
->smt_dest
)) {
592 struct smt_p_state
*st
;
596 &smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
598 DB_SMT("SMT : updated my UNA = %s\n",
599 addr_to_string(&sm
->smt_source
),0) ;
600 if (!is_equal(&smc
->mib
.m
[MAC0
].
601 fddiMACUpstreamNbr
,&SMT_Unknown
)){
602 /* Do not update unknown address */
603 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
=
604 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
607 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
=
610 SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
612 smt_echo_test(smc
,0) ;
614 smc
->sm
.smt_tvu
= smt_get_time() ;
615 st
= (struct smt_p_state
*)
616 sm_to_para(smc
,sm
,SMT_P_STATE
) ;
618 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
=
619 (st
->st_dupl_addr
& SMT_ST_MY_DUPA
) ?
624 if ((sm
->smt_type
== SMT_REQUEST
) &&
625 is_individual(&sm
->smt_source
) &&
626 ((!(fs
& A_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
) ||
627 (m_fc(mb
) != FC_SMT_NSA
))) {
628 DB_SMT("SMT : replying to NIF request %s\n",
629 addr_to_string(&sm
->smt_source
),0) ;
630 smt_send_nif(smc
,&sm
->smt_source
,
637 DB_SMT("SMT : received NIF response from %s\n",
638 addr_to_string(&sm
->smt_source
),0) ;
639 if (fs
& A_INDICATOR
) {
640 smc
->sm
.pend
[SMT_TID_NIF
] = 0 ;
641 DB_SMT("SMT : duplicate address\n",0,0) ;
642 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
=
644 smc
->r
.dup_addr_test
= DA_FAILED
;
645 queue_event(smc
,EVENT_RMT
,RM_DUP_ADDR
) ;
646 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
= TRUE
;
650 if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_NIF
]) {
651 smc
->sm
.pend
[SMT_TID_NIF
] = 0 ;
654 &smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
,
656 DB_SMT("SMT : updated my DNA\n",0,0) ;
657 if (!is_equal(&smc
->mib
.m
[MAC0
].
658 fddiMACDownstreamNbr
, &SMT_Unknown
)){
659 /* Do not update unknown address */
660 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
=
661 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
664 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
=
667 SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
669 smt_echo_test(smc
,1) ;
671 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
= FALSE
;
673 smc
->sm
.smt_tvd
= smt_get_time() ;
674 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
=
676 if (smc
->r
.dup_addr_test
!= DA_PASSED
) {
677 smc
->r
.dup_addr_test
= DA_PASSED
;
678 queue_event(smc
,EVENT_RMT
,RM_DUP_ADDR
) ;
681 else if (sm
->smt_tid
==
682 smc
->sm
.pend
[SMT_TID_NIF_TEST
]) {
683 DB_SMT("SMT : NIF test TID ok\n",0,0) ;
686 DB_SMT("SMT : expected TID %lx, got %lx\n",
687 smc
->sm
.pend
[SMT_TID_NIF
],sm
->smt_tid
) ;
695 case SMT_SIF_CONFIG
: /* station information */
696 if (sm
->smt_type
!= SMT_REQUEST
)
698 DB_SMT("SMT : replying to SIF Config request from %s\n",
699 addr_to_string(&sm
->smt_source
),0) ;
700 smt_send_sif_config(smc
,&sm
->smt_source
,sm
->smt_tid
,local
) ;
702 case SMT_SIF_OPER
: /* station information */
703 if (sm
->smt_type
!= SMT_REQUEST
)
705 DB_SMT("SMT : replying to SIF Operation request from %s\n",
706 addr_to_string(&sm
->smt_source
),0) ;
707 smt_send_sif_operation(smc
,&sm
->smt_source
,sm
->smt_tid
,local
) ;
709 case SMT_ECF
: /* echo frame */
710 switch (sm
->smt_type
) {
712 smc
->mib
.priv
.fddiPRIVECF_Reply_Rx
++ ;
713 DB_SMT("SMT: received ECF reply from %s\n",
714 addr_to_string(&sm
->smt_source
),0) ;
715 if (sm_to_para(smc
,sm
,SMT_P_ECHODATA
) == NULL
) {
716 DB_SMT("SMT: ECHODATA missing\n",0,0) ;
719 if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF
]) {
720 DB_SMT("SMT : ECF test TID ok\n",0,0) ;
722 else if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF_UNA
]) {
723 DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
725 else if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF_DNA
]) {
726 DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
729 DB_SMT("SMT : expected TID %lx, got %lx\n",
730 smc
->sm
.pend
[SMT_TID_ECF
],
735 smc
->mib
.priv
.fddiPRIVECF_Req_Rx
++ ;
737 if (sm
->smt_len
&& !sm_to_para(smc
,sm
,SMT_P_ECHODATA
)) {
738 DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
739 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_LENGTH
,
743 DB_SMT("SMT - sending ECF reply to %s\n",
744 addr_to_string(&sm
->smt_source
),0) ;
746 /* set destination addr. & reply */
747 sm
->smt_dest
= sm
->smt_source
;
748 sm
->smt_type
= SMT_REPLY
;
749 dump_smt(smc
,sm
,"ECF REPLY") ;
750 smc
->mib
.priv
.fddiPRIVECF_Reply_Tx
++ ;
751 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
752 return ; /* DON'T free mbuf */
760 case SMT_RAF
: /* resource allocation */
762 DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
763 fs
= ess_raf_received_pack(smc
,mb
,sm
,fs
) ;
767 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
768 sba_raf_received_pack(smc
,sm
,fs
) ;
771 case SMT_RDF
: /* request denied */
772 smc
->mib
.priv
.fddiPRIVRDF_Rx
++ ;
774 case SMT_ESF
: /* extended service - not supported */
775 if (sm
->smt_type
== SMT_REQUEST
) {
776 DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
777 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_CLASS
,local
) ;
782 if (sm
->smt_type
!= SMT_REQUEST
)
784 /* update statistics */
785 if (sm
->smt_class
== SMT_PMF_GET
)
786 smc
->mib
.priv
.fddiPRIVPMF_Get_Rx
++ ;
788 smc
->mib
.priv
.fddiPRIVPMF_Set_Rx
++ ;
790 * ignore PMF SET with I/G set
792 if ((sm
->smt_class
== SMT_PMF_SET
) &&
793 !is_individual(&sm
->smt_dest
)) {
794 DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
797 smt_pmf_received_pack(smc
,mb
, local
) ;
800 dump_smt(smc
,sm
,"SRF received") ;
803 if (sm
->smt_type
!= SMT_REQUEST
)
806 * For frames with unknown class:
807 * we need to send a RDF frame according to 8.1.3.1.1,
808 * only if it is a REQUEST.
810 DB_SMT("SMT : class = %d, send RDF to %s\n",
811 sm
->smt_class
, addr_to_string(&sm
->smt_source
)) ;
813 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_CLASS
,local
) ;
818 DB_SMT("SMT: discarding invalid frame, reason = %d\n",
821 smt_free_mbuf(smc
,mb
) ;
824 static void update_dac(struct s_smc
*smc
, int report
)
828 cond
= ( smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
|
829 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
) != 0 ;
830 if (report
&& (cond
!= smc
->mib
.m
[MAC0
].fddiMACDuplicateAddressCond
))
831 smt_srf_event(smc
, SMT_COND_MAC_DUP_ADDR
,INDEX_MAC
,cond
) ;
833 smc
->mib
.m
[MAC0
].fddiMACDuplicateAddressCond
= cond
;
842 void smt_send_frame(struct s_smc
*smc
, SMbuf
*mb
, int fc
, int local
)
843 /* SMbuf *mb; buffer to send */
844 /* int fc; FC value */
846 struct smt_header
*sm
;
848 if (!smc
->r
.sm_ma_avail
&& !local
) {
849 smt_free_mbuf(smc
,mb
) ;
852 sm
= smtod(mb
,struct smt_header
*) ;
853 sm
->smt_source
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
854 sm
->smt_sid
= smc
->mib
.fddiSMTStationId
;
856 smt_swap_para(sm
,(int) mb
->sm_len
,0) ; /* swap para & header */
857 hwm_conv_can(smc
,(char *)sm
,12) ; /* convert SA and DA */
858 smc
->mib
.m
[MAC0
].fddiMACSMTTransmit_Ct
++ ;
859 smt_send_mbuf(smc
,mb
,local
? FC_SMT_LOC
: fc
) ;
863 * generate and send RDF
865 static void smt_send_rdf(struct s_smc
*smc
, SMbuf
*rej
, int fc
, int reason
,
867 /* SMbuf *rej; mbuf of offending frame */
868 /* int fc; FC of denied frame */
869 /* int reason; reason code */
872 struct smt_header
*sm
; /* header of offending frame */
873 struct smt_rdf
*rdf
;
877 sm
= smtod(rej
,struct smt_header
*) ;
878 if (sm
->smt_type
!= SMT_REQUEST
)
881 DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
882 addr_to_string(&sm
->smt_source
),reason
) ;
886 * note: get framelength from MAC length, NOT from SMT header
887 * smt header length is included in sm_len
889 frame_len
= rej
->sm_len
;
891 if (!(mb
=smt_build_frame(smc
,SMT_RDF
,SMT_REPLY
,sizeof(struct smt_rdf
))))
893 rdf
= smtod(mb
,struct smt_rdf
*) ;
894 rdf
->smt
.smt_tid
= sm
->smt_tid
; /* use TID from sm */
895 rdf
->smt
.smt_dest
= sm
->smt_source
; /* set dest = source */
898 rdf
->reason
.para
.p_type
= SMT_P_REASON
;
899 rdf
->reason
.para
.p_len
= sizeof(struct smt_p_reason
) - PARA_LEN
;
900 rdf
->reason
.rdf_reason
= reason
;
903 rdf
->version
.para
.p_type
= SMT_P_VERSION
;
904 rdf
->version
.para
.p_len
= sizeof(struct smt_p_version
) - PARA_LEN
;
905 rdf
->version
.v_pad
= 0 ;
906 rdf
->version
.v_n
= 1 ;
907 rdf
->version
.v_index
= 1 ;
908 rdf
->version
.v_version
[0] = SMT_VID_2
;
909 rdf
->version
.v_pad2
= 0 ;
912 if ((unsigned) frame_len
<= SMT_MAX_INFO_LEN
- sizeof(*rdf
) +
913 2*sizeof(struct smt_header
))
916 len
= SMT_MAX_INFO_LEN
- sizeof(*rdf
) +
917 2*sizeof(struct smt_header
) ;
918 /* make length multiple of 4 */
920 rdf
->refused
.para
.p_type
= SMT_P_REFUSED
;
921 /* length of para is smt_frame + ref_fc */
922 rdf
->refused
.para
.p_len
= len
+ 4 ;
923 rdf
->refused
.ref_fc
= fc
;
926 smt_swap_para(sm
,frame_len
,0) ;
928 memcpy((char *) &rdf
->refused
.ref_header
,(char *) sm
,len
) ;
930 len
-= sizeof(struct smt_header
) ;
932 rdf
->smt
.smt_len
+= len
;
934 dump_smt(smc
,(struct smt_header
*)rdf
,"RDF") ;
935 smc
->mib
.priv
.fddiPRIVRDF_Tx
++ ;
936 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
940 * generate and send NIF
942 static void smt_send_nif(struct s_smc
*smc
, const struct fddi_addr
*dest
,
943 int fc
, u_long tid
, int type
, int local
)
944 /* struct fddi_addr *dest; dest address */
945 /* int fc; frame control */
946 /* u_long tid; transaction id */
947 /* int type; frame type */
949 struct smt_nif
*nif
;
952 if (!(mb
= smt_build_frame(smc
,SMT_NIF
,type
,sizeof(struct smt_nif
))))
954 nif
= smtod(mb
, struct smt_nif
*) ;
955 smt_fill_una(smc
,&nif
->una
) ; /* set UNA */
956 smt_fill_sde(smc
,&nif
->sde
) ; /* set station descriptor */
957 smt_fill_state(smc
,&nif
->state
) ; /* set state information */
959 smt_fill_fsc(smc
,&nif
->fsc
) ; /* set frame status cap. */
961 nif
->smt
.smt_dest
= *dest
; /* destination address */
962 nif
->smt
.smt_tid
= tid
; /* transaction ID */
963 dump_smt(smc
,(struct smt_header
*)nif
,"NIF") ;
964 smt_send_frame(smc
,mb
,fc
,local
) ;
969 * send NIF request (test purpose)
971 static void smt_send_nif_request(struct s_smc
*smc
, struct fddi_addr
*dest
)
973 smc
->sm
.pend
[SMT_TID_NIF_TEST
] = smt_get_tid(smc
) ;
974 smt_send_nif(smc
,dest
, FC_SMT_INFO
, smc
->sm
.pend
[SMT_TID_NIF_TEST
],
979 * send ECF request (test purpose)
981 static void smt_send_ecf_request(struct s_smc
*smc
, struct fddi_addr
*dest
,
984 smc
->sm
.pend
[SMT_TID_ECF
] = smt_get_tid(smc
) ;
985 smt_send_ecf(smc
,dest
, FC_SMT_INFO
, smc
->sm
.pend
[SMT_TID_ECF
],
993 static void smt_echo_test(struct s_smc
*smc
, int dna
)
997 smc
->sm
.pend
[dna
? SMT_TID_ECF_DNA
: SMT_TID_ECF_UNA
] =
998 tid
= smt_get_tid(smc
) ;
999 smt_send_ecf(smc
, dna
?
1000 &smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
:
1001 &smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
1002 FC_SMT_INFO
,tid
, SMT_REQUEST
, (SMT_TEST_ECHO_LEN
& ~3)-8) ;
1006 * generate and send ECF
1008 static void smt_send_ecf(struct s_smc
*smc
, struct fddi_addr
*dest
, int fc
,
1009 u_long tid
, int type
, int len
)
1010 /* struct fddi_addr *dest; dest address */
1011 /* int fc; frame control */
1012 /* u_long tid; transaction id */
1013 /* int type; frame type */
1014 /* int len; frame length */
1016 struct smt_ecf
*ecf
;
1019 if (!(mb
= smt_build_frame(smc
,SMT_ECF
,type
,SMT_ECF_LEN
+ len
)))
1021 ecf
= smtod(mb
, struct smt_ecf
*) ;
1023 smt_fill_echo(smc
,&ecf
->ec_echo
,tid
,len
) ; /* set ECHO */
1024 ecf
->smt
.smt_dest
= *dest
; /* destination address */
1025 ecf
->smt
.smt_tid
= tid
; /* transaction ID */
1026 smc
->mib
.priv
.fddiPRIVECF_Req_Tx
++ ;
1027 smt_send_frame(smc
,mb
,fc
,0) ;
1031 * generate and send SIF config response
1034 static void smt_send_sif_config(struct s_smc
*smc
, struct fddi_addr
*dest
,
1035 u_long tid
, int local
)
1036 /* struct fddi_addr *dest; dest address */
1037 /* u_long tid; transaction id */
1039 struct smt_sif_config
*sif
;
1042 if (!(mb
= smt_build_frame(smc
,SMT_SIF_CONFIG
,SMT_REPLY
,
1043 SIZEOF_SMT_SIF_CONFIG
)))
1046 sif
= smtod(mb
, struct smt_sif_config
*) ;
1047 smt_fill_timestamp(smc
,&sif
->ts
) ; /* set time stamp */
1048 smt_fill_sde(smc
,&sif
->sde
) ; /* set station descriptor */
1049 smt_fill_version(smc
,&sif
->version
) ; /* set version information */
1050 smt_fill_state(smc
,&sif
->state
) ; /* set state information */
1051 smt_fill_policy(smc
,&sif
->policy
) ; /* set station policy */
1052 smt_fill_latency(smc
,&sif
->latency
); /* set station latency */
1053 smt_fill_neighbor(smc
,&sif
->neighbor
); /* set station neighbor */
1054 smt_fill_setcount(smc
,&sif
->setcount
) ; /* set count */
1055 len
= smt_fill_path(smc
,&sif
->path
); /* set station path descriptor*/
1056 sif
->smt
.smt_dest
= *dest
; /* destination address */
1057 sif
->smt
.smt_tid
= tid
; /* transaction ID */
1058 smt_add_frame_len(mb
,len
) ; /* adjust length fields */
1059 dump_smt(smc
,(struct smt_header
*)sif
,"SIF Configuration Reply") ;
1060 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
1064 * generate and send SIF operation response
1067 static void smt_send_sif_operation(struct s_smc
*smc
, struct fddi_addr
*dest
,
1068 u_long tid
, int local
)
1069 /* struct fddi_addr *dest; dest address */
1070 /* u_long tid; transaction id */
1072 struct smt_sif_operation
*sif
;
1078 #ifndef CONCENTRATOR
1079 if (smc
->s
.sas
== SMT_SAS
)
1083 if (!(mb
= smt_build_frame(smc
,SMT_SIF_OPER
,SMT_REPLY
,
1084 SIZEOF_SMT_SIF_OPERATION
+ports
*sizeof(struct smt_p_lem
))))
1086 sif
= smtod(mb
, struct smt_sif_operation
*) ;
1087 smt_fill_timestamp(smc
,&sif
->ts
) ; /* set time stamp */
1088 smt_fill_mac_status(smc
,&sif
->status
) ; /* set mac status */
1089 smt_fill_mac_counter(smc
,&sif
->mc
) ; /* set mac counter field */
1090 smt_fill_mac_fnc(smc
,&sif
->fnc
) ; /* set frame not copied counter */
1091 smt_fill_manufacturer(smc
,&sif
->man
) ; /* set manufacturer field */
1092 smt_fill_user(smc
,&sif
->user
) ; /* set user field */
1093 smt_fill_setcount(smc
,&sif
->setcount
) ; /* set count */
1095 * set link error mon information
1098 smt_fill_lem(smc
,sif
->lem
,PS
) ;
1101 for (i
= 0 ; i
< ports
; i
++) {
1102 smt_fill_lem(smc
,&sif
->lem
[i
],i
) ;
1106 sif
->smt
.smt_dest
= *dest
; /* destination address */
1107 sif
->smt
.smt_tid
= tid
; /* transaction ID */
1108 dump_smt(smc
,(struct smt_header
*)sif
,"SIF Operation Reply") ;
1109 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
1113 * get and initialize SMT frame
1115 SMbuf
*smt_build_frame(struct s_smc
*smc
, int class, int type
,
1119 struct smt_header
*smt
;
1122 if (!smc
->r
.sm_ma_avail
) {
1126 if (!(mb
= smt_get_mbuf(smc
)))
1129 mb
->sm_len
= length
;
1130 smt
= smtod(mb
, struct smt_header
*) ;
1131 smt
->smt_dest
= fddi_broadcast
; /* set dest = broadcast */
1132 smt
->smt_class
= class ;
1133 smt
->smt_type
= type
;
1136 case SMT_SIF_CONFIG
:
1139 smt
->smt_version
= SMT_VID
;
1142 smt
->smt_version
= SMT_VID_2
;
1145 smt
->smt_tid
= smt_get_tid(smc
) ; /* set transaction ID */
1147 smt
->smt_len
= length
- sizeof(struct smt_header
) ;
1151 static void smt_add_frame_len(SMbuf
*mb
, int len
)
1153 struct smt_header
*smt
;
1155 smt
= smtod(mb
, struct smt_header
*) ;
1156 smt
->smt_len
+= len
;
1163 * fill values in UNA parameter
1165 static void smt_fill_una(struct s_smc
*smc
, struct smt_p_una
*una
)
1167 SMTSETPARA(una
,SMT_P_UNA
) ;
1169 una
->una_node
= smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
1173 * fill values in SDE parameter
1175 static void smt_fill_sde(struct s_smc
*smc
, struct smt_p_sde
*sde
)
1177 SMTSETPARA(sde
,SMT_P_SDE
) ;
1178 sde
->sde_non_master
= smc
->mib
.fddiSMTNonMaster_Ct
;
1179 sde
->sde_master
= smc
->mib
.fddiSMTMaster_Ct
;
1180 sde
->sde_mac_count
= NUMMACS
; /* only 1 MAC */
1182 sde
->sde_type
= SMT_SDE_CONCENTRATOR
;
1184 sde
->sde_type
= SMT_SDE_STATION
;
1189 * fill in values in station state parameter
1191 static void smt_fill_state(struct s_smc
*smc
, struct smt_p_state
*state
)
1196 SMTSETPARA(state
,SMT_P_STATE
) ;
1199 /* determine topology */
1201 if (smc
->mib
.fddiSMTPeerWrapFlag
) {
1202 top
|= SMT_ST_WRAPPED
; /* state wrapped */
1205 if (cfm_status_unattached(smc
)) {
1206 top
|= SMT_ST_UNATTACHED
; /* unattached concentrator */
1209 if ((twist
= pcm_status_twisted(smc
)) & 1) {
1210 top
|= SMT_ST_TWISTED_A
; /* twisted cable */
1213 top
|= SMT_ST_TWISTED_B
; /* twisted cable */
1218 if (pcm_rooted_station(smc
))
1219 top
|= SMT_ST_ROOTED_S
;
1220 if (smc
->mib
.a
[0].fddiPATHSbaPayload
!= 0)
1221 top
|= SMT_ST_SYNC_SERVICE
;
1222 state
->st_topology
= top
;
1223 state
->st_dupl_addr
=
1224 ((smc
->mib
.m
[MAC0
].fddiMACDA_Flag
? SMT_ST_MY_DUPA
: 0 ) |
1225 (smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
? SMT_ST_UNA_DUPA
: 0)) ;
1229 * fill values in timestamp parameter
1231 static void smt_fill_timestamp(struct s_smc
*smc
, struct smt_p_timestamp
*ts
)
1234 SMTSETPARA(ts
,SMT_P_TIMESTAMP
) ;
1235 smt_set_timestamp(smc
,ts
->ts_time
) ;
1238 void smt_set_timestamp(struct s_smc
*smc
, u_char
*p
)
1244 * timestamp is 64 bits long ; resolution is 80 nS
1245 * our clock resolution is 10mS
1246 * 10mS/80ns = 125000 ~ 2^17 = 131072
1248 utime
= smt_get_time() ;
1249 time
= utime
* 100 ;
1250 time
/= TICKS_PER_SECOND
;
1252 p
[1] = (u_char
)((time
>>(8+8+8+8-1)) & 1) ;
1253 p
[2] = (u_char
)(time
>>(8+8+8-1)) ;
1254 p
[3] = (u_char
)(time
>>(8+8-1)) ;
1255 p
[4] = (u_char
)(time
>>(8-1)) ;
1256 p
[5] = (u_char
)(time
<<1) ;
1257 p
[6] = (u_char
)(smc
->sm
.uniq_ticks
>>8) ;
1258 p
[7] = (u_char
)smc
->sm
.uniq_ticks
;
1260 * make sure we don't wrap: restart whenever the upper digits change
1262 if (utime
!= smc
->sm
.uniq_time
) {
1263 smc
->sm
.uniq_ticks
= 0 ;
1265 smc
->sm
.uniq_ticks
++ ;
1266 smc
->sm
.uniq_time
= utime
;
1270 * fill values in station policy parameter
1272 static void smt_fill_policy(struct s_smc
*smc
, struct smt_p_policy
*policy
)
1280 * MIB para 101b (fddiSMTConnectionPolicy) coding
1281 * is different from 0005 coding
1283 static u_char ansi_weirdness
[16] = {
1284 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1286 SMTSETPARA(policy
,SMT_P_POLICY
) ;
1289 in
= smc
->mib
.fddiSMTConnectionPolicy
;
1290 for (i
= 0, map
= ansi_weirdness
; i
< 16 ; i
++) {
1296 policy
->pl_config
= smc
->mib
.fddiSMTConfigPolicy
;
1297 policy
->pl_connect
= out
;
1301 * fill values in latency equivalent parameter
1303 static void smt_fill_latency(struct s_smc
*smc
, struct smt_p_latency
*latency
)
1305 SMTSETPARA(latency
,SMT_P_LATENCY
) ;
1307 latency
->lt_phyout_idx1
= phy_index(smc
,0) ;
1308 latency
->lt_latency1
= 10 ; /* in octets (byte clock) */
1310 * note: latency has two phy entries by definition
1311 * for a SAS, the 2nd one is null
1313 if (smc
->s
.sas
== SMT_DAS
) {
1314 latency
->lt_phyout_idx2
= phy_index(smc
,1) ;
1315 latency
->lt_latency2
= 10 ; /* in octets (byte clock) */
1318 latency
->lt_phyout_idx2
= 0 ;
1319 latency
->lt_latency2
= 0 ;
1324 * fill values in MAC neighbors parameter
1326 static void smt_fill_neighbor(struct s_smc
*smc
, struct smt_p_neighbor
*neighbor
)
1328 SMTSETPARA(neighbor
,SMT_P_NEIGHBORS
) ;
1330 neighbor
->nb_mib_index
= INDEX_MAC
;
1331 neighbor
->nb_mac_index
= mac_index(smc
,1) ;
1332 neighbor
->nb_una
= smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
1333 neighbor
->nb_dna
= smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
1337 * fill values in path descriptor
1340 #define ALLPHYS NUMPHYS
1342 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1345 static int smt_fill_path(struct s_smc
*smc
, struct smt_p_path
*path
)
1347 SK_LOC_DECL(int,type
) ;
1348 SK_LOC_DECL(int,state
) ;
1349 SK_LOC_DECL(int,remote
) ;
1350 SK_LOC_DECL(int,mac
) ;
1354 struct smt_phy_rec
*phy
;
1355 struct smt_mac_rec
*pd_mac
;
1358 sizeof(struct smt_mac_rec
) * NUMMACS
+
1359 sizeof(struct smt_phy_rec
) * ALLPHYS
;
1360 path
->para
.p_type
= SMT_P_PATH
;
1361 path
->para
.p_len
= len
- PARA_LEN
;
1364 for (p
= 0,phy
= path
->pd_phy
; p
< ALLPHYS
; p
++, phy
++) {
1366 #ifndef CONCENTRATOR
1367 if (smc
->s
.sas
== SMT_SAS
)
1370 pcm_status_state(smc
,physp
,&type
,&state
,&remote
,&mac
) ;
1371 #ifdef LITTLE_ENDIAN
1372 phy
->phy_mib_index
= smt_swap_short((u_short
)p
+INDEX_PORT
) ;
1374 phy
->phy_mib_index
= p
+INDEX_PORT
;
1376 phy
->phy_type
= type
;
1377 phy
->phy_connect_state
= state
;
1378 phy
->phy_remote_type
= remote
;
1379 phy
->phy_remote_mac
= mac
;
1380 phy
->phy_resource_idx
= phy_con_resource_index(smc
,p
) ;
1384 pd_mac
= (struct smt_mac_rec
*) phy
;
1385 pd_mac
->mac_addr
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
1386 pd_mac
->mac_resource_idx
= mac_con_resource_index(smc
,1) ;
1391 * fill values in mac status
1393 static void smt_fill_mac_status(struct s_smc
*smc
, struct smt_p_mac_status
*st
)
1395 SMTSETPARA(st
,SMT_P_MAC_STATUS
) ;
1397 st
->st_mib_index
= INDEX_MAC
;
1398 st
->st_mac_index
= mac_index(smc
,1) ;
1400 mac_update_counter(smc
) ;
1402 * timer values are represented in SMT as 2's complement numbers
1403 * units : internal : 2's complement BCLK
1405 st
->st_t_req
= smc
->mib
.m
[MAC0
].fddiMACT_Req
;
1406 st
->st_t_neg
= smc
->mib
.m
[MAC0
].fddiMACT_Neg
;
1407 st
->st_t_max
= smc
->mib
.m
[MAC0
].fddiMACT_Max
;
1408 st
->st_tvx_value
= smc
->mib
.m
[MAC0
].fddiMACTvxValue
;
1409 st
->st_t_min
= smc
->mib
.m
[MAC0
].fddiMACT_Min
;
1411 st
->st_sba
= smc
->mib
.a
[PATH0
].fddiPATHSbaPayload
;
1412 st
->st_frame_ct
= smc
->mib
.m
[MAC0
].fddiMACFrame_Ct
;
1413 st
->st_error_ct
= smc
->mib
.m
[MAC0
].fddiMACError_Ct
;
1414 st
->st_lost_ct
= smc
->mib
.m
[MAC0
].fddiMACLost_Ct
;
1418 * fill values in LEM status
1420 static void smt_fill_lem(struct s_smc
*smc
, struct smt_p_lem
*lem
, int phy
)
1422 struct fddi_mib_p
*mib
;
1424 mib
= smc
->y
[phy
].mib
;
1426 SMTSETPARA(lem
,SMT_P_LEM
) ;
1427 lem
->lem_mib_index
= phy
+INDEX_PORT
;
1428 lem
->lem_phy_index
= phy_index(smc
,phy
) ;
1430 lem
->lem_cutoff
= mib
->fddiPORTLer_Cutoff
;
1431 lem
->lem_alarm
= mib
->fddiPORTLer_Alarm
;
1432 /* long term bit error rate */
1433 lem
->lem_estimate
= mib
->fddiPORTLer_Estimate
;
1434 /* # of rejected connections */
1435 lem
->lem_reject_ct
= mib
->fddiPORTLem_Reject_Ct
;
1436 lem
->lem_ct
= mib
->fddiPORTLem_Ct
; /* total number of errors */
1440 * fill version parameter
1442 static void smt_fill_version(struct s_smc
*smc
, struct smt_p_version
*vers
)
1445 SMTSETPARA(vers
,SMT_P_VERSION
) ;
1447 vers
->v_n
= 1 ; /* one version is enough .. */
1449 vers
->v_version
[0] = SMT_VID_2
;
1455 * fill frame status capabilities
1458 * note: this para 200B is NOT in swap table, because it's also set in
1461 static void smt_fill_fsc(struct s_smc
*smc
, struct smt_p_fsc
*fsc
)
1464 SMTSETPARA(fsc
,SMT_P_FSC
) ;
1466 fsc
->fsc_mac_index
= INDEX_MAC
; /* this is MIB ; MIB is NOT
1470 fsc
->fsc_value
= FSC_TYPE0
; /* "normal" node */
1471 #ifdef LITTLE_ENDIAN
1472 fsc
->fsc_mac_index
= smt_swap_short(INDEX_MAC
) ;
1473 fsc
->fsc_value
= smt_swap_short(FSC_TYPE0
) ;
1479 * fill mac counter field
1481 static void smt_fill_mac_counter(struct s_smc
*smc
, struct smt_p_mac_counter
*mc
)
1483 SMTSETPARA(mc
,SMT_P_MAC_COUNTER
) ;
1484 mc
->mc_mib_index
= INDEX_MAC
;
1485 mc
->mc_index
= mac_index(smc
,1) ;
1486 mc
->mc_receive_ct
= smc
->mib
.m
[MAC0
].fddiMACCopied_Ct
;
1487 mc
->mc_transmit_ct
= smc
->mib
.m
[MAC0
].fddiMACTransmit_Ct
;
1491 * fill mac frame not copied counter
1493 static void smt_fill_mac_fnc(struct s_smc
*smc
, struct smt_p_mac_fnc
*fnc
)
1495 SMTSETPARA(fnc
,SMT_P_MAC_FNC
) ;
1496 fnc
->nc_mib_index
= INDEX_MAC
;
1497 fnc
->nc_index
= mac_index(smc
,1) ;
1498 fnc
->nc_counter
= smc
->mib
.m
[MAC0
].fddiMACNotCopied_Ct
;
1503 * fill manufacturer field
1505 static void smt_fill_manufacturer(struct s_smc
*smc
,
1506 struct smp_p_manufacturer
*man
)
1508 SMTSETPARA(man
,SMT_P_MANUFACTURER
) ;
1509 memcpy((char *) man
->mf_data
,
1510 (char *) smc
->mib
.fddiSMTManufacturerData
,
1511 sizeof(man
->mf_data
)) ;
1517 static void smt_fill_user(struct s_smc
*smc
, struct smp_p_user
*user
)
1519 SMTSETPARA(user
,SMT_P_USER
) ;
1520 memcpy((char *) user
->us_data
,
1521 (char *) smc
->mib
.fddiSMTUserData
,
1522 sizeof(user
->us_data
)) ;
1528 static void smt_fill_setcount(struct s_smc
*smc
, struct smt_p_setcount
*setcount
)
1531 SMTSETPARA(setcount
,SMT_P_SETCOUNT
) ;
1532 setcount
->count
= smc
->mib
.fddiSMTSetCount
.count
;
1533 memcpy((char *)setcount
->timestamp
,
1534 (char *)smc
->mib
.fddiSMTSetCount
.timestamp
,8) ;
1540 static void smt_fill_echo(struct s_smc
*smc
, struct smt_p_echo
*echo
, u_long seed
,
1546 SMTSETPARA(echo
,SMT_P_ECHODATA
) ;
1547 echo
->para
.p_len
= len
;
1548 for (p
= echo
->ec_data
; len
; len
--) {
1549 *p
++ = (u_char
) seed
;
1556 * called from CFM if configuration changes
1558 static void smt_clear_una_dna(struct s_smc
*smc
)
1560 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
= SMT_Unknown
;
1561 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
= SMT_Unknown
;
1564 static void smt_clear_old_una_dna(struct s_smc
*smc
)
1566 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
= SMT_Unknown
;
1567 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
= SMT_Unknown
;
1570 u_long
smt_get_tid(struct s_smc
*smc
)
1573 while ((tid
= ++(smc
->sm
.smt_tid
) ^ SMT_TID_MAGIC
) == 0)
1575 return(tid
& 0x3fffffffL
) ;
1580 * table of parameter lengths
1582 static const struct smt_pdef
{
1587 { SMT_P_UNA
, sizeof(struct smt_p_una
) ,
1589 { SMT_P_SDE
, sizeof(struct smt_p_sde
) ,
1591 { SMT_P_STATE
, sizeof(struct smt_p_state
) ,
1592 SWAP_SMT_P_STATE
} ,
1593 { SMT_P_TIMESTAMP
,sizeof(struct smt_p_timestamp
) ,
1594 SWAP_SMT_P_TIMESTAMP
} ,
1595 { SMT_P_POLICY
, sizeof(struct smt_p_policy
) ,
1596 SWAP_SMT_P_POLICY
} ,
1597 { SMT_P_LATENCY
, sizeof(struct smt_p_latency
) ,
1598 SWAP_SMT_P_LATENCY
} ,
1599 { SMT_P_NEIGHBORS
,sizeof(struct smt_p_neighbor
) ,
1600 SWAP_SMT_P_NEIGHBORS
} ,
1601 { SMT_P_PATH
, sizeof(struct smt_p_path
) ,
1603 { SMT_P_MAC_STATUS
,sizeof(struct smt_p_mac_status
) ,
1604 SWAP_SMT_P_MAC_STATUS
} ,
1605 { SMT_P_LEM
, sizeof(struct smt_p_lem
) ,
1607 { SMT_P_MAC_COUNTER
,sizeof(struct smt_p_mac_counter
) ,
1608 SWAP_SMT_P_MAC_COUNTER
} ,
1609 { SMT_P_MAC_FNC
,sizeof(struct smt_p_mac_fnc
) ,
1610 SWAP_SMT_P_MAC_FNC
} ,
1611 { SMT_P_PRIORITY
,sizeof(struct smt_p_priority
) ,
1612 SWAP_SMT_P_PRIORITY
} ,
1613 { SMT_P_EB
,sizeof(struct smt_p_eb
) ,
1615 { SMT_P_MANUFACTURER
,sizeof(struct smp_p_manufacturer
) ,
1616 SWAP_SMT_P_MANUFACTURER
} ,
1617 { SMT_P_REASON
, sizeof(struct smt_p_reason
) ,
1618 SWAP_SMT_P_REASON
} ,
1619 { SMT_P_REFUSED
, sizeof(struct smt_p_refused
) ,
1620 SWAP_SMT_P_REFUSED
} ,
1621 { SMT_P_VERSION
, sizeof(struct smt_p_version
) ,
1622 SWAP_SMT_P_VERSION
} ,
1624 { SMT_P0015
, sizeof(struct smt_p_0015
) , SWAP_SMT_P0015
} ,
1625 { SMT_P0016
, sizeof(struct smt_p_0016
) , SWAP_SMT_P0016
} ,
1626 { SMT_P0017
, sizeof(struct smt_p_0017
) , SWAP_SMT_P0017
} ,
1627 { SMT_P0018
, sizeof(struct smt_p_0018
) , SWAP_SMT_P0018
} ,
1628 { SMT_P0019
, sizeof(struct smt_p_0019
) , SWAP_SMT_P0019
} ,
1629 { SMT_P001A
, sizeof(struct smt_p_001a
) , SWAP_SMT_P001A
} ,
1630 { SMT_P001B
, sizeof(struct smt_p_001b
) , SWAP_SMT_P001B
} ,
1631 { SMT_P001C
, sizeof(struct smt_p_001c
) , SWAP_SMT_P001C
} ,
1632 { SMT_P001D
, sizeof(struct smt_p_001d
) , SWAP_SMT_P001D
} ,
1635 { SMT_P_FSC
, sizeof(struct smt_p_fsc
) ,
1639 { SMT_P_SETCOUNT
,0, SWAP_SMT_P_SETCOUNT
} ,
1640 { SMT_P1048
, 0, SWAP_SMT_P1048
} ,
1641 { SMT_P208C
, 0, SWAP_SMT_P208C
} ,
1642 { SMT_P208D
, 0, SWAP_SMT_P208D
} ,
1643 { SMT_P208E
, 0, SWAP_SMT_P208E
} ,
1644 { SMT_P208F
, 0, SWAP_SMT_P208F
} ,
1645 { SMT_P2090
, 0, SWAP_SMT_P2090
} ,
1647 { SMT_P320B
, sizeof(struct smt_p_320b
) , SWAP_SMT_P320B
} ,
1648 { SMT_P320F
, sizeof(struct smt_p_320f
) , SWAP_SMT_P320F
} ,
1649 { SMT_P3210
, sizeof(struct smt_p_3210
) , SWAP_SMT_P3210
} ,
1651 { SMT_P4050
, 0, SWAP_SMT_P4050
} ,
1652 { SMT_P4051
, 0, SWAP_SMT_P4051
} ,
1653 { SMT_P4052
, 0, SWAP_SMT_P4052
} ,
1654 { SMT_P4053
, 0, SWAP_SMT_P4053
} ,
1657 #define N_SMT_PLEN ARRAY_SIZE(smt_pdef)
1659 int smt_check_para(struct s_smc
*smc
, struct smt_header
*sm
,
1660 const u_short list
[])
1662 const u_short
*p
= list
;
1664 if (!sm_to_para(smc
,sm
,(int) *p
)) {
1665 DB_SMT("SMT: smt_check_para - missing para %x\n",*p
,0);
1673 void *sm_to_para(struct s_smc
*smc
, struct smt_header
*sm
, int para
)
1683 p
= (char *)(sm
+1) ; /* pointer to info */
1685 if (((struct smt_para
*)p
)->p_type
== para
)
1686 found
= (void *) p
;
1687 plen
= ((struct smt_para
*)p
)->p_len
+ PARA_LEN
;
1691 DB_SMT("SMT : sm_to_para - length error %d\n",plen
,0) ;
1694 if ((plen
& 3) && (para
!= SMT_P_ECHODATA
)) {
1695 DB_SMT("SMT : sm_to_para - odd length %d\n",plen
,0) ;
1706 * send ANTC data test frame
1708 void fddi_send_antc(struct s_smc
*smc
, struct fddi_addr
*dest
)
1714 struct smt_header
*smt
;
1718 mb
= smt_get_mbuf() ;
1719 mb
->sm_len
= 3000+12 ;
1720 p
= smtod(mb
, char *) + 12 ;
1721 for (i
= 0 ; i
< 3000 ; i
++)
1724 smt
= smtod(mb
, struct smt_header
*) ;
1725 smt
->smt_dest
= *dest
;
1726 smt
->smt_source
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
1727 smt_send_mbuf(smc
,mb
,FC_ASYNC_LLC
) ;
1733 #define hextoasc(x) "0123456789abcdef"[x]
1735 char *addr_to_string(struct fddi_addr
*addr
)
1738 static char string
[6*3] = "****" ;
1740 for (i
= 0 ; i
< 6 ; i
++) {
1741 string
[i
*3] = hextoasc((addr
->a
[i
]>>4)&0xf) ;
1742 string
[i
*3+1] = hextoasc((addr
->a
[i
])&0xf) ;
1743 string
[i
*3+2] = ':' ;
1751 int smt_ifconfig(int argc
, char *argv
[])
1753 if (argc
>= 2 && !strcmp(argv
[0],"opt_bypass") &&
1754 !strcmp(argv
[1],"yes")) {
1755 smc
->mib
.fddiSMTBypassPresent
= 1 ;
1758 return(amdfddi_config(0,argc
,argv
)) ;
1763 * return static mac index
1765 static int mac_index(struct s_smc
*smc
, int mac
)
1772 return((smc
->s
.sas
== SMT_SAS
) ? 2 : 3) ;
1777 * return static phy index
1779 static int phy_index(struct s_smc
*smc
, int phy
)
1786 * return dynamic mac connection resource index
1788 static int mac_con_resource_index(struct s_smc
*smc
, int mac
)
1793 return(entity_to_index(smc
,cem_get_downstream(smc
,ENTITY_MAC
))) ;
1796 switch (smc
->mib
.fddiSMTCF_State
) {
1799 case SC11_C_WRAP_S
:
1801 case SC10_C_WRAP_B
:
1805 return(smc
->s
.sas
== SMT_SAS
? 2 : 3) ;
1810 * return dynamic phy connection resource index
1812 static int phy_con_resource_index(struct s_smc
*smc
, int phy
)
1815 return(entity_to_index(smc
,cem_get_downstream(smc
,ENTITY_PHY(phy
)))) ;
1817 switch (smc
->mib
.fddiSMTCF_State
) {
1819 return(phy
== PA
? 3 : 2) ;
1820 case SC10_C_WRAP_B
:
1821 return(phy
== PA
? 1 : 3) ;
1823 return(phy
== PA
? 3 : 1) ;
1825 return(phy
== PA
? 2 : 3) ;
1826 case SC11_C_WRAP_S
:
1834 static int entity_to_index(struct s_smc
*smc
, int e
)
1836 if (e
== ENTITY_MAC
)
1837 return(mac_index(smc
,1)) ;
1839 return(phy_index(smc
,e
- ENTITY_PHY(0))) ;
1843 #ifdef LITTLE_ENDIAN
1844 static int smt_swap_short(u_short s
)
1846 return(((s
>>8)&0xff)|((s
&0xff)<<8)) ;
1849 void smt_swap_para(struct smt_header
*sm
, int len
, int direction
)
1850 /* int direction; 0 encode 1 decode */
1852 struct smt_para
*pa
;
1853 const struct smt_pdef
*pd
;
1859 /* printf("smt_swap_para sm %x len %d dir %d\n",
1862 smt_string_swap((char *)sm
,SWAP_SMTHEADER
,len
) ;
1865 len
-= sizeof(struct smt_header
) ;
1867 p
= (char *) (sm
+ 1) ;
1869 pa
= (struct smt_para
*) p
;
1872 pa
->p_type
= smt_swap_short(pa
->p_type
) ;
1873 pa
->p_len
= smt_swap_short(pa
->p_len
) ;
1879 * note: paras can have 0 length !
1884 for (i
= N_SMT_PLEN
, pd
= smt_pdef
; i
; i
--,pd
++) {
1885 if (pd
->ptype
== type
)
1888 if (i
&& pd
->pswap
) {
1889 smt_string_swap(p
+PARA_LEN
,pd
->pswap
,len
) ;
1896 static void smt_string_swap(char *data
, const char *format
, int len
)
1898 const char *open_paren
= NULL
;
1901 while (len
> 0 && *format
) {
1904 open_paren
= format
;
1907 format
= open_paren
;
1918 data
+= *format
- '0' ;
1919 len
-= *format
- '0' ;
1947 void smt_swap_para(struct smt_header
*sm
, int len
, int direction
)
1948 /* int direction; 0 encode 1 decode */
1952 SK_UNUSED(direction
) ;
1959 int smt_action(struct s_smc
*smc
, int class, int code
, int index
)
1963 DB_SMT("SMT: action %d code %d\n",class,code
) ;
1965 case SMT_STATION_ACTION
:
1967 case SMT_STATION_ACTION_CONNECT
:
1968 smc
->mib
.fddiSMTRemoteDisconnectFlag
= FALSE
;
1969 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
1971 case SMT_STATION_ACTION_DISCONNECT
:
1972 queue_event(smc
,EVENT_ECM
,EC_DISCONNECT
) ;
1973 smc
->mib
.fddiSMTRemoteDisconnectFlag
= TRUE
;
1974 RS_SET(smc
,RS_DISCONNECT
) ;
1975 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1976 FDDI_SMT_EVENT
, (u_long
) FDDI_REMOTE_DISCONNECT
,
1977 smt_get_event_word(smc
));
1979 case SMT_STATION_ACTION_PATHTEST
:
1980 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1981 FDDI_SMT_EVENT
, (u_long
) FDDI_PATH_TEST
,
1982 smt_get_event_word(smc
));
1984 case SMT_STATION_ACTION_SELFTEST
:
1985 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1986 FDDI_SMT_EVENT
, (u_long
) FDDI_REMOTE_SELF_TEST
,
1987 smt_get_event_word(smc
));
1989 case SMT_STATION_ACTION_DISABLE_A
:
1990 if (smc
->y
[PA
].pc_mode
== PM_PEER
) {
1991 RS_SET(smc
,RS_EVENT
) ;
1992 queue_event(smc
,EVENT_PCM
+PA
,PC_DISABLE
) ;
1995 case SMT_STATION_ACTION_DISABLE_B
:
1996 if (smc
->y
[PB
].pc_mode
== PM_PEER
) {
1997 RS_SET(smc
,RS_EVENT
) ;
1998 queue_event(smc
,EVENT_PCM
+PB
,PC_DISABLE
) ;
2001 case SMT_STATION_ACTION_DISABLE_M
:
2002 for (port
= 0 ; port
< NUMPHYS
; port
++) {
2003 if (smc
->mib
.p
[port
].fddiPORTMy_Type
!= TM
)
2005 RS_SET(smc
,RS_EVENT
) ;
2006 queue_event(smc
,EVENT_PCM
+port
,PC_DISABLE
) ;
2013 case SMT_PORT_ACTION
:
2015 case SMT_PORT_ACTION_ENABLE
:
2018 case SMT_PORT_ACTION_DISABLE
:
2019 event
= PC_DISABLE
;
2021 case SMT_PORT_ACTION_MAINT
:
2024 case SMT_PORT_ACTION_START
:
2027 case SMT_PORT_ACTION_STOP
:
2033 queue_event(smc
,EVENT_PCM
+index
,event
) ;
2042 * canonical conversion of <len> bytes beginning form *data
2045 static void hwm_conv_can(struct s_smc
*smc
, char *data
, int len
)
2051 for (i
= len
; i
; i
--, data
++)
2052 *data
= bitrev8(*data
);
2056 #endif /* no SLIM_SMT */