/* * * cppi_server.c * Description: * cppi over MRPC server driver * * * GPL LICENSE SUMMARY * * Copyright(c) 2016-2018 Intel Corporation. * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * The full GNU General Public License is included in this distribution * in the file called LICENSE.GPL. * * Contact Information: * Intel Corporation * 2200 Mission College Blvd. * Santa Clara, CA 97052 */ #define pr_fmt(fmt) KBUILD_MODNAME ":%s:%d " fmt "\n", __func__, __LINE__ /************************************************/ /** Includes */ /************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define DEBUG #ifdef DEBUG #define DBG(fmt, ...) pr_err(fmt, ##__VA_ARGS__) #else #define DBG(fmt, ...) pr_debug(fmt, ##__VA_ARGS__) #endif /* driver private database */ struct cppi_private { struct platform_device *pdev; /* platform device */ struct mrpc_server *mrpc; /* mrpc server handle */ }; struct mrpc_cppi_init_pp_buffer_pool_args { Uint32 size; }; struct mrpc_cppi_get_skb_shared_info_struct_size_args { Uint32 sizeof_arm_skb_shared_info_struct; }; /* p_arglen is assigned the sizof(func_args), therefor each arguments struct name should begin with the function's name */ #define CPPI_PROC_32(proc, func) \ MRPC_PROCINFO_ENTRY(proc, func, sizeof(struct func ## _args), sizeof(Uint32)) typedef enum { SKB_SHARED_INFO_STATUS_OK = 0, SKB_SHARED_INFO_STATUS_NOK, } skb_shared_info_status_e; enum { CPPI_INIT_PP_BUFFER_POOL = 0, CPPI_GET_SKB_SHARED_INFO, }; static int mrpc_cppi_init_pp_buffer_pool(void *arg, ssize_t arglen, void *rep, ssize_t replen) { Uint32 *p_rep = rep; struct mrpc_cppi_init_pp_buffer_pool_args *p_arg = arg; Uint32 size; Uint32 *buf; *p_rep = 0; size = be32_to_cpu(p_arg->size); printk(KERN_ERR "MRPC server mrpc_cppi_init_pp_buffer_pool with size: %d\n", size); buf = PAL_osMemAllocSizeAligned(size); if (NULL != buf) { memset(buf, 0, size); *p_rep = virt_to_phys(buf); } DBG("init_pp_buffer_pool: size: %d phys_addr: 0x%x\n", size, *p_rep); *p_rep = cpu_to_be32(*p_rep); return 0; } static int mrpc_cppi_get_skb_shared_info_struct_size(void *arg, ssize_t arglen, void *rep, ssize_t replen) { Uint32 *p_rep = rep; *p_rep = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); printk(KERN_ERR "MRPC server mrpc_cppi_get_skb_shared_info_struct_size with skb_shared_info_size (reply): %d\n", *p_rep); *p_rep = cpu_to_be32(*p_rep); return 0; } static struct mrpc_procinfo cppi_server_procs[] = { CPPI_PROC_32(CPPI_INIT_PP_BUFFER_POOL, mrpc_cppi_init_pp_buffer_pool), CPPI_PROC_32(CPPI_GET_SKB_SHARED_INFO, mrpc_cppi_get_skb_shared_info_struct_size), }; /* sysfs for future use */ static ssize_t status_show(struct device *dev, struct device_attribute *attr, char *buf) { struct cppi_private *priv = dev_get_drvdata(dev); if (!priv) return -EINVAL; return scnprintf(buf, PAGE_SIZE, "status ok"); } static DEVICE_ATTR(status, S_IRUGO, status_show, NULL); static struct attribute *cppi_attrs[] = { &dev_attr_status.attr, NULL }; static struct attribute_group cppi_attrs_group = { .attrs = cppi_attrs, }; /** * cppi_probe * * @param pdev platform device * * @return 0 for success, error code otherwise */ static int cppi_probe(struct platform_device *pdev) { struct cppi_private *priv; int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) { pr_err("memory allocation failed"); return -ENOMEM; } dev_set_drvdata(&pdev->dev, priv); priv->pdev = pdev; ret = sysfs_create_group(&priv->pdev->dev.kobj, &cppi_attrs_group); if (ret) { pr_err("sysfs_create_group failed (ret=%d)", ret); return ret; } priv->mrpc = mrpc_server_register(MRPC_RESERVED_ID_CPPI, "cppi_server", cppi_server_procs, ARRAY_SIZE(cppi_server_procs)); if (!priv->mrpc) { pr_err("failed to register cppi"); ret = -ENODEV; goto out_remove_group; } return 0; out_remove_group: sysfs_remove_group(&priv->pdev->dev.kobj, &cppi_attrs_group); return ret; } /** * cppi_remove * * This function is called when the cppi driver is removed. * * @param pdev platform device * * @return 0 for success, error code otherwise */ static int cppi_remove(struct platform_device *pdev) { struct cppi_private *priv = platform_get_drvdata(pdev); mrpc_server_unregister(priv->mrpc); sysfs_remove_group(&priv->pdev->dev.kobj, &cppi_attrs_group); dev_set_drvdata(&pdev->dev, NULL); return 0; } static struct platform_driver cppi_driver = { .driver = { .name = "cppi_server", }, .probe = cppi_probe, .remove = cppi_remove, }; static struct platform_device *cppi_device; static int cppi_server_init(void) { int ret; ret = platform_driver_register(&cppi_driver); if (ret < 0) { pr_err("Failed to register cppi platform driver: %d\n", ret); return ret; } pr_debug("cppi server platform driver is registered"); cppi_device = platform_device_register_simple("cppi_server", -1, NULL, 0); if (IS_ERR(cppi_device)) { pr_err("Failed to register cppi platform device\n"); platform_driver_unregister(&cppi_driver); return PTR_ERR(cppi_device); } dev_info(&cppi_device->dev, "platform device is registered\n"); return 0; } static void __exit cppi_server_exit(void) { platform_device_unregister(cppi_device); platform_driver_unregister(&cppi_driver); } /******************************************************/ /** Module Declarations **/ /******************************************************/ static_notifier_module_init(mrpc_ready, cppi_server_init); module_exit(cppi_server_exit); MODULE_AUTHOR("Intel Corporation"); MODULE_AUTHOR("Yair Weiss yair.weiss@intel.com"); MODULE_DESCRIPTION("cppi mrpc server"); MODULE_LICENSE("GPL"); MODULE_VERSION("1.0");