FreeBSD/sys/dev/wl/if_wl.c
/*
 * wlattach:
 *
 *	This function attaches a WaveLAN board to the "system".  The rest of
 *	runtime structures are initialized here (this routine is called after
 *	a successful probe of the board).  Once the ethernet address is read
 *	and stored, the board's ifnet structure is attached and readied.
 *
 * input	: isa_dev structure setup in autoconfig
 * output	: board structs and ifnet is setup
 *
 */
This function attaches a WaveLAN board to the "system".  The rest of
runtime structures are initialized here (this routine is called after
a successful probe of the board).  Once the ethernet address is read
and stored, the board's ifnet structure is attached and readied.

input        : isa_dev structure setup in autoconfig
output       : board structs and ifnet is setup
This function attaches a WaveLAN board to the " system " . The rest of runtime structures are initialized here ( this routine is called after a successful probe of the board ) . Once the ethernet address is read and stored the board ' s ifnet structure is attached and readied . input : isa_dev structure setup in autoconfig output : board structs and ifnet is setup
static int
wlattach(device_t device)
{
    struct wl_softc	*sc;
    int			error, i, j;
    struct ifnet	*ifp;
    u_char		eaddr[6];
    sc = device_get_softc(device);
    sc->dev = device;
    ifp = sc->ifp = if_alloc(IFT_ETHER);
    if (ifp == NULL) {
	device_printf(device, "can not if_alloc()\n");
	return (ENOSPC);
    }
    mtx_init(&sc->wl_mtx, device_get_nameunit(device), MTX_NETWORK_LOCK,
	MTX_DEF);
    callout_init_mtx(&sc->watchdog_timer, &sc->wl_mtx, 0);
    error = wl_allocate_resources(device);
    if (error) {
	wl_deallocate_resources(device);
	return (ENXIO);
    }
#ifdef WLDEBUG
    printf("wlattach: base %jx, unit %d\n", rman_get_start(sc->res_ioport),
	device_get_unit(device));
#endif
    sc->flags = 0;
    sc->mode = 0;
    sc->hacr = HACR_RESET;
    CMD(sc);				
    DELAY(DELAYCONST);	                
    sc->hacr = (HACR_DEFAULT & ~HACR_16BITS);
    CMD(sc);
    wlgetpsa(sc, sc->psa);
    sc->nwid[0] = sc->psa[WLPSA_NWID];
    sc->nwid[1] = sc->psa[WLPSA_NWID+1];
    if (sc->psa[WLPSA_MACSEL] & 1)
	j = WLPSA_LOCALMAC;
    else
	j = WLPSA_UNIMAC;
    for (i=0; i < WAVELAN_ADDR_SIZE; ++i)
	eaddr[i] = sc->psa[j + i];
    sc->hacr = HACR_DEFAULT;
    CMD(sc);
    wlinitmmc(sc);
    WL_WRITE_2(sc, PIOR1, OFFSET_SCB + 8);	
    WL_WRITE_2(sc, PIOP1, 0);			
    WL_WRITE_2(sc, PIOP1, 0);			
    WL_WRITE_2(sc, PIOP1, 0);			
    WL_WRITE_2(sc, PIOP1, 0);			
    ifp->if_softc = sc;
    ifp->if_mtu = WAVELAN_MTU;
    ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
#ifdef    WLDEBUG
    ifp->if_flags |= IFF_DEBUG;
#endif
#if	MULTICAST
    ifp->if_flags |= IFF_MULTICAST;
#endif	
    if_initname(ifp, device_get_name(device), device_get_unit(device));
    ifp->if_init = wlinit;
    ifp->if_start = wlstart;
    ifp->if_ioctl = wlioctl;
    ifp->if_snd.ifq_maxlen = ifqmaxlen;
    ether_ifattach(ifp, eaddr);
    if_printf(ifp, "NWID 0x%02x%02x", sc->nwid[0], sc->nwid[1]);
    if (sc->freq24) 
	printf(", Freq %d MHz",sc->freq24); 		
    printf("\n");                                       
    bus_setup_intr(device, sc->res_irq, INTR_TYPE_NET, NULL, wlintr, sc, &sc->intr_cookie);
    if (bootverbose)
	wldump(sc);
    return (0);
}
static int wlattach ( device_t device ) { struct wl_softc * sc ; int error , i , j ; struct ifnet * ifp ; u_char eaddr [ 6 ] ; sc = device_get_softc ( device ) ; sc -> dev = device ; ifp = sc -> ifp = if_alloc ( IFT_ETHER ) ; if ( ifp == NULL ) { device_printf ( device , " \n " ) ; return ( ENOSPC ) ; } mtx_init ( & sc -> wl_mtx , device_get_nameunit ( device ) , MTX_NETWORK_LOCK , MTX_DEF ) ; callout_init_mtx ( & sc -> watchdog_timer , & sc -> wl_mtx , 0 ) ; error = wl_allocate_resources ( device ) ; if ( error ) { wl_deallocate_resources ( device ) ; return ( ENXIO ) ; } #ifdef WLDEBUG printf ( " \n " , rman_get_start ( sc -> res_ioport ) , device_get_unit ( device ) ) ; #endif sc -> flags = 0 ; sc -> mode = 0 ; sc -> hacr = HACR_RESET ; CMD ( sc ) ; DELAY ( DELAYCONST ) ; sc -> hacr = ( HACR_DEFAULT & ~ HACR_16BITS ) ; CMD ( sc ) ; wlgetpsa ( sc , sc -> psa ) ; sc -> nwid [ 0 ] = sc -> psa [ WLPSA_NWID ] ; sc -> nwid [ 1 ] = sc -> psa [ WLPSA_NWID + 1 ] ; if ( sc -> psa [ WLPSA_MACSEL ] & 1 ) j = WLPSA_LOCALMAC ; else j = WLPSA_UNIMAC ; for ( i = 0 ; i < WAVELAN_ADDR_SIZE ; ++ i ) eaddr [ i ] = sc -> psa [ j + i ] ; sc -> hacr = HACR_DEFAULT ; CMD ( sc ) ; wlinitmmc ( sc ) ; WL_WRITE_2 ( sc , PIOR1 , OFFSET_SCB + 8 ) ; WL_WRITE_2 ( sc , PIOP1 , 0 ) ; WL_WRITE_2 ( sc , PIOP1 , 0 ) ; WL_WRITE_2 ( sc , PIOP1 , 0 ) ; WL_WRITE_2 ( sc , PIOP1 , 0 ) ; ifp -> if_softc = sc ; ifp -> if_mtu = WAVELAN_MTU ; ifp -> if_flags = IFF_BROADCAST | IFF_SIMPLEX ; #ifdef WLDEBUG ifp -> if_flags |= IFF_DEBUG ; #endif #if MULTICAST ifp -> if_flags |= IFF_MULTICAST ; #endif if_initname ( ifp , device_get_name ( device ) , device_get_unit ( device ) ) ; ifp -> if_init = wlinit ; ifp -> if_start = wlstart ; ifp -> if_ioctl = wlioctl ; ifp -> if_snd . ifq_maxlen = ifqmaxlen ; ether_ifattach ( ifp , eaddr ) ; if_printf ( ifp , " " , sc -> nwid [ 0 ] , sc -> nwid [ 1 ] ) ; if ( sc -> freq24 ) printf ( " " , sc -> freq24 ) ; printf ( " \n " ) ; bus_setup_intr ( device , sc -> res_irq , INTR_TYPE_NET , NULL , wlintr , sc , & sc -> intr_cookie ) ; if ( bootverbose ) wldump ( sc ) ; return ( 0 ) ; }
wlattach:
      This function attaches a WaveLAN board to the "system".
wlattach : This function attaches a WaveLAN board to the " system " .
/* reset the board */ /* >> 4 clocks at 6MHz */ /* clear reset command and set PIO#2 in parameter access mode */ /* Read the PSA from the board for our later reference */ /* fetch NWID */ /* fetch MAC address - decide which one first */ /* enter normal 16 bit mode operation */ /* address of scb_crcerrs */ /* clear scb_crcerrs */ /* clear scb_alnerrs */ /* clear scb_rscerrs */ /* clear scb_ovrnerrs */ /* MULTICAST */ /* no entries
       ifp->if_done
       ifp->if_reset
       */ /* 2.4 Gz       */ /* 2.4 Gz       */