diff --git a/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_debugfs.c b/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_debugfs.c index 5f052fdc4af96b4299eb0154da41b7ea6a51536f..fa290fc0b9dfea731136b490e6368f41a6ec9a8c 100644 --- a/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_debugfs.c +++ b/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_debugfs.c @@ -33,119 +33,130 @@ #define PP_BM_DEBUGFS_DIR "ppv4_bm" +typedef int (*file_func)(struct seq_file *, void *); + +static int dbg_dump_hw_stats(struct seq_file *f, void *unused); +static int dbg_dump_sw_stats(struct seq_file *f, void *unused); +static int dbg_pop(struct seq_file *f, void *unused); +static int dbg_push(struct seq_file *f, void *unused); +static int dbg_test_dma(struct seq_file *f, void *unused); +static int dbg_test_init(struct seq_file *f, void *unused); + +struct bm_debugfs_file_info { + const char *name; + file_func func; +}; + +static struct bm_debugfs_file_info bm_debugfs_files[] = { + {"hw_stats", dbg_dump_hw_stats}, + {"sw_stats", dbg_dump_sw_stats}, + {"pop", dbg_pop}, + {"push", dbg_push}, + {"test_dma", dbg_test_dma}, + {"test_init", dbg_test_init}, +}; + //!< debugfs dir static struct dentry *bm_dir; +static u16 policy_pop_test; +static struct bmgr_buff_info buff_info; -ssize_t bm_commmads_read(void *data, u64 *val) -{ - pr_info("commands:\n"); - - pr_info("1. Init buffer manager\n"); - pr_info("2. Allocate default buffer\n"); - pr_info("3. De-Allocate default buffer\n"); - pr_info("4. Print DB counters\n"); - pr_info("5. Print HW counters\n"); - - return 0; -} - -void dump_db(struct bmgr_driver_private *pdata) +static void dump_pools(struct seq_file *f, struct bmgr_driver_private *pdata) { u8 idx; - u8 idx2; - u32 num = 0; - u32 pool_id = 0; - u32 max_allowed = 0; - struct bmgr_policy_db_entry *policy; struct bmgr_pool_db_entry *pool; - struct bmgr_group_db_entry *group; - struct bmgr_pool_in_policy_info *pool_in_policy; - - pr_info("=================================\n"); - pr_info("====== BUFFER MANAGER DUMP ======\n"); - pr_info("=================================\n"); - - // Dump all DB general counters - pr_info("======= GENERAL COUNTERS ========\n"); - pr_info("Number of active pools: %d\n", - pdata->driver_db.num_pools); - pr_info("Number of active groups: %d\n", - pdata->driver_db.num_groups); - pr_info("Number of active policies: %d\n", - pdata->driver_db.num_policies); // Dump all pools - pr_info("============= POOLS =============\n"); - for (idx = 0; idx < PP_BMGR_MAX_POOLS; idx++) { + seq_puts(f, "============= POOLS =============\n"); + for (idx = 0; idx < pdata->driver_db.num_pools; idx++) { pool = &pdata->driver_db.pools[idx]; if (!pool->is_busy) continue; - pr_info("Active pool %d:\n", idx); - pr_info("\t\tNum allocated buffers: %d\n", + seq_printf(f, "Active pool %d:\n", idx); + seq_printf(f, "\t\tNum allocated buffers: %d\n", pool->num_allocated_buffers); - pr_info("\t\tNum deallocated buffers: %d\n", + seq_printf(f, "\t\tNum deallocated buffers: %d\n", pool->num_deallocated_buffers); - pr_info("\t\tInternal table address: %x\n", + seq_printf(f, "\t\tInternal table address: %x\n", (phys_addr_t)pool->internal_pointers_tables); - pr_info("\t\tNum buffers: %d\n", + seq_printf(f, "\t\tNum buffers: %d\n", pool->pool_params.num_buffers); - pr_info("\t\tSize of buffer: %d\n", + seq_printf(f, "\t\tSize of buffer: %d\n", pool->pool_params.size_of_buffer); - pr_info("\t\tGroup id: %d\n", + seq_printf(f, "\t\tGroup id: %d\n", pool->pool_params.group_id); - pr_info("\t\tBase address low: 0x%x\n", + seq_printf(f, "\t\tBase address low: 0x%x\n", pool->pool_params.base_addr_low); - pr_info("\t\tBase address high: 0x%x\n", + seq_printf(f, "\t\tBase address high: 0x%x\n", pool->pool_params.base_addr_high); - pr_info("\t\tFlags: %d\n", + seq_printf(f, "\t\tFlags: %d\n", pool->pool_params.flags); } +} + +static void dump_groups(struct seq_file *f, struct bmgr_driver_private *pdata) +{ + struct bmgr_group_db_entry *group; + u8 idx; + u8 idx2; + u32 num = 0; // Dump all groups - pr_info("============= GROUPS ============\n"); - for (idx = 0; idx < PP_BMGR_MAX_GROUPS; idx++) { + seq_puts(f, "============= GROUPS ============\n"); + for (idx = 0; idx < pdata->driver_db.num_groups; idx++) { group = &pdata->driver_db.groups[idx]; if (group->num_pools_in_group) { - pr_info("Active group %d:\n", idx); - pr_info("\t\tAvailable buffers: %d\n", + seq_printf(f, "Active group %d:\n", idx); + seq_printf(f, "\t\tAvailable buffers: %d\n", group->available_buffers); - pr_info("\t\tReserved buffers: %d\n", + seq_printf(f, "\t\tReserved buffers: %d\n", group->reserved_buffers); - pr_info("\t\tPools in group:"); + seq_puts(f, "\t\tPools in group:"); num = group->num_pools_in_group; for (idx2 = 0; idx2 < num; idx2++) { if (group->pools[idx2]) - pr_info(" %d", idx2); + seq_printf(f, " %d", idx2); } - pr_info("\n"); + seq_puts(f, "\n"); } } +} + +static void dump_policies(struct seq_file *f, struct bmgr_driver_private *pdata) +{ + struct bmgr_policy_db_entry *policy; + struct bmgr_pool_in_policy_info *pool_in_policy; + u16 idx; + u8 idx2; + u32 num = 0; + u32 pool_id = 0; + u32 max_allowed = 0; // Dump all policies - pr_info("============= POLICIES ==========\n"); - for (idx = 0; idx < PP_BMGR_MAX_POLICIES; idx++) { + seq_puts(f, "============= POLICIES ==========\n"); + for (idx = 0; idx < pdata->driver_db.num_policies; idx++) { policy = &pdata->driver_db.policies[idx]; if (!policy->is_busy) continue; - pr_info("Active policy %d:\n", idx); - pr_info("\t\tNum allocated buffers: %d\n", + seq_printf(f, "Active policy %d:\n", idx); + seq_printf(f, "\t\tNum allocated buffers: %d\n", policy->num_allocated_buffers); - pr_info("\t\tNum deallocated buffers: %d\n", + seq_printf(f, "\t\tNum deallocated buffers: %d\n", policy->num_deallocated_buffers); - pr_info("\t\tMax allowed: %d\n", + seq_printf(f, "\t\tMax allowed: %d\n", policy->policy_params.max_allowed); - pr_info("\t\tMin guaranteed: %d\n", + seq_printf(f, "\t\tMin guaranteed: %d\n", policy->policy_params.min_guaranteed); - pr_info("\t\tGroup id: %d\n", + seq_printf(f, "\t\tGroup id: %d\n", policy->policy_params.group_id); - pr_info("\t\tFlags: %d\n", + seq_printf(f, "\t\tFlags: %d\n", policy->policy_params.flags); - pr_info("\t\tPools in policy:"); + seq_puts(f, "\t\tPools in policy:\n"); num = policy->policy_params.num_pools_in_policy; for (idx2 = 0; idx2 < num; idx2++) { pool_in_policy = @@ -153,80 +164,174 @@ void dump_db(struct bmgr_driver_private *pdata) pool_id = pool_in_policy->pool_id; max_allowed = pool_in_policy->max_allowed; - pr_info("\t\t\t%d. id %d, max allowed %d\n", + seq_printf(f, "\t\t\t%d. id %d, max allowed %d\n", idx2, pool_id, max_allowed); } } +} + +static void dump_db(struct seq_file *f, struct bmgr_driver_private *pdata) +{ + seq_puts(f, "=================================\n"); + seq_puts(f, "====== BUFFER MANAGER DUMP ======\n"); + seq_puts(f, "=================================\n"); - pr_info("=================================\n"); - pr_info("========== END OF DUMP ==========\n"); - pr_info("=================================\n"); + // Dump all DB general counters + seq_puts(f, "======= GENERAL COUNTERS ========\n"); + seq_printf(f, "Number of active pools: %d\n", + pdata->driver_db.num_pools); + seq_printf(f, "Number of active groups: %d\n", + pdata->driver_db.num_groups); + seq_printf(f, "Number of active policies: %d\n", + pdata->driver_db.num_policies); + + dump_pools(f, pdata); + dump_groups(f, pdata); + dump_policies(f, pdata); + + seq_puts(f, "=================================\n"); + seq_puts(f, "========== END OF DUMP ==========\n"); + seq_puts(f, "=================================\n"); } -static u16 policy_pop_test; -static struct bmgr_buff_info buff_info; +static int dbg_dump_hw_stats(struct seq_file *f, void *unused) +{ + struct bmgr_driver_private *pdata; + + pdata = dev_get_drvdata(f->private); + + print_hw_stats(); + + return 0; +} -ssize_t bm_commmads_write(void *data, u64 val) +static int dbg_dump_sw_stats(struct seq_file *f, void *unused) { - struct platform_device *pdev; struct bmgr_driver_private *pdata; - pdev = data; - pdata = platform_get_drvdata(pdev); + pdata = dev_get_drvdata(f->private); + + dump_db(f, pdata); + + return 0; +} + +static int dbg_test_dma(struct seq_file *f, void *unused) +{ + struct bmgr_driver_private *pdata; + + pdata = dev_get_drvdata(f->private); + + bmgr_test_dma(8); - dev_info(&pdev->dev, "command: %llu", val); - - switch (val) { - case 1: - test_init_bmgr(&pdev->dev); - break; - case 2: - memset(&buff_info, 0x0, sizeof(buff_info)); - - buff_info.num_allocs = 1; - buff_info.policy_id = policy_pop_test; - - bmgr_pop_buffer(&buff_info); - - policy_pop_test++; - if (policy_pop_test == 4) - policy_pop_test = 0; - - pr_info("pop buffer address 0x%x (high 0x%x) from policy %d pool %d\n", - buff_info.addr_low[0], buff_info.addr_high[0], - buff_info.policy_id, buff_info.pool_id[0]); - break; - case 3: - bmgr_push_buffer(&buff_info); - - pr_info("push buffer address 0x%x (high 0x%x) from policy %d pool %d\n", - buff_info.addr_low[0], buff_info.addr_high[0], - buff_info.policy_id, buff_info.pool_id[0]); - break; - case 4: - dump_db(pdata); - break; - case 5: - print_hw_stats(); - break; - default: - pr_info("unknown command\n"); - break; + return 0; +} + +static int dbg_test_init(struct seq_file *f, void *unused) +{ + struct bmgr_driver_private *pdata; + struct bmgr_pool_params pool_params; + struct bmgr_policy_params policy_params; + u8 pool_id; + u8 policy_id; + u8 num_buffers = 10; + u8 size_of_buffer = 64; + void *ptr = NULL; + + pdata = dev_get_drvdata(f->private); + + if (bmgr_driver_init() != 0) { + seq_puts(f, "dbg_test_init(): bmgr_driver_init failed\n"); + return 0; + } + + ptr = devm_kzalloc(f->private, + size_of_buffer * num_buffers, + GFP_KERNEL); + if (!ptr) + return 0; + + pool_params.base_addr_low = (u32)ptr; + + pool_params.base_addr_high = 0; + pool_params.size_of_buffer = size_of_buffer; + pool_params.num_buffers = num_buffers; + pool_params.group_id = 0; + pool_params.flags = 0; + if (bmgr_pool_configure(&pool_params, &pool_id) != 0) { + seq_puts(f, "dbg_test_init(): bmgr_pool_configure failed\n"); + return 0; } + seq_printf(f, "dbg_test_init(): configured pool_id %d with %d buffers (of %d), group id 0, address 0x%x\n", + pool_id, num_buffers, size_of_buffer, (u32)ptr); + + policy_params.flags = 0; + policy_params.group_id = 0; + policy_params.max_allowed = num_buffers / 2; + policy_params.min_guaranteed = num_buffers / 5; + policy_params.num_pools_in_policy = 1; + policy_params.pools_in_policy[0].max_allowed = num_buffers; + policy_params.pools_in_policy[0].pool_id = 0; + if (bmgr_policy_configure(&policy_params, &policy_id) != 0) { + seq_puts(f, "dbg_test_init(): bmgr_policy_configure failed\n"); + return 0; + } + + seq_printf(f, "dbg_test_init(): configured policy_id %d with max allowed %d, min guaranteed %d, pool 0 (max allowed %d) group 0\n", + policy_id, num_buffers / 2, num_buffers / 5, num_buffers); + return 0; } -DEFINE_DEBUGFS_ATTRIBUTE(bm_commmads_fops, - bm_commmads_read, - bm_commmads_write, - "%llu\n"); +// Currently pop one buffer from policies 0-3 in increament order +static int dbg_pop(struct seq_file *f, void *unused) +{ + struct bmgr_driver_private *pdata; + + pdata = dev_get_drvdata(f->private); + + memset(&buff_info, 0x0, sizeof(buff_info)); + + buff_info.num_allocs = 1; + buff_info.policy_id = policy_pop_test; + + bmgr_pop_buffer(&buff_info); + + policy_pop_test++; + if (policy_pop_test == 4) + policy_pop_test = 0; + + seq_printf(f, "pop buffer address 0x%x (high 0x%x) from policy %d pool %d\n", + buff_info.addr_low[0], buff_info.addr_high[0], + buff_info.policy_id, buff_info.pool_id[0]); + + return 0; +} + +// Currently push only last pop-ed buffer +static int dbg_push(struct seq_file *f, void *unused) +{ + struct bmgr_driver_private *pdata; + + pdata = dev_get_drvdata(f->private); + + bmgr_push_buffer(&buff_info); + + seq_printf(f, "push buffer address 0x%x (high 0x%x) from policy %d pool %d\n", + buff_info.addr_low[0], buff_info.addr_high[0], + buff_info.policy_id, buff_info.pool_id[0]); + + return 0; +} int bm_dbg_dev_init(struct platform_device *pdev) { struct bmgr_driver_private *pdata; struct dentry *dent; int err; + u32 num_files = sizeof(bm_debugfs_files)/sizeof(struct bm_debugfs_file_info); + u16 ind = 0; if (!pdev) { dev_err(&pdev->dev, "Invalid platform device\n"); @@ -274,16 +379,19 @@ int bm_dbg_dev_init(struct platform_device *pdev) return err; } - dent = debugfs_create_file("commands", 0644, - pdata->debugfs_info.dir, - pdev, - &bm_commmads_fops); - if (IS_ERR_OR_NULL(dent)) { - err = (int)PTR_ERR(dent); - dev_err(&pdev->dev, - "debugfs_create_file failed creating commands with %d\n", - err); - return err; + for (ind = 0; ind < num_files; ind++) { + dent = debugfs_create_devm_seqfile(&pdev->dev, + bm_debugfs_files[ind].name, + pdata->debugfs_info.dir, + bm_debugfs_files[ind].func); + if (IS_ERR_OR_NULL(dent)) { + err = (int)PTR_ERR(dent); + dev_err(&pdev->dev, + "debugfs_create_file failed creating %s with %d\n", + bm_debugfs_files[ind].name, + err); + return err; + } } return 0; diff --git a/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv.c b/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv.c index a0b4134a2578f08766ff69d6afe95593b6acb4e9..6dcfa2b6341cb1c5dff7dcef22c068c47708ee0c 100644 --- a/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv.c +++ b/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv.c @@ -25,10 +25,9 @@ * Santa Clara, CA 97052 */ -//#define _FPGA_ - #include <linux/kernel.h> #include <linux/platform_device.h> +#include <linux/of_device.h> #include <linux/debugfs.h> #include <linux/moduleparam.h> #include <linux/slab.h> @@ -83,12 +82,7 @@ static struct platform_driver g_bm_platform_driver = { }; //!< global pointer for private database -#ifdef _FPGA_ - static struct bmgr_driver_private real_driver_private; - static struct bmgr_driver_private *this = &real_driver_private; -#else - static struct bmgr_driver_private *this; -#endif +static struct bmgr_driver_private *this; void __iomem *bm_config_addr_base; void __iomem *bm_policy_mngr_addr_base; @@ -169,6 +163,59 @@ static s32 buffer_manager_db_init(struct bmgr_driver_private *priv) return 0; } +static struct resource *get_resource(struct platform_device *pdev, + const char *name, + unsigned int type, + size_t size) +{ + struct resource *r; + size_t sz; + struct device *dev; + + dev = &pdev->dev; + + r = platform_get_resource_byname(pdev, type, name); + if (!r) { + dev_err(dev, "Could not get %s resource\n", name); + return NULL; + } + + sz = resource_size(r); + if (size && sz != size) { + dev_err(dev, "Illegal size %zu for %s resource expected %zu\n", + sz, name, size); + return NULL; + } + + return r; +} + +static void print_resource(struct device *dev, + const char *name, + struct resource *r) +{ + + dev_info(dev, "%s memory resource: start(0x%08zX), size(%zu)\n", + name, + (size_t)(uintptr_t)r->start, + (size_t)(uintptr_t)resource_size(r)); +} + +static void __iomem *get_resource_mapped_addr(struct platform_device *pdev, + const char *name, + unsigned int size) +{ + struct resource *res; + + res = get_resource(pdev, name, IORESOURCE_MEM, size); + if (!res) + return NULL; + + print_resource(&pdev->dev, name, res); + + return devm_ioremap_resource(&pdev->dev, res); +} + /************************************************************************** *! \fn buffer_manager_probe ************************************************************************** @@ -184,18 +231,17 @@ static int buffer_manager_probe(struct platform_device *pdev) { int ret; struct bmgr_driver_private *priv; - struct resource *res[3]; - int i; + u32 val; + struct device_node *node; + int err; dev_info(&pdev->dev, "BM probe...\n"); -#ifdef _FPGA_ - priv = this; -#else + node = pdev->dev.of_node; + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; -#endif platform_set_drvdata(pdev, priv); priv->pdev = pdev; @@ -208,21 +254,9 @@ static int buffer_manager_probe(struct platform_device *pdev) return -ENOMEM; } - /* load the memory ranges */ - for (i = 0; i < 3; i++) { - //dev_info(&pdev->dev, "i = %d\n", i); - res[i] = platform_get_resource(pdev, IORESOURCE_MEM, i); - if (!res[i]) { - dev_err(&pdev->dev, "failed to get resources %d\n", i); - return -ENOENT; - } - //dev_info(&pdev->dev, "i = %d, resource start = %d\n", - // i, res[i]->start); - } - - bm_config_addr_base = devm_ioremap_resource(&pdev->dev, res[0]); - bm_policy_mngr_addr_base = devm_ioremap_resource(&pdev->dev, res[1]); - uc_mcdma0_config_addr_base = devm_ioremap_resource(&pdev->dev, res[2]); + bm_config_addr_base = get_resource_mapped_addr(pdev, "reg-config", 0x10000); + bm_policy_mngr_addr_base = get_resource_mapped_addr(pdev, "ram-config", 0x10000); + uc_mcdma0_config_addr_base = get_resource_mapped_addr(pdev, "uc-mcdma0", 0x200); if (!bm_config_addr_base || !bm_policy_mngr_addr_base || @@ -231,6 +265,54 @@ static int buffer_manager_probe(struct platform_device *pdev) return -ENOMEM; } + err = of_property_read_u32(node, "intel,max-policies", &val); + if (err) { + dev_err(&pdev->dev, + "Could not get max policies from DT, error is %d\n", + err); + return -ENODEV; + } + + dev_info(&pdev->dev, "max-policies = %d\n", val); + this->driver_db.max_policies = val; + if (this->driver_db.max_policies > PP_BMGR_MAX_POLICIES) { + dev_err(&pdev->dev, "max policies %d is %d\n", + this->driver_db.max_policies, PP_BMGR_MAX_POLICIES); + return -ENODEV; + } + + err = of_property_read_u32(node, "intel,max-groups", &val); + if (err) { + dev_err(&pdev->dev, + "Could not get max groups from DT, error is %d\n", + err); + return -ENODEV; + } + + dev_info(&pdev->dev, "max-groups = %d\n", val); + this->driver_db.max_groups = val; + if (this->driver_db.max_groups > PP_BMGR_MAX_GROUPS) { + dev_err(&pdev->dev, "max groups %d is %d\n", + this->driver_db.max_groups, PP_BMGR_MAX_GROUPS); + return -ENODEV; + } + + err = of_property_read_u32(node, "intel,max-pools", &val); + if (err) { + dev_err(&pdev->dev, + "Could not get max pools from DT, error is %d\n", + err); + return -ENODEV; + } + + dev_info(&pdev->dev, "max-pools = %d\n", val); + this->driver_db.max_pools = val; + if (this->driver_db.max_pools > PP_BMGR_MAX_POOLS) { + dev_err(&pdev->dev, "max pools %d is %d\n", + this->driver_db.max_pools, PP_BMGR_MAX_POOLS); + return -ENODEV; + } + bm_dbg_dev_init(pdev); return 0; @@ -439,9 +521,9 @@ static s32 bmgr_is_pool_params_valid( return -EINVAL; } - if (pool_params->group_id >= PP_BMGR_MAX_GROUPS) { + if (pool_params->group_id >= this->driver_db.max_groups) { pr_err("bmgr_is_pool_params_valid: group_id %d must be smaller than %d\n", - pool_params->group_id, PP_BMGR_MAX_GROUPS); + pool_params->group_id, this->driver_db.max_groups); return -EINVAL; } @@ -467,9 +549,9 @@ static s32 bmgr_is_policy_params_valid( return -EINVAL; } - if (policy_params->group_id >= PP_BMGR_MAX_GROUPS) { + if (policy_params->group_id >= this->driver_db.max_groups) { pr_err("group_id %d >= %d\n", - policy_params->group_id, PP_BMGR_MAX_GROUPS); + policy_params->group_id, this->driver_db.max_groups); return -EINVAL; } @@ -523,9 +605,9 @@ static s32 bmgr_enable_min_guarantee_per_pool(u8 pool_id, u8 enable) u32 mask; // Validity check - if (pool_id >= PP_BMGR_MAX_POOLS) { + if (pool_id >= this->driver_db.max_pools) { pr_err("pool_id %d out of range %d\n", - pool_id, PP_BMGR_MAX_POOLS); + pool_id, this->driver_db.max_pools); return -EINVAL; } @@ -563,9 +645,9 @@ static s32 bmgr_pool_enable(u8 pool_id, bool enable) u32 mask; // Validity check - if (pool_id >= PP_BMGR_MAX_POOLS) { + if (pool_id >= this->driver_db.max_pools) { pr_err("pool_id %d out of range %d\n", - pool_id, PP_BMGR_MAX_POOLS); + pool_id, this->driver_db.max_pools); return -EINVAL; } @@ -603,9 +685,9 @@ static s32 bmgr_pool_reset_fifo(u8 pool_id) u32 reset_reg; // Validity check - if (pool_id >= PP_BMGR_MAX_POOLS) { + if (pool_id >= this->driver_db.max_pools) { pr_err("pool_id %d out of range %d\n", - pool_id, PP_BMGR_MAX_POOLS); + pool_id, this->driver_db.max_pools); return -EINVAL; } @@ -1483,28 +1565,29 @@ static u32 bmgr_get_policy_num_allocated_per_pool(u8 policy_id, BM_RAM_BASE, pool_id, policy_id)); } -static s32 bmgr_test_dma(u32 num_bytes) +s32 bmgr_test_dma(u32 num_bytes) { - void *addr; - void *addr1; + void *addr = NULL; + void *addr1 = NULL; dma_addr_t dma; dma_addr_t dma1; - addr = dmam_alloc_coherent(&this->pdev->dev, + addr = dma_alloc_coherent(&this->pdev->dev, 2 * sizeof(u32), &dma, GFP_KERNEL | GFP_DMA); if (!addr) { - dev_err(&this->pdev->dev, "Could not allocate using dmam_alloc_coherent\n"); + dev_err(&this->pdev->dev, "Could not allocate addr using dmam_alloc_coherent\n"); return -ENOMEM; } - addr1 = dmam_alloc_coherent(&this->pdev->dev, + addr1 = dma_alloc_coherent(&this->pdev->dev, 2 * sizeof(u32), &dma1, GFP_KERNEL | GFP_DMA); if (!addr1) { - dev_err(&this->pdev->dev, "Could not allocate using dmam_alloc_coherent\n"); + dev_err(&this->pdev->dev, "Could not allocate addr1 using dmam_alloc_coherent\n"); + dma_free_coherent(&this->pdev->dev, 2 * sizeof(u32), addr, dma); return -ENOMEM; } @@ -1516,14 +1599,24 @@ static s32 bmgr_test_dma(u32 num_bytes) pr_info("ADDRESSES ======> 0x%x[0x%x] ; 0x%x[0x%x] ; 0x%x[0x%x] ; 0x%x[0x%x]\n", (u32)addr, (u32)dma, (u32)(addr + 4), (u32)(dma + 4), (u32)(addr1), (u32)(dma1), (u32)(addr1 + 4), (u32)(dma1 + 4)); - pr_info("TEST 1 ======> 0x%x ; 0x%x ; 0x%x ; 0x%x\n", + pr_info("Before TEST ======> 0x%x ; 0x%x ; 0x%x ; 0x%x\n", RD_REG_32(addr), RD_REG_32(addr + 4), RD_REG_32(addr1), RD_REG_32(addr1 + 4)); copy_dma((u32)dma1, (u32)dma, (0x80100000 | (8 * num_bytes))); - pr_info("TEST 2 ======> 0x%x ; 0x%x ; 0x%x ; 0x%x\n", + pr_info("After TEST ======> 0x%x ; 0x%x ; 0x%x ; 0x%x\n", RD_REG_32(addr), RD_REG_32(addr + 4), RD_REG_32(addr1), RD_REG_32(addr1 + 4)); + if ((RD_REG_32(addr) == RD_REG_32(addr1)) && + (RD_REG_32(addr + 4) == RD_REG_32(addr1 + 4))) { + pr_info("\nDMA Test OK\n"); + } else { + pr_info("\nDMA Test Failed\n"); + } + + dma_free_coherent(&this->pdev->dev, 2 * sizeof(u32), addr1, dma1); + dma_free_coherent(&this->pdev->dev, 2 * sizeof(u32), addr, dma); + return 0; } @@ -1594,7 +1687,7 @@ s32 bmgr_pop_buffer(struct bmgr_buff_info * const buff_info) (void *)buff_info->addr_low[index], (void *)buff_info->addr_high[index]); - if (buff_info->pool_id[index] >= PP_BMGR_MAX_POOLS) { + if (buff_info->pool_id[index] >= this->driver_db.max_pools) { this->driver_db.policies[buff_info->policy_id]. num_allocated_buffers += index; pr_info("Can't pop from policy %d\n", @@ -1699,11 +1792,11 @@ s32 bmgr_driver_init(void) bmgr_configure_ocp_master(); // Reset group reserved buffers - for (index = 0; index < PP_BMGR_MAX_GROUPS; index++) + for (index = 0; index < this->driver_db.max_groups; index++) bmgr_set_group_reserved_buffers(index, 0); // Init RAM - for (index = 0; index < PP_BMGR_MAX_POLICIES; index++) { + for (index = 0; index < this->driver_db.max_policies; index++) { bmgr_set_policy_max_allowed_per_policy(index, 0); bmgr_set_policy_min_guaranteed_per_policy(index, 0); bmgr_set_policy_group_association(index, 0); @@ -1711,7 +1804,7 @@ s32 bmgr_driver_init(void) 0); WR_REG_32(BMGR_POLICY_ALLOC_BUFF_COUNTER_ADDR(BM_RAM_BASE, index), 0); - for (idx2 = 0; idx2 < PP_BMGR_MAX_POOLS; idx2++) { + for (idx2 = 0; idx2 < this->driver_db.max_pools; idx2++) { bmgr_set_policy_max_allowed_per_pool(index, idx2, 0); WR_REG_32(BMGR_POLICY_ALLOC_BUFF_PER_POOL_COUNTER_ADDR( BM_RAM_BASE, idx2, index), 0); @@ -1749,9 +1842,6 @@ s32 bmgr_pool_configure(const struct bmgr_pool_params * const pool_params, u64 user_array_ptr; u32 phy_ll_base; u32 val = 0; -#ifdef _FPGA_ - //u32 fpga_ddr_address = 0x500000; -#endif pr_info("Configuring buffer manager pool..."); @@ -1766,7 +1856,7 @@ s32 bmgr_pool_configure(const struct bmgr_pool_params * const pool_params, *pool_id = 0; // Find next available slot in pools db - for (index = 0; index < PP_BMGR_MAX_POOLS; index++) { + for (index = 0; index < this->driver_db.max_pools; index++) { if (this->driver_db.pools[index].is_busy == 0) { *pool_id = index; break; @@ -1774,7 +1864,7 @@ s32 bmgr_pool_configure(const struct bmgr_pool_params * const pool_params, } // If not found (Can be done also using num_pools) - if (index == PP_BMGR_MAX_POOLS) { + if (index == this->driver_db.max_pools) { pr_err("bmgr_pool_configure: pools DB is full!"); status = -EIO; @@ -1782,15 +1872,9 @@ s32 bmgr_pool_configure(const struct bmgr_pool_params * const pool_params, } // Allocate pool_param->pool_num_of_buff * POINTER_SIZE bytes array -#ifdef _FPGA_ - pointers_table = (void *)(pool_params->base_addr_low + - pool_params->num_buffers * pool_params->size_of_buffer + - 0x1000);//(void *)fpga_ddr_address; -#else pointers_table = devm_kzalloc(&this->pdev->dev, sizeof(u32) * pool_params->num_buffers, GFP_KERNEL); -#endif if (!pointers_table) { pr_err("bmgr_pool_configure: Failed to allocate pointers_table, num_buffers %d", pool_params->num_buffers); @@ -1798,12 +1882,8 @@ s32 bmgr_pool_configure(const struct bmgr_pool_params * const pool_params, goto unlock; } -#ifdef _FPGA_ - temp_pointers_table_ptr = (u32 *)((u32)pointers_table + - this->debugfs_info.ddrvirt2phyoff); -#else temp_pointers_table_ptr = (u32 *)pointers_table; -#endif + user_array_ptr = (pool_params->base_addr_low) | ((u64)pool_params->base_addr_high << 32); @@ -1931,9 +2011,7 @@ s32 bmgr_pool_configure(const struct bmgr_pool_params * const pool_params, free_memory: // free pointers_table - #ifndef _FPGA_ kfree(pointers_table); - #endif unlock: // @unlock bmgr_db_unlock(); @@ -1976,7 +2054,7 @@ s32 bmgr_policy_configure(const struct bmgr_policy_params * const policy_params, *policy_id = 0; // Find next available slot in policy db - for (index = 0; index < PP_BMGR_MAX_POLICIES; index++) { + for (index = 0; index < this->driver_db.max_policies; index++) { if (this->driver_db.policies[index].is_busy == 0) { *policy_id = index; break; @@ -1984,7 +2062,7 @@ s32 bmgr_policy_configure(const struct bmgr_policy_params * const policy_params, } // If not found (Can be done also using num_policies) - if (index == PP_BMGR_MAX_POLICIES) { + if (index == this->driver_db.max_policies) { pr_err("No free policy!"); status = -EIO; @@ -2061,62 +2139,6 @@ unlock: } EXPORT_SYMBOL(bmgr_policy_configure); -void test_init_bmgr(struct device *dev) -{ - struct bmgr_pool_params pool_params; - struct bmgr_policy_params policy_params; - u8 pool_id; - u8 policy_id; - u8 num_buffers = 10; - u8 size_of_buffer = 64; - void *ptr = NULL; - - if (bmgr_driver_init() != RC_SUCCESS) { - pr_err("commands_store(): bmgr_driver_init failed\n"); - return; - } - - #ifdef _FPGA_ - pool_params.base_addr_low = 0x400000; - #else - ptr = devm_kzalloc(dev, - size_of_buffer * num_buffers, - GFP_KERNEL); - if (!ptr) - return; - - pool_params.base_addr_low = (u32)ptr; - #endif - - pool_params.base_addr_high = 0; - pool_params.size_of_buffer = size_of_buffer; - pool_params.num_buffers = num_buffers; - pool_params.group_id = 0; - pool_params.flags = 0; - if (bmgr_pool_configure(&pool_params, &pool_id) != RC_SUCCESS) { - pr_err("commands_store(): bmgr_pool_configure failed\n"); - return; - } - - pr_info("test_init_bmgr(): configured pool_id %d with %d buffers (of %d), group id 0, address 0x%x\n", - pool_id, num_buffers, size_of_buffer, (u32)ptr); - - policy_params.flags = 0; - policy_params.group_id = 0; - policy_params.max_allowed = num_buffers / 2; - policy_params.min_guaranteed = num_buffers / 5; - policy_params.num_pools_in_policy = 1; - policy_params.pools_in_policy[0].max_allowed = num_buffers; - policy_params.pools_in_policy[0].pool_id = 0; - if (bmgr_policy_configure(&policy_params, &policy_id) != RC_SUCCESS) { - pr_err("test_init_bmgr(): bmgr_policy_configure failed\n"); - return; - } - - pr_info("test_init_bmgr(): configured policy_id %d with max allowed %d, min guaranteed %d, pool 0 (max allowed %d) group 0\n", - policy_id, num_buffers / 2, num_buffers / 5, num_buffers); -} - void print_hw_stats(void) { u32 counter; diff --git a/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv.h b/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv.h index b2dc147cab219bfb3aa84939a5b508a090ceffe4..911eb8b0729373986bc4568bc37cec123bede5a1 100644 --- a/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv.h +++ b/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv.h @@ -34,49 +34,25 @@ ********************************** **********************************/ -#define FALCON_SOC - -#ifdef FALCON_SOC - /*! \def PP_BMGR_MAX_POOLS - * Max supported pools - */ - #define PP_BMGR_MAX_POOLS (4) - - /*! \def PP_BMGR_MAX_POOLS_IN_GROUP - * Max pools in group - */ - #define PP_BMGR_MAX_POOLS_IN_GROUP (4) - - /*! \def PP_BMGR_MAX_GROUPS - * Max supported groups - */ - #define PP_BMGR_MAX_GROUPS (2) - - /*! \def PP_BMGR_MAX_POLICIES - * Max supported policies - */ - #define PP_BMGR_MAX_POLICIES (32) -#else /* PPv4 */ - /*! \def PP_BMGR_MAX_POOLS - * Max supported pools - */ - #define PP_BMGR_MAX_POOLS (16) +/*! \def PP_BMGR_MAX_POOLS + * Max supported pools. Real max defined in the DTS + */ +#define PP_BMGR_MAX_POOLS (16) - /*! \def PP_BMGR_MAX_POOLS_IN_GROUP - * Max pools in group - */ - #define PP_BMGR_MAX_POOLS_IN_GROUP (4) +/*! \def PP_BMGR_MAX_POOLS_IN_GROUP + * Max pools in group + */ +#define PP_BMGR_MAX_POOLS_IN_GROUP (4) - /*! \def PP_BMGR_MAX_GROUPS - * Max supported groups - */ - #define PP_BMGR_MAX_GROUPS (16) +/*! \def PP_BMGR_MAX_GROUPS + * Max supported groups. Real max defined in the DTS + */ +#define PP_BMGR_MAX_GROUPS (16) - /*! \def PP_BMGR_MAX_POLICIES - * Max supoorted policies - */ - #define PP_BMGR_MAX_POLICIES (256) -#endif +/*! \def PP_BMGR_MAX_POLICIES + * Max supoorted policies. Real max defined in the DTS + */ +#define PP_BMGR_MAX_POLICIES (256) /*! \def POOL_ENABLE_FOR_MIN_GRNT_POLICY_CALC * bmgr pools flags (Used in bmgr_pool_params.pool_flags) diff --git a/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv_internal.h b/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv_internal.h index 5f4c548c2a12b8de8c1889772c5ef41a38055fd2..e37fa13e9cb646846a1df6189493b37cabc03846 100644 --- a/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv_internal.h +++ b/drivers/net/ethernet/lantiq/ppv4/bm/pp_bm_drv_internal.h @@ -164,6 +164,14 @@ struct bmgr_driver_db { //!< Number of active policies u32 num_policies; + // per project constants + //!< Max number of pools + u32 max_pools; + //!< Max number of groups + u32 max_groups; + //!< Max number of policies + u32 max_policies; + //!< spinlock spinlock_t db_lock; }; @@ -178,9 +186,9 @@ struct bmgr_driver_db { struct bmgr_debugfs_info { //!< Debugfs dir struct dentry *dir; - u32 virt2phyoff; - u32 ddrvirt2phyoff; - u32 fpga_offset; + u32 virt2phyoff; + u32 ddrvirt2phyoff; + u32 fpga_offset; }; /************************************************************************** @@ -194,14 +202,14 @@ struct bmgr_driver_private { //!< Platform device pointer struct platform_device *pdev; //!< Is driver enabled - int enabled; + int enabled; //!< Platform device DB struct bmgr_driver_db driver_db; //!< Debugfs info struct bmgr_debugfs_info debugfs_info; }; -void test_init_bmgr(struct device *dev); +s32 bmgr_test_dma(u32 num_bytes); void print_hw_stats(void); int bm_dbg_dev_init(struct platform_device *pdev); diff --git a/include/net/pp_bm_regs.h b/include/net/pp_bm_regs.h index 83d6e94c3199c1caeafe9fd93f6bfc48c44ed550..b757623938c595cf5791a57ced33a7b0cd7c45fc 100755 --- a/include/net/pp_bm_regs.h +++ b/include/net/pp_bm_regs.h @@ -79,7 +79,8 @@ #define BMGR_POLICY_ALLOC_BUFF_PER_POOL_COUNTER_ADDR(BMGR_RAM_BASE, pool, policy) (BMGR_RAM_BASE + 0xB000 + BMGR_OFFSET_OF_POOL_IN_POLICY(pool, policy)) // Data -#define BMGR_DATAPATH_BASE (0x18BC0000) +#define BMGR_DATAPATH_BASE_HOST (0x18BC0000) +#define BMGR_DATAPATH_BASE (0x3C0000) #endif // _PP_BMGR_REGS_H_