Received: by 10.213.65.68 with SMTP id h4csp1019495imn; Sat, 24 Mar 2018 00:52:41 -0700 (PDT) X-Google-Smtp-Source: AG47ELtIUhfza5Orr0RROq3ORwKnZTmtXKRaT9pGbeNARXvuB0LJHMRvcbKJ2NJJdIwSXiCkQNjS X-Received: by 10.99.97.149 with SMTP id v143mr23154008pgb.319.1521877961592; Sat, 24 Mar 2018 00:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521877961; cv=none; d=google.com; s=arc-20160816; b=JQknVFuCUTdhKxMcIlh8KEm7vNXqfdCvkERFquurKEWWZDuQsPKLExUWLdfNE9+3Ci zoOSqRWrQIHVFNnaE4JtYD6IyxO5Fx7SWTdwRChz7Xnn2K7y5BTD0iAnaLrE5IWb5n4T Ki66cL+TSRSDKcMBZg045w2ihOi/OQJ7QCmWhBC9RuuxEZQqym07gxb/JCM13bpYTi8M kQA+HOGvSJ8sgdAR8/ffVrOpJ63iqdFSkDVxojdXHPR/mFh+1xLJhUcFGzOCmWXgZ+Oi Nhb1bnDm7XSNjTkDHyv6Ls3HRUXknprp3isSZloD/zDG5u5iK4v/+o0kww7pQaIlEri9 U8CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=eVP+v7GCryVm6E5SK1VcxqZyGv1dQ+viY+IjTwlC01s=; b=TPZUATHHnN4RVNL2vaGfjlptOlmqJ9gvyC0X4QIEitPYb0suX1VVcE9twCfZ8HxOB9 tsGImed+0GYMee0Iv9XyQwwaSNSQ7+IkY7mp1Y/1pjew17V+VEcNYWkn3ZOywJR+7DOz jcxfwgShTHrNbSIhvOp5NHuXYjMOwG9YpTHtCpVmJpb4c0kjQ3QPOeeVYnyrCASohdBC TrTyJISJz3UxMrvTREYjIbBMiG8xpgK4oZRExz9k6tAmcPdmMHpQVjS+eFqwbG/oyRAL CDrnB6KICbXz2L08r2EtNHM/e9GjfjwBfSlAeFmD90lT8ec7K+tPkH4EYlTynidfEN6R b4og== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fn6ee0Wj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bh1-v6si9394338plb.246.2018.03.24.00.52.26; Sat, 24 Mar 2018 00:52:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fn6ee0Wj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751668AbeCXHvd (ORCPT + 99 others); Sat, 24 Mar 2018 03:51:33 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:32925 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750769AbeCXHvc (ORCPT ); Sat, 24 Mar 2018 03:51:32 -0400 Received: by mail-io0-f196.google.com with SMTP id l3so17732533iog.0 for ; Sat, 24 Mar 2018 00:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=eVP+v7GCryVm6E5SK1VcxqZyGv1dQ+viY+IjTwlC01s=; b=fn6ee0Wj6kbO7r07n6O9aV2m2PlQzXTzVxw23LgjfYD1SaVNPyW9BidZ1p4xZHWIUH AiaOR81ggTNRfRW6IoXL/2UMYHPCUQfhRBG8kx9pjYfeOwz3hpc+EL+K/6NG/rsFtPZi 6bRLncgPp/BJrsQXZT9ODgKyDQjtpVtUSruZbe6u4AX3I1isRqtVhlp20grKFjYLvfq8 ssJoeHYXMYOCuLyP7q6U7ErGe7ywqfX47Yeukr2pycry/mlSpq4khfT4/NP8QjQqRgJN cTpjabzG9RryBLxXfA0QpbzmKk8MHv2CWDsEKW08/TCjLn75ce+mRozmeYi5vi7uHPa/ jPoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=eVP+v7GCryVm6E5SK1VcxqZyGv1dQ+viY+IjTwlC01s=; b=tECxW7rAmu/gwWnuf7UHjxS3GFY5AGHih+vC6ZpZ7a249QpgMu/i42U6s+w1rtfUf9 JFa7Zcbh7ToomgLgC2w+26TIz1HzeDQRcBf5D0I3BV7fHug3MX0K2gbTXuZma+GNZ7nQ d7m0faNI4rQCV7WbGcGKPDQrZgXqVYuHcyFZ68XpBCw5TOsOyqF50BjMBiBRIbxhhzsT q9e3NElspsAgOea8Ehgv2u9jy6QgSY8VB+WusGs/V2sVEmpL7G9Ti6cJ7ZdzF5QyhrYL /1twkEfVqGvm9sMCf2n/z0hUhmetbBfnWgW9OvB7Zj9lCwsMonIprlvN7OlbhMP9bQ52 MEAQ== X-Gm-Message-State: AElRT7EjabMEDNMTV1QrmumjxgeAFnQ4ZmKQH22GS0FM5kM2FXtAkRMs nHB9YCsslprp7VUSHjGw2H3m2WeoOR0HLNz8WMs= X-Received: by 10.107.159.76 with SMTP id i73mr34754873ioe.0.1521877891749; Sat, 24 Mar 2018 00:51:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.209.205 with HTTP; Sat, 24 Mar 2018 00:51:30 -0700 (PDT) In-Reply-To: References: From: Arnd Bergmann Date: Sat, 24 Mar 2018 15:51:30 +0800 X-Google-Sender-Auth: oKO0m3q6fHa9XK_cdo606aao3jI Message-ID: Subject: Re: [PATCH v3 2/4] bus: fsl-mc: add restool userspace support To: Ioana Ciornei Cc: gregkh , Laurentiu Tudor , Linux Kernel Mailing List , Stuart Yoder , Ruxandra Ioana Radulescu , razvan.stefanescu@nxp.com, Roy Pledge Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 23, 2018 at 11:38 PM, Ioana Ciornei wrote: > Adding kernel support for restool, a userspace tool for resource > management, means exporting an ioctl capable device file representing > the root resource container. > This new functionality in the fsl-mc bus driver intends to provide > restool an interface to interact with the MC firmware. > Commands that are composed in userspace are sent to the MC firmware > through the RESTOOL_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. Hi Ioana, So this driver is a direct passthrough to your hardware for passing fixed-length command/response pairs. Have you considered using a higher-level interface instead? Can you list some of the commands that are passed here as clarification, and explain what the tradeoffs are that have led to adopting a low-level interface instead of a high-level interface? The main downside of the direct passthrough obviously is that you tie your user space to a particular hardware implementation, while a high-level abstraction could in principle work across a wider range of hardware revisions or even across multiple vendors implementing the same concept by different means. > +static long fsl_mc_restool_dev_ioctl(struct file *file, > + unsigned int cmd, > + unsigned long arg) > +{ > + int error; > + > + switch (cmd) { > + case RESTOOL_SEND_MC_COMMAND: > + error = fsl_mc_restool_send_command(arg, file->private_data); > + break; > @@ -14,10 +14,18 @@ > * struct fsl_mc_command - Management Complex (MC) command structure > * @header: MC command header > * @params: MC command parameters > + * > + * Used by RESTOOL_SEND_MC_COMMAND > */ > struct fsl_mc_command { > __u64 header; > __u64 params[MC_CMD_NUM_OF_PARAMS]; > }; > > +#define RESTOOL_IOCTL_TYPE 'R' > +#define RESTOOL_IOCTL_SEQ 0xE0 I tried to follow the code path into the hardware and am a bit confused about the semantics of the 'header' field and the data. Both are accessed passed to the hardware using writeq(le64_to_cpu(cmd->header)) which would indicate a fixed byte layout on the user structure and that it should really be a '__le64' instead of '__u64', or possibly should be represented as '__u8 header[8]' to clarify that the byte ordering is supposed to match the order of the byte addresses of the register. However, the in-kernel usage of that field suggests that we treat it as a 64-bit cpu-endian number, for which the hardware needs to know the endianess of the currently running kernel and user space. Can you have a look at where the mistake is and what the byteorder for the fsl_mc_command structure is supposed to be? Obviously, this is one thing that would be simplified by using a high-level interface, but it's possible to do it like this as long as it's completely clear how the structure layout is meant to be used in the uapi header. Arnd