From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758355AbbJ2XzE (ORCPT ); Thu, 29 Oct 2015 19:55:04 -0400 Received: from mail-bn1bon0133.outbound.protection.outlook.com ([157.56.111.133]:52192 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758310AbbJ2Xy7 (ORCPT ); Thu, 29 Oct 2015 19:54:59 -0400 From: Lijun Pan To: Scott Wood CC: "gregkh@linuxfoundation.org" , "arnd@arndb.de" , "devel@driverdev.osuosl.org" , "linux-kernel@vger.kernel.org" , Stuart Yoder , Katz Itai , "Jose Rivera" , Li Leo , "agraf@suse.de" , Hamciuc Bogdan , Marginean Alexandru , Sharma Bhupesh , Erez Nir , "Richard Schmitt" , "dan.carpenter@oracle.com" Subject: RE: [PATCH 5/5] staging: fsl-mc: Management Complex restool driver Thread-Topic: [PATCH 5/5] staging: fsl-mc: Management Complex restool driver Thread-Index: AQHRD3ht4quo2eVK0k+x6D3bnmu2tp5+zm8AgARa+UA= Date: Thu, 29 Oct 2015 23:54:53 +0000 Message-ID: References: <1445812883-23551-1-git-send-email-Lijun.Pan@freescale.com> <1445812883-23551-6-git-send-email-Lijun.Pan@freescale.com> <1445923012.701.316.camel@freescale.com> In-Reply-To: <1445923012.701.316.camel@freescale.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Lijun.Pan@freescale.com; x-originating-ip: [192.88.168.50] x-microsoft-exchange-diagnostics: 1;BY1PR03MB1483;5:OrJrh70EKGeP2nKOmYdjCtQbtyoFYz1KdDM1upKo1U/ovzKbfrnU/mRKxYv5/iCylD24IoqKLtM5a16d5Mrdy5YSu8VafGuxWKuq89j6mRBoUtGYue9iZQZCwAYrxh3XqYmb7QsqcFzwYDCeBbojbQ==;24:c0ElgANgZO7RitvlwFeRTrz3YHFANtbBXPN4oqIk040M7zxmRaGVPllP8lYgHefhh+VfQ+dHxuOafCt7Z2iVcihwH+CJ0/h3WUX9wJKC9pc=;20:4+8MOqCDwrM6KoS0Fpe7tU+tL8w0bISVDJ5mSSUWXuX9AhW1KESbCLRQLEeF1H/dCSNDWmVRaLebM11UkHCpKQ== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR03MB1483; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(101931422205132)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(10201501046)(3002001)(102215026);SRVR:BY1PR03MB1483;BCL:0;PCL:0;RULEID:;SRVR:BY1PR03MB1483; x-forefront-prvs: 0744CFB5E8 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(377454003)(13464003)(189002)(199003)(24454002)(377424004)(97736004)(5002640100001)(5001960100002)(5003600100002)(2900100001)(33656002)(189998001)(110136002)(86362001)(5007970100001)(102836002)(92566002)(11100500001)(4001450100002)(74316001)(77096005)(2950100001)(10400500002)(5004730100002)(40100003)(105586002)(106116001)(122556002)(66066001)(76176999)(4001150100001)(106356001)(50986999)(87936001)(81156007)(101416001)(5008740100001)(54356999)(99286002)(19580405001)(76576001)(19580395003);DIR:OUT;SFP:1102;SCL:1;SRVR:BY1PR03MB1483;H:BY1PR03MB1452.namprd03.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Oct 2015 23:54:53.0991 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR03MB1483 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t9TNtACL017189 > -----Original Message----- > From: Wood Scott-B07421 > Sent: Tuesday, October 27, 2015 12:17 AM > To: Pan Lijun-B44306 > Cc: gregkh@linuxfoundation.org; arnd@arndb.de; devel@driverdev.osuosl.org; > linux-kernel@vger.kernel.org; Yoder Stuart-B08248 > ; katz Itai-RM05202 ; > Rivera Jose-B46482 ; Li Yang-Leo-R58472 > ; agraf@suse.de; Hamciuc Bogdan-BHAMCIU1 > ; Marginean Alexandru-R89243 > ; Sharma Bhupesh-B45370 > ; Erez Nir-RM30794 > ; Schmitt Richard-B43082 > ; dan.carpenter@oracle.com > Subject: Re: [PATCH 5/5] staging: fsl-mc: Management Complex restool driver > > On Sun, 2015-10-25 at 17:41 -0500, Lijun Pan wrote: > > The 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. > > > > Signed-off-by: Lijun Pan > > --- > > drivers/staging/fsl-mc/bus/Kconfig | 7 +- > > drivers/staging/fsl-mc/bus/Makefile | 3 + > > drivers/staging/fsl-mc/bus/mc-ioctl.h | 24 ++ > > drivers/staging/fsl-mc/bus/mc-restool.c | 488 > > ++++++++++++++++++++++++++++++++ > > 4 files changed, 521 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 > > > > diff --git a/drivers/staging/fsl-mc/bus/Kconfig b/drivers/staging/fsl- > > mc/bus/Kconfig index 0d779d9..39c6ef9 100644 > > --- a/drivers/staging/fsl-mc/bus/Kconfig > > +++ b/drivers/staging/fsl-mc/bus/Kconfig > > @@ -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. > > diff --git a/drivers/staging/fsl-mc/bus/Makefile > > b/drivers/staging/fsl- mc/bus/Makefile index 25433a9..28b5fc0 100644 > > --- a/drivers/staging/fsl-mc/bus/Makefile > > +++ b/drivers/staging/fsl-mc/bus/Makefile > > @@ -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 > > diff --git a/drivers/staging/fsl-mc/bus/mc-ioctl.h > > b/drivers/staging/fsl- mc/bus/mc-ioctl.h new file mode 100644 index > > 0000000..e52f907 > > --- /dev/null > > +++ b/drivers/staging/fsl-mc/bus/mc-ioctl.h > > @@ -0,0 +1,24 @@ > > +/* > > + * Freescale Management Complex (MC) ioclt interface > > ioctl > > > + * > > + * Copyright (C) 2014 Freescale Semiconductor, Inc. > > + * Author: Lijun Pan > > + * > > + * 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 > > + > > +#define RESTOOL_IOCTL_TYPE 'R' > > + > > +#define RESTOOL_DPRC_SYNC \ > > + _IO(RESTOOL_IOCTL_TYPE, 0x2) > > + > > +#define RESTOOL_SEND_MC_COMMAND \ > > + _IOWR(RESTOOL_IOCTL_TYPE, 0x4, struct mc_command) > > Look at Documentation/ioctl/ioctl-number.txt and reserve a range within 'R' > that doesn't conflict. > > Add thorough documentation of this API. What path do you recommend me to put documentation of this API? > > I'm not sure how it's usually handled with staging drivers, but eventually this > will need to move to an appropriate uapi header. Is this functionality even > needed before the driver comes out of staging? I don't see "userspace restool > support" in drivers/staging/fsl-mc/TODO. > > Don't reference struct mc_command without including the header that defines > it. > > > +#endif /* _FSL_MC_IOCTL_H_ */ > > diff --git a/drivers/staging/fsl-mc/bus/mc-restool.c > > b/drivers/staging/fsl- mc/bus/mc-restool.c new file mode 100644 index > > 0000000..a219172 > > --- /dev/null > > +++ b/drivers/staging/fsl-mc/bus/mc-restool.c > > @@ -0,0 +1,488 @@ > > +/* > > + * Freescale Management Complex (MC) restool driver > > + * > > + * Copyright (C) 2014 Freescale Semiconductor, Inc. > > + * Author: Lijun Pan > > + * > > + * 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. > > + */ > > + > > +#include "../include/mc-private.h" > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include "mc-ioctl.h" > > +#include "../include/mc-sys.h" > > +#include "../include/mc-cmd.h" > > +#include "../include/dpmng.h" > > + > > +/** > > + * Maximum number of DPRCs that can be opened at the same time */ > > +#define MAX_DPRC_HANDLES 64 > > + > > +/** > > + * restool_misc - information associated with the newly added > > +miscdevice > > + * @misc: newly created miscdevice associated with root dprc > > + * @miscdevt: device id of this miscdevice > > + * @list: a linked list node representing this miscdevcie > > + * @static_mc_io: pointer to the static MC I/O object used by the > > +restool > > + * @dynamic_instance_count: number of dynamically created instances > > + * @static_instance_in_use: static instance is in use or not > > + * @mutex: mutex lock to serialze the operations > > + * @dev: root dprc associated with this miscdevice */ struct > > +restool_misc { > > + struct miscdevice misc; > > + dev_t miscdevt; > > + struct list_head list; > > + struct fsl_mc_io *static_mc_io; > > + uint32_t dynamic_instance_count; > > + bool static_instance_in_use; > > + struct mutex mutex; > > + struct device *dev; > > +}; > > + > > +/* > > + * initialize a global list to link all > > + * the miscdevice nodes (struct restool_misc) */ > > +LIST_HEAD(misc_list); > > static > > > +static int fsl_mc_restool_dev_open(struct inode *inode, struct file > > +*filep) { > > + struct fsl_mc_device *root_mc_dev; > > + int error = 0; > > + struct fsl_mc_io *dynamic_mc_io = NULL; > > + struct restool_misc *restool_misc; > > + struct restool_misc *restool_misc_cursor; > > + > > + pr_debug("%s: inode's dev_t == %u\n", __func__, inode->i_rdev); > > + > > + list_for_each_entry(restool_misc_cursor, &misc_list, list) { > > + if (restool_misc_cursor->miscdevt == inode->i_rdev) { > > + pr_debug("%s: Found the restool_misc\n", __func__); > > + restool_misc = restool_misc_cursor; > > + break; > > + } > > + } > > No synchronization on the list? > > > + > > + if (!restool_misc) > > + return -EINVAL; > > + > > + if (WARN_ON(restool_misc->dev == NULL)) > > + return -EINVAL; > > + > > + mutex_lock(&restool_misc->mutex); > > + > > + if (!restool_misc->static_instance_in_use) { > > + restool_misc->static_instance_in_use = true; > > + filep->private_data = restool_misc->static_mc_io; > > + } else { > > + dynamic_mc_io = kzalloc(sizeof(struct fsl_mc_io), GFP_KERNEL); > > + if (dynamic_mc_io == NULL) { > > + error = -ENOMEM; > > + goto error; > > + } > > + > > + root_mc_dev = to_fsl_mc_device(restool_misc->dev); > > + error = fsl_mc_portal_allocate(root_mc_dev, 0, &dynamic_mc_io); > > + if (error < 0) { > > + pr_err("Not able to allocate MC portal\n"); > > + goto error; > > + } > > + ++restool_misc->dynamic_instance_count; > > + filep->private_data = dynamic_mc_io; > > + } > > Why is the first user handled differently from subsequent users? Does each > user really need its own portal, or can you just synchronize access? First user get the statically allocated portal. Second user need to dynamically allocate one. Some operations may take a long time (say 1 second) in MC object creation. In order to support asynchronous portal operation, We allocate portal for each user. Lijun > > -Scott {.n++%ݶw{.n+{G{ayʇڙ,jfhz_(階ݢj"mG?&~iOzv^m ?I