FreeBSD/sys/dev/vxge/vxge.c
/*
 * vxge_attach
 * Connects driver to the system if probe was success @ndev handle
 */
vxge_attach
Connects driver to the system if probe was success @ndev handle
vxge_attach Connects driver to the system if probe was success @ndev handle
int
vxge_attach(device_t ndev)
{
	int err = 0;
	vxge_dev_t *vdev;
	vxge_hal_device_t *hldev = NULL;
	vxge_hal_device_attr_t device_attr;
	vxge_free_resources_e error_level = VXGE_FREE_NONE;
	vxge_hal_status_e status = VXGE_HAL_OK;
	vdev = (vxge_dev_t *) device_get_softc(ndev);
	if (!vdev)
		goto _exit0;
	bzero(vdev, sizeof(vxge_dev_t));
	vdev->ndev = ndev;
	strlcpy(vdev->ndev_name, "vxge", sizeof(vdev->ndev_name));
	err = vxge_driver_config(vdev);
	if (err != 0)
		goto _exit0;
	status = vxge_driver_init(vdev);
	if (status != VXGE_HAL_OK) {
		device_printf(vdev->ndev, "Failed to initialize driver\n");
		goto _exit0;
	}
	pci_enable_busmaster(ndev);
	err = vxge_alloc_resources(vdev);
	if (err != 0) {
		device_printf(vdev->ndev, "resource allocation failed\n");
		goto _exit0;
	}
	err = vxge_device_hw_info_get(vdev);
	if (err != 0) {
		error_level = VXGE_FREE_BAR2;
		goto _exit0;
	}
	vxge_hal_device_config_default_get(vdev->device_config);
	vxge_vpath_config(vdev);
	err = vxge_alloc_isr_resources(vdev);
	if (err != 0) {
		error_level = VXGE_FREE_ISR_RESOURCE;
		device_printf(vdev->ndev, "isr resource allocation failed\n");
		goto _exit0;
	}
	device_attr.bar0 = (u8 *) vdev->pdev->bar_info[0];
	device_attr.bar1 = (u8 *) vdev->pdev->bar_info[1];
	device_attr.bar2 = (u8 *) vdev->pdev->bar_info[2];
	device_attr.regh0 = (vxge_bus_res_t *) vdev->pdev->reg_map[0];
	device_attr.regh1 = (vxge_bus_res_t *) vdev->pdev->reg_map[1];
	device_attr.regh2 = (vxge_bus_res_t *) vdev->pdev->reg_map[2];
	device_attr.irqh = (pci_irq_h) vdev->config.isr_info[0].irq_handle;
	device_attr.cfgh = vdev->pdev;
	device_attr.pdev = vdev->pdev;
	status = vxge_hal_device_initialize((vxge_hal_device_h *) &hldev,
	    &device_attr, vdev->device_config);
	if (status != VXGE_HAL_OK) {
		error_level = VXGE_FREE_ISR_RESOURCE;
		device_printf(vdev->ndev, "hal device initialization failed\n");
		goto _exit0;
	}
	vdev->devh = hldev;
	vxge_hal_device_private_set(hldev, vdev);
	if (vdev->is_privilaged) {
		err = vxge_firmware_verify(vdev);
		if (err != 0) {
			vxge_dev_req_reboot = 1;
			error_level = VXGE_FREE_TERMINATE_DEVICE;
			goto _exit0;
		}
	}
	vdev->vpaths = (vxge_vpath_t *)
	    vxge_mem_alloc(vdev->no_of_vpath * sizeof(vxge_vpath_t));
	if (vdev->vpaths == NULL) {
		error_level = VXGE_FREE_TERMINATE_DEVICE;
		device_printf(vdev->ndev, "vpath memory allocation failed\n");
		goto _exit0;
	}
	vdev->no_of_func = 1;
	if (vdev->is_privilaged) {
		vxge_hal_func_mode_count(vdev->devh,
		    vdev->config.hw_info.function_mode, &vdev->no_of_func);
		vxge_bw_priority_config(vdev);
	}
	vxge_mutex_init(vdev);
	vxge_media_init(vdev);
	err = vxge_ifp_setup(ndev);
	if (err != 0) {
		error_level = VXGE_FREE_MEDIA;
		device_printf(vdev->ndev, "setting up interface failed\n");
		goto _exit0;
	}
	err = vxge_isr_setup(vdev);
	if (err != 0) {
		error_level = VXGE_FREE_INTERFACE;
		device_printf(vdev->ndev,
		    "failed to associate interrupt handler with device\n");
		goto _exit0;
	}
	vxge_device_hw_info_print(vdev);
	vdev->is_active = TRUE;
_exit0:
	if (error_level) {
		vxge_free_resources(ndev, error_level);
		err = ENXIO;
	}
	return (err);
}
int vxge_attach ( device_t ndev ) { int err = 0 ; vxge_dev_t * vdev ; vxge_hal_device_t * hldev = NULL ; vxge_hal_device_attr_t device_attr ; vxge_free_resources_e error_level = VXGE_FREE_NONE ; vxge_hal_status_e status = VXGE_HAL_OK ; vdev = ( vxge_dev_t * ) device_get_softc ( ndev ) ; if ( ! vdev ) goto _exit0 ; bzero ( vdev , sizeof ( vxge_dev_t ) ) ; vdev -> ndev = ndev ; strlcpy ( vdev -> ndev_name , " " , sizeof ( vdev -> ndev_name ) ) ; err = vxge_driver_config ( vdev ) ; if ( err != 0 ) goto _exit0 ; status = vxge_driver_init ( vdev ) ; if ( status != VXGE_HAL_OK ) { device_printf ( vdev -> ndev , " \n " ) ; goto _exit0 ; } pci_enable_busmaster ( ndev ) ; err = vxge_alloc_resources ( vdev ) ; if ( err != 0 ) { device_printf ( vdev -> ndev , " \n " ) ; goto _exit0 ; } err = vxge_device_hw_info_get ( vdev ) ; if ( err != 0 ) { error_level = VXGE_FREE_BAR2 ; goto _exit0 ; } vxge_hal_device_config_default_get ( vdev -> device_config ) ; vxge_vpath_config ( vdev ) ; err = vxge_alloc_isr_resources ( vdev ) ; if ( err != 0 ) { error_level = VXGE_FREE_ISR_RESOURCE ; device_printf ( vdev -> ndev , " \n " ) ; goto _exit0 ; } device_attr . bar0 = ( u8 * ) vdev -> pdev -> bar_info [ 0 ] ; device_attr . bar1 = ( u8 * ) vdev -> pdev -> bar_info [ 1 ] ; device_attr . bar2 = ( u8 * ) vdev -> pdev -> bar_info [ 2 ] ; device_attr . regh0 = ( vxge_bus_res_t * ) vdev -> pdev -> reg_map [ 0 ] ; device_attr . regh1 = ( vxge_bus_res_t * ) vdev -> pdev -> reg_map [ 1 ] ; device_attr . regh2 = ( vxge_bus_res_t * ) vdev -> pdev -> reg_map [ 2 ] ; device_attr . irqh = ( pci_irq_h ) vdev -> config . isr_info [ 0 ] . irq_handle ; device_attr . cfgh = vdev -> pdev ; device_attr . pdev = vdev -> pdev ; status = vxge_hal_device_initialize ( ( vxge_hal_device_h * ) & hldev , & device_attr , vdev -> device_config ) ; if ( status != VXGE_HAL_OK ) { error_level = VXGE_FREE_ISR_RESOURCE ; device_printf ( vdev -> ndev , " \n " ) ; goto _exit0 ; } vdev -> devh = hldev ; vxge_hal_device_private_set ( hldev , vdev ) ; if ( vdev -> is_privilaged ) { err = vxge_firmware_verify ( vdev ) ; if ( err != 0 ) { vxge_dev_req_reboot = 1 ; error_level = VXGE_FREE_TERMINATE_DEVICE ; goto _exit0 ; } } vdev -> vpaths = ( vxge_vpath_t * ) vxge_mem_alloc ( vdev -> no_of_vpath * sizeof ( vxge_vpath_t ) ) ; if ( vdev -> vpaths == NULL ) { error_level = VXGE_FREE_TERMINATE_DEVICE ; device_printf ( vdev -> ndev , " \n " ) ; goto _exit0 ; } vdev -> no_of_func = 1 ; if ( vdev -> is_privilaged ) { vxge_hal_func_mode_count ( vdev -> devh , vdev -> config . hw_info . function_mode , & vdev -> no_of_func ) ; vxge_bw_priority_config ( vdev ) ; } vxge_mutex_init ( vdev ) ; vxge_media_init ( vdev ) ; err = vxge_ifp_setup ( ndev ) ; if ( err != 0 ) { error_level = VXGE_FREE_MEDIA ; device_printf ( vdev -> ndev , " \n " ) ; goto _exit0 ; } err = vxge_isr_setup ( vdev ) ; if ( err != 0 ) { error_level = VXGE_FREE_INTERFACE ; device_printf ( vdev -> ndev , " \n " ) ; goto _exit0 ; } vxge_device_hw_info_print ( vdev ) ; vdev -> is_active = TRUE ; _exit0 : if ( error_level ) { vxge_free_resources ( ndev , error_level ) ; err = ENXIO ; } return ( err ) ; }
vxge_attach
 Connects driver to the system if probe was success @ndev handle
vxge_attach Connects driver to the system if probe was success @ndev handle
/* Get per-ndev buffer */ /* Initialize HAL driver */ /* Enable PCI bus-master */ /* Allocate resources */ /* Get firmware default values for Device Configuration */ /* Customize Device Configuration based on User request */ /* Allocate ISR resources */ /* HAL attributes */ /* Initialize HAL Device */ /* Allocate memory for vpath */ /* Initialize mutexes */ /* Initialize Media */