cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

smtdef.c (9562B)


      1// SPDX-License-Identifier: GPL-2.0-or-later
      2/******************************************************************************
      3 *
      4 *	(C)Copyright 1998,1999 SysKonnect,
      5 *	a business unit of Schneider & Koch & Co. Datensysteme GmbH.
      6 *
      7 *	See the file "skfddi.c" for further information.
      8 *
      9 *	The information in this file is provided "AS IS" without warranty.
     10 *
     11 ******************************************************************************/
     12
     13/*
     14	SMT/CMT defaults
     15*/
     16
     17#include "h/types.h"
     18#include "h/fddi.h"
     19#include "h/smc.h"
     20
     21#ifndef OEM_USER_DATA
     22#define OEM_USER_DATA	"SK-NET FDDI V2.0 Userdata"
     23#endif
     24
     25/*
     26 * defaults
     27 */
     28#define TTMS(x)	((u_long)(x)*1000L)
     29#define TTS(x)	((u_long)(x)*1000000L)
     30#define TTUS(x)	((u_long)(x))
     31
     32#define DEFAULT_TB_MIN		TTMS(5)
     33#define DEFAULT_TB_MAX		TTMS(50)
     34#define DEFAULT_C_MIN		TTUS(1600)
     35#define DEFAULT_T_OUT		TTMS(100+5)
     36#define DEFAULT_TL_MIN		TTUS(30)
     37#define DEFAULT_LC_SHORT	TTMS(50+5)
     38#define DEFAULT_LC_MEDIUM	TTMS(500+20)
     39#define DEFAULT_LC_LONG		TTS(5)+TTMS(50)
     40#define DEFAULT_LC_EXTENDED	TTS(50)+TTMS(50)
     41#define DEFAULT_T_NEXT_9	TTMS(200+10)
     42#define DEFAULT_NS_MAX		TTUS(1310)
     43#define DEFAULT_I_MAX		TTMS(25)
     44#define DEFAULT_IN_MAX		TTMS(40)
     45#define DEFAULT_TD_MIN		TTMS(5)
     46#define DEFAULT_T_NON_OP	TTS(1)
     47#define DEFAULT_T_STUCK		TTS(8)
     48#define DEFAULT_T_DIRECT	TTMS(370)
     49#define DEFAULT_T_JAM		TTMS(370)
     50#define DEFAULT_T_ANNOUNCE	TTMS(2500)
     51#define DEFAULT_D_MAX		TTUS(1617)
     52#define DEFAULT_LEM_ALARM	(8)
     53#define DEFAULT_LEM_CUTOFF	(7)
     54#define DEFAULT_TEST_DONE	TTS(1)
     55#define DEFAULT_CHECK_POLL	TTS(1)
     56#define DEFAULT_POLL		TTMS(50)
     57
     58/*
     59 * LCT errors threshold
     60 */
     61#define DEFAULT_LCT_SHORT	1
     62#define DEFAULT_LCT_MEDIUM	3
     63#define DEFAULT_LCT_LONG	5
     64#define DEFAULT_LCT_EXTEND	50
     65
     66/* Forward declarations */
     67void smt_reset_defaults(struct s_smc *smc, int level);
     68static void smt_init_mib(struct s_smc *smc, int level);
     69static int set_min_max(int maxflag, u_long mib, u_long limit, u_long *oper);
     70
     71#define MS2BCLK(x)	((x)*12500L)
     72#define US2BCLK(x)	((x)*1250L)
     73
     74void smt_reset_defaults(struct s_smc *smc, int level)
     75{
     76	struct smt_config	*smt ;
     77	int			i ;
     78	u_long			smt_boot_time;
     79
     80
     81	smt_init_mib(smc,level) ;
     82
     83	smc->os.smc_version = SMC_VERSION ;
     84	smt_boot_time = smt_get_time();
     85	for( i = 0; i < NUMMACS; i++ )
     86		smc->sm.last_tok_time[i] = smt_boot_time ;
     87	smt = &smc->s ;
     88	smt->attach_s = 0 ;
     89	smt->build_ring_map = 1 ;
     90	smt->sas = SMT_DAS ;
     91	smt->numphys = NUMPHYS ;
     92	smt->pcm_tb_min = DEFAULT_TB_MIN ;
     93	smt->pcm_tb_max = DEFAULT_TB_MAX ;
     94	smt->pcm_c_min = DEFAULT_C_MIN ;
     95	smt->pcm_t_out = DEFAULT_T_OUT ;
     96	smt->pcm_tl_min = DEFAULT_TL_MIN ;
     97	smt->pcm_lc_short = DEFAULT_LC_SHORT ;
     98	smt->pcm_lc_medium = DEFAULT_LC_MEDIUM ;
     99	smt->pcm_lc_long = DEFAULT_LC_LONG ;
    100	smt->pcm_lc_extended = DEFAULT_LC_EXTENDED ;
    101	smt->pcm_t_next_9 = DEFAULT_T_NEXT_9 ;
    102	smt->pcm_ns_max = DEFAULT_NS_MAX ;
    103	smt->ecm_i_max = DEFAULT_I_MAX ;
    104	smt->ecm_in_max = DEFAULT_IN_MAX ;
    105	smt->ecm_td_min = DEFAULT_TD_MIN ;
    106	smt->ecm_test_done = DEFAULT_TEST_DONE ;
    107	smt->ecm_check_poll = DEFAULT_CHECK_POLL ;
    108	smt->rmt_t_non_op = DEFAULT_T_NON_OP ;
    109	smt->rmt_t_stuck = DEFAULT_T_STUCK ;
    110	smt->rmt_t_direct = DEFAULT_T_DIRECT ;
    111	smt->rmt_t_jam = DEFAULT_T_JAM ;
    112	smt->rmt_t_announce = DEFAULT_T_ANNOUNCE ;
    113	smt->rmt_t_poll = DEFAULT_POLL ;
    114        smt->rmt_dup_mac_behavior = FALSE ;  /* See Struct smt_config */
    115	smt->mac_d_max = DEFAULT_D_MAX ;
    116
    117	smt->lct_short = DEFAULT_LCT_SHORT ;
    118	smt->lct_medium = DEFAULT_LCT_MEDIUM ;
    119	smt->lct_long = DEFAULT_LCT_LONG ;
    120	smt->lct_extended = DEFAULT_LCT_EXTEND ;
    121
    122#ifndef	SLIM_SMT
    123#ifdef	ESS
    124	if (level == 0) {
    125		smc->ess.sync_bw_available = FALSE ;
    126		smc->mib.fddiESSPayload = 0 ;
    127		smc->mib.fddiESSOverhead = 0 ;
    128		smc->mib.fddiESSMaxTNeg = (u_long)(- MS2BCLK(25)) ;
    129		smc->mib.fddiESSMinSegmentSize = 1 ;
    130		smc->mib.fddiESSCategory = SB_STATIC ;
    131		smc->mib.fddiESSSynchTxMode = FALSE ;
    132		smc->ess.raf_act_timer_poll = FALSE ;
    133		smc->ess.timer_count = 7 ; 	/* first RAF alc req after 3s */
    134	}
    135	smc->ess.local_sba_active = FALSE ;
    136	smc->ess.sba_reply_pend = NULL ;
    137#endif
    138#ifdef	SBA
    139	smt_init_sba(smc,level) ;
    140#endif
    141#endif	/* no SLIM_SMT */
    142#ifdef	TAG_MODE
    143	if (level == 0) {
    144		smc->hw.pci_fix_value = 0 ;
    145	}
    146#endif
    147}
    148
    149/*
    150 * manufacturer data
    151 */
    152static const char man_data[32] =
    153/*	 01234567890123456789012345678901	*/
    154	"xxxSK-NET FDDI SMT 7.3 - V2.8.8" ;
    155
    156static void smt_init_mib(struct s_smc *smc, int level)
    157{
    158	struct fddi_mib		*mib ;
    159	struct fddi_mib_p	*pm ;
    160	int			port ;
    161	int			path ;
    162
    163	mib = &smc->mib ;
    164	if (level == 0) {
    165		/*
    166		 * set EVERYTHING to ZERO
    167		 * EXCEPT hw and os
    168		 */
    169		memset(((char *)smc)+
    170			sizeof(struct s_smt_os)+sizeof(struct s_smt_hw), 0,
    171			sizeof(struct s_smc) -
    172			sizeof(struct s_smt_os) - sizeof(struct s_smt_hw)) ;
    173	}
    174	else {
    175		mib->fddiSMTRemoteDisconnectFlag = 0 ;
    176		mib->fddiSMTPeerWrapFlag = 0 ;
    177	}
    178
    179	mib->fddiSMTOpVersionId = 2 ;
    180	mib->fddiSMTHiVersionId = 2 ;
    181	mib->fddiSMTLoVersionId = 2 ;
    182	memcpy((char *) mib->fddiSMTManufacturerData,man_data,32) ;
    183	if (level == 0) {
    184		strcpy(mib->fddiSMTUserData,OEM_USER_DATA) ;
    185	}
    186	mib->fddiSMTMIBVersionId = 1 ;
    187	mib->fddiSMTMac_Ct = NUMMACS ;
    188	mib->fddiSMTConnectionPolicy = POLICY_MM | POLICY_AA | POLICY_BB ;
    189
    190	/*
    191	 * fddiSMTNonMaster_Ct and fddiSMTMaster_Ct are set in smt_fixup_mib
    192	 * s.sas is not set yet (is set in init driver)
    193	 */
    194	mib->fddiSMTAvailablePaths = MIB_PATH_P | MIB_PATH_S ;
    195
    196	mib->fddiSMTConfigCapabilities = 0 ;	/* no hold,no wrap_ab*/
    197	mib->fddiSMTTT_Notify = 10 ;
    198	mib->fddiSMTStatRptPolicy = TRUE ;
    199	mib->fddiSMTTrace_MaxExpiration = SEC2MIB(7) ;
    200	mib->fddiSMTMACIndexes = INDEX_MAC ;
    201	mib->fddiSMTStationStatus = MIB_SMT_STASTA_SEPA ;	/* separated */
    202
    203	mib->m[MAC0].fddiMACIndex = INDEX_MAC ;
    204	mib->m[MAC0].fddiMACFrameStatusFunctions = FSC_TYPE0 ;
    205	mib->m[MAC0].fddiMACRequestedPaths =
    206		MIB_P_PATH_LOCAL |
    207		MIB_P_PATH_SEC_ALTER |
    208		MIB_P_PATH_PRIM_ALTER ;
    209	mib->m[MAC0].fddiMACAvailablePaths = MIB_PATH_P ;
    210	mib->m[MAC0].fddiMACCurrentPath = MIB_PATH_PRIMARY ;
    211	mib->m[MAC0].fddiMACT_MaxCapabilitiy = (u_long)(- MS2BCLK(165)) ;
    212	mib->m[MAC0].fddiMACTVXCapabilitiy = (u_long)(- US2BCLK(52)) ;
    213	if (level == 0) {
    214		mib->m[MAC0].fddiMACTvxValue = (u_long)(- US2BCLK(27)) ;
    215		mib->m[MAC0].fddiMACTvxValueMIB = (u_long)(- US2BCLK(27)) ;
    216		mib->m[MAC0].fddiMACT_Req = (u_long)(- MS2BCLK(165)) ;
    217		mib->m[MAC0].fddiMACT_ReqMIB = (u_long)(- MS2BCLK(165)) ;
    218		mib->m[MAC0].fddiMACT_Max = (u_long)(- MS2BCLK(165)) ;
    219		mib->m[MAC0].fddiMACT_MaxMIB = (u_long)(- MS2BCLK(165)) ;
    220		mib->m[MAC0].fddiMACT_Min = (u_long)(- MS2BCLK(4)) ;
    221	}
    222	mib->m[MAC0].fddiMACHardwarePresent = TRUE ;
    223	mib->m[MAC0].fddiMACMA_UnitdataEnable = TRUE ;
    224	mib->m[MAC0].fddiMACFrameErrorThreshold = 1 ;
    225	mib->m[MAC0].fddiMACNotCopiedThreshold = 1 ;
    226	/*
    227	 * Path attributes
    228	 */
    229	for (path = 0 ; path < NUMPATHS ; path++) {
    230		mib->a[path].fddiPATHIndex = INDEX_PATH + path ;
    231		if (level == 0) {
    232			mib->a[path].fddiPATHTVXLowerBound =
    233				(u_long)(- US2BCLK(27)) ;
    234			mib->a[path].fddiPATHT_MaxLowerBound =
    235				(u_long)(- MS2BCLK(165)) ;
    236			mib->a[path].fddiPATHMaxT_Req =
    237				(u_long)(- MS2BCLK(165)) ;
    238		}
    239	}
    240
    241
    242	/*
    243	 * Port attributes
    244	 */
    245	pm = mib->p ;
    246	for (port = 0 ; port <  NUMPHYS ; port++) {
    247		/*
    248		 * set MIB pointer in phy
    249		 */
    250		/* Attention: don't initialize mib pointer here! */
    251		/*  It must be initialized during phase 2 */
    252		smc->y[port].mib = NULL;
    253		mib->fddiSMTPORTIndexes[port] = port+INDEX_PORT ;
    254
    255		pm->fddiPORTIndex = port+INDEX_PORT ;
    256		pm->fddiPORTHardwarePresent = TRUE ;
    257		if (level == 0) {
    258			pm->fddiPORTLer_Alarm = DEFAULT_LEM_ALARM ;
    259			pm->fddiPORTLer_Cutoff = DEFAULT_LEM_CUTOFF ;
    260		}
    261		/*
    262		 * fddiPORTRequestedPaths are set in pcmplc.c
    263		 * we don't know the port type yet !
    264		 */
    265		pm->fddiPORTRequestedPaths[1] = 0 ;
    266		pm->fddiPORTRequestedPaths[2] = 0 ;
    267		pm->fddiPORTRequestedPaths[3] = 0 ;
    268		pm->fddiPORTAvailablePaths = MIB_PATH_P ;
    269		pm->fddiPORTPMDClass = MIB_PMDCLASS_MULTI ;
    270		pm++ ;
    271	}
    272
    273	(void) smt_set_mac_opvalues(smc) ;
    274}
    275
    276int smt_set_mac_opvalues(struct s_smc *smc)
    277{
    278	int	st ;
    279	int	st2 ;
    280
    281	st = set_min_max(1,smc->mib.m[MAC0].fddiMACTvxValueMIB,
    282		smc->mib.a[PATH0].fddiPATHTVXLowerBound,
    283		&smc->mib.m[MAC0].fddiMACTvxValue) ;
    284	st |= set_min_max(0,smc->mib.m[MAC0].fddiMACT_MaxMIB,
    285		smc->mib.a[PATH0].fddiPATHT_MaxLowerBound,
    286		&smc->mib.m[MAC0].fddiMACT_Max) ;
    287	st |= (st2 = set_min_max(0,smc->mib.m[MAC0].fddiMACT_ReqMIB,
    288		smc->mib.a[PATH0].fddiPATHMaxT_Req,
    289		&smc->mib.m[MAC0].fddiMACT_Req)) ;
    290	if (st2) {
    291		/* Treq attribute changed remotely. So send an AIX_EVENT to the
    292		 * user
    293		 */
    294		AIX_EVENT(smc, (u_long) FDDI_RING_STATUS, (u_long)
    295			FDDI_SMT_EVENT, (u_long) FDDI_REMOTE_T_REQ,
    296			smt_get_event_word(smc));
    297	}
    298	return st;
    299}
    300
    301void smt_fixup_mib(struct s_smc *smc)
    302{
    303#ifdef	CONCENTRATOR
    304	switch (smc->s.sas) {
    305	case SMT_SAS :
    306		smc->mib.fddiSMTNonMaster_Ct = 1 ;
    307		break ;
    308	case SMT_DAS :
    309		smc->mib.fddiSMTNonMaster_Ct = 2 ;
    310		break ;
    311	case SMT_NAC :
    312		smc->mib.fddiSMTNonMaster_Ct = 0 ;
    313		break ;
    314	}
    315	smc->mib.fddiSMTMaster_Ct = NUMPHYS - smc->mib.fddiSMTNonMaster_Ct ;
    316#else
    317	switch (smc->s.sas) {
    318	case SMT_SAS :
    319		smc->mib.fddiSMTNonMaster_Ct = 1 ;
    320		break ;
    321	case SMT_DAS :
    322		smc->mib.fddiSMTNonMaster_Ct = 2 ;
    323		break ;
    324	}
    325	smc->mib.fddiSMTMaster_Ct = 0 ;
    326#endif
    327}
    328
    329/*
    330 * determine new setting for operational value
    331 * if limit is lower than mib
    332 *	use limit
    333 * else
    334 *	use mib
    335 * NOTE : numbers are negative, negate comparison !
    336 */
    337static int set_min_max(int maxflag, u_long mib, u_long limit, u_long *oper)
    338{
    339	u_long	old ;
    340	old = *oper ;
    341	if ((limit > mib) ^ maxflag)
    342		*oper = limit ;
    343	else
    344		*oper = mib ;
    345	return old != *oper;
    346}
    347