Received: by 10.213.65.68 with SMTP id h4csp632644imn; Wed, 28 Mar 2018 09:51:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx48GBzC7dUSJFU9bwakpCvHfX68nb3CNHkfMbJsITZtoEIs6hO28DL66WK1gnn+fzde+uqrV X-Received: by 10.98.206.77 with SMTP id y74mr3592329pfg.205.1522255896116; Wed, 28 Mar 2018 09:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522255896; cv=none; d=google.com; s=arc-20160816; b=PlgbXkUNchDXM2BmibMt2nFi4XnvfP+NfzZEoaE9ItDdGtcOh9RdFTvRObOCobKER1 bN92UfkmxGBWPyXxaePhIQ3HCQxjI2ue2TN8zPf9sbNzLhAmA5IoPkjWnGEBpRCAXxX+ 7DQyp4SfFYMsvGEYGEt/vZ3AtakRIVVeB5MfEuikzUO0u1BnEd3HaeEKiCMRmjzfWQ8a W+97JwB7bKDIVYQtov/S7avfwlAXuIsvm1j7+rLUpnqAob30a7o7vhoKLCFR/ZVYArtO coX5v0R/ZZ5OEumyXa576jK4MNVrraeeHKlR+ZKpnisTLXX0zpIFmqBY4evY8FegZcYG Mutw== 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=PUN0tswLv6+u/DnaFNoaVu6lyrIrZff0lP11C3UeTgw=; b=q8CnG6j1Y6y9T9HRKpcLxIPJ1Sw4uaE/u/o0eRrhPHQxqYiqTotcwfi2E/remD+HRo 5WJmyjiv/pl1cu+XwcRClUIyQfDzen9wpHsEQFtFoi4noPRGgyajU7PFEEqhLKAIJi15 2WBNS81bximnXUXmvPFyVLgj0+GQot7qBCA9ZC/cDQ2On0LEhxj9Rngvj6Lmp92fqf9g PKUlRO3k9CvpXURSHxWnvo68j2sylvG1O39fAD+JUtDywNPb/cX+26qZ1qYBA/EhOuG5 KEBv0/8Pghtc1Z2xo8ina8rF2VQQBy9sjKgP2/6YYAyII5E0hl0q4zjzuvcGffCufg1w QXAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TCl/JsQG; 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 r68si3084269pfi.413.2018.03.28.09.51.20; Wed, 28 Mar 2018 09:51:36 -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=TCl/JsQG; 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 S1754113AbeC1Pno (ORCPT + 99 others); Wed, 28 Mar 2018 11:43:44 -0400 Received: from mail-qt0-f175.google.com ([209.85.216.175]:39235 "EHLO mail-qt0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753886AbeC1Pnn (ORCPT ); Wed, 28 Mar 2018 11:43:43 -0400 Received: by mail-qt0-f175.google.com with SMTP id v11so3016221qtj.6; Wed, 28 Mar 2018 08:43:42 -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=PUN0tswLv6+u/DnaFNoaVu6lyrIrZff0lP11C3UeTgw=; b=TCl/JsQGkNvkFPC/ERer66xxmsA4pKZs5+3Er/YKIzUiYqKq0pqgsEcjnZNWdy9DcN u1orutzfFAKMCiJqvNm6vgXYLs7EnZek/zlwdnTzceN7FLzHjla++VM/VeWScwPylS82 0h8mk3jzvS7jSyODOXTJKhT0jgt/pgTbKPJALM5ICxClfWaFS25zpGgG5yoxIAHuo+LG OHgQbcFTq+/JpF/mH73aAYpxZ6E+8l1hgDGhJ9J6iQhpXuLvmvzEC1UqpdEvPaRdUmzu 028fb6BRYUdetmU3udFs7LWiGXFcbrAJEekWbsG7aSGJHy0hXv8XjJrAfpM9oZg03r6s eFYQ== 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=PUN0tswLv6+u/DnaFNoaVu6lyrIrZff0lP11C3UeTgw=; b=JfqFBWCYW+NfbRFWZgcog5RBUF+Xtsw4yxi1G35VOyM+XQSL6ygqyRclzX38bhGm9j fXaBX/qAVtOlEoMq4KDqJNTQx7PujLqQadUgF1WpnAW3qRX3/SeVFTdHp7QAKV+cMPuC Jvmuh2obvuJB6de3NYuQ42rsJxiha+plBK+DkWytQvOw+poGmPkqrIB3OiS+l74LZaoB ehkksEqfqO+kbuhcX1UJawInthjv3FFvpTQqyzBFWCUpFWfIcw0WHrTQ38TY10maXu4p eORUaYSLEEj90oJPeQ8jAMQik0ZdnlQfpG2kUCT7GCaLiEL2pyj5vEJfo1u8lH6+nEzv pwaw== X-Gm-Message-State: AElRT7F+DAK9h3kTw3+SCz7Asvo/J07GJOMC0LjSALZesLJcsZMYgi0Y CBv10nHnPmINBSUYowCYshz685qD+J1aYV7p4lE= X-Received: by 10.200.56.177 with SMTP id f46mr6144862qtc.9.1522251822043; Wed, 28 Mar 2018 08:43:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.12.185.25 with HTTP; Wed, 28 Mar 2018 08:43:40 -0700 (PDT) In-Reply-To: References: From: Arnd Bergmann Date: Wed, 28 Mar 2018 17:43:40 +0200 X-Google-Sender-Auth: szD_FQjDGRbMhmlAE_J21M2Pb78 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 Ciocoi Radulescu , Razvan Stefanescu , Roy Pledge , Networking 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 Wed, Mar 28, 2018 at 4:27 PM, Ioana Ciornei wrote: > Hi, > >> >> 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. > > If by "higher-level" you mean an implementation where commands are created by the kernel at userspace's request, then I believe this approach is not really viable because of the sheer number of possible commands that would bloat the driver. > > For example, a DPNI (Data Path Network Interface) can be created using a command that has the following structure: > > struct dpni_cmd_create { > uint32_t options; > uint8_t num_queues; > uint8_t num_tcs; > uint8_t mac_filter_entries; > uint8_t pad1; > uint8_t vlan_filter_entries; > uint8_t pad2; > uint8_t qos_entries; > uint8_t pad3; > uint16_t fs_entries; > }; > > In the above structure, each field has a meaning that the end-user might want to be able to change according to their particular use-case (not much is left at its default value). > The same level of complexity is encountered for all the commands that interact with Data Path objects such as DPBP(buffer pools), DPRC(Resource Container) etc. > You can find more examples of commands in restool's repo: https://github.com/qoriq-open-source/restool/tree/integration/mc_v10 > > In my opinion, an in-kernel implementation that is equivalent in terms of flexibility will turn > into a giant ioctl parser, all while also exposing an userspace API that is not as simple/easy to use. (adding the netdev list) The command you list there seems to be networking related, so instead of an ioctl based interface, a high-lever interface would likely use netlink for consistency with other drivers. Are all commands for networking or are there some that are talking to the device to do something unrelated? Obviously creating a high-level interface would be a lot of work in the kernel, and it only pays off if there are multiple independent users, we wouldn't do that for just one driver. I'm still not convinced either way (high-level or low-level interface), but I think this needs to be discussed with the networking maintainers. Given the examples on the github page you linked to, the high-level user space commands based on these ioctls ls-addni # adds a network interface ls-addmux # adds a dpdmux ls-addsw # adds an l2switch ls-listmac # lists MACs and their connections ls-listni # lists network interfaces and their connections and I see that you also support the switchdev interface in drivers/staging/fsl-dpaa2, which I think does some of the same things, presumably by implementing the switchdev API using fsl_mc_command low-level interfaces in the kernel. Is that a correct interpretation? If yes, could we extend switchdev or other networking interfaces to fill in whatever those don't handle yet? >> > @@ -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. >> > > Indeed, the struct fsl_mc_command should use '__le64' instead of '__u64', so that the UAPI header file clearly states what endianness should the userspace prepare. > The writeq appeared as a consequence of a previous mail thread https://lkml.org/lkml/2017/7/17/415, because the endianness of the command is handled by the user and the bus should leave the binary blob intact. Ok. However, with the dpni_cmd_create structure you list above, it seems that it doesn't actually contain a set of __le64 but rather an array of bytes, so it might be best to >> 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. >> > > I might have not understood what you are trying to say, but the in-kernel code treats the fsl_mc_command as little endian by using cpu_to_leXX and leXX_to_cpu in order to setup the command structure. One function that seems to have a problem is this one: static enum mc_cmd_status mc_cmd_hdr_read_status(struct fsl_mc_command *cmd) { struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header; return (enum mc_cmd_status)hdr->status; } If cmd->header is little-endian here, then the result is not an 'enum mc_cmd_status'. I think it would be good to change the types for fsl_mc_command to __le64 first and run everything through 'sparse' with 'make C=1' to find any remaining endianess problems. Arnd