FreeBSD/sys/dev/mrsas/mrsas.c
/*
 * mrsas_setup_raidmap:	Set up RAID map.
 * input:				Adapter instance soft state
 *
 * Allocate DMA memory for the RAID maps and perform setup.
 */
Set up RAID map.
input:                               Adapter instance soft state

Allocate DMA memory for the RAID maps and perform setup.
Set up RAID map . input : Adapter instance soft state Allocate DMA memory for the RAID maps and perform setup .
static int
mrsas_setup_raidmap(struct mrsas_softc *sc)
{
	int i;
	for (i = 0; i < 2; i++) {
		sc->ld_drv_map[i] =
		    (void *)malloc(sc->drv_map_sz, M_MRSAS, M_NOWAIT);
		if (!sc->ld_drv_map[i]) {
			device_printf(sc->mrsas_dev, "Could not allocate memory for local map");
			if (i == 1)
				free(sc->ld_drv_map[0], M_MRSAS);
			goto ABORT;
		}
	}
	for (int i = 0; i < 2; i++) {
		if (bus_dma_tag_create(sc->mrsas_parent_tag,
		    4, 0,
		    BUS_SPACE_MAXADDR_32BIT,
		    BUS_SPACE_MAXADDR,
		    NULL, NULL,
		    sc->max_map_sz,
		    1,
		    sc->max_map_sz,
		    BUS_DMA_ALLOCNOW,
		    NULL, NULL,
		    &sc->raidmap_tag[i])) {
			device_printf(sc->mrsas_dev,
			    "Cannot allocate raid map tag.\n");
			return (ENOMEM);
		}
		if (bus_dmamem_alloc(sc->raidmap_tag[i],
		    (void **)&sc->raidmap_mem[i],
		    BUS_DMA_NOWAIT, &sc->raidmap_dmamap[i])) {
			device_printf(sc->mrsas_dev,
			    "Cannot allocate raidmap memory.\n");
			return (ENOMEM);
		}
		bzero(sc->raidmap_mem[i], sc->max_map_sz);
		if (bus_dmamap_load(sc->raidmap_tag[i], sc->raidmap_dmamap[i],
		    sc->raidmap_mem[i], sc->max_map_sz,
		    mrsas_addr_cb, &sc->raidmap_phys_addr[i],
		    BUS_DMA_NOWAIT)) {
			device_printf(sc->mrsas_dev, "Cannot load raidmap memory.\n");
			return (ENOMEM);
		}
		if (!sc->raidmap_mem[i]) {
			device_printf(sc->mrsas_dev,
			    "Cannot allocate memory for raid map.\n");
			return (ENOMEM);
		}
	}
	if (!mrsas_get_map_info(sc))
		mrsas_sync_map_info(sc);
	return (0);
ABORT:
	return (1);
}
static int mrsas_setup_raidmap ( struct mrsas_softc * sc ) { int i ; for ( i = 0 ; i < 2 ; i ++ ) { sc -> ld_drv_map [ i ] = ( void * ) malloc ( sc -> drv_map_sz , M_MRSAS , M_NOWAIT ) ; if ( ! sc -> ld_drv_map [ i ] ) { device_printf ( sc -> mrsas_dev , " " ) ; if ( i == 1 ) free ( sc -> ld_drv_map [ 0 ] , M_MRSAS ) ; goto ABORT ; } } for ( int i = 0 ; i < 2 ; i ++ ) { if ( bus_dma_tag_create ( sc -> mrsas_parent_tag , 4 , 0 , BUS_SPACE_MAXADDR_32BIT , BUS_SPACE_MAXADDR , NULL , NULL , sc -> max_map_sz , 1 , sc -> max_map_sz , BUS_DMA_ALLOCNOW , NULL , NULL , & sc -> raidmap_tag [ i ] ) ) { device_printf ( sc -> mrsas_dev , " \n " ) ; return ( ENOMEM ) ; } if ( bus_dmamem_alloc ( sc -> raidmap_tag [ i ] , ( void * * ) & sc -> raidmap_mem [ i ] , BUS_DMA_NOWAIT , & sc -> raidmap_dmamap [ i ] ) ) { device_printf ( sc -> mrsas_dev , " \n " ) ; return ( ENOMEM ) ; } bzero ( sc -> raidmap_mem [ i ] , sc -> max_map_sz ) ; if ( bus_dmamap_load ( sc -> raidmap_tag [ i ] , sc -> raidmap_dmamap [ i ] , sc -> raidmap_mem [ i ] , sc -> max_map_sz , mrsas_addr_cb , & sc -> raidmap_phys_addr [ i ] , BUS_DMA_NOWAIT ) ) { device_printf ( sc -> mrsas_dev , " \n " ) ; return ( ENOMEM ) ; } if ( ! sc -> raidmap_mem [ i ] ) { device_printf ( sc -> mrsas_dev , " \n " ) ; return ( ENOMEM ) ; } } if ( ! mrsas_get_map_info ( sc ) ) mrsas_sync_map_info ( sc ) ; return ( 0 ) ; ABORT : return ( 1 ) ; }
mrsas_setup_raidmap: Set up RAID map.
mrsas_setup_raidmap : Set up RAID map .
/* Do Error handling */ /* ABORT driver initialization */