FreeBSD/sys/dev/ste/if_ste.c
/*
 * Attach the interface. Allocate softc structures, do ifmedia
 * setup and ethernet/BPF attach.
 */
Attach the interface. Allocate softc structures, do ifmedia
setup and ethernet/BPF attach.
Attach the interface . Allocate softc structures do ifmedia setup and ethernet / BPF attach .
static int
ste_attach(device_t dev)
{
	struct ste_softc *sc;
	struct ifnet *ifp;
	uint16_t eaddr[ETHER_ADDR_LEN / 2];
	int error = 0, phy, pmc, prefer_iomap, rid;
	sc = device_get_softc(dev);
	sc->ste_dev = dev;
	if (pci_get_vendor(dev) == DL_VENDORID &&
	    pci_get_device(dev) == DL_DEVICEID_DL10050 &&
	    pci_get_revid(dev) == 0x12 )
		sc->ste_flags |= STE_FLAG_ONE_PHY;
	mtx_init(&sc->ste_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
	    MTX_DEF);
	pci_enable_busmaster(dev);
	prefer_iomap = 0;
	if (pci_get_device(dev) == ST_DEVICEID_ST201_1)
		prefer_iomap = 1;
	else
		resource_int_value(device_get_name(sc->ste_dev),
		    device_get_unit(sc->ste_dev), "prefer_iomap",
		    &prefer_iomap);
	if (prefer_iomap == 0) {
		sc->ste_res_id = PCIR_BAR(1);
		sc->ste_res_type = SYS_RES_MEMORY;
		sc->ste_res = bus_alloc_resource_any(dev, sc->ste_res_type,
		    &sc->ste_res_id, RF_ACTIVE);
	}
	if (prefer_iomap || sc->ste_res == NULL) {
		sc->ste_res_id = PCIR_BAR(0);
		sc->ste_res_type = SYS_RES_IOPORT;
		sc->ste_res = bus_alloc_resource_any(dev, sc->ste_res_type,
		    &sc->ste_res_id, RF_ACTIVE);
	}
	if (sc->ste_res == NULL) {
		device_printf(dev, "couldn't map ports/memory\n");
		error = ENXIO;
		goto fail;
	}
	rid = 0;
	sc->ste_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
	    RF_SHAREABLE | RF_ACTIVE);
	if (sc->ste_irq == NULL) {
		device_printf(dev, "couldn't map interrupt\n");
		error = ENXIO;
		goto fail;
	}
	callout_init_mtx(&sc->ste_callout, &sc->ste_mtx, 0);
	ste_reset(sc);
	if (ste_read_eeprom(sc, eaddr, STE_EEADDR_NODE0, ETHER_ADDR_LEN / 2)) {
		device_printf(dev, "failed to read station address\n");
		error = ENXIO;
		goto fail;
	}
	ste_sysctl_node(sc);
	if ((error = ste_dma_alloc(sc)) != 0)
		goto fail;
	ifp = sc->ste_ifp = if_alloc(IFT_ETHER);
	if (ifp == NULL) {
		device_printf(dev, "can not if_alloc()\n");
		error = ENOSPC;
		goto fail;
	}
	phy = MII_PHY_ANY;
	if ((sc->ste_flags & STE_FLAG_ONE_PHY) != 0)
		phy = 0;
	error = mii_attach(dev, &sc->ste_miibus, ifp, ste_ifmedia_upd,
		ste_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
	if (error != 0) {
		device_printf(dev, "attaching PHYs failed\n");
		goto fail;
	}
	ifp->if_softc = sc;
	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
	ifp->if_ioctl = ste_ioctl;
	ifp->if_start = ste_start;
	ifp->if_init = ste_init;
	IFQ_SET_MAXLEN(&ifp->if_snd, STE_TX_LIST_CNT - 1);
	ifp->if_snd.ifq_drv_maxlen = STE_TX_LIST_CNT - 1;
	IFQ_SET_READY(&ifp->if_snd);
	sc->ste_tx_thresh = STE_TXSTART_THRESH;
	ether_ifattach(ifp, (uint8_t *)eaddr);
	ifp->if_hdrlen = sizeof(struct ether_vlan_header);
	ifp->if_capabilities |= IFCAP_VLAN_MTU;
	if (pci_find_cap(dev, PCIY_PMG, &pmc) == 0)
		ifp->if_capabilities |= IFCAP_WOL_MAGIC;
	ifp->if_capenable = ifp->if_capabilities;
#ifdef DEVICE_POLLING
	ifp->if_capabilities |= IFCAP_POLLING;
#endif
	error = bus_setup_intr(dev, sc->ste_irq, INTR_TYPE_NET | INTR_MPSAFE,
	    NULL, ste_intr, sc, &sc->ste_intrhand);
	if (error) {
		device_printf(dev, "couldn't set up irq\n");
		ether_ifdetach(ifp);
		goto fail;
	}
fail:
	if (error)
		ste_detach(dev);
	return (error);
}
static int ste_attach ( device_t dev ) { struct ste_softc * sc ; struct ifnet * ifp ; uint16_t eaddr [ ETHER_ADDR_LEN / 2 ] ; int error = 0 , phy , pmc , prefer_iomap , rid ; sc = device_get_softc ( dev ) ; sc -> ste_dev = dev ; if ( pci_get_vendor ( dev ) == DL_VENDORID && pci_get_device ( dev ) == DL_DEVICEID_DL10050 && pci_get_revid ( dev ) == 0x12 ) sc -> ste_flags |= STE_FLAG_ONE_PHY ; mtx_init ( & sc -> ste_mtx , device_get_nameunit ( dev ) , MTX_NETWORK_LOCK , MTX_DEF ) ; pci_enable_busmaster ( dev ) ; prefer_iomap = 0 ; if ( pci_get_device ( dev ) == ST_DEVICEID_ST201_1 ) prefer_iomap = 1 ; else resource_int_value ( device_get_name ( sc -> ste_dev ) , device_get_unit ( sc -> ste_dev ) , " " , & prefer_iomap ) ; if ( prefer_iomap == 0 ) { sc -> ste_res_id = PCIR_BAR ( 1 ) ; sc -> ste_res_type = SYS_RES_MEMORY ; sc -> ste_res = bus_alloc_resource_any ( dev , sc -> ste_res_type , & sc -> ste_res_id , RF_ACTIVE ) ; } if ( prefer_iomap || sc -> ste_res == NULL ) { sc -> ste_res_id = PCIR_BAR ( 0 ) ; sc -> ste_res_type = SYS_RES_IOPORT ; sc -> ste_res = bus_alloc_resource_any ( dev , sc -> ste_res_type , & sc -> ste_res_id , RF_ACTIVE ) ; } if ( sc -> ste_res == NULL ) { device_printf ( dev , " \n " ) ; error = ENXIO ; goto fail ; } rid = 0 ; sc -> ste_irq = bus_alloc_resource_any ( dev , SYS_RES_IRQ , & rid , RF_SHAREABLE | RF_ACTIVE ) ; if ( sc -> ste_irq == NULL ) { device_printf ( dev , " \n " ) ; error = ENXIO ; goto fail ; } callout_init_mtx ( & sc -> ste_callout , & sc -> ste_mtx , 0 ) ; ste_reset ( sc ) ; if ( ste_read_eeprom ( sc , eaddr , STE_EEADDR_NODE0 , ETHER_ADDR_LEN / 2 ) ) { device_printf ( dev , " \n " ) ; error = ENXIO ; goto fail ; } ste_sysctl_node ( sc ) ; if ( ( error = ste_dma_alloc ( sc ) ) != 0 ) goto fail ; ifp = sc -> ste_ifp = if_alloc ( IFT_ETHER ) ; if ( ifp == NULL ) { device_printf ( dev , " \n " ) ; error = ENOSPC ; goto fail ; } phy = MII_PHY_ANY ; if ( ( sc -> ste_flags & STE_FLAG_ONE_PHY ) != 0 ) phy = 0 ; error = mii_attach ( dev , & sc -> ste_miibus , ifp , ste_ifmedia_upd , ste_ifmedia_sts , BMSR_DEFCAPMASK , phy , MII_OFFSET_ANY , 0 ) ; if ( error != 0 ) { device_printf ( dev , " \n " ) ; goto fail ; } ifp -> if_softc = sc ; if_initname ( ifp , device_get_name ( dev ) , device_get_unit ( dev ) ) ; ifp -> if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST ; ifp -> if_ioctl = ste_ioctl ; ifp -> if_start = ste_start ; ifp -> if_init = ste_init ; IFQ_SET_MAXLEN ( & ifp -> if_snd , STE_TX_LIST_CNT - 1 ) ; ifp -> if_snd . ifq_drv_maxlen = STE_TX_LIST_CNT - 1 ; IFQ_SET_READY ( & ifp -> if_snd ) ; sc -> ste_tx_thresh = STE_TXSTART_THRESH ; ether_ifattach ( ifp , ( uint8_t * ) eaddr ) ; ifp -> if_hdrlen = sizeof ( struct ether_vlan_header ) ; ifp -> if_capabilities |= IFCAP_VLAN_MTU ; if ( pci_find_cap ( dev , PCIY_PMG , & pmc ) == 0 ) ifp -> if_capabilities |= IFCAP_WOL_MAGIC ; ifp -> if_capenable = ifp -> if_capabilities ; #ifdef DEVICE_POLLING ifp -> if_capabilities |= IFCAP_POLLING ; #endif error = bus_setup_intr ( dev , sc -> ste_irq , INTR_TYPE_NET | INTR_MPSAFE , NULL , ste_intr , sc , & sc -> ste_intrhand ) ; if ( error ) { device_printf ( dev , " \n " ) ; ether_ifdetach ( ifp ) ; goto fail ; } fail : if ( error ) ste_detach ( dev ) ; return ( error ) ; }
Attach the interface.
Attach the interface .
/*
	 * Only use one PHY since this chip reports multiple
	 * Note on the DFE-550 the PHY is at 1 on the DFE-580
	 * it is at 0 & 1.  It is rev 0x12.
	 */ /*
	 * Map control/status registers.
	 */ /*
	 * Prefer memory space register mapping over IO space but use
	 * IO space for a device that is known to have issues on memory
	 * mapping.
	 */ /* Allocate interrupt */ /* Reset the adapter. */ /*
	 * Get station address from the EEPROM.
	 */ /* Do MII setup. */ /*
	 * Call MI attach routine.
	 */ /*
	 * Tell the upper layer(s) we support long frames.
	 */ /* Hook interrupt last to avoid having to lock softc */