Received: by 10.223.164.221 with SMTP id h29csp2323935wrb; Mon, 30 Oct 2017 01:49:28 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SnNgAM0H1yIqSSn3BRGxcCRAVKlgNLXdfQox/aEq9pgU9SNp7y0uL8GW3RVx4Ywxjj5dI0 X-Received: by 10.99.135.199 with SMTP id i190mr7248477pge.5.1509353368773; Mon, 30 Oct 2017 01:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509353368; cv=none; d=google.com; s=arc-20160816; b=ri9fVQxn9pE3mOJIVAhzxJ8Fpm+L9s8NsqDyHLlN/ZkS8k43NDwZTYT60ZaYHjsZHT CYK5UmeNXT3HH+vS0zks1zbYwXUTg5J8PP7O0W/zRFQhGrF9fw5HDaARGeTenzXVat1E cSf0N4QBAFC2BwzppuYrcYkdbSbK9UmROY2Tghrvj4IjuTd7e+okW+pc4C+LXtbcsrzY nS+3uUqzpCXqmN/au4j+Bq1ZqdkJ4GNtM/xNT3bWRwvC8uaYXA6RBHlOJdMreNFMjl+x k1SgjgXLuGMkRfV1WLRYUC7vkC5xK4g+Iw9Ag2+unBb7Vb9PqirsYJ3GzFZKRbyT76oq wqUQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature :arc-authentication-results; bh=eksemFisWhva+4vQPTwcSYqskxytIN5fN0/mcSBXNU0=; b=o9C6g+ZxeXJ+RC2CsdpSNTARk+9IOJq9MWCmhA0LiYg5JpQuOvQKyhRmxsF1U0j1Id pkcXglGaNx+MELMlMfVhBQdBZfejU1b7kuNBCVZlCcsycCuY6nmzlk4++AxtPdd7DbEN nrBDTbo40uLKzN3D19HyC7W40OurpKeUB8KooIvHAxVHeAo3aGhPjyDgJixm7y6EoiZD R5ZaaSi1qdCicMzKzJ4guYkn7b9+EMogyJ+EnsON8z9c58mPGlRqiHWcp5XcK5y9GX22 oI/mmQp86OWrbNL5v0+ur252MFmfa4Cnw3QqoSWpFrCFpZhvnNNqOmPwpq24m5FrGZ1i Mjvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=rRSERCN3; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s10si9543668pgd.559.2017.10.30.01.49.15; Mon, 30 Oct 2017 01:49:28 -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=@ti.com header.s=ti-com-17Q1 header.b=rRSERCN3; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752634AbdJ3IsX (ORCPT + 99 others); Mon, 30 Oct 2017 04:48:23 -0400 Received: from lelnx194.ext.ti.com ([198.47.27.80]:10243 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752266AbdJ3IsU (ORCPT ); Mon, 30 Oct 2017 04:48:20 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id v9U8mBMm004712; Mon, 30 Oct 2017 03:48:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1509353291; bh=rb6rt6biYqtUxSNLVNKoeplDppiS8P5GP7gk8pCR6pU=; h=Subject:From:To:CC:References:Date:In-Reply-To; b=rRSERCN3P8rIrxDCi1oZ/CnzbgCzFJ0C4ZE6hj13fRs0gP+w24/QAlYzPxJ6vrUMv mU9mgsfrv0kBiQBmh6O+WPFms4sZizNTMuAnCfT1qaMJMYScajBH1Ee9yn+AA6wzIP tWQkPp3EyjBavcIu7cFIUwhLUILETUJ1eBUveeE8= Received: from DLEE101.ent.ti.com (dlee101.ent.ti.com [157.170.170.31]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9U8mAMk027024; Mon, 30 Oct 2017 03:48:11 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE101.ent.ti.com (157.170.170.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.845.34; Mon, 30 Oct 2017 03:48:10 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.845.34 via Frontend Transport; Mon, 30 Oct 2017 03:48:10 -0500 Received: from [172.24.190.215] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id v9U8m7Im026748; Mon, 30 Oct 2017 03:48:08 -0500 Subject: Re: [PATCH v2] dwc: dra7xx: Print link state to console for debug From: Faiz Abbas To: David Laight , "kishon@ti.com" CC: "bhelgaas@google.com" , "linux-omap@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <1508417009-30869-1-git-send-email-faiz_abbas@ti.com> <9378c5c9-381d-4c40-3290-f7e3720792ba@ti.com> <063D6719AE5E284EB5DD2968C1650D6DD009C62B@AcuExch.aculab.com> <53ed97ab-ed02-23be-0ce9-e79f2aaac979@ti.com> Message-ID: Date: Mon, 30 Oct 2017 14:18:32 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <53ed97ab-ed02-23be-0ce9-e79f2aaac979@ti.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday 26 October 2017 01:29 PM, Faiz Abbas wrote: > David, > > On Thursday 19 October 2017 06:56 PM, David Laight wrote: >> From: Faiz Abbas >>> Sent: 19 October 2017 14:09 >>> On Thursday 19 October 2017 06:13 PM, Faiz Abbas wrote: >>>> Enable support for printing the LTSSM link state for debugging PCI >>>> when link is down. >>>> >>>> Signed-off-by: Faiz Abbas >>>> --- >>>> v2: >>>> 1. Changed dev_err() to dev_dbg() >>>> 2. Changed static char array to static const char * const >>>> 3. format changes >>>> >>>> drivers/pci/dwc/pci-dra7xx.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ >>>> 1 file changed, 48 insertions(+) >>>> >>>> diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c >>>> index 34427a6..0e70e77 100644 >>>> --- a/drivers/pci/dwc/pci-dra7xx.c >>>> +++ b/drivers/pci/dwc/pci-dra7xx.c >>>> @@ -98,6 +98,45 @@ struct dra7xx_pcie_of_data { >>>> >>>> #define to_dra7xx_pcie(x) dev_get_drvdata((x)->dev) >>>> >>>> +static const char * const state[] = { >>>> + "DETECT_QUIET", >> ... >>>> + "RCVRY_EQ3" >>>> +}; >>>> + >>>> static inline u32 dra7xx_pcie_readl(struct dra7xx_pcie *pcie, u32 offset) >>>> { >>>> return readl(pcie->base + offset); >>>> @@ -118,6 +157,15 @@ static int dra7xx_pcie_link_up(struct dw_pcie *pci) >>>> { >>>> struct dra7xx_pcie *dra7xx = to_dra7xx_pcie(pci); >>>> u32 reg = dra7xx_pcie_readl(dra7xx, PCIECTRL_DRA7XX_CONF_PHY_CS); >>>> + u32 cmd_reg; >>>> + u32 ltssm_state; >>>> + >>>> + if (!(reg & LINK_UP)) { >>>> + cmd_reg = dra7xx_pcie_readl(dra7xx, >>>> + PCIECTRL_DRA7XX_CONF_DEVICE_CMD); >>>> + ltssm_state = (cmd_reg & GENMASK(7, 2)) >> 2; >>>> + dev_dbg(pci->dev, "Link state:%s\n", state[ltssm_state]); >> >> Hmmm... GENMASK leaves by hunting header files...> Why not (cmd_reg >> 2) & 63 and explicitly define state[64] >> to guarantee that you never print anything worse than a NULL >> pointer. > > I'm not sure what you mean. Are you worried we might print something > outside the array bounds? How is this easier to decipher than GENMASK? > >> >>>> + } >>>> >>>> return !!(reg & LINK_UP); >>>> } >>>> >>> >>> I missed David's comment in v1. Will submit a new version. Please ignore. >> >> I've a 'neat' trick for generating strings that match constants. >> You can get the compiler to do all the work for you: >> (Assuming I've typed it correctly) >> >> #define LTSSM_DEFS(x) \ >> x(DETECT_QUIET) \ >> x(DETECT_ACT) \ >> (continue for all the names) >> >> Define an enum with the named constants: >> #define X(name) LTSSM_STATE_##name, >> enum (LTSSM_DEFS(X) LTSSM_STATE_SIZE=64); >> #undef X >> >> Array of strings: >> #define X(name) [LTSSM_STATE_##name] = #name >> static const char * const state_names[LTSSM_STATE_SIZE] = { LTSSM_DEFS(X) }; >> #undef X >> >> David >> > > So I implemented your idea and it looks like this: > http://pastebin.ubuntu.com/25821834/ > > I don't know how much we gained by adding the trick. I still had to be > careful not to be off by 1 when writing the list. Plus we are never > saying anything like printk("%s", state[LTSSM_STATE_DETECT_QUIET]. Its a > register read which is used to index the list array. > > Thanks, > Faiz > Gentle Ping. From 1582306206780171483@xxx Thu Oct 26 07:59:50 +0000 2017 X-GM-THRID: 1581691652519634530 X-Gmail-Labels: Inbox,Category Forums