if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_MACRONIX) { if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_MACRONIX_MX98713) { if (PCI_REVISION(pa->pa_class) < MX_REVISION_98713A) sc->mx_type = MX_TYPE_98713; else sc->mx_type = MX_TYPE_98713A; } if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_MACRONIX_MX98715) { sc->mx_type = MX_TYPE_987x5; } }
if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_MACRONIX_MX98713 && PCI_REVISION(pa->pa_class) < MX_REVISION_98713A) sc->mx_type = MX_TYPE_98713; else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_COMPEX_98713 && PCI_REVISION(pa->pa_class) < MX_REVISION_98713A) sc->mx_type = MX_TYPE_98713; else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_MACRONIX_MX98713 && PCI_REVISION(pa->pa_class) >= MX_REVISION_98713A) sc->mx_type = MX_TYPE_98713A; else sc->mx_type = MX_TYPE_987x5;   sc->mx_cachesize = pci_conf_read(pa->pa_pc, pa->pa_tag, MX_PCI_CACHELEN) & 0xFF;  sc->mx_info.mx_vid = PCI_VENDOR(pa->pa_id); sc->mx_info.mx_did = PCI_PRODUCT(pa->pa_id);
mx_attach(parent, self, aux)	struct device *parent, *self;	void *aux;{	struct mx_softc *sc = (struct mx_softc *)self;	struct pci_attach_args *pa = aux;	pci_chipset_tag_t pc = pa->pa_pc;	pci_intr_handle_t ih;	const char *intrstr = NULL;	struct ifnet *ifp = &sc->arpcom.ac_if;	bus_addr_t iobase;	bus_size_t iosize;	unsigned int round;	caddr_t roundptr;	u_int32_t command;	u_int16_t phy_sts, phy_did, phy_vid, mac_offset = 0;	int s, i, media;	s = splimp();	sc->mx_unit = sc->sc_dev.dv_unit;	command = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);#ifdef MX_USEIOSPACE	if (!(command & PCI_COMMAND_IO_ENABLE)) {		printf(": failed to enable i/o ports\n");		goto fail;	}	if (pci_io_find(pc, pa->pa_tag, MX_PCI_LOIO, &iobase, &iosize)) {		printf(": can't find i/o space\n");		goto fail;	}	if (bus_space_map(pa->pa_iot, iobase, iosize, 0, &sc->mx_bhandle)) {		printf(": can't map i/o space\n");		goto fail;	}	sc->mx_btag = pa->pa_iot;#else	if (!(command & PCI_COMMAND_MEM_ENABLE)) {		printf(": failed to enable memory mapping\n");		goto fail;	}	if (pci_mem_find(pc, pa->pa_tag, MX_PCI_LOMEM, &iobase, &iosize)) {		printf(": can't find mem space\n");		goto fail;	}	if (bus_space_map(pa->pa_memt, iobase, iosize, 0, &sc->mx_bhandle)) {		printf(": can't map mem space\n");		goto fail;	}	sc->mx_btag = pa->pa_memt;#endif	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,	    pa->pa_intrline, &ih)) {		printf(": couldn't map interrupt\n");		goto fail;	}	intrstr = pci_intr_string(pc, ih);	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, mx_intr, sc,	    self->dv_xname);	if (sc->sc_ih == NULL) {		printf(": could not establish interrupt");		if (intrstr != NULL)			printf(" at %s", intrstr);		printf("\n");		goto fail;	}	printf(": %s", intrstr);	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_MACRONIX) {		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_MACRONIX_MX98713) {			if (PCI_REVISION(pa->pa_class) < MX_REVISION_98713A)				sc->mx_type = MX_TYPE_98713;			else				sc->mx_type = MX_TYPE_98713A;		}		if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_MACRONIX_MX98715) {			sc->mx_type = MX_TYPE_987x5;		}	}	mx_reset(sc);	mx_read_eeprom(sc, (caddr_t)&mac_offset,	    (MX_EE_NODEADDR_OFFSET / 2), 1, 0);	mx_read_eeprom(sc, (caddr_t)&sc->arpcom.ac_enaddr,	    (mac_offset / 2), 3, 0);	printf(" address %s\n", ether_sprintf(sc->arpcom.ac_enaddr));	sc->mx_ldata_ptr = malloc(sizeof(struct mx_list_data) + 8,	    M_DEVBUF, M_NOWAIT);	if (sc->mx_ldata_ptr == NULL) {		printf("%s: no memory for list buffers\n", sc->sc_dev.dv_xname);		goto fail;	}	sc->mx_ldata = (struct mx_list_data *)sc->mx_ldata_ptr;	round = (unsigned int)sc->mx_ldata_ptr & 0xf;	roundptr = sc->mx_ldata_ptr;	for (i = 0; i < 8; i++) {		if (round % 8) {			round++;			roundptr++;		}		else			break;	}	sc->mx_ldata = (struct mx_list_data *)roundptr;	bzero(sc->mx_ldata, sizeof(struct mx_list_data));	ifp = &sc->arpcom.ac_if;	ifp->if_softc = sc;	ifp->if_mtu = ETHERMTU;	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;	ifp->if_ioctl = mx_ioctl;	ifp->if_output = ether_output;	ifp->if_start = mx_start;	ifp->if_watchdog = mx_watchdog;	ifp->if_baudrate = 10000000;	ifp->if_snd.ifq_maxlen = MX_TX_LIST_CNT - 1;	bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);	if (sc->mx_type == MX_TYPE_98713) {		for (i = MX_PHYADDR_MIN; i < MX_PHYADDR_MAX + 1; i++) {			sc->mx_phy_addr = i;			mx_phy_writereg(sc, PHY_BMCR, PHY_BMCR_RESET);			while (mx_phy_readreg(sc, PHY_BMCR) & PHY_BMCR_RESET);			if ((phy_sts = mx_phy_readreg(sc, PHY_BMSR)))				break;		}		if (phy_sts) {			phy_vid = mx_phy_readreg(sc, PHY_VENID);			phy_did = mx_phy_readreg(sc, PHY_DEVID);			sc->mx_hasmii = 1;		}		else {			printf("%s: MII without any phy!\n",			    sc->sc_dev.dv_xname);			goto fail;		}	}	ifmedia_init(&sc->ifmedia, 0, mx_ifmedia_upd, mx_ifmedia_sts);	if (sc->mx_type == MX_TYPE_98713 && sc->mx_hasmii != 0) {		mx_getmode_mii(sc);		mx_autoneg_mii(sc, MX_FLAG_FORCEDELAY, 1);	} else {		ifmedia_add(&sc->ifmedia,			IFM_ETHER|IFM_10_T|IFM_HDX, 0, NULL);		ifmedia_add(&sc->ifmedia,			IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL);		ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);		ifmedia_add(&sc->ifmedia,			IFM_ETHER|IFM_100_TX|IFM_HDX, 0, NULL);		ifmedia_add(&sc->ifmedia,			IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL);		ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_TX, 0, NULL);		ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);		mx_autoneg(sc, MX_FLAG_FORCEDELAY, 1);	}	media = sc->ifmedia.ifm_media;	mx_stop(sc);	ifmedia_set(&sc->ifmedia, media);	if_attach(ifp);	ether_ifattach(ifp);#if NBPFILTER > 0	bpfattach(&sc->arpcom.ac_if.if_bpf, ifp,	    DLT_EN10MB, sizeof(struct ether_header));#endif	shutdownhook_establish(mx_shutdown, sc);fail:	splx(s);}