else { ep->want_autoneg = 0;  /* Select highest supported speed/duplex */ if (ep->phy_mii.def->features & SUPPORTED_1000baseT_Full) { ep->phy_mii.speed = SPEED_1000; ep->phy_mii.duplex = DUPLEX_FULL; } else if (ep->phy_mii.def->features & SUPPORTED_1000baseT_Half) { ep->phy_mii.speed = SPEED_1000; ep->phy_mii.duplex = DUPLEX_HALF; } else if (ep->phy_mii.def->features & SUPPORTED_100baseT_Full) { ep->phy_mii.speed = SPEED_100; ep->phy_mii.duplex = DUPLEX_FULL; } else if (ep->phy_mii.def->features & SUPPORTED_100baseT_Half) { ep->phy_mii.speed = SPEED_100; ep->phy_mii.duplex = DUPLEX_HALF; } else if (ep->phy_mii.def->features & SUPPORTED_10baseT_Full) { ep->phy_mii.speed = SPEED_10; ep->phy_mii.duplex = DUPLEX_FULL; } else { ep->phy_mii.speed = SPEED_10; ep->phy_mii.duplex = DUPLEX_HALF; } } 
static int emac_init_device(struct ocp_device *ocpdev, struct ibm_ocp_mal *mal){	int deferred_init = 0;	int rc = 0, i;	struct net_device *ndev;	struct ocp_enet_private *ep;	struct ocp_func_emac_data *emacdata;	int commac_reg = 0;	u32 phy_map;	emacdata = (struct ocp_func_emac_data *)ocpdev->def->additions;	if (!emacdata) {		printk(KERN_ERR "emac%d: Missing additional data!\n",		       ocpdev->def->index);		return -ENODEV;	}	/* Allocate our net_device structure */	ndev = alloc_etherdev(sizeof(struct ocp_enet_private));	if (ndev == NULL) {		printk(KERN_ERR		       "emac%d: Could not allocate ethernet device.\n",		       ocpdev->def->index);		return -ENOMEM;	}	ep = ndev->priv;	ep->ndev = ndev;	ep->ocpdev = ocpdev;	ndev->irq = ocpdev->def->irq;	ep->wol_irq = emacdata->wol_irq;	if (emacdata->mdio_idx >= 0) {		if (emacdata->mdio_idx == ocpdev->def->index) {			/* Set the common MDIO net_device */			mdio_ndev = ndev;			deferred_init = 1;		}		ep->mdio_dev = mdio_ndev;	} else {		ep->mdio_dev = ndev;	}	ocp_set_drvdata(ocpdev, ndev);	spin_lock_init(&ep->lock);	/* Fill out MAL informations and register commac */	ep->mal = mal;	ep->mal_tx_chan = emacdata->mal_tx_chan;	ep->mal_rx_chan = emacdata->mal_rx_chan;	ep->commac.ops = &emac_commac_ops;	ep->commac.dev = ndev;	ep->commac.tx_chan_mask = MAL_CHAN_MASK(ep->mal_tx_chan);	ep->commac.rx_chan_mask = MAL_CHAN_MASK(ep->mal_rx_chan);	rc = mal_register_commac(ep->mal, &ep->commac);	if (rc != 0)		goto bail;	commac_reg = 1;	/* Map our MMIOs */	ep->emacp = (emac_t *) ioremap(ocpdev->def->paddr, sizeof(emac_t));	/* Check if we need to attach to a ZMII */	if (emacdata->zmii_idx >= 0) {		ep->zmii_input = emacdata->zmii_mux;		ep->zmii_dev =		    ocp_find_device(OCP_ANY_ID, OCP_FUNC_ZMII,				    emacdata->zmii_idx);		if (ep->zmii_dev == NULL)			printk(KERN_WARNING			       "emac%d: ZMII %d requested but not found !\n",			       ocpdev->def->index, emacdata->zmii_idx);		else if ((rc =			  emac_init_zmii(ep->zmii_dev, ep->zmii_input,					 emacdata->phy_mode)) != 0)			goto bail;	}	/* Check if we need to attach to a RGMII */	if (emacdata->rgmii_idx >= 0) {		ep->rgmii_input = emacdata->rgmii_mux;		ep->rgmii_dev =		    ocp_find_device(OCP_ANY_ID, OCP_FUNC_RGMII,				    emacdata->rgmii_idx);		if (ep->rgmii_dev == NULL)			printk(KERN_WARNING			       "emac%d: RGMII %d requested but not found !\n",			       ocpdev->def->index, emacdata->rgmii_idx);		else if ((rc =			  emac_init_rgmii(ep->rgmii_dev, ep->rgmii_input,					  emacdata->phy_mode)) != 0)			goto bail;	}	/* Check if we need to attach to a TAH */	if (emacdata->tah_idx >= 0) {		ep->tah_dev =		    ocp_find_device(OCP_ANY_ID, OCP_FUNC_TAH,				    emacdata->tah_idx);		if (ep->tah_dev == NULL)			printk(KERN_WARNING			       "emac%d: TAH %d requested but not found !\n",			       ocpdev->def->index, emacdata->tah_idx);		else if ((rc = emac_init_tah(ep)) != 0)			goto bail;	}	if (deferred_init) {		if (!list_empty(&emac_init_list)) {			struct list_head *entry;			struct emac_def_dev *ddev;			list_for_each(entry, &emac_init_list) {				ddev =				    list_entry(entry, struct emac_def_dev,					       link);				emac_init_device(ddev->ocpdev, ddev->mal);			}		}	}	/* Init link monitoring timer */	init_timer(&ep->link_timer);	ep->link_timer.function = emac_link_timer;	ep->link_timer.data = (unsigned long)ep;	ep->timer_ticks = 0;	/* Fill up the mii_phy structure */	ep->phy_mii.dev = ndev;	ep->phy_mii.mdio_read = emac_phy_read;	ep->phy_mii.mdio_write = emac_phy_write;	ep->phy_mii.mode = emacdata->phy_mode;	/* Find PHY */	phy_map = emacdata->phy_map | busy_phy_map;	for (i = 0; i <= 0x1f; i++, phy_map >>= 1) {		if ((phy_map & 0x1) == 0) {			int val = emac_phy_read(ndev, i, MII_BMCR);			if (val != 0xffff && val != -1)				break;		}	}	if (i == 0x20) {		printk(KERN_WARNING "emac%d: Can't find PHY.\n",		       ocpdev->def->index);		rc = -ENODEV;		goto bail;	}	busy_phy_map |= 1 << i;	ep->mii_phy_addr = i;	rc = mii_phy_probe(&ep->phy_mii, i);	if (rc) {		printk(KERN_WARNING "emac%d: Failed to probe PHY type.\n",		       ocpdev->def->index);		rc = -ENODEV;		goto bail;	}	/* Setup initial PHY config & startup aneg */	if (ep->phy_mii.def->ops->init)		ep->phy_mii.def->ops->init(&ep->phy_mii);	netif_carrier_off(ndev);	if (ep->phy_mii.def->features & SUPPORTED_Autoneg)		ep->want_autoneg = 1;	emac_start_link(ep, NULL);	/* read the MAC Address */	for (i = 0; i < 6; i++)		ndev->dev_addr[i] = emacdata->mac_addr[i];	/* Fill in the driver function table */	ndev->open = &emac_open;	ndev->hard_start_xmit = &emac_start_xmit;	ndev->stop = &emac_close;	ndev->get_stats = &emac_stats;	if (emacdata->jumbo)		ndev->change_mtu = &emac_change_mtu;	ndev->set_mac_address = &emac_set_mac_address;	ndev->set_multicast_list = &emac_set_multicast_list;	ndev->do_ioctl = &emac_ioctl;	SET_ETHTOOL_OPS(ndev, &emac_ethtool_ops);	if (emacdata->tah_idx >= 0)		ndev->features = NETIF_F_IP_CSUM | NETIF_F_SG;#ifdef CONFIG_NET_POLL_CONTROLLER	ndev->poll_controller = emac_netpoll;#endif	SET_MODULE_OWNER(ndev);	rc = register_netdev(ndev);	if (rc != 0)		goto bail;	printk("%s: IBM emac, MAC %02x:%02x:%02x:%02x:%02x:%02x\n",	       ndev->name,	       ndev->dev_addr[0], ndev->dev_addr[1], ndev->dev_addr[2],	       ndev->dev_addr[3], ndev->dev_addr[4], ndev->dev_addr[5]);	printk(KERN_INFO "%s: Found %s PHY (0x%02x)\n",	       ndev->name, ep->phy_mii.def->name, ep->mii_phy_addr);      bail:	if (rc && commac_reg)		mal_unregister_commac(ep->mal, &ep->commac);	if (rc && ndev)		kfree(ndev);	return rc;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/49a9db07abd4ac89693dbd4dcd92fcd1f30ece00/ibm_emac_core.c/buggy/drivers/net/ibm_emac/ibm_emac_core.c