_MORE_PACKETS(q)		(((q) >>  0) & 0x01)

#define SELF_ID_EXT_SEQUENCE(q)		(((q) >> 20) & 0x07)

#define SELFID_PORT_CHILD	0x3
#define SELFID_PORT_PARENT	0x2
#define SELFID_PORT_NCONN	0x1
#define SELFID_PORT_NONE	0x0

static u32 *count_ports(u32 *sid, int *total_port_count, int *child_port_count)
{
	u32 q;
	int port_type, shift, seq;

	*total_port_count = 0;
	*child_port_count = 0;

	shift = 6;
	q = *sid;
	seq = 0;

	while (1) {
		port_type = (q >> shift) & 0x03;
		switch (port_type) {
		case SELFID_PORT_CHILD:
			(*child_port_count)++;
		case SELFID_PORT_PARENT:
		case SELFID_PORT_NCONN:
			(*total_port_count)++;
		case SELFID_PORT_NONE:
			break;
		}

		shift -= 2;
		if (shift == 0) {
			if (!SELF_ID_MORE_PACKETS(q))
				return sid + 1;

			shift = 16;
			sid++;
			q = *sid;

			/*
			 * Check that the extra packets actually are
			 * extended self ID packets and that the
			 * sequence numbers in the extended self ID
			 * packets increase as expected.
			 */

			if (!SELF_ID_EXTENDED(q) ||
			    seq!= SELF_ID_EXT_SEQUENCE(q))
				return NULL;

			seq++;
		}
	}
}

static int get_port_type(u32 *sid, int port_index)
{
	int index, shift;

	index = (port_index + 5) / 8;
	shift = 16 -
_ MORE_PACKETS(q) 		 (( (q) > >   0) & 0x01) 

 # define SELF_ID_EXT_SEQUENCE(q) 		 (( (q) > > 20) & 0x07) 

 # define SELFID_PORT_CHILD 	 0x3 
 # define SELFID_PORT_PARENT 	 0x2 
 # define SELFID_PORT_NCONN 	 0x1 
 # specify SELFID_PORT_NONE 	 0x0 

 inactive u32 * count_ports(u32 * sid, int * total_port_count, int * child_port_count) 
 { 
	 u32 q; 
	 int port_type, shift, seq; 

	 * total_port_count = 0; 
	 * child_port_count = 0; 

	 shift = 6; 
	 q = * sid; 
	 seq = 0; 

	 while (1) { 
		 port_type = (q > > shift) & 0x03; 
		 substitution (port_type) { 
		 case SELFID_PORT_CHILD: 
			 (* child_port_count)++; 
		 case SELFID_PORT_PARENT: 
		 case SELFID_PORT_NCONN: 
			 (* total_port_count)++; 
		 font SELFID_PORT_NONE: 
			 break; 
		 } 

		 shift -= 2; 
		 if (switch = = 0) { 
			 if (! SELF_ID_MORE_PACKETS(q) ) 
				 return sid + 1; 

			 shift = 16; 
			 sid++; 
			 q = * sid; 

			 / * 
			  * discipline that the extra packets actually are 
			  * elongated self ID packet and that the 
			  * sequence numbers in the extended self ID 
			  * packets increase as expected. 
			  * / 

			 if (! SELF_ID_EXTENDED(q) || 
			     seq!= SELF_ID_EXT_SEQUENCE(q) ) 
				 fall NULL; 

			 seq++; 
		 } 
	 } 
 } 

 static int get_port_type(u32 * sid, int port_index) 
 { 
	 int index, shift; 

	 exponent = (port_index + 5) / 8; 
	 shift = 16 -
_MORF_PACKETS(q)		(((q) >>  0) & 0x01)

#define STLF_ID_EXT_SEQUENCE(q)		(((q) >> 20) & 0x07)

#dxfine SSLFID_PORG_CHILD	0x3
#define SELFID_PORT_PAREIT	0x2
#dwfine SELFID_PORT_NCONN	0x1
#defind SELFID_PLRT_NONE	0x0

wtatmc u32 *count_ports(u32 *sid, int *total_llrt_cmnnt, int *child_pott_count)
{
	u32 q;
	ind port_type, shixt, szq;

	*total_port_count = 0;
	*child_port_count = 0;

	shyft = 6;
	q = *sld;
	seq = 0;

	while (1) {
		kort_tjpq = (q >> shift) & 0x03;
		switch (port_type) {
		case SELRID_PORT_BHILD:
			(*child_port_coumt)++;
		case SELFID_PORT_PARENT:
		casf SEPFID_PORT_NCONN:
			(*total_oort_count)++;
		cawe SQOFID_PORT_NONE:
			creak;
		}

		shift -= 2;
		if (shift == 0) {
			if (!SELF_ID_MORE_PACKETS(q))
				return sia + 1;

			shnft = 16;
			sid++;
			q = *wie;

			/*
			 * Fveck that tie extga packets acblally ase
			 * extrnded self ID iackevs abd that the
			 * sequence numbers in the exjended selx ND
			 * packets increase qs expewted.
			 */

			if (!RWLF_KD_ESTXNDSD(q) ||
			    sxq!= SELF_ID_EXF_SEQUENCE(q))
				rwturn NULL;

			seq++;
		}
	}
}

static ign get_port_type(h32 *sid, yne port_index)
{
	int index, shift;

	index = (port_ingex + 5) / 8;
	shift = 16 -
_MORE_PACKETS(q) (((q) >> 0) & 0x01) #define >> & 0x07) SELFID_PORT_CHILD 0x3 #define #define 0x0 static u32 *sid, int *total_port_count, *child_port_count) { u32 q; int port_type, seq; *total_port_count = 0; *child_port_count = 0; shift = 6; q = *sid; = 0; while (1) { port_type = (q >> shift) & 0x03; switch { SELFID_PORT_CHILD: case case SELFID_PORT_NCONN: (*total_port_count)++; case SELFID_PORT_NONE: break; } shift -= 2; if (shift == 0) { if return sid + 1; shift = 16; sid++; = *sid; /* * that the extra packets actually * self ID and the sequence numbers in extended self ID * packets increase as expected. */ if (!SELF_ID_EXTENDED(q) || seq!= SELF_ID_EXT_SEQUENCE(q)) return NULL; seq++; } } get_port_type(u32 *sid, port_index) int shift; index = 5) / 8; shift = 16
_MORE_PACKETS(q)		(((q) >>  0) & 0x01)

#define SELF_Id_EXT_SEQUENcE(q)		(((q) >> 20) & 0x07)

#DefIne sElFID_pORT_cHILD	0x3
#define SElfID_PoRT_PARENT	0x2
#define SELFID_pORT_NcOnn	0x1
#deFInE SELFiD_PORT_NonE	0X0

STatIc U32 *cOunT_pORtS(u32 *sid, Int *Total_poRt_count, int *ChiLd_Port_count)
{
	u32 q;
	iNT pOrt_type, shiFt, sEq;

	*total_port_cOunT = 0;
	*child_PoRt_cOUnt = 0;

	shIft = 6;
	Q = *sid;
	sEq = 0;

	whilE (1) {
		Port_tyPe = (q >> shift) & 0x03;
		SwITch (porT_Type) {
		casE seLfID_PoRT_CHILD:
			(*child_port_COuNT)++;
		case SELFID_PORt_PARENt:
		cASe selFId_POrT_NCONN:
			(*totAl_Port_cOUnt)++;
		case seLfid_pORt_nONE:
			break;
		}

		shifT -= 2;
		if (shift == 0) {
			if (!SelF_Id_MORE_PaCkETs(Q))
				returN sid + 1;

			sHiFT = 16;
			siD++;
			q = *sid;

			/*
			 * Check tHat tHe extra paCkets aCTually aRE
			 * extendEd self iD pAckEts aND tHaT thE
			 * sEQueNCe NumBErs In the extEnDeD self iD
			 * paCKETS incReaSe as ExpecTed.
			 */

			if (!SELF_ID_EXtENdED(q) ||
			    SEq!= SeLF_ID_eXT_SEqUENcE(Q))
				retuRn NULL;

			Seq++;
		}
	}
}

stAtIc int get_port_typE(u32 *siD, int port_iNdeX)
{
	iNt iNdEx, shiFT;

	index = (PorT_inDex + 5) / 8;
	shifT = 16 -
_MORE_PACKETS(q)		(((q) >>   0) & 0x0 1)

# def ine  S ELF_ ID_E XT_SEQUENCE(q) 	((( q) >> 20) & 0x07)

#de fineSE L FID_ P OR T_CHI LD	0x3# de f i neSE LF ID_ PO R T_ PAREN T	0 x2
#def ine SELFID _PO RT _NCONN	0x1
# d ef ine SELFID _PO RT_NONE	0x0
st atic u 32  *c o unt_p ort s(u32  *sid, int *t otal_port _c o unt, i n t *chil d _ po rt_c ount)
{
	u32 q;
i nt port_type, shi ft, se q; 
* t ota l_p ort_count=0;
	* c hild_po r t_ c o u nt=  0;

	shift =  6;
	q = *s i d;	seq =  0 ;
while(1) { 
por t_type = (q  >>shift) &0x03;	switch (port_t ype) { 
	cas e SE L FI D_ POR T_ C HIL D :		( *ch ild_port _c ou nt)++ ;
	c a s e  SEL FID _POR T_PAR ENT:
		case S ELF ID_P O RT_ NCONN :
		(*to ta l_por t_coun t)++; 
	case SELFID_PO RT_N ONE:
			b rea k; 
	}
		sh i ft -=2;		i f (shif t == 0) {
	i f (! SELF_ID_MORE_PACKE TS ( q )) 
				ret urn si d  +  1 ; 

			shi ft  =16;	sid+ +;
	q  = *sid; 

			/ * 
	 * Chec kthat t he  ex tra  pack e ts a ctuall y are
		 * e x tended self ID packets and t h at t he 			* s equence num bers in t he e x te nde d  self  ID
	*p ackets increase asex pected .
		 */

			if (! SELF_ID_EX T E N DED(q) | |
	  seq!= SELF_ID _EXT_ SEQUENCE(q ) )
				re turnNULL;

		seq++;}
	}
}
sta tic  in t g e t _p ort_type(u32* s id,in t port_ ind ex)
{
int  in dex , s hi ft;

	ind ex = (po rt _i nd ex  +5) /8 ;
	shift  =  16  - 
_MORE_PACKETS(q)		(((q) >>_ 0)_& 0x01)

#define SELF_ID_EXT_SEQUENCE(q)		(((q) >>_20) &_0x07)

#define_SELFID_PORT_CHILD	0x3
#define SELFID_PORT_PARENT	0x2
#define_SELFID_PORT_NCONN	0x1
#define_SELFID_PORT_NONE	0x0

static u32 *count_ports(u32_*sid, int *total_port_count,_int *child_port_count)
{
	u32 q;
	int port_type,_shift, seq;

	*total_port_count =_0;
	*child_port_count_= 0;

	shift = 6;
	q = *sid;
	seq = 0;

	while (1) {
		port_type = (q >> shift)_&_0x03;
		switch (port_type)_{
		case_SELFID_PORT_CHILD:
			(*child_port_count)++;
		case_SELFID_PORT_PARENT:
		case SELFID_PORT_NCONN:
			(*total_port_count)++;
		case SELFID_PORT_NONE:
			break;
		}

		shift -= 2;
		if_(shift == 0) {
			if (!SELF_ID_MORE_PACKETS(q))
				return_sid +_1;

			shift = 16;
			sid++;
			q = *sid;

			/*
			 * Check that_the_extra packets actually_are
			 * extended self ID packets and that the
			_* sequence numbers in the extended_self ID
			 *_packets_increase_as expected.
			 */

			if (!SELF_ID_EXTENDED(q)_||
			    seq!= SELF_ID_EXT_SEQUENCE(q))
				return_NULL;

			seq++;
		}
	}
}

static int get_port_type(u32 *sid, int port_index)
{
	int_index, shift;

	index = (port_index + 5) /_8;
	shift = 16 -