Skip to content

Commit 2cf1e70

Browse files
IoanaCiorneigregkh
authored andcommitted
bus: fsl-mc: add fsl-mc userspace support
Adding userspace support for the MC (Management Complex) means exporting an ioctl capable device file representing the root resource container. This new functionality in the fsl-mc bus driver intends to provide userspace applications an interface to interact with the MC firmware. Commands that are composed in userspace are sent to the MC firmware through the FSL_MC_SEND_MC_COMMAND ioctl. By default the implicit MC I/O portal is used for this operation, but if the implicit one is busy, a dynamic portal is allocated and then freed upon execution. The command received through the ioctl interface is checked against a known whitelist of accepted MC commands. Commands that attempt a change in hardware configuration will need CAP_NET_ADMIN, while commands used in debugging do not need it. Acked-by: Laurentiu Tudor <laurentiu.tudor@nxp.com> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com> Link: https://lore.kernel.org/r/20210114170752.2927915-4-ciorneiioana@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4670798 commit 2cf1e70

7 files changed

Lines changed: 618 additions & 0 deletions

File tree

‎Documentation/userspace-api/ioctl/ioctl-number.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Code Seq# Include File Comments
180180
'R' 00-1F linux/random.h conflict!
181181
'R' 01 linux/rfkill.h conflict!
182182
'R' C0-DF net/bluetooth/rfcomm.h
183+
'R' E0 uapi/linux/fsl_mc.h
183184
'S' all linux/cdrom.h conflict!
184185
'S' 80-81 scsi/scsi_ioctl.h conflict!
185186
'S' 82-FF scsi/scsi.h conflict!

‎drivers/bus/fsl-mc/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ config FSL_MC_BUS
1414
architecture. The fsl-mc bus driver handles discovery of
1515
DPAA2 objects (which are represented as Linux devices) and
1616
binding objects to drivers.
17+
18+
config FSL_MC_UAPI_SUPPORT
19+
bool "Management Complex (MC) userspace support"
20+
depends on FSL_MC_BUS
21+
help
22+
Provides userspace support for interrogating, creating, destroying or
23+
configuring DPAA2 objects exported by the Management Complex.

‎drivers/bus/fsl-mc/Makefile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ mc-bus-driver-objs := fsl-mc-bus.o \
1616
fsl-mc-allocator.o \
1717
fsl-mc-msi.o \
1818
dpmcp.o
19+
20+
# MC userspace support
21+
obj-$(CONFIG_FSL_MC_UAPI_SUPPORT) += fsl-mc-uapi.o

‎drivers/bus/fsl-mc/dprc-driver.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ int dprc_setup(struct fsl_mc_device *mc_dev)
603603
struct irq_domain *mc_msi_domain;
604604
bool mc_io_created = false;
605605
bool msi_domain_set = false;
606+
bool uapi_created = false;
606607
u16 major_ver, minor_ver;
607608
size_t region_size;
608609
int error;
@@ -635,6 +636,11 @@ int dprc_setup(struct fsl_mc_device *mc_dev)
635636
return error;
636637

637638
mc_io_created = true;
639+
} else {
640+
error = fsl_mc_uapi_create_device_file(mc_bus);
641+
if (error < 0)
642+
return -EPROBE_DEFER;
643+
uapi_created = true;
638644
}
639645

640646
mc_msi_domain = fsl_mc_find_msi_domain(&mc_dev->dev);
@@ -692,6 +698,9 @@ int dprc_setup(struct fsl_mc_device *mc_dev)
692698
mc_dev->mc_io = NULL;
693699
}
694700

701+
if (uapi_created)
702+
fsl_mc_uapi_remove_device_file(mc_bus);
703+
695704
return error;
696705
}
697706
EXPORT_SYMBOL_GPL(dprc_setup);
@@ -763,6 +772,7 @@ static void dprc_teardown_irq(struct fsl_mc_device *mc_dev)
763772

764773
int dprc_cleanup(struct fsl_mc_device *mc_dev)
765774
{
775+
struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
766776
int error;
767777

768778
/* this function should be called only for DPRCs, it
@@ -793,6 +803,8 @@ int dprc_cleanup(struct fsl_mc_device *mc_dev)
793803
if (!fsl_mc_is_root_dprc(&mc_dev->dev)) {
794804
fsl_destroy_mc_io(mc_dev->mc_io);
795805
mc_dev->mc_io = NULL;
806+
} else {
807+
fsl_mc_uapi_remove_device_file(mc_bus);
796808
}
797809

798810
return 0;

‎drivers/bus/fsl-mc/fsl-mc-private.h‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include <linux/fsl/mc.h>
1212
#include <linux/mutex.h>
13+
#include <linux/ioctl.h>
14+
#include <linux/miscdevice.h>
1315

1416
/*
1517
* Data Path Management Complex (DPMNG) General API
@@ -542,6 +544,22 @@ struct fsl_mc_resource_pool {
542544
struct fsl_mc_bus *mc_bus;
543545
};
544546

547+
/**
548+
* struct fsl_mc_uapi - information associated with a device file
549+
* @misc: struct miscdevice linked to the root dprc
550+
* @device: newly created device in /dev
551+
* @mutex: mutex lock to serialize the open/release operations
552+
* @local_instance_in_use: local MC I/O instance in use or not
553+
* @static_mc_io: pointer to the static MC I/O object
554+
*/
555+
struct fsl_mc_uapi {
556+
struct miscdevice misc;
557+
struct device *device;
558+
struct mutex mutex; /* serialize open/release operations */
559+
u32 local_instance_in_use;
560+
struct fsl_mc_io *static_mc_io;
561+
};
562+
545563
/**
546564
* struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
547565
* @mc_dev: fsl-mc device for the bus device itself.
@@ -551,13 +569,15 @@ struct fsl_mc_resource_pool {
551569
* @irq_resources: Pointer to array of IRQ objects for the IRQ pool
552570
* @scan_mutex: Serializes bus scanning
553571
* @dprc_attr: DPRC attributes
572+
* @uapi_misc: struct that abstracts the interaction with userspace
554573
*/
555574
struct fsl_mc_bus {
556575
struct fsl_mc_device mc_dev;
557576
struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
558577
struct fsl_mc_device_irq *irq_resources;
559578
struct mutex scan_mutex; /* serializes bus scanning */
560579
struct dprc_attributes dprc_attr;
580+
struct fsl_mc_uapi uapi_misc;
561581
};
562582

563583
#define to_fsl_mc_bus(_mc_dev) \
@@ -614,4 +634,23 @@ struct fsl_mc_device *fsl_mc_device_lookup(struct fsl_mc_obj_desc *obj_desc,
614634

615635
u16 mc_cmd_hdr_read_cmdid(struct fsl_mc_command *cmd);
616636

637+
#ifdef CONFIG_FSL_MC_UAPI_SUPPORT
638+
639+
int fsl_mc_uapi_create_device_file(struct fsl_mc_bus *mc_bus);
640+
641+
void fsl_mc_uapi_remove_device_file(struct fsl_mc_bus *mc_bus);
642+
643+
#else
644+
645+
static inline int fsl_mc_uapi_create_device_file(struct fsl_mc_bus *mc_bus)
646+
{
647+
return 0;
648+
}
649+
650+
static inline void fsl_mc_uapi_remove_device_file(struct fsl_mc_bus *mc_bus)
651+
{
652+
}
653+
654+
#endif
655+
617656
#endif /* _FSL_MC_PRIVATE_H_ */

0 commit comments

Comments
 (0)