static int dpbp_init(void) { int err; struct dpbp_attr dpbp_attr; struct dpbp_cfg dpbp_cfg; dflt_dpbp = (struct fsl_dpbp_obj *)malloc(sizeof(struct fsl_dpbp_obj)); if (!dflt_dpbp) { printf("No memory: malloc() failed\n"); err = -ENOMEM; goto err_malloc; } dpbp_cfg.options = 512; err = dpbp_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpbp_cfg, &dflt_dpbp->dpbp_handle); if (err < 0) { err = -ENODEV; printf("dpbp_create() failed: %d\n", err); goto err_create; } memset(&dpbp_attr, 0, sizeof(struct dpbp_attr)); err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle, &dpbp_attr); if (err < 0) { printf("dpbp_get_attributes() failed: %d\n", err); goto err_get_attr; } dflt_dpbp->dpbp_attr.id = dpbp_attr.id; #ifdef DEBUG printf("Init: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id); #endif err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); if (err < 0) { printf("dpbp_close() failed: %d\n", err); goto err_close; } return 0; err_close: free(dflt_dpbp); err_get_attr: dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); dpbp_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); err_create: err_malloc: return err; }
static void ldpaa_dpbp_free(void) { ldpaa_dpbp_drain(); dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); dpbp_reset(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); }
int dpaa2_create_dpbp_device( int dpbp_id) { struct dpaa2_dpbp_dev *dpbp_node; int ret; if (!dpbp_dev_list) { dpbp_dev_list = malloc(sizeof(struct dpbp_device_list)); if (!dpbp_dev_list) { PMD_INIT_LOG(ERR, "Memory alloc failed in DPBP list\n"); return -1; } /* Initialize the DPBP List */ TAILQ_INIT(dpbp_dev_list); } /* Allocate DPAA2 dpbp handle */ dpbp_node = (struct dpaa2_dpbp_dev *) malloc(sizeof(struct dpaa2_dpbp_dev)); if (!dpbp_node) { PMD_INIT_LOG(ERR, "Memory allocation failed for DPBP Device"); return -1; } /* Open the dpbp object */ dpbp_node->dpbp.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX]; ret = dpbp_open(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_id, &dpbp_node->token); if (ret) { PMD_INIT_LOG(ERR, "Resource alloc failure with err code: %d", ret); free(dpbp_node); return -1; } /* Clean the device first */ ret = dpbp_reset(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token); if (ret) { PMD_INIT_LOG(ERR, "Failure cleaning dpbp device with" " error code %d\n", ret); dpbp_close(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token); free(dpbp_node); return -1; } dpbp_node->dpbp_id = dpbp_id; rte_atomic16_init(&dpbp_node->in_use); TAILQ_INSERT_HEAD(dpbp_dev_list, dpbp_node, next); PMD_INIT_LOG(DEBUG, "Buffer pool resource initialized %d", dpbp_id); return 0; }
static int ldpaa_dpbp_setup(void) { int err; err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id, &dflt_dpbp->dpbp_handle); if (err) { printf("dpbp_open() failed\n"); goto err_open; } err = dpbp_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); if (err) { printf("dpbp_enable() failed\n"); goto err_enable; } err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle, &dflt_dpbp->dpbp_attr); if (err) { printf("dpbp_get_attributes() failed\n"); goto err_get_attr; } err = ldpaa_dpbp_seed(dflt_dpbp->dpbp_attr.bpid); if (err) { printf("Buffer seeding failed for DPBP %d (bpid=%d)\n", dflt_dpbp->dpbp_attr.id, dflt_dpbp->dpbp_attr.bpid); goto err_seed; } return 0; err_seed: err_get_attr: dpbp_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); err_enable: dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); err_open: return err; }
static int dpbp_init(void) { int err; struct dpbp_attr dpbp_attr; struct dpbp_cfg dpbp_cfg; uint16_t major_ver, minor_ver; dflt_dpbp = (struct fsl_dpbp_obj *)calloc( sizeof(struct fsl_dpbp_obj), 1); if (!dflt_dpbp) { printf("No memory: calloc() failed\n"); err = -ENOMEM; goto err_calloc; } dpbp_cfg.options = 512; err = dpbp_create(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, &dpbp_cfg, &dflt_dpbp->dpbp_id); if (err < 0) { err = -ENODEV; printf("dpbp_create() failed: %d\n", err); goto err_create; } err = dpbp_get_api_version(dflt_mc_io, 0, &major_ver, &minor_ver); if (err < 0) { printf("dpbp_get_api_version() failed: %d\n", err); goto err_get_api_ver; } if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR && minor_ver < DPBP_VER_MINOR)) { printf("DPBP version mismatch found %u.%u,", major_ver, minor_ver); printf("supported version is %u.%u\n", DPBP_VER_MAJOR, DPBP_VER_MINOR); } err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_id, &dflt_dpbp->dpbp_handle); if (err) { printf("dpbp_open() failed\n"); goto err_open; } memset(&dpbp_attr, 0, sizeof(struct dpbp_attr)); err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle, &dpbp_attr); if (err < 0) { printf("dpbp_get_attributes() failed: %d\n", err); goto err_get_attr; } if (dflt_dpbp->dpbp_id != dpbp_attr.id) { printf("dpbp object id and attribute id are not same\n"); goto err_attr_not_same; } #ifdef DEBUG printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id); #endif err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); if (err < 0) { printf("dpbp_close() failed: %d\n", err); goto err_close; } return 0; err_get_attr: err_attr_not_same: dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_id); err_get_api_ver: err_close: err_open: err_create: free(dflt_dpbp); err_calloc: return err; }
static int dpbp_init(void) { int err; struct dpbp_attr dpbp_attr; struct dpbp_cfg dpbp_cfg; dflt_dpbp = (struct fsl_dpbp_obj *)malloc(sizeof(struct fsl_dpbp_obj)); if (!dflt_dpbp) { printf("No memory: malloc() failed\n"); err = -ENOMEM; goto err_malloc; } dpbp_cfg.options = 512; err = dpbp_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpbp_cfg, &dflt_dpbp->dpbp_handle); if (err < 0) { err = -ENODEV; printf("dpbp_create() failed: %d\n", err); goto err_create; } memset(&dpbp_attr, 0, sizeof(struct dpbp_attr)); err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle, &dpbp_attr); if (err < 0) { printf("dpbp_get_attributes() failed: %d\n", err); goto err_get_attr; } if ((dpbp_attr.version.major != DPBP_VER_MAJOR) || (dpbp_attr.version.minor != DPBP_VER_MINOR)) { printf("DPBP version mismatch found %u.%u,", dpbp_attr.version.major, dpbp_attr.version.minor); printf("supported version is %u.%u\n", DPBP_VER_MAJOR, DPBP_VER_MINOR); } dflt_dpbp->dpbp_attr.id = dpbp_attr.id; #ifdef DEBUG printf("Init: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id); #endif err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); if (err < 0) { printf("dpbp_close() failed: %d\n", err); goto err_close; } return 0; err_close: free(dflt_dpbp); err_get_attr: dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); dpbp_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); err_create: err_malloc: return err; }