Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7700072imu; Tue, 22 Jan 2019 10:05:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN5GeIPlwZksRPrHRtT97FHpePPVCIa85gk9QDlkWdtJ8qPv9+sWlkDC2KTbsoFBiDDVTp1a X-Received: by 2002:a65:4646:: with SMTP id k6mr27819686pgr.153.1548180338020; Tue, 22 Jan 2019 10:05:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548180337; cv=none; d=google.com; s=arc-20160816; b=sxQR28Y1zgT1ZITR64EW2q19sb3koKu6cUCGqhUIReUjJ1GEzHsR5XhfWqnD0luSVf yiIT0b9TbiRKsfNaKnCvQrX1BgZZ0idL7UVt2p3I5qvpTv/FS/b74QbC09FcOEg8SBOx BtBuxXnia5+ulI7E6s+6B/AGGZWXbrtS2d5aT9yx81hv7Tx+5fhVD72tpYdajRnLglEv yf1133GjS8Qj153jxBUlNqfx3ErnOMHJs1kdl1eM1pQODXYJinfXQTKzbE1HhsxmKXMz ik3ODHkbfCDzXfH1GOaiir1ZWiouXrWk9zXA89JOxVOBX1HDeoiGyC2lKdBc6Q2GNeWI lVzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=LziRkSZLT0z/Jxq8iGYf/seHXgBAOV6ZmnF12I7nVdc=; b=L3WHS1MAiB6XkxkmibVdLI4HFWOxy1gt02ecOxVzNVAN28mSyu4JtbTjM3UFOpvokN Quv+Dr94eud+Yg/SDmWb2EBc86Z/KiKbYUm0beOZpIdWkv8va6CO9EMAeME4CVoEbcdU jy61glktxn6FuW7+UtYzwlBk0FDdw7G3HMpcCkTKgGKpj+IhzcASCV3XqETgGHKm/bLg GbmmovD4YbbuVtU4fKmdp0FSY6vjR5DKfFf7DUEgdj06tCK82s0FApjtXOsKZE+qoZgz M1Bi9m9GToVM3VzCDW3VlfcOweXU6MjbTfbRmqLfG94jnSAEqkgkrk6ffm6FLiUq5rMn rzHw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u22si12166408pgk.335.2019.01.22.10.05.10; Tue, 22 Jan 2019 10:05:37 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726291AbfAVR4w (ORCPT + 99 others); Tue, 22 Jan 2019 12:56:52 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:37590 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725950AbfAVR4w (ORCPT ); Tue, 22 Jan 2019 12:56:52 -0500 Received: by mail-lf1-f65.google.com with SMTP id y11so18771757lfj.4; Tue, 22 Jan 2019 09:56:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=LziRkSZLT0z/Jxq8iGYf/seHXgBAOV6ZmnF12I7nVdc=; b=RWHOrCz5t5V/30zosq0W8PPPdcZzb1iOVvfs/uTBkJR0uKDs3SbAsAj8QfM0dFWev/ geqYYHh1N3qgIzP8TVGLtPBUZBFh9Y0aSk+ID0A2HRx9o3s0fzehI21b2YaC7QwYjvE8 9UwbKr45mDDVFdgLfQ3Y2m79bC1LeqJ9BGZ9CAI7Cn3v9rEKdAC6OJZOZ5dAPq2M8+mx xW4dBAAJ9ktpLzClisLTYwLxHgi0ScNy/JiZWfSkJonOVST7ngk6sJTcOYx5vyUvsKCS pystXzJI46E+wngrJAmbqcza9ix3CpaExCozvx6rpIwSI+T+ELFWgCf8Y2bEBqLr//OW Z9FA== X-Gm-Message-State: AJcUukdaxYMC6GjRcnCBashEU6ItgxWfKX3sknEdSaT6h48NL0797F8n IkdlFQv75Qk6nYtPHKSxC9w= X-Received: by 2002:a19:f115:: with SMTP id p21mr17622429lfh.20.1548179807804; Tue, 22 Jan 2019 09:56:47 -0800 (PST) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id r4sm105668lfe.60.2019.01.22.09.56.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 09:56:47 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1gm0Hz-0004r9-0r; Tue, 22 Jan 2019 18:56:43 +0100 Date: Tue, 22 Jan 2019 18:56:43 +0100 From: Johan Hovold To: Andreas Kemnade Cc: letux-kernel@openphoenux.org, johan@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/6] gnss: sirf: add support for configurations without wakeup signal Message-ID: <20190122175643.GR3691@localhost> References: <20190116211812.6337-1-andreas@kemnade.info> <20190116211812.6337-4-andreas@kemnade.info> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190116211812.6337-4-andreas@kemnade.info> User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 16, 2019 at 10:18:09PM +0100, Andreas Kemnade wrote: > Some Wi2Wi devices do not have a wakeup output, so device state can > only be indirectly detected by looking whether there is communitcation communication > over the serial lines. > This approach requires a report cycle set to a low value to be reliable. How low? Better to spell out your current assumptions so people can configure accordingly. > Signed-off-by: Andreas Kemnade > --- > Changes in v3: > - was 2/5 earlier > - changed commit headline > - more style cleanup > - split out initial power off as 2/6 > - introduced SIRF_REPORT_CYCLE constant > - added documentation about limitations > - ignore first data after power state on so no > shutdown meassages are treated as power on success > - clearer logic in sirf_wait_for_power_state > > Changes in v2: > - style cleanup > - do not keep serdev open just because runtime is active, > only when needed (gnss device is opened or state is changed) > - clearer timeout semantics > > > drivers/gnss/sirf.c | 117 +++++++++++++++++++++++++++++++++++++++++----------- > 1 file changed, 93 insertions(+), 24 deletions(-) > > diff --git a/drivers/gnss/sirf.c b/drivers/gnss/sirf.c > index c7706b91f6f0..943a2ec9b708 100644 > --- a/drivers/gnss/sirf.c > +++ b/drivers/gnss/sirf.c > @@ -25,6 +25,16 @@ > #define SIRF_ON_OFF_PULSE_TIME 100 > #define SIRF_ACTIVATE_TIMEOUT 200 > #define SIRF_HIBERNATE_TIMEOUT 200 > +/* > + * If no data arrives for this time, we expect the chip to be off. "we assume that the chip is off"? > + * REVISIT: The report cycle is configurable and can be several minutes long, > + * so this will only work reliably if the report cycle is set to a reasonable > + * low value. Also power saving settings (like send data only on movement) > + * might things work even worse. > + * Workaround might be to parse shutdown or bootup messages. > + * This problem mainly makes error checking uncertain. I'd drop the last sentence. You could also fail to detect the state and waste power indefinitely, right? > + */ > +#define SIRF_REPORT_CYCLE 2000 > > struct sirf_data { > struct gnss_device *gdev; > @@ -39,9 +49,45 @@ struct sirf_data { > struct mutex gdev_mutex; > bool open; > > + /* > + * Using the same mutex inside a serdev callback > + * and around a serdev call leads to lockdep problems. Lockdep is not a problem; a possible deadlock is. Just drop this comment. > + */ > + struct mutex serdev_mutex; > + int serdev_count; > + > wait_queue_head_t power_wait; > }; > > +static int sirf_serdev_open(struct sirf_data *data) > +{ > + int ret = 0; > + > + mutex_lock(&data->serdev_mutex); > + if (++data->serdev_count == 1) { > + ret = serdev_device_open(data->serdev); > + if (ret) { > + data->serdev_count--; > + mutex_unlock(&data->serdev_mutex); Use a common "out_unlock:" path below. > + return ret; > + } > + > + serdev_device_set_baudrate(data->serdev, data->speed); > + serdev_device_set_flow_control(data->serdev, false); > + } > + mutex_unlock(&data->serdev_mutex); > + > + return ret; > +} > @@ -128,6 +170,11 @@ static int sirf_receive_buf(struct serdev_device *serdev, > struct gnss_device *gdev = data->gdev; > int ret = 0; > > + if (!data->wakeup && !data->active) { > + data->active = true; > + wake_up_interruptible(&data->power_wait); > + } > + > mutex_lock(&data->gdev_mutex); > if (data->open) > ret = gnss_insert_raw(gdev, buf, count); > @@ -163,6 +210,24 @@ static int sirf_wait_for_power_state(struct sirf_data *data, bool active, > { > int ret; > > + if (!data->wakeup) { You currently don't share any code with the wakeup-case; better to keep this in a separate helper if so. > + /* Wait for boot or shutdown messages */ /* Wait for state change (including any shutdown messages). */ > + msleep(timeout); > + data->active = false; > + /* Now check if it is really off. */ You now also use this code to check for activate state: /* Wait for data reception or timeout. */ > + ret = wait_event_interruptible_timeout(data->power_wait, > + data->active, > + msecs_to_jiffies(SIRF_REPORT_CYCLE)); > + if (ret < 0) > + return ret; > + > + if ((ret > 0 && !active) || > + (ret == 0 && active)) Split these cases in two add add comments (failed suspend and failed resume) for readability. > + return -ETIMEDOUT; > + > + return 0; > + } > + > ret = wait_event_interruptible_timeout(data->power_wait, > data->active == active, msecs_to_jiffies(timeout)); > if (ret < 0) > @@ -195,18 +260,29 @@ static int sirf_set_active(struct sirf_data *data, bool active) > else > timeout = SIRF_HIBERNATE_TIMEOUT; > > + if (!data->wakeup) { > + ret = sirf_serdev_open(data); > + if (ret) > + return ret; > + } > + > do { > - sirf_pulse_on_off(data); > + /* > + * Try to avoid unneeded, time-consuming state toggles > + * in the configurations without wakeup signal. This counts > + * especially for the initial off state check. > + */ > + if (data->wakeup || data->active || active) > + sirf_pulse_on_off(data); Special casing like this only hurts readability. This is better handled as a I did for the wakeup case in the series I just posted, that is, by making sure the receiver is hibernated in probe. You just need to add a helper to determine the state for no-wakeup. > + > ret = sirf_wait_for_power_state(data, active, timeout); > - if (ret < 0) { > - if (ret == -ETIMEDOUT) > - continue; > + } while (ret == -ETIMEDOUT && retries--); Why change this? > > - return ret; A break should do right? > - } > + if (!data->wakeup) > + sirf_serdev_close(data); > > - break; > - } while (retries--); > + if (ret) > + return ret; > > if (retries < 0) > return -ETIMEDOUT; Johan