if (!in_interrupt()) { set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(1); } 
if (!in_interrupt()) schedule_timeout_interruptible(1); 
static int hp100_login_to_vg_hub(struct net_device *dev, u_short force_relogin){	int ioaddr = dev->base_addr;	struct hp100_private *lp = netdev_priv(dev);	u_short val = 0;	unsigned long time;	int startst;#ifdef HP100_DEBUG_B	hp100_outw(0x4225, TRACE);	printk("hp100: %s: login_to_vg_hub\n", dev->name);#endif	/* Initiate a login sequence iff VG MAC is enabled and either Load Address	 * bit is zero or the force relogin flag is set (e.g. due to MAC address or	 * promiscuous mode change)	 */	hp100_page(MAC_CTRL);	startst = hp100_inb(VG_LAN_CFG_1);	if ((force_relogin == 1) || (hp100_inb(MAC_CFG_4) & HP100_MAC_SEL_ST)) {#ifdef HP100_DEBUG_TRAINING		printk("hp100: %s: Start training\n", dev->name);#endif		/* Ensure VG Reset bit is 1 (i.e., do not reset) */		hp100_orb(HP100_VG_RESET, VG_LAN_CFG_1);		/* If Lassen AND auto-select-mode AND VG tones were sensed on */		/* entry then temporarily put them into force 100Mbit mode */		if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST))			hp100_andb(~HP100_DOT3_MAC, 10_LAN_CFG_2);		/* Drop the VG link by zeroing Link Up Command and Load Address  */		hp100_andb(~(HP100_LINK_CMD /* |HP100_LOAD_ADDR */ ), VG_LAN_CFG_1);#ifdef HP100_DEBUG_TRAINING		printk("hp100: %s: Bring down the link\n", dev->name);#endif		/* Wait for link to drop */		time = jiffies + (HZ / 10);		do {			if (~(hp100_inb(VG_LAN_CFG_1) & HP100_LINK_UP_ST))				break;			if (!in_interrupt()) {				set_current_state(TASK_INTERRUPTIBLE);				schedule_timeout(1);			}		} while (time_after(time, jiffies));		/* Start an addressed training and optionally request promiscuous port */		if ((dev->flags) & IFF_PROMISC) {			hp100_orb(HP100_PROM_MODE, VG_LAN_CFG_2);			if (lp->chip == HP100_CHIPID_LASSEN)				hp100_orw(HP100_MACRQ_PROMSC, TRAIN_REQUEST);		} else {			hp100_andb(~HP100_PROM_MODE, VG_LAN_CFG_2);			/* For ETR parts we need to reset the prom. bit in the training			 * register, otherwise promiscious mode won't be disabled.			 */			if (lp->chip == HP100_CHIPID_LASSEN) {				hp100_andw(~HP100_MACRQ_PROMSC, TRAIN_REQUEST);			}		}		/* With ETR parts, frame format request bits can be set. */		if (lp->chip == HP100_CHIPID_LASSEN)			hp100_orb(HP100_MACRQ_FRAMEFMT_EITHER, TRAIN_REQUEST);		hp100_orb(HP100_LINK_CMD | HP100_LOAD_ADDR | HP100_VG_RESET, VG_LAN_CFG_1);		/* Note: Next wait could be omitted for Hood and earlier chips under */		/* certain circumstances */		/* TODO: check if hood/earlier and skip wait. */		/* Wait for either short timeout for VG tones or long for login    */		/* Wait for the card hardware to signalise link cable status ok... */		hp100_page(MAC_CTRL);		time = jiffies + (1 * HZ);	/* 1 sec timeout for cable st */		do {			if (hp100_inb(VG_LAN_CFG_1) & HP100_LINK_CABLE_ST)				break;			if (!in_interrupt()) {				set_current_state(TASK_INTERRUPTIBLE);				schedule_timeout(1);			}		} while (time_before(jiffies, time));		if (time_after_eq(jiffies, time)) {#ifdef HP100_DEBUG_TRAINING			printk("hp100: %s: Link cable status not ok? Training aborted.\n", dev->name);#endif		} else {#ifdef HP100_DEBUG_TRAINING			printk			    ("hp100: %s: HUB tones detected. Trying to train.\n",			     dev->name);#endif			time = jiffies + (2 * HZ);	/* again a timeout */			do {				val = hp100_inb(VG_LAN_CFG_1);				if ((val & (HP100_LINK_UP_ST))) {#ifdef HP100_DEBUG_TRAINING					printk("hp100: %s: Passed training.\n", dev->name);#endif					break;				}				if (!in_interrupt()) {					set_current_state(TASK_INTERRUPTIBLE);					schedule_timeout(1);				}			} while (time_after(time, jiffies));		}		/* If LINK_UP_ST is set, then we are logged into the hub. */		if (time_before_eq(jiffies, time) && (val & HP100_LINK_UP_ST)) {#ifdef HP100_DEBUG_TRAINING			printk("hp100: %s: Successfully logged into the HUB.\n", dev->name);			if (lp->chip == HP100_CHIPID_LASSEN) {				val = hp100_inw(TRAIN_ALLOW);				printk("hp100: %s: Card supports 100VG MAC Version \"%s\" ",					     dev->name, (hp100_inw(TRAIN_REQUEST) & HP100_CARD_MACVER) ? "802.12" : "Pre");				printk("Driver will use MAC Version \"%s\"\n", (val & HP100_HUB_MACVER) ? "802.12" : "Pre");				printk("hp100: %s: Frame format is %s.\n", dev->name, (val & HP100_MALLOW_FRAMEFMT) ? "802.5" : "802.3");			}#endif		} else {			/* If LINK_UP_ST is not set, login was not successful */			printk("hp100: %s: Problem logging into the HUB.\n", dev->name);			if (lp->chip == HP100_CHIPID_LASSEN) {				/* Check allowed Register to find out why there is a problem. */				val = hp100_inw(TRAIN_ALLOW);	/* won't work on non-ETR card */#ifdef HP100_DEBUG_TRAINING				printk("hp100: %s: MAC Configuration requested: 0x%04x, HUB allowed: 0x%04x\n", dev->name, hp100_inw(TRAIN_REQUEST), val);#endif				if (val & HP100_MALLOW_ACCDENIED)					printk("hp100: %s: HUB access denied.\n", dev->name);				if (val & HP100_MALLOW_CONFIGURE)					printk("hp100: %s: MAC Configuration is incompatible with the Network.\n", dev->name);				if (val & HP100_MALLOW_DUPADDR)					printk("hp100: %s: Duplicate MAC Address on the Network.\n", dev->name);			}		}		/* If we have put the chip into forced 100 Mbit mode earlier, go back */		/* to auto-select mode */		if ((lp->chip == HP100_CHIPID_LASSEN) && (startst & HP100_LINK_CABLE_ST)) {			hp100_page(MAC_CTRL);			hp100_orb(HP100_DOT3_MAC, 10_LAN_CFG_2);		}		val = hp100_inb(VG_LAN_CFG_1);		/* Clear the MISC_ERROR Interrupt, which might be generated when doing the relogin */		hp100_page(PERFORMANCE);		hp100_outw(HP100_MISC_ERROR, IRQ_STATUS);		if (val & HP100_LINK_UP_ST)			return (0);	/* login was ok */		else {			printk("hp100: %s: Training failed.\n", dev->name);			hp100_down_vg_link(dev);			return -EIO;		}	}	/* no forced relogin & already link there->no training. */	return -EIO;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/3173c8907ffb2c64456142da3df2bd0500bd59e0/hp100.c/clean/drivers/net/hp100.c