Management Complex restool driver
Subsystems (2)
v2 cover Management Complex restool driver
This series of patches are based on
http://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/commit/?h=staging-next&id=63f2be5c3b358db031f86eafa9cd450f6558a55b
patch v1 1/5 "staging: fsl-mc: section mismatch bug fix" is already accepted.
This v2 series have,
patch 1/8 use inline function to differentiate root dprc patch 2/8 add sysfs rescan attribute in TODO list
patch 3/8 add sysfs rescan documentation for dprc device patch 4/8 introduce the sysfs rescan attribute for root dprc device patch 5/8 add sysfs rescan documentation for fsl-mc bus patch 6/8 introduce the sysfs rescan attribute for fsl-mc bus patch 7/8 add restool driver introduction in TODO list and README patch 8/8 introduction of restool driver, which sits on fsl-mc bus and utilizes fsl-mc bus to communicate with MC firmware. restool driver is the first driver to start using fsl-mc bus. This restool driver is small and helps fsl-mc bus move out of staging.
Lijun Pan (8):
staging: fsl-mc: static inline function to differentiate root dprc
staging: fsl-mc: add sysfs rescan attribute in TODO
staging: fsl-mc: dprc device's sysfs rescan documentation
staging: fsl-mc: root dprc rescan attribute to sync kernel with MC
staging: fsl-mc: fsl-mc bus's sysfs rescan documentation
staging: fsl-mc: bus rescan attribute to sync kernel with MC
staging: fsl-mc: update TODO and README for restool driver
staging: fsl-mc: Management Complex restool driver
Documentation/ABI/testing/sysfs-bus-fsl-mc | 11 + Documentation/ABI/testing/sysfs-devices-dprc | 13 + Documentation/ioctl/ioctl-number.txt | 1 + drivers/staging/fsl-mc/README.txt | 11 +- drivers/staging/fsl-mc/TODO | 24 +- drivers/staging/fsl-mc/bus/Kconfig | 7 +- drivers/staging/fsl-mc/bus/Makefile | 3 + drivers/staging/fsl-mc/bus/mc-bus.c | 112 ++++++-- drivers/staging/fsl-mc/bus/mc-ioctl.h | 22 ++ drivers/staging/fsl-mc/bus/mc-restool.c | 392 +++++++++++++++++++++++++++ drivers/staging/fsl-mc/include/mc.h | 14 + 11 files changed, 587 insertions(+), 23 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-fsl-mc create mode 100644 Documentation/ABI/testing/sysfs-devices-dprc create mode 100644 drivers/staging/fsl-mc/bus/mc-ioctl.h create mode 100644 drivers/staging/fsl-mc/bus/mc-restool.c
Signature · 1 line
2.3.3
PATCH v2 1/8 staging: fsl-mc: static inline function to differentiate root dprc
Define a static inline function is_root_dprc(dev) to tell whether a device is root dprc or not via platform_bus_type. Remove fsl_mc_is_root_dprc() because is_root_dprc() is simpler and easier to understand.
---
v2: use static inline function instead of macro
replace the fsl_mc_is_root_dprc with is_root_dprc
drivers/staging/fsl-mc/bus/mc-bus.c | 22 +++------------------- drivers/staging/fsl-mc/include/mc.h | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 19 deletions(-)
drivers/staging/fsl-mc/bus/mc-bus.c +3 -19
@@ -22,8 +22,6 @@static struct kmem_cache *mc_dev_cache; -static bool fsl_mc_is_root_dprc (struct device *dev); -/** * fsl_mc_bus_match - device to driver matching callback * @dev: the MC object device structure to match against
@@ -52,7 +50,7 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)* Only exception is the root DPRC, which is a special case. */ if ((mc_dev->obj_desc.state &DPRC_OBJ_STATE_PLUGGED ) ==0 && - !fsl_mc_is_root_dprc (&mc_dev->dev)) + !is_root_dprc (&mc_dev->dev)) goto out;/*
@@ -236,20 +234,6 @@ static void fsl_mc_get_root_dprc(struct device *dev, } } -/** -* fsl_mc_is_root_dprc - function to check if a given device is a root dprc -*/ -static bool fsl_mc_is_root_dprc (struct device *dev) -{ -struct device *root_dprc_dev; - -fsl_mc_get_root_dprc (dev, &root_dprc_dev); -if (!root_dprc_dev) -return false; -else -return dev == root_dprc_dev; -} -static int get_dprc_icid (struct fsl_mc_io *mc_io,int container_id,u16 *icid) {
@@ -541,7 +525,7 @@ void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) mc_dev->mc_io =NULL ; } -if (fsl_mc_is_root_dprc (&mc_dev->dev)) { +if (is_root_dprc (&mc_dev->dev)) {if (atomic_read (&root_dprc_count) >0 )atomic_dec (&root_dprc_count);else
@@ -772,7 +756,7 @@ static int fsl_mc_bus_remove(struct platform_device *pdev) {struct fsl_mc *mc =platform_get_drvdata (pdev); -if (WARN_ON (!fsl_mc_is_root_dprc (&mc->root_mc_bus_dev->dev))) +if (WARN_ON (!is_root_dprc (&mc->root_mc_bus_dev->dev)))return -EINVAL ;fsl_mc_device_remove (mc->root_mc_bus_dev);
drivers/staging/fsl-mc/include/mc.h +14 -0
@@ -14,6 +14,7 @@#include <linux/device.h> #include <linux/mod_devicetable.h> #include <linux/list.h> +#include <linux/platform_device.h> #include "../include/dprc.h" #define FSL_MC_VENDOR_FREESCALE 0x1957
@@ -200,4 +201,17 @@ void fsl_mc_object_free(struct fsl_mc_device *mc_adev);extern struct bus_type fsl_mc_bus_type; +/** +* is_root_dprc - tell whether dev is root dprc or not. +* root dprc's parent is a platform device, +* that platform device's bus type is platform_bus_type. +* @dev: MC object device +* return 1 on root dprc, 0 otherwise +*/ +static inline bool is_root_dprc (struct device *dev) +{ +return ((to_fsl_mc_device (dev)->flags &FSL_MC_IS_DPRC ) && + ((dev)->bus == &fsl_mc_bus_type) && + ((dev)->parent->bus == &platform_bus_type)); +}#endif /* _FSL_MC_H_ */
Signature · 1 line
2.3.3
PATCH v2 2/8 staging: fsl-mc: add sysfs rescan attribute in TODO
In reply to Lijun PanDemonstrate why sysfs rescan attribute is helpful for moving fsl-mc bus out of staging.
--- drivers/staging/fsl-mc/TODO | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/staging/fsl-mc/TODO +6 -0
@@ -1,3 +1,9 @@ +* Add sysfs rescan attribute for fsl-mc bus, and dprc device. The rescan will + trigger the fsl-mc bus, dprc driver to re-discover the objects under fsl-mc + bus and dprc.X container. Hence this feature actually verifies the + functionality of fsl-mc bus, and dprc driver, and it helps moving + fsl-mc bus out of staging. + * Decide if multiple root fsl-mc buses will be supported per Linux instance, and if so add support for this.
Signature · 1 line
2.3.3
PATCH v2 4/8 staging: fsl-mc: root dprc rescan attribute to sync kernel with MC
In reply to Lijun PanIntroduce the rescan attribute as a device attribute to synchronize the fsl-mc bus objects and the MC firmware.
To rescan the root dprc only, e.g.
echo 1 > /sys/bus/fsl-mc/devices/dprc.1/rescan
--- drivers/staging/fsl-mc/bus/mc-bus.c | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
drivers/staging/fsl-mc/bus/mc-bus.c +43 -0
@@ -100,10 +100,53 @@ static int fsl_mc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)return 0 ; } +static ssize_t rescan_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +unsigned long val; +struct fsl_mc_device *root_mc_dev; +struct fsl_mc_bus *root_mc_bus; + +if (!is_root_dprc (dev)) +return -EINVAL ; + + root_mc_dev =to_fsl_mc_device (dev); + root_mc_bus =to_fsl_mc_bus (root_mc_dev); + +if (kstrtoul (buf,0 , &val) <0 ) +return -EINVAL ; + +if (val) { +mutex_lock (&root_mc_bus->scan_mutex); +dprc_scan_objects (root_mc_dev); +mutex_unlock (&root_mc_bus->scan_mutex); + } + +return count; +} + +static DEVICE_ATTR_WO (rescan); + +static struct attribute *fsl_mc_dev_attrs[] = { + &dev_attr_rescan.attr, +NULL , +}; + +static const struct attribute_group fsl_mc_dev_group = { + .attrs = fsl_mc_dev_attrs, +}; + +static const struct attribute_group *fsl_mc_dev_groups[] = { + &fsl_mc_dev_group, +NULL , +}; +struct bus_type fsl_mc_bus_type = { .name ="fsl-mc" , .match = fsl_mc_bus_match, .uevent = fsl_mc_bus_uevent, + .dev_groups = fsl_mc_dev_groups, };EXPORT_SYMBOL_GPL (fsl_mc_bus_type);
Signature · 1 line
2.3.3
PATCH v2 5/8 staging: fsl-mc: fsl-mc bus's sysfs rescan documentation
In reply to Lijun PanAdd the sysfs documentation for the rescan attribute of fsl-mc bus.
--- Documentation/ABI/testing/sysfs-bus-fsl-mc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-fsl-mc
Documentation/ABI/testing/sysfs-bus-fsl-mc new file +11 -0
@@ -0,0 +1,11 @@ +What: /sys/bus/fsl-mc/rescan +Date: October 2015 +Contact: Lijun Pan <[email protected]> +Description: + Writing a non-zero value to this attribute will + force a rescan of fsl-mc bus in the system, and + add/remove previously added/removed objects in + Management Complex firmwarer, i.e., synchronize + the objects under fsl-mc bus and Management Complex + firmware. For example: + # echo 1 > /sys/bus/fsl-mc/rescan
Signature · 1 line
2.3.3
PATCH v3 3/8 staging: fsl-mc: dprc device's sysfs rescan documentation
In reply to Lijun PanAdd the sysfs documentation for the rescan attribute of dprc devices.
--- Documentation/ABI/testing/sysfs-devices-dprc | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-devices-dprc
Documentation/ABI/testing/sysfs-devices-dprc new file +13 -0
@@ -0,0 +1,13 @@ +What: /sys/devices/.../dprc.X/rescan +Date: October 2015 +Contact: Lijun Pan <[email protected]> +Description: + Writing a non-zero value to this attribute will + force a rescan of dprc.X container in the system, and + add/remove previously added/removed objects in + Management Complex firmwarer, i.e., synchronize + the objects under dprc.X and Management Complex + firmware. For example: + # echo 1 > /sys/devices/platform/80c000000.fsl-mc/dprc.1/rescan + +
Signature · 1 line
2.3.3
PATCH v2 6/8 staging: fsl-mc: bus rescan attribute to sync kernel with MC
In reply to Lijun PanIntroduce the rescan attribute as a bus attribute to synchronize the fsl-mc bus objects and the MC firmware.
To rescan the fsl-mc bus, e.g.,
echo 1 > /sys/bus/fsl-mc/rescan
--- drivers/staging/fsl-mc/bus/mc-bus.c | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/staging/fsl-mc/bus/mc-bus.c +46 -0
@@ -142,11 +142,57 @@ static const struct attribute_group *fsl_mc_dev_groups[] = { NULL, }; +static int scan_fsl_mc_bus (struct device *dev,void *data) +{ +struct fsl_mc_device *root_mc_dev; +struct fsl_mc_bus *root_mc_bus; + +if (is_root_dprc (dev)) { + root_mc_dev =to_fsl_mc_device (dev); + root_mc_bus =to_fsl_mc_bus (root_mc_dev); +mutex_lock (&root_mc_bus->scan_mutex); +dprc_scan_objects (root_mc_dev); +mutex_unlock (&root_mc_bus->scan_mutex); + } + +return 0 ; +} + +static ssize_t bus_rescan_store (struct bus_type *bus, +const char *buf,size_t count) +{ +unsigned long val; + +if (kstrtoul (buf,0 , &val) <0 ) +return -EINVAL ; + +if (val) +bus_for_each_dev (bus,NULL ,NULL , scan_fsl_mc_bus); + +return count; +} +static BUS_ATTR(rescan, (S_IWUSR | S_IWGRP), NULL, bus_rescan_store); + +static struct attribute *fsl_mc_bus_attrs[] = { + &bus_attr_rescan.attr, +NULL , +}; + +static const struct attribute_group fsl_mc_bus_group = { + .attrs = fsl_mc_bus_attrs, +}; + +static const struct attribute_group *fsl_mc_bus_groups[] = { + &fsl_mc_bus_group, +NULL , +}; +struct bus_type fsl_mc_bus_type = { .name ="fsl-mc" , .match = fsl_mc_bus_match, .uevent = fsl_mc_bus_uevent, .dev_groups = fsl_mc_dev_groups, + .bus_groups = fsl_mc_bus_groups, };EXPORT_SYMBOL_GPL (fsl_mc_bus_type);
Signature · 1 line
2.3.3
PATCH v2 7/8 staging: fsl-mc: update TODO and README for restool driver
In reply to Lijun PanAdd more introduction of restool driver and state why restool driver is needed in helping moving fsl-mc bus out of staging tree.
--- drivers/staging/fsl-mc/README.txt | 11 ++++++++++- drivers/staging/fsl-mc/TODO | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-)
drivers/staging/fsl-mc/README.txt +10 -1
@@ -130,7 +130,16 @@ the objects involved in creating a network interfaces. via a config file passed to the MC when firmware starts it. There is also a Linux user space tool called "restool" that can be used to create/destroy containers and objects - dynamically. + dynamically. The kernel side restool driver communicates with + user space restool via ioctl. Restool relies on allocator driver + to allocate dpmcp resources, enumerates fsl-mc bus to find root dprc + objects of interest. When the user space restool program sends a request + to restool driver to create a dp* objects in MC firmware, an interrupt + will be triggered by MC firmware and the dprc driver's interrupt handler + shall process the interrupt (synchronizing the objects in MC firmware and + objects in Linux kernel). Though small, restool driver helps verify all + the functionality of fsl-mc bus, dprc driver, allocator driver, + and MC flib API. -DPAA2 Objects for an Ethernet Network Interface
drivers/staging/fsl-mc/TODO +16 -2
@@ -5,10 +5,24 @@ fsl-mc bus out of staging. * Decide if multiple root fsl-mc buses will be supported per Linux instance, - and if so add support for this. + and if so add support for this. No matter fsl-mc bus support multiple root + dprc or not, restool driver is designed to support multiple root if fsl-mc + bus is ready some day later. If there is only one root dprc, restool driver + works fine. + +* Add at least one driver utilizing fsl-mc bus. Restool driver is a very + small and simple driver, which interacts with fsl-mc bus, dprc driver, + allocator driver. Restool relies on allocator driver to allocate + dpmcp resources, enumerates fsl-mc bus to find root dprc objects of interest. + When the user space restool program sends a request to restool driver to + create a dp* objects in MC firmware, an interrupt will be triggered by + MC firmware and the dprc driver's interrupt handler shall process the + interrupt. Though small, restool driver helps verify all the functionality + of fsl-mc bus, dprc driver, allocator driver, and MC flib API. Restool + driver helps in moving fsl-mc bus out of staging branch. * Add at least one device driver for a DPAA2 object (child device of the - fsl-mc bus). Most likely candidate for this is adding DPAA2 Ethernet + fsl-mc bus). Most likely candidate for this is adding DPAA2 Ethernet driver support, which depends on drivers for several objects: DPNI, DPIO, DPMAC. Other pre-requisites include:
Signature · 1 line
2.3.3
PATCH v2 8/8 staging: fsl-mc: Management Complex restool driver
In reply to Lijun PanThe kernel support for the restool (a user space resource management tool) is a driver for the /dev/dprc.N device file.
Its purpose is to provide an ioctl interface,
which the restool uses to interact with the MC bus driver and with the MC firmware.
We allocate a dpmcp at driver initialization,
and keep that dpmcp until driver exit.
We use that dpmcp by default.
If that dpmcp is in use, we create another portal at run time and destroy the newly created portal after use.
The ioctl RESTOOL_SEND_MC_COMMAND sends user space command to fsl-mc bus and utilizes the fsl-mc bus to communicate with MC firmware. The ioctl RESTOOL_DPRC_SYNC request the mc-bus launch objects scan under root dprc.
In order to support multiple root dprc, we utilize the bus notify mechanism to scan fsl_mc_bus_type for the newly added root dprc. After discovering the root dprc, it creates a miscdevice /dev/dprc.N to associate with this root dprc.
---
v2:
remove verbose printk
improve error handling
synchronize misc_list access
reserve ioctl range in Documentation/ioctl/ioctl-number.txt remove ioctl sync command
flip if(!...) to make them fit in 80 columns change if(x==NULL) to if(!x)
change ("int error = 0;" initialization) to (int error;)
Documentation/ioctl/ioctl-number.txt | 1 + drivers/staging/fsl-mc/bus/Kconfig | 7 +- drivers/staging/fsl-mc/bus/Makefile | 3 + drivers/staging/fsl-mc/bus/mc-ioctl.h | 22 ++ drivers/staging/fsl-mc/bus/mc-restool.c | 392 ++++++++++++++++++++++++++++++++ 5 files changed, 424 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/fsl-mc/bus/mc-ioctl.h create mode 100644 drivers/staging/fsl-mc/bus/mc-restool.c
Documentation/ioctl/ioctl-number.txt +1 -0
@@ -166,6 +166,7 @@ Code Seq#(hex) Include File Comments 'R' 00-1F linux/random.h conflict! 'R' 01 linux/rfkill.h conflict! 'R' C0-DF net/bluetooth/rfcomm.h +'R' E0-EF drivers/staging/fsl-mc/bus/mc-ioctl.h 'S' all linux/cdrom.h conflict! 'S' 80-81 scsi/scsi_ioctl.h conflict! 'S' 82-FF scsi/scsi.h conflict!
drivers/staging/fsl-mc/bus/Kconfig +6 -1
@@ -21,4 +21,9 @@ config FSL_MC_BUS Only enable this option when building the kernel for Freescale QorQIQ LS2xxxx SoCs. - +config FSL_MC_RESTOOL + tristate "Freescale Management Complex (MC) restool driver" + depends on FSL_MC_BUS + help + Driver that provides kernel support for the Freescale Management + Complex resource manager user-space tool.
drivers/staging/fsl-mc/bus/Makefile +3 -0
@@ -15,3 +15,6 @@ mc-bus-driver-objs := mc-bus.o \ mc-allocator.o \ dpmcp.o \ dpbp.o + +# MC restool kernel support +obj-$(CONFIG_FSL_MC_RESTOOL) += mc-restool.o
drivers/staging/fsl-mc/bus/mc-ioctl.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Freescale Management Complex (MC) ioclt interface +* +* Copyright (C) 2014 Freescale Semiconductor, Inc. +* Author: Lijun Pan <[email protected]> +* +* This file is licensed under the terms of the GNU General Public +* License version 2. This program is licensed "as is" without any +* warranty of any kind, whether express or implied. +*/ +#ifndef _FSL_MC_IOCTL_H_ +#define _FSL_MC_IOCTL_H_ + +#include <linux/ioctl.h> +#include "../include/mc-sys.h" + +#define RESTOOL_IOCTL_TYPE 'R' + +#define RESTOOL_SEND_MC_COMMAND \ + _IOWR(RESTOOL_IOCTL_TYPE, 0xE0, struct mc_command) + +#endif /* _FSL_MC_IOCTL_H_ */
drivers/staging/fsl-mc/bus/mc-restool.c new file +392 -0
392 lines not on this page · raw message
Signature · 1 line
2.3.3