Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp655638yba; Fri, 5 Apr 2019 14:22:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjRf6PwFTkZ0Z2NniNvXBZ1H7GFmMd7ZX5jy/hILlDqCPu2GucDTo1u1TLZAzg4CWUI5Il X-Received: by 2002:a17:902:2702:: with SMTP id c2mr14579997plb.239.1554499363786; Fri, 05 Apr 2019 14:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554499363; cv=none; d=google.com; s=arc-20160816; b=SbTH7cjl+N8cXYK7X4kNzkBXaWGQkRIktOKwaCSs+ajuSEWbEQy7y9RMi9/DmBEUEn VtPUjUleKmD/7AQ9zh6QYjae9kIyWBnfPZgfQG+/zVMMxnWgQBY2qxnvq1F37ayWn2m5 8IAB2gb3WAEOAKPOASRSBTN7A5I7uWgr9FmlLKr4DLK38GcJJzDOuT9fmWT/6AwzeWfj 6LqPoHVstfhIhhgFDMrEfrqj0gSjM8rNGh5Pm70fHvsSPX7cCYH2IZCCtcklvygpUeg9 /q9+3ZNZlLhdZAbUJWfn/URye9U0i7mG/IQkaQHbxPSppUCSaWvmg/hg638ltIjncZTT OFtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Dpxx/MPLM5U9jBhNiMPxgjV+FsSZSY4WqIn1eJmAXcQ=; b=mJIN99x/QaQkGpUtdJb/lR46OaIowU8PWuXrTbJQiAvpXhIQL4QoodFlvtEDya1hNQ IDZp+vEoIWByojRwaNiq3rg3k6DYi0yvsL9Ui/1eSkdiegnEkaW3XSZDsHoba8GMbbDm Hh7YcJqKv2H5FJhcBwhaxEb3aFaVSFUDcYvbi7BSmPyBBfCVOqgSEbEKOeOECa7vhee/ x+DywRze87hTZWb8Mfvcz6r73TApSuFC+wyM/VqTJVDkCt9V/O2d6ENAYOyrSzSpNj+H 7BVpWDpHJ4lG9PDknIHYNoChuutUVhssOxrPni50y/mx4hHvhfbsQPqvb4hToLOt4Vd9 LS8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HLSTcoWh; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u37si19704754pga.301.2019.04.05.14.22.27; Fri, 05 Apr 2019 14:22:43 -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=pass header.i=@gmail.com header.s=20161025 header.b=HLSTcoWh; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726310AbfDEVVo (ORCPT + 99 others); Fri, 5 Apr 2019 17:21:44 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:44242 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725967AbfDEVVn (ORCPT ); Fri, 5 Apr 2019 17:21:43 -0400 Received: by mail-qt1-f194.google.com with SMTP id w5so9063322qtb.11 for ; Fri, 05 Apr 2019 14:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Dpxx/MPLM5U9jBhNiMPxgjV+FsSZSY4WqIn1eJmAXcQ=; b=HLSTcoWhJV2FaRyws/H1jCa/x5KsSulMnTJ2WnBPZyid1fJaAc56euf9J2Jc3kXjIP 5Ua2SVYnegWFn5lHbsWWp6bABDHQOROp2k/Zi9n60+my2h5r2lHqTo25ensXIN84NXG4 5hKrl2Kcb3melDtQxCkQG4v9N6YoK5PQ76t4zeWH1aGq1gpXYdWJSz0O4FI+1r8TG9Qk O709YWtwupBEegdpY3iH2k9X8dWG3d3q6eyQeOErwyFKoEypgPjgb3nbvqmG+hyZRbdt DboHwnr4d0wWnS93v5hl/VLEISL8Jtn2C0AmLIs5YPsfV89r9+JfAKrNF8YH7LXhMD59 Q+pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Dpxx/MPLM5U9jBhNiMPxgjV+FsSZSY4WqIn1eJmAXcQ=; b=uVpgm4FiWtZK09P2/VQYMuwelqhM+bF+mVGsZ12zUHL81orISsqCH4BNPQmtD8vxvU 47HYtCa4GgU7CtJi/42O/gZvUL6zOumUiF/KlVJaKzWtwcxEppYbq3vJgFw45ywfUrSB t8nUJzlJo6fdtZSL5K/7GQJWxnjA2W1wANaRKRqeaC7Kpah0b/Uk5PhdSaeQEYM7Nehc 20WEE7+tSLr8tdJm4/Yj+aLQSh30Qirtg8ngQp6cN0JGyKAnPVCdBrgvMrxl2gL7+KkU k/vJ9r/ju/IbqEOWvg9/whnuvgFRvlCecV/5a22GKV2HRIiVXRSos01L3W/nsg0HLiA/ NXHg== X-Gm-Message-State: APjAAAUo0c6lv33vd1vbdgacqUBg8DI4qAECu6fHNanSYHPJ7Asm1Vdd ba7MVM1rcDZn5XHiTXl1U51EOlbuonscmFsSQQE= X-Received: by 2002:ac8:85c:: with SMTP id x28mr13611833qth.90.1554499302348; Fri, 05 Apr 2019 14:21:42 -0700 (PDT) MIME-Version: 1.0 References: <20190405200742.107973-1-ncrews@chromium.org> In-Reply-To: <20190405200742.107973-1-ncrews@chromium.org> From: Enric Balletbo Serra Date: Fri, 5 Apr 2019 23:21:31 +0200 Message-ID: Subject: Re: [PATCH 1/3] platform/chrome: wilco_ec: Standardize mailbox interface To: Nick Crews Cc: Enric Balletbo i Serra , Benson Leung , linux-kernel , dlaurie@chromium.org, Daniel Erat , Guenter Roeck , Dmitry Torokhov , lamzin@google.com, sjg@gchromium.org, Alexandre Belloni Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nick, Missatge de Nick Crews del dia dv., 5 d=E2=80=99abr. 2019 a les 22:09: > > The current API for the wilco EC mailbox interface is bad. > > It assumes that most messages sent to the EC follow a similar structure, > with a command byte in MBOX[0], followed by a junk byte, followed by > actual data. This doesn't happen in several cases, such as setting the > RTC time, using the raw debugfs interface, and reading or writing > properties such as the Peak Shift policy (this last to be submitted soon)= . > > Similarly for the response message from the EC, the current interface > assumes that the first byte of data is always 0, and the second byte > is unused. However, in both setting and getting the RTC time, in the > debugfs interface, and for reading and writing properties, this isn't > true. > > The current way to resolve this is to use WILCO_EC_FLAG_RAW* flags to > specify when and when not to skip these initial bytes in the sent and > received message. They are confusing and used so much that they are > normal, and not exceptions. In addition, the first byte of > response in the debugfs interface is still always skipped, which is > weird, since this raw interface should be giving the entire result. > > Additionally, sent messages assume the first byte is a command, and so > struct wilco_ec_message contains the "command" field. In setting or > getting properties however, the first byte is not a command, and so this > field has to be filled with a byte that isn't actually a command. This > is again inconsistent. > > wilco_ec_message contains a result field as well, copied from > wilco_ec_response->result. The message result field should be removed: > if the message fails, the cause is already logged, and the callers are > alerted. They will never care about the actual state of the result flag. > > These flags and different cases make the wilco_ec_transfer() function, > used in wilco_ec_mailbox(), really gross, dealing with a bunch of > different cases. It's difficult to figure out what it is doing. > > Finally, making these assumptions about the structure of a message make > it so that the messages do not correspond well with the specification > for the EC's mailbox interface. For instance, this interface > specification may say that MBOX[9] in the received message contains > some information, but the calling code needs to remember that the first > byte of response is always skipped, and because it didn't set the > RESPONSE_RAW flag, the next byte is also skipped, so this information > is actually contained within wilco_ec_message->response_data[7]. This > makes it difficult to maintain this code in the future. > > To fix these problems this patch standardizes the mailbox interface by: > - Removing the WILCO_EC_FLAG_RAW* flags > - Removing the command and reserved_raw bytes from wilco_ec_request > - Removing the mbox0 byte from wilco_ec_response > - Simplifying wilco_ec_transfer() because of these changes > - Gives the callers of wilco_ec_mailbox() the responsibility of exactly > and consistently defining the structure of the mailbox request and > response > - Removing command and result from wilco_ec_message. > > This results in the reduction of total code, and makes it much more > maintainable and understandable. > > Signed-off-by: Nick Crews > Acked-by: Alexandre Belloni > --- > drivers/platform/chrome/wilco_ec/debugfs.c | 43 ++++++++------- > drivers/platform/chrome/wilco_ec/mailbox.c | 53 ++++++++---------- > drivers/rtc/rtc-wilco-ec.c | 63 +++++++++++++--------- > include/linux/platform_data/wilco-ec.h | 22 +------- > 4 files changed, 83 insertions(+), 98 deletions(-) > Now I'm confused, isn't this the same patch I picked this morning from you and is already applied in chrome-platform for-next? [snip]