Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1477645imm; Thu, 12 Jul 2018 02:34:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf8eN6eXFOhh+x/JIt8k7i1IULDvQdEiZHkGZV+YOym0Rnsd/4WynO8AvorlgtR4qZRRrla X-Received: by 2002:a63:3444:: with SMTP id b65-v6mr1386011pga.396.1531388061464; Thu, 12 Jul 2018 02:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531388061; cv=none; d=google.com; s=arc-20160816; b=VHzRSNuLnDVia5swWnndamZyBxYz30IBR1+aAoCam7jiaIYP4JOJyf+Y5ttRgoxC+x D4HlIOGi7tLNUSWlV6eLSIM4evBdyc/BGgpcY9VzmGkHbuBb5OE1fYb53YLZs0jTsf8m hgMEuOh0ozGW1AsMzpyUHoqifK+6MsrYryCW0O60k1nuuxGJjjrYVgJpQx1pS4Fmc6FV 5srYu7u670WDGkJuUb8dH+77PO2orzrmqgOS9ePCwHaPaMGH8AlY/+pAJLEw4a9MqA1M 9X34D9GSpPWM6j6/SH+LIPopzTxXkVZYRZeFuUqnnaADinrCS5IXyhJjIXkkF3mxXdCl wSUQ== 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 :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=cvezg0H1R5cj86TL6CQFpifq3Ylpvdob6co5WNClqus=; b=wYSTig9P93ubUnInNBv0LEetvX4bF7Q5u8Ihl0NvP1TjVCSgv20IP+XGtb+1UYDX84 2KtVSZ0aPVVwl/GCSvuxTU2/P73W4b0TfE0iRRHr7snvf3XXUGRcFroTe6rusdTpzYWO UnjS7mIljhMm73TfuBqyqB/LJmDPqYZxhth0LUfxjAHWRnrDFeid9plNHCTP2I0ZDQSU l4QEzZfsQe0VUIlF0jVVPI+iPVT4hot+dAK6EnlTbJrEwdSY/Wz72JF9DcSIjt/B/mWu 2rrx0codNF619UZnseWKS1VDXYLpk+K7H4QY+PPArwuoNKLcm4t/YKELxPdX1cvf5cmp lAXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=P7yqMzLP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9-v6si19507687pgo.397.2018.07.12.02.34.05; Thu, 12 Jul 2018 02:34:21 -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=@google.com header.s=20161025 header.b=P7yqMzLP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726535AbeGLJmP (ORCPT + 99 others); Thu, 12 Jul 2018 05:42:15 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:38583 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbeGLJmP (ORCPT ); Thu, 12 Jul 2018 05:42:15 -0400 Received: by mail-oi0-f68.google.com with SMTP id v8-v6so54599883oie.5 for ; Thu, 12 Jul 2018 02:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cvezg0H1R5cj86TL6CQFpifq3Ylpvdob6co5WNClqus=; b=P7yqMzLPjCwrwoy1XZClDeczI/5YBjdUhKytIJcgjMq2a/hBcmp9/aKZUexDm/u5X2 mgo7myItMigOzaKIi7ewUZjhqyY/C79vd0GbVm/0nyviyWR2NQTWMiIXzMhZlpPmqC8l ALpcCkthKbQScEdfLB0I0ArvWAYgUCGimpK/GmBzyamCPGgCp341zbYlE6b0V7gvI5t8 K/VGjJxEJ6MqI6JqpvSrNuakna49H8f7N3fy9Fp011H4ou+xokGy51B74FiAe5WVbis6 oDmMOSmp4Kf6nATk0dTHEz/ABnLQ0AgxvXQMX56Vvc51vaSsUlUXV6ej5DIOxlieps8d ixDw== 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; bh=cvezg0H1R5cj86TL6CQFpifq3Ylpvdob6co5WNClqus=; b=ZCfF6McLQRHZmWzFjQeWwGI/lZCI6Z9DY5PzkZ0RSOLMoCSnBIVJjqAlSrmbIRu1Wy Foytq8eZR8+pcSF2DzLxtwoRwe95hyEweqpYhK3Gi+IQfoc+BmhAiT3bOYtqiXIsP5wi wiuj42Dp3iXOsC+1osrj35ztmjUFzBK8i8ftALGFkuMiZtJWWB1sP04z0Upch2jchmYM Cre4KDti4FcWjx5jqb/+W00XIthgU+DFSfNwKH7j/YT6N+G3xbbq/vABHn7sLckM4auW Y7hvtFe2X8RXUsL3MofL36+p33Fxv7TZLxLd4bjCAhG4JYitluHIQQ9tiU1UkcRYw5sO ss9Q== X-Gm-Message-State: AOUpUlGCIob9oSPUBfLEKk+CfGGIZuoZlPmitadhWXQYBiJlBOoL2gV5 S69EDKELZWdnN/gO4hTZTFXWRCfpWPfrrUdLEr2HkA== X-Received: by 2002:aca:190d:: with SMTP id l13-v6mr1597772oii.216.1531388008292; Thu, 12 Jul 2018 02:33:28 -0700 (PDT) MIME-Version: 1.0 References: <20180626165812.4141-1-jae.hyun.yoo@linux.intel.com> In-Reply-To: From: Brendan Higgins Date: Thu, 12 Jul 2018 02:33:16 -0700 Message-ID: Subject: Re: [PATCH] i2c: aspeed: Improve driver to support multi-master use cases stably To: jae.hyun.yoo@linux.intel.com Cc: Benjamin Herrenschmidt , Joel Stanley , Andrew Jeffery , linux-i2c@vger.kernel.org, OpenBMC Maillist , Linux ARM , linux-aspeed@lists.ozlabs.org, Linux Kernel Mailing List , james.feist@linux.intel.com, vernon.mauery@linux.intel.com, Benjamin Fair , Patrick Venture 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, Jun 27, 2018 at 10:55 AM Jae Hyun Yoo wrote: > > >> +/* Timeout for bus busy checking */ > >> +#define BUS_BUSY_CHECK_TIMEOUT 250000 /* 250ms */ > >> +#define BUS_BUSY_CHECK_INTERVAL 10000 /* 10ms */ > > > > Could you add a comment on where you got these values from? > > > > These are coming from ASPEED SDK code. Actually, they use 100ms for > timeout and 10ms for interval but I increased the timeout value to > 250ms so that it covers a various range of bus speed. I think, it > should be computed at run time based on the current bus speed, or > we could add these as device tree settings. How do you think about it? > This should definitely be a device tree setting. If one of the busses is being used as a regular I2C bus, it could hold the bus for an unlimited amount of time before sending a STOP. As for a default, 100ms is probably fine given that, a) the limit will only apply to multi-master mode, and b) multi-master mode will probably almost always be used with IPMB, or MCTP (MCTP actually recommends a 100ms timeout for this purpose, see https://www.dmtf.org/sites/default/files/standards/documents/DSP0237_1.1.0.pdf, symbol PT2a). That being said, if you actually want to implement IPMB, or MCTP arbitration logic, it is much more complicated. > > > >> #if IS_ENABLED(CONFIG_I2C_SLAVE) > >> - if (aspeed_i2c_slave_irq(bus)) { > >> - dev_dbg(bus->dev, "irq handled by slave.\n"); > >> - return IRQ_HANDLED; > >> + if (bus->master_state != ASPEED_I2C_MASTER_INACTIVE) { > >> + if (!aspeed_i2c_master_irq(bus)) > > > > Why do you check the slave if master fails (or vice versa)? I > > understand that there are some status bits that have not been handled, > > but it doesn't seem reasonable to assume that there is state that the > > other should do something with; the only way this would happen is if > > the state that you think you are in does not match the status bits you > > have been given, but if this is the case, you are already hosed; I > > don't think trying the other handler is likely to make things better, > > unless there is something that I am missing. > > > > In most of cases, interrupt bits are set one by one but there are also a > lot of other cases that ASPEED I2C H/W sends multiple interrupt bits > with combining master and slave events using a single interrupt call. It > happens much in multi-master environment than single-master. For > example, when master is waiting for a NORMAL_STOP interrupt in its > MASTER_STOP state, SLAVE_MATCH and RX_DONE interrupts could come along > with the NORMAL_STOP in case of an another master immediately sends data > just after acquiring the bus - it happens a lot in BMC-ME connection > practically. In this case, the NORMAL_STOP interrupt should be handled > by master_irq and the SLAVE_MATCH and RX_DONE interrupts should be > handled by slave_irq so it's the reason why this code is added. That sucks. Well, it sounds like there are only a handful of cases in which this can happen. Maybe enumerate these cases and error out or at least warn if it is not one of them? > > >> + for (;;) { > >> + if (!(readl(bus->base + ASPEED_I2C_CMD_REG) & > >> + (ASPEED_I2CD_BUS_BUSY_STS | > >> + ASPEED_I2CD_XFER_MODE_STS_MASK))) > > > > Is using the Transfer Mode State Machine bits necessary? The > > documentation marks it as "for debugging purpose only," so relying on > > it makes me nervous. > > > > As you said, the documentation marks it as "for debugging purpose only." > but ASPEED also uses this way in their SDK code because it's the best > way for checking bus busy status which can cover both single and > multi-master use cases. > Well, it would also be really nice to have access to this bit if someone wants to implement MCTP. Could we maybe check with Aspeed what them meant by "for debugging purposes only" and document it here? It makes me nervous to rely on debugging functionality for normal usage. > >> + return 0; > >> + if (ktime_compare(ktime_get(), timeout) > 0) > >> + break; > >> + usleep_range((BUS_BUSY_CHECK_INTERVAL >> 2) + 1, > > > > Where did you get this minimum value? > > > > No source for the minimum value. ASPEED uses mdelay(10) in their SDK > but I changed that code using usleep_range and the range value was set > with considering time stretching of usleep_range. > regmap_read_poll_timeout was a reference for this code. What protocol are you trying to implement on top of this? You mentioned BMC-ME above; that's IPMB, right? For most use cases, this should work, but if you need arbitration, you will need to do quite a bit more work. > > Thanks, > > Jae Cheers