Example #1
0
File: netShow.c Project: phoboz/vmx
LOCAL void clPoolShow(NET_POOL_ID poolId)
{
  unsigned char type;
  CL_POOL_ID clPoolId;

  /* Print header */
  printf("__________________\n");
  printf("CLUSTER POOL TABLE\n");
  printf(sepLine);
  printf("size     clusters  free      usage\n");
  printf(sepLine);

  /* For all cluster types */
  for (type = poolId->clLg2Min; type <= poolId->clLg2Max; type++) {

    /* Get cluster pool */
    clPoolId = netClPoolIdGet(poolId, CL_LOG2_TO_CL_SIZE(type), TRUE);

    /* Print if available */
    if (clPoolId != NULL) {

      printf("%-9d", clPoolId->clSize);
      printf("%-10d", clPoolId->clNum);
      printf("%-10d", clPoolId->clNumFree);
      printf("%-14d\n", clPoolId->clUsage);
    }

    printf(sepLine);

  } /* End for all cluster types */

}
Example #2
0
/* Netpool create */
LOCAL int
roboTxRxNetpoolCreate()
{
    memset(&robo_txrx_info, 0, sizeof(robo_txrx_info));
    robo_txrx_info.roboNetPoolID =  (NET_POOL_ID)calloc(1, sizeof(NET_POOL));

    if (robo_txrx_info.roboNetPoolID == NULL) {
        return(0);
    }

    robo_txrx_info.m_cl_blks.mBlkNum = ROBO_TXRX_MBLKS;
    robo_txrx_info.m_cl_blks.clBlkNum = ROBO_TXRX_CLBLKS;
    robo_txrx_info.m_cl_blks.memSize =
            (robo_txrx_info.m_cl_blks.mBlkNum * (M_BLK_SZ + sizeof(long))) +
            (robo_txrx_info.m_cl_blks.clBlkNum * (CL_BLK_SZ + sizeof(long)));;
    robo_txrx_info.m_cl_blks.memArea = 
            (char *)memalign (sizeof (long), robo_txrx_info.m_cl_blks.memSize);
    if (robo_txrx_info.m_cl_blks.memArea == NULL) {
        free(robo_txrx_info.roboNetPoolID);
        robo_txrx_info.roboNetPoolID = NULL;
        return(0);
    }

    robo_txrx_info.cluster.clNum = ROBO_TXRX_CLBUFS;
    robo_txrx_info.cluster.clSize = ROBO_TX_RX_PK_SZ;
    robo_txrx_info.cluster.memSize = robo_txrx_info.cluster.clNum *
            (robo_txrx_info.cluster.clSize + sizeof(long)) + sizeof(long);
    robo_txrx_info.cluster.memArea = cacheDmaMalloc(
                                    robo_txrx_info.cluster.memSize);
    if (robo_txrx_info.cluster.memArea == NULL) {
        free(robo_txrx_info.roboNetPoolID);
        robo_txrx_info.roboNetPoolID = NULL;
        free(robo_txrx_info.m_cl_blks.memArea);
        robo_txrx_info.m_cl_blks.memArea = NULL;
        return(0);
    }

    if (netPoolInit(robo_txrx_info.roboNetPoolID,
                &robo_txrx_info.m_cl_blks,
                &robo_txrx_info.cluster, 1, NULL) != OK) {

        free(robo_txrx_info.roboNetPoolID);
        robo_txrx_info.roboNetPoolID = NULL;
        free(robo_txrx_info.m_cl_blks.memArea);
        robo_txrx_info.m_cl_blks.memArea = NULL;
        free(robo_txrx_info.cluster.memArea);
        robo_txrx_info.cluster.memArea = NULL;
        return(0);
    }
    robo_txrx_info.clpool_id = netClPoolIdGet(robo_txrx_info.roboNetPoolID,
                                robo_txrx_info.cluster.clSize, FALSE);
    return(1);
}
Example #3
0
/* Netpool create */
LOCAL int
et_drvTxRxNetpoolCreate(int unit)
{
    et_drv_txrx_info[unit].et_drvNetPoolID =  (NET_POOL_ID)calloc(1, sizeof(NET_POOL));

    if (et_drv_txrx_info[unit].et_drvNetPoolID == NULL) {
        return(0);
    }

    et_drv_txrx_info[unit].m_cl_blks.mBlkNum = ET_DRV_TXRX_MBLKS;
    et_drv_txrx_info[unit].m_cl_blks.clBlkNum = ET_DRV_TXRX_CLBLKS;
    et_drv_txrx_info[unit].m_cl_blks.memSize =
            (et_drv_txrx_info[unit].m_cl_blks.mBlkNum * (M_BLK_SZ + sizeof(long))) +
            (et_drv_txrx_info[unit].m_cl_blks.clBlkNum * (CL_BLK_SZ + sizeof(long)));
    et_drv_txrx_info[unit].m_cl_blks.memArea = 
            (char *)memalign (sizeof (long), et_drv_txrx_info[unit].m_cl_blks.memSize);
    if (et_drv_txrx_info[unit].m_cl_blks.memArea == NULL) {
        free(et_drv_txrx_info[unit].et_drvNetPoolID);
        et_drv_txrx_info[unit].et_drvNetPoolID = NULL;
        return(0);
    }

    et_drv_txrx_info[unit].cluster.clNum = ET_DRV_TXRX_CLBUFS;
    et_drv_txrx_info[unit].cluster.clSize = ET_DRV_TX_RX_PK_SZ;
    et_drv_txrx_info[unit].cluster.memSize = et_drv_txrx_info[unit].cluster.clNum *
            (et_drv_txrx_info[unit].cluster.clSize + sizeof(long)) + sizeof(long);
    et_drv_txrx_info[unit].cluster.memArea = cacheDmaMalloc(
                                    et_drv_txrx_info[unit].cluster.memSize);
    if (et_drv_txrx_info[unit].cluster.memArea == NULL) {
        free(et_drv_txrx_info[unit].et_drvNetPoolID);
        et_drv_txrx_info[unit].et_drvNetPoolID = NULL;
        free(et_drv_txrx_info[unit].m_cl_blks.memArea);
        et_drv_txrx_info[unit].m_cl_blks.memArea = NULL;
        return(0);
    }

    if (netPoolInit(et_drv_txrx_info[unit].et_drvNetPoolID,
                &et_drv_txrx_info[unit].m_cl_blks,
                &et_drv_txrx_info[unit].cluster, 1, NULL) != OK) {

        free(et_drv_txrx_info[unit].et_drvNetPoolID);
        et_drv_txrx_info[unit].et_drvNetPoolID = NULL;
        free(et_drv_txrx_info[unit].m_cl_blks.memArea);
        et_drv_txrx_info[unit].m_cl_blks.memArea = NULL;
        free(et_drv_txrx_info[unit].cluster.memArea);
        et_drv_txrx_info[unit].cluster.memArea = NULL;
        return(0);
    }
    et_drv_txrx_info[unit].clpool_id = netClPoolIdGet(et_drv_txrx_info[unit].et_drvNetPoolID,
                                et_drv_txrx_info[unit].cluster.clSize, FALSE);
    return(1);
}
Example #4
0
File: netdrv.c Project: ariavie/bcm
/**
 *
 * NetdrvMemInit - initialize memory for the chip
 *
 * This routine is highly specific to the device.
 *
 * Input: device to be initialized
 * RETURNS: OK or ERROR.
 *
 *
 **/
STATUS
NetdrvMemInit(END_DEVICE * pDrvCtrl)
{
    

    /*
     * This is how we would set up and END netPool using netBufLib(1).
     * This code is pretty generic.
     */
    if(pDrvCtrl == NULL)
        return ERROR;

    if((pDrvCtrl->end.pNetPool = malloc (sizeof(NET_POOL))) == NULL)
        return (ERROR);

    NetdrvMclBlkConfig.mBlkNum = 1024 /*32*/;
    NetdrvClDescTbl[0].clNum = 512 /* 1MB */;
    NetdrvMclBlkConfig.clBlkNum = NetdrvClDescTbl[0].clNum;

    /* Calculate the total memory for all the M-Blks and CL-Blks. */
    NetdrvMclBlkConfig.memSize =
        (NetdrvMclBlkConfig.mBlkNum * (MSIZE + sizeof (int))) +
        (NetdrvMclBlkConfig.clBlkNum * (CL_BLK_SZ));

    NetdrvMclBlkConfig.memArea =
        (char *) memalign (4, (UINT) NetdrvMclBlkConfig.memSize);

    if(NetdrvMclBlkConfig.memArea == NULL)
        return (ERROR);

    /* Calculate the memory size of all the clusters. */
    NetdrvClDescTbl[0].memSize = (NetdrvClDescTbl[0].clNum *
        (NetdrvClDescTbl[0].clSize + sizeof(int)));

    /* Allocate the memory for the clusters from cache safe memory. */
    NetdrvClDescTbl[0].memArea =
        (char *) sal_dma_alloc(NetdrvClDescTbl[0].memSize, "mema");

    if (NetdrvClDescTbl[0].memArea == NULL) {
        PRINTF_ERROR(("\r\nsystem memory unavailable!"));
        return (ERROR);
    }

    /* Initialize the memory pool. */
    if (netPoolInit(pDrvCtrl->end.pNetPool, &NetdrvMclBlkConfig,
        &NetdrvClDescTbl[0], NetdrvClDescTblNumEnt, NULL) == ERROR) {
        PRINTF_ERROR(("\r\nCould not init buffering"));
        return (ERROR);
    }

    /*
     * If you need clusters to store received packets into then get them
     * here ahead of time.
     */
    if ((pDrvCtrl->pClPoolId =
        netClPoolIdGet (pDrvCtrl->end.pNetPool, sizeof (RFD), FALSE)) == NULL) {
        return (ERROR);
    }

    PRINTF_DEBUG(("\r\nMemory setup complete"));

    return OK;
}
Example #5
0
File: socend.c Project: ariavie/bcm
static	STATUS
socend_mempool_alloc(socend_t *se, int pksize, int clblks, int cl, int mblks)
/*
 * Function: 	socend_mempool_alloc
 * Purpose:	Initialize END memory pools for the specified SOC.
 * Parameters:	u - unit number to initialize.
 *		pksize - Packet size to use, MUST BE MTU size or greater.
 *		clblks - number of cluster block headers this unit
 *		cl - number of actual cluster buffers this unit.
 *		mblks - number of mblks this unit.
 *
 * Returns:	OK or error if failed.
 * Notes:	If already initialized, nothing is done.
 */
{
    seu_t	*seu = &socend_seu[se->se_unit];

    LOG_INFO(BSL_LS_SYS_END,
             (BSL_META("socend_mempool_alloc: Unit %d %sinitialized\n"),
              se->se_unit, seu->seu_init ? "" : "not "));
    /*
     * If already done, skip the allocation and just assign the required
     * values.
     */
    if (!seu->seu_init) {
	seu->seu_init = TRUE;
	seu->seu_netpool_id = (NET_POOL_ID)sal_alloc(sizeof(NET_POOL),
						     "net_pool");

	/* First Initialize the CL configuration */

	seu->seu_blks.mBlkNum = mblks;
	seu->seu_blks.clBlkNum= clblks;
	seu->seu_blks.memSize = (mblks * (M_BLK_SZ + sizeof(long)))
	    + (clblks * (CL_BLK_SZ + sizeof(long)));
	seu->seu_blks.memArea = sal_alloc(seu->seu_blks.memSize, "socend cl");

	/* Now initialize the actual cluster buffers that contain packets */

	seu->seu_cluster.clNum = cl;
	seu->seu_cluster.clSize = pksize;
	seu->seu_cluster.memSize = cl*(pksize + sizeof(long)) + sizeof(long);
       
        if (SOC_IS_ESW(se->se_unit)) {
           seu->seu_cluster.memArea = sal_dma_alloc(seu->seu_cluster.memSize,
						 "socend_mempool");
        } else {
           seu->seu_cluster.memArea = memalign(4096, 
                                           seu->seu_cluster.memSize);
        }
	/* Now set up the pool and GO! */

	if (!seu->seu_blks.memArea || !seu->seu_cluster.memArea ||
	    !seu->seu_netpool_id ||
	    (OK != netPoolInit(seu->seu_netpool_id, &seu->seu_blks,
			       &seu->seu_cluster, 1, NULL))){
	    LOG_CLI((BSL_META("socend_mempool_init: Failed for unit %d\n"), se->se_unit));
	    if (seu->seu_blks.memArea) {
		sal_free(seu->seu_blks.memArea);
	    }
	    if (seu->seu_cluster.memArea) {
		sal_dma_free(seu->seu_cluster.memArea);
	    }
	    if (seu->seu_netpool_id) {
		free(seu->seu_netpool_id);
	    }
	    bzero((void *)seu, sizeof(*seu));
	    return(ERROR);
	}
	seu->seu_clpool_id = netClPoolIdGet(seu->seu_netpool_id, pksize,
					    FALSE);
    }

    se->se_eo.pNetPool	= seu->seu_netpool_id;

    return(OK);
}