 mdelay(1);  
void tulip_select_media(struct net_device *dev, int startup){	struct tulip_private *tp = netdev_priv(dev);	void __iomem *ioaddr = tp->base_addr;	struct mediatable *mtable = tp->mtable;	u32 new_csr6;	int i;	if (mtable) {		struct medialeaf *mleaf = &mtable->mleaf[tp->cur_index];		unsigned char *p = mleaf->leafdata;		switch (mleaf->type) {		case 0:					/* 21140 non-MII xcvr. */			if (tulip_debug > 1)				printk(KERN_DEBUG "%s: Using a 21140 non-MII transceiver"					   " with control setting %2.2x.\n",					   dev->name, p[1]);			dev->if_port = p[0];			if (startup)				iowrite32(mtable->csr12dir | 0x100, ioaddr + CSR12);			iowrite32(p[1], ioaddr + CSR12);			new_csr6 = 0x02000000 | ((p[2] & 0x71) << 18);			break;		case 2: case 4: {			u16 setup[5];			u32 csr13val, csr14val, csr15dir, csr15val;			for (i = 0; i < 5; i++)				setup[i] = get_u16(&p[i*2 + 1]);			dev->if_port = p[0] & MEDIA_MASK;			if (tulip_media_cap[dev->if_port] & MediaAlwaysFD)				tp->full_duplex = 1;			if (startup && mtable->has_reset) {				struct medialeaf *rleaf = &mtable->mleaf[mtable->has_reset];				unsigned char *rst = rleaf->leafdata;				if (tulip_debug > 1)					printk(KERN_DEBUG "%s: Resetting the transceiver.\n",						   dev->name);				for (i = 0; i < rst[0]; i++)					iowrite32(get_u16(rst + 1 + (i<<1)) << 16, ioaddr + CSR15);			}			if (tulip_debug > 1)				printk(KERN_DEBUG "%s: 21143 non-MII %s transceiver control "					   "%4.4x/%4.4x.\n",					   dev->name, medianame[dev->if_port], setup[0], setup[1]);			if (p[0] & 0x40) {	/* SIA (CSR13-15) setup values are provided. */				csr13val = setup[0];				csr14val = setup[1];				csr15dir = (setup[3]<<16) | setup[2];				csr15val = (setup[4]<<16) | setup[2];				iowrite32(0, ioaddr + CSR13);				iowrite32(csr14val, ioaddr + CSR14);				iowrite32(csr15dir, ioaddr + CSR15);	/* Direction */				iowrite32(csr15val, ioaddr + CSR15);	/* Data */				iowrite32(csr13val, ioaddr + CSR13);			} else {				csr13val = 1;				csr14val = 0;				csr15dir = (setup[0]<<16) | 0x0008;				csr15val = (setup[1]<<16) | 0x0008;				if (dev->if_port <= 4)					csr14val = t21142_csr14[dev->if_port];				if (startup) {					iowrite32(0, ioaddr + CSR13);					iowrite32(csr14val, ioaddr + CSR14);				}				iowrite32(csr15dir, ioaddr + CSR15);	/* Direction */				iowrite32(csr15val, ioaddr + CSR15);	/* Data */				if (startup) iowrite32(csr13val, ioaddr + CSR13);			}			if (tulip_debug > 1)				printk(KERN_DEBUG "%s:  Setting CSR15 to %8.8x/%8.8x.\n",					   dev->name, csr15dir, csr15val);			if (mleaf->type == 4)				new_csr6 = 0x82020000 | ((setup[2] & 0x71) << 18);			else				new_csr6 = 0x82420000;			break;		}		case 1: case 3: {			int phy_num = p[0];			int init_length = p[1];			u16 *misc_info, tmp_info;			dev->if_port = 11;			new_csr6 = 0x020E0000;			if (mleaf->type == 3) {	/* 21142 */				u16 *init_sequence = (u16*)(p+2);				u16 *reset_sequence = &((u16*)(p+3))[init_length];				int reset_length = p[2 + init_length*2];				misc_info = reset_sequence + reset_length;				if (startup)					for (i = 0; i < reset_length; i++)						iowrite32(get_u16(&reset_sequence[i]) << 16, ioaddr + CSR15);				for (i = 0; i < init_length; i++)					iowrite32(get_u16(&init_sequence[i]) << 16, ioaddr + CSR15);			} else {				u8 *init_sequence = p + 2;				u8 *reset_sequence = p + 3 + init_length;				int reset_length = p[2 + init_length];				misc_info = (u16*)(reset_sequence + reset_length);				if (startup) {					iowrite32(mtable->csr12dir | 0x100, ioaddr + CSR12);					for (i = 0; i < reset_length; i++)						iowrite32(reset_sequence[i], ioaddr + CSR12);				}				for (i = 0; i < init_length; i++)					iowrite32(init_sequence[i], ioaddr + CSR12);			}			tmp_info = get_u16(&misc_info[1]);			if (tmp_info)				tp->advertising[phy_num] = tmp_info | 1;			if (tmp_info && startup < 2) {				if (tp->mii_advertise == 0)					tp->mii_advertise = tp->advertising[phy_num];				if (tulip_debug > 1)					printk(KERN_DEBUG "%s:  Advertising %4.4x on MII %d.\n",					       dev->name, tp->mii_advertise, tp->phys[phy_num]);				tulip_mdio_write(dev, tp->phys[phy_num], 4, tp->mii_advertise);			}			break;		}		case 5: case 6: {			u16 setup[5];			new_csr6 = 0; /* FIXME */			for (i = 0; i < 5; i++)				setup[i] = get_u16(&p[i*2 + 1]);			if (startup && mtable->has_reset) {				struct medialeaf *rleaf = &mtable->mleaf[mtable->has_reset];				unsigned char *rst = rleaf->leafdata;				if (tulip_debug > 1)					printk(KERN_DEBUG "%s: Resetting the transceiver.\n",						   dev->name);				for (i = 0; i < rst[0]; i++)					iowrite32(get_u16(rst + 1 + (i<<1)) << 16, ioaddr + CSR15);			}			break;		}		default:			printk(KERN_DEBUG "%s:  Invalid media table selection %d.\n",					   dev->name, mleaf->type);			new_csr6 = 0x020E0000;		}		if (tulip_debug > 1)			printk(KERN_DEBUG "%s: Using media type %s, CSR12 is %2.2x.\n",				   dev->name, medianame[dev->if_port],				   ioread32(ioaddr + CSR12) & 0xff);	} else if (tp->chip_id == LC82C168) {		if (startup && ! tp->medialock)			dev->if_port = tp->mii_cnt ? 11 : 0;		if (tulip_debug > 1)			printk(KERN_DEBUG "%s: PNIC PHY status is %3.3x, media %s.\n",				   dev->name, ioread32(ioaddr + 0xB8), medianame[dev->if_port]);		if (tp->mii_cnt) {			new_csr6 = 0x810C0000;			iowrite32(0x0001, ioaddr + CSR15);			iowrite32(0x0201B07A, ioaddr + 0xB8);		} else if (startup) {			/* Start with 10mbps to do autonegotiation. */			iowrite32(0x32, ioaddr + CSR12);			new_csr6 = 0x00420000;			iowrite32(0x0001B078, ioaddr + 0xB8);			iowrite32(0x0201B078, ioaddr + 0xB8);		} else if (dev->if_port == 3  ||  dev->if_port == 5) {			iowrite32(0x33, ioaddr + CSR12);			new_csr6 = 0x01860000;			/* Trigger autonegotiation. */			iowrite32(startup ? 0x0201F868 : 0x0001F868, ioaddr + 0xB8);		} else {			iowrite32(0x32, ioaddr + CSR12);			new_csr6 = 0x00420000;			iowrite32(0x1F078, ioaddr + 0xB8);		}	} else {					/* Unknown chip type with no media table. */		if (tp->default_port == 0)			dev->if_port = tp->mii_cnt ? 11 : 3;		if (tulip_media_cap[dev->if_port] & MediaIsMII) {			new_csr6 = 0x020E0000;		} else if (tulip_media_cap[dev->if_port] & MediaIsFx) {			new_csr6 = 0x02860000;		} else			new_csr6 = 0x03860000;		if (tulip_debug > 1)			printk(KERN_DEBUG "%s: No media description table, assuming "				   "%s transceiver, CSR12 %2.2x.\n",				   dev->name, medianame[dev->if_port],				   ioread32(ioaddr + CSR12));	}	tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);	return;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/12755c16a9e4fa2fd5b0ca1963e83d671a6251da/media.c/clean/drivers/net/tulip/media.c