Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / net / skfp / smt.c
blob99a776a51fb5764872d2d5a4ee7f44e373556b3f
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 ******************************************************************************/
17 #include "h/types.h"
18 #include "h/fddi.h"
19 #include "h/smc.h"
20 #include "h/smt_p.h"
22 #define KERNEL
23 #include "h/smtstate.h"
25 #ifndef lint
26 static const char ID_sccs[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
27 #endif
29 extern const u_char canonical[256] ;
32 * FC in SMbuf
34 #define m_fc(mb) ((mb)->sm_data[0])
36 #define SMT_TID_MAGIC 0x1f0a7b3c
38 #ifdef DEBUG
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"
44 } ;
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"
49 } ;
50 #endif
51 #define LAST_CLASS (SMT_PMF_SET)
53 static const struct fddi_addr SMT_Unknown = {
54 { 0,0,0x1f,0,0,0 }
55 } ;
58 * external variables
60 extern const struct fddi_addr fddi_broadcast ;
63 * external functions
65 int pcm_status_twisted(struct s_smc *smc);
68 * function prototypes
70 #ifdef LITTLE_ENDIAN
71 static int smt_swap_short(u_short s);
72 #endif
73 static int mac_index(struct s_smc *smc, int mac);
74 static int phy_index(struct s_smc *smc, int phy);
75 static int mac_con_resource_index(struct s_smc *smc, int mac);
76 static int phy_con_resource_index(struct s_smc *smc, int phy);
77 static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
78 int local);
79 static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
80 int fc, u_long tid, int type, int local);
81 static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
82 u_long tid, int type, int len);
83 static void smt_echo_test(struct s_smc *smc, int dna);
84 static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
85 u_long tid, int local);
86 static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
87 u_long tid, int local);
88 #ifdef LITTLE_ENDIAN
89 static void smt_string_swap(char *data, const char *format, int len);
90 #endif
91 static void smt_add_frame_len(SMbuf *mb, int len);
92 static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
93 static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde);
94 static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state);
95 static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts);
96 static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy);
97 static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency);
98 static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor);
99 static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path);
100 static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st);
101 static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy);
102 static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers);
103 static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc);
104 static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc);
105 static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc);
106 static void smt_fill_manufacturer(struct s_smc *smc,
107 struct smp_p_manufacturer *man);
108 static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user);
109 static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount);
110 static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
111 int len);
113 static void smt_clear_una_dna(struct s_smc *smc);
114 static void smt_clear_old_una_dna(struct s_smc *smc);
115 #ifdef CONCENTRATOR
116 static int entity_to_index(void);
117 #endif
118 static void update_dac(struct s_smc *smc, int report);
119 static int div_ratio(u_long upper, u_long lower);
120 #ifdef USE_CAN_ADDR
121 static void hwm_conv_can(struct s_smc *smc, char *data, int len);
122 #else
123 #define hwm_conv_can(smc,data,len)
124 #endif
127 static inline int is_my_addr(const struct s_smc *smc,
128 const struct fddi_addr *addr)
130 return(*(short *)(&addr->a[0]) ==
131 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[0])
132 && *(short *)(&addr->a[2]) ==
133 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[2])
134 && *(short *)(&addr->a[4]) ==
135 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[4])) ;
138 static inline int is_broadcast(const struct fddi_addr *addr)
140 return(*(u_short *)(&addr->a[0]) == 0xffff &&
141 *(u_short *)(&addr->a[2]) == 0xffff &&
142 *(u_short *)(&addr->a[4]) == 0xffff ) ;
145 static inline int is_individual(const struct fddi_addr *addr)
147 return(!(addr->a[0] & GROUP_ADDR)) ;
150 static inline int is_equal(const struct fddi_addr *addr1,
151 const struct fddi_addr *addr2)
153 return(*(u_short *)(&addr1->a[0]) == *(u_short *)(&addr2->a[0]) &&
154 *(u_short *)(&addr1->a[2]) == *(u_short *)(&addr2->a[2]) &&
155 *(u_short *)(&addr1->a[4]) == *(u_short *)(&addr2->a[4]) ) ;
159 * list of mandatory paras in frames
161 static const u_short plist_nif[] = { SMT_P_UNA,SMT_P_SDE,SMT_P_STATE,0 } ;
164 * init SMT agent
166 void smt_agent_init(struct s_smc *smc)
168 int i ;
171 * get MAC address
173 smc->mib.m[MAC0].fddiMACSMTAddress = smc->hw.fddi_home_addr ;
176 * get OUI address from driver (bia == built-in-address)
178 smc->mib.fddiSMTStationId.sid_oem[0] = 0 ;
179 smc->mib.fddiSMTStationId.sid_oem[1] = 0 ;
180 driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
181 for (i = 0 ; i < 6 ; i ++) {
182 smc->mib.fddiSMTStationId.sid_node.a[i] =
183 canonical[smc->mib.fddiSMTStationId.sid_node.a[i]] ;
185 smc->mib.fddiSMTManufacturerData[0] =
186 smc->mib.fddiSMTStationId.sid_node.a[0] ;
187 smc->mib.fddiSMTManufacturerData[1] =
188 smc->mib.fddiSMTStationId.sid_node.a[1] ;
189 smc->mib.fddiSMTManufacturerData[2] =
190 smc->mib.fddiSMTStationId.sid_node.a[2] ;
191 smc->sm.smt_tid = 0 ;
192 smc->mib.m[MAC0].fddiMACDupAddressTest = DA_NONE ;
193 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
194 #ifndef SLIM_SMT
195 smt_clear_una_dna(smc) ;
196 smt_clear_old_una_dna(smc) ;
197 #endif
198 for (i = 0 ; i < SMT_MAX_TEST ; i++)
199 smc->sm.pend[i] = 0 ;
200 smc->sm.please_reconnect = 0 ;
201 smc->sm.uniq_ticks = 0 ;
205 * SMT task
206 * forever
207 * delay 30 seconds
208 * send NIF
209 * check tvu & tvd
210 * end
212 void smt_agent_task(struct s_smc *smc)
214 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
215 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
216 DB_SMT("SMT agent task\n",0,0) ;
219 #ifndef SMT_REAL_TOKEN_CT
220 void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
222 u_long count;
223 u_long time;
226 time = smt_get_time();
227 count = ((time - smc->sm.last_tok_time[mac_index]) *
228 100)/TICKS_PER_SECOND;
231 * Only when ring is up we will have a token count. The
232 * flag is unfortunatly a single instance value. This
233 * doesn't matter now, because we currently have only
234 * one MAC instance.
236 if (smc->hw.mac_ring_is_up){
237 smc->mib.m[mac_index].fddiMACToken_Ct += count;
240 /* Remember current time */
241 smc->sm.last_tok_time[mac_index] = time;
244 #endif
246 /*ARGSUSED1*/
247 void smt_event(struct s_smc *smc, int event)
249 u_long time ;
250 #ifndef SMT_REAL_TOKEN_CT
251 int i ;
252 #endif
255 if (smc->sm.please_reconnect) {
256 smc->sm.please_reconnect -- ;
257 if (smc->sm.please_reconnect == 0) {
258 /* Counted down */
259 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
263 if (event == SM_FAST)
264 return ;
267 * timer for periodic cleanup in driver
268 * reset and start the watchdog (FM2)
269 * ESS timer
270 * SBA timer
272 smt_timer_poll(smc) ;
273 smt_start_watchdog(smc) ;
274 #ifndef SLIM_SMT
275 #ifndef BOOT
276 #ifdef ESS
277 ess_timer_poll(smc) ;
278 #endif
279 #endif
280 #ifdef SBA
281 sba_timer_poll(smc) ;
282 #endif
284 smt_srf_event(smc,0,0,0) ;
286 #endif /* no SLIM_SMT */
288 time = smt_get_time() ;
290 if (time - smc->sm.smt_last_lem >= TICKS_PER_SECOND*8) {
292 * Use 8 sec. for the time intervall, it simplifies the
293 * LER estimation.
295 struct fddi_mib_m *mib ;
296 u_long upper ;
297 u_long lower ;
298 int cond ;
299 int port;
300 struct s_phy *phy ;
302 * calculate LEM bit error rate
304 sm_lem_evaluate(smc) ;
305 smc->sm.smt_last_lem = time ;
308 * check conditions
310 #ifndef SLIM_SMT
311 mac_update_counter(smc) ;
312 mib = smc->mib.m ;
313 upper =
314 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) +
315 (mib->fddiMACError_Ct - mib->fddiMACOld_Error_Ct) ;
316 lower =
317 (mib->fddiMACFrame_Ct - mib->fddiMACOld_Frame_Ct) +
318 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) ;
319 mib->fddiMACFrameErrorRatio = div_ratio(upper,lower) ;
321 cond =
322 ((!mib->fddiMACFrameErrorThreshold &&
323 mib->fddiMACError_Ct != mib->fddiMACOld_Error_Ct) ||
324 (mib->fddiMACFrameErrorRatio >
325 mib->fddiMACFrameErrorThreshold)) ;
327 if (cond != mib->fddiMACFrameErrorFlag)
328 smt_srf_event(smc,SMT_COND_MAC_FRAME_ERROR,
329 INDEX_MAC,cond) ;
331 upper =
332 (mib->fddiMACNotCopied_Ct - mib->fddiMACOld_NotCopied_Ct) ;
333 lower =
334 upper +
335 (mib->fddiMACCopied_Ct - mib->fddiMACOld_Copied_Ct) ;
336 mib->fddiMACNotCopiedRatio = div_ratio(upper,lower) ;
338 cond =
339 ((!mib->fddiMACNotCopiedThreshold &&
340 mib->fddiMACNotCopied_Ct !=
341 mib->fddiMACOld_NotCopied_Ct)||
342 (mib->fddiMACNotCopiedRatio >
343 mib->fddiMACNotCopiedThreshold)) ;
345 if (cond != mib->fddiMACNotCopiedFlag)
346 smt_srf_event(smc,SMT_COND_MAC_NOT_COPIED,
347 INDEX_MAC,cond) ;
350 * set old values
352 mib->fddiMACOld_Frame_Ct = mib->fddiMACFrame_Ct ;
353 mib->fddiMACOld_Copied_Ct = mib->fddiMACCopied_Ct ;
354 mib->fddiMACOld_Error_Ct = mib->fddiMACError_Ct ;
355 mib->fddiMACOld_Lost_Ct = mib->fddiMACLost_Ct ;
356 mib->fddiMACOld_NotCopied_Ct = mib->fddiMACNotCopied_Ct ;
359 * Check port EBError Condition
361 for (port = 0; port < NUMPHYS; port ++) {
362 phy = &smc->y[port] ;
364 if (!phy->mib->fddiPORTHardwarePresent) {
365 continue;
368 cond = (phy->mib->fddiPORTEBError_Ct -
369 phy->mib->fddiPORTOldEBError_Ct > 5) ;
371 /* If ratio is more than 5 in 8 seconds
372 * Set the condition.
374 smt_srf_event(smc,SMT_COND_PORT_EB_ERROR,
375 (int) (INDEX_PORT+ phy->np) ,cond) ;
378 * set old values
380 phy->mib->fddiPORTOldEBError_Ct =
381 phy->mib->fddiPORTEBError_Ct ;
384 #endif /* no SLIM_SMT */
387 #ifndef SLIM_SMT
389 if (time - smc->sm.smt_last_notify >= (u_long)
390 (smc->mib.fddiSMTTT_Notify * TICKS_PER_SECOND) ) {
392 * we can either send an announcement or a request
393 * a request will trigger a reply so that we can update
394 * our dna
395 * note: same tid must be used until reply is received
397 if (!smc->sm.pend[SMT_TID_NIF])
398 smc->sm.pend[SMT_TID_NIF] = smt_get_tid(smc) ;
399 smt_send_nif(smc,&fddi_broadcast, FC_SMT_NSA,
400 smc->sm.pend[SMT_TID_NIF], SMT_REQUEST,0) ;
401 smc->sm.smt_last_notify = time ;
405 * check timer
407 if (smc->sm.smt_tvu &&
408 time - smc->sm.smt_tvu > 228*TICKS_PER_SECOND) {
409 DB_SMT("SMT : UNA expired\n",0,0) ;
410 smc->sm.smt_tvu = 0 ;
412 if (!is_equal(&smc->mib.m[MAC0].fddiMACUpstreamNbr,
413 &SMT_Unknown)){
414 /* Do not update unknown address */
415 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
416 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
418 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
419 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
421 * Make sure the fddiMACUNDA_Flag = FALSE is
422 * included in the SRF so we don't generate
423 * a separate SRF for the deassertion of this
424 * condition
426 update_dac(smc,0) ;
427 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
428 INDEX_MAC,0) ;
430 if (smc->sm.smt_tvd &&
431 time - smc->sm.smt_tvd > 228*TICKS_PER_SECOND) {
432 DB_SMT("SMT : DNA expired\n",0,0) ;
433 smc->sm.smt_tvd = 0 ;
434 if (!is_equal(&smc->mib.m[MAC0].fddiMACDownstreamNbr,
435 &SMT_Unknown)){
436 /* Do not update unknown address */
437 smc->mib.m[MAC0].fddiMACOldDownstreamNbr=
438 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
440 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
441 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
442 INDEX_MAC,0) ;
445 #endif /* no SLIM_SMT */
447 #ifndef SMT_REAL_TOKEN_CT
449 * Token counter emulation section. If hardware supports the token
450 * count, the token counter will be updated in mac_update_counter.
452 for (i = MAC0; i < NUMMACS; i++ ){
453 if (time - smc->sm.last_tok_time[i] > 2*TICKS_PER_SECOND ){
454 smt_emulate_token_ct( smc, i );
457 #endif
459 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
460 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
463 static int div_ratio(u_long upper, u_long lower)
465 if ((upper<<16L) < upper)
466 upper = 0xffff0000L ;
467 else
468 upper <<= 16L ;
469 if (!lower)
470 return(0) ;
471 return((int)(upper/lower)) ;
474 #ifndef SLIM_SMT
477 * receive packet handler
479 void smt_received_pack(struct s_smc *smc, SMbuf *mb, int fs)
480 /* int fs; frame status */
482 struct smt_header *sm ;
483 int local ;
485 int illegal = 0 ;
487 switch (m_fc(mb)) {
488 case FC_SMT_INFO :
489 case FC_SMT_LAN_LOC :
490 case FC_SMT_LOC :
491 case FC_SMT_NSA :
492 break ;
493 default :
494 smt_free_mbuf(smc,mb) ;
495 return ;
498 smc->mib.m[MAC0].fddiMACSMTCopied_Ct++ ;
499 sm = smtod(mb,struct smt_header *) ;
500 local = ((fs & L_INDICATOR) != 0) ;
501 hwm_conv_can(smc,(char *)sm,12) ;
503 /* check destination address */
504 if (is_individual(&sm->smt_dest) && !is_my_addr(smc,&sm->smt_dest)) {
505 smt_free_mbuf(smc,mb) ;
506 return ;
508 #if 0 /* for DUP recognition, do NOT filter them */
509 /* ignore loop back packets */
510 if (is_my_addr(smc,&sm->smt_source) && !local) {
511 smt_free_mbuf(smc,mb) ;
512 return ;
514 #endif
516 smt_swap_para(sm,(int) mb->sm_len,1) ;
517 DB_SMT("SMT : received packet [%s] at 0x%x\n",
518 smt_type_name[m_fc(mb) & 0xf],sm) ;
519 DB_SMT("SMT : version %d, class %s\n",sm->smt_version,
520 smt_class_name[(sm->smt_class>LAST_CLASS)?0 : sm->smt_class]) ;
522 #ifdef SBA
524 * check if NSA frame
526 if (m_fc(mb) == FC_SMT_NSA && sm->smt_class == SMT_NIF &&
527 (sm->smt_type == SMT_ANNOUNCE || sm->smt_type == SMT_REQUEST)) {
528 smc->sba.sm = sm ;
529 sba(smc,NIF) ;
531 #endif
534 * ignore any packet with NSA and A-indicator set
536 if ( (fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) {
537 DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
538 addr_to_string(&sm->smt_source),0) ;
539 smt_free_mbuf(smc,mb) ;
540 return ;
544 * ignore frames with illegal length
546 if (((sm->smt_class == SMT_ECF) && (sm->smt_len > SMT_MAX_ECHO_LEN)) ||
547 ((sm->smt_class != SMT_ECF) && (sm->smt_len > SMT_MAX_INFO_LEN))) {
548 smt_free_mbuf(smc,mb) ;
549 return ;
553 * check SMT version
555 switch (sm->smt_class) {
556 case SMT_NIF :
557 case SMT_SIF_CONFIG :
558 case SMT_SIF_OPER :
559 case SMT_ECF :
560 if (sm->smt_version != SMT_VID)
561 illegal = 1;
562 break ;
563 default :
564 if (sm->smt_version != SMT_VID_2)
565 illegal = 1;
566 break ;
568 if (illegal) {
569 DB_SMT("SMT : version = %d, dest = %s\n",
570 sm->smt_version,addr_to_string(&sm->smt_source)) ;
571 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_VERSION,local) ;
572 smt_free_mbuf(smc,mb) ;
573 return ;
575 if ((sm->smt_len > mb->sm_len - sizeof(struct smt_header)) ||
576 ((sm->smt_len & 3) && (sm->smt_class != SMT_ECF))) {
577 DB_SMT("SMT: info length error, len = %d\n",sm->smt_len,0) ;
578 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,local) ;
579 smt_free_mbuf(smc,mb) ;
580 return ;
582 switch (sm->smt_class) {
583 case SMT_NIF :
584 if (smt_check_para(smc,sm,plist_nif)) {
585 DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
586 break ;
588 switch (sm->smt_type) {
589 case SMT_ANNOUNCE :
590 case SMT_REQUEST :
591 if (!(fs & C_INDICATOR) && m_fc(mb) == FC_SMT_NSA
592 && is_broadcast(&sm->smt_dest)) {
593 struct smt_p_state *st ;
595 /* set my UNA */
596 if (!is_equal(
597 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
598 &sm->smt_source)) {
599 DB_SMT("SMT : updated my UNA = %s\n",
600 addr_to_string(&sm->smt_source),0) ;
601 if (!is_equal(&smc->mib.m[MAC0].
602 fddiMACUpstreamNbr,&SMT_Unknown)){
603 /* Do not update unknown address */
604 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
605 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
608 smc->mib.m[MAC0].fddiMACUpstreamNbr =
609 sm->smt_source ;
610 smt_srf_event(smc,
611 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
612 INDEX_MAC,0) ;
613 smt_echo_test(smc,0) ;
615 smc->sm.smt_tvu = smt_get_time() ;
616 st = (struct smt_p_state *)
617 sm_to_para(smc,sm,SMT_P_STATE) ;
618 if (st) {
619 smc->mib.m[MAC0].fddiMACUNDA_Flag =
620 (st->st_dupl_addr & SMT_ST_MY_DUPA) ?
621 TRUE : FALSE ;
622 update_dac(smc,1) ;
625 if ((sm->smt_type == SMT_REQUEST) &&
626 is_individual(&sm->smt_source) &&
627 ((!(fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) ||
628 (m_fc(mb) != FC_SMT_NSA))) {
629 DB_SMT("SMT : replying to NIF request %s\n",
630 addr_to_string(&sm->smt_source),0) ;
631 smt_send_nif(smc,&sm->smt_source,
632 FC_SMT_INFO,
633 sm->smt_tid,
634 SMT_REPLY,local) ;
636 break ;
637 case SMT_REPLY :
638 DB_SMT("SMT : received NIF response from %s\n",
639 addr_to_string(&sm->smt_source),0) ;
640 if (fs & A_INDICATOR) {
641 smc->sm.pend[SMT_TID_NIF] = 0 ;
642 DB_SMT("SMT : duplicate address\n",0,0) ;
643 smc->mib.m[MAC0].fddiMACDupAddressTest =
644 DA_FAILED ;
645 smc->r.dup_addr_test = DA_FAILED ;
646 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
647 smc->mib.m[MAC0].fddiMACDA_Flag = TRUE ;
648 update_dac(smc,1) ;
649 break ;
651 if (sm->smt_tid == smc->sm.pend[SMT_TID_NIF]) {
652 smc->sm.pend[SMT_TID_NIF] = 0 ;
653 /* set my DNA */
654 if (!is_equal(
655 &smc->mib.m[MAC0].fddiMACDownstreamNbr,
656 &sm->smt_source)) {
657 DB_SMT("SMT : updated my DNA\n",0,0) ;
658 if (!is_equal(&smc->mib.m[MAC0].
659 fddiMACDownstreamNbr, &SMT_Unknown)){
660 /* Do not update unknown address */
661 smc->mib.m[MAC0].fddiMACOldDownstreamNbr =
662 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
665 smc->mib.m[MAC0].fddiMACDownstreamNbr =
666 sm->smt_source ;
667 smt_srf_event(smc,
668 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
669 INDEX_MAC,0) ;
670 smt_echo_test(smc,1) ;
672 smc->mib.m[MAC0].fddiMACDA_Flag = FALSE ;
673 update_dac(smc,1) ;
674 smc->sm.smt_tvd = smt_get_time() ;
675 smc->mib.m[MAC0].fddiMACDupAddressTest =
676 DA_PASSED ;
677 if (smc->r.dup_addr_test != DA_PASSED) {
678 smc->r.dup_addr_test = DA_PASSED ;
679 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
682 else if (sm->smt_tid ==
683 smc->sm.pend[SMT_TID_NIF_TEST]) {
684 DB_SMT("SMT : NIF test TID ok\n",0,0) ;
686 else {
687 DB_SMT("SMT : expected TID %lx, got %lx\n",
688 smc->sm.pend[SMT_TID_NIF],sm->smt_tid) ;
690 break ;
691 default :
692 illegal = 2 ;
693 break ;
695 break ;
696 case SMT_SIF_CONFIG : /* station information */
697 if (sm->smt_type != SMT_REQUEST)
698 break ;
699 DB_SMT("SMT : replying to SIF Config request from %s\n",
700 addr_to_string(&sm->smt_source),0) ;
701 smt_send_sif_config(smc,&sm->smt_source,sm->smt_tid,local) ;
702 break ;
703 case SMT_SIF_OPER : /* station information */
704 if (sm->smt_type != SMT_REQUEST)
705 break ;
706 DB_SMT("SMT : replying to SIF Operation request from %s\n",
707 addr_to_string(&sm->smt_source),0) ;
708 smt_send_sif_operation(smc,&sm->smt_source,sm->smt_tid,local) ;
709 break ;
710 case SMT_ECF : /* echo frame */
711 switch (sm->smt_type) {
712 case SMT_REPLY :
713 smc->mib.priv.fddiPRIVECF_Reply_Rx++ ;
714 DB_SMT("SMT: received ECF reply from %s\n",
715 addr_to_string(&sm->smt_source),0) ;
716 if (sm_to_para(smc,sm,SMT_P_ECHODATA) == 0) {
717 DB_SMT("SMT: ECHODATA missing\n",0,0) ;
718 break ;
720 if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF]) {
721 DB_SMT("SMT : ECF test TID ok\n",0,0) ;
723 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_UNA]) {
724 DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
726 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_DNA]) {
727 DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
729 else {
730 DB_SMT("SMT : expected TID %lx, got %lx\n",
731 smc->sm.pend[SMT_TID_ECF],
732 sm->smt_tid) ;
734 break ;
735 case SMT_REQUEST :
736 smc->mib.priv.fddiPRIVECF_Req_Rx++ ;
738 if (sm->smt_len && !sm_to_para(smc,sm,SMT_P_ECHODATA)) {
739 DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
740 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,
741 local) ;
742 break ;
744 DB_SMT("SMT - sending ECF reply to %s\n",
745 addr_to_string(&sm->smt_source),0) ;
747 /* set destination addr. & reply */
748 sm->smt_dest = sm->smt_source ;
749 sm->smt_type = SMT_REPLY ;
750 dump_smt(smc,sm,"ECF REPLY") ;
751 smc->mib.priv.fddiPRIVECF_Reply_Tx++ ;
752 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
753 return ; /* DON'T free mbuf */
755 default :
756 illegal = 1 ;
757 break ;
759 break ;
760 #ifndef BOOT
761 case SMT_RAF : /* resource allocation */
762 #ifdef ESS
763 DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
764 fs = ess_raf_received_pack(smc,mb,sm,fs) ;
765 #endif
767 #ifdef SBA
768 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
769 sba_raf_received_pack(smc,sm,fs) ;
770 #endif
771 break ;
772 case SMT_RDF : /* request denied */
773 smc->mib.priv.fddiPRIVRDF_Rx++ ;
774 break ;
775 case SMT_ESF : /* extended service - not supported */
776 if (sm->smt_type == SMT_REQUEST) {
777 DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
778 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
780 break ;
781 case SMT_PMF_GET :
782 case SMT_PMF_SET :
783 if (sm->smt_type != SMT_REQUEST)
784 break ;
785 /* update statistics */
786 if (sm->smt_class == SMT_PMF_GET)
787 smc->mib.priv.fddiPRIVPMF_Get_Rx++ ;
788 else
789 smc->mib.priv.fddiPRIVPMF_Set_Rx++ ;
791 * ignore PMF SET with I/G set
793 if ((sm->smt_class == SMT_PMF_SET) &&
794 !is_individual(&sm->smt_dest)) {
795 DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
796 break ;
798 smt_pmf_received_pack(smc,mb, local) ;
799 break ;
800 case SMT_SRF :
801 dump_smt(smc,sm,"SRF received") ;
802 break ;
803 default :
804 if (sm->smt_type != SMT_REQUEST)
805 break ;
807 * For frames with unknown class:
808 * we need to send a RDF frame according to 8.1.3.1.1,
809 * only if it is a REQUEST.
811 DB_SMT("SMT : class = %d, send RDF to %s\n",
812 sm->smt_class, addr_to_string(&sm->smt_source)) ;
814 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
815 break ;
816 #endif
818 if (illegal) {
819 DB_SMT("SMT: discarding invalid frame, reason = %d\n",
820 illegal,0) ;
822 smt_free_mbuf(smc,mb) ;
825 static void update_dac(struct s_smc *smc, int report)
827 int cond ;
829 cond = ( smc->mib.m[MAC0].fddiMACUNDA_Flag |
830 smc->mib.m[MAC0].fddiMACDA_Flag) != 0 ;
831 if (report && (cond != smc->mib.m[MAC0].fddiMACDuplicateAddressCond))
832 smt_srf_event(smc, SMT_COND_MAC_DUP_ADDR,INDEX_MAC,cond) ;
833 else
834 smc->mib.m[MAC0].fddiMACDuplicateAddressCond = cond ;
838 * send SMT frame
839 * set source address
840 * set station ID
841 * send frame
843 void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local)
844 /* SMbuf *mb; buffer to send */
845 /* int fc; FC value */
847 struct smt_header *sm ;
849 if (!smc->r.sm_ma_avail && !local) {
850 smt_free_mbuf(smc,mb) ;
851 return ;
853 sm = smtod(mb,struct smt_header *) ;
854 sm->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
855 sm->smt_sid = smc->mib.fddiSMTStationId ;
857 smt_swap_para(sm,(int) mb->sm_len,0) ; /* swap para & header */
858 hwm_conv_can(smc,(char *)sm,12) ; /* convert SA and DA */
859 smc->mib.m[MAC0].fddiMACSMTTransmit_Ct++ ;
860 smt_send_mbuf(smc,mb,local ? FC_SMT_LOC : fc) ;
864 * generate and send RDF
866 static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
867 int local)
868 /* SMbuf *rej; mbuf of offending frame */
869 /* int fc; FC of denied frame */
870 /* int reason; reason code */
872 SMbuf *mb ;
873 struct smt_header *sm ; /* header of offending frame */
874 struct smt_rdf *rdf ;
875 int len ;
876 int frame_len ;
878 sm = smtod(rej,struct smt_header *) ;
879 if (sm->smt_type != SMT_REQUEST)
880 return ;
882 DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
883 addr_to_string(&sm->smt_source),reason) ;
887 * note: get framelength from MAC length, NOT from SMT header
888 * smt header length is included in sm_len
890 frame_len = rej->sm_len ;
892 if (!(mb=smt_build_frame(smc,SMT_RDF,SMT_REPLY,sizeof(struct smt_rdf))))
893 return ;
894 rdf = smtod(mb,struct smt_rdf *) ;
895 rdf->smt.smt_tid = sm->smt_tid ; /* use TID from sm */
896 rdf->smt.smt_dest = sm->smt_source ; /* set dest = source */
898 /* set P12 */
899 rdf->reason.para.p_type = SMT_P_REASON ;
900 rdf->reason.para.p_len = sizeof(struct smt_p_reason) - PARA_LEN ;
901 rdf->reason.rdf_reason = reason ;
903 /* set P14 */
904 rdf->version.para.p_type = SMT_P_VERSION ;
905 rdf->version.para.p_len = sizeof(struct smt_p_version) - PARA_LEN ;
906 rdf->version.v_pad = 0 ;
907 rdf->version.v_n = 1 ;
908 rdf->version.v_index = 1 ;
909 rdf->version.v_version[0] = SMT_VID_2 ;
910 rdf->version.v_pad2 = 0 ;
912 /* set P13 */
913 if ((unsigned) frame_len <= SMT_MAX_INFO_LEN - sizeof(*rdf) +
914 2*sizeof(struct smt_header))
915 len = frame_len ;
916 else
917 len = SMT_MAX_INFO_LEN - sizeof(*rdf) +
918 2*sizeof(struct smt_header) ;
919 /* make length multiple of 4 */
920 len &= ~3 ;
921 rdf->refused.para.p_type = SMT_P_REFUSED ;
922 /* length of para is smt_frame + ref_fc */
923 rdf->refused.para.p_len = len + 4 ;
924 rdf->refused.ref_fc = fc ;
926 /* swap it back */
927 smt_swap_para(sm,frame_len,0) ;
929 memcpy((char *) &rdf->refused.ref_header,(char *) sm,len) ;
931 len -= sizeof(struct smt_header) ;
932 mb->sm_len += len ;
933 rdf->smt.smt_len += len ;
935 dump_smt(smc,(struct smt_header *)rdf,"RDF") ;
936 smc->mib.priv.fddiPRIVRDF_Tx++ ;
937 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
941 * generate and send NIF
943 static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
944 int fc, u_long tid, int type, int local)
945 /* struct fddi_addr *dest; dest address */
946 /* int fc; frame control */
947 /* u_long tid; transaction id */
948 /* int type; frame type */
950 struct smt_nif *nif ;
951 SMbuf *mb ;
953 if (!(mb = smt_build_frame(smc,SMT_NIF,type,sizeof(struct smt_nif))))
954 return ;
955 nif = smtod(mb, struct smt_nif *) ;
956 smt_fill_una(smc,&nif->una) ; /* set UNA */
957 smt_fill_sde(smc,&nif->sde) ; /* set station descriptor */
958 smt_fill_state(smc,&nif->state) ; /* set state information */
959 #ifdef SMT6_10
960 smt_fill_fsc(smc,&nif->fsc) ; /* set frame status cap. */
961 #endif
962 nif->smt.smt_dest = *dest ; /* destination address */
963 nif->smt.smt_tid = tid ; /* transaction ID */
964 dump_smt(smc,(struct smt_header *)nif,"NIF") ;
965 smt_send_frame(smc,mb,fc,local) ;
968 #ifdef DEBUG
970 * send NIF request (test purpose)
972 static void smt_send_nif_request(struct s_smc *smc, struct fddi_addr *dest)
974 smc->sm.pend[SMT_TID_NIF_TEST] = smt_get_tid(smc) ;
975 smt_send_nif(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_NIF_TEST],
976 SMT_REQUEST,0) ;
980 * send ECF request (test purpose)
982 static void smt_send_ecf_request(struct s_smc *smc, struct fddi_addr *dest,
983 int len)
985 smc->sm.pend[SMT_TID_ECF] = smt_get_tid(smc) ;
986 smt_send_ecf(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_ECF],
987 SMT_REQUEST,len) ;
989 #endif
992 * echo test
994 static void smt_echo_test(struct s_smc *smc, int dna)
996 u_long tid ;
998 smc->sm.pend[dna ? SMT_TID_ECF_DNA : SMT_TID_ECF_UNA] =
999 tid = smt_get_tid(smc) ;
1000 smt_send_ecf(smc, dna ?
1001 &smc->mib.m[MAC0].fddiMACDownstreamNbr :
1002 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
1003 FC_SMT_INFO,tid, SMT_REQUEST, (SMT_TEST_ECHO_LEN & ~3)-8) ;
1007 * generate and send ECF
1009 static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
1010 u_long tid, int type, int len)
1011 /* struct fddi_addr *dest; dest address */
1012 /* int fc; frame control */
1013 /* u_long tid; transaction id */
1014 /* int type; frame type */
1015 /* int len; frame length */
1017 struct smt_ecf *ecf ;
1018 SMbuf *mb ;
1020 if (!(mb = smt_build_frame(smc,SMT_ECF,type,SMT_ECF_LEN + len)))
1021 return ;
1022 ecf = smtod(mb, struct smt_ecf *) ;
1024 smt_fill_echo(smc,&ecf->ec_echo,tid,len) ; /* set ECHO */
1025 ecf->smt.smt_dest = *dest ; /* destination address */
1026 ecf->smt.smt_tid = tid ; /* transaction ID */
1027 smc->mib.priv.fddiPRIVECF_Req_Tx++ ;
1028 smt_send_frame(smc,mb,fc,0) ;
1032 * generate and send SIF config response
1035 static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
1036 u_long tid, int local)
1037 /* struct fddi_addr *dest; dest address */
1038 /* u_long tid; transaction id */
1040 struct smt_sif_config *sif ;
1041 SMbuf *mb ;
1042 int len ;
1043 if (!(mb = smt_build_frame(smc,SMT_SIF_CONFIG,SMT_REPLY,
1044 SIZEOF_SMT_SIF_CONFIG)))
1045 return ;
1047 sif = smtod(mb, struct smt_sif_config *) ;
1048 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1049 smt_fill_sde(smc,&sif->sde) ; /* set station descriptor */
1050 smt_fill_version(smc,&sif->version) ; /* set version information */
1051 smt_fill_state(smc,&sif->state) ; /* set state information */
1052 smt_fill_policy(smc,&sif->policy) ; /* set station policy */
1053 smt_fill_latency(smc,&sif->latency); /* set station latency */
1054 smt_fill_neighbor(smc,&sif->neighbor); /* set station neighbor */
1055 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1056 len = smt_fill_path(smc,&sif->path); /* set station path descriptor*/
1057 sif->smt.smt_dest = *dest ; /* destination address */
1058 sif->smt.smt_tid = tid ; /* transaction ID */
1059 smt_add_frame_len(mb,len) ; /* adjust length fields */
1060 dump_smt(smc,(struct smt_header *)sif,"SIF Configuration Reply") ;
1061 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1065 * generate and send SIF operation response
1068 static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
1069 u_long tid, int local)
1070 /* struct fddi_addr *dest; dest address */
1071 /* u_long tid; transaction id */
1073 struct smt_sif_operation *sif ;
1074 SMbuf *mb ;
1075 int ports ;
1076 int i ;
1078 ports = NUMPHYS ;
1079 #ifndef CONCENTRATOR
1080 if (smc->s.sas == SMT_SAS)
1081 ports = 1 ;
1082 #endif
1084 if (!(mb = smt_build_frame(smc,SMT_SIF_OPER,SMT_REPLY,
1085 SIZEOF_SMT_SIF_OPERATION+ports*sizeof(struct smt_p_lem))))
1086 return ;
1087 sif = smtod(mb, struct smt_sif_operation *) ;
1088 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1089 smt_fill_mac_status(smc,&sif->status) ; /* set mac status */
1090 smt_fill_mac_counter(smc,&sif->mc) ; /* set mac counter field */
1091 smt_fill_mac_fnc(smc,&sif->fnc) ; /* set frame not copied counter */
1092 smt_fill_manufacturer(smc,&sif->man) ; /* set manufacturer field */
1093 smt_fill_user(smc,&sif->user) ; /* set user field */
1094 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1096 * set link error mon information
1098 if (ports == 1) {
1099 smt_fill_lem(smc,sif->lem,PS) ;
1101 else {
1102 for (i = 0 ; i < ports ; i++) {
1103 smt_fill_lem(smc,&sif->lem[i],i) ;
1107 sif->smt.smt_dest = *dest ; /* destination address */
1108 sif->smt.smt_tid = tid ; /* transaction ID */
1109 dump_smt(smc,(struct smt_header *)sif,"SIF Operation Reply") ;
1110 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1114 * get and initialize SMT frame
1116 SMbuf *smt_build_frame(struct s_smc *smc, int class, int type,
1117 int length)
1119 SMbuf *mb ;
1120 struct smt_header *smt ;
1122 #if 0
1123 if (!smc->r.sm_ma_avail) {
1124 return(0) ;
1126 #endif
1127 if (!(mb = smt_get_mbuf(smc)))
1128 return(mb) ;
1130 mb->sm_len = length ;
1131 smt = smtod(mb, struct smt_header *) ;
1132 smt->smt_dest = fddi_broadcast ; /* set dest = broadcast */
1133 smt->smt_class = class ;
1134 smt->smt_type = type ;
1135 switch (class) {
1136 case SMT_NIF :
1137 case SMT_SIF_CONFIG :
1138 case SMT_SIF_OPER :
1139 case SMT_ECF :
1140 smt->smt_version = SMT_VID ;
1141 break ;
1142 default :
1143 smt->smt_version = SMT_VID_2 ;
1144 break ;
1146 smt->smt_tid = smt_get_tid(smc) ; /* set transaction ID */
1147 smt->smt_pad = 0 ;
1148 smt->smt_len = length - sizeof(struct smt_header) ;
1149 return(mb) ;
1152 static void smt_add_frame_len(SMbuf *mb, int len)
1154 struct smt_header *smt ;
1156 smt = smtod(mb, struct smt_header *) ;
1157 smt->smt_len += len ;
1158 mb->sm_len += len ;
1164 * fill values in UNA parameter
1166 static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una)
1168 SMTSETPARA(una,SMT_P_UNA) ;
1169 una->una_pad = 0 ;
1170 una->una_node = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1174 * fill values in SDE parameter
1176 static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde)
1178 SMTSETPARA(sde,SMT_P_SDE) ;
1179 sde->sde_non_master = smc->mib.fddiSMTNonMaster_Ct ;
1180 sde->sde_master = smc->mib.fddiSMTMaster_Ct ;
1181 sde->sde_mac_count = NUMMACS ; /* only 1 MAC */
1182 #ifdef CONCENTRATOR
1183 sde->sde_type = SMT_SDE_CONCENTRATOR ;
1184 #else
1185 sde->sde_type = SMT_SDE_STATION ;
1186 #endif
1190 * fill in values in station state parameter
1192 static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state)
1194 int top ;
1195 int twist ;
1197 SMTSETPARA(state,SMT_P_STATE) ;
1198 state->st_pad = 0 ;
1200 /* determine topology */
1201 top = 0 ;
1202 if (smc->mib.fddiSMTPeerWrapFlag) {
1203 top |= SMT_ST_WRAPPED ; /* state wrapped */
1205 #ifdef CONCENTRATOR
1206 if (cfm_status_unattached(smc)) {
1207 top |= SMT_ST_UNATTACHED ; /* unattached concentrator */
1209 #endif
1210 if ((twist = pcm_status_twisted(smc)) & 1) {
1211 top |= SMT_ST_TWISTED_A ; /* twisted cable */
1213 if (twist & 2) {
1214 top |= SMT_ST_TWISTED_B ; /* twisted cable */
1216 #ifdef OPT_SRF
1217 top |= SMT_ST_SRF ;
1218 #endif
1219 if (pcm_rooted_station(smc))
1220 top |= SMT_ST_ROOTED_S ;
1221 if (smc->mib.a[0].fddiPATHSbaPayload != 0)
1222 top |= SMT_ST_SYNC_SERVICE ;
1223 state->st_topology = top ;
1224 state->st_dupl_addr =
1225 ((smc->mib.m[MAC0].fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0 ) |
1226 (smc->mib.m[MAC0].fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0)) ;
1230 * fill values in timestamp parameter
1232 static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts)
1235 SMTSETPARA(ts,SMT_P_TIMESTAMP) ;
1236 smt_set_timestamp(smc,ts->ts_time) ;
1239 void smt_set_timestamp(struct s_smc *smc, u_char *p)
1241 u_long time ;
1242 u_long utime ;
1245 * timestamp is 64 bits long ; resolution is 80 nS
1246 * our clock resolution is 10mS
1247 * 10mS/80ns = 125000 ~ 2^17 = 131072
1249 utime = smt_get_time() ;
1250 time = utime * 100 ;
1251 time /= TICKS_PER_SECOND ;
1252 p[0] = 0 ;
1253 p[1] = (u_char)((time>>(8+8+8+8-1)) & 1) ;
1254 p[2] = (u_char)(time>>(8+8+8-1)) ;
1255 p[3] = (u_char)(time>>(8+8-1)) ;
1256 p[4] = (u_char)(time>>(8-1)) ;
1257 p[5] = (u_char)(time<<1) ;
1258 p[6] = (u_char)(smc->sm.uniq_ticks>>8) ;
1259 p[7] = (u_char)smc->sm.uniq_ticks ;
1261 * make sure we don't wrap: restart whenever the upper digits change
1263 if (utime != smc->sm.uniq_time) {
1264 smc->sm.uniq_ticks = 0 ;
1266 smc->sm.uniq_ticks++ ;
1267 smc->sm.uniq_time = utime ;
1271 * fill values in station policy parameter
1273 static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy)
1275 int i ;
1276 u_char *map ;
1277 u_short in ;
1278 u_short out ;
1281 * MIB para 101b (fddiSMTConnectionPolicy) coding
1282 * is different from 0005 coding
1284 static u_char ansi_weirdness[16] = {
1285 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1287 SMTSETPARA(policy,SMT_P_POLICY) ;
1289 out = 0 ;
1290 in = smc->mib.fddiSMTConnectionPolicy ;
1291 for (i = 0, map = ansi_weirdness ; i < 16 ; i++) {
1292 if (in & 1)
1293 out |= (1<<*map) ;
1294 in >>= 1 ;
1295 map++ ;
1297 policy->pl_config = smc->mib.fddiSMTConfigPolicy ;
1298 policy->pl_connect = out ;
1302 * fill values in latency equivalent parameter
1304 static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency)
1306 SMTSETPARA(latency,SMT_P_LATENCY) ;
1308 latency->lt_phyout_idx1 = phy_index(smc,0) ;
1309 latency->lt_latency1 = 10 ; /* in octets (byte clock) */
1311 * note: latency has two phy entries by definition
1312 * for a SAS, the 2nd one is null
1314 if (smc->s.sas == SMT_DAS) {
1315 latency->lt_phyout_idx2 = phy_index(smc,1) ;
1316 latency->lt_latency2 = 10 ; /* in octets (byte clock) */
1318 else {
1319 latency->lt_phyout_idx2 = 0 ;
1320 latency->lt_latency2 = 0 ;
1325 * fill values in MAC neighbors parameter
1327 static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor)
1329 SMTSETPARA(neighbor,SMT_P_NEIGHBORS) ;
1331 neighbor->nb_mib_index = INDEX_MAC ;
1332 neighbor->nb_mac_index = mac_index(smc,1) ;
1333 neighbor->nb_una = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1334 neighbor->nb_dna = smc->mib.m[MAC0].fddiMACDownstreamNbr ;
1338 * fill values in path descriptor
1340 #ifdef CONCENTRATOR
1341 #define ALLPHYS NUMPHYS
1342 #else
1343 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1344 #endif
1346 static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path)
1348 SK_LOC_DECL(int,type) ;
1349 SK_LOC_DECL(int,state) ;
1350 SK_LOC_DECL(int,remote) ;
1351 SK_LOC_DECL(int,mac) ;
1352 int len ;
1353 int p ;
1354 int physp ;
1355 struct smt_phy_rec *phy ;
1356 struct smt_mac_rec *pd_mac ;
1358 len = PARA_LEN +
1359 sizeof(struct smt_mac_rec) * NUMMACS +
1360 sizeof(struct smt_phy_rec) * ALLPHYS ;
1361 path->para.p_type = SMT_P_PATH ;
1362 path->para.p_len = len - PARA_LEN ;
1364 /* PHYs */
1365 for (p = 0,phy = path->pd_phy ; p < ALLPHYS ; p++, phy++) {
1366 physp = p ;
1367 #ifndef CONCENTRATOR
1368 if (smc->s.sas == SMT_SAS)
1369 physp = PS ;
1370 #endif
1371 pcm_status_state(smc,physp,&type,&state,&remote,&mac) ;
1372 #ifdef LITTLE_ENDIAN
1373 phy->phy_mib_index = smt_swap_short((u_short)p+INDEX_PORT) ;
1374 #else
1375 phy->phy_mib_index = p+INDEX_PORT ;
1376 #endif
1377 phy->phy_type = type ;
1378 phy->phy_connect_state = state ;
1379 phy->phy_remote_type = remote ;
1380 phy->phy_remote_mac = mac ;
1381 phy->phy_resource_idx = phy_con_resource_index(smc,p) ;
1384 /* MAC */
1385 pd_mac = (struct smt_mac_rec *) phy ;
1386 pd_mac->mac_addr = smc->mib.m[MAC0].fddiMACSMTAddress ;
1387 pd_mac->mac_resource_idx = mac_con_resource_index(smc,1) ;
1388 return(len) ;
1392 * fill values in mac status
1394 static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st)
1396 SMTSETPARA(st,SMT_P_MAC_STATUS) ;
1398 st->st_mib_index = INDEX_MAC ;
1399 st->st_mac_index = mac_index(smc,1) ;
1401 mac_update_counter(smc) ;
1403 * timer values are represented in SMT as 2's complement numbers
1404 * units : internal : 2's complement BCLK
1406 st->st_t_req = smc->mib.m[MAC0].fddiMACT_Req ;
1407 st->st_t_neg = smc->mib.m[MAC0].fddiMACT_Neg ;
1408 st->st_t_max = smc->mib.m[MAC0].fddiMACT_Max ;
1409 st->st_tvx_value = smc->mib.m[MAC0].fddiMACTvxValue ;
1410 st->st_t_min = smc->mib.m[MAC0].fddiMACT_Min ;
1412 st->st_sba = smc->mib.a[PATH0].fddiPATHSbaPayload ;
1413 st->st_frame_ct = smc->mib.m[MAC0].fddiMACFrame_Ct ;
1414 st->st_error_ct = smc->mib.m[MAC0].fddiMACError_Ct ;
1415 st->st_lost_ct = smc->mib.m[MAC0].fddiMACLost_Ct ;
1419 * fill values in LEM status
1421 static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy)
1423 struct fddi_mib_p *mib ;
1425 mib = smc->y[phy].mib ;
1427 SMTSETPARA(lem,SMT_P_LEM) ;
1428 lem->lem_mib_index = phy+INDEX_PORT ;
1429 lem->lem_phy_index = phy_index(smc,phy) ;
1430 lem->lem_pad2 = 0 ;
1431 lem->lem_cutoff = mib->fddiPORTLer_Cutoff ;
1432 lem->lem_alarm = mib->fddiPORTLer_Alarm ;
1433 /* long term bit error rate */
1434 lem->lem_estimate = mib->fddiPORTLer_Estimate ;
1435 /* # of rejected connections */
1436 lem->lem_reject_ct = mib->fddiPORTLem_Reject_Ct ;
1437 lem->lem_ct = mib->fddiPORTLem_Ct ; /* total number of errors */
1441 * fill version parameter
1443 static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers)
1445 SK_UNUSED(smc) ;
1446 SMTSETPARA(vers,SMT_P_VERSION) ;
1447 vers->v_pad = 0 ;
1448 vers->v_n = 1 ; /* one version is enough .. */
1449 vers->v_index = 1 ;
1450 vers->v_version[0] = SMT_VID_2 ;
1451 vers->v_pad2 = 0 ;
1454 #ifdef SMT6_10
1456 * fill frame status capabilities
1459 * note: this para 200B is NOT in swap table, because it's also set in
1460 * PMF add_para
1462 static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc)
1464 SK_UNUSED(smc) ;
1465 SMTSETPARA(fsc,SMT_P_FSC) ;
1466 fsc->fsc_pad0 = 0 ;
1467 fsc->fsc_mac_index = INDEX_MAC ; /* this is MIB ; MIB is NOT
1468 * mac_index ()i !
1470 fsc->fsc_pad1 = 0 ;
1471 fsc->fsc_value = FSC_TYPE0 ; /* "normal" node */
1472 #ifdef LITTLE_ENDIAN
1473 fsc->fsc_mac_index = smt_swap_short(INDEX_MAC) ;
1474 fsc->fsc_value = smt_swap_short(FSC_TYPE0) ;
1475 #endif
1477 #endif
1480 * fill mac counter field
1482 static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc)
1484 SMTSETPARA(mc,SMT_P_MAC_COUNTER) ;
1485 mc->mc_mib_index = INDEX_MAC ;
1486 mc->mc_index = mac_index(smc,1) ;
1487 mc->mc_receive_ct = smc->mib.m[MAC0].fddiMACCopied_Ct ;
1488 mc->mc_transmit_ct = smc->mib.m[MAC0].fddiMACTransmit_Ct ;
1492 * fill mac frame not copied counter
1494 static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc)
1496 SMTSETPARA(fnc,SMT_P_MAC_FNC) ;
1497 fnc->nc_mib_index = INDEX_MAC ;
1498 fnc->nc_index = mac_index(smc,1) ;
1499 fnc->nc_counter = smc->mib.m[MAC0].fddiMACNotCopied_Ct ;
1504 * fill manufacturer field
1506 static void smt_fill_manufacturer(struct s_smc *smc,
1507 struct smp_p_manufacturer *man)
1509 SMTSETPARA(man,SMT_P_MANUFACTURER) ;
1510 memcpy((char *) man->mf_data,
1511 (char *) smc->mib.fddiSMTManufacturerData,
1512 sizeof(man->mf_data)) ;
1516 * fill user field
1518 static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user)
1520 SMTSETPARA(user,SMT_P_USER) ;
1521 memcpy((char *) user->us_data,
1522 (char *) smc->mib.fddiSMTUserData,
1523 sizeof(user->us_data)) ;
1527 * fill set count
1529 static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount)
1531 SK_UNUSED(smc) ;
1532 SMTSETPARA(setcount,SMT_P_SETCOUNT) ;
1533 setcount->count = smc->mib.fddiSMTSetCount.count ;
1534 memcpy((char *)setcount->timestamp,
1535 (char *)smc->mib.fddiSMTSetCount.timestamp,8) ;
1539 * fill echo data
1541 static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
1542 int len)
1544 u_char *p ;
1546 SK_UNUSED(smc) ;
1547 SMTSETPARA(echo,SMT_P_ECHODATA) ;
1548 echo->para.p_len = len ;
1549 for (p = echo->ec_data ; len ; len--) {
1550 *p++ = (u_char) seed ;
1551 seed += 13 ;
1556 * clear DNA and UNA
1557 * called from CFM if configuration changes
1559 static void smt_clear_una_dna(struct s_smc *smc)
1561 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1562 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
1565 static void smt_clear_old_una_dna(struct s_smc *smc)
1567 smc->mib.m[MAC0].fddiMACOldUpstreamNbr = SMT_Unknown ;
1568 smc->mib.m[MAC0].fddiMACOldDownstreamNbr = SMT_Unknown ;
1571 u_long smt_get_tid(struct s_smc *smc)
1573 u_long tid ;
1574 while ((tid = ++(smc->sm.smt_tid) ^ SMT_TID_MAGIC) == 0)
1576 return(tid & 0x3fffffffL) ;
1581 * table of parameter lengths
1583 static const struct smt_pdef {
1584 int ptype ;
1585 int plen ;
1586 const char *pswap ;
1587 } smt_pdef[] = {
1588 { SMT_P_UNA, sizeof(struct smt_p_una) ,
1589 SWAP_SMT_P_UNA } ,
1590 { SMT_P_SDE, sizeof(struct smt_p_sde) ,
1591 SWAP_SMT_P_SDE } ,
1592 { SMT_P_STATE, sizeof(struct smt_p_state) ,
1593 SWAP_SMT_P_STATE } ,
1594 { SMT_P_TIMESTAMP,sizeof(struct smt_p_timestamp) ,
1595 SWAP_SMT_P_TIMESTAMP } ,
1596 { SMT_P_POLICY, sizeof(struct smt_p_policy) ,
1597 SWAP_SMT_P_POLICY } ,
1598 { SMT_P_LATENCY, sizeof(struct smt_p_latency) ,
1599 SWAP_SMT_P_LATENCY } ,
1600 { SMT_P_NEIGHBORS,sizeof(struct smt_p_neighbor) ,
1601 SWAP_SMT_P_NEIGHBORS } ,
1602 { SMT_P_PATH, sizeof(struct smt_p_path) ,
1603 SWAP_SMT_P_PATH } ,
1604 { SMT_P_MAC_STATUS,sizeof(struct smt_p_mac_status) ,
1605 SWAP_SMT_P_MAC_STATUS } ,
1606 { SMT_P_LEM, sizeof(struct smt_p_lem) ,
1607 SWAP_SMT_P_LEM } ,
1608 { SMT_P_MAC_COUNTER,sizeof(struct smt_p_mac_counter) ,
1609 SWAP_SMT_P_MAC_COUNTER } ,
1610 { SMT_P_MAC_FNC,sizeof(struct smt_p_mac_fnc) ,
1611 SWAP_SMT_P_MAC_FNC } ,
1612 { SMT_P_PRIORITY,sizeof(struct smt_p_priority) ,
1613 SWAP_SMT_P_PRIORITY } ,
1614 { SMT_P_EB,sizeof(struct smt_p_eb) ,
1615 SWAP_SMT_P_EB } ,
1616 { SMT_P_MANUFACTURER,sizeof(struct smp_p_manufacturer) ,
1617 SWAP_SMT_P_MANUFACTURER } ,
1618 { SMT_P_REASON, sizeof(struct smt_p_reason) ,
1619 SWAP_SMT_P_REASON } ,
1620 { SMT_P_REFUSED, sizeof(struct smt_p_refused) ,
1621 SWAP_SMT_P_REFUSED } ,
1622 { SMT_P_VERSION, sizeof(struct smt_p_version) ,
1623 SWAP_SMT_P_VERSION } ,
1624 #ifdef ESS
1625 { SMT_P0015, sizeof(struct smt_p_0015) , SWAP_SMT_P0015 } ,
1626 { SMT_P0016, sizeof(struct smt_p_0016) , SWAP_SMT_P0016 } ,
1627 { SMT_P0017, sizeof(struct smt_p_0017) , SWAP_SMT_P0017 } ,
1628 { SMT_P0018, sizeof(struct smt_p_0018) , SWAP_SMT_P0018 } ,
1629 { SMT_P0019, sizeof(struct smt_p_0019) , SWAP_SMT_P0019 } ,
1630 { SMT_P001A, sizeof(struct smt_p_001a) , SWAP_SMT_P001A } ,
1631 { SMT_P001B, sizeof(struct smt_p_001b) , SWAP_SMT_P001B } ,
1632 { SMT_P001C, sizeof(struct smt_p_001c) , SWAP_SMT_P001C } ,
1633 { SMT_P001D, sizeof(struct smt_p_001d) , SWAP_SMT_P001D } ,
1634 #endif
1635 #if 0
1636 { SMT_P_FSC, sizeof(struct smt_p_fsc) ,
1637 SWAP_SMT_P_FSC } ,
1638 #endif
1640 { SMT_P_SETCOUNT,0, SWAP_SMT_P_SETCOUNT } ,
1641 { SMT_P1048, 0, SWAP_SMT_P1048 } ,
1642 { SMT_P208C, 0, SWAP_SMT_P208C } ,
1643 { SMT_P208D, 0, SWAP_SMT_P208D } ,
1644 { SMT_P208E, 0, SWAP_SMT_P208E } ,
1645 { SMT_P208F, 0, SWAP_SMT_P208F } ,
1646 { SMT_P2090, 0, SWAP_SMT_P2090 } ,
1647 #ifdef ESS
1648 { SMT_P320B, sizeof(struct smt_p_320b) , SWAP_SMT_P320B } ,
1649 { SMT_P320F, sizeof(struct smt_p_320f) , SWAP_SMT_P320F } ,
1650 { SMT_P3210, sizeof(struct smt_p_3210) , SWAP_SMT_P3210 } ,
1651 #endif
1652 { SMT_P4050, 0, SWAP_SMT_P4050 } ,
1653 { SMT_P4051, 0, SWAP_SMT_P4051 } ,
1654 { SMT_P4052, 0, SWAP_SMT_P4052 } ,
1655 { SMT_P4053, 0, SWAP_SMT_P4053 } ,
1658 #define N_SMT_PLEN (sizeof(smt_pdef)/sizeof(smt_pdef[0]))
1660 int smt_check_para(struct s_smc *smc, struct smt_header *sm,
1661 const u_short list[])
1663 const u_short *p = list ;
1664 while (*p) {
1665 if (!sm_to_para(smc,sm,(int) *p)) {
1666 DB_SMT("SMT: smt_check_para - missing para %x\n",*p,0);
1667 return(-1) ;
1669 p++ ;
1671 return(0) ;
1674 void *sm_to_para(struct s_smc *smc, struct smt_header *sm, int para)
1676 char *p ;
1677 int len ;
1678 int plen ;
1679 void *found = NULL;
1681 SK_UNUSED(smc) ;
1683 len = sm->smt_len ;
1684 p = (char *)(sm+1) ; /* pointer to info */
1685 while (len > 0 ) {
1686 if (((struct smt_para *)p)->p_type == para)
1687 found = (void *) p ;
1688 plen = ((struct smt_para *)p)->p_len + PARA_LEN ;
1689 p += plen ;
1690 len -= plen ;
1691 if (len < 0) {
1692 DB_SMT("SMT : sm_to_para - length error %d\n",plen,0) ;
1693 return NULL;
1695 if ((plen & 3) && (para != SMT_P_ECHODATA)) {
1696 DB_SMT("SMT : sm_to_para - odd length %d\n",plen,0) ;
1697 return NULL;
1699 if (found)
1700 return(found) ;
1702 return NULL;
1705 #if 0
1707 * send ANTC data test frame
1709 void fddi_send_antc(struct s_smc *smc, struct fddi_addr *dest)
1711 SK_UNUSED(smc) ;
1712 SK_UNUSED(dest) ;
1713 #if 0
1714 SMbuf *mb ;
1715 struct smt_header *smt ;
1716 int i ;
1717 char *p ;
1719 mb = smt_get_mbuf() ;
1720 mb->sm_len = 3000+12 ;
1721 p = smtod(mb, char *) + 12 ;
1722 for (i = 0 ; i < 3000 ; i++)
1723 *p++ = 1 << (i&7) ;
1725 smt = smtod(mb, struct smt_header *) ;
1726 smt->smt_dest = *dest ;
1727 smt->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
1728 smt_send_mbuf(smc,mb,FC_ASYNC_LLC) ;
1729 #endif
1731 #endif
1733 #ifdef DEBUG
1734 #define hextoasc(x) "0123456789abcdef"[x]
1736 char *addr_to_string(struct fddi_addr *addr)
1738 int i ;
1739 static char string[6*3] = "****" ;
1741 for (i = 0 ; i < 6 ; i++) {
1742 string[i*3] = hextoasc((addr->a[i]>>4)&0xf) ;
1743 string[i*3+1] = hextoasc((addr->a[i])&0xf) ;
1744 string[i*3+2] = ':' ;
1746 string[5*3+2] = 0 ;
1747 return(string) ;
1749 #endif
1751 #ifdef AM29K
1752 smt_ifconfig(int argc, char *argv[])
1754 if (argc >= 2 && !strcmp(argv[0],"opt_bypass") &&
1755 !strcmp(argv[1],"yes")) {
1756 smc->mib.fddiSMTBypassPresent = 1 ;
1757 return(0) ;
1759 return(amdfddi_config(0,argc,argv)) ;
1761 #endif
1764 * return static mac index
1766 static int mac_index(struct s_smc *smc, int mac)
1768 SK_UNUSED(mac) ;
1769 #ifdef CONCENTRATOR
1770 SK_UNUSED(smc) ;
1771 return(NUMPHYS+1) ;
1772 #else
1773 return((smc->s.sas == SMT_SAS) ? 2 : 3) ;
1774 #endif
1778 * return static phy index
1780 static int phy_index(struct s_smc *smc, int phy)
1782 SK_UNUSED(smc) ;
1783 return(phy+1);
1787 * return dynamic mac connection resource index
1789 static int mac_con_resource_index(struct s_smc *smc, int mac)
1791 #ifdef CONCENTRATOR
1792 SK_UNUSED(smc) ;
1793 SK_UNUSED(mac) ;
1794 return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_MAC))) ;
1795 #else
1796 SK_UNUSED(mac) ;
1797 switch (smc->mib.fddiSMTCF_State) {
1798 case SC9_C_WRAP_A :
1799 case SC5_THRU_B :
1800 case SC11_C_WRAP_S :
1801 return(1) ;
1802 case SC10_C_WRAP_B :
1803 case SC4_THRU_A :
1804 return(2) ;
1806 return(smc->s.sas == SMT_SAS ? 2 : 3) ;
1807 #endif
1811 * return dynamic phy connection resource index
1813 static int phy_con_resource_index(struct s_smc *smc, int phy)
1815 #ifdef CONCENTRATOR
1816 return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_PHY(phy)))) ;
1817 #else
1818 switch (smc->mib.fddiSMTCF_State) {
1819 case SC9_C_WRAP_A :
1820 return(phy == PA ? 3 : 2) ;
1821 case SC10_C_WRAP_B :
1822 return(phy == PA ? 1 : 3) ;
1823 case SC4_THRU_A :
1824 return(phy == PA ? 3 : 1) ;
1825 case SC5_THRU_B :
1826 return(phy == PA ? 2 : 3) ;
1827 case SC11_C_WRAP_S :
1828 return(2) ;
1830 return(phy) ;
1831 #endif
1834 #ifdef CONCENTRATOR
1835 static int entity_to_index(struct s_smc *smc, int e)
1837 if (e == ENTITY_MAC)
1838 return(mac_index(smc,1)) ;
1839 else
1840 return(phy_index(smc,e - ENTITY_PHY(0))) ;
1842 #endif
1844 #ifdef LITTLE_ENDIAN
1845 static int smt_swap_short(u_short s)
1847 return(((s>>8)&0xff)|((s&0xff)<<8)) ;
1850 void smt_swap_para(struct smt_header *sm, int len, int direction)
1851 /* int direction; 0 encode 1 decode */
1853 struct smt_para *pa ;
1854 const struct smt_pdef *pd ;
1855 char *p ;
1856 int plen ;
1857 int type ;
1858 int i ;
1860 /* printf("smt_swap_para sm %x len %d dir %d\n",
1861 sm,len,direction) ;
1863 smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
1865 /* swap args */
1866 len -= sizeof(struct smt_header) ;
1868 p = (char *) (sm + 1) ;
1869 while (len > 0) {
1870 pa = (struct smt_para *) p ;
1871 plen = pa->p_len ;
1872 type = pa->p_type ;
1873 pa->p_type = smt_swap_short(pa->p_type) ;
1874 pa->p_len = smt_swap_short(pa->p_len) ;
1875 if (direction) {
1876 plen = pa->p_len ;
1877 type = pa->p_type ;
1880 * note: paras can have 0 length !
1882 if (plen < 0)
1883 break ;
1884 plen += PARA_LEN ;
1885 for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
1886 if (pd->ptype == type)
1887 break ;
1889 if (i && pd->pswap) {
1890 smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
1892 len -= plen ;
1893 p += plen ;
1897 static void smt_string_swap(char *data, const char *format, int len)
1899 const char *open_paren = NULL ;
1900 int x ;
1902 while (len > 0 && *format) {
1903 switch (*format) {
1904 case '[' :
1905 open_paren = format ;
1906 break ;
1907 case ']' :
1908 format = open_paren ;
1909 break ;
1910 case '1' :
1911 case '2' :
1912 case '3' :
1913 case '4' :
1914 case '5' :
1915 case '6' :
1916 case '7' :
1917 case '8' :
1918 case '9' :
1919 data += *format - '0' ;
1920 len -= *format - '0' ;
1921 break ;
1922 case 'c':
1923 data++ ;
1924 len-- ;
1925 break ;
1926 case 's' :
1927 x = data[0] ;
1928 data[0] = data[1] ;
1929 data[1] = x ;
1930 data += 2 ;
1931 len -= 2 ;
1932 break ;
1933 case 'l' :
1934 x = data[0] ;
1935 data[0] = data[3] ;
1936 data[3] = x ;
1937 x = data[1] ;
1938 data[1] = data[2] ;
1939 data[2] = x ;
1940 data += 4 ;
1941 len -= 4 ;
1942 break ;
1944 format++ ;
1947 #else
1948 void smt_swap_para(struct smt_header *sm, int len, int direction)
1949 /* int direction; 0 encode 1 decode */
1951 SK_UNUSED(sm) ;
1952 SK_UNUSED(len) ;
1953 SK_UNUSED(direction) ;
1955 #endif
1958 * PMF actions
1960 int smt_action(struct s_smc *smc, int class, int code, int index)
1962 int event ;
1963 int port ;
1964 DB_SMT("SMT: action %d code %d\n",class,code) ;
1965 switch(class) {
1966 case SMT_STATION_ACTION :
1967 switch(code) {
1968 case SMT_STATION_ACTION_CONNECT :
1969 smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
1970 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
1971 break ;
1972 case SMT_STATION_ACTION_DISCONNECT :
1973 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
1974 smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
1975 RS_SET(smc,RS_DISCONNECT) ;
1976 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1977 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
1978 smt_get_event_word(smc));
1979 break ;
1980 case SMT_STATION_ACTION_PATHTEST :
1981 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1982 FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
1983 smt_get_event_word(smc));
1984 break ;
1985 case SMT_STATION_ACTION_SELFTEST :
1986 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1987 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
1988 smt_get_event_word(smc));
1989 break ;
1990 case SMT_STATION_ACTION_DISABLE_A :
1991 if (smc->y[PA].pc_mode == PM_PEER) {
1992 RS_SET(smc,RS_EVENT) ;
1993 queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
1995 break ;
1996 case SMT_STATION_ACTION_DISABLE_B :
1997 if (smc->y[PB].pc_mode == PM_PEER) {
1998 RS_SET(smc,RS_EVENT) ;
1999 queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
2001 break ;
2002 case SMT_STATION_ACTION_DISABLE_M :
2003 for (port = 0 ; port < NUMPHYS ; port++) {
2004 if (smc->mib.p[port].fddiPORTMy_Type != TM)
2005 continue ;
2006 RS_SET(smc,RS_EVENT) ;
2007 queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
2009 break ;
2010 default :
2011 return(1) ;
2013 break ;
2014 case SMT_PORT_ACTION :
2015 switch(code) {
2016 case SMT_PORT_ACTION_ENABLE :
2017 event = PC_ENABLE ;
2018 break ;
2019 case SMT_PORT_ACTION_DISABLE :
2020 event = PC_DISABLE ;
2021 break ;
2022 case SMT_PORT_ACTION_MAINT :
2023 event = PC_MAINT ;
2024 break ;
2025 case SMT_PORT_ACTION_START :
2026 event = PC_START ;
2027 break ;
2028 case SMT_PORT_ACTION_STOP :
2029 event = PC_STOP ;
2030 break ;
2031 default :
2032 return(1) ;
2034 queue_event(smc,EVENT_PCM+index,event) ;
2035 break ;
2036 default :
2037 return(1) ;
2039 return(0) ;
2043 * canonical conversion of <len> bytes beginning form *data
2045 #ifdef USE_CAN_ADDR
2046 static void hwm_conv_can(struct s_smc *smc, char *data, int len)
2048 int i ;
2050 SK_UNUSED(smc) ;
2052 for (i = len; i ; i--, data++) {
2053 *data = canonical[*(u_char *)data] ;
2056 #endif
2058 #endif /* no SLIM_SMT */