⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xircom_tulip_cb.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
				csr14val = setup[1];				csr15dir = (setup[3]<<16) | setup[2];				csr15val = (setup[4]<<16) | setup[2];				outl(0, ioaddr + CSR13);				outl(csr14val, ioaddr + CSR14);				outl(csr15dir, ioaddr + CSR15);	/* Direction */				outl(csr15val, ioaddr + CSR15);	/* Data */				outl(csr13val, ioaddr + CSR13);			} else {				csr13val = 1;				csr14val = 0x0003FF7F;				csr15dir = (setup[0]<<16) | 0x0008;				csr15val = (setup[1]<<16) | 0x0008;				if (dev->if_port <= 4)					csr14val = t21142_csr14[dev->if_port];				if (startup) {					outl(0, ioaddr + CSR13);					outl(csr14val, ioaddr + CSR14);				}				outl(csr15dir, ioaddr + CSR15);	/* Direction */				outl(csr15val, ioaddr + CSR15);	/* Data */				if (startup) outl(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;			u16 to_advertise;			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++)						outl(get_u16(&reset_sequence[i]) << 16, ioaddr + CSR15);				for (i = 0; i < init_length; i++)					outl(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) {					outl(mtable->csr12dir | 0x100, ioaddr + CSR12);					for (i = 0; i < reset_length; i++)						outl(reset_sequence[i], ioaddr + CSR12);				}				for (i = 0; i < init_length; i++)					outl(init_sequence[i], ioaddr + CSR12);			}			to_advertise = (get_u16(&misc_info[1]) & tp->to_advertise) | 1;			tp->advertising[phy_num] = to_advertise;			if (tulip_debug > 1)				printk(KERN_DEBUG "%s:  Advertising %4.4x on PHY %d (%d).\n",					   dev->name, to_advertise, phy_num, tp->phys[phy_num]);			/* Bogus: put in by a committee?  */			mdio_write(dev, tp->phys[phy_num], 4, to_advertise);			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],				   inl(ioaddr + CSR12) & 0xff);	} else if (tp->chip_id == DC21041) {		if (tulip_debug > 1)			printk(KERN_DEBUG "%s: 21041 using media %s, CSR12 is %4.4x.\n",				   dev->name, medianame[dev->if_port & 15],				   inl(ioaddr + CSR12) & 0xffff);		outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */		outl(t21041_csr14[dev->if_port], ioaddr + CSR14);		outl(t21041_csr15[dev->if_port], ioaddr + CSR15);		outl(t21041_csr13[dev->if_port], ioaddr + CSR13);		new_csr6 = 0x80020000;	} else if (tp->chip_id == LC82C168 || tp->chip_id == PNIC2) {		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, CSR12 %4.4x,"				   " media %s.\n",				   dev->name, inl(ioaddr + 0xB8), inl(ioaddr + CSR12),				   medianame[dev->if_port]);		if (tp->mii_cnt) {			new_csr6 = 0x810C0000;			outl(0x0001, ioaddr + CSR15);			outl(0x0201B07A, ioaddr + 0xB8);		} else if (startup) {			/* Start with 10mbps to do autonegotiation. */			outl(0x32, ioaddr + CSR12);			new_csr6 = 0x00420000;			outl(0x0001B078, ioaddr + 0xB8);			outl(0x0201B078, ioaddr + 0xB8);		} else if (dev->if_port == 3  ||  dev->if_port == 5) {			outl(0x33, ioaddr + CSR12);			new_csr6 = 0x01860000;			if (startup)				outl(0x0201F868, ioaddr + 0xB8); /* Trigger autonegotiation. */			else				outl(0x1F868, ioaddr + 0xB8);		} else {			outl(0x32, ioaddr + CSR12);			new_csr6 = 0x00420000;			outl(0x1F078, ioaddr + 0xB8);		}	} else if (tp->chip_id == DC21040) {					/* 21040 */		/* Turn on the xcvr interface. */		int csr12 = inl(ioaddr + CSR12);		if (tulip_debug > 1)			printk(KERN_DEBUG "%s: 21040 media type is %s, CSR12 is %2.2x.\n",				   dev->name, medianame[dev->if_port], csr12);		if (media_cap[dev->if_port] & MediaAlwaysFD)			tp->full_duplex = 1;		new_csr6 = 0x20000;		/* Set the full duplux match frame. */		outl(FULL_DUPLEX_MAGIC, ioaddr + CSR11);		outl(0x00000000, ioaddr + CSR13); /* Reset the serial interface */		if (t21040_csr13[dev->if_port] & 8) {			outl(0x0705, ioaddr + CSR14);			outl(0x0006, ioaddr + CSR15);		} else {			outl(0xffff, ioaddr + CSR14);			outl(0x0000, ioaddr + CSR15);		}		outl(0x8f01 | t21040_csr13[dev->if_port], ioaddr + CSR13);	} else if (tp->chip_id == X3201_3) {					/* Xircom */		if (tp->default_port == 0)			dev->if_port = tp->mii_cnt ? 11 : 3;/* Someone is on crack, the Xircom only does MII, no Fx *//*		if (media_cap[dev->if_port] & MediaIsMII) {			new_csr6 = 0x020E0000;		} else if (media_cap[dev->if_port] & MediaIsFx) {			new_csr6 = 0x028600000;		} else			new_csr6 = 0x038600000;*/		new_csr6 = 0x324c0000;		if (tulip_debug > 1)			printk(KERN_DEBUG "%s: Xircom CardBus Adapter: "				   "%s transceiver, CSR12 %2.2x.\n",				   dev->name, medianame[dev->if_port],				   inl(ioaddr + CSR12));	} else {					/* Unknown chip type with no media table. */		if (tp->default_port == 0)			dev->if_port = tp->mii_cnt ? 11 : 3;		if (media_cap[dev->if_port] & MediaIsMII) {			new_csr6 = 0x020E0000;		} else if (media_cap[dev->if_port] & MediaIsFx) {			new_csr6 = 0x028600000;		} else			new_csr6 = 0x038600000;		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],				   inl(ioaddr + CSR12));	}	tp->csr6 = new_csr6 | (tp->csr6 & 0xfdff) | (tp->full_duplex ? 0x0200 : 0);	return;}/*  Check the MII negotiated duplex, and change the CSR6 setting if  required.  Return 0 if everything is OK.  Return < 0 if the transceiver is missing or has no link beat.  */static int check_duplex(struct net_device *dev){	long ioaddr = dev->base_addr;	struct tulip_private *tp = (struct tulip_private *)dev->priv;	int mii_reg1, mii_reg5, negotiated, duplex;	if (tp->full_duplex_lock)		return 0;	mii_reg1 = mdio_read(dev, tp->phys[0], 1);	mii_reg5 = mdio_read(dev, tp->phys[0], 5);	if (tulip_debug > 1)		printk(KERN_INFO "%s: MII status %4.4x, Link partner report "			   "%4.4x.\n", dev->name, mii_reg1, mii_reg5);	if (mii_reg1 == 0xffff)		return -2;	if ((mii_reg1 & 0x0004) == 0) {		int new_reg1 = mdio_read(dev, tp->phys[0], 1);		if ((new_reg1 & 0x0004) == 0) {			if (tulip_debug  > 1)				printk(KERN_INFO "%s: No link beat on the MII interface,"					   " status %4.4x.\n", dev->name, new_reg1);			return -1;		}	}	negotiated = mii_reg5 & tp->advertising[0];	duplex = ((negotiated & 0x0300) == 0x0100			  || (negotiated & 0x00C0) == 0x0040);	/* 100baseTx-FD  or  10T-FD, but not 100-HD */	if (tp->full_duplex != duplex) {		tp->full_duplex = duplex;		if (tp->full_duplex) tp->csr6 |= 0x0200;		else				 tp->csr6 &= ~0x0200;		outl_CSR6(tp->csr6 | 0x0002, ioaddr, tp->chip_id);		outl_CSR6(tp->csr6 | 0x2002, ioaddr, tp->chip_id);		if (tulip_debug > 0)			printk(KERN_INFO "%s: Setting %s-duplex based on MII"				   "#%d link partner capability of %4.4x.\n",				   dev->name, tp->full_duplex ? "full" : "half",				   tp->phys[0], mii_reg5);	}	return 0;}static void tulip_timer(unsigned long data){	struct net_device *dev = (struct net_device *)data;	struct tulip_private *tp = (struct tulip_private *)dev->priv;	long ioaddr = dev->base_addr;	u32 csr12 = inl(ioaddr + CSR12);	int next_tick = 2*HZ;	if (tulip_debug > 2) {		printk(KERN_DEBUG "%s: Media selection tick, status %8.8x mode %8.8x "			   "SIA %8.8x %8.8x %8.8x %8.8x.\n",			   dev->name, inl(ioaddr + CSR5), inl(ioaddr + CSR6),			   csr12, inl(ioaddr + CSR13),			   inl(ioaddr + CSR14), inl(ioaddr + CSR15));	}	switch (tp->chip_id) {	case DC21040:		if (!tp->medialock  &&  csr12 & 0x0002) { /* Network error */			printk(KERN_INFO "%s: No link beat found.\n",				   dev->name);			dev->if_port = (dev->if_port == 2 ? 0 : 2);			select_media(dev, 0);			dev->trans_start = jiffies;		}		break;	case DC21041:		if (tulip_debug > 2)			printk(KERN_DEBUG "%s: 21041 media tick  CSR12 %8.8x.\n",				   dev->name, csr12);		switch (dev->if_port) {		case 0: case 3: case 4:		  if (csr12 & 0x0004) { /*LnkFail */			/* 10baseT is dead.  Check for activity on alternate port. */			tp->mediasense = 1;			if (csr12 & 0x0200)				dev->if_port = 2;			else				dev->if_port = 1;			printk(KERN_INFO "%s: No 21041 10baseT link beat, Media switched to %s.\n",				   dev->name, medianame[dev->if_port]);			outl(0, ioaddr + CSR13); /* Reset */			outl(t21041_csr14[dev->if_port], ioaddr + CSR14);			outl(t21041_csr15[dev->if_port], ioaddr + CSR15);			outl(t21041_csr13[dev->if_port], ioaddr + CSR13);			next_tick = 10*HZ;			/* 2.4 sec. */		  } else			next_tick = 30*HZ;		  break;		case 1:					/* 10base2 */		case 2:					/* AUI */			if (csr12 & 0x0100) {				next_tick = (30*HZ);			/* 30 sec. */				tp->mediasense = 0;			} else if ((csr12 & 0x0004) == 0) {				printk(KERN_INFO "%s: 21041 media switched to 10baseT.\n",					   dev->name);				dev->if_port = 0;				select_media(dev, 0);				next_tick = (24*HZ)/10;				/* 2.4 sec. */			} else if (tp->mediasense || (csr12 & 0x0002)) {				dev->if_port = 3 - dev->if_port; /* Swap ports. */				select_media(dev, 0);				next_tick = 20*HZ;			} else {				next_tick = 20*HZ;			}			break;		}		break;	case DC21140:  case DC21142: case MX98713: case COMPEX9881: default: {		struct medialeaf *mleaf;		unsigned char *p;		if (tp->mtable == NULL) {	/* No EEPROM info, use generic code. */			/* Not much that can be done.			   Assume this a generic MII or SYM transceiver. */			next_tick = 60*HZ;			if (tulip_debug > 2)				printk(KERN_DEBUG "%s: network media monitor CSR6 %8.8x "					   "CSR12 0x%2.2x.\n",					   dev->name, inl(ioaddr + CSR6), csr12 & 0xff);			break;		}		mleaf = &tp->mtable->mleaf[tp->cur_index];		p = mleaf->leafdata;		switch (mleaf->type) {		case 0: case 4: {			/* Type 0 serial or 4 SYM transceiver.  Check the link beat bit. */			int offset = mleaf->type == 4 ? 5 : 2;			s8 bitnum = p[offset];			if (p[offset+1] & 0x80) {				if (tulip_debug > 1)					printk(KERN_DEBUG"%s: Transceiver monitor tick "						   "CSR12=%#2.2x, no media sense.\n",						   dev->name, csr12);				if (mleaf->type == 4) {					if (mleaf->media == 3 && (csr12 & 0x02))						goto select_next_media;				}				break;			}			if (tulip_debug > 2)				printk(KERN_DEBUG "%s: Transceiver monitor tick: CSR12=%#2.2x"					   " bit %d is %d, expecting %d.\n",					   dev->name, csr12, (bitnum >> 1) & 7,					   (csr12 & (1 << ((bitnum >> 1) & 7))) != 0,					   (bitnum >= 0));			/* Check that the specified bit has the proper value. */			if ((bitnum < 0) !=				((csr12 & (1 << ((bitnum >> 1) & 7))) != 0)) {				if (tulip_debug > 1)					printk(KERN_DEBUG "%s: Link beat detected for %s.\n", dev->name,						   medianame[mleaf->media]);				if ((p[2] & 0x61) == 0x01)	/* Bogus Znyx board. */					goto actually_mii;				break;			}			if (tp->medialock)				break;	  select_next_media:			if (--tp->cur_index < 0) {				/* We start again, but should instead look for default. */				tp->cur_index = tp->mtable->leafcount - 1;			}			dev->if_port = tp->mtable->mleaf[tp->cur_index].media;			if (media_cap[dev->if_port] & MediaIsFD)				goto select_next_media; /* Skip FD entries. */			if (tulip_debug > 1)				printk(KERN_DEBUG "%s: No link beat on media %s,"					   " trying transceiver type %s.\n",					   dev->name, medianame[mleaf->media & 15],					   medianame[tp->mtable->mleaf[tp->cur_index].media]);			select_media(dev, 0);			/* Restart the transmit process. */			outl_CSR6(tp->csr6 | 0x0002, ioaddr, tp->chip_id);			outl_CSR6(tp->csr6 | 0x2002, ioaddr, tp->chip_id);			next_tick = (24*HZ)/10;			break;		}		case 1:  case 3:		/* 21140, 21142 MII */		actually_mii:			check_duplex(dev);			next_tick = 60*HZ;			break;		case 2:					/* 21142 serial block has no link beat. */		default:			break;		}	}	break;	}	tp->timer.expires = RUN_AT(next_tick);	add_timer(&tp->timer);}/* Handle th

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -