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>
22 #include <linux/kernel.h>
25 #include "h/smtstate.h"
28 static const char ID_sccs
[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
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
= {
61 static int smt_swap_short(u_short s
);
63 static int mac_index(struct s_smc
*smc
, int mac
);
64 static int phy_index(struct s_smc
*smc
, int phy
);
65 static int mac_con_resource_index(struct s_smc
*smc
, int mac
);
66 static int phy_con_resource_index(struct s_smc
*smc
, int phy
);
67 static void smt_send_rdf(struct s_smc
*smc
, SMbuf
*rej
, int fc
, int reason
,
69 static void smt_send_nif(struct s_smc
*smc
, const struct fddi_addr
*dest
,
70 int fc
, u_long tid
, int type
, int local
);
71 static void smt_send_ecf(struct s_smc
*smc
, struct fddi_addr
*dest
, int fc
,
72 u_long tid
, int type
, int len
);
73 static void smt_echo_test(struct s_smc
*smc
, int dna
);
74 static void smt_send_sif_config(struct s_smc
*smc
, struct fddi_addr
*dest
,
75 u_long tid
, int local
);
76 static void smt_send_sif_operation(struct s_smc
*smc
, struct fddi_addr
*dest
,
77 u_long tid
, int local
);
79 static void smt_string_swap(char *data
, const char *format
, int len
);
81 static void smt_add_frame_len(SMbuf
*mb
, int len
);
82 static void smt_fill_una(struct s_smc
*smc
, struct smt_p_una
*una
);
83 static void smt_fill_sde(struct s_smc
*smc
, struct smt_p_sde
*sde
);
84 static void smt_fill_state(struct s_smc
*smc
, struct smt_p_state
*state
);
85 static void smt_fill_timestamp(struct s_smc
*smc
, struct smt_p_timestamp
*ts
);
86 static void smt_fill_policy(struct s_smc
*smc
, struct smt_p_policy
*policy
);
87 static void smt_fill_latency(struct s_smc
*smc
, struct smt_p_latency
*latency
);
88 static void smt_fill_neighbor(struct s_smc
*smc
, struct smt_p_neighbor
*neighbor
);
89 static int smt_fill_path(struct s_smc
*smc
, struct smt_p_path
*path
);
90 static void smt_fill_mac_status(struct s_smc
*smc
, struct smt_p_mac_status
*st
);
91 static void smt_fill_lem(struct s_smc
*smc
, struct smt_p_lem
*lem
, int phy
);
92 static void smt_fill_version(struct s_smc
*smc
, struct smt_p_version
*vers
);
93 static void smt_fill_fsc(struct s_smc
*smc
, struct smt_p_fsc
*fsc
);
94 static void smt_fill_mac_counter(struct s_smc
*smc
, struct smt_p_mac_counter
*mc
);
95 static void smt_fill_mac_fnc(struct s_smc
*smc
, struct smt_p_mac_fnc
*fnc
);
96 static void smt_fill_manufacturer(struct s_smc
*smc
,
97 struct smp_p_manufacturer
*man
);
98 static void smt_fill_user(struct s_smc
*smc
, struct smp_p_user
*user
);
99 static void smt_fill_setcount(struct s_smc
*smc
, struct smt_p_setcount
*setcount
);
100 static void smt_fill_echo(struct s_smc
*smc
, struct smt_p_echo
*echo
, u_long seed
,
103 static void smt_clear_una_dna(struct s_smc
*smc
);
104 static void smt_clear_old_una_dna(struct s_smc
*smc
);
106 static int entity_to_index(void);
108 static void update_dac(struct s_smc
*smc
, int report
);
109 static int div_ratio(u_long upper
, u_long lower
);
111 static void hwm_conv_can(struct s_smc
*smc
, char *data
, int len
);
113 #define hwm_conv_can(smc,data,len)
117 static inline int is_my_addr(const struct s_smc
*smc
,
118 const struct fddi_addr
*addr
)
120 return(*(short *)(&addr
->a
[0]) ==
121 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[0])
122 && *(short *)(&addr
->a
[2]) ==
123 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[2])
124 && *(short *)(&addr
->a
[4]) ==
125 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[4])) ;
128 static inline int is_broadcast(const struct fddi_addr
*addr
)
130 return(*(u_short
*)(&addr
->a
[0]) == 0xffff &&
131 *(u_short
*)(&addr
->a
[2]) == 0xffff &&
132 *(u_short
*)(&addr
->a
[4]) == 0xffff ) ;
135 static inline int is_individual(const struct fddi_addr
*addr
)
137 return(!(addr
->a
[0] & GROUP_ADDR
)) ;
140 static inline int is_equal(const struct fddi_addr
*addr1
,
141 const struct fddi_addr
*addr2
)
143 return(*(u_short
*)(&addr1
->a
[0]) == *(u_short
*)(&addr2
->a
[0]) &&
144 *(u_short
*)(&addr1
->a
[2]) == *(u_short
*)(&addr2
->a
[2]) &&
145 *(u_short
*)(&addr1
->a
[4]) == *(u_short
*)(&addr2
->a
[4]) ) ;
149 * list of mandatory paras in frames
151 static const u_short plist_nif
[] = { SMT_P_UNA
,SMT_P_SDE
,SMT_P_STATE
,0 } ;
156 void smt_agent_init(struct s_smc
*smc
)
163 smc
->mib
.m
[MAC0
].fddiMACSMTAddress
= smc
->hw
.fddi_home_addr
;
166 * get OUI address from driver (bia == built-in-address)
168 smc
->mib
.fddiSMTStationId
.sid_oem
[0] = 0 ;
169 smc
->mib
.fddiSMTStationId
.sid_oem
[1] = 0 ;
170 driver_get_bia(smc
,&smc
->mib
.fddiSMTStationId
.sid_node
) ;
171 for (i
= 0 ; i
< 6 ; i
++) {
172 smc
->mib
.fddiSMTStationId
.sid_node
.a
[i
] =
173 bitrev8(smc
->mib
.fddiSMTStationId
.sid_node
.a
[i
]);
175 smc
->mib
.fddiSMTManufacturerData
[0] =
176 smc
->mib
.fddiSMTStationId
.sid_node
.a
[0] ;
177 smc
->mib
.fddiSMTManufacturerData
[1] =
178 smc
->mib
.fddiSMTStationId
.sid_node
.a
[1] ;
179 smc
->mib
.fddiSMTManufacturerData
[2] =
180 smc
->mib
.fddiSMTStationId
.sid_node
.a
[2] ;
181 smc
->sm
.smt_tid
= 0 ;
182 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
= DA_NONE
;
183 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
= FALSE
;
185 smt_clear_una_dna(smc
) ;
186 smt_clear_old_una_dna(smc
) ;
188 for (i
= 0 ; i
< SMT_MAX_TEST
; i
++)
189 smc
->sm
.pend
[i
] = 0 ;
190 smc
->sm
.please_reconnect
= 0 ;
191 smc
->sm
.uniq_ticks
= 0 ;
202 void smt_agent_task(struct s_smc
*smc
)
204 smt_timer_start(smc
,&smc
->sm
.smt_timer
, (u_long
)1000000L,
205 EV_TOKEN(EVENT_SMT
,SM_TIMER
)) ;
206 DB_SMT("SMT agent task\n",0,0) ;
209 #ifndef SMT_REAL_TOKEN_CT
210 void smt_emulate_token_ct(struct s_smc
*smc
, int mac_index
)
216 time
= smt_get_time();
217 count
= ((time
- smc
->sm
.last_tok_time
[mac_index
]) *
218 100)/TICKS_PER_SECOND
;
221 * Only when ring is up we will have a token count. The
222 * flag is unfortunatly a single instance value. This
223 * doesn't matter now, because we currently have only
226 if (smc
->hw
.mac_ring_is_up
){
227 smc
->mib
.m
[mac_index
].fddiMACToken_Ct
+= count
;
230 /* Remember current time */
231 smc
->sm
.last_tok_time
[mac_index
] = time
;
237 void smt_event(struct s_smc
*smc
, int event
)
240 #ifndef SMT_REAL_TOKEN_CT
245 if (smc
->sm
.please_reconnect
) {
246 smc
->sm
.please_reconnect
-- ;
247 if (smc
->sm
.please_reconnect
== 0) {
249 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
253 if (event
== SM_FAST
)
257 * timer for periodic cleanup in driver
258 * reset and start the watchdog (FM2)
262 smt_timer_poll(smc
) ;
263 smt_start_watchdog(smc
) ;
267 ess_timer_poll(smc
) ;
271 sba_timer_poll(smc
) ;
274 smt_srf_event(smc
,0,0,0) ;
276 #endif /* no SLIM_SMT */
278 time
= smt_get_time() ;
280 if (time
- smc
->sm
.smt_last_lem
>= TICKS_PER_SECOND
*8) {
282 * Use 8 sec. for the time intervall, it simplifies the
285 struct fddi_mib_m
*mib
;
292 * calculate LEM bit error rate
294 sm_lem_evaluate(smc
) ;
295 smc
->sm
.smt_last_lem
= time
;
301 mac_update_counter(smc
) ;
304 (mib
->fddiMACLost_Ct
- mib
->fddiMACOld_Lost_Ct
) +
305 (mib
->fddiMACError_Ct
- mib
->fddiMACOld_Error_Ct
) ;
307 (mib
->fddiMACFrame_Ct
- mib
->fddiMACOld_Frame_Ct
) +
308 (mib
->fddiMACLost_Ct
- mib
->fddiMACOld_Lost_Ct
) ;
309 mib
->fddiMACFrameErrorRatio
= div_ratio(upper
,lower
) ;
312 ((!mib
->fddiMACFrameErrorThreshold
&&
313 mib
->fddiMACError_Ct
!= mib
->fddiMACOld_Error_Ct
) ||
314 (mib
->fddiMACFrameErrorRatio
>
315 mib
->fddiMACFrameErrorThreshold
)) ;
317 if (cond
!= mib
->fddiMACFrameErrorFlag
)
318 smt_srf_event(smc
,SMT_COND_MAC_FRAME_ERROR
,
322 (mib
->fddiMACNotCopied_Ct
- mib
->fddiMACOld_NotCopied_Ct
) ;
325 (mib
->fddiMACCopied_Ct
- mib
->fddiMACOld_Copied_Ct
) ;
326 mib
->fddiMACNotCopiedRatio
= div_ratio(upper
,lower
) ;
329 ((!mib
->fddiMACNotCopiedThreshold
&&
330 mib
->fddiMACNotCopied_Ct
!=
331 mib
->fddiMACOld_NotCopied_Ct
)||
332 (mib
->fddiMACNotCopiedRatio
>
333 mib
->fddiMACNotCopiedThreshold
)) ;
335 if (cond
!= mib
->fddiMACNotCopiedFlag
)
336 smt_srf_event(smc
,SMT_COND_MAC_NOT_COPIED
,
342 mib
->fddiMACOld_Frame_Ct
= mib
->fddiMACFrame_Ct
;
343 mib
->fddiMACOld_Copied_Ct
= mib
->fddiMACCopied_Ct
;
344 mib
->fddiMACOld_Error_Ct
= mib
->fddiMACError_Ct
;
345 mib
->fddiMACOld_Lost_Ct
= mib
->fddiMACLost_Ct
;
346 mib
->fddiMACOld_NotCopied_Ct
= mib
->fddiMACNotCopied_Ct
;
349 * Check port EBError Condition
351 for (port
= 0; port
< NUMPHYS
; port
++) {
352 phy
= &smc
->y
[port
] ;
354 if (!phy
->mib
->fddiPORTHardwarePresent
) {
358 cond
= (phy
->mib
->fddiPORTEBError_Ct
-
359 phy
->mib
->fddiPORTOldEBError_Ct
> 5) ;
361 /* If ratio is more than 5 in 8 seconds
364 smt_srf_event(smc
,SMT_COND_PORT_EB_ERROR
,
365 (int) (INDEX_PORT
+ phy
->np
) ,cond
) ;
370 phy
->mib
->fddiPORTOldEBError_Ct
=
371 phy
->mib
->fddiPORTEBError_Ct
;
374 #endif /* no SLIM_SMT */
379 if (time
- smc
->sm
.smt_last_notify
>= (u_long
)
380 (smc
->mib
.fddiSMTTT_Notify
* TICKS_PER_SECOND
) ) {
382 * we can either send an announcement or a request
383 * a request will trigger a reply so that we can update
385 * note: same tid must be used until reply is received
387 if (!smc
->sm
.pend
[SMT_TID_NIF
])
388 smc
->sm
.pend
[SMT_TID_NIF
] = smt_get_tid(smc
) ;
389 smt_send_nif(smc
,&fddi_broadcast
, FC_SMT_NSA
,
390 smc
->sm
.pend
[SMT_TID_NIF
], SMT_REQUEST
,0) ;
391 smc
->sm
.smt_last_notify
= time
;
397 if (smc
->sm
.smt_tvu
&&
398 time
- smc
->sm
.smt_tvu
> 228*TICKS_PER_SECOND
) {
399 DB_SMT("SMT : UNA expired\n",0,0) ;
400 smc
->sm
.smt_tvu
= 0 ;
402 if (!is_equal(&smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
404 /* Do not update unknown address */
405 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
=
406 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
408 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
= SMT_Unknown
;
409 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
= FALSE
;
411 * Make sure the fddiMACUNDA_Flag = FALSE is
412 * included in the SRF so we don't generate
413 * a separate SRF for the deassertion of this
417 smt_srf_event(smc
, SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
420 if (smc
->sm
.smt_tvd
&&
421 time
- smc
->sm
.smt_tvd
> 228*TICKS_PER_SECOND
) {
422 DB_SMT("SMT : DNA expired\n",0,0) ;
423 smc
->sm
.smt_tvd
= 0 ;
424 if (!is_equal(&smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
,
426 /* Do not update unknown address */
427 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
=
428 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
430 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
= SMT_Unknown
;
431 smt_srf_event(smc
, SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
435 #endif /* no SLIM_SMT */
437 #ifndef SMT_REAL_TOKEN_CT
439 * Token counter emulation section. If hardware supports the token
440 * count, the token counter will be updated in mac_update_counter.
442 for (i
= MAC0
; i
< NUMMACS
; i
++ ){
443 if (time
- smc
->sm
.last_tok_time
[i
] > 2*TICKS_PER_SECOND
){
444 smt_emulate_token_ct( smc
, i
);
449 smt_timer_start(smc
,&smc
->sm
.smt_timer
, (u_long
)1000000L,
450 EV_TOKEN(EVENT_SMT
,SM_TIMER
)) ;
453 static int div_ratio(u_long upper
, u_long lower
)
455 if ((upper
<<16L) < upper
)
456 upper
= 0xffff0000L
;
461 return((int)(upper
/lower
)) ;
467 * receive packet handler
469 void smt_received_pack(struct s_smc
*smc
, SMbuf
*mb
, int fs
)
470 /* int fs; frame status */
472 struct smt_header
*sm
;
479 case FC_SMT_LAN_LOC
:
484 smt_free_mbuf(smc
,mb
) ;
488 smc
->mib
.m
[MAC0
].fddiMACSMTCopied_Ct
++ ;
489 sm
= smtod(mb
,struct smt_header
*) ;
490 local
= ((fs
& L_INDICATOR
) != 0) ;
491 hwm_conv_can(smc
,(char *)sm
,12) ;
493 /* check destination address */
494 if (is_individual(&sm
->smt_dest
) && !is_my_addr(smc
,&sm
->smt_dest
)) {
495 smt_free_mbuf(smc
,mb
) ;
498 #if 0 /* for DUP recognition, do NOT filter them */
499 /* ignore loop back packets */
500 if (is_my_addr(smc
,&sm
->smt_source
) && !local
) {
501 smt_free_mbuf(smc
,mb
) ;
506 smt_swap_para(sm
,(int) mb
->sm_len
,1) ;
507 DB_SMT("SMT : received packet [%s] at 0x%x\n",
508 smt_type_name
[m_fc(mb
) & 0xf],sm
) ;
509 DB_SMT("SMT : version %d, class %s\n",sm
->smt_version
,
510 smt_class_name
[(sm
->smt_class
>LAST_CLASS
)?0 : sm
->smt_class
]) ;
516 if (m_fc(mb
) == FC_SMT_NSA
&& sm
->smt_class
== SMT_NIF
&&
517 (sm
->smt_type
== SMT_ANNOUNCE
|| sm
->smt_type
== SMT_REQUEST
)) {
524 * ignore any packet with NSA and A-indicator set
526 if ( (fs
& A_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
) {
527 DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
528 addr_to_string(&sm
->smt_source
),0) ;
529 smt_free_mbuf(smc
,mb
) ;
534 * ignore frames with illegal length
536 if (((sm
->smt_class
== SMT_ECF
) && (sm
->smt_len
> SMT_MAX_ECHO_LEN
)) ||
537 ((sm
->smt_class
!= SMT_ECF
) && (sm
->smt_len
> SMT_MAX_INFO_LEN
))) {
538 smt_free_mbuf(smc
,mb
) ;
545 switch (sm
->smt_class
) {
547 case SMT_SIF_CONFIG
:
550 if (sm
->smt_version
!= SMT_VID
)
554 if (sm
->smt_version
!= SMT_VID_2
)
559 DB_SMT("SMT : version = %d, dest = %s\n",
560 sm
->smt_version
,addr_to_string(&sm
->smt_source
)) ;
561 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_VERSION
,local
) ;
562 smt_free_mbuf(smc
,mb
) ;
565 if ((sm
->smt_len
> mb
->sm_len
- sizeof(struct smt_header
)) ||
566 ((sm
->smt_len
& 3) && (sm
->smt_class
!= SMT_ECF
))) {
567 DB_SMT("SMT: info length error, len = %d\n",sm
->smt_len
,0) ;
568 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_LENGTH
,local
) ;
569 smt_free_mbuf(smc
,mb
) ;
572 switch (sm
->smt_class
) {
574 if (smt_check_para(smc
,sm
,plist_nif
)) {
575 DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
578 switch (sm
->smt_type
) {
581 if (!(fs
& C_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
582 && is_broadcast(&sm
->smt_dest
)) {
583 struct smt_p_state
*st
;
587 &smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
589 DB_SMT("SMT : updated my UNA = %s\n",
590 addr_to_string(&sm
->smt_source
),0) ;
591 if (!is_equal(&smc
->mib
.m
[MAC0
].
592 fddiMACUpstreamNbr
,&SMT_Unknown
)){
593 /* Do not update unknown address */
594 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
=
595 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
598 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
=
601 SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
603 smt_echo_test(smc
,0) ;
605 smc
->sm
.smt_tvu
= smt_get_time() ;
606 st
= (struct smt_p_state
*)
607 sm_to_para(smc
,sm
,SMT_P_STATE
) ;
609 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
=
610 (st
->st_dupl_addr
& SMT_ST_MY_DUPA
) ?
615 if ((sm
->smt_type
== SMT_REQUEST
) &&
616 is_individual(&sm
->smt_source
) &&
617 ((!(fs
& A_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
) ||
618 (m_fc(mb
) != FC_SMT_NSA
))) {
619 DB_SMT("SMT : replying to NIF request %s\n",
620 addr_to_string(&sm
->smt_source
),0) ;
621 smt_send_nif(smc
,&sm
->smt_source
,
628 DB_SMT("SMT : received NIF response from %s\n",
629 addr_to_string(&sm
->smt_source
),0) ;
630 if (fs
& A_INDICATOR
) {
631 smc
->sm
.pend
[SMT_TID_NIF
] = 0 ;
632 DB_SMT("SMT : duplicate address\n",0,0) ;
633 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
=
635 smc
->r
.dup_addr_test
= DA_FAILED
;
636 queue_event(smc
,EVENT_RMT
,RM_DUP_ADDR
) ;
637 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
= TRUE
;
641 if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_NIF
]) {
642 smc
->sm
.pend
[SMT_TID_NIF
] = 0 ;
645 &smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
,
647 DB_SMT("SMT : updated my DNA\n",0,0) ;
648 if (!is_equal(&smc
->mib
.m
[MAC0
].
649 fddiMACDownstreamNbr
, &SMT_Unknown
)){
650 /* Do not update unknown address */
651 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
=
652 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
655 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
=
658 SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
660 smt_echo_test(smc
,1) ;
662 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
= FALSE
;
664 smc
->sm
.smt_tvd
= smt_get_time() ;
665 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
=
667 if (smc
->r
.dup_addr_test
!= DA_PASSED
) {
668 smc
->r
.dup_addr_test
= DA_PASSED
;
669 queue_event(smc
,EVENT_RMT
,RM_DUP_ADDR
) ;
672 else if (sm
->smt_tid
==
673 smc
->sm
.pend
[SMT_TID_NIF_TEST
]) {
674 DB_SMT("SMT : NIF test TID ok\n",0,0) ;
677 DB_SMT("SMT : expected TID %lx, got %lx\n",
678 smc
->sm
.pend
[SMT_TID_NIF
],sm
->smt_tid
) ;
686 case SMT_SIF_CONFIG
: /* station information */
687 if (sm
->smt_type
!= SMT_REQUEST
)
689 DB_SMT("SMT : replying to SIF Config request from %s\n",
690 addr_to_string(&sm
->smt_source
),0) ;
691 smt_send_sif_config(smc
,&sm
->smt_source
,sm
->smt_tid
,local
) ;
693 case SMT_SIF_OPER
: /* station information */
694 if (sm
->smt_type
!= SMT_REQUEST
)
696 DB_SMT("SMT : replying to SIF Operation request from %s\n",
697 addr_to_string(&sm
->smt_source
),0) ;
698 smt_send_sif_operation(smc
,&sm
->smt_source
,sm
->smt_tid
,local
) ;
700 case SMT_ECF
: /* echo frame */
701 switch (sm
->smt_type
) {
703 smc
->mib
.priv
.fddiPRIVECF_Reply_Rx
++ ;
704 DB_SMT("SMT: received ECF reply from %s\n",
705 addr_to_string(&sm
->smt_source
),0) ;
706 if (sm_to_para(smc
,sm
,SMT_P_ECHODATA
) == NULL
) {
707 DB_SMT("SMT: ECHODATA missing\n",0,0) ;
710 if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF
]) {
711 DB_SMT("SMT : ECF test TID ok\n",0,0) ;
713 else if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF_UNA
]) {
714 DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
716 else if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF_DNA
]) {
717 DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
720 DB_SMT("SMT : expected TID %lx, got %lx\n",
721 smc
->sm
.pend
[SMT_TID_ECF
],
726 smc
->mib
.priv
.fddiPRIVECF_Req_Rx
++ ;
728 if (sm
->smt_len
&& !sm_to_para(smc
,sm
,SMT_P_ECHODATA
)) {
729 DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
730 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_LENGTH
,
734 DB_SMT("SMT - sending ECF reply to %s\n",
735 addr_to_string(&sm
->smt_source
),0) ;
737 /* set destination addr. & reply */
738 sm
->smt_dest
= sm
->smt_source
;
739 sm
->smt_type
= SMT_REPLY
;
740 dump_smt(smc
,sm
,"ECF REPLY") ;
741 smc
->mib
.priv
.fddiPRIVECF_Reply_Tx
++ ;
742 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
743 return ; /* DON'T free mbuf */
751 case SMT_RAF
: /* resource allocation */
753 DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
754 fs
= ess_raf_received_pack(smc
,mb
,sm
,fs
) ;
758 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
759 sba_raf_received_pack(smc
,sm
,fs
) ;
762 case SMT_RDF
: /* request denied */
763 smc
->mib
.priv
.fddiPRIVRDF_Rx
++ ;
765 case SMT_ESF
: /* extended service - not supported */
766 if (sm
->smt_type
== SMT_REQUEST
) {
767 DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
768 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_CLASS
,local
) ;
773 if (sm
->smt_type
!= SMT_REQUEST
)
775 /* update statistics */
776 if (sm
->smt_class
== SMT_PMF_GET
)
777 smc
->mib
.priv
.fddiPRIVPMF_Get_Rx
++ ;
779 smc
->mib
.priv
.fddiPRIVPMF_Set_Rx
++ ;
781 * ignore PMF SET with I/G set
783 if ((sm
->smt_class
== SMT_PMF_SET
) &&
784 !is_individual(&sm
->smt_dest
)) {
785 DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
788 smt_pmf_received_pack(smc
,mb
, local
) ;
791 dump_smt(smc
,sm
,"SRF received") ;
794 if (sm
->smt_type
!= SMT_REQUEST
)
797 * For frames with unknown class:
798 * we need to send a RDF frame according to 8.1.3.1.1,
799 * only if it is a REQUEST.
801 DB_SMT("SMT : class = %d, send RDF to %s\n",
802 sm
->smt_class
, addr_to_string(&sm
->smt_source
)) ;
804 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_CLASS
,local
) ;
809 DB_SMT("SMT: discarding invalid frame, reason = %d\n",
812 smt_free_mbuf(smc
,mb
) ;
815 static void update_dac(struct s_smc
*smc
, int report
)
819 cond
= ( smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
|
820 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
) != 0 ;
821 if (report
&& (cond
!= smc
->mib
.m
[MAC0
].fddiMACDuplicateAddressCond
))
822 smt_srf_event(smc
, SMT_COND_MAC_DUP_ADDR
,INDEX_MAC
,cond
) ;
824 smc
->mib
.m
[MAC0
].fddiMACDuplicateAddressCond
= cond
;
833 void smt_send_frame(struct s_smc
*smc
, SMbuf
*mb
, int fc
, int local
)
834 /* SMbuf *mb; buffer to send */
835 /* int fc; FC value */
837 struct smt_header
*sm
;
839 if (!smc
->r
.sm_ma_avail
&& !local
) {
840 smt_free_mbuf(smc
,mb
) ;
843 sm
= smtod(mb
,struct smt_header
*) ;
844 sm
->smt_source
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
845 sm
->smt_sid
= smc
->mib
.fddiSMTStationId
;
847 smt_swap_para(sm
,(int) mb
->sm_len
,0) ; /* swap para & header */
848 hwm_conv_can(smc
,(char *)sm
,12) ; /* convert SA and DA */
849 smc
->mib
.m
[MAC0
].fddiMACSMTTransmit_Ct
++ ;
850 smt_send_mbuf(smc
,mb
,local
? FC_SMT_LOC
: fc
) ;
854 * generate and send RDF
856 static void smt_send_rdf(struct s_smc
*smc
, SMbuf
*rej
, int fc
, int reason
,
858 /* SMbuf *rej; mbuf of offending frame */
859 /* int fc; FC of denied frame */
860 /* int reason; reason code */
863 struct smt_header
*sm
; /* header of offending frame */
864 struct smt_rdf
*rdf
;
868 sm
= smtod(rej
,struct smt_header
*) ;
869 if (sm
->smt_type
!= SMT_REQUEST
)
872 DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
873 addr_to_string(&sm
->smt_source
),reason
) ;
877 * note: get framelength from MAC length, NOT from SMT header
878 * smt header length is included in sm_len
880 frame_len
= rej
->sm_len
;
882 if (!(mb
=smt_build_frame(smc
,SMT_RDF
,SMT_REPLY
,sizeof(struct smt_rdf
))))
884 rdf
= smtod(mb
,struct smt_rdf
*) ;
885 rdf
->smt
.smt_tid
= sm
->smt_tid
; /* use TID from sm */
886 rdf
->smt
.smt_dest
= sm
->smt_source
; /* set dest = source */
889 rdf
->reason
.para
.p_type
= SMT_P_REASON
;
890 rdf
->reason
.para
.p_len
= sizeof(struct smt_p_reason
) - PARA_LEN
;
891 rdf
->reason
.rdf_reason
= reason
;
894 rdf
->version
.para
.p_type
= SMT_P_VERSION
;
895 rdf
->version
.para
.p_len
= sizeof(struct smt_p_version
) - PARA_LEN
;
896 rdf
->version
.v_pad
= 0 ;
897 rdf
->version
.v_n
= 1 ;
898 rdf
->version
.v_index
= 1 ;
899 rdf
->version
.v_version
[0] = SMT_VID_2
;
900 rdf
->version
.v_pad2
= 0 ;
903 if ((unsigned) frame_len
<= SMT_MAX_INFO_LEN
- sizeof(*rdf
) +
904 2*sizeof(struct smt_header
))
907 len
= SMT_MAX_INFO_LEN
- sizeof(*rdf
) +
908 2*sizeof(struct smt_header
) ;
909 /* make length multiple of 4 */
911 rdf
->refused
.para
.p_type
= SMT_P_REFUSED
;
912 /* length of para is smt_frame + ref_fc */
913 rdf
->refused
.para
.p_len
= len
+ 4 ;
914 rdf
->refused
.ref_fc
= fc
;
917 smt_swap_para(sm
,frame_len
,0) ;
919 memcpy((char *) &rdf
->refused
.ref_header
,(char *) sm
,len
) ;
921 len
-= sizeof(struct smt_header
) ;
923 rdf
->smt
.smt_len
+= len
;
925 dump_smt(smc
,(struct smt_header
*)rdf
,"RDF") ;
926 smc
->mib
.priv
.fddiPRIVRDF_Tx
++ ;
927 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
931 * generate and send NIF
933 static void smt_send_nif(struct s_smc
*smc
, const struct fddi_addr
*dest
,
934 int fc
, u_long tid
, int type
, int local
)
935 /* struct fddi_addr *dest; dest address */
936 /* int fc; frame control */
937 /* u_long tid; transaction id */
938 /* int type; frame type */
940 struct smt_nif
*nif
;
943 if (!(mb
= smt_build_frame(smc
,SMT_NIF
,type
,sizeof(struct smt_nif
))))
945 nif
= smtod(mb
, struct smt_nif
*) ;
946 smt_fill_una(smc
,&nif
->una
) ; /* set UNA */
947 smt_fill_sde(smc
,&nif
->sde
) ; /* set station descriptor */
948 smt_fill_state(smc
,&nif
->state
) ; /* set state information */
950 smt_fill_fsc(smc
,&nif
->fsc
) ; /* set frame status cap. */
952 nif
->smt
.smt_dest
= *dest
; /* destination address */
953 nif
->smt
.smt_tid
= tid
; /* transaction ID */
954 dump_smt(smc
,(struct smt_header
*)nif
,"NIF") ;
955 smt_send_frame(smc
,mb
,fc
,local
) ;
960 * send NIF request (test purpose)
962 static void smt_send_nif_request(struct s_smc
*smc
, struct fddi_addr
*dest
)
964 smc
->sm
.pend
[SMT_TID_NIF_TEST
] = smt_get_tid(smc
) ;
965 smt_send_nif(smc
,dest
, FC_SMT_INFO
, smc
->sm
.pend
[SMT_TID_NIF_TEST
],
970 * send ECF request (test purpose)
972 static void smt_send_ecf_request(struct s_smc
*smc
, struct fddi_addr
*dest
,
975 smc
->sm
.pend
[SMT_TID_ECF
] = smt_get_tid(smc
) ;
976 smt_send_ecf(smc
,dest
, FC_SMT_INFO
, smc
->sm
.pend
[SMT_TID_ECF
],
984 static void smt_echo_test(struct s_smc
*smc
, int dna
)
988 smc
->sm
.pend
[dna
? SMT_TID_ECF_DNA
: SMT_TID_ECF_UNA
] =
989 tid
= smt_get_tid(smc
) ;
990 smt_send_ecf(smc
, dna
?
991 &smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
:
992 &smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
993 FC_SMT_INFO
,tid
, SMT_REQUEST
, (SMT_TEST_ECHO_LEN
& ~3)-8) ;
997 * generate and send ECF
999 static void smt_send_ecf(struct s_smc
*smc
, struct fddi_addr
*dest
, int fc
,
1000 u_long tid
, int type
, int len
)
1001 /* struct fddi_addr *dest; dest address */
1002 /* int fc; frame control */
1003 /* u_long tid; transaction id */
1004 /* int type; frame type */
1005 /* int len; frame length */
1007 struct smt_ecf
*ecf
;
1010 if (!(mb
= smt_build_frame(smc
,SMT_ECF
,type
,SMT_ECF_LEN
+ len
)))
1012 ecf
= smtod(mb
, struct smt_ecf
*) ;
1014 smt_fill_echo(smc
,&ecf
->ec_echo
,tid
,len
) ; /* set ECHO */
1015 ecf
->smt
.smt_dest
= *dest
; /* destination address */
1016 ecf
->smt
.smt_tid
= tid
; /* transaction ID */
1017 smc
->mib
.priv
.fddiPRIVECF_Req_Tx
++ ;
1018 smt_send_frame(smc
,mb
,fc
,0) ;
1022 * generate and send SIF config response
1025 static void smt_send_sif_config(struct s_smc
*smc
, struct fddi_addr
*dest
,
1026 u_long tid
, int local
)
1027 /* struct fddi_addr *dest; dest address */
1028 /* u_long tid; transaction id */
1030 struct smt_sif_config
*sif
;
1033 if (!(mb
= smt_build_frame(smc
,SMT_SIF_CONFIG
,SMT_REPLY
,
1034 SIZEOF_SMT_SIF_CONFIG
)))
1037 sif
= smtod(mb
, struct smt_sif_config
*) ;
1038 smt_fill_timestamp(smc
,&sif
->ts
) ; /* set time stamp */
1039 smt_fill_sde(smc
,&sif
->sde
) ; /* set station descriptor */
1040 smt_fill_version(smc
,&sif
->version
) ; /* set version information */
1041 smt_fill_state(smc
,&sif
->state
) ; /* set state information */
1042 smt_fill_policy(smc
,&sif
->policy
) ; /* set station policy */
1043 smt_fill_latency(smc
,&sif
->latency
); /* set station latency */
1044 smt_fill_neighbor(smc
,&sif
->neighbor
); /* set station neighbor */
1045 smt_fill_setcount(smc
,&sif
->setcount
) ; /* set count */
1046 len
= smt_fill_path(smc
,&sif
->path
); /* set station path descriptor*/
1047 sif
->smt
.smt_dest
= *dest
; /* destination address */
1048 sif
->smt
.smt_tid
= tid
; /* transaction ID */
1049 smt_add_frame_len(mb
,len
) ; /* adjust length fields */
1050 dump_smt(smc
,(struct smt_header
*)sif
,"SIF Configuration Reply") ;
1051 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
1055 * generate and send SIF operation response
1058 static void smt_send_sif_operation(struct s_smc
*smc
, struct fddi_addr
*dest
,
1059 u_long tid
, int local
)
1060 /* struct fddi_addr *dest; dest address */
1061 /* u_long tid; transaction id */
1063 struct smt_sif_operation
*sif
;
1069 #ifndef CONCENTRATOR
1070 if (smc
->s
.sas
== SMT_SAS
)
1074 if (!(mb
= smt_build_frame(smc
,SMT_SIF_OPER
,SMT_REPLY
,
1075 SIZEOF_SMT_SIF_OPERATION
+ports
*sizeof(struct smt_p_lem
))))
1077 sif
= smtod(mb
, struct smt_sif_operation
*) ;
1078 smt_fill_timestamp(smc
,&sif
->ts
) ; /* set time stamp */
1079 smt_fill_mac_status(smc
,&sif
->status
) ; /* set mac status */
1080 smt_fill_mac_counter(smc
,&sif
->mc
) ; /* set mac counter field */
1081 smt_fill_mac_fnc(smc
,&sif
->fnc
) ; /* set frame not copied counter */
1082 smt_fill_manufacturer(smc
,&sif
->man
) ; /* set manufacturer field */
1083 smt_fill_user(smc
,&sif
->user
) ; /* set user field */
1084 smt_fill_setcount(smc
,&sif
->setcount
) ; /* set count */
1086 * set link error mon information
1089 smt_fill_lem(smc
,sif
->lem
,PS
) ;
1092 for (i
= 0 ; i
< ports
; i
++) {
1093 smt_fill_lem(smc
,&sif
->lem
[i
],i
) ;
1097 sif
->smt
.smt_dest
= *dest
; /* destination address */
1098 sif
->smt
.smt_tid
= tid
; /* transaction ID */
1099 dump_smt(smc
,(struct smt_header
*)sif
,"SIF Operation Reply") ;
1100 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
1104 * get and initialize SMT frame
1106 SMbuf
*smt_build_frame(struct s_smc
*smc
, int class, int type
,
1110 struct smt_header
*smt
;
1113 if (!smc
->r
.sm_ma_avail
) {
1117 if (!(mb
= smt_get_mbuf(smc
)))
1120 mb
->sm_len
= length
;
1121 smt
= smtod(mb
, struct smt_header
*) ;
1122 smt
->smt_dest
= fddi_broadcast
; /* set dest = broadcast */
1123 smt
->smt_class
= class ;
1124 smt
->smt_type
= type
;
1127 case SMT_SIF_CONFIG
:
1130 smt
->smt_version
= SMT_VID
;
1133 smt
->smt_version
= SMT_VID_2
;
1136 smt
->smt_tid
= smt_get_tid(smc
) ; /* set transaction ID */
1138 smt
->smt_len
= length
- sizeof(struct smt_header
) ;
1142 static void smt_add_frame_len(SMbuf
*mb
, int len
)
1144 struct smt_header
*smt
;
1146 smt
= smtod(mb
, struct smt_header
*) ;
1147 smt
->smt_len
+= len
;
1154 * fill values in UNA parameter
1156 static void smt_fill_una(struct s_smc
*smc
, struct smt_p_una
*una
)
1158 SMTSETPARA(una
,SMT_P_UNA
) ;
1160 una
->una_node
= smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
1164 * fill values in SDE parameter
1166 static void smt_fill_sde(struct s_smc
*smc
, struct smt_p_sde
*sde
)
1168 SMTSETPARA(sde
,SMT_P_SDE
) ;
1169 sde
->sde_non_master
= smc
->mib
.fddiSMTNonMaster_Ct
;
1170 sde
->sde_master
= smc
->mib
.fddiSMTMaster_Ct
;
1171 sde
->sde_mac_count
= NUMMACS
; /* only 1 MAC */
1173 sde
->sde_type
= SMT_SDE_CONCENTRATOR
;
1175 sde
->sde_type
= SMT_SDE_STATION
;
1180 * fill in values in station state parameter
1182 static void smt_fill_state(struct s_smc
*smc
, struct smt_p_state
*state
)
1187 SMTSETPARA(state
,SMT_P_STATE
) ;
1190 /* determine topology */
1192 if (smc
->mib
.fddiSMTPeerWrapFlag
) {
1193 top
|= SMT_ST_WRAPPED
; /* state wrapped */
1196 if (cfm_status_unattached(smc
)) {
1197 top
|= SMT_ST_UNATTACHED
; /* unattached concentrator */
1200 if ((twist
= pcm_status_twisted(smc
)) & 1) {
1201 top
|= SMT_ST_TWISTED_A
; /* twisted cable */
1204 top
|= SMT_ST_TWISTED_B
; /* twisted cable */
1209 if (pcm_rooted_station(smc
))
1210 top
|= SMT_ST_ROOTED_S
;
1211 if (smc
->mib
.a
[0].fddiPATHSbaPayload
!= 0)
1212 top
|= SMT_ST_SYNC_SERVICE
;
1213 state
->st_topology
= top
;
1214 state
->st_dupl_addr
=
1215 ((smc
->mib
.m
[MAC0
].fddiMACDA_Flag
? SMT_ST_MY_DUPA
: 0 ) |
1216 (smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
? SMT_ST_UNA_DUPA
: 0)) ;
1220 * fill values in timestamp parameter
1222 static void smt_fill_timestamp(struct s_smc
*smc
, struct smt_p_timestamp
*ts
)
1225 SMTSETPARA(ts
,SMT_P_TIMESTAMP
) ;
1226 smt_set_timestamp(smc
,ts
->ts_time
) ;
1229 void smt_set_timestamp(struct s_smc
*smc
, u_char
*p
)
1235 * timestamp is 64 bits long ; resolution is 80 nS
1236 * our clock resolution is 10mS
1237 * 10mS/80ns = 125000 ~ 2^17 = 131072
1239 utime
= smt_get_time() ;
1240 time
= utime
* 100 ;
1241 time
/= TICKS_PER_SECOND
;
1243 p
[1] = (u_char
)((time
>>(8+8+8+8-1)) & 1) ;
1244 p
[2] = (u_char
)(time
>>(8+8+8-1)) ;
1245 p
[3] = (u_char
)(time
>>(8+8-1)) ;
1246 p
[4] = (u_char
)(time
>>(8-1)) ;
1247 p
[5] = (u_char
)(time
<<1) ;
1248 p
[6] = (u_char
)(smc
->sm
.uniq_ticks
>>8) ;
1249 p
[7] = (u_char
)smc
->sm
.uniq_ticks
;
1251 * make sure we don't wrap: restart whenever the upper digits change
1253 if (utime
!= smc
->sm
.uniq_time
) {
1254 smc
->sm
.uniq_ticks
= 0 ;
1256 smc
->sm
.uniq_ticks
++ ;
1257 smc
->sm
.uniq_time
= utime
;
1261 * fill values in station policy parameter
1263 static void smt_fill_policy(struct s_smc
*smc
, struct smt_p_policy
*policy
)
1271 * MIB para 101b (fddiSMTConnectionPolicy) coding
1272 * is different from 0005 coding
1274 static u_char ansi_weirdness
[16] = {
1275 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1277 SMTSETPARA(policy
,SMT_P_POLICY
) ;
1280 in
= smc
->mib
.fddiSMTConnectionPolicy
;
1281 for (i
= 0, map
= ansi_weirdness
; i
< 16 ; i
++) {
1287 policy
->pl_config
= smc
->mib
.fddiSMTConfigPolicy
;
1288 policy
->pl_connect
= out
;
1292 * fill values in latency equivalent parameter
1294 static void smt_fill_latency(struct s_smc
*smc
, struct smt_p_latency
*latency
)
1296 SMTSETPARA(latency
,SMT_P_LATENCY
) ;
1298 latency
->lt_phyout_idx1
= phy_index(smc
,0) ;
1299 latency
->lt_latency1
= 10 ; /* in octets (byte clock) */
1301 * note: latency has two phy entries by definition
1302 * for a SAS, the 2nd one is null
1304 if (smc
->s
.sas
== SMT_DAS
) {
1305 latency
->lt_phyout_idx2
= phy_index(smc
,1) ;
1306 latency
->lt_latency2
= 10 ; /* in octets (byte clock) */
1309 latency
->lt_phyout_idx2
= 0 ;
1310 latency
->lt_latency2
= 0 ;
1315 * fill values in MAC neighbors parameter
1317 static void smt_fill_neighbor(struct s_smc
*smc
, struct smt_p_neighbor
*neighbor
)
1319 SMTSETPARA(neighbor
,SMT_P_NEIGHBORS
) ;
1321 neighbor
->nb_mib_index
= INDEX_MAC
;
1322 neighbor
->nb_mac_index
= mac_index(smc
,1) ;
1323 neighbor
->nb_una
= smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
1324 neighbor
->nb_dna
= smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
1328 * fill values in path descriptor
1331 #define ALLPHYS NUMPHYS
1333 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1336 static int smt_fill_path(struct s_smc
*smc
, struct smt_p_path
*path
)
1338 SK_LOC_DECL(int,type
) ;
1339 SK_LOC_DECL(int,state
) ;
1340 SK_LOC_DECL(int,remote
) ;
1341 SK_LOC_DECL(int,mac
) ;
1345 struct smt_phy_rec
*phy
;
1346 struct smt_mac_rec
*pd_mac
;
1349 sizeof(struct smt_mac_rec
) * NUMMACS
+
1350 sizeof(struct smt_phy_rec
) * ALLPHYS
;
1351 path
->para
.p_type
= SMT_P_PATH
;
1352 path
->para
.p_len
= len
- PARA_LEN
;
1355 for (p
= 0,phy
= path
->pd_phy
; p
< ALLPHYS
; p
++, phy
++) {
1357 #ifndef CONCENTRATOR
1358 if (smc
->s
.sas
== SMT_SAS
)
1361 pcm_status_state(smc
,physp
,&type
,&state
,&remote
,&mac
) ;
1362 #ifdef LITTLE_ENDIAN
1363 phy
->phy_mib_index
= smt_swap_short((u_short
)p
+INDEX_PORT
) ;
1365 phy
->phy_mib_index
= p
+INDEX_PORT
;
1367 phy
->phy_type
= type
;
1368 phy
->phy_connect_state
= state
;
1369 phy
->phy_remote_type
= remote
;
1370 phy
->phy_remote_mac
= mac
;
1371 phy
->phy_resource_idx
= phy_con_resource_index(smc
,p
) ;
1375 pd_mac
= (struct smt_mac_rec
*) phy
;
1376 pd_mac
->mac_addr
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
1377 pd_mac
->mac_resource_idx
= mac_con_resource_index(smc
,1) ;
1382 * fill values in mac status
1384 static void smt_fill_mac_status(struct s_smc
*smc
, struct smt_p_mac_status
*st
)
1386 SMTSETPARA(st
,SMT_P_MAC_STATUS
) ;
1388 st
->st_mib_index
= INDEX_MAC
;
1389 st
->st_mac_index
= mac_index(smc
,1) ;
1391 mac_update_counter(smc
) ;
1393 * timer values are represented in SMT as 2's complement numbers
1394 * units : internal : 2's complement BCLK
1396 st
->st_t_req
= smc
->mib
.m
[MAC0
].fddiMACT_Req
;
1397 st
->st_t_neg
= smc
->mib
.m
[MAC0
].fddiMACT_Neg
;
1398 st
->st_t_max
= smc
->mib
.m
[MAC0
].fddiMACT_Max
;
1399 st
->st_tvx_value
= smc
->mib
.m
[MAC0
].fddiMACTvxValue
;
1400 st
->st_t_min
= smc
->mib
.m
[MAC0
].fddiMACT_Min
;
1402 st
->st_sba
= smc
->mib
.a
[PATH0
].fddiPATHSbaPayload
;
1403 st
->st_frame_ct
= smc
->mib
.m
[MAC0
].fddiMACFrame_Ct
;
1404 st
->st_error_ct
= smc
->mib
.m
[MAC0
].fddiMACError_Ct
;
1405 st
->st_lost_ct
= smc
->mib
.m
[MAC0
].fddiMACLost_Ct
;
1409 * fill values in LEM status
1411 static void smt_fill_lem(struct s_smc
*smc
, struct smt_p_lem
*lem
, int phy
)
1413 struct fddi_mib_p
*mib
;
1415 mib
= smc
->y
[phy
].mib
;
1417 SMTSETPARA(lem
,SMT_P_LEM
) ;
1418 lem
->lem_mib_index
= phy
+INDEX_PORT
;
1419 lem
->lem_phy_index
= phy_index(smc
,phy
) ;
1421 lem
->lem_cutoff
= mib
->fddiPORTLer_Cutoff
;
1422 lem
->lem_alarm
= mib
->fddiPORTLer_Alarm
;
1423 /* long term bit error rate */
1424 lem
->lem_estimate
= mib
->fddiPORTLer_Estimate
;
1425 /* # of rejected connections */
1426 lem
->lem_reject_ct
= mib
->fddiPORTLem_Reject_Ct
;
1427 lem
->lem_ct
= mib
->fddiPORTLem_Ct
; /* total number of errors */
1431 * fill version parameter
1433 static void smt_fill_version(struct s_smc
*smc
, struct smt_p_version
*vers
)
1436 SMTSETPARA(vers
,SMT_P_VERSION
) ;
1438 vers
->v_n
= 1 ; /* one version is enough .. */
1440 vers
->v_version
[0] = SMT_VID_2
;
1446 * fill frame status capabilities
1449 * note: this para 200B is NOT in swap table, because it's also set in
1452 static void smt_fill_fsc(struct s_smc
*smc
, struct smt_p_fsc
*fsc
)
1455 SMTSETPARA(fsc
,SMT_P_FSC
) ;
1457 fsc
->fsc_mac_index
= INDEX_MAC
; /* this is MIB ; MIB is NOT
1461 fsc
->fsc_value
= FSC_TYPE0
; /* "normal" node */
1462 #ifdef LITTLE_ENDIAN
1463 fsc
->fsc_mac_index
= smt_swap_short(INDEX_MAC
) ;
1464 fsc
->fsc_value
= smt_swap_short(FSC_TYPE0
) ;
1470 * fill mac counter field
1472 static void smt_fill_mac_counter(struct s_smc
*smc
, struct smt_p_mac_counter
*mc
)
1474 SMTSETPARA(mc
,SMT_P_MAC_COUNTER
) ;
1475 mc
->mc_mib_index
= INDEX_MAC
;
1476 mc
->mc_index
= mac_index(smc
,1) ;
1477 mc
->mc_receive_ct
= smc
->mib
.m
[MAC0
].fddiMACCopied_Ct
;
1478 mc
->mc_transmit_ct
= smc
->mib
.m
[MAC0
].fddiMACTransmit_Ct
;
1482 * fill mac frame not copied counter
1484 static void smt_fill_mac_fnc(struct s_smc
*smc
, struct smt_p_mac_fnc
*fnc
)
1486 SMTSETPARA(fnc
,SMT_P_MAC_FNC
) ;
1487 fnc
->nc_mib_index
= INDEX_MAC
;
1488 fnc
->nc_index
= mac_index(smc
,1) ;
1489 fnc
->nc_counter
= smc
->mib
.m
[MAC0
].fddiMACNotCopied_Ct
;
1494 * fill manufacturer field
1496 static void smt_fill_manufacturer(struct s_smc
*smc
,
1497 struct smp_p_manufacturer
*man
)
1499 SMTSETPARA(man
,SMT_P_MANUFACTURER
) ;
1500 memcpy((char *) man
->mf_data
,
1501 (char *) smc
->mib
.fddiSMTManufacturerData
,
1502 sizeof(man
->mf_data
)) ;
1508 static void smt_fill_user(struct s_smc
*smc
, struct smp_p_user
*user
)
1510 SMTSETPARA(user
,SMT_P_USER
) ;
1511 memcpy((char *) user
->us_data
,
1512 (char *) smc
->mib
.fddiSMTUserData
,
1513 sizeof(user
->us_data
)) ;
1519 static void smt_fill_setcount(struct s_smc
*smc
, struct smt_p_setcount
*setcount
)
1522 SMTSETPARA(setcount
,SMT_P_SETCOUNT
) ;
1523 setcount
->count
= smc
->mib
.fddiSMTSetCount
.count
;
1524 memcpy((char *)setcount
->timestamp
,
1525 (char *)smc
->mib
.fddiSMTSetCount
.timestamp
,8) ;
1531 static void smt_fill_echo(struct s_smc
*smc
, struct smt_p_echo
*echo
, u_long seed
,
1537 SMTSETPARA(echo
,SMT_P_ECHODATA
) ;
1538 echo
->para
.p_len
= len
;
1539 for (p
= echo
->ec_data
; len
; len
--) {
1540 *p
++ = (u_char
) seed
;
1547 * called from CFM if configuration changes
1549 static void smt_clear_una_dna(struct s_smc
*smc
)
1551 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
= SMT_Unknown
;
1552 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
= SMT_Unknown
;
1555 static void smt_clear_old_una_dna(struct s_smc
*smc
)
1557 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
= SMT_Unknown
;
1558 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
= SMT_Unknown
;
1561 u_long
smt_get_tid(struct s_smc
*smc
)
1564 while ((tid
= ++(smc
->sm
.smt_tid
) ^ SMT_TID_MAGIC
) == 0)
1566 return(tid
& 0x3fffffffL
) ;
1571 * table of parameter lengths
1573 static const struct smt_pdef
{
1578 { SMT_P_UNA
, sizeof(struct smt_p_una
) ,
1580 { SMT_P_SDE
, sizeof(struct smt_p_sde
) ,
1582 { SMT_P_STATE
, sizeof(struct smt_p_state
) ,
1583 SWAP_SMT_P_STATE
} ,
1584 { SMT_P_TIMESTAMP
,sizeof(struct smt_p_timestamp
) ,
1585 SWAP_SMT_P_TIMESTAMP
} ,
1586 { SMT_P_POLICY
, sizeof(struct smt_p_policy
) ,
1587 SWAP_SMT_P_POLICY
} ,
1588 { SMT_P_LATENCY
, sizeof(struct smt_p_latency
) ,
1589 SWAP_SMT_P_LATENCY
} ,
1590 { SMT_P_NEIGHBORS
,sizeof(struct smt_p_neighbor
) ,
1591 SWAP_SMT_P_NEIGHBORS
} ,
1592 { SMT_P_PATH
, sizeof(struct smt_p_path
) ,
1594 { SMT_P_MAC_STATUS
,sizeof(struct smt_p_mac_status
) ,
1595 SWAP_SMT_P_MAC_STATUS
} ,
1596 { SMT_P_LEM
, sizeof(struct smt_p_lem
) ,
1598 { SMT_P_MAC_COUNTER
,sizeof(struct smt_p_mac_counter
) ,
1599 SWAP_SMT_P_MAC_COUNTER
} ,
1600 { SMT_P_MAC_FNC
,sizeof(struct smt_p_mac_fnc
) ,
1601 SWAP_SMT_P_MAC_FNC
} ,
1602 { SMT_P_PRIORITY
,sizeof(struct smt_p_priority
) ,
1603 SWAP_SMT_P_PRIORITY
} ,
1604 { SMT_P_EB
,sizeof(struct smt_p_eb
) ,
1606 { SMT_P_MANUFACTURER
,sizeof(struct smp_p_manufacturer
) ,
1607 SWAP_SMT_P_MANUFACTURER
} ,
1608 { SMT_P_REASON
, sizeof(struct smt_p_reason
) ,
1609 SWAP_SMT_P_REASON
} ,
1610 { SMT_P_REFUSED
, sizeof(struct smt_p_refused
) ,
1611 SWAP_SMT_P_REFUSED
} ,
1612 { SMT_P_VERSION
, sizeof(struct smt_p_version
) ,
1613 SWAP_SMT_P_VERSION
} ,
1615 { SMT_P0015
, sizeof(struct smt_p_0015
) , SWAP_SMT_P0015
} ,
1616 { SMT_P0016
, sizeof(struct smt_p_0016
) , SWAP_SMT_P0016
} ,
1617 { SMT_P0017
, sizeof(struct smt_p_0017
) , SWAP_SMT_P0017
} ,
1618 { SMT_P0018
, sizeof(struct smt_p_0018
) , SWAP_SMT_P0018
} ,
1619 { SMT_P0019
, sizeof(struct smt_p_0019
) , SWAP_SMT_P0019
} ,
1620 { SMT_P001A
, sizeof(struct smt_p_001a
) , SWAP_SMT_P001A
} ,
1621 { SMT_P001B
, sizeof(struct smt_p_001b
) , SWAP_SMT_P001B
} ,
1622 { SMT_P001C
, sizeof(struct smt_p_001c
) , SWAP_SMT_P001C
} ,
1623 { SMT_P001D
, sizeof(struct smt_p_001d
) , SWAP_SMT_P001D
} ,
1626 { SMT_P_FSC
, sizeof(struct smt_p_fsc
) ,
1630 { SMT_P_SETCOUNT
,0, SWAP_SMT_P_SETCOUNT
} ,
1631 { SMT_P1048
, 0, SWAP_SMT_P1048
} ,
1632 { SMT_P208C
, 0, SWAP_SMT_P208C
} ,
1633 { SMT_P208D
, 0, SWAP_SMT_P208D
} ,
1634 { SMT_P208E
, 0, SWAP_SMT_P208E
} ,
1635 { SMT_P208F
, 0, SWAP_SMT_P208F
} ,
1636 { SMT_P2090
, 0, SWAP_SMT_P2090
} ,
1638 { SMT_P320B
, sizeof(struct smt_p_320b
) , SWAP_SMT_P320B
} ,
1639 { SMT_P320F
, sizeof(struct smt_p_320f
) , SWAP_SMT_P320F
} ,
1640 { SMT_P3210
, sizeof(struct smt_p_3210
) , SWAP_SMT_P3210
} ,
1642 { SMT_P4050
, 0, SWAP_SMT_P4050
} ,
1643 { SMT_P4051
, 0, SWAP_SMT_P4051
} ,
1644 { SMT_P4052
, 0, SWAP_SMT_P4052
} ,
1645 { SMT_P4053
, 0, SWAP_SMT_P4053
} ,
1648 #define N_SMT_PLEN ARRAY_SIZE(smt_pdef)
1650 int smt_check_para(struct s_smc
*smc
, struct smt_header
*sm
,
1651 const u_short list
[])
1653 const u_short
*p
= list
;
1655 if (!sm_to_para(smc
,sm
,(int) *p
)) {
1656 DB_SMT("SMT: smt_check_para - missing para %x\n",*p
,0);
1664 void *sm_to_para(struct s_smc
*smc
, struct smt_header
*sm
, int para
)
1674 p
= (char *)(sm
+1) ; /* pointer to info */
1676 if (((struct smt_para
*)p
)->p_type
== para
)
1677 found
= (void *) p
;
1678 plen
= ((struct smt_para
*)p
)->p_len
+ PARA_LEN
;
1682 DB_SMT("SMT : sm_to_para - length error %d\n",plen
,0) ;
1685 if ((plen
& 3) && (para
!= SMT_P_ECHODATA
)) {
1686 DB_SMT("SMT : sm_to_para - odd length %d\n",plen
,0) ;
1697 * send ANTC data test frame
1699 void fddi_send_antc(struct s_smc
*smc
, struct fddi_addr
*dest
)
1705 struct smt_header
*smt
;
1709 mb
= smt_get_mbuf() ;
1710 mb
->sm_len
= 3000+12 ;
1711 p
= smtod(mb
, char *) + 12 ;
1712 for (i
= 0 ; i
< 3000 ; i
++)
1715 smt
= smtod(mb
, struct smt_header
*) ;
1716 smt
->smt_dest
= *dest
;
1717 smt
->smt_source
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
1718 smt_send_mbuf(smc
,mb
,FC_ASYNC_LLC
) ;
1724 char *addr_to_string(struct fddi_addr
*addr
)
1727 static char string
[6*3] = "****" ;
1729 for (i
= 0 ; i
< 6 ; i
++) {
1730 string
[i
* 3] = hex_asc_hi(addr
->a
[i
]);
1731 string
[i
* 3 + 1] = hex_asc_lo(addr
->a
[i
]);
1732 string
[i
* 3 + 2] = ':';
1734 string
[5 * 3 + 2] = 0;
1740 int smt_ifconfig(int argc
, char *argv
[])
1742 if (argc
>= 2 && !strcmp(argv
[0],"opt_bypass") &&
1743 !strcmp(argv
[1],"yes")) {
1744 smc
->mib
.fddiSMTBypassPresent
= 1 ;
1747 return(amdfddi_config(0,argc
,argv
)) ;
1752 * return static mac index
1754 static int mac_index(struct s_smc
*smc
, int mac
)
1761 return((smc
->s
.sas
== SMT_SAS
) ? 2 : 3) ;
1766 * return static phy index
1768 static int phy_index(struct s_smc
*smc
, int phy
)
1775 * return dynamic mac connection resource index
1777 static int mac_con_resource_index(struct s_smc
*smc
, int mac
)
1782 return(entity_to_index(smc
,cem_get_downstream(smc
,ENTITY_MAC
))) ;
1785 switch (smc
->mib
.fddiSMTCF_State
) {
1788 case SC11_C_WRAP_S
:
1790 case SC10_C_WRAP_B
:
1794 return(smc
->s
.sas
== SMT_SAS
? 2 : 3) ;
1799 * return dynamic phy connection resource index
1801 static int phy_con_resource_index(struct s_smc
*smc
, int phy
)
1804 return(entity_to_index(smc
,cem_get_downstream(smc
,ENTITY_PHY(phy
)))) ;
1806 switch (smc
->mib
.fddiSMTCF_State
) {
1808 return(phy
== PA
? 3 : 2) ;
1809 case SC10_C_WRAP_B
:
1810 return(phy
== PA
? 1 : 3) ;
1812 return(phy
== PA
? 3 : 1) ;
1814 return(phy
== PA
? 2 : 3) ;
1815 case SC11_C_WRAP_S
:
1823 static int entity_to_index(struct s_smc
*smc
, int e
)
1825 if (e
== ENTITY_MAC
)
1826 return(mac_index(smc
,1)) ;
1828 return(phy_index(smc
,e
- ENTITY_PHY(0))) ;
1832 #ifdef LITTLE_ENDIAN
1833 static int smt_swap_short(u_short s
)
1835 return(((s
>>8)&0xff)|((s
&0xff)<<8)) ;
1838 void smt_swap_para(struct smt_header
*sm
, int len
, int direction
)
1839 /* int direction; 0 encode 1 decode */
1841 struct smt_para
*pa
;
1842 const struct smt_pdef
*pd
;
1848 /* printf("smt_swap_para sm %x len %d dir %d\n",
1851 smt_string_swap((char *)sm
,SWAP_SMTHEADER
,len
) ;
1854 len
-= sizeof(struct smt_header
) ;
1856 p
= (char *) (sm
+ 1) ;
1858 pa
= (struct smt_para
*) p
;
1861 pa
->p_type
= smt_swap_short(pa
->p_type
) ;
1862 pa
->p_len
= smt_swap_short(pa
->p_len
) ;
1868 * note: paras can have 0 length !
1873 for (i
= N_SMT_PLEN
, pd
= smt_pdef
; i
; i
--,pd
++) {
1874 if (pd
->ptype
== type
)
1877 if (i
&& pd
->pswap
) {
1878 smt_string_swap(p
+PARA_LEN
,pd
->pswap
,len
) ;
1885 static void smt_string_swap(char *data
, const char *format
, int len
)
1887 const char *open_paren
= NULL
;
1890 while (len
> 0 && *format
) {
1893 open_paren
= format
;
1896 format
= open_paren
;
1907 data
+= *format
- '0' ;
1908 len
-= *format
- '0' ;
1936 void smt_swap_para(struct smt_header
*sm
, int len
, int direction
)
1937 /* int direction; 0 encode 1 decode */
1941 SK_UNUSED(direction
) ;
1948 int smt_action(struct s_smc
*smc
, int class, int code
, int index
)
1952 DB_SMT("SMT: action %d code %d\n",class,code
) ;
1954 case SMT_STATION_ACTION
:
1956 case SMT_STATION_ACTION_CONNECT
:
1957 smc
->mib
.fddiSMTRemoteDisconnectFlag
= FALSE
;
1958 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
1960 case SMT_STATION_ACTION_DISCONNECT
:
1961 queue_event(smc
,EVENT_ECM
,EC_DISCONNECT
) ;
1962 smc
->mib
.fddiSMTRemoteDisconnectFlag
= TRUE
;
1963 RS_SET(smc
,RS_DISCONNECT
) ;
1964 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1965 FDDI_SMT_EVENT
, (u_long
) FDDI_REMOTE_DISCONNECT
,
1966 smt_get_event_word(smc
));
1968 case SMT_STATION_ACTION_PATHTEST
:
1969 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1970 FDDI_SMT_EVENT
, (u_long
) FDDI_PATH_TEST
,
1971 smt_get_event_word(smc
));
1973 case SMT_STATION_ACTION_SELFTEST
:
1974 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1975 FDDI_SMT_EVENT
, (u_long
) FDDI_REMOTE_SELF_TEST
,
1976 smt_get_event_word(smc
));
1978 case SMT_STATION_ACTION_DISABLE_A
:
1979 if (smc
->y
[PA
].pc_mode
== PM_PEER
) {
1980 RS_SET(smc
,RS_EVENT
) ;
1981 queue_event(smc
,EVENT_PCM
+PA
,PC_DISABLE
) ;
1984 case SMT_STATION_ACTION_DISABLE_B
:
1985 if (smc
->y
[PB
].pc_mode
== PM_PEER
) {
1986 RS_SET(smc
,RS_EVENT
) ;
1987 queue_event(smc
,EVENT_PCM
+PB
,PC_DISABLE
) ;
1990 case SMT_STATION_ACTION_DISABLE_M
:
1991 for (port
= 0 ; port
< NUMPHYS
; port
++) {
1992 if (smc
->mib
.p
[port
].fddiPORTMy_Type
!= TM
)
1994 RS_SET(smc
,RS_EVENT
) ;
1995 queue_event(smc
,EVENT_PCM
+port
,PC_DISABLE
) ;
2002 case SMT_PORT_ACTION
:
2004 case SMT_PORT_ACTION_ENABLE
:
2007 case SMT_PORT_ACTION_DISABLE
:
2008 event
= PC_DISABLE
;
2010 case SMT_PORT_ACTION_MAINT
:
2013 case SMT_PORT_ACTION_START
:
2016 case SMT_PORT_ACTION_STOP
:
2022 queue_event(smc
,EVENT_PCM
+index
,event
) ;
2031 * canonical conversion of <len> bytes beginning form *data
2034 static void hwm_conv_can(struct s_smc
*smc
, char *data
, int len
)
2040 for (i
= len
; i
; i
--, data
++)
2041 *data
= bitrev8(*data
);
2045 #endif /* no SLIM_SMT */