From owner-freebsd-current@freebsd.org Mon Jul 1 17:07:10 2019 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E99AC15DFF20 for ; Mon, 1 Jul 2019 17:07:09 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BF23A87E3D for ; Mon, 1 Jul 2019 17:07:08 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qt1-x82f.google.com with SMTP id p15so15441175qtl.3 for ; Mon, 01 Jul 2019 10:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9ZD2al5pF60lGHyVcmdHGx1qQDa093W47yPaszmMruE=; b=De9yNNo9Mv2+Lb9qAt0KSxAknkUZ1VTW6BKqMN8ZdyUwohNhhuDk+NoD9lFjg8CRCQ LNprmmtHsKc8d0oRzkdl8ebuLjluzGPNEwngY5/9GT1Dp0vvw/0C/M1WL1chd/+5Yks2 7hFUKyjKR2Xbd/dbMaoSKzb6EUaGiAQvgP3JYGy5BL07cJYZqUnw8wYtN8bjwRtKe8gb dGkLnuEa8hFUXnK5x7UNYATssm9UlW8ZcXPA+h7El1PWOoTaNtMlsfIzeMVh81/q+gd+ U+0pD52ZwJDUKyooQZfVUWBQDcvoM4Mky85g3YBZkhWty2TUB0zfXT2c071OmyCzyr2i PIqQ== 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=9ZD2al5pF60lGHyVcmdHGx1qQDa093W47yPaszmMruE=; b=idHDezSqJBMa2Nabdr21hVWhO1xnWH61/aA2igJ8UlCFfHaF3SEkLhHF5YkxS17zdd v97tmUpT94BLNUlzZD8SeXEss7Ic9oHSlTHUJ00JTdd+ilf0DuIaKI0I5ahwDqhTs3Ck IZBGx0ue+I9AL1YxkWKVA6t5Z1G0j49mzDqbjmi3kGer+wpY9qtKmvDbWIEoGvl+UYDF FfAQdsYsACfyEYVgb+Ei+gJQOkTE1NjALNc2hnrt0qfkuo2BnRkJ6IXZKwU0QoE2KU7H MNOeht3m6QwWLElpMRN0yOZ4knN7q2mxw3NL6Bd55Z/pvtr4yHNhUJRioHxWs0Q+DsBt coEg== X-Gm-Message-State: APjAAAUQqc41ds4Vuf3byF5odAzV+2/5zc80k8AoM9eZYhxgY9ak3I9a K6zLwLI8GD8YpDXEi06RZXWQEhUCXyNUg7BiYxW57Q== X-Google-Smtp-Source: APXvYqzfIxOrh9yMXUaazzPqyxk84dddF7wHXG4i4ULMNcvqCwYw2vWIQkcu+PYkro42+ZKMggMYQWw31Pw6nITPOtE= X-Received: by 2002:ac8:2baa:: with SMTP id m39mr21703250qtm.242.1562000827998; Mon, 01 Jul 2019 10:07:07 -0700 (PDT) MIME-Version: 1.0 References: <7e5d8a06bc2d46263262369464e9348b82263847.camel@freebsd.org> In-Reply-To: <7e5d8a06bc2d46263262369464e9348b82263847.camel@freebsd.org> From: Warner Losh Date: Mon, 1 Jul 2019 11:06:57 -0600 Message-ID: Subject: Re: i2c bit banging timeout for SCL To: Ian Lepore Cc: Andriy Gapon , FreeBSD Current X-Rspamd-Queue-Id: BF23A87E3D X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=bsdimp-com.20150623.gappssmtp.com header.s=20150623 header.b=De9yNNo9 X-Spamd-Result: default: False [-5.89 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[bsdimp-com.20150623.gappssmtp.com:s=20150623]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-current@freebsd.org]; DMARC_NA(0.00)[bsdimp.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; MX_GOOD(-0.01)[cached: ALT1.aspmx.l.google.com]; DKIM_TRACE(0.00)[bsdimp-com.20150623.gappssmtp.com:+]; RCVD_IN_DNSWL_NONE(0.00)[f.2.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; NEURAL_HAM_SHORT(-0.89)[-0.890,0]; R_SPF_NA(0.00)[]; FORGED_SENDER(0.30)[imp@bsdimp.com,wlosh@bsdimp.com]; MIME_TRACE(0.00)[0:+,1:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[imp@bsdimp.com,wlosh@bsdimp.com]; IP_SCORE(-2.99)[ip: (-9.41), ipnet: 2607:f8b0::/32(-3.13), asn: 15169(-2.34), country: US(-0.06)]; RCVD_COUNT_TWO(0.00)[2] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jul 2019 17:07:10 -0000 On Mon, Jul 1, 2019 at 10:30 AM Ian Lepore wrote: > On Mon, 2019-07-01 at 19:03 +0300, Andriy Gapon wrote: > > iicbb driver has a hardcoded timeout that defines how long the driver > waits for > > SCL line to go high after the driver releases it to float. Sometimes > slaves > > hold the line low until they are ready to continue with the > communication. > > As a side note, the timeout means that the driver just goes on as if the > line > > became high. Maybe it should produce an error instead. > > > > Anyway, I would like to increase the current timeout of 100 x 10us to > 1000 x > > 10us. The rationale is that there are many slave devices, like sensors, > that > > take about 10 ms to return a result. So, I think that it makes sense to > play > > nice with such devices by default. > > > > Probably I'll add a sysctl for that parameter while I'll be there. > > > > Any objections? > > Many (perhaps most?) modern i2c slave devices are both i2c and smbus > compatible, and the smbus slave timeout is 35ms, so that wouldn't be a > bad default value. > I'd concur here. Someone else will have a device that takes 20ms to reply and wonder why we're broken... The only issue, really, is that this timeout is a busy loop and there may be I/O bus contention introduced on these systems. My gut tells me that we should look out for that, but bump the default timeout to the limit of the spec we implement. There's no I2C limit, and there is a smbus one, so let's go with the latter. Most of the time, most of the devices will react within a millisecond anyway, which isn't terrible for a bit-banged situation. > I don't think ignoring the error and forging ahead is a good idea. It > should return an error, and perhaps it should use the bitbang bus- > recovery sequence (from iic_recover_bus.c) to unwedge the slave device. > Also agreed. Warner