1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
7 * See the file "skfddi.c" for further information.
9 * The information in this file is provided "AS IS" without warranty.
11 ******************************************************************************/
17 #include <linux/bitrev.h>
18 #include <linux/kernel.h>
21 #include "h/smtstate.h"
24 static const char ID_sccs
[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
30 #define m_fc(mb) ((mb)->sm_data[0])
32 #define SMT_TID_MAGIC 0x1f0a7b3c
34 static const char *const smt_type_name
[] = {
35 "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
36 "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
37 "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
38 "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
41 static const char *const smt_class_name
[] = {
42 "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
43 "SRF","PMF_GET","PMF_SET","ESF"
46 #define LAST_CLASS (SMT_PMF_SET)
48 static const struct fddi_addr SMT_Unknown
= {
56 static int smt_swap_short(u_short s
);
58 static int mac_index(struct s_smc
*smc
, int mac
);
59 static int phy_index(struct s_smc
*smc
, int phy
);
60 static int mac_con_resource_index(struct s_smc
*smc
, int mac
);
61 static int phy_con_resource_index(struct s_smc
*smc
, int phy
);
62 static void smt_send_rdf(struct s_smc
*smc
, SMbuf
*rej
, int fc
, int reason
,
64 static void smt_send_nif(struct s_smc
*smc
, const struct fddi_addr
*dest
,
65 int fc
, u_long tid
, int type
, int local
);
66 static void smt_send_ecf(struct s_smc
*smc
, struct fddi_addr
*dest
, int fc
,
67 u_long tid
, int type
, int len
);
68 static void smt_echo_test(struct s_smc
*smc
, int dna
);
69 static void smt_send_sif_config(struct s_smc
*smc
, struct fddi_addr
*dest
,
70 u_long tid
, int local
);
71 static void smt_send_sif_operation(struct s_smc
*smc
, struct fddi_addr
*dest
,
72 u_long tid
, int local
);
74 static void smt_string_swap(char *data
, const char *format
, int len
);
76 static void smt_add_frame_len(SMbuf
*mb
, int len
);
77 static void smt_fill_una(struct s_smc
*smc
, struct smt_p_una
*una
);
78 static void smt_fill_sde(struct s_smc
*smc
, struct smt_p_sde
*sde
);
79 static void smt_fill_state(struct s_smc
*smc
, struct smt_p_state
*state
);
80 static void smt_fill_timestamp(struct s_smc
*smc
, struct smt_p_timestamp
*ts
);
81 static void smt_fill_policy(struct s_smc
*smc
, struct smt_p_policy
*policy
);
82 static void smt_fill_latency(struct s_smc
*smc
, struct smt_p_latency
*latency
);
83 static void smt_fill_neighbor(struct s_smc
*smc
, struct smt_p_neighbor
*neighbor
);
84 static int smt_fill_path(struct s_smc
*smc
, struct smt_p_path
*path
);
85 static void smt_fill_mac_status(struct s_smc
*smc
, struct smt_p_mac_status
*st
);
86 static void smt_fill_lem(struct s_smc
*smc
, struct smt_p_lem
*lem
, int phy
);
87 static void smt_fill_version(struct s_smc
*smc
, struct smt_p_version
*vers
);
88 static void smt_fill_fsc(struct s_smc
*smc
, struct smt_p_fsc
*fsc
);
89 static void smt_fill_mac_counter(struct s_smc
*smc
, struct smt_p_mac_counter
*mc
);
90 static void smt_fill_mac_fnc(struct s_smc
*smc
, struct smt_p_mac_fnc
*fnc
);
91 static void smt_fill_manufacturer(struct s_smc
*smc
,
92 struct smp_p_manufacturer
*man
);
93 static void smt_fill_user(struct s_smc
*smc
, struct smp_p_user
*user
);
94 static void smt_fill_setcount(struct s_smc
*smc
, struct smt_p_setcount
*setcount
);
95 static void smt_fill_echo(struct s_smc
*smc
, struct smt_p_echo
*echo
, u_long seed
,
98 static void smt_clear_una_dna(struct s_smc
*smc
);
99 static void smt_clear_old_una_dna(struct s_smc
*smc
);
101 static int entity_to_index(void);
103 static void update_dac(struct s_smc
*smc
, int report
);
104 static int div_ratio(u_long upper
, u_long lower
);
106 static void hwm_conv_can(struct s_smc
*smc
, char *data
, int len
);
108 #define hwm_conv_can(smc,data,len)
112 static inline int is_my_addr(const struct s_smc
*smc
,
113 const struct fddi_addr
*addr
)
115 return(*(short *)(&addr
->a
[0]) ==
116 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[0])
117 && *(short *)(&addr
->a
[2]) ==
118 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[2])
119 && *(short *)(&addr
->a
[4]) ==
120 *(short *)(&smc
->mib
.m
[MAC0
].fddiMACSMTAddress
.a
[4])) ;
123 static inline int is_broadcast(const struct fddi_addr
*addr
)
125 return *(u_short
*)(&addr
->a
[0]) == 0xffff &&
126 *(u_short
*)(&addr
->a
[2]) == 0xffff &&
127 *(u_short
*)(&addr
->a
[4]) == 0xffff;
130 static inline int is_individual(const struct fddi_addr
*addr
)
132 return !(addr
->a
[0] & GROUP_ADDR
);
135 static inline int is_equal(const struct fddi_addr
*addr1
,
136 const struct fddi_addr
*addr2
)
138 return *(u_short
*)(&addr1
->a
[0]) == *(u_short
*)(&addr2
->a
[0]) &&
139 *(u_short
*)(&addr1
->a
[2]) == *(u_short
*)(&addr2
->a
[2]) &&
140 *(u_short
*)(&addr1
->a
[4]) == *(u_short
*)(&addr2
->a
[4]);
144 * list of mandatory paras in frames
146 static const u_short plist_nif
[] = { SMT_P_UNA
,SMT_P_SDE
,SMT_P_STATE
,0 } ;
151 void smt_agent_init(struct s_smc
*smc
)
158 smc
->mib
.m
[MAC0
].fddiMACSMTAddress
= smc
->hw
.fddi_home_addr
;
161 * get OUI address from driver (bia == built-in-address)
163 smc
->mib
.fddiSMTStationId
.sid_oem
[0] = 0 ;
164 smc
->mib
.fddiSMTStationId
.sid_oem
[1] = 0 ;
165 driver_get_bia(smc
,&smc
->mib
.fddiSMTStationId
.sid_node
) ;
166 for (i
= 0 ; i
< 6 ; i
++) {
167 smc
->mib
.fddiSMTStationId
.sid_node
.a
[i
] =
168 bitrev8(smc
->mib
.fddiSMTStationId
.sid_node
.a
[i
]);
170 smc
->mib
.fddiSMTManufacturerData
[0] =
171 smc
->mib
.fddiSMTStationId
.sid_node
.a
[0] ;
172 smc
->mib
.fddiSMTManufacturerData
[1] =
173 smc
->mib
.fddiSMTStationId
.sid_node
.a
[1] ;
174 smc
->mib
.fddiSMTManufacturerData
[2] =
175 smc
->mib
.fddiSMTStationId
.sid_node
.a
[2] ;
176 smc
->sm
.smt_tid
= 0 ;
177 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
= DA_NONE
;
178 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
= FALSE
;
180 smt_clear_una_dna(smc
) ;
181 smt_clear_old_una_dna(smc
) ;
183 for (i
= 0 ; i
< SMT_MAX_TEST
; i
++)
184 smc
->sm
.pend
[i
] = 0 ;
185 smc
->sm
.please_reconnect
= 0 ;
186 smc
->sm
.uniq_ticks
= 0 ;
197 void smt_agent_task(struct s_smc
*smc
)
199 smt_timer_start(smc
,&smc
->sm
.smt_timer
, (u_long
)1000000L,
200 EV_TOKEN(EVENT_SMT
,SM_TIMER
)) ;
201 DB_SMT("SMT agent task");
204 #ifndef SMT_REAL_TOKEN_CT
205 void smt_emulate_token_ct(struct s_smc
*smc
, int mac_index
)
211 time
= smt_get_time();
212 count
= ((time
- smc
->sm
.last_tok_time
[mac_index
]) *
213 100)/TICKS_PER_SECOND
;
216 * Only when ring is up we will have a token count. The
217 * flag is unfortunately a single instance value. This
218 * doesn't matter now, because we currently have only
221 if (smc
->hw
.mac_ring_is_up
){
222 smc
->mib
.m
[mac_index
].fddiMACToken_Ct
+= count
;
225 /* Remember current time */
226 smc
->sm
.last_tok_time
[mac_index
] = time
;
232 void smt_event(struct s_smc
*smc
, int event
)
235 #ifndef SMT_REAL_TOKEN_CT
240 if (smc
->sm
.please_reconnect
) {
241 smc
->sm
.please_reconnect
-- ;
242 if (smc
->sm
.please_reconnect
== 0) {
244 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
248 if (event
== SM_FAST
)
252 * timer for periodic cleanup in driver
253 * reset and start the watchdog (FM2)
257 smt_timer_poll(smc
) ;
258 smt_start_watchdog(smc
) ;
262 ess_timer_poll(smc
) ;
266 sba_timer_poll(smc
) ;
269 smt_srf_event(smc
,0,0,0) ;
271 #endif /* no SLIM_SMT */
273 time
= smt_get_time() ;
275 if (time
- smc
->sm
.smt_last_lem
>= TICKS_PER_SECOND
*8) {
277 * Use 8 sec. for the time intervall, it simplifies the
280 struct fddi_mib_m
*mib
;
287 * calculate LEM bit error rate
289 sm_lem_evaluate(smc
) ;
290 smc
->sm
.smt_last_lem
= time
;
296 mac_update_counter(smc
) ;
299 (mib
->fddiMACLost_Ct
- mib
->fddiMACOld_Lost_Ct
) +
300 (mib
->fddiMACError_Ct
- mib
->fddiMACOld_Error_Ct
) ;
302 (mib
->fddiMACFrame_Ct
- mib
->fddiMACOld_Frame_Ct
) +
303 (mib
->fddiMACLost_Ct
- mib
->fddiMACOld_Lost_Ct
) ;
304 mib
->fddiMACFrameErrorRatio
= div_ratio(upper
,lower
) ;
307 ((!mib
->fddiMACFrameErrorThreshold
&&
308 mib
->fddiMACError_Ct
!= mib
->fddiMACOld_Error_Ct
) ||
309 (mib
->fddiMACFrameErrorRatio
>
310 mib
->fddiMACFrameErrorThreshold
)) ;
312 if (cond
!= mib
->fddiMACFrameErrorFlag
)
313 smt_srf_event(smc
,SMT_COND_MAC_FRAME_ERROR
,
317 (mib
->fddiMACNotCopied_Ct
- mib
->fddiMACOld_NotCopied_Ct
) ;
320 (mib
->fddiMACCopied_Ct
- mib
->fddiMACOld_Copied_Ct
) ;
321 mib
->fddiMACNotCopiedRatio
= div_ratio(upper
,lower
) ;
324 ((!mib
->fddiMACNotCopiedThreshold
&&
325 mib
->fddiMACNotCopied_Ct
!=
326 mib
->fddiMACOld_NotCopied_Ct
)||
327 (mib
->fddiMACNotCopiedRatio
>
328 mib
->fddiMACNotCopiedThreshold
)) ;
330 if (cond
!= mib
->fddiMACNotCopiedFlag
)
331 smt_srf_event(smc
,SMT_COND_MAC_NOT_COPIED
,
337 mib
->fddiMACOld_Frame_Ct
= mib
->fddiMACFrame_Ct
;
338 mib
->fddiMACOld_Copied_Ct
= mib
->fddiMACCopied_Ct
;
339 mib
->fddiMACOld_Error_Ct
= mib
->fddiMACError_Ct
;
340 mib
->fddiMACOld_Lost_Ct
= mib
->fddiMACLost_Ct
;
341 mib
->fddiMACOld_NotCopied_Ct
= mib
->fddiMACNotCopied_Ct
;
344 * Check port EBError Condition
346 for (port
= 0; port
< NUMPHYS
; port
++) {
347 phy
= &smc
->y
[port
] ;
349 if (!phy
->mib
->fddiPORTHardwarePresent
) {
353 cond
= (phy
->mib
->fddiPORTEBError_Ct
-
354 phy
->mib
->fddiPORTOldEBError_Ct
> 5) ;
356 /* If ratio is more than 5 in 8 seconds
359 smt_srf_event(smc
,SMT_COND_PORT_EB_ERROR
,
360 (int) (INDEX_PORT
+ phy
->np
) ,cond
) ;
365 phy
->mib
->fddiPORTOldEBError_Ct
=
366 phy
->mib
->fddiPORTEBError_Ct
;
369 #endif /* no SLIM_SMT */
374 if (time
- smc
->sm
.smt_last_notify
>= (u_long
)
375 (smc
->mib
.fddiSMTTT_Notify
* TICKS_PER_SECOND
) ) {
377 * we can either send an announcement or a request
378 * a request will trigger a reply so that we can update
380 * note: same tid must be used until reply is received
382 if (!smc
->sm
.pend
[SMT_TID_NIF
])
383 smc
->sm
.pend
[SMT_TID_NIF
] = smt_get_tid(smc
) ;
384 smt_send_nif(smc
,&fddi_broadcast
, FC_SMT_NSA
,
385 smc
->sm
.pend
[SMT_TID_NIF
], SMT_REQUEST
,0) ;
386 smc
->sm
.smt_last_notify
= time
;
392 if (smc
->sm
.smt_tvu
&&
393 time
- smc
->sm
.smt_tvu
> 228*TICKS_PER_SECOND
) {
394 DB_SMT("SMT : UNA expired");
395 smc
->sm
.smt_tvu
= 0 ;
397 if (!is_equal(&smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
399 /* Do not update unknown address */
400 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
=
401 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
403 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
= SMT_Unknown
;
404 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
= FALSE
;
406 * Make sure the fddiMACUNDA_Flag = FALSE is
407 * included in the SRF so we don't generate
408 * a separate SRF for the deassertion of this
412 smt_srf_event(smc
, SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
415 if (smc
->sm
.smt_tvd
&&
416 time
- smc
->sm
.smt_tvd
> 228*TICKS_PER_SECOND
) {
417 DB_SMT("SMT : DNA expired");
418 smc
->sm
.smt_tvd
= 0 ;
419 if (!is_equal(&smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
,
421 /* Do not update unknown address */
422 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
=
423 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
425 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
= SMT_Unknown
;
426 smt_srf_event(smc
, SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
430 #endif /* no SLIM_SMT */
432 #ifndef SMT_REAL_TOKEN_CT
434 * Token counter emulation section. If hardware supports the token
435 * count, the token counter will be updated in mac_update_counter.
437 for (i
= MAC0
; i
< NUMMACS
; i
++ ){
438 if (time
- smc
->sm
.last_tok_time
[i
] > 2*TICKS_PER_SECOND
){
439 smt_emulate_token_ct( smc
, i
);
444 smt_timer_start(smc
,&smc
->sm
.smt_timer
, (u_long
)1000000L,
445 EV_TOKEN(EVENT_SMT
,SM_TIMER
)) ;
448 static int div_ratio(u_long upper
, u_long lower
)
450 if ((upper
<<16L) < upper
)
451 upper
= 0xffff0000L
;
456 return (int)(upper
/lower
) ;
462 * receive packet handler
464 void smt_received_pack(struct s_smc
*smc
, SMbuf
*mb
, int fs
)
465 /* int fs; frame status */
467 struct smt_header
*sm
;
474 case FC_SMT_LAN_LOC
:
479 smt_free_mbuf(smc
,mb
) ;
483 smc
->mib
.m
[MAC0
].fddiMACSMTCopied_Ct
++ ;
484 sm
= smtod(mb
,struct smt_header
*) ;
485 local
= ((fs
& L_INDICATOR
) != 0) ;
486 hwm_conv_can(smc
,(char *)sm
,12) ;
488 /* check destination address */
489 if (is_individual(&sm
->smt_dest
) && !is_my_addr(smc
,&sm
->smt_dest
)) {
490 smt_free_mbuf(smc
,mb
) ;
493 #if 0 /* for DUP recognition, do NOT filter them */
494 /* ignore loop back packets */
495 if (is_my_addr(smc
,&sm
->smt_source
) && !local
) {
496 smt_free_mbuf(smc
,mb
) ;
501 smt_swap_para(sm
,(int) mb
->sm_len
,1) ;
502 DB_SMT("SMT : received packet [%s] at 0x%p",
503 smt_type_name
[m_fc(mb
) & 0xf], sm
);
504 DB_SMT("SMT : version %d, class %s",
506 smt_class_name
[sm
->smt_class
> LAST_CLASS
? 0 : sm
->smt_class
]);
512 if (m_fc(mb
) == FC_SMT_NSA
&& sm
->smt_class
== SMT_NIF
&&
513 (sm
->smt_type
== SMT_ANNOUNCE
|| sm
->smt_type
== SMT_REQUEST
)) {
520 * ignore any packet with NSA and A-indicator set
522 if ( (fs
& A_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
) {
523 DB_SMT("SMT : ignoring NSA with A-indicator set from %s",
524 addr_to_string(&sm
->smt_source
));
525 smt_free_mbuf(smc
,mb
) ;
530 * ignore frames with illegal length
532 if (((sm
->smt_class
== SMT_ECF
) && (sm
->smt_len
> SMT_MAX_ECHO_LEN
)) ||
533 ((sm
->smt_class
!= SMT_ECF
) && (sm
->smt_len
> SMT_MAX_INFO_LEN
))) {
534 smt_free_mbuf(smc
,mb
) ;
541 switch (sm
->smt_class
) {
543 case SMT_SIF_CONFIG
:
546 if (sm
->smt_version
!= SMT_VID
)
550 if (sm
->smt_version
!= SMT_VID_2
)
555 DB_SMT("SMT : version = %d, dest = %s",
556 sm
->smt_version
, addr_to_string(&sm
->smt_source
));
557 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_VERSION
,local
) ;
558 smt_free_mbuf(smc
,mb
) ;
561 if ((sm
->smt_len
> mb
->sm_len
- sizeof(struct smt_header
)) ||
562 ((sm
->smt_len
& 3) && (sm
->smt_class
!= SMT_ECF
))) {
563 DB_SMT("SMT: info length error, len = %d", sm
->smt_len
);
564 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_LENGTH
,local
) ;
565 smt_free_mbuf(smc
,mb
) ;
568 switch (sm
->smt_class
) {
570 if (smt_check_para(smc
,sm
,plist_nif
)) {
571 DB_SMT("SMT: NIF with para problem, ignoring");
574 switch (sm
->smt_type
) {
577 if (!(fs
& C_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
578 && is_broadcast(&sm
->smt_dest
)) {
579 struct smt_p_state
*st
;
583 &smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
585 DB_SMT("SMT : updated my UNA = %s",
586 addr_to_string(&sm
->smt_source
));
587 if (!is_equal(&smc
->mib
.m
[MAC0
].
588 fddiMACUpstreamNbr
,&SMT_Unknown
)){
589 /* Do not update unknown address */
590 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
=
591 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
594 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
=
597 SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
599 smt_echo_test(smc
,0) ;
601 smc
->sm
.smt_tvu
= smt_get_time() ;
602 st
= (struct smt_p_state
*)
603 sm_to_para(smc
,sm
,SMT_P_STATE
) ;
605 smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
=
606 (st
->st_dupl_addr
& SMT_ST_MY_DUPA
) ?
611 if ((sm
->smt_type
== SMT_REQUEST
) &&
612 is_individual(&sm
->smt_source
) &&
613 ((!(fs
& A_INDICATOR
) && m_fc(mb
) == FC_SMT_NSA
) ||
614 (m_fc(mb
) != FC_SMT_NSA
))) {
615 DB_SMT("SMT : replying to NIF request %s",
616 addr_to_string(&sm
->smt_source
));
617 smt_send_nif(smc
,&sm
->smt_source
,
624 DB_SMT("SMT : received NIF response from %s",
625 addr_to_string(&sm
->smt_source
));
626 if (fs
& A_INDICATOR
) {
627 smc
->sm
.pend
[SMT_TID_NIF
] = 0 ;
628 DB_SMT("SMT : duplicate address");
629 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
=
631 smc
->r
.dup_addr_test
= DA_FAILED
;
632 queue_event(smc
,EVENT_RMT
,RM_DUP_ADDR
) ;
633 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
= TRUE
;
637 if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_NIF
]) {
638 smc
->sm
.pend
[SMT_TID_NIF
] = 0 ;
641 &smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
,
643 DB_SMT("SMT : updated my DNA");
644 if (!is_equal(&smc
->mib
.m
[MAC0
].
645 fddiMACDownstreamNbr
, &SMT_Unknown
)){
646 /* Do not update unknown address */
647 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
=
648 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
651 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
=
654 SMT_EVENT_MAC_NEIGHBOR_CHANGE
,
656 smt_echo_test(smc
,1) ;
658 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
= FALSE
;
660 smc
->sm
.smt_tvd
= smt_get_time() ;
661 smc
->mib
.m
[MAC0
].fddiMACDupAddressTest
=
663 if (smc
->r
.dup_addr_test
!= DA_PASSED
) {
664 smc
->r
.dup_addr_test
= DA_PASSED
;
665 queue_event(smc
,EVENT_RMT
,RM_DUP_ADDR
) ;
668 else if (sm
->smt_tid
==
669 smc
->sm
.pend
[SMT_TID_NIF_TEST
]) {
670 DB_SMT("SMT : NIF test TID ok");
673 DB_SMT("SMT : expected TID %lx, got %x",
674 smc
->sm
.pend
[SMT_TID_NIF
], sm
->smt_tid
);
682 case SMT_SIF_CONFIG
: /* station information */
683 if (sm
->smt_type
!= SMT_REQUEST
)
685 DB_SMT("SMT : replying to SIF Config request from %s",
686 addr_to_string(&sm
->smt_source
));
687 smt_send_sif_config(smc
,&sm
->smt_source
,sm
->smt_tid
,local
) ;
689 case SMT_SIF_OPER
: /* station information */
690 if (sm
->smt_type
!= SMT_REQUEST
)
692 DB_SMT("SMT : replying to SIF Operation request from %s",
693 addr_to_string(&sm
->smt_source
));
694 smt_send_sif_operation(smc
,&sm
->smt_source
,sm
->smt_tid
,local
) ;
696 case SMT_ECF
: /* echo frame */
697 switch (sm
->smt_type
) {
699 smc
->mib
.priv
.fddiPRIVECF_Reply_Rx
++ ;
700 DB_SMT("SMT: received ECF reply from %s",
701 addr_to_string(&sm
->smt_source
));
702 if (sm_to_para(smc
,sm
,SMT_P_ECHODATA
) == NULL
) {
703 DB_SMT("SMT: ECHODATA missing");
706 if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF
]) {
707 DB_SMT("SMT : ECF test TID ok");
709 else if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF_UNA
]) {
710 DB_SMT("SMT : ECF test UNA ok");
712 else if (sm
->smt_tid
== smc
->sm
.pend
[SMT_TID_ECF_DNA
]) {
713 DB_SMT("SMT : ECF test DNA ok");
716 DB_SMT("SMT : expected TID %lx, got %x",
717 smc
->sm
.pend
[SMT_TID_ECF
],
722 smc
->mib
.priv
.fddiPRIVECF_Req_Rx
++ ;
724 if (sm
->smt_len
&& !sm_to_para(smc
,sm
,SMT_P_ECHODATA
)) {
725 DB_SMT("SMT: ECF with para problem,sending RDF");
726 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_LENGTH
,
730 DB_SMT("SMT - sending ECF reply to %s",
731 addr_to_string(&sm
->smt_source
));
733 /* set destination addr. & reply */
734 sm
->smt_dest
= sm
->smt_source
;
735 sm
->smt_type
= SMT_REPLY
;
736 dump_smt(smc
,sm
,"ECF REPLY") ;
737 smc
->mib
.priv
.fddiPRIVECF_Reply_Tx
++ ;
738 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
739 return ; /* DON'T free mbuf */
747 case SMT_RAF
: /* resource allocation */
749 DB_ESSN(2, "ESS: RAF frame received");
750 fs
= ess_raf_received_pack(smc
,mb
,sm
,fs
) ;
754 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
755 sba_raf_received_pack(smc
,sm
,fs
) ;
758 case SMT_RDF
: /* request denied */
759 smc
->mib
.priv
.fddiPRIVRDF_Rx
++ ;
761 case SMT_ESF
: /* extended service - not supported */
762 if (sm
->smt_type
== SMT_REQUEST
) {
763 DB_SMT("SMT - received ESF, sending RDF");
764 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_CLASS
,local
) ;
769 if (sm
->smt_type
!= SMT_REQUEST
)
771 /* update statistics */
772 if (sm
->smt_class
== SMT_PMF_GET
)
773 smc
->mib
.priv
.fddiPRIVPMF_Get_Rx
++ ;
775 smc
->mib
.priv
.fddiPRIVPMF_Set_Rx
++ ;
777 * ignore PMF SET with I/G set
779 if ((sm
->smt_class
== SMT_PMF_SET
) &&
780 !is_individual(&sm
->smt_dest
)) {
781 DB_SMT("SMT: ignoring PMF-SET with I/G set");
784 smt_pmf_received_pack(smc
,mb
, local
) ;
787 dump_smt(smc
,sm
,"SRF received") ;
790 if (sm
->smt_type
!= SMT_REQUEST
)
793 * For frames with unknown class:
794 * we need to send a RDF frame according to 8.1.3.1.1,
795 * only if it is a REQUEST.
797 DB_SMT("SMT : class = %d, send RDF to %s",
798 sm
->smt_class
, addr_to_string(&sm
->smt_source
));
800 smt_send_rdf(smc
,mb
,m_fc(mb
),SMT_RDF_CLASS
,local
) ;
805 DB_SMT("SMT: discarding invalid frame, reason = %d", illegal
);
807 smt_free_mbuf(smc
,mb
) ;
810 static void update_dac(struct s_smc
*smc
, int report
)
814 cond
= ( smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
|
815 smc
->mib
.m
[MAC0
].fddiMACDA_Flag
) != 0 ;
816 if (report
&& (cond
!= smc
->mib
.m
[MAC0
].fddiMACDuplicateAddressCond
))
817 smt_srf_event(smc
, SMT_COND_MAC_DUP_ADDR
,INDEX_MAC
,cond
) ;
819 smc
->mib
.m
[MAC0
].fddiMACDuplicateAddressCond
= cond
;
828 void smt_send_frame(struct s_smc
*smc
, SMbuf
*mb
, int fc
, int local
)
829 /* SMbuf *mb; buffer to send */
830 /* int fc; FC value */
832 struct smt_header
*sm
;
834 if (!smc
->r
.sm_ma_avail
&& !local
) {
835 smt_free_mbuf(smc
,mb
) ;
838 sm
= smtod(mb
,struct smt_header
*) ;
839 sm
->smt_source
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
840 sm
->smt_sid
= smc
->mib
.fddiSMTStationId
;
842 smt_swap_para(sm
,(int) mb
->sm_len
,0) ; /* swap para & header */
843 hwm_conv_can(smc
,(char *)sm
,12) ; /* convert SA and DA */
844 smc
->mib
.m
[MAC0
].fddiMACSMTTransmit_Ct
++ ;
845 smt_send_mbuf(smc
,mb
,local
? FC_SMT_LOC
: fc
) ;
849 * generate and send RDF
851 static void smt_send_rdf(struct s_smc
*smc
, SMbuf
*rej
, int fc
, int reason
,
853 /* SMbuf *rej; mbuf of offending frame */
854 /* int fc; FC of denied frame */
855 /* int reason; reason code */
858 struct smt_header
*sm
; /* header of offending frame */
859 struct smt_rdf
*rdf
;
863 sm
= smtod(rej
,struct smt_header
*) ;
864 if (sm
->smt_type
!= SMT_REQUEST
)
867 DB_SMT("SMT: sending RDF to %s,reason = 0x%x",
868 addr_to_string(&sm
->smt_source
), reason
);
872 * note: get framelength from MAC length, NOT from SMT header
873 * smt header length is included in sm_len
875 frame_len
= rej
->sm_len
;
877 if (!(mb
=smt_build_frame(smc
,SMT_RDF
,SMT_REPLY
,sizeof(struct smt_rdf
))))
879 rdf
= smtod(mb
,struct smt_rdf
*) ;
880 rdf
->smt
.smt_tid
= sm
->smt_tid
; /* use TID from sm */
881 rdf
->smt
.smt_dest
= sm
->smt_source
; /* set dest = source */
884 rdf
->reason
.para
.p_type
= SMT_P_REASON
;
885 rdf
->reason
.para
.p_len
= sizeof(struct smt_p_reason
) - PARA_LEN
;
886 rdf
->reason
.rdf_reason
= reason
;
889 rdf
->version
.para
.p_type
= SMT_P_VERSION
;
890 rdf
->version
.para
.p_len
= sizeof(struct smt_p_version
) - PARA_LEN
;
891 rdf
->version
.v_pad
= 0 ;
892 rdf
->version
.v_n
= 1 ;
893 rdf
->version
.v_index
= 1 ;
894 rdf
->version
.v_version
[0] = SMT_VID_2
;
895 rdf
->version
.v_pad2
= 0 ;
898 if ((unsigned int) frame_len
<= SMT_MAX_INFO_LEN
- sizeof(*rdf
) +
899 2*sizeof(struct smt_header
))
902 len
= SMT_MAX_INFO_LEN
- sizeof(*rdf
) +
903 2*sizeof(struct smt_header
) ;
904 /* make length multiple of 4 */
906 rdf
->refused
.para
.p_type
= SMT_P_REFUSED
;
907 /* length of para is smt_frame + ref_fc */
908 rdf
->refused
.para
.p_len
= len
+ 4 ;
909 rdf
->refused
.ref_fc
= fc
;
912 smt_swap_para(sm
,frame_len
,0) ;
914 memcpy((char *) &rdf
->refused
.ref_header
,(char *) sm
,len
) ;
916 len
-= sizeof(struct smt_header
) ;
918 rdf
->smt
.smt_len
+= len
;
920 dump_smt(smc
,(struct smt_header
*)rdf
,"RDF") ;
921 smc
->mib
.priv
.fddiPRIVRDF_Tx
++ ;
922 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
926 * generate and send NIF
928 static void smt_send_nif(struct s_smc
*smc
, const struct fddi_addr
*dest
,
929 int fc
, u_long tid
, int type
, int local
)
930 /* struct fddi_addr *dest; dest address */
931 /* int fc; frame control */
932 /* u_long tid; transaction id */
933 /* int type; frame type */
935 struct smt_nif
*nif
;
938 if (!(mb
= smt_build_frame(smc
,SMT_NIF
,type
,sizeof(struct smt_nif
))))
940 nif
= smtod(mb
, struct smt_nif
*) ;
941 smt_fill_una(smc
,&nif
->una
) ; /* set UNA */
942 smt_fill_sde(smc
,&nif
->sde
) ; /* set station descriptor */
943 smt_fill_state(smc
,&nif
->state
) ; /* set state information */
945 smt_fill_fsc(smc
,&nif
->fsc
) ; /* set frame status cap. */
947 nif
->smt
.smt_dest
= *dest
; /* destination address */
948 nif
->smt
.smt_tid
= tid
; /* transaction ID */
949 dump_smt(smc
,(struct smt_header
*)nif
,"NIF") ;
950 smt_send_frame(smc
,mb
,fc
,local
) ;
955 * send NIF request (test purpose)
957 static void smt_send_nif_request(struct s_smc
*smc
, struct fddi_addr
*dest
)
959 smc
->sm
.pend
[SMT_TID_NIF_TEST
] = smt_get_tid(smc
) ;
960 smt_send_nif(smc
,dest
, FC_SMT_INFO
, smc
->sm
.pend
[SMT_TID_NIF_TEST
],
965 * send ECF request (test purpose)
967 static void smt_send_ecf_request(struct s_smc
*smc
, struct fddi_addr
*dest
,
970 smc
->sm
.pend
[SMT_TID_ECF
] = smt_get_tid(smc
) ;
971 smt_send_ecf(smc
,dest
, FC_SMT_INFO
, smc
->sm
.pend
[SMT_TID_ECF
],
979 static void smt_echo_test(struct s_smc
*smc
, int dna
)
983 smc
->sm
.pend
[dna
? SMT_TID_ECF_DNA
: SMT_TID_ECF_UNA
] =
984 tid
= smt_get_tid(smc
) ;
985 smt_send_ecf(smc
, dna
?
986 &smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
:
987 &smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
,
988 FC_SMT_INFO
,tid
, SMT_REQUEST
, (SMT_TEST_ECHO_LEN
& ~3)-8) ;
992 * generate and send ECF
994 static void smt_send_ecf(struct s_smc
*smc
, struct fddi_addr
*dest
, int fc
,
995 u_long tid
, int type
, int len
)
996 /* struct fddi_addr *dest; dest address */
997 /* int fc; frame control */
998 /* u_long tid; transaction id */
999 /* int type; frame type */
1000 /* int len; frame length */
1002 struct smt_ecf
*ecf
;
1005 if (!(mb
= smt_build_frame(smc
,SMT_ECF
,type
,SMT_ECF_LEN
+ len
)))
1007 ecf
= smtod(mb
, struct smt_ecf
*) ;
1009 smt_fill_echo(smc
,&ecf
->ec_echo
,tid
,len
) ; /* set ECHO */
1010 ecf
->smt
.smt_dest
= *dest
; /* destination address */
1011 ecf
->smt
.smt_tid
= tid
; /* transaction ID */
1012 smc
->mib
.priv
.fddiPRIVECF_Req_Tx
++ ;
1013 smt_send_frame(smc
,mb
,fc
,0) ;
1017 * generate and send SIF config response
1020 static void smt_send_sif_config(struct s_smc
*smc
, struct fddi_addr
*dest
,
1021 u_long tid
, int local
)
1022 /* struct fddi_addr *dest; dest address */
1023 /* u_long tid; transaction id */
1025 struct smt_sif_config
*sif
;
1028 if (!(mb
= smt_build_frame(smc
,SMT_SIF_CONFIG
,SMT_REPLY
,
1029 SIZEOF_SMT_SIF_CONFIG
)))
1032 sif
= smtod(mb
, struct smt_sif_config
*) ;
1033 smt_fill_timestamp(smc
,&sif
->ts
) ; /* set time stamp */
1034 smt_fill_sde(smc
,&sif
->sde
) ; /* set station descriptor */
1035 smt_fill_version(smc
,&sif
->version
) ; /* set version information */
1036 smt_fill_state(smc
,&sif
->state
) ; /* set state information */
1037 smt_fill_policy(smc
,&sif
->policy
) ; /* set station policy */
1038 smt_fill_latency(smc
,&sif
->latency
); /* set station latency */
1039 smt_fill_neighbor(smc
,&sif
->neighbor
); /* set station neighbor */
1040 smt_fill_setcount(smc
,&sif
->setcount
) ; /* set count */
1041 len
= smt_fill_path(smc
,&sif
->path
); /* set station path descriptor*/
1042 sif
->smt
.smt_dest
= *dest
; /* destination address */
1043 sif
->smt
.smt_tid
= tid
; /* transaction ID */
1044 smt_add_frame_len(mb
,len
) ; /* adjust length fields */
1045 dump_smt(smc
,(struct smt_header
*)sif
,"SIF Configuration Reply") ;
1046 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
1050 * generate and send SIF operation response
1053 static void smt_send_sif_operation(struct s_smc
*smc
, struct fddi_addr
*dest
,
1054 u_long tid
, int local
)
1055 /* struct fddi_addr *dest; dest address */
1056 /* u_long tid; transaction id */
1058 struct smt_sif_operation
*sif
;
1064 #ifndef CONCENTRATOR
1065 if (smc
->s
.sas
== SMT_SAS
)
1069 if (!(mb
= smt_build_frame(smc
,SMT_SIF_OPER
,SMT_REPLY
,
1070 SIZEOF_SMT_SIF_OPERATION
+ports
*sizeof(struct smt_p_lem
))))
1072 sif
= smtod(mb
, struct smt_sif_operation
*) ;
1073 smt_fill_timestamp(smc
,&sif
->ts
) ; /* set time stamp */
1074 smt_fill_mac_status(smc
,&sif
->status
) ; /* set mac status */
1075 smt_fill_mac_counter(smc
,&sif
->mc
) ; /* set mac counter field */
1076 smt_fill_mac_fnc(smc
,&sif
->fnc
) ; /* set frame not copied counter */
1077 smt_fill_manufacturer(smc
,&sif
->man
) ; /* set manufacturer field */
1078 smt_fill_user(smc
,&sif
->user
) ; /* set user field */
1079 smt_fill_setcount(smc
,&sif
->setcount
) ; /* set count */
1081 * set link error mon information
1084 smt_fill_lem(smc
,sif
->lem
,PS
) ;
1087 for (i
= 0 ; i
< ports
; i
++) {
1088 smt_fill_lem(smc
,&sif
->lem
[i
],i
) ;
1092 sif
->smt
.smt_dest
= *dest
; /* destination address */
1093 sif
->smt
.smt_tid
= tid
; /* transaction ID */
1094 dump_smt(smc
,(struct smt_header
*)sif
,"SIF Operation Reply") ;
1095 smt_send_frame(smc
,mb
,FC_SMT_INFO
,local
) ;
1099 * get and initialize SMT frame
1101 SMbuf
*smt_build_frame(struct s_smc
*smc
, int class, int type
,
1105 struct smt_header
*smt
;
1108 if (!smc
->r
.sm_ma_avail
) {
1112 if (!(mb
= smt_get_mbuf(smc
)))
1115 mb
->sm_len
= length
;
1116 smt
= smtod(mb
, struct smt_header
*) ;
1117 smt
->smt_dest
= fddi_broadcast
; /* set dest = broadcast */
1118 smt
->smt_class
= class ;
1119 smt
->smt_type
= type
;
1122 case SMT_SIF_CONFIG
:
1125 smt
->smt_version
= SMT_VID
;
1128 smt
->smt_version
= SMT_VID_2
;
1131 smt
->smt_tid
= smt_get_tid(smc
) ; /* set transaction ID */
1133 smt
->smt_len
= length
- sizeof(struct smt_header
) ;
1137 static void smt_add_frame_len(SMbuf
*mb
, int len
)
1139 struct smt_header
*smt
;
1141 smt
= smtod(mb
, struct smt_header
*) ;
1142 smt
->smt_len
+= len
;
1149 * fill values in UNA parameter
1151 static void smt_fill_una(struct s_smc
*smc
, struct smt_p_una
*una
)
1153 SMTSETPARA(una
,SMT_P_UNA
) ;
1155 una
->una_node
= smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
1159 * fill values in SDE parameter
1161 static void smt_fill_sde(struct s_smc
*smc
, struct smt_p_sde
*sde
)
1163 SMTSETPARA(sde
,SMT_P_SDE
) ;
1164 sde
->sde_non_master
= smc
->mib
.fddiSMTNonMaster_Ct
;
1165 sde
->sde_master
= smc
->mib
.fddiSMTMaster_Ct
;
1166 sde
->sde_mac_count
= NUMMACS
; /* only 1 MAC */
1168 sde
->sde_type
= SMT_SDE_CONCENTRATOR
;
1170 sde
->sde_type
= SMT_SDE_STATION
;
1175 * fill in values in station state parameter
1177 static void smt_fill_state(struct s_smc
*smc
, struct smt_p_state
*state
)
1182 SMTSETPARA(state
,SMT_P_STATE
) ;
1185 /* determine topology */
1187 if (smc
->mib
.fddiSMTPeerWrapFlag
) {
1188 top
|= SMT_ST_WRAPPED
; /* state wrapped */
1191 if (cfm_status_unattached(smc
)) {
1192 top
|= SMT_ST_UNATTACHED
; /* unattached concentrator */
1195 if ((twist
= pcm_status_twisted(smc
)) & 1) {
1196 top
|= SMT_ST_TWISTED_A
; /* twisted cable */
1199 top
|= SMT_ST_TWISTED_B
; /* twisted cable */
1204 if (pcm_rooted_station(smc
))
1205 top
|= SMT_ST_ROOTED_S
;
1206 if (smc
->mib
.a
[0].fddiPATHSbaPayload
!= 0)
1207 top
|= SMT_ST_SYNC_SERVICE
;
1208 state
->st_topology
= top
;
1209 state
->st_dupl_addr
=
1210 ((smc
->mib
.m
[MAC0
].fddiMACDA_Flag
? SMT_ST_MY_DUPA
: 0 ) |
1211 (smc
->mib
.m
[MAC0
].fddiMACUNDA_Flag
? SMT_ST_UNA_DUPA
: 0)) ;
1215 * fill values in timestamp parameter
1217 static void smt_fill_timestamp(struct s_smc
*smc
, struct smt_p_timestamp
*ts
)
1220 SMTSETPARA(ts
,SMT_P_TIMESTAMP
) ;
1221 smt_set_timestamp(smc
,ts
->ts_time
) ;
1224 void smt_set_timestamp(struct s_smc
*smc
, u_char
*p
)
1230 * timestamp is 64 bits long ; resolution is 80 nS
1231 * our clock resolution is 10mS
1232 * 10mS/80ns = 125000 ~ 2^17 = 131072
1234 utime
= smt_get_time() ;
1235 time
= utime
* 100 ;
1236 time
/= TICKS_PER_SECOND
;
1238 p
[1] = (u_char
)((time
>>(8+8+8+8-1)) & 1) ;
1239 p
[2] = (u_char
)(time
>>(8+8+8-1)) ;
1240 p
[3] = (u_char
)(time
>>(8+8-1)) ;
1241 p
[4] = (u_char
)(time
>>(8-1)) ;
1242 p
[5] = (u_char
)(time
<<1) ;
1243 p
[6] = (u_char
)(smc
->sm
.uniq_ticks
>>8) ;
1244 p
[7] = (u_char
)smc
->sm
.uniq_ticks
;
1246 * make sure we don't wrap: restart whenever the upper digits change
1248 if (utime
!= smc
->sm
.uniq_time
) {
1249 smc
->sm
.uniq_ticks
= 0 ;
1251 smc
->sm
.uniq_ticks
++ ;
1252 smc
->sm
.uniq_time
= utime
;
1256 * fill values in station policy parameter
1258 static void smt_fill_policy(struct s_smc
*smc
, struct smt_p_policy
*policy
)
1266 * MIB para 101b (fddiSMTConnectionPolicy) coding
1267 * is different from 0005 coding
1269 static const u_char ansi_weirdness
[16] = {
1270 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1272 SMTSETPARA(policy
,SMT_P_POLICY
) ;
1275 in
= smc
->mib
.fddiSMTConnectionPolicy
;
1276 for (i
= 0, map
= ansi_weirdness
; i
< 16 ; i
++) {
1282 policy
->pl_config
= smc
->mib
.fddiSMTConfigPolicy
;
1283 policy
->pl_connect
= out
;
1287 * fill values in latency equivalent parameter
1289 static void smt_fill_latency(struct s_smc
*smc
, struct smt_p_latency
*latency
)
1291 SMTSETPARA(latency
,SMT_P_LATENCY
) ;
1293 latency
->lt_phyout_idx1
= phy_index(smc
,0) ;
1294 latency
->lt_latency1
= 10 ; /* in octets (byte clock) */
1296 * note: latency has two phy entries by definition
1297 * for a SAS, the 2nd one is null
1299 if (smc
->s
.sas
== SMT_DAS
) {
1300 latency
->lt_phyout_idx2
= phy_index(smc
,1) ;
1301 latency
->lt_latency2
= 10 ; /* in octets (byte clock) */
1304 latency
->lt_phyout_idx2
= 0 ;
1305 latency
->lt_latency2
= 0 ;
1310 * fill values in MAC neighbors parameter
1312 static void smt_fill_neighbor(struct s_smc
*smc
, struct smt_p_neighbor
*neighbor
)
1314 SMTSETPARA(neighbor
,SMT_P_NEIGHBORS
) ;
1316 neighbor
->nb_mib_index
= INDEX_MAC
;
1317 neighbor
->nb_mac_index
= mac_index(smc
,1) ;
1318 neighbor
->nb_una
= smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
;
1319 neighbor
->nb_dna
= smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
;
1323 * fill values in path descriptor
1326 #define ALLPHYS NUMPHYS
1328 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1331 static int smt_fill_path(struct s_smc
*smc
, struct smt_p_path
*path
)
1333 SK_LOC_DECL(int,type
) ;
1334 SK_LOC_DECL(int,state
) ;
1335 SK_LOC_DECL(int,remote
) ;
1336 SK_LOC_DECL(int,mac
) ;
1340 struct smt_phy_rec
*phy
;
1341 struct smt_mac_rec
*pd_mac
;
1344 sizeof(struct smt_mac_rec
) * NUMMACS
+
1345 sizeof(struct smt_phy_rec
) * ALLPHYS
;
1346 path
->para
.p_type
= SMT_P_PATH
;
1347 path
->para
.p_len
= len
- PARA_LEN
;
1350 for (p
= 0,phy
= path
->pd_phy
; p
< ALLPHYS
; p
++, phy
++) {
1352 #ifndef CONCENTRATOR
1353 if (smc
->s
.sas
== SMT_SAS
)
1356 pcm_status_state(smc
,physp
,&type
,&state
,&remote
,&mac
) ;
1357 #ifdef LITTLE_ENDIAN
1358 phy
->phy_mib_index
= smt_swap_short((u_short
)p
+INDEX_PORT
) ;
1360 phy
->phy_mib_index
= p
+INDEX_PORT
;
1362 phy
->phy_type
= type
;
1363 phy
->phy_connect_state
= state
;
1364 phy
->phy_remote_type
= remote
;
1365 phy
->phy_remote_mac
= mac
;
1366 phy
->phy_resource_idx
= phy_con_resource_index(smc
,p
) ;
1370 pd_mac
= (struct smt_mac_rec
*) phy
;
1371 pd_mac
->mac_addr
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
1372 pd_mac
->mac_resource_idx
= mac_con_resource_index(smc
,1) ;
1377 * fill values in mac status
1379 static void smt_fill_mac_status(struct s_smc
*smc
, struct smt_p_mac_status
*st
)
1381 SMTSETPARA(st
,SMT_P_MAC_STATUS
) ;
1383 st
->st_mib_index
= INDEX_MAC
;
1384 st
->st_mac_index
= mac_index(smc
,1) ;
1386 mac_update_counter(smc
) ;
1388 * timer values are represented in SMT as 2's complement numbers
1389 * units : internal : 2's complement BCLK
1391 st
->st_t_req
= smc
->mib
.m
[MAC0
].fddiMACT_Req
;
1392 st
->st_t_neg
= smc
->mib
.m
[MAC0
].fddiMACT_Neg
;
1393 st
->st_t_max
= smc
->mib
.m
[MAC0
].fddiMACT_Max
;
1394 st
->st_tvx_value
= smc
->mib
.m
[MAC0
].fddiMACTvxValue
;
1395 st
->st_t_min
= smc
->mib
.m
[MAC0
].fddiMACT_Min
;
1397 st
->st_sba
= smc
->mib
.a
[PATH0
].fddiPATHSbaPayload
;
1398 st
->st_frame_ct
= smc
->mib
.m
[MAC0
].fddiMACFrame_Ct
;
1399 st
->st_error_ct
= smc
->mib
.m
[MAC0
].fddiMACError_Ct
;
1400 st
->st_lost_ct
= smc
->mib
.m
[MAC0
].fddiMACLost_Ct
;
1404 * fill values in LEM status
1406 static void smt_fill_lem(struct s_smc
*smc
, struct smt_p_lem
*lem
, int phy
)
1408 struct fddi_mib_p
*mib
;
1410 mib
= smc
->y
[phy
].mib
;
1412 SMTSETPARA(lem
,SMT_P_LEM
) ;
1413 lem
->lem_mib_index
= phy
+INDEX_PORT
;
1414 lem
->lem_phy_index
= phy_index(smc
,phy
) ;
1416 lem
->lem_cutoff
= mib
->fddiPORTLer_Cutoff
;
1417 lem
->lem_alarm
= mib
->fddiPORTLer_Alarm
;
1418 /* long term bit error rate */
1419 lem
->lem_estimate
= mib
->fddiPORTLer_Estimate
;
1420 /* # of rejected connections */
1421 lem
->lem_reject_ct
= mib
->fddiPORTLem_Reject_Ct
;
1422 lem
->lem_ct
= mib
->fddiPORTLem_Ct
; /* total number of errors */
1426 * fill version parameter
1428 static void smt_fill_version(struct s_smc
*smc
, struct smt_p_version
*vers
)
1431 SMTSETPARA(vers
,SMT_P_VERSION
) ;
1433 vers
->v_n
= 1 ; /* one version is enough .. */
1435 vers
->v_version
[0] = SMT_VID_2
;
1441 * fill frame status capabilities
1444 * note: this para 200B is NOT in swap table, because it's also set in
1447 static void smt_fill_fsc(struct s_smc
*smc
, struct smt_p_fsc
*fsc
)
1450 SMTSETPARA(fsc
,SMT_P_FSC
) ;
1452 fsc
->fsc_mac_index
= INDEX_MAC
; /* this is MIB ; MIB is NOT
1456 fsc
->fsc_value
= FSC_TYPE0
; /* "normal" node */
1457 #ifdef LITTLE_ENDIAN
1458 fsc
->fsc_mac_index
= smt_swap_short(INDEX_MAC
) ;
1459 fsc
->fsc_value
= smt_swap_short(FSC_TYPE0
) ;
1465 * fill mac counter field
1467 static void smt_fill_mac_counter(struct s_smc
*smc
, struct smt_p_mac_counter
*mc
)
1469 SMTSETPARA(mc
,SMT_P_MAC_COUNTER
) ;
1470 mc
->mc_mib_index
= INDEX_MAC
;
1471 mc
->mc_index
= mac_index(smc
,1) ;
1472 mc
->mc_receive_ct
= smc
->mib
.m
[MAC0
].fddiMACCopied_Ct
;
1473 mc
->mc_transmit_ct
= smc
->mib
.m
[MAC0
].fddiMACTransmit_Ct
;
1477 * fill mac frame not copied counter
1479 static void smt_fill_mac_fnc(struct s_smc
*smc
, struct smt_p_mac_fnc
*fnc
)
1481 SMTSETPARA(fnc
,SMT_P_MAC_FNC
) ;
1482 fnc
->nc_mib_index
= INDEX_MAC
;
1483 fnc
->nc_index
= mac_index(smc
,1) ;
1484 fnc
->nc_counter
= smc
->mib
.m
[MAC0
].fddiMACNotCopied_Ct
;
1489 * fill manufacturer field
1491 static void smt_fill_manufacturer(struct s_smc
*smc
,
1492 struct smp_p_manufacturer
*man
)
1494 SMTSETPARA(man
,SMT_P_MANUFACTURER
) ;
1495 memcpy((char *) man
->mf_data
,
1496 (char *) smc
->mib
.fddiSMTManufacturerData
,
1497 sizeof(man
->mf_data
)) ;
1503 static void smt_fill_user(struct s_smc
*smc
, struct smp_p_user
*user
)
1505 SMTSETPARA(user
,SMT_P_USER
) ;
1506 memcpy((char *) user
->us_data
,
1507 (char *) smc
->mib
.fddiSMTUserData
,
1508 sizeof(user
->us_data
)) ;
1514 static void smt_fill_setcount(struct s_smc
*smc
, struct smt_p_setcount
*setcount
)
1517 SMTSETPARA(setcount
,SMT_P_SETCOUNT
) ;
1518 setcount
->count
= smc
->mib
.fddiSMTSetCount
.count
;
1519 memcpy((char *)setcount
->timestamp
,
1520 (char *)smc
->mib
.fddiSMTSetCount
.timestamp
,8) ;
1526 static void smt_fill_echo(struct s_smc
*smc
, struct smt_p_echo
*echo
, u_long seed
,
1532 SMTSETPARA(echo
,SMT_P_ECHODATA
) ;
1533 echo
->para
.p_len
= len
;
1534 for (p
= echo
->ec_data
; len
; len
--) {
1535 *p
++ = (u_char
) seed
;
1542 * called from CFM if configuration changes
1544 static void smt_clear_una_dna(struct s_smc
*smc
)
1546 smc
->mib
.m
[MAC0
].fddiMACUpstreamNbr
= SMT_Unknown
;
1547 smc
->mib
.m
[MAC0
].fddiMACDownstreamNbr
= SMT_Unknown
;
1550 static void smt_clear_old_una_dna(struct s_smc
*smc
)
1552 smc
->mib
.m
[MAC0
].fddiMACOldUpstreamNbr
= SMT_Unknown
;
1553 smc
->mib
.m
[MAC0
].fddiMACOldDownstreamNbr
= SMT_Unknown
;
1556 u_long
smt_get_tid(struct s_smc
*smc
)
1559 while ((tid
= ++(smc
->sm
.smt_tid
) ^ SMT_TID_MAGIC
) == 0)
1561 return tid
& 0x3fffffffL
;
1566 * table of parameter lengths
1568 static const struct smt_pdef
{
1573 { SMT_P_UNA
, sizeof(struct smt_p_una
) ,
1575 { SMT_P_SDE
, sizeof(struct smt_p_sde
) ,
1577 { SMT_P_STATE
, sizeof(struct smt_p_state
) ,
1578 SWAP_SMT_P_STATE
} ,
1579 { SMT_P_TIMESTAMP
,sizeof(struct smt_p_timestamp
) ,
1580 SWAP_SMT_P_TIMESTAMP
} ,
1581 { SMT_P_POLICY
, sizeof(struct smt_p_policy
) ,
1582 SWAP_SMT_P_POLICY
} ,
1583 { SMT_P_LATENCY
, sizeof(struct smt_p_latency
) ,
1584 SWAP_SMT_P_LATENCY
} ,
1585 { SMT_P_NEIGHBORS
,sizeof(struct smt_p_neighbor
) ,
1586 SWAP_SMT_P_NEIGHBORS
} ,
1587 { SMT_P_PATH
, sizeof(struct smt_p_path
) ,
1589 { SMT_P_MAC_STATUS
,sizeof(struct smt_p_mac_status
) ,
1590 SWAP_SMT_P_MAC_STATUS
} ,
1591 { SMT_P_LEM
, sizeof(struct smt_p_lem
) ,
1593 { SMT_P_MAC_COUNTER
,sizeof(struct smt_p_mac_counter
) ,
1594 SWAP_SMT_P_MAC_COUNTER
} ,
1595 { SMT_P_MAC_FNC
,sizeof(struct smt_p_mac_fnc
) ,
1596 SWAP_SMT_P_MAC_FNC
} ,
1597 { SMT_P_PRIORITY
,sizeof(struct smt_p_priority
) ,
1598 SWAP_SMT_P_PRIORITY
} ,
1599 { SMT_P_EB
,sizeof(struct smt_p_eb
) ,
1601 { SMT_P_MANUFACTURER
,sizeof(struct smp_p_manufacturer
) ,
1602 SWAP_SMT_P_MANUFACTURER
} ,
1603 { SMT_P_REASON
, sizeof(struct smt_p_reason
) ,
1604 SWAP_SMT_P_REASON
} ,
1605 { SMT_P_REFUSED
, sizeof(struct smt_p_refused
) ,
1606 SWAP_SMT_P_REFUSED
} ,
1607 { SMT_P_VERSION
, sizeof(struct smt_p_version
) ,
1608 SWAP_SMT_P_VERSION
} ,
1610 { SMT_P0015
, sizeof(struct smt_p_0015
) , SWAP_SMT_P0015
} ,
1611 { SMT_P0016
, sizeof(struct smt_p_0016
) , SWAP_SMT_P0016
} ,
1612 { SMT_P0017
, sizeof(struct smt_p_0017
) , SWAP_SMT_P0017
} ,
1613 { SMT_P0018
, sizeof(struct smt_p_0018
) , SWAP_SMT_P0018
} ,
1614 { SMT_P0019
, sizeof(struct smt_p_0019
) , SWAP_SMT_P0019
} ,
1615 { SMT_P001A
, sizeof(struct smt_p_001a
) , SWAP_SMT_P001A
} ,
1616 { SMT_P001B
, sizeof(struct smt_p_001b
) , SWAP_SMT_P001B
} ,
1617 { SMT_P001C
, sizeof(struct smt_p_001c
) , SWAP_SMT_P001C
} ,
1618 { SMT_P001D
, sizeof(struct smt_p_001d
) , SWAP_SMT_P001D
} ,
1621 { SMT_P_FSC
, sizeof(struct smt_p_fsc
) ,
1625 { SMT_P_SETCOUNT
,0, SWAP_SMT_P_SETCOUNT
} ,
1626 { SMT_P1048
, 0, SWAP_SMT_P1048
} ,
1627 { SMT_P208C
, 0, SWAP_SMT_P208C
} ,
1628 { SMT_P208D
, 0, SWAP_SMT_P208D
} ,
1629 { SMT_P208E
, 0, SWAP_SMT_P208E
} ,
1630 { SMT_P208F
, 0, SWAP_SMT_P208F
} ,
1631 { SMT_P2090
, 0, SWAP_SMT_P2090
} ,
1633 { SMT_P320B
, sizeof(struct smt_p_320b
) , SWAP_SMT_P320B
} ,
1634 { SMT_P320F
, sizeof(struct smt_p_320f
) , SWAP_SMT_P320F
} ,
1635 { SMT_P3210
, sizeof(struct smt_p_3210
) , SWAP_SMT_P3210
} ,
1637 { SMT_P4050
, 0, SWAP_SMT_P4050
} ,
1638 { SMT_P4051
, 0, SWAP_SMT_P4051
} ,
1639 { SMT_P4052
, 0, SWAP_SMT_P4052
} ,
1640 { SMT_P4053
, 0, SWAP_SMT_P4053
} ,
1643 #define N_SMT_PLEN ARRAY_SIZE(smt_pdef)
1645 int smt_check_para(struct s_smc
*smc
, struct smt_header
*sm
,
1646 const u_short list
[])
1648 const u_short
*p
= list
;
1650 if (!sm_to_para(smc
,sm
,(int) *p
)) {
1651 DB_SMT("SMT: smt_check_para - missing para %hx", *p
);
1659 void *sm_to_para(struct s_smc
*smc
, struct smt_header
*sm
, int para
)
1669 p
= (char *)(sm
+1) ; /* pointer to info */
1671 if (((struct smt_para
*)p
)->p_type
== para
)
1672 found
= (void *) p
;
1673 plen
= ((struct smt_para
*)p
)->p_len
+ PARA_LEN
;
1677 DB_SMT("SMT : sm_to_para - length error %d", plen
);
1680 if ((plen
& 3) && (para
!= SMT_P_ECHODATA
)) {
1681 DB_SMT("SMT : sm_to_para - odd length %d", plen
);
1692 * send ANTC data test frame
1694 void fddi_send_antc(struct s_smc
*smc
, struct fddi_addr
*dest
)
1700 struct smt_header
*smt
;
1704 mb
= smt_get_mbuf() ;
1705 mb
->sm_len
= 3000+12 ;
1706 p
= smtod(mb
, char *) + 12 ;
1707 for (i
= 0 ; i
< 3000 ; i
++)
1710 smt
= smtod(mb
, struct smt_header
*) ;
1711 smt
->smt_dest
= *dest
;
1712 smt
->smt_source
= smc
->mib
.m
[MAC0
].fddiMACSMTAddress
;
1713 smt_send_mbuf(smc
,mb
,FC_ASYNC_LLC
) ;
1719 char *addr_to_string(struct fddi_addr
*addr
)
1722 static char string
[6*3] = "****" ;
1724 for (i
= 0 ; i
< 6 ; i
++) {
1725 string
[i
* 3] = hex_asc_hi(addr
->a
[i
]);
1726 string
[i
* 3 + 1] = hex_asc_lo(addr
->a
[i
]);
1727 string
[i
* 3 + 2] = ':';
1729 string
[5 * 3 + 2] = 0;
1735 * return static mac index
1737 static int mac_index(struct s_smc
*smc
, int mac
)
1744 return (smc
->s
.sas
== SMT_SAS
) ? 2 : 3;
1749 * return static phy index
1751 static int phy_index(struct s_smc
*smc
, int phy
)
1758 * return dynamic mac connection resource index
1760 static int mac_con_resource_index(struct s_smc
*smc
, int mac
)
1765 return entity_to_index(smc
, cem_get_downstream(smc
, ENTITY_MAC
));
1768 switch (smc
->mib
.fddiSMTCF_State
) {
1771 case SC11_C_WRAP_S
:
1773 case SC10_C_WRAP_B
:
1777 return smc
->s
.sas
== SMT_SAS
? 2 : 3;
1782 * return dynamic phy connection resource index
1784 static int phy_con_resource_index(struct s_smc
*smc
, int phy
)
1787 return entity_to_index(smc
, cem_get_downstream(smc
, ENTITY_PHY(phy
))) ;
1789 switch (smc
->mib
.fddiSMTCF_State
) {
1791 return phy
== PA
? 3 : 2;
1792 case SC10_C_WRAP_B
:
1793 return phy
== PA
? 1 : 3;
1795 return phy
== PA
? 3 : 1;
1797 return phy
== PA
? 2 : 3;
1798 case SC11_C_WRAP_S
:
1806 static int entity_to_index(struct s_smc
*smc
, int e
)
1808 if (e
== ENTITY_MAC
)
1809 return mac_index(smc
, 1);
1811 return phy_index(smc
, e
- ENTITY_PHY(0));
1815 #ifdef LITTLE_ENDIAN
1816 static int smt_swap_short(u_short s
)
1818 return ((s
>>8)&0xff) | ((s
&0xff)<<8);
1821 void smt_swap_para(struct smt_header
*sm
, int len
, int direction
)
1822 /* int direction; 0 encode 1 decode */
1824 struct smt_para
*pa
;
1825 const struct smt_pdef
*pd
;
1831 /* printf("smt_swap_para sm %x len %d dir %d\n",
1834 smt_string_swap((char *)sm
,SWAP_SMTHEADER
,len
) ;
1837 len
-= sizeof(struct smt_header
) ;
1839 p
= (char *) (sm
+ 1) ;
1841 pa
= (struct smt_para
*) p
;
1844 pa
->p_type
= smt_swap_short(pa
->p_type
) ;
1845 pa
->p_len
= smt_swap_short(pa
->p_len
) ;
1851 * note: paras can have 0 length !
1856 for (i
= N_SMT_PLEN
, pd
= smt_pdef
; i
; i
--,pd
++) {
1857 if (pd
->ptype
== type
)
1860 if (i
&& pd
->pswap
) {
1861 smt_string_swap(p
+PARA_LEN
,pd
->pswap
,len
) ;
1868 static void smt_string_swap(char *data
, const char *format
, int len
)
1870 const char *open_paren
= NULL
;
1873 while (len
> 0 && *format
) {
1876 open_paren
= format
;
1879 format
= open_paren
;
1890 data
+= *format
- '0' ;
1891 len
-= *format
- '0' ;
1919 void smt_swap_para(struct smt_header
*sm
, int len
, int direction
)
1920 /* int direction; 0 encode 1 decode */
1924 SK_UNUSED(direction
) ;
1931 int smt_action(struct s_smc
*smc
, int class, int code
, int index
)
1935 DB_SMT("SMT: action %d code %d", class, code
);
1937 case SMT_STATION_ACTION
:
1939 case SMT_STATION_ACTION_CONNECT
:
1940 smc
->mib
.fddiSMTRemoteDisconnectFlag
= FALSE
;
1941 queue_event(smc
,EVENT_ECM
,EC_CONNECT
) ;
1943 case SMT_STATION_ACTION_DISCONNECT
:
1944 queue_event(smc
,EVENT_ECM
,EC_DISCONNECT
) ;
1945 smc
->mib
.fddiSMTRemoteDisconnectFlag
= TRUE
;
1946 RS_SET(smc
,RS_DISCONNECT
) ;
1947 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1948 FDDI_SMT_EVENT
, (u_long
) FDDI_REMOTE_DISCONNECT
,
1949 smt_get_event_word(smc
));
1951 case SMT_STATION_ACTION_PATHTEST
:
1952 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1953 FDDI_SMT_EVENT
, (u_long
) FDDI_PATH_TEST
,
1954 smt_get_event_word(smc
));
1956 case SMT_STATION_ACTION_SELFTEST
:
1957 AIX_EVENT(smc
, (u_long
) FDDI_RING_STATUS
, (u_long
)
1958 FDDI_SMT_EVENT
, (u_long
) FDDI_REMOTE_SELF_TEST
,
1959 smt_get_event_word(smc
));
1961 case SMT_STATION_ACTION_DISABLE_A
:
1962 if (smc
->y
[PA
].pc_mode
== PM_PEER
) {
1963 RS_SET(smc
,RS_EVENT
) ;
1964 queue_event(smc
,EVENT_PCM
+PA
,PC_DISABLE
) ;
1967 case SMT_STATION_ACTION_DISABLE_B
:
1968 if (smc
->y
[PB
].pc_mode
== PM_PEER
) {
1969 RS_SET(smc
,RS_EVENT
) ;
1970 queue_event(smc
,EVENT_PCM
+PB
,PC_DISABLE
) ;
1973 case SMT_STATION_ACTION_DISABLE_M
:
1974 for (port
= 0 ; port
< NUMPHYS
; port
++) {
1975 if (smc
->mib
.p
[port
].fddiPORTMy_Type
!= TM
)
1977 RS_SET(smc
,RS_EVENT
) ;
1978 queue_event(smc
,EVENT_PCM
+port
,PC_DISABLE
) ;
1985 case SMT_PORT_ACTION
:
1987 case SMT_PORT_ACTION_ENABLE
:
1990 case SMT_PORT_ACTION_DISABLE
:
1991 event
= PC_DISABLE
;
1993 case SMT_PORT_ACTION_MAINT
:
1996 case SMT_PORT_ACTION_START
:
1999 case SMT_PORT_ACTION_STOP
:
2005 queue_event(smc
,EVENT_PCM
+index
,event
) ;
2014 * canonical conversion of <len> bytes beginning form *data
2017 static void hwm_conv_can(struct s_smc
*smc
, char *data
, int len
)
2023 for (i
= len
; i
; i
--, data
++)
2024 *data
= bitrev8(*data
);
2028 #endif /* no SLIM_SMT */