sys/dev/atm/hfa/fore_load.c
static void
fore_pci_attach(pcici_t config_id, int unit)
{
	Fore_unit	*fup;
	vm_offset_t	va;
	vm_offset_t	pa;
	pcidi_t		device_id;
	long		val;
	int		err_count = BOOT_LOOPS;

	/*
	 * Just checking...
	 */
	if (unit >= FORE_MAX_UNITS) {
		log(LOG_ERR, "%s%d: too many devices\n", 
			FORE_DEV_NAME, unit);
		return;
	}

	/*
	 * Make sure this isn't a duplicate unit
	 */
	if (fore_units[unit] != NULL)
		return;

	/*
	 * Allocate a new unit structure
	 */
	fup = (Fore_unit *) atm_dev_alloc(sizeof(Fore_unit), sizeof(int), 0);
	if (fup == NULL)
		return;

	/*
	 * Start initializing it
	 */
	fup->fu_unit = unit;
	fup->fu_mtu = FORE_IFF_MTU;
	fup->fu_pcitag = config_id;
	fup->fu_vcc_pool = &fore_vcc_pool;
	fup->fu_nif_pool = &fore_nif_pool;
	fup->fu_ioctl = fore_atm_ioctl;
	fup->fu_instvcc = fore_instvcc;
	fup->fu_openvcc = fore_openvcc;
	fup->fu_closevcc = fore_closevcc;
	fup->fu_output = fore_output;
	callout_init(&fup->fu_init_timer);

	/*
	 * Get our device type
	 */
	device_id = pci_conf_read ( config_id, PCI_ID_REG );
	switch ((device_id >> 16) & 0xffff) {

	case FORE_PCA200E_ID:
		fup->fu_config.ac_device = DEV_FORE_PCA200E;
		break;

	default:
		fup->fu_config.ac_device = DEV_UNKNOWN;
	}

	/*
	 * Enable Memory Mapping / Bus Mastering 
	 */
	val = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
	val |= (PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN);
	pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, val);

	/*
	 * Map RAM
	 */
	val = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
	if ((val & PCIM_CMD_MEMEN) == 0) {
		log(LOG_ERR, "%s%d: memory mapping not enabled\n", 
			FORE_DEV_NAME, unit);
		goto failed;
	}
	if ((pci_map_mem(config_id, PCA200E_PCI_MEMBASE, &va, &pa)) == 0) {
		log(LOG_ERR, "%s%d: unable to map memory\n", 
			FORE_DEV_NAME, unit);
		goto failed;
	}
	fup->fu_ram = (Fore_mem *)va;
	fup->fu_ramsize = PCA200E_RAM_SIZE;
	fup->fu_mon = (Mon960 *)(fup->fu_ram + MON960_BASE);
	fup->fu_ctlreg = (Fore_reg *)(va + PCA200E_HCR_OFFSET);
	fup->fu_imask = (Fore_reg *)(va + PCA200E_IMASK_OFFSET);
	fup->fu_psr = (Fore_reg *)(va + PCA200E_PSR_OFFSET);

	/*
	 * Convert Endianess of Slave RAM accesses
	 */
	val = pci_conf_read(config_id, PCA200E_PCI_MCTL);
	val |= PCA200E_MCTL_SWAP;
	pci_conf_write(config_id, PCA200E_PCI_MCTL, val);

	/*
	 * Map interrupt in
	 */
	if ( !pci_map_int( config_id, fore_intr, fup) ) {
		log(LOG_ERR, "%s%d: unable to map interrupt\n", 
			FORE_DEV_NAME, unit);
		goto failed;
	}

	/*
	 * Poke the hardware - boot the CP and prepare it for downloading
	 */
	fore_reset(fup);

	/*
	 * Wait for the monitor to perform self-test
	 */
	while (CP_READ(fup->fu_mon->mon_bstat) != BOOT_MONREADY) {
		if (CP_READ(fup->fu_mon->mon_bstat) == BOOT_FAILTEST) {
			log(LOG_ERR, "%s%d: failed self-test\n", 
				FORE_DEV_NAME, unit);
			goto failed;
		} else if ( --err_count == 0 ) {
			log(LOG_ERR, "%s%d: unable to boot - status=0x%lx\n", 
				FORE_DEV_NAME, unit,
				(u_long)CP_READ(fup->fu_mon->mon_bstat));
			goto failed;
		}
		DELAY ( BOOT_DELAY );
	}

	/*
	 * Setup the adapter config info - at least as much as we can
	 */
	fup->fu_config.ac_vendor = VENDOR_FORE;
	fup->fu_config.ac_vendapi = VENDAPI_FORE_1;
	fup->fu_config.ac_media = MEDIA_OC3C;
	fup->fu_pif.pif_pcr = ATM_PCR_OC3C;
	fup->fu_config.ac_bustype = BUS_PCI;
	fup->fu_config.ac_busslot = config_id->bus << 8 | config_id->slot;

	/*
	 * Save device ram info for user-level programs
	 */
	fup->fu_config.ac_ram = (long)fup->fu_ram;
	fup->fu_config.ac_ramsize = fup->fu_ramsize;

	/*
	 * Set device capabilities
	 */
	fup->fu_pif.pif_maxvpi = FORE_MAX_VPI;
	fup->fu_pif.pif_maxvci = FORE_MAX_VCI;

	/*
	 * Register this interface with ATM core services
	 */
        if ( atm_physif_register
			((Cmn_unit *)fup, FORE_DEV_NAME, fore_services) != 0 )
	{
		/*
		 * Registration failed - back everything out
		 */
		goto failed;
	}

	fore_units[unit] = fup;
	fore_nunits++;

	/*
	 * Add hook to our shutdown function
	 */
	EVENTHANDLER_REGISTER(shutdown_post_sync, fore_pci_shutdown, fup,
			      SHUTDOWN_PRI_DRIVER);

	/*
	 * Initialize the CP microcode program.
	 */
	fore_initialize(fup);

	return;

failed:
	/*
	 * Unattach the device from the system
	 */
	fore_unattach(fup);

	/*
	 * Free any Fore-specific device resources
	 */
	fore_interface_free(fup);

	atm_dev_free(fup);

	return;
}
/*
 * Device attach routine
 * 
 * Attach a device we've previously claimed to support.  Walk through its
 * register set and map, as required.  Determine what level the device will
 * be interrupting at and then register an interrupt handler for it.  If we
 * succeed, then reset the adapter and initialize the microcode.
 * Last, register the interface with the kernel ATM services.
 *
 * Arguments:
 *	config_id	device's PCI configuration ID
 *	unit		device unit number
 *
 * Returns:
 *	none
 *
 */
Device attach routine

Attach a device we've previously claimed to support.  Walk through its
register set and map, as required.  Determine what level the device will
be interrupting at and then register an interrupt handler for it.  If we
succeed, then reset the adapter and initialize the microcode.
Last, register the interface with the kernel ATM services.

config_id       device's PCI configuration ID
unit            device unit number

none
Device attach routine Attach a device we ' ve previously claimed to support . Walk through its register set and map as required . Determine what level the device will be interrupting at and then register an interrupt handler for it . If we succeed then reset the adapter and initialize the microcode . Last register the interface with the kernel ATM services . config_id device ' s PCI configuration ID unit device unit number none
static void
fore_pci_attach(pcici_t config_id, int unit)
{
	Fore_unit	*fup;
	vm_offset_t	va;
	vm_offset_t	pa;
	pcidi_t		device_id;
	long		val;
	int		err_count = BOOT_LOOPS;
	if (unit >= FORE_MAX_UNITS) {
		log(LOG_ERR, "%s%d: too many devices\n", 
			FORE_DEV_NAME, unit);
		return;
	}
	if (fore_units[unit] != NULL)
		return;
	fup = (Fore_unit *) atm_dev_alloc(sizeof(Fore_unit), sizeof(int), 0);
	if (fup == NULL)
		return;
	fup->fu_unit = unit;
	fup->fu_mtu = FORE_IFF_MTU;
	fup->fu_pcitag = config_id;
	fup->fu_vcc_pool = &fore_vcc_pool;
	fup->fu_nif_pool = &fore_nif_pool;
	fup->fu_ioctl = fore_atm_ioctl;
	fup->fu_instvcc = fore_instvcc;
	fup->fu_openvcc = fore_openvcc;
	fup->fu_closevcc = fore_closevcc;
	fup->fu_output = fore_output;
	callout_init(&fup->fu_init_timer);
	device_id = pci_conf_read ( config_id, PCI_ID_REG );
	switch ((device_id >> 16) & 0xffff) {
	case FORE_PCA200E_ID:
		fup->fu_config.ac_device = DEV_FORE_PCA200E;
		break;
	default:
		fup->fu_config.ac_device = DEV_UNKNOWN;
	}
	val = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
	val |= (PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN);
	pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, val);
	val = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
	if ((val & PCIM_CMD_MEMEN) == 0) {
		log(LOG_ERR, "%s%d: memory mapping not enabled\n", 
			FORE_DEV_NAME, unit);
		goto failed;
	}
	if ((pci_map_mem(config_id, PCA200E_PCI_MEMBASE, &va, &pa)) == 0) {
		log(LOG_ERR, "%s%d: unable to map memory\n", 
			FORE_DEV_NAME, unit);
		goto failed;
	}
	fup->fu_ram = (Fore_mem *)va;
	fup->fu_ramsize = PCA200E_RAM_SIZE;
	fup->fu_mon = (Mon960 *)(fup->fu_ram + MON960_BASE);
	fup->fu_ctlreg = (Fore_reg *)(va + PCA200E_HCR_OFFSET);
	fup->fu_imask = (Fore_reg *)(va + PCA200E_IMASK_OFFSET);
	fup->fu_psr = (Fore_reg *)(va + PCA200E_PSR_OFFSET);
	val = pci_conf_read(config_id, PCA200E_PCI_MCTL);
	val |= PCA200E_MCTL_SWAP;
	pci_conf_write(config_id, PCA200E_PCI_MCTL, val);
	if ( !pci_map_int( config_id, fore_intr, fup) ) {
		log(LOG_ERR, "%s%d: unable to map interrupt\n", 
			FORE_DEV_NAME, unit);
		goto failed;
	}
	fore_reset(fup);
	while (CP_READ(fup->fu_mon->mon_bstat) != BOOT_MONREADY) {
		if (CP_READ(fup->fu_mon->mon_bstat) == BOOT_FAILTEST) {
			log(LOG_ERR, "%s%d: failed self-test\n", 
				FORE_DEV_NAME, unit);
			goto failed;
		} else if ( --err_count == 0 ) {
			log(LOG_ERR, "%s%d: unable to boot - status=0x%lx\n", 
				FORE_DEV_NAME, unit,
				(u_long)CP_READ(fup->fu_mon->mon_bstat));
			goto failed;
		}
		DELAY ( BOOT_DELAY );
	}
	fup->fu_config.ac_vendor = VENDOR_FORE;
	fup->fu_config.ac_vendapi = VENDAPI_FORE_1;
	fup->fu_config.ac_media = MEDIA_OC3C;
	fup->fu_pif.pif_pcr = ATM_PCR_OC3C;
	fup->fu_config.ac_bustype = BUS_PCI;
	fup->fu_config.ac_busslot = config_id->bus << 8 | config_id->slot;
	fup->fu_config.ac_ram = (long)fup->fu_ram;
	fup->fu_config.ac_ramsize = fup->fu_ramsize;
	fup->fu_pif.pif_maxvpi = FORE_MAX_VPI;
	fup->fu_pif.pif_maxvci = FORE_MAX_VCI;
        if ( atm_physif_register
			((Cmn_unit *)fup, FORE_DEV_NAME, fore_services) != 0 )
	{
		goto failed;
	}
	fore_units[unit] = fup;
	fore_nunits++;
	EVENTHANDLER_REGISTER(shutdown_post_sync, fore_pci_shutdown, fup,
			      SHUTDOWN_PRI_DRIVER);
	fore_initialize(fup);
	return;
failed:
	fore_unattach(fup);
	fore_interface_free(fup);
	atm_dev_free(fup);
	return;
}
static void fore_pci_attach ( pcici_t config_id , int unit ) { Fore_unit * fup ; vm_offset_t va ; vm_offset_t pa ; pcidi_t device_id ; long val ; int err_count = BOOT_LOOPS ; if ( unit >= FORE_MAX_UNITS ) { log ( LOG_ERR , " \n " , FORE_DEV_NAME , unit ) ; return ; } if ( fore_units [ unit ] != NULL ) return ; fup = ( Fore_unit * ) atm_dev_alloc ( sizeof ( Fore_unit ) , sizeof ( int ) , 0 ) ; if ( fup == NULL ) return ; fup -> fu_unit = unit ; fup -> fu_mtu = FORE_IFF_MTU ; fup -> fu_pcitag = config_id ; fup -> fu_vcc_pool = & fore_vcc_pool ; fup -> fu_nif_pool = & fore_nif_pool ; fup -> fu_ioctl = fore_atm_ioctl ; fup -> fu_instvcc = fore_instvcc ; fup -> fu_openvcc = fore_openvcc ; fup -> fu_closevcc = fore_closevcc ; fup -> fu_output = fore_output ; callout_init ( & fup -> fu_init_timer ) ; device_id = pci_conf_read ( config_id , PCI_ID_REG ) ; switch ( ( device_id >> 16 ) & 0xffff ) { case FORE_PCA200E_ID : fup -> fu_config . ac_device = DEV_FORE_PCA200E ; break ; default : fup -> fu_config . ac_device = DEV_UNKNOWN ; } val = pci_conf_read ( config_id , PCI_COMMAND_STATUS_REG ) ; val |= ( PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN ) ; pci_conf_write ( config_id , PCI_COMMAND_STATUS_REG , val ) ; val = pci_conf_read ( config_id , PCI_COMMAND_STATUS_REG ) ; if ( ( val & PCIM_CMD_MEMEN ) == 0 ) { log ( LOG_ERR , " \n " , FORE_DEV_NAME , unit ) ; goto failed ; } if ( ( pci_map_mem ( config_id , PCA200E_PCI_MEMBASE , & va , & pa ) ) == 0 ) { log ( LOG_ERR , " \n " , FORE_DEV_NAME , unit ) ; goto failed ; } fup -> fu_ram = ( Fore_mem * ) va ; fup -> fu_ramsize = PCA200E_RAM_SIZE ; fup -> fu_mon = ( Mon960 * ) ( fup -> fu_ram + MON960_BASE ) ; fup -> fu_ctlreg = ( Fore_reg * ) ( va + PCA200E_HCR_OFFSET ) ; fup -> fu_imask = ( Fore_reg * ) ( va + PCA200E_IMASK_OFFSET ) ; fup -> fu_psr = ( Fore_reg * ) ( va + PCA200E_PSR_OFFSET ) ; val = pci_conf_read ( config_id , PCA200E_PCI_MCTL ) ; val |= PCA200E_MCTL_SWAP ; pci_conf_write ( config_id , PCA200E_PCI_MCTL , val ) ; if ( ! pci_map_int ( config_id , fore_intr , fup ) ) { log ( LOG_ERR , " \n " , FORE_DEV_NAME , unit ) ; goto failed ; } fore_reset ( fup ) ; while ( CP_READ ( fup -> fu_mon -> mon_bstat ) != BOOT_MONREADY ) { if ( CP_READ ( fup -> fu_mon -> mon_bstat ) == BOOT_FAILTEST ) { log ( LOG_ERR , " \n " , FORE_DEV_NAME , unit ) ; goto failed ; } else if ( -- err_count == 0 ) { log ( LOG_ERR , " \n " , FORE_DEV_NAME , unit , ( u_long ) CP_READ ( fup -> fu_mon -> mon_bstat ) ) ; goto failed ; } DELAY ( BOOT_DELAY ) ; } fup -> fu_config . ac_vendor = VENDOR_FORE ; fup -> fu_config . ac_vendapi = VENDAPI_FORE_1 ; fup -> fu_config . ac_media = MEDIA_OC3C ; fup -> fu_pif . pif_pcr = ATM_PCR_OC3C ; fup -> fu_config . ac_bustype = BUS_PCI ; fup -> fu_config . ac_busslot = config_id -> bus << 8 | config_id -> slot ; fup -> fu_config . ac_ram = ( long ) fup -> fu_ram ; fup -> fu_config . ac_ramsize = fup -> fu_ramsize ; fup -> fu_pif . pif_maxvpi = FORE_MAX_VPI ; fup -> fu_pif . pif_maxvci = FORE_MAX_VCI ; if ( atm_physif_register ( ( Cmn_unit * ) fup , FORE_DEV_NAME , fore_services ) != 0 ) { goto failed ; } fore_units [ unit ] = fup ; fore_nunits ++ ; EVENTHANDLER_REGISTER ( shutdown_post_sync , fore_pci_shutdown , fup , SHUTDOWN_PRI_DRIVER ) ; fore_initialize ( fup ) ; return ; failed : fore_unattach ( fup ) ; fore_interface_free ( fup ) ; atm_dev_free ( fup ) ; return ; }
Device attach routine
Device attach routine
/*
	 * Just checking...
	 */ /*
	 * Make sure this isn't a duplicate unit
	 */ /*
	 * Allocate a new unit structure
	 */ /*
	 * Start initializing it
	 */ /*
	 * Get our device type
	 */ /*
	 * Enable Memory Mapping / Bus Mastering 
	 */ /*
	 * Map RAM
	 */ /*
	 * Convert Endianess of Slave RAM accesses
	 */ /*
	 * Map interrupt in
	 */ /*
	 * Poke the hardware - boot the CP and prepare it for downloading
	 */ /*
	 * Wait for the monitor to perform self-test
	 */ /*
	 * Setup the adapter config info - at least as much as we can
	 */ /*
	 * Save device ram info for user-level programs
	 */ /*
	 * Set device capabilities
	 */ /*
	 * Register this interface with ATM core services
	 */ /*
		 * Registration failed - back everything out
		 */ /*
	 * Add hook to our shutdown function
	 */ /*
	 * Initialize the CP microcode program.
	 */ /*
	 * Unattach the device from the system
	 */ /*
	 * Free any Fore-specific device resources
	 */