Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1902850ybp; Wed, 9 Oct 2019 22:39:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKeGwpuGNxwt9eCV5rrcSi653eULhRkAq2+PY0bKpgKy2KPsyB8d+iivpPmtwfq0SRDcGs X-Received: by 2002:aa7:d753:: with SMTP id a19mr6644712eds.80.1570685944815; Wed, 09 Oct 2019 22:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570685944; cv=none; d=google.com; s=arc-20160816; b=rU8IiX12VnFxZita1FT0GejTMDfzAEAocwv1T+UD1oxRTNdV8RjiTRk+RDMmXAaYRN ZeJ5XQhqIloxwx5xmTOootTkZLwsSzuPpWcm1FgPqxPGMK6GEh5YZAGbS/WPmzI5whWt iYjY+7slqfMsU5KlOSxbyvRZ3hGWsdaLB6Mai4GGKhCQigsi2txh2ln7P1v0n4uDQY00 KsGSrgB4TvcqvAEHUTBoT172nsdZqkVLk8dmZ2hW8nDHGPWeXg27dAXmePGxOudrU3Kz 5Z0kdmoO8poA+TFOiFpsdE8uMq/NS90iaBRVR2bgHH9REzeISvDiLkUlwkDKVjZWvoIo nmOg== 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; bh=ld57m95bHJQBRxDnF5FnlK1Sfbx3W7UXVC5v8g98wR4=; b=YPcLl1dmPiNNFP6ua8IiyRbY9pMva4/9RtdKVjqbikWh6aLESpjg9RLxQBbQNrUKng mGb+3GeqBeJsU95a9m3HXkTmpdzM8EHPFQMGoa1nOn/R2Z7syUFyTC+iRNrrh5fYa39l ctkNqy+dDhYfq8nAON4GaZfxc+UD40N93QAIxEzAJPU9qdCvggIQM8tRoVYHKCx7WWUb x/Lh/BniYP90O+bqS4lA5TRgS2IIOk+a7R6m5+tddenDq5qtw44CLC8ggmS5uab/VkSe cV8hcpBnhWn6zu35E+cJuGGH8lSVqQmEITDp2HfIl3QV/NiK+gcEKXqlIFlJ4uWxjdl+ 5uvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iXJ5vQVG; 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 p18si2755843ejn.370.2019.10.09.22.38.40; Wed, 09 Oct 2019 22:39:04 -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=iXJ5vQVG; 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 S1732885AbfJJFhP (ORCPT + 99 others); Thu, 10 Oct 2019 01:37:15 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40758 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726612AbfJJFhP (ORCPT ); Thu, 10 Oct 2019 01:37:15 -0400 Received: by mail-pg1-f193.google.com with SMTP id d26so2917141pgl.7; Wed, 09 Oct 2019 22:37:15 -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; bh=ld57m95bHJQBRxDnF5FnlK1Sfbx3W7UXVC5v8g98wR4=; b=iXJ5vQVG3nQIDNvzt3AWLSYveRStNbcXZccXNXLBr55Dpz2RUwVzLtlrPVLOTmwc9O JTYO5JlumlbzUVivQqGlauVQBPQmkENIAGljV/VSXMzW3pjS2HvTtNlxSwnVsKKVeFfY VHE1lMB5NNAxqJa3oxlmSN/fYXLpyXeCTtjb5WPFY6CcakSNS8PwIfCFutTz5NWilk1V GuMORY7w/6cTzTHoPQnYrSgaGwxu8a0TRvo4fr5qhlT0rshAgkJwzIRA0EAHdE5UEvpB OV4edPzJeSxrAiF0+6teKeZ+pYqgHG03zZUBeUYVSEngfKvaAw8zQta/AyxumcMc3lkL RpYw== 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=ld57m95bHJQBRxDnF5FnlK1Sfbx3W7UXVC5v8g98wR4=; b=krizwEZJNDEFu0evJX6bqjVhtYx3L09DxPCQqE/YT/o713kksM4hMKjcnwHu0hPJ9M FRBYli+ieCNJICHbrX3PCGCZALhqLvd8dmHOz4ZdC5smAdctOddEcfR0RSqa5rP+TTn0 jOirKervrboE00UAzuiSeN4cSmwG/zTxOJVsWUoy4AgTG+yr21iXhget+O2MAyM8zcBs fIWeUMSXhsz4Ng3hMhN9zYiTDsrJYOJmKkcogAi+6jm9M+B/sR30uitZxYaMGyPT4ZF/ tOduRghtU1iU9u1GMSns9SBoen6aDd5WemfoOTm1i4kKa1x09THnwego/Oybj+FA6A9p JRhg== X-Gm-Message-State: APjAAAX7WsXoq29cnqUYKj9eskaMczQIR/6ycxIoZkqeDHEyh/YB/6LC VyAeKmus9Gtockx6pMo/P5abf92DoEbOC39/3gA= X-Received: by 2002:a63:d0a:: with SMTP id c10mr6760026pgl.203.1570685834587; Wed, 09 Oct 2019 22:37:14 -0700 (PDT) MIME-Version: 1.0 References: <20191009200523.8436-1-stuart.w.hayes@gmail.com> <20191009200523.8436-3-stuart.w.hayes@gmail.com> In-Reply-To: <20191009200523.8436-3-stuart.w.hayes@gmail.com> From: Andy Shevchenko Date: Thu, 10 Oct 2019 08:37:02 +0300 Message-ID: Subject: Re: [PATCH 2/3] PCI: pciehp: Wait for PDS if in-band presence is disabled To: Stuart Hayes Cc: Bjorn Helgaas , Austin Bolen , Keith Busch , Alexandru Gagniuc , "Rafael J . Wysocki" , Mika Westerberg , "Gustavo A . R . Silva" , Sinan Kaya , Oza Pawandeep , linux-pci@vger.kernel.org, Linux Kernel Mailing List , Lukas Wunner 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, Oct 9, 2019 at 11:05 PM Stuart Hayes wrote: > > From: Alexandru Gagniuc > > When inband presence is disabled, PDS may come up at any time, or not > at all. PDS being low may indicate that the card is still mating, and > we could expect contact bounce to bring down the link as well. > > It is reasonable to assume that most cards will mate in a hotplug slot > in about a second. Thus, when we know PDS only reflects out-of-band > presence, it's worthwhile to wait the extra second or so to make sure > the card is properly mated before loading the driver, and to prevent > the hotplug code from disabling a device if the presence detect change > goes active after the device is enabled. > +static void pcie_wait_for_presence(struct pci_dev *pdev) > +{ > + int timeout = 1250; > + bool pds; > + u16 slot_status; > + > + while (true) { > + pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); > + pds = !!(slot_status & PCI_EXP_SLTSTA_PDS); > + if (pds || timeout <= 0) > + break; > + msleep(10); > + timeout -= 10; > + } Can we avoid infinite loops? They are hard to parse (in most cases, and especially when it's a timeout loop) unsigned int retries = 125; // 1250 ms do { ... } while (--retries); > + > + if (!pds) > + pci_info(pdev, "Presence Detect state not set in 1250 msec\n"); > +} -- With Best Regards, Andy Shevchenko