kmemtrace: SLOB hooks.
[linux-2.6/kmemtrace.git] / drivers / net / skfp / smt.c
blobffbfb1b79f97360975cd8da31d198591fde55037
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"
21 #include <linux/bitrev.h>
23 #define KERNEL
24 #include "h/smtstate.h"
26 #ifndef lint
27 static const char ID_sccs[] = "@(#)smt.c 2.43 98/11/23 (C) SK " ;
28 #endif
31 * FC in SMbuf
33 #define m_fc(mb) ((mb)->sm_data[0])
35 #define SMT_TID_MAGIC 0x1f0a7b3c
37 #ifdef DEBUG
38 static const char *const smt_type_name[] = {
39 "SMT_00??", "SMT_INFO", "SMT_02??", "SMT_03??",
40 "SMT_04??", "SMT_05??", "SMT_06??", "SMT_07??",
41 "SMT_08??", "SMT_09??", "SMT_0A??", "SMT_0B??",
42 "SMT_0C??", "SMT_0D??", "SMT_0E??", "SMT_NSA"
43 } ;
45 static const char *const smt_class_name[] = {
46 "UNKNOWN","NIF","SIF_CONFIG","SIF_OPER","ECF","RAF","RDF",
47 "SRF","PMF_GET","PMF_SET","ESF"
48 } ;
49 #endif
50 #define LAST_CLASS (SMT_PMF_SET)
52 static const struct fddi_addr SMT_Unknown = {
53 { 0,0,0x1f,0,0,0 }
54 } ;
57 * external variables
59 extern const struct fddi_addr fddi_broadcast ;
62 * external functions
64 int pcm_status_twisted(struct s_smc *smc);
67 * function prototypes
69 #ifdef LITTLE_ENDIAN
70 static int smt_swap_short(u_short s);
71 #endif
72 static int mac_index(struct s_smc *smc, int mac);
73 static int phy_index(struct s_smc *smc, int phy);
74 static int mac_con_resource_index(struct s_smc *smc, int mac);
75 static int phy_con_resource_index(struct s_smc *smc, int phy);
76 static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
77 int local);
78 static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
79 int fc, u_long tid, int type, int local);
80 static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
81 u_long tid, int type, int len);
82 static void smt_echo_test(struct s_smc *smc, int dna);
83 static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
84 u_long tid, int local);
85 static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
86 u_long tid, int local);
87 #ifdef LITTLE_ENDIAN
88 static void smt_string_swap(char *data, const char *format, int len);
89 #endif
90 static void smt_add_frame_len(SMbuf *mb, int len);
91 static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una);
92 static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde);
93 static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state);
94 static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts);
95 static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy);
96 static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency);
97 static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor);
98 static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path);
99 static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st);
100 static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy);
101 static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers);
102 static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc);
103 static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc);
104 static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc);
105 static void smt_fill_manufacturer(struct s_smc *smc,
106 struct smp_p_manufacturer *man);
107 static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user);
108 static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount);
109 static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
110 int len);
112 static void smt_clear_una_dna(struct s_smc *smc);
113 static void smt_clear_old_una_dna(struct s_smc *smc);
114 #ifdef CONCENTRATOR
115 static int entity_to_index(void);
116 #endif
117 static void update_dac(struct s_smc *smc, int report);
118 static int div_ratio(u_long upper, u_long lower);
119 #ifdef USE_CAN_ADDR
120 static void hwm_conv_can(struct s_smc *smc, char *data, int len);
121 #else
122 #define hwm_conv_can(smc,data,len)
123 #endif
126 static inline int is_my_addr(const struct s_smc *smc,
127 const struct fddi_addr *addr)
129 return(*(short *)(&addr->a[0]) ==
130 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[0])
131 && *(short *)(&addr->a[2]) ==
132 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[2])
133 && *(short *)(&addr->a[4]) ==
134 *(short *)(&smc->mib.m[MAC0].fddiMACSMTAddress.a[4])) ;
137 static inline int is_broadcast(const struct fddi_addr *addr)
139 return(*(u_short *)(&addr->a[0]) == 0xffff &&
140 *(u_short *)(&addr->a[2]) == 0xffff &&
141 *(u_short *)(&addr->a[4]) == 0xffff ) ;
144 static inline int is_individual(const struct fddi_addr *addr)
146 return(!(addr->a[0] & GROUP_ADDR)) ;
149 static inline int is_equal(const struct fddi_addr *addr1,
150 const struct fddi_addr *addr2)
152 return(*(u_short *)(&addr1->a[0]) == *(u_short *)(&addr2->a[0]) &&
153 *(u_short *)(&addr1->a[2]) == *(u_short *)(&addr2->a[2]) &&
154 *(u_short *)(&addr1->a[4]) == *(u_short *)(&addr2->a[4]) ) ;
158 * list of mandatory paras in frames
160 static const u_short plist_nif[] = { SMT_P_UNA,SMT_P_SDE,SMT_P_STATE,0 } ;
163 * init SMT agent
165 void smt_agent_init(struct s_smc *smc)
167 int i ;
170 * get MAC address
172 smc->mib.m[MAC0].fddiMACSMTAddress = smc->hw.fddi_home_addr ;
175 * get OUI address from driver (bia == built-in-address)
177 smc->mib.fddiSMTStationId.sid_oem[0] = 0 ;
178 smc->mib.fddiSMTStationId.sid_oem[1] = 0 ;
179 driver_get_bia(smc,&smc->mib.fddiSMTStationId.sid_node) ;
180 for (i = 0 ; i < 6 ; i ++) {
181 smc->mib.fddiSMTStationId.sid_node.a[i] =
182 bitrev8(smc->mib.fddiSMTStationId.sid_node.a[i]);
184 smc->mib.fddiSMTManufacturerData[0] =
185 smc->mib.fddiSMTStationId.sid_node.a[0] ;
186 smc->mib.fddiSMTManufacturerData[1] =
187 smc->mib.fddiSMTStationId.sid_node.a[1] ;
188 smc->mib.fddiSMTManufacturerData[2] =
189 smc->mib.fddiSMTStationId.sid_node.a[2] ;
190 smc->sm.smt_tid = 0 ;
191 smc->mib.m[MAC0].fddiMACDupAddressTest = DA_NONE ;
192 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
193 #ifndef SLIM_SMT
194 smt_clear_una_dna(smc) ;
195 smt_clear_old_una_dna(smc) ;
196 #endif
197 for (i = 0 ; i < SMT_MAX_TEST ; i++)
198 smc->sm.pend[i] = 0 ;
199 smc->sm.please_reconnect = 0 ;
200 smc->sm.uniq_ticks = 0 ;
204 * SMT task
205 * forever
206 * delay 30 seconds
207 * send NIF
208 * check tvu & tvd
209 * end
211 void smt_agent_task(struct s_smc *smc)
213 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
214 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
215 DB_SMT("SMT agent task\n",0,0) ;
218 #ifndef SMT_REAL_TOKEN_CT
219 void smt_emulate_token_ct(struct s_smc *smc, int mac_index)
221 u_long count;
222 u_long time;
225 time = smt_get_time();
226 count = ((time - smc->sm.last_tok_time[mac_index]) *
227 100)/TICKS_PER_SECOND;
230 * Only when ring is up we will have a token count. The
231 * flag is unfortunatly a single instance value. This
232 * doesn't matter now, because we currently have only
233 * one MAC instance.
235 if (smc->hw.mac_ring_is_up){
236 smc->mib.m[mac_index].fddiMACToken_Ct += count;
239 /* Remember current time */
240 smc->sm.last_tok_time[mac_index] = time;
243 #endif
245 /*ARGSUSED1*/
246 void smt_event(struct s_smc *smc, int event)
248 u_long time ;
249 #ifndef SMT_REAL_TOKEN_CT
250 int i ;
251 #endif
254 if (smc->sm.please_reconnect) {
255 smc->sm.please_reconnect -- ;
256 if (smc->sm.please_reconnect == 0) {
257 /* Counted down */
258 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
262 if (event == SM_FAST)
263 return ;
266 * timer for periodic cleanup in driver
267 * reset and start the watchdog (FM2)
268 * ESS timer
269 * SBA timer
271 smt_timer_poll(smc) ;
272 smt_start_watchdog(smc) ;
273 #ifndef SLIM_SMT
274 #ifndef BOOT
275 #ifdef ESS
276 ess_timer_poll(smc) ;
277 #endif
278 #endif
279 #ifdef SBA
280 sba_timer_poll(smc) ;
281 #endif
283 smt_srf_event(smc,0,0,0) ;
285 #endif /* no SLIM_SMT */
287 time = smt_get_time() ;
289 if (time - smc->sm.smt_last_lem >= TICKS_PER_SECOND*8) {
291 * Use 8 sec. for the time intervall, it simplifies the
292 * LER estimation.
294 struct fddi_mib_m *mib ;
295 u_long upper ;
296 u_long lower ;
297 int cond ;
298 int port;
299 struct s_phy *phy ;
301 * calculate LEM bit error rate
303 sm_lem_evaluate(smc) ;
304 smc->sm.smt_last_lem = time ;
307 * check conditions
309 #ifndef SLIM_SMT
310 mac_update_counter(smc) ;
311 mib = smc->mib.m ;
312 upper =
313 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) +
314 (mib->fddiMACError_Ct - mib->fddiMACOld_Error_Ct) ;
315 lower =
316 (mib->fddiMACFrame_Ct - mib->fddiMACOld_Frame_Ct) +
317 (mib->fddiMACLost_Ct - mib->fddiMACOld_Lost_Ct) ;
318 mib->fddiMACFrameErrorRatio = div_ratio(upper,lower) ;
320 cond =
321 ((!mib->fddiMACFrameErrorThreshold &&
322 mib->fddiMACError_Ct != mib->fddiMACOld_Error_Ct) ||
323 (mib->fddiMACFrameErrorRatio >
324 mib->fddiMACFrameErrorThreshold)) ;
326 if (cond != mib->fddiMACFrameErrorFlag)
327 smt_srf_event(smc,SMT_COND_MAC_FRAME_ERROR,
328 INDEX_MAC,cond) ;
330 upper =
331 (mib->fddiMACNotCopied_Ct - mib->fddiMACOld_NotCopied_Ct) ;
332 lower =
333 upper +
334 (mib->fddiMACCopied_Ct - mib->fddiMACOld_Copied_Ct) ;
335 mib->fddiMACNotCopiedRatio = div_ratio(upper,lower) ;
337 cond =
338 ((!mib->fddiMACNotCopiedThreshold &&
339 mib->fddiMACNotCopied_Ct !=
340 mib->fddiMACOld_NotCopied_Ct)||
341 (mib->fddiMACNotCopiedRatio >
342 mib->fddiMACNotCopiedThreshold)) ;
344 if (cond != mib->fddiMACNotCopiedFlag)
345 smt_srf_event(smc,SMT_COND_MAC_NOT_COPIED,
346 INDEX_MAC,cond) ;
349 * set old values
351 mib->fddiMACOld_Frame_Ct = mib->fddiMACFrame_Ct ;
352 mib->fddiMACOld_Copied_Ct = mib->fddiMACCopied_Ct ;
353 mib->fddiMACOld_Error_Ct = mib->fddiMACError_Ct ;
354 mib->fddiMACOld_Lost_Ct = mib->fddiMACLost_Ct ;
355 mib->fddiMACOld_NotCopied_Ct = mib->fddiMACNotCopied_Ct ;
358 * Check port EBError Condition
360 for (port = 0; port < NUMPHYS; port ++) {
361 phy = &smc->y[port] ;
363 if (!phy->mib->fddiPORTHardwarePresent) {
364 continue;
367 cond = (phy->mib->fddiPORTEBError_Ct -
368 phy->mib->fddiPORTOldEBError_Ct > 5) ;
370 /* If ratio is more than 5 in 8 seconds
371 * Set the condition.
373 smt_srf_event(smc,SMT_COND_PORT_EB_ERROR,
374 (int) (INDEX_PORT+ phy->np) ,cond) ;
377 * set old values
379 phy->mib->fddiPORTOldEBError_Ct =
380 phy->mib->fddiPORTEBError_Ct ;
383 #endif /* no SLIM_SMT */
386 #ifndef SLIM_SMT
388 if (time - smc->sm.smt_last_notify >= (u_long)
389 (smc->mib.fddiSMTTT_Notify * TICKS_PER_SECOND) ) {
391 * we can either send an announcement or a request
392 * a request will trigger a reply so that we can update
393 * our dna
394 * note: same tid must be used until reply is received
396 if (!smc->sm.pend[SMT_TID_NIF])
397 smc->sm.pend[SMT_TID_NIF] = smt_get_tid(smc) ;
398 smt_send_nif(smc,&fddi_broadcast, FC_SMT_NSA,
399 smc->sm.pend[SMT_TID_NIF], SMT_REQUEST,0) ;
400 smc->sm.smt_last_notify = time ;
404 * check timer
406 if (smc->sm.smt_tvu &&
407 time - smc->sm.smt_tvu > 228*TICKS_PER_SECOND) {
408 DB_SMT("SMT : UNA expired\n",0,0) ;
409 smc->sm.smt_tvu = 0 ;
411 if (!is_equal(&smc->mib.m[MAC0].fddiMACUpstreamNbr,
412 &SMT_Unknown)){
413 /* Do not update unknown address */
414 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
415 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
417 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
418 smc->mib.m[MAC0].fddiMACUNDA_Flag = FALSE ;
420 * Make sure the fddiMACUNDA_Flag = FALSE is
421 * included in the SRF so we don't generate
422 * a separate SRF for the deassertion of this
423 * condition
425 update_dac(smc,0) ;
426 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
427 INDEX_MAC,0) ;
429 if (smc->sm.smt_tvd &&
430 time - smc->sm.smt_tvd > 228*TICKS_PER_SECOND) {
431 DB_SMT("SMT : DNA expired\n",0,0) ;
432 smc->sm.smt_tvd = 0 ;
433 if (!is_equal(&smc->mib.m[MAC0].fddiMACDownstreamNbr,
434 &SMT_Unknown)){
435 /* Do not update unknown address */
436 smc->mib.m[MAC0].fddiMACOldDownstreamNbr=
437 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
439 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
440 smt_srf_event(smc, SMT_EVENT_MAC_NEIGHBOR_CHANGE,
441 INDEX_MAC,0) ;
444 #endif /* no SLIM_SMT */
446 #ifndef SMT_REAL_TOKEN_CT
448 * Token counter emulation section. If hardware supports the token
449 * count, the token counter will be updated in mac_update_counter.
451 for (i = MAC0; i < NUMMACS; i++ ){
452 if (time - smc->sm.last_tok_time[i] > 2*TICKS_PER_SECOND ){
453 smt_emulate_token_ct( smc, i );
456 #endif
458 smt_timer_start(smc,&smc->sm.smt_timer, (u_long)1000000L,
459 EV_TOKEN(EVENT_SMT,SM_TIMER)) ;
462 static int div_ratio(u_long upper, u_long lower)
464 if ((upper<<16L) < upper)
465 upper = 0xffff0000L ;
466 else
467 upper <<= 16L ;
468 if (!lower)
469 return(0) ;
470 return((int)(upper/lower)) ;
473 #ifndef SLIM_SMT
476 * receive packet handler
478 void smt_received_pack(struct s_smc *smc, SMbuf *mb, int fs)
479 /* int fs; frame status */
481 struct smt_header *sm ;
482 int local ;
484 int illegal = 0 ;
486 switch (m_fc(mb)) {
487 case FC_SMT_INFO :
488 case FC_SMT_LAN_LOC :
489 case FC_SMT_LOC :
490 case FC_SMT_NSA :
491 break ;
492 default :
493 smt_free_mbuf(smc,mb) ;
494 return ;
497 smc->mib.m[MAC0].fddiMACSMTCopied_Ct++ ;
498 sm = smtod(mb,struct smt_header *) ;
499 local = ((fs & L_INDICATOR) != 0) ;
500 hwm_conv_can(smc,(char *)sm,12) ;
502 /* check destination address */
503 if (is_individual(&sm->smt_dest) && !is_my_addr(smc,&sm->smt_dest)) {
504 smt_free_mbuf(smc,mb) ;
505 return ;
507 #if 0 /* for DUP recognition, do NOT filter them */
508 /* ignore loop back packets */
509 if (is_my_addr(smc,&sm->smt_source) && !local) {
510 smt_free_mbuf(smc,mb) ;
511 return ;
513 #endif
515 smt_swap_para(sm,(int) mb->sm_len,1) ;
516 DB_SMT("SMT : received packet [%s] at 0x%x\n",
517 smt_type_name[m_fc(mb) & 0xf],sm) ;
518 DB_SMT("SMT : version %d, class %s\n",sm->smt_version,
519 smt_class_name[(sm->smt_class>LAST_CLASS)?0 : sm->smt_class]) ;
521 #ifdef SBA
523 * check if NSA frame
525 if (m_fc(mb) == FC_SMT_NSA && sm->smt_class == SMT_NIF &&
526 (sm->smt_type == SMT_ANNOUNCE || sm->smt_type == SMT_REQUEST)) {
527 smc->sba.sm = sm ;
528 sba(smc,NIF) ;
530 #endif
533 * ignore any packet with NSA and A-indicator set
535 if ( (fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) {
536 DB_SMT("SMT : ignoring NSA with A-indicator set from %s\n",
537 addr_to_string(&sm->smt_source),0) ;
538 smt_free_mbuf(smc,mb) ;
539 return ;
543 * ignore frames with illegal length
545 if (((sm->smt_class == SMT_ECF) && (sm->smt_len > SMT_MAX_ECHO_LEN)) ||
546 ((sm->smt_class != SMT_ECF) && (sm->smt_len > SMT_MAX_INFO_LEN))) {
547 smt_free_mbuf(smc,mb) ;
548 return ;
552 * check SMT version
554 switch (sm->smt_class) {
555 case SMT_NIF :
556 case SMT_SIF_CONFIG :
557 case SMT_SIF_OPER :
558 case SMT_ECF :
559 if (sm->smt_version != SMT_VID)
560 illegal = 1;
561 break ;
562 default :
563 if (sm->smt_version != SMT_VID_2)
564 illegal = 1;
565 break ;
567 if (illegal) {
568 DB_SMT("SMT : version = %d, dest = %s\n",
569 sm->smt_version,addr_to_string(&sm->smt_source)) ;
570 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_VERSION,local) ;
571 smt_free_mbuf(smc,mb) ;
572 return ;
574 if ((sm->smt_len > mb->sm_len - sizeof(struct smt_header)) ||
575 ((sm->smt_len & 3) && (sm->smt_class != SMT_ECF))) {
576 DB_SMT("SMT: info length error, len = %d\n",sm->smt_len,0) ;
577 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,local) ;
578 smt_free_mbuf(smc,mb) ;
579 return ;
581 switch (sm->smt_class) {
582 case SMT_NIF :
583 if (smt_check_para(smc,sm,plist_nif)) {
584 DB_SMT("SMT: NIF with para problem, ignoring\n",0,0) ;
585 break ;
587 switch (sm->smt_type) {
588 case SMT_ANNOUNCE :
589 case SMT_REQUEST :
590 if (!(fs & C_INDICATOR) && m_fc(mb) == FC_SMT_NSA
591 && is_broadcast(&sm->smt_dest)) {
592 struct smt_p_state *st ;
594 /* set my UNA */
595 if (!is_equal(
596 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
597 &sm->smt_source)) {
598 DB_SMT("SMT : updated my UNA = %s\n",
599 addr_to_string(&sm->smt_source),0) ;
600 if (!is_equal(&smc->mib.m[MAC0].
601 fddiMACUpstreamNbr,&SMT_Unknown)){
602 /* Do not update unknown address */
603 smc->mib.m[MAC0].fddiMACOldUpstreamNbr=
604 smc->mib.m[MAC0].fddiMACUpstreamNbr ;
607 smc->mib.m[MAC0].fddiMACUpstreamNbr =
608 sm->smt_source ;
609 smt_srf_event(smc,
610 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
611 INDEX_MAC,0) ;
612 smt_echo_test(smc,0) ;
614 smc->sm.smt_tvu = smt_get_time() ;
615 st = (struct smt_p_state *)
616 sm_to_para(smc,sm,SMT_P_STATE) ;
617 if (st) {
618 smc->mib.m[MAC0].fddiMACUNDA_Flag =
619 (st->st_dupl_addr & SMT_ST_MY_DUPA) ?
620 TRUE : FALSE ;
621 update_dac(smc,1) ;
624 if ((sm->smt_type == SMT_REQUEST) &&
625 is_individual(&sm->smt_source) &&
626 ((!(fs & A_INDICATOR) && m_fc(mb) == FC_SMT_NSA) ||
627 (m_fc(mb) != FC_SMT_NSA))) {
628 DB_SMT("SMT : replying to NIF request %s\n",
629 addr_to_string(&sm->smt_source),0) ;
630 smt_send_nif(smc,&sm->smt_source,
631 FC_SMT_INFO,
632 sm->smt_tid,
633 SMT_REPLY,local) ;
635 break ;
636 case SMT_REPLY :
637 DB_SMT("SMT : received NIF response from %s\n",
638 addr_to_string(&sm->smt_source),0) ;
639 if (fs & A_INDICATOR) {
640 smc->sm.pend[SMT_TID_NIF] = 0 ;
641 DB_SMT("SMT : duplicate address\n",0,0) ;
642 smc->mib.m[MAC0].fddiMACDupAddressTest =
643 DA_FAILED ;
644 smc->r.dup_addr_test = DA_FAILED ;
645 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
646 smc->mib.m[MAC0].fddiMACDA_Flag = TRUE ;
647 update_dac(smc,1) ;
648 break ;
650 if (sm->smt_tid == smc->sm.pend[SMT_TID_NIF]) {
651 smc->sm.pend[SMT_TID_NIF] = 0 ;
652 /* set my DNA */
653 if (!is_equal(
654 &smc->mib.m[MAC0].fddiMACDownstreamNbr,
655 &sm->smt_source)) {
656 DB_SMT("SMT : updated my DNA\n",0,0) ;
657 if (!is_equal(&smc->mib.m[MAC0].
658 fddiMACDownstreamNbr, &SMT_Unknown)){
659 /* Do not update unknown address */
660 smc->mib.m[MAC0].fddiMACOldDownstreamNbr =
661 smc->mib.m[MAC0].fddiMACDownstreamNbr ;
664 smc->mib.m[MAC0].fddiMACDownstreamNbr =
665 sm->smt_source ;
666 smt_srf_event(smc,
667 SMT_EVENT_MAC_NEIGHBOR_CHANGE,
668 INDEX_MAC,0) ;
669 smt_echo_test(smc,1) ;
671 smc->mib.m[MAC0].fddiMACDA_Flag = FALSE ;
672 update_dac(smc,1) ;
673 smc->sm.smt_tvd = smt_get_time() ;
674 smc->mib.m[MAC0].fddiMACDupAddressTest =
675 DA_PASSED ;
676 if (smc->r.dup_addr_test != DA_PASSED) {
677 smc->r.dup_addr_test = DA_PASSED ;
678 queue_event(smc,EVENT_RMT,RM_DUP_ADDR) ;
681 else if (sm->smt_tid ==
682 smc->sm.pend[SMT_TID_NIF_TEST]) {
683 DB_SMT("SMT : NIF test TID ok\n",0,0) ;
685 else {
686 DB_SMT("SMT : expected TID %lx, got %lx\n",
687 smc->sm.pend[SMT_TID_NIF],sm->smt_tid) ;
689 break ;
690 default :
691 illegal = 2 ;
692 break ;
694 break ;
695 case SMT_SIF_CONFIG : /* station information */
696 if (sm->smt_type != SMT_REQUEST)
697 break ;
698 DB_SMT("SMT : replying to SIF Config request from %s\n",
699 addr_to_string(&sm->smt_source),0) ;
700 smt_send_sif_config(smc,&sm->smt_source,sm->smt_tid,local) ;
701 break ;
702 case SMT_SIF_OPER : /* station information */
703 if (sm->smt_type != SMT_REQUEST)
704 break ;
705 DB_SMT("SMT : replying to SIF Operation request from %s\n",
706 addr_to_string(&sm->smt_source),0) ;
707 smt_send_sif_operation(smc,&sm->smt_source,sm->smt_tid,local) ;
708 break ;
709 case SMT_ECF : /* echo frame */
710 switch (sm->smt_type) {
711 case SMT_REPLY :
712 smc->mib.priv.fddiPRIVECF_Reply_Rx++ ;
713 DB_SMT("SMT: received ECF reply from %s\n",
714 addr_to_string(&sm->smt_source),0) ;
715 if (sm_to_para(smc,sm,SMT_P_ECHODATA) == NULL) {
716 DB_SMT("SMT: ECHODATA missing\n",0,0) ;
717 break ;
719 if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF]) {
720 DB_SMT("SMT : ECF test TID ok\n",0,0) ;
722 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_UNA]) {
723 DB_SMT("SMT : ECF test UNA ok\n",0,0) ;
725 else if (sm->smt_tid == smc->sm.pend[SMT_TID_ECF_DNA]) {
726 DB_SMT("SMT : ECF test DNA ok\n",0,0) ;
728 else {
729 DB_SMT("SMT : expected TID %lx, got %lx\n",
730 smc->sm.pend[SMT_TID_ECF],
731 sm->smt_tid) ;
733 break ;
734 case SMT_REQUEST :
735 smc->mib.priv.fddiPRIVECF_Req_Rx++ ;
737 if (sm->smt_len && !sm_to_para(smc,sm,SMT_P_ECHODATA)) {
738 DB_SMT("SMT: ECF with para problem,sending RDF\n",0,0) ;
739 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_LENGTH,
740 local) ;
741 break ;
743 DB_SMT("SMT - sending ECF reply to %s\n",
744 addr_to_string(&sm->smt_source),0) ;
746 /* set destination addr. & reply */
747 sm->smt_dest = sm->smt_source ;
748 sm->smt_type = SMT_REPLY ;
749 dump_smt(smc,sm,"ECF REPLY") ;
750 smc->mib.priv.fddiPRIVECF_Reply_Tx++ ;
751 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
752 return ; /* DON'T free mbuf */
754 default :
755 illegal = 1 ;
756 break ;
758 break ;
759 #ifndef BOOT
760 case SMT_RAF : /* resource allocation */
761 #ifdef ESS
762 DB_ESSN(2,"ESS: RAF frame received\n",0,0) ;
763 fs = ess_raf_received_pack(smc,mb,sm,fs) ;
764 #endif
766 #ifdef SBA
767 DB_SBAN(2,"SBA: RAF frame received\n",0,0) ;
768 sba_raf_received_pack(smc,sm,fs) ;
769 #endif
770 break ;
771 case SMT_RDF : /* request denied */
772 smc->mib.priv.fddiPRIVRDF_Rx++ ;
773 break ;
774 case SMT_ESF : /* extended service - not supported */
775 if (sm->smt_type == SMT_REQUEST) {
776 DB_SMT("SMT - received ESF, sending RDF\n",0,0) ;
777 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
779 break ;
780 case SMT_PMF_GET :
781 case SMT_PMF_SET :
782 if (sm->smt_type != SMT_REQUEST)
783 break ;
784 /* update statistics */
785 if (sm->smt_class == SMT_PMF_GET)
786 smc->mib.priv.fddiPRIVPMF_Get_Rx++ ;
787 else
788 smc->mib.priv.fddiPRIVPMF_Set_Rx++ ;
790 * ignore PMF SET with I/G set
792 if ((sm->smt_class == SMT_PMF_SET) &&
793 !is_individual(&sm->smt_dest)) {
794 DB_SMT("SMT: ignoring PMF-SET with I/G set\n",0,0) ;
795 break ;
797 smt_pmf_received_pack(smc,mb, local) ;
798 break ;
799 case SMT_SRF :
800 dump_smt(smc,sm,"SRF received") ;
801 break ;
802 default :
803 if (sm->smt_type != SMT_REQUEST)
804 break ;
806 * For frames with unknown class:
807 * we need to send a RDF frame according to 8.1.3.1.1,
808 * only if it is a REQUEST.
810 DB_SMT("SMT : class = %d, send RDF to %s\n",
811 sm->smt_class, addr_to_string(&sm->smt_source)) ;
813 smt_send_rdf(smc,mb,m_fc(mb),SMT_RDF_CLASS,local) ;
814 break ;
815 #endif
817 if (illegal) {
818 DB_SMT("SMT: discarding invalid frame, reason = %d\n",
819 illegal,0) ;
821 smt_free_mbuf(smc,mb) ;
824 static void update_dac(struct s_smc *smc, int report)
826 int cond ;
828 cond = ( smc->mib.m[MAC0].fddiMACUNDA_Flag |
829 smc->mib.m[MAC0].fddiMACDA_Flag) != 0 ;
830 if (report && (cond != smc->mib.m[MAC0].fddiMACDuplicateAddressCond))
831 smt_srf_event(smc, SMT_COND_MAC_DUP_ADDR,INDEX_MAC,cond) ;
832 else
833 smc->mib.m[MAC0].fddiMACDuplicateAddressCond = cond ;
837 * send SMT frame
838 * set source address
839 * set station ID
840 * send frame
842 void smt_send_frame(struct s_smc *smc, SMbuf *mb, int fc, int local)
843 /* SMbuf *mb; buffer to send */
844 /* int fc; FC value */
846 struct smt_header *sm ;
848 if (!smc->r.sm_ma_avail && !local) {
849 smt_free_mbuf(smc,mb) ;
850 return ;
852 sm = smtod(mb,struct smt_header *) ;
853 sm->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
854 sm->smt_sid = smc->mib.fddiSMTStationId ;
856 smt_swap_para(sm,(int) mb->sm_len,0) ; /* swap para & header */
857 hwm_conv_can(smc,(char *)sm,12) ; /* convert SA and DA */
858 smc->mib.m[MAC0].fddiMACSMTTransmit_Ct++ ;
859 smt_send_mbuf(smc,mb,local ? FC_SMT_LOC : fc) ;
863 * generate and send RDF
865 static void smt_send_rdf(struct s_smc *smc, SMbuf *rej, int fc, int reason,
866 int local)
867 /* SMbuf *rej; mbuf of offending frame */
868 /* int fc; FC of denied frame */
869 /* int reason; reason code */
871 SMbuf *mb ;
872 struct smt_header *sm ; /* header of offending frame */
873 struct smt_rdf *rdf ;
874 int len ;
875 int frame_len ;
877 sm = smtod(rej,struct smt_header *) ;
878 if (sm->smt_type != SMT_REQUEST)
879 return ;
881 DB_SMT("SMT: sending RDF to %s,reason = 0x%x\n",
882 addr_to_string(&sm->smt_source),reason) ;
886 * note: get framelength from MAC length, NOT from SMT header
887 * smt header length is included in sm_len
889 frame_len = rej->sm_len ;
891 if (!(mb=smt_build_frame(smc,SMT_RDF,SMT_REPLY,sizeof(struct smt_rdf))))
892 return ;
893 rdf = smtod(mb,struct smt_rdf *) ;
894 rdf->smt.smt_tid = sm->smt_tid ; /* use TID from sm */
895 rdf->smt.smt_dest = sm->smt_source ; /* set dest = source */
897 /* set P12 */
898 rdf->reason.para.p_type = SMT_P_REASON ;
899 rdf->reason.para.p_len = sizeof(struct smt_p_reason) - PARA_LEN ;
900 rdf->reason.rdf_reason = reason ;
902 /* set P14 */
903 rdf->version.para.p_type = SMT_P_VERSION ;
904 rdf->version.para.p_len = sizeof(struct smt_p_version) - PARA_LEN ;
905 rdf->version.v_pad = 0 ;
906 rdf->version.v_n = 1 ;
907 rdf->version.v_index = 1 ;
908 rdf->version.v_version[0] = SMT_VID_2 ;
909 rdf->version.v_pad2 = 0 ;
911 /* set P13 */
912 if ((unsigned) frame_len <= SMT_MAX_INFO_LEN - sizeof(*rdf) +
913 2*sizeof(struct smt_header))
914 len = frame_len ;
915 else
916 len = SMT_MAX_INFO_LEN - sizeof(*rdf) +
917 2*sizeof(struct smt_header) ;
918 /* make length multiple of 4 */
919 len &= ~3 ;
920 rdf->refused.para.p_type = SMT_P_REFUSED ;
921 /* length of para is smt_frame + ref_fc */
922 rdf->refused.para.p_len = len + 4 ;
923 rdf->refused.ref_fc = fc ;
925 /* swap it back */
926 smt_swap_para(sm,frame_len,0) ;
928 memcpy((char *) &rdf->refused.ref_header,(char *) sm,len) ;
930 len -= sizeof(struct smt_header) ;
931 mb->sm_len += len ;
932 rdf->smt.smt_len += len ;
934 dump_smt(smc,(struct smt_header *)rdf,"RDF") ;
935 smc->mib.priv.fddiPRIVRDF_Tx++ ;
936 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
940 * generate and send NIF
942 static void smt_send_nif(struct s_smc *smc, const struct fddi_addr *dest,
943 int fc, u_long tid, int type, int local)
944 /* struct fddi_addr *dest; dest address */
945 /* int fc; frame control */
946 /* u_long tid; transaction id */
947 /* int type; frame type */
949 struct smt_nif *nif ;
950 SMbuf *mb ;
952 if (!(mb = smt_build_frame(smc,SMT_NIF,type,sizeof(struct smt_nif))))
953 return ;
954 nif = smtod(mb, struct smt_nif *) ;
955 smt_fill_una(smc,&nif->una) ; /* set UNA */
956 smt_fill_sde(smc,&nif->sde) ; /* set station descriptor */
957 smt_fill_state(smc,&nif->state) ; /* set state information */
958 #ifdef SMT6_10
959 smt_fill_fsc(smc,&nif->fsc) ; /* set frame status cap. */
960 #endif
961 nif->smt.smt_dest = *dest ; /* destination address */
962 nif->smt.smt_tid = tid ; /* transaction ID */
963 dump_smt(smc,(struct smt_header *)nif,"NIF") ;
964 smt_send_frame(smc,mb,fc,local) ;
967 #ifdef DEBUG
969 * send NIF request (test purpose)
971 static void smt_send_nif_request(struct s_smc *smc, struct fddi_addr *dest)
973 smc->sm.pend[SMT_TID_NIF_TEST] = smt_get_tid(smc) ;
974 smt_send_nif(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_NIF_TEST],
975 SMT_REQUEST,0) ;
979 * send ECF request (test purpose)
981 static void smt_send_ecf_request(struct s_smc *smc, struct fddi_addr *dest,
982 int len)
984 smc->sm.pend[SMT_TID_ECF] = smt_get_tid(smc) ;
985 smt_send_ecf(smc,dest, FC_SMT_INFO, smc->sm.pend[SMT_TID_ECF],
986 SMT_REQUEST,len) ;
988 #endif
991 * echo test
993 static void smt_echo_test(struct s_smc *smc, int dna)
995 u_long tid ;
997 smc->sm.pend[dna ? SMT_TID_ECF_DNA : SMT_TID_ECF_UNA] =
998 tid = smt_get_tid(smc) ;
999 smt_send_ecf(smc, dna ?
1000 &smc->mib.m[MAC0].fddiMACDownstreamNbr :
1001 &smc->mib.m[MAC0].fddiMACUpstreamNbr,
1002 FC_SMT_INFO,tid, SMT_REQUEST, (SMT_TEST_ECHO_LEN & ~3)-8) ;
1006 * generate and send ECF
1008 static void smt_send_ecf(struct s_smc *smc, struct fddi_addr *dest, int fc,
1009 u_long tid, int type, int len)
1010 /* struct fddi_addr *dest; dest address */
1011 /* int fc; frame control */
1012 /* u_long tid; transaction id */
1013 /* int type; frame type */
1014 /* int len; frame length */
1016 struct smt_ecf *ecf ;
1017 SMbuf *mb ;
1019 if (!(mb = smt_build_frame(smc,SMT_ECF,type,SMT_ECF_LEN + len)))
1020 return ;
1021 ecf = smtod(mb, struct smt_ecf *) ;
1023 smt_fill_echo(smc,&ecf->ec_echo,tid,len) ; /* set ECHO */
1024 ecf->smt.smt_dest = *dest ; /* destination address */
1025 ecf->smt.smt_tid = tid ; /* transaction ID */
1026 smc->mib.priv.fddiPRIVECF_Req_Tx++ ;
1027 smt_send_frame(smc,mb,fc,0) ;
1031 * generate and send SIF config response
1034 static void smt_send_sif_config(struct s_smc *smc, struct fddi_addr *dest,
1035 u_long tid, int local)
1036 /* struct fddi_addr *dest; dest address */
1037 /* u_long tid; transaction id */
1039 struct smt_sif_config *sif ;
1040 SMbuf *mb ;
1041 int len ;
1042 if (!(mb = smt_build_frame(smc,SMT_SIF_CONFIG,SMT_REPLY,
1043 SIZEOF_SMT_SIF_CONFIG)))
1044 return ;
1046 sif = smtod(mb, struct smt_sif_config *) ;
1047 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1048 smt_fill_sde(smc,&sif->sde) ; /* set station descriptor */
1049 smt_fill_version(smc,&sif->version) ; /* set version information */
1050 smt_fill_state(smc,&sif->state) ; /* set state information */
1051 smt_fill_policy(smc,&sif->policy) ; /* set station policy */
1052 smt_fill_latency(smc,&sif->latency); /* set station latency */
1053 smt_fill_neighbor(smc,&sif->neighbor); /* set station neighbor */
1054 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1055 len = smt_fill_path(smc,&sif->path); /* set station path descriptor*/
1056 sif->smt.smt_dest = *dest ; /* destination address */
1057 sif->smt.smt_tid = tid ; /* transaction ID */
1058 smt_add_frame_len(mb,len) ; /* adjust length fields */
1059 dump_smt(smc,(struct smt_header *)sif,"SIF Configuration Reply") ;
1060 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1064 * generate and send SIF operation response
1067 static void smt_send_sif_operation(struct s_smc *smc, struct fddi_addr *dest,
1068 u_long tid, int local)
1069 /* struct fddi_addr *dest; dest address */
1070 /* u_long tid; transaction id */
1072 struct smt_sif_operation *sif ;
1073 SMbuf *mb ;
1074 int ports ;
1075 int i ;
1077 ports = NUMPHYS ;
1078 #ifndef CONCENTRATOR
1079 if (smc->s.sas == SMT_SAS)
1080 ports = 1 ;
1081 #endif
1083 if (!(mb = smt_build_frame(smc,SMT_SIF_OPER,SMT_REPLY,
1084 SIZEOF_SMT_SIF_OPERATION+ports*sizeof(struct smt_p_lem))))
1085 return ;
1086 sif = smtod(mb, struct smt_sif_operation *) ;
1087 smt_fill_timestamp(smc,&sif->ts) ; /* set time stamp */
1088 smt_fill_mac_status(smc,&sif->status) ; /* set mac status */
1089 smt_fill_mac_counter(smc,&sif->mc) ; /* set mac counter field */
1090 smt_fill_mac_fnc(smc,&sif->fnc) ; /* set frame not copied counter */
1091 smt_fill_manufacturer(smc,&sif->man) ; /* set manufacturer field */
1092 smt_fill_user(smc,&sif->user) ; /* set user field */
1093 smt_fill_setcount(smc,&sif->setcount) ; /* set count */
1095 * set link error mon information
1097 if (ports == 1) {
1098 smt_fill_lem(smc,sif->lem,PS) ;
1100 else {
1101 for (i = 0 ; i < ports ; i++) {
1102 smt_fill_lem(smc,&sif->lem[i],i) ;
1106 sif->smt.smt_dest = *dest ; /* destination address */
1107 sif->smt.smt_tid = tid ; /* transaction ID */
1108 dump_smt(smc,(struct smt_header *)sif,"SIF Operation Reply") ;
1109 smt_send_frame(smc,mb,FC_SMT_INFO,local) ;
1113 * get and initialize SMT frame
1115 SMbuf *smt_build_frame(struct s_smc *smc, int class, int type,
1116 int length)
1118 SMbuf *mb ;
1119 struct smt_header *smt ;
1121 #if 0
1122 if (!smc->r.sm_ma_avail) {
1123 return(0) ;
1125 #endif
1126 if (!(mb = smt_get_mbuf(smc)))
1127 return(mb) ;
1129 mb->sm_len = length ;
1130 smt = smtod(mb, struct smt_header *) ;
1131 smt->smt_dest = fddi_broadcast ; /* set dest = broadcast */
1132 smt->smt_class = class ;
1133 smt->smt_type = type ;
1134 switch (class) {
1135 case SMT_NIF :
1136 case SMT_SIF_CONFIG :
1137 case SMT_SIF_OPER :
1138 case SMT_ECF :
1139 smt->smt_version = SMT_VID ;
1140 break ;
1141 default :
1142 smt->smt_version = SMT_VID_2 ;
1143 break ;
1145 smt->smt_tid = smt_get_tid(smc) ; /* set transaction ID */
1146 smt->smt_pad = 0 ;
1147 smt->smt_len = length - sizeof(struct smt_header) ;
1148 return(mb) ;
1151 static void smt_add_frame_len(SMbuf *mb, int len)
1153 struct smt_header *smt ;
1155 smt = smtod(mb, struct smt_header *) ;
1156 smt->smt_len += len ;
1157 mb->sm_len += len ;
1163 * fill values in UNA parameter
1165 static void smt_fill_una(struct s_smc *smc, struct smt_p_una *una)
1167 SMTSETPARA(una,SMT_P_UNA) ;
1168 una->una_pad = 0 ;
1169 una->una_node = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1173 * fill values in SDE parameter
1175 static void smt_fill_sde(struct s_smc *smc, struct smt_p_sde *sde)
1177 SMTSETPARA(sde,SMT_P_SDE) ;
1178 sde->sde_non_master = smc->mib.fddiSMTNonMaster_Ct ;
1179 sde->sde_master = smc->mib.fddiSMTMaster_Ct ;
1180 sde->sde_mac_count = NUMMACS ; /* only 1 MAC */
1181 #ifdef CONCENTRATOR
1182 sde->sde_type = SMT_SDE_CONCENTRATOR ;
1183 #else
1184 sde->sde_type = SMT_SDE_STATION ;
1185 #endif
1189 * fill in values in station state parameter
1191 static void smt_fill_state(struct s_smc *smc, struct smt_p_state *state)
1193 int top ;
1194 int twist ;
1196 SMTSETPARA(state,SMT_P_STATE) ;
1197 state->st_pad = 0 ;
1199 /* determine topology */
1200 top = 0 ;
1201 if (smc->mib.fddiSMTPeerWrapFlag) {
1202 top |= SMT_ST_WRAPPED ; /* state wrapped */
1204 #ifdef CONCENTRATOR
1205 if (cfm_status_unattached(smc)) {
1206 top |= SMT_ST_UNATTACHED ; /* unattached concentrator */
1208 #endif
1209 if ((twist = pcm_status_twisted(smc)) & 1) {
1210 top |= SMT_ST_TWISTED_A ; /* twisted cable */
1212 if (twist & 2) {
1213 top |= SMT_ST_TWISTED_B ; /* twisted cable */
1215 #ifdef OPT_SRF
1216 top |= SMT_ST_SRF ;
1217 #endif
1218 if (pcm_rooted_station(smc))
1219 top |= SMT_ST_ROOTED_S ;
1220 if (smc->mib.a[0].fddiPATHSbaPayload != 0)
1221 top |= SMT_ST_SYNC_SERVICE ;
1222 state->st_topology = top ;
1223 state->st_dupl_addr =
1224 ((smc->mib.m[MAC0].fddiMACDA_Flag ? SMT_ST_MY_DUPA : 0 ) |
1225 (smc->mib.m[MAC0].fddiMACUNDA_Flag ? SMT_ST_UNA_DUPA : 0)) ;
1229 * fill values in timestamp parameter
1231 static void smt_fill_timestamp(struct s_smc *smc, struct smt_p_timestamp *ts)
1234 SMTSETPARA(ts,SMT_P_TIMESTAMP) ;
1235 smt_set_timestamp(smc,ts->ts_time) ;
1238 void smt_set_timestamp(struct s_smc *smc, u_char *p)
1240 u_long time ;
1241 u_long utime ;
1244 * timestamp is 64 bits long ; resolution is 80 nS
1245 * our clock resolution is 10mS
1246 * 10mS/80ns = 125000 ~ 2^17 = 131072
1248 utime = smt_get_time() ;
1249 time = utime * 100 ;
1250 time /= TICKS_PER_SECOND ;
1251 p[0] = 0 ;
1252 p[1] = (u_char)((time>>(8+8+8+8-1)) & 1) ;
1253 p[2] = (u_char)(time>>(8+8+8-1)) ;
1254 p[3] = (u_char)(time>>(8+8-1)) ;
1255 p[4] = (u_char)(time>>(8-1)) ;
1256 p[5] = (u_char)(time<<1) ;
1257 p[6] = (u_char)(smc->sm.uniq_ticks>>8) ;
1258 p[7] = (u_char)smc->sm.uniq_ticks ;
1260 * make sure we don't wrap: restart whenever the upper digits change
1262 if (utime != smc->sm.uniq_time) {
1263 smc->sm.uniq_ticks = 0 ;
1265 smc->sm.uniq_ticks++ ;
1266 smc->sm.uniq_time = utime ;
1270 * fill values in station policy parameter
1272 static void smt_fill_policy(struct s_smc *smc, struct smt_p_policy *policy)
1274 int i ;
1275 u_char *map ;
1276 u_short in ;
1277 u_short out ;
1280 * MIB para 101b (fddiSMTConnectionPolicy) coding
1281 * is different from 0005 coding
1283 static u_char ansi_weirdness[16] = {
1284 0,7,5,3,8,1,6,4,9,10,2,11,12,13,14,15
1286 SMTSETPARA(policy,SMT_P_POLICY) ;
1288 out = 0 ;
1289 in = smc->mib.fddiSMTConnectionPolicy ;
1290 for (i = 0, map = ansi_weirdness ; i < 16 ; i++) {
1291 if (in & 1)
1292 out |= (1<<*map) ;
1293 in >>= 1 ;
1294 map++ ;
1296 policy->pl_config = smc->mib.fddiSMTConfigPolicy ;
1297 policy->pl_connect = out ;
1301 * fill values in latency equivalent parameter
1303 static void smt_fill_latency(struct s_smc *smc, struct smt_p_latency *latency)
1305 SMTSETPARA(latency,SMT_P_LATENCY) ;
1307 latency->lt_phyout_idx1 = phy_index(smc,0) ;
1308 latency->lt_latency1 = 10 ; /* in octets (byte clock) */
1310 * note: latency has two phy entries by definition
1311 * for a SAS, the 2nd one is null
1313 if (smc->s.sas == SMT_DAS) {
1314 latency->lt_phyout_idx2 = phy_index(smc,1) ;
1315 latency->lt_latency2 = 10 ; /* in octets (byte clock) */
1317 else {
1318 latency->lt_phyout_idx2 = 0 ;
1319 latency->lt_latency2 = 0 ;
1324 * fill values in MAC neighbors parameter
1326 static void smt_fill_neighbor(struct s_smc *smc, struct smt_p_neighbor *neighbor)
1328 SMTSETPARA(neighbor,SMT_P_NEIGHBORS) ;
1330 neighbor->nb_mib_index = INDEX_MAC ;
1331 neighbor->nb_mac_index = mac_index(smc,1) ;
1332 neighbor->nb_una = smc->mib.m[MAC0].fddiMACUpstreamNbr ;
1333 neighbor->nb_dna = smc->mib.m[MAC0].fddiMACDownstreamNbr ;
1337 * fill values in path descriptor
1339 #ifdef CONCENTRATOR
1340 #define ALLPHYS NUMPHYS
1341 #else
1342 #define ALLPHYS ((smc->s.sas == SMT_SAS) ? 1 : 2)
1343 #endif
1345 static int smt_fill_path(struct s_smc *smc, struct smt_p_path *path)
1347 SK_LOC_DECL(int,type) ;
1348 SK_LOC_DECL(int,state) ;
1349 SK_LOC_DECL(int,remote) ;
1350 SK_LOC_DECL(int,mac) ;
1351 int len ;
1352 int p ;
1353 int physp ;
1354 struct smt_phy_rec *phy ;
1355 struct smt_mac_rec *pd_mac ;
1357 len = PARA_LEN +
1358 sizeof(struct smt_mac_rec) * NUMMACS +
1359 sizeof(struct smt_phy_rec) * ALLPHYS ;
1360 path->para.p_type = SMT_P_PATH ;
1361 path->para.p_len = len - PARA_LEN ;
1363 /* PHYs */
1364 for (p = 0,phy = path->pd_phy ; p < ALLPHYS ; p++, phy++) {
1365 physp = p ;
1366 #ifndef CONCENTRATOR
1367 if (smc->s.sas == SMT_SAS)
1368 physp = PS ;
1369 #endif
1370 pcm_status_state(smc,physp,&type,&state,&remote,&mac) ;
1371 #ifdef LITTLE_ENDIAN
1372 phy->phy_mib_index = smt_swap_short((u_short)p+INDEX_PORT) ;
1373 #else
1374 phy->phy_mib_index = p+INDEX_PORT ;
1375 #endif
1376 phy->phy_type = type ;
1377 phy->phy_connect_state = state ;
1378 phy->phy_remote_type = remote ;
1379 phy->phy_remote_mac = mac ;
1380 phy->phy_resource_idx = phy_con_resource_index(smc,p) ;
1383 /* MAC */
1384 pd_mac = (struct smt_mac_rec *) phy ;
1385 pd_mac->mac_addr = smc->mib.m[MAC0].fddiMACSMTAddress ;
1386 pd_mac->mac_resource_idx = mac_con_resource_index(smc,1) ;
1387 return(len) ;
1391 * fill values in mac status
1393 static void smt_fill_mac_status(struct s_smc *smc, struct smt_p_mac_status *st)
1395 SMTSETPARA(st,SMT_P_MAC_STATUS) ;
1397 st->st_mib_index = INDEX_MAC ;
1398 st->st_mac_index = mac_index(smc,1) ;
1400 mac_update_counter(smc) ;
1402 * timer values are represented in SMT as 2's complement numbers
1403 * units : internal : 2's complement BCLK
1405 st->st_t_req = smc->mib.m[MAC0].fddiMACT_Req ;
1406 st->st_t_neg = smc->mib.m[MAC0].fddiMACT_Neg ;
1407 st->st_t_max = smc->mib.m[MAC0].fddiMACT_Max ;
1408 st->st_tvx_value = smc->mib.m[MAC0].fddiMACTvxValue ;
1409 st->st_t_min = smc->mib.m[MAC0].fddiMACT_Min ;
1411 st->st_sba = smc->mib.a[PATH0].fddiPATHSbaPayload ;
1412 st->st_frame_ct = smc->mib.m[MAC0].fddiMACFrame_Ct ;
1413 st->st_error_ct = smc->mib.m[MAC0].fddiMACError_Ct ;
1414 st->st_lost_ct = smc->mib.m[MAC0].fddiMACLost_Ct ;
1418 * fill values in LEM status
1420 static void smt_fill_lem(struct s_smc *smc, struct smt_p_lem *lem, int phy)
1422 struct fddi_mib_p *mib ;
1424 mib = smc->y[phy].mib ;
1426 SMTSETPARA(lem,SMT_P_LEM) ;
1427 lem->lem_mib_index = phy+INDEX_PORT ;
1428 lem->lem_phy_index = phy_index(smc,phy) ;
1429 lem->lem_pad2 = 0 ;
1430 lem->lem_cutoff = mib->fddiPORTLer_Cutoff ;
1431 lem->lem_alarm = mib->fddiPORTLer_Alarm ;
1432 /* long term bit error rate */
1433 lem->lem_estimate = mib->fddiPORTLer_Estimate ;
1434 /* # of rejected connections */
1435 lem->lem_reject_ct = mib->fddiPORTLem_Reject_Ct ;
1436 lem->lem_ct = mib->fddiPORTLem_Ct ; /* total number of errors */
1440 * fill version parameter
1442 static void smt_fill_version(struct s_smc *smc, struct smt_p_version *vers)
1444 SK_UNUSED(smc) ;
1445 SMTSETPARA(vers,SMT_P_VERSION) ;
1446 vers->v_pad = 0 ;
1447 vers->v_n = 1 ; /* one version is enough .. */
1448 vers->v_index = 1 ;
1449 vers->v_version[0] = SMT_VID_2 ;
1450 vers->v_pad2 = 0 ;
1453 #ifdef SMT6_10
1455 * fill frame status capabilities
1458 * note: this para 200B is NOT in swap table, because it's also set in
1459 * PMF add_para
1461 static void smt_fill_fsc(struct s_smc *smc, struct smt_p_fsc *fsc)
1463 SK_UNUSED(smc) ;
1464 SMTSETPARA(fsc,SMT_P_FSC) ;
1465 fsc->fsc_pad0 = 0 ;
1466 fsc->fsc_mac_index = INDEX_MAC ; /* this is MIB ; MIB is NOT
1467 * mac_index ()i !
1469 fsc->fsc_pad1 = 0 ;
1470 fsc->fsc_value = FSC_TYPE0 ; /* "normal" node */
1471 #ifdef LITTLE_ENDIAN
1472 fsc->fsc_mac_index = smt_swap_short(INDEX_MAC) ;
1473 fsc->fsc_value = smt_swap_short(FSC_TYPE0) ;
1474 #endif
1476 #endif
1479 * fill mac counter field
1481 static void smt_fill_mac_counter(struct s_smc *smc, struct smt_p_mac_counter *mc)
1483 SMTSETPARA(mc,SMT_P_MAC_COUNTER) ;
1484 mc->mc_mib_index = INDEX_MAC ;
1485 mc->mc_index = mac_index(smc,1) ;
1486 mc->mc_receive_ct = smc->mib.m[MAC0].fddiMACCopied_Ct ;
1487 mc->mc_transmit_ct = smc->mib.m[MAC0].fddiMACTransmit_Ct ;
1491 * fill mac frame not copied counter
1493 static void smt_fill_mac_fnc(struct s_smc *smc, struct smt_p_mac_fnc *fnc)
1495 SMTSETPARA(fnc,SMT_P_MAC_FNC) ;
1496 fnc->nc_mib_index = INDEX_MAC ;
1497 fnc->nc_index = mac_index(smc,1) ;
1498 fnc->nc_counter = smc->mib.m[MAC0].fddiMACNotCopied_Ct ;
1503 * fill manufacturer field
1505 static void smt_fill_manufacturer(struct s_smc *smc,
1506 struct smp_p_manufacturer *man)
1508 SMTSETPARA(man,SMT_P_MANUFACTURER) ;
1509 memcpy((char *) man->mf_data,
1510 (char *) smc->mib.fddiSMTManufacturerData,
1511 sizeof(man->mf_data)) ;
1515 * fill user field
1517 static void smt_fill_user(struct s_smc *smc, struct smp_p_user *user)
1519 SMTSETPARA(user,SMT_P_USER) ;
1520 memcpy((char *) user->us_data,
1521 (char *) smc->mib.fddiSMTUserData,
1522 sizeof(user->us_data)) ;
1526 * fill set count
1528 static void smt_fill_setcount(struct s_smc *smc, struct smt_p_setcount *setcount)
1530 SK_UNUSED(smc) ;
1531 SMTSETPARA(setcount,SMT_P_SETCOUNT) ;
1532 setcount->count = smc->mib.fddiSMTSetCount.count ;
1533 memcpy((char *)setcount->timestamp,
1534 (char *)smc->mib.fddiSMTSetCount.timestamp,8) ;
1538 * fill echo data
1540 static void smt_fill_echo(struct s_smc *smc, struct smt_p_echo *echo, u_long seed,
1541 int len)
1543 u_char *p ;
1545 SK_UNUSED(smc) ;
1546 SMTSETPARA(echo,SMT_P_ECHODATA) ;
1547 echo->para.p_len = len ;
1548 for (p = echo->ec_data ; len ; len--) {
1549 *p++ = (u_char) seed ;
1550 seed += 13 ;
1555 * clear DNA and UNA
1556 * called from CFM if configuration changes
1558 static void smt_clear_una_dna(struct s_smc *smc)
1560 smc->mib.m[MAC0].fddiMACUpstreamNbr = SMT_Unknown ;
1561 smc->mib.m[MAC0].fddiMACDownstreamNbr = SMT_Unknown ;
1564 static void smt_clear_old_una_dna(struct s_smc *smc)
1566 smc->mib.m[MAC0].fddiMACOldUpstreamNbr = SMT_Unknown ;
1567 smc->mib.m[MAC0].fddiMACOldDownstreamNbr = SMT_Unknown ;
1570 u_long smt_get_tid(struct s_smc *smc)
1572 u_long tid ;
1573 while ((tid = ++(smc->sm.smt_tid) ^ SMT_TID_MAGIC) == 0)
1575 return(tid & 0x3fffffffL) ;
1580 * table of parameter lengths
1582 static const struct smt_pdef {
1583 int ptype ;
1584 int plen ;
1585 const char *pswap ;
1586 } smt_pdef[] = {
1587 { SMT_P_UNA, sizeof(struct smt_p_una) ,
1588 SWAP_SMT_P_UNA } ,
1589 { SMT_P_SDE, sizeof(struct smt_p_sde) ,
1590 SWAP_SMT_P_SDE } ,
1591 { SMT_P_STATE, sizeof(struct smt_p_state) ,
1592 SWAP_SMT_P_STATE } ,
1593 { SMT_P_TIMESTAMP,sizeof(struct smt_p_timestamp) ,
1594 SWAP_SMT_P_TIMESTAMP } ,
1595 { SMT_P_POLICY, sizeof(struct smt_p_policy) ,
1596 SWAP_SMT_P_POLICY } ,
1597 { SMT_P_LATENCY, sizeof(struct smt_p_latency) ,
1598 SWAP_SMT_P_LATENCY } ,
1599 { SMT_P_NEIGHBORS,sizeof(struct smt_p_neighbor) ,
1600 SWAP_SMT_P_NEIGHBORS } ,
1601 { SMT_P_PATH, sizeof(struct smt_p_path) ,
1602 SWAP_SMT_P_PATH } ,
1603 { SMT_P_MAC_STATUS,sizeof(struct smt_p_mac_status) ,
1604 SWAP_SMT_P_MAC_STATUS } ,
1605 { SMT_P_LEM, sizeof(struct smt_p_lem) ,
1606 SWAP_SMT_P_LEM } ,
1607 { SMT_P_MAC_COUNTER,sizeof(struct smt_p_mac_counter) ,
1608 SWAP_SMT_P_MAC_COUNTER } ,
1609 { SMT_P_MAC_FNC,sizeof(struct smt_p_mac_fnc) ,
1610 SWAP_SMT_P_MAC_FNC } ,
1611 { SMT_P_PRIORITY,sizeof(struct smt_p_priority) ,
1612 SWAP_SMT_P_PRIORITY } ,
1613 { SMT_P_EB,sizeof(struct smt_p_eb) ,
1614 SWAP_SMT_P_EB } ,
1615 { SMT_P_MANUFACTURER,sizeof(struct smp_p_manufacturer) ,
1616 SWAP_SMT_P_MANUFACTURER } ,
1617 { SMT_P_REASON, sizeof(struct smt_p_reason) ,
1618 SWAP_SMT_P_REASON } ,
1619 { SMT_P_REFUSED, sizeof(struct smt_p_refused) ,
1620 SWAP_SMT_P_REFUSED } ,
1621 { SMT_P_VERSION, sizeof(struct smt_p_version) ,
1622 SWAP_SMT_P_VERSION } ,
1623 #ifdef ESS
1624 { SMT_P0015, sizeof(struct smt_p_0015) , SWAP_SMT_P0015 } ,
1625 { SMT_P0016, sizeof(struct smt_p_0016) , SWAP_SMT_P0016 } ,
1626 { SMT_P0017, sizeof(struct smt_p_0017) , SWAP_SMT_P0017 } ,
1627 { SMT_P0018, sizeof(struct smt_p_0018) , SWAP_SMT_P0018 } ,
1628 { SMT_P0019, sizeof(struct smt_p_0019) , SWAP_SMT_P0019 } ,
1629 { SMT_P001A, sizeof(struct smt_p_001a) , SWAP_SMT_P001A } ,
1630 { SMT_P001B, sizeof(struct smt_p_001b) , SWAP_SMT_P001B } ,
1631 { SMT_P001C, sizeof(struct smt_p_001c) , SWAP_SMT_P001C } ,
1632 { SMT_P001D, sizeof(struct smt_p_001d) , SWAP_SMT_P001D } ,
1633 #endif
1634 #if 0
1635 { SMT_P_FSC, sizeof(struct smt_p_fsc) ,
1636 SWAP_SMT_P_FSC } ,
1637 #endif
1639 { SMT_P_SETCOUNT,0, SWAP_SMT_P_SETCOUNT } ,
1640 { SMT_P1048, 0, SWAP_SMT_P1048 } ,
1641 { SMT_P208C, 0, SWAP_SMT_P208C } ,
1642 { SMT_P208D, 0, SWAP_SMT_P208D } ,
1643 { SMT_P208E, 0, SWAP_SMT_P208E } ,
1644 { SMT_P208F, 0, SWAP_SMT_P208F } ,
1645 { SMT_P2090, 0, SWAP_SMT_P2090 } ,
1646 #ifdef ESS
1647 { SMT_P320B, sizeof(struct smt_p_320b) , SWAP_SMT_P320B } ,
1648 { SMT_P320F, sizeof(struct smt_p_320f) , SWAP_SMT_P320F } ,
1649 { SMT_P3210, sizeof(struct smt_p_3210) , SWAP_SMT_P3210 } ,
1650 #endif
1651 { SMT_P4050, 0, SWAP_SMT_P4050 } ,
1652 { SMT_P4051, 0, SWAP_SMT_P4051 } ,
1653 { SMT_P4052, 0, SWAP_SMT_P4052 } ,
1654 { SMT_P4053, 0, SWAP_SMT_P4053 } ,
1657 #define N_SMT_PLEN ARRAY_SIZE(smt_pdef)
1659 int smt_check_para(struct s_smc *smc, struct smt_header *sm,
1660 const u_short list[])
1662 const u_short *p = list ;
1663 while (*p) {
1664 if (!sm_to_para(smc,sm,(int) *p)) {
1665 DB_SMT("SMT: smt_check_para - missing para %x\n",*p,0);
1666 return(-1) ;
1668 p++ ;
1670 return(0) ;
1673 void *sm_to_para(struct s_smc *smc, struct smt_header *sm, int para)
1675 char *p ;
1676 int len ;
1677 int plen ;
1678 void *found = NULL;
1680 SK_UNUSED(smc) ;
1682 len = sm->smt_len ;
1683 p = (char *)(sm+1) ; /* pointer to info */
1684 while (len > 0 ) {
1685 if (((struct smt_para *)p)->p_type == para)
1686 found = (void *) p ;
1687 plen = ((struct smt_para *)p)->p_len + PARA_LEN ;
1688 p += plen ;
1689 len -= plen ;
1690 if (len < 0) {
1691 DB_SMT("SMT : sm_to_para - length error %d\n",plen,0) ;
1692 return NULL;
1694 if ((plen & 3) && (para != SMT_P_ECHODATA)) {
1695 DB_SMT("SMT : sm_to_para - odd length %d\n",plen,0) ;
1696 return NULL;
1698 if (found)
1699 return(found) ;
1701 return NULL;
1704 #if 0
1706 * send ANTC data test frame
1708 void fddi_send_antc(struct s_smc *smc, struct fddi_addr *dest)
1710 SK_UNUSED(smc) ;
1711 SK_UNUSED(dest) ;
1712 #if 0
1713 SMbuf *mb ;
1714 struct smt_header *smt ;
1715 int i ;
1716 char *p ;
1718 mb = smt_get_mbuf() ;
1719 mb->sm_len = 3000+12 ;
1720 p = smtod(mb, char *) + 12 ;
1721 for (i = 0 ; i < 3000 ; i++)
1722 *p++ = 1 << (i&7) ;
1724 smt = smtod(mb, struct smt_header *) ;
1725 smt->smt_dest = *dest ;
1726 smt->smt_source = smc->mib.m[MAC0].fddiMACSMTAddress ;
1727 smt_send_mbuf(smc,mb,FC_ASYNC_LLC) ;
1728 #endif
1730 #endif
1732 #ifdef DEBUG
1733 #define hextoasc(x) "0123456789abcdef"[x]
1735 char *addr_to_string(struct fddi_addr *addr)
1737 int i ;
1738 static char string[6*3] = "****" ;
1740 for (i = 0 ; i < 6 ; i++) {
1741 string[i*3] = hextoasc((addr->a[i]>>4)&0xf) ;
1742 string[i*3+1] = hextoasc((addr->a[i])&0xf) ;
1743 string[i*3+2] = ':' ;
1745 string[5*3+2] = 0 ;
1746 return(string) ;
1748 #endif
1750 #ifdef AM29K
1751 int smt_ifconfig(int argc, char *argv[])
1753 if (argc >= 2 && !strcmp(argv[0],"opt_bypass") &&
1754 !strcmp(argv[1],"yes")) {
1755 smc->mib.fddiSMTBypassPresent = 1 ;
1756 return(0) ;
1758 return(amdfddi_config(0,argc,argv)) ;
1760 #endif
1763 * return static mac index
1765 static int mac_index(struct s_smc *smc, int mac)
1767 SK_UNUSED(mac) ;
1768 #ifdef CONCENTRATOR
1769 SK_UNUSED(smc) ;
1770 return(NUMPHYS+1) ;
1771 #else
1772 return((smc->s.sas == SMT_SAS) ? 2 : 3) ;
1773 #endif
1777 * return static phy index
1779 static int phy_index(struct s_smc *smc, int phy)
1781 SK_UNUSED(smc) ;
1782 return(phy+1);
1786 * return dynamic mac connection resource index
1788 static int mac_con_resource_index(struct s_smc *smc, int mac)
1790 #ifdef CONCENTRATOR
1791 SK_UNUSED(smc) ;
1792 SK_UNUSED(mac) ;
1793 return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_MAC))) ;
1794 #else
1795 SK_UNUSED(mac) ;
1796 switch (smc->mib.fddiSMTCF_State) {
1797 case SC9_C_WRAP_A :
1798 case SC5_THRU_B :
1799 case SC11_C_WRAP_S :
1800 return(1) ;
1801 case SC10_C_WRAP_B :
1802 case SC4_THRU_A :
1803 return(2) ;
1805 return(smc->s.sas == SMT_SAS ? 2 : 3) ;
1806 #endif
1810 * return dynamic phy connection resource index
1812 static int phy_con_resource_index(struct s_smc *smc, int phy)
1814 #ifdef CONCENTRATOR
1815 return(entity_to_index(smc,cem_get_downstream(smc,ENTITY_PHY(phy)))) ;
1816 #else
1817 switch (smc->mib.fddiSMTCF_State) {
1818 case SC9_C_WRAP_A :
1819 return(phy == PA ? 3 : 2) ;
1820 case SC10_C_WRAP_B :
1821 return(phy == PA ? 1 : 3) ;
1822 case SC4_THRU_A :
1823 return(phy == PA ? 3 : 1) ;
1824 case SC5_THRU_B :
1825 return(phy == PA ? 2 : 3) ;
1826 case SC11_C_WRAP_S :
1827 return(2) ;
1829 return(phy) ;
1830 #endif
1833 #ifdef CONCENTRATOR
1834 static int entity_to_index(struct s_smc *smc, int e)
1836 if (e == ENTITY_MAC)
1837 return(mac_index(smc,1)) ;
1838 else
1839 return(phy_index(smc,e - ENTITY_PHY(0))) ;
1841 #endif
1843 #ifdef LITTLE_ENDIAN
1844 static int smt_swap_short(u_short s)
1846 return(((s>>8)&0xff)|((s&0xff)<<8)) ;
1849 void smt_swap_para(struct smt_header *sm, int len, int direction)
1850 /* int direction; 0 encode 1 decode */
1852 struct smt_para *pa ;
1853 const struct smt_pdef *pd ;
1854 char *p ;
1855 int plen ;
1856 int type ;
1857 int i ;
1859 /* printf("smt_swap_para sm %x len %d dir %d\n",
1860 sm,len,direction) ;
1862 smt_string_swap((char *)sm,SWAP_SMTHEADER,len) ;
1864 /* swap args */
1865 len -= sizeof(struct smt_header) ;
1867 p = (char *) (sm + 1) ;
1868 while (len > 0) {
1869 pa = (struct smt_para *) p ;
1870 plen = pa->p_len ;
1871 type = pa->p_type ;
1872 pa->p_type = smt_swap_short(pa->p_type) ;
1873 pa->p_len = smt_swap_short(pa->p_len) ;
1874 if (direction) {
1875 plen = pa->p_len ;
1876 type = pa->p_type ;
1879 * note: paras can have 0 length !
1881 if (plen < 0)
1882 break ;
1883 plen += PARA_LEN ;
1884 for (i = N_SMT_PLEN, pd = smt_pdef; i ; i--,pd++) {
1885 if (pd->ptype == type)
1886 break ;
1888 if (i && pd->pswap) {
1889 smt_string_swap(p+PARA_LEN,pd->pswap,len) ;
1891 len -= plen ;
1892 p += plen ;
1896 static void smt_string_swap(char *data, const char *format, int len)
1898 const char *open_paren = NULL ;
1899 int x ;
1901 while (len > 0 && *format) {
1902 switch (*format) {
1903 case '[' :
1904 open_paren = format ;
1905 break ;
1906 case ']' :
1907 format = open_paren ;
1908 break ;
1909 case '1' :
1910 case '2' :
1911 case '3' :
1912 case '4' :
1913 case '5' :
1914 case '6' :
1915 case '7' :
1916 case '8' :
1917 case '9' :
1918 data += *format - '0' ;
1919 len -= *format - '0' ;
1920 break ;
1921 case 'c':
1922 data++ ;
1923 len-- ;
1924 break ;
1925 case 's' :
1926 x = data[0] ;
1927 data[0] = data[1] ;
1928 data[1] = x ;
1929 data += 2 ;
1930 len -= 2 ;
1931 break ;
1932 case 'l' :
1933 x = data[0] ;
1934 data[0] = data[3] ;
1935 data[3] = x ;
1936 x = data[1] ;
1937 data[1] = data[2] ;
1938 data[2] = x ;
1939 data += 4 ;
1940 len -= 4 ;
1941 break ;
1943 format++ ;
1946 #else
1947 void smt_swap_para(struct smt_header *sm, int len, int direction)
1948 /* int direction; 0 encode 1 decode */
1950 SK_UNUSED(sm) ;
1951 SK_UNUSED(len) ;
1952 SK_UNUSED(direction) ;
1954 #endif
1957 * PMF actions
1959 int smt_action(struct s_smc *smc, int class, int code, int index)
1961 int event ;
1962 int port ;
1963 DB_SMT("SMT: action %d code %d\n",class,code) ;
1964 switch(class) {
1965 case SMT_STATION_ACTION :
1966 switch(code) {
1967 case SMT_STATION_ACTION_CONNECT :
1968 smc->mib.fddiSMTRemoteDisconnectFlag = FALSE ;
1969 queue_event(smc,EVENT_ECM,EC_CONNECT) ;
1970 break ;
1971 case SMT_STATION_ACTION_DISCONNECT :
1972 queue_event(smc,EVENT_ECM,EC_DISCONNECT) ;
1973 smc->mib.fddiSMTRemoteDisconnectFlag = TRUE ;
1974 RS_SET(smc,RS_DISCONNECT) ;
1975 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1976 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_DISCONNECT,
1977 smt_get_event_word(smc));
1978 break ;
1979 case SMT_STATION_ACTION_PATHTEST :
1980 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1981 FDDI_SMT_EVENT, (u_long) FDDI_PATH_TEST,
1982 smt_get_event_word(smc));
1983 break ;
1984 case SMT_STATION_ACTION_SELFTEST :
1985 AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
1986 FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_SELF_TEST,
1987 smt_get_event_word(smc));
1988 break ;
1989 case SMT_STATION_ACTION_DISABLE_A :
1990 if (smc->y[PA].pc_mode == PM_PEER) {
1991 RS_SET(smc,RS_EVENT) ;
1992 queue_event(smc,EVENT_PCM+PA,PC_DISABLE) ;
1994 break ;
1995 case SMT_STATION_ACTION_DISABLE_B :
1996 if (smc->y[PB].pc_mode == PM_PEER) {
1997 RS_SET(smc,RS_EVENT) ;
1998 queue_event(smc,EVENT_PCM+PB,PC_DISABLE) ;
2000 break ;
2001 case SMT_STATION_ACTION_DISABLE_M :
2002 for (port = 0 ; port < NUMPHYS ; port++) {
2003 if (smc->mib.p[port].fddiPORTMy_Type != TM)
2004 continue ;
2005 RS_SET(smc,RS_EVENT) ;
2006 queue_event(smc,EVENT_PCM+port,PC_DISABLE) ;
2008 break ;
2009 default :
2010 return(1) ;
2012 break ;
2013 case SMT_PORT_ACTION :
2014 switch(code) {
2015 case SMT_PORT_ACTION_ENABLE :
2016 event = PC_ENABLE ;
2017 break ;
2018 case SMT_PORT_ACTION_DISABLE :
2019 event = PC_DISABLE ;
2020 break ;
2021 case SMT_PORT_ACTION_MAINT :
2022 event = PC_MAINT ;
2023 break ;
2024 case SMT_PORT_ACTION_START :
2025 event = PC_START ;
2026 break ;
2027 case SMT_PORT_ACTION_STOP :
2028 event = PC_STOP ;
2029 break ;
2030 default :
2031 return(1) ;
2033 queue_event(smc,EVENT_PCM+index,event) ;
2034 break ;
2035 default :
2036 return(1) ;
2038 return(0) ;
2042 * canonical conversion of <len> bytes beginning form *data
2044 #ifdef USE_CAN_ADDR
2045 static void hwm_conv_can(struct s_smc *smc, char *data, int len)
2047 int i ;
2049 SK_UNUSED(smc) ;
2051 for (i = len; i ; i--, data++)
2052 *data = bitrev8(*data);
2054 #endif
2056 #endif /* no SLIM_SMT */