Message ID | 20240223-opp_support-v7-6-10b4363d7e71@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-78537-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp632274dyb; Fri, 23 Feb 2024 06:51:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXFLI/PBCzDngscw/4OWn0voXwH1qM0y2uNldP02PoPTuME3cPGTfoQzu6aQFvOrjim6zYIGDhIh5XC5ADQvR2m6+wY8g== X-Google-Smtp-Source: AGHT+IFp4vGFXrgn4thWaIFvVx9/BM4vERrtASeaVgfLQuA/UwwVg1isFxdLfYpokxAa3HrOzAmR X-Received: by 2002:ac8:5e52:0:b0:42d:ad3f:6c3f with SMTP id i18-20020ac85e52000000b0042dad3f6c3fmr2825487qtx.49.1708699900310; Fri, 23 Feb 2024 06:51:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708699900; cv=pass; d=google.com; s=arc-20160816; b=mdy9RduHx5pVMxkJGbx4hPBx7WHcmmQDz+oSYxbwPJ9cK1KACLmbAalN6oN8h7H3rp fHEa6DxnN+VcniepKcHZWVm5DO6yTe+rNPAK7CcJ4hHu43p1z8Z88okWPqlAJmCr5TFu 8HjCTPNNssbOppvRaN8IQ6KFM4qjNqAxwETce/hyBl5Vx/Fi5C3DM3uGC/GZAclNt5Ul Mm9wvlbdGTx7AkjNXlFDU0PsjltD/2edRjiEbGe6BxkCwEcLDO6HjUX70bvdVkzQWY6O ZEi73iIOOOQX86IznjanC6Z/eXhr+dG9k7hKXJo692kE9KZvb8RoojXriG0IF8kTsNkb mSIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=wbeG60PGiWYs8AGZnrSHodCHU/ETFy6J6eK7ZeNFV5o=; fh=mLeyOiXXxJHJYs8dxImKbmNctx3gBpnhH0V2tKEUcOs=; b=OE3ElKGn1HbQ+KqR7HiKMyLffpdYkr6mXx6yb4pccuMP+yMomxoHc2jcxlPhr/bdHv FfJ6IUxFrqma2iDjJISLgxgDvgAaCXeeTYo4jim3yGNzaCP9thINKNaUOQRLofQ0uiLg Iz429kT4MEvrT9ijfY6EaeCJUuSZb0RKSj6gD3O/ecSPFTvghoUfghCZ9jm+m0Y/zc17 V7QTdGo9hJogTALt+Lfwz64sVvDzXfxJOsO7jUs9LVsYy2aYMleVO5kC1vv2itXZPGpM qID+U63B4HBc9WrpQVCdaDJLTWd/VsYSNdMQCw5ehnnFpyNrtA3N4dgW7jTHV9WCnjxT LTsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=UQhEbcjp; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-78537-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78537-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b12-20020ac8678c000000b0042dc30c48d6si14228760qtp.231.2024.02.23.06.51.40 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 06:51:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78537-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=UQhEbcjp; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-78537-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78537-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id ABA401C23021 for <ouuuleilei@gmail.com>; Fri, 23 Feb 2024 14:51:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68ABB126F18; Fri, 23 Feb 2024 14:49:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="UQhEbcjp" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CE7982880; Fri, 23 Feb 2024 14:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708699748; cv=none; b=GS4m+EkObpcDqDhvnDQjtXUmc2OLhosWdSidRoWmdn0zQYNdKml53aQjtLNbf0p9esx6NoXIEm/85iU9XM/fORMfiRrWihUUxydZ1uvHrWlnlyIUrCLH68JVJlmOT5cwbNS+k/L5oEaIG1ZF/2qbEOkW/EvDrbairmt6fR90L9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708699748; c=relaxed/simple; bh=dQL5VWWKTej0nc9NPBoJbDAFF6a/cDeRgspLAeElQQ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=gT8b/Bpxjnq2z5faJIWlhNuvXssH/dU2NwLUFUIquq8sIJ8ZE1QEHaaTppRzbJN5zX1PyFKvUibJ4gTpwUAIsX68ioiEfqrb+M0jNb8qS8F6Q1AhOkMWgEdlsKs7XfqEZl0IuTIDwyED8JrbWlyyFKjXhIEPz4Ox3jXfw7ms6CE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=UQhEbcjp; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41NCVG0w022251; Fri, 23 Feb 2024 14:49:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=wbeG60PGiWYs8AGZnrSHodCHU/ETFy6J6eK7ZeNFV5o =; b=UQhEbcjpZ6t7mIdL/wkGCOG2Sb+FhVBdvrYGWNMLxNkNS8SiwQFO2RtqyYa trPoG2jtAhlB1ESU4SPPgchGnhKY4klAiM6QuIUYUgqGOGVly/C2q9M/jTFnfqxl ZjjCI4cSgzXLp2NqWzFWr1cl82Tg8cuId/qt9nLdpaEB6PNOrcYm74IFE1f4a8Ud h/vFvTPxLq9PEwrpPsiTErR3bFcCNIxgT7UyNC77o1cetvsVPG8FVuH8AZYR1ffe IGeEGOu5S/AS1BsMpmBh55kHUcw0OBf7x/Ba+n7FtghPQwUCctdejxd1odh+F5N0 xrNRTk4GyQtxzhRwLNGuG9VZBsw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3we3233efh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 14:48:59 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41NEmwZ3028071 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 14:48:58 GMT Received: from hu-krichai-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 23 Feb 2024 06:48:52 -0800 From: Krishna chaitanya chundru <quic_krichai@quicinc.com> Date: Fri, 23 Feb 2024 20:18:03 +0530 Subject: [PATCH v7 6/7] PCI: Bring out the pcie link speed to MBps logic to new function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20240223-opp_support-v7-6-10b4363d7e71@quicinc.com> References: <20240223-opp_support-v7-0-10b4363d7e71@quicinc.com> In-Reply-To: <20240223-opp_support-v7-0-10b4363d7e71@quicinc.com> To: Bjorn Andersson <andersson@kernel.org>, Konrad Dybcio <konrad.dybcio@linaro.org>, Lorenzo Pieralisi <lpieralisi@kernel.org>, =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= <kw@linux.com>, Rob Herring <robh@kernel.org>, Bjorn Helgaas <bhelgaas@google.com>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org>, Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>, Rob Herring <robh+dt@kernel.org>, Johan Hovold <johan+linaro@kernel.org>, Brian Masney <bmasney@redhat.com>, Georgi Djakov <djakov@kernel.org> CC: <linux-arm-msm@vger.kernel.org>, <linux-pci@vger.kernel.org>, <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <vireshk@kernel.org>, <quic_vbadigan@quicinc.com>, <quic_skananth@quicinc.com>, <quic_nitegupt@quicinc.com>, <quic_parass@quicinc.com>, Krishna chaitanya chundru <quic_krichai@quicinc.com> X-Mailer: b4 0.13-dev-83828 X-Developer-Signature: v=1; a=ed25519-sha256; t=1708699693; l=2094; i=quic_krichai@quicinc.com; s=20230907; h=from:subject:message-id; bh=dQL5VWWKTej0nc9NPBoJbDAFF6a/cDeRgspLAeElQQ0=; b=JVb3rvUorTHlakJa3kbwbub8f7OcM5C6LhYiHKop7CjTCOXvy8hGD62q+yyZ3Xh7xDBlAIAlH omKcGgReDwSDkC1lQ8oOojCQeWSjmDUpvPv5VxXZkVhB8bYoFBAwWZl X-Developer-Key: i=quic_krichai@quicinc.com; a=ed25519; pk=10CL2pdAKFyzyOHbfSWHCD0X0my7CXxj8gJScmn1FAg= X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: JI6s7wAKXxqIiw1x-KOalk3oOZE_eIdL X-Proofpoint-GUID: JI6s7wAKXxqIiw1x-KOalk3oOZE_eIdL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-22_15,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 clxscore=1015 suspectscore=0 malwarescore=0 mlxlogscore=955 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402230108 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791701706522489847 X-GMAIL-MSGID: 1791701706522489847 |
Series |
PCI: qcom: Add support for OPP
|
|
Commit Message
Krishna chaitanya chundru
Feb. 23, 2024, 2:48 p.m. UTC
Bring the switch case in pcie_link_speed_mbps to new function to
the header file so that it can be used in other places like
in controller driver.
Create a new macro to convert from MBps to frequency.
Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
drivers/pci/pci.c | 19 +------------------
drivers/pci/pci.h | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 18 deletions(-)
Comments
Mention the new interface name in the subject and in the commit log. s/pcie/PCIe/ The subject says "to MBps", but the commit log says "to frequency". On Fri, Feb 23, 2024 at 08:18:03PM +0530, Krishna chaitanya chundru wrote: > Bring the switch case in pcie_link_speed_mbps to new function to > the header file so that it can be used in other places like > in controller driver. s/pcie_link_speed_mbps/pcie_link_speed_mbps()/ to identify it as a function. > Create a new macro to convert from MBps to frequency. Include the new macro name here. I think pcie_link_speed_mbps() returns Mb/s (mega*bits* per second), not MB/s (mega*bytes* per second). > Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> > --- > drivers/pci/pci.c | 19 +------------------ > drivers/pci/pci.h | 24 ++++++++++++++++++++++++ > 2 files changed, 25 insertions(+), 18 deletions(-) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index d8f11a078924..b441ab862a8d 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -6309,24 +6309,7 @@ int pcie_link_speed_mbps(struct pci_dev *pdev) > if (err) > return err; > > - switch (to_pcie_link_speed(lnksta)) { > - case PCIE_SPEED_2_5GT: > - return 2500; > - case PCIE_SPEED_5_0GT: > - return 5000; > - case PCIE_SPEED_8_0GT: > - return 8000; > - case PCIE_SPEED_16_0GT: > - return 16000; > - case PCIE_SPEED_32_0GT: > - return 32000; > - case PCIE_SPEED_64_0GT: > - return 64000; > - default: > - break; > - } > - > - return -EINVAL; > + return pcie_link_speed_to_mbps(to_pcie_link_speed(lnksta)); > } > EXPORT_SYMBOL(pcie_link_speed_mbps); > > diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h > index 2336a8d1edab..82e715ebe383 100644 > --- a/drivers/pci/pci.h > +++ b/drivers/pci/pci.h > @@ -282,6 +282,30 @@ void pci_bus_put(struct pci_bus *bus); > (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \ > 0) > > +static inline int pcie_link_speed_to_mbps(enum pci_bus_speed speed) > +{ > + switch (speed) { > + case PCIE_SPEED_2_5GT: > + return 2500; > + case PCIE_SPEED_5_0GT: > + return 5000; > + case PCIE_SPEED_8_0GT: > + return 8000; > + case PCIE_SPEED_16_0GT: > + return 16000; > + case PCIE_SPEED_32_0GT: > + return 32000; > + case PCIE_SPEED_64_0GT: > + return 64000; > + default: > + break; > + } > + > + return -EINVAL; > +} > + > +#define PCIE_MBS2FREQ(speed) (pcie_link_speed_to_mbps(speed) * 1000) I feel like I might have asked some of this before; if so, my apologies and maybe a comment would be useful here to save answering again. The MBS2FREQ name suggests that "speed" is Mb/s, but it's not; it's an enum pci_bus_speed just like PCIE_SPEED2MBS_ENC() takes. When PCI SIG defines a new data rate, PCIE_MBS2FREQ() will do something completely wrong when pcie_link_speed_to_mbps() returns -EINVAL. I think it would be better to do this in a way that we can warn about the unknown speed and fall back to some reasonable default instead of whatever (-EINVAL * 1000) works out to. PCIE_MBS2FREQ() looks an awful lot like PCIE_SPEED2MBS_ENC(), except that it doesn't adjust for the encoding overhead and it multiplies by 1000. I don't know what that result means. The name suggests a frequency? pcie_link_speed_to_mbps(PCIE_SPEED_2_5GT) == 2500 Mbit/s (raw data rate) PCIE_SPEED2MBS_ENC(PCIE_SPEED_2_5GT) == 2000 Mbit/s or 2 Gbit/s (effective data rate) PCIE_MBS2FREQ(PCIE_SPEED_2_5GT) == 2500000 (? 2.5M of something) I don't really know how OPP works, but it looks like maybe PCIE_MBS2FREQ() is a shim that depends on how the OPP tables in DT are encoded? I'm surprised that the DT OPP tables aren't encoded with either the raw data rate or the effective data rate directly instead of what looks like the raw data rate / 1000. Is this a standard OPP encoding that will apply to other drivers? If so, it would be helpful to point to where that encoding is defined. If not, PCIE_MBS2FREQ() should probably be defined in pcie-qcom.c. Bjorn
On 2/28/2024 5:55 AM, Bjorn Helgaas wrote: > Mention the new interface name in the subject and in the commit log. > > s/pcie/PCIe/ > > The subject says "to MBps", but the commit log says "to frequency". > > On Fri, Feb 23, 2024 at 08:18:03PM +0530, Krishna chaitanya chundru wrote: >> Bring the switch case in pcie_link_speed_mbps to new function to >> the header file so that it can be used in other places like >> in controller driver. > > s/pcie_link_speed_mbps/pcie_link_speed_mbps()/ to identify it as a > function. > >> Create a new macro to convert from MBps to frequency. > > Include the new macro name here. > > I think pcie_link_speed_mbps() returns Mb/s (mega*bits* per second), > not MB/s (mega*bytes* per second). > >> Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> >> --- >> drivers/pci/pci.c | 19 +------------------ >> drivers/pci/pci.h | 24 ++++++++++++++++++++++++ >> 2 files changed, 25 insertions(+), 18 deletions(-) >> >> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c >> index d8f11a078924..b441ab862a8d 100644 >> --- a/drivers/pci/pci.c >> +++ b/drivers/pci/pci.c >> @@ -6309,24 +6309,7 @@ int pcie_link_speed_mbps(struct pci_dev *pdev) >> if (err) >> return err; >> >> - switch (to_pcie_link_speed(lnksta)) { >> - case PCIE_SPEED_2_5GT: >> - return 2500; >> - case PCIE_SPEED_5_0GT: >> - return 5000; >> - case PCIE_SPEED_8_0GT: >> - return 8000; >> - case PCIE_SPEED_16_0GT: >> - return 16000; >> - case PCIE_SPEED_32_0GT: >> - return 32000; >> - case PCIE_SPEED_64_0GT: >> - return 64000; >> - default: >> - break; >> - } >> - >> - return -EINVAL; >> + return pcie_link_speed_to_mbps(to_pcie_link_speed(lnksta)); >> } >> EXPORT_SYMBOL(pcie_link_speed_mbps); >> >> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h >> index 2336a8d1edab..82e715ebe383 100644 >> --- a/drivers/pci/pci.h >> +++ b/drivers/pci/pci.h >> @@ -282,6 +282,30 @@ void pci_bus_put(struct pci_bus *bus); >> (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \ >> 0) >> >> +static inline int pcie_link_speed_to_mbps(enum pci_bus_speed speed) >> +{ >> + switch (speed) { >> + case PCIE_SPEED_2_5GT: >> + return 2500; >> + case PCIE_SPEED_5_0GT: >> + return 5000; >> + case PCIE_SPEED_8_0GT: >> + return 8000; >> + case PCIE_SPEED_16_0GT: >> + return 16000; >> + case PCIE_SPEED_32_0GT: >> + return 32000; >> + case PCIE_SPEED_64_0GT: >> + return 64000; >> + default: >> + break; >> + } >> + >> + return -EINVAL; >> +} >> + >> +#define PCIE_MBS2FREQ(speed) (pcie_link_speed_to_mbps(speed) * 1000) > > I feel like I might have asked some of this before; if so, my > apologies and maybe a comment would be useful here to save answering > again. > > The MBS2FREQ name suggests that "speed" is Mb/s, but it's not; it's an > enum pci_bus_speed just like PCIE_SPEED2MBS_ENC() takes. > > When PCI SIG defines a new data rate, PCIE_MBS2FREQ() will do > something completely wrong when pcie_link_speed_to_mbps() returns > -EINVAL. I think it would be better to do this in a way that we can > warn about the unknown speed and fall back to some reasonable default > instead of whatever (-EINVAL * 1000) works out to. > As commented below I will move PCIE_MBS2FREQ to qcom driver and I will take care about -EINVAL in the qcom driver itself. > PCIE_MBS2FREQ() looks an awful lot like PCIE_SPEED2MBS_ENC(), except > that it doesn't adjust for the encoding overhead and it multiplies by > 1000. I don't know what that result means. The name suggests a > frequency? > > pcie_link_speed_to_mbps(PCIE_SPEED_2_5GT) == 2500 Mbit/s (raw data rate) > PCIE_SPEED2MBS_ENC(PCIE_SPEED_2_5GT) == 2000 Mbit/s or 2 Gbit/s (effective data rate) > PCIE_MBS2FREQ(PCIE_SPEED_2_5GT) == 2500000 (? 2.5M of something) > > I don't really know how OPP works, but it looks like maybe > PCIE_MBS2FREQ() is a shim that depends on how the OPP tables in DT are > encoded? I'm surprised that the DT OPP tables aren't encoded with > either the raw data rate or the effective data rate directly instead > of what looks like the raw data rate / 1000. > > Is this a standard OPP encoding that will apply to other drivers? If > so, it would be helpful to point to where that encoding is defined. > If not, PCIE_MBS2FREQ() should probably be defined in pcie-qcom.c. > It depends on how driver use OPP, I think as you suggested PCIE_MBS2FREQ should belong to pcie-qcom.c as no other driver is using it for now. I will move to pcie_qcom.c in my next series. - Krishna Chaitanya. > Bjorn >
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index d8f11a078924..b441ab862a8d 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6309,24 +6309,7 @@ int pcie_link_speed_mbps(struct pci_dev *pdev) if (err) return err; - switch (to_pcie_link_speed(lnksta)) { - case PCIE_SPEED_2_5GT: - return 2500; - case PCIE_SPEED_5_0GT: - return 5000; - case PCIE_SPEED_8_0GT: - return 8000; - case PCIE_SPEED_16_0GT: - return 16000; - case PCIE_SPEED_32_0GT: - return 32000; - case PCIE_SPEED_64_0GT: - return 64000; - default: - break; - } - - return -EINVAL; + return pcie_link_speed_to_mbps(to_pcie_link_speed(lnksta)); } EXPORT_SYMBOL(pcie_link_speed_mbps); diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 2336a8d1edab..82e715ebe383 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -282,6 +282,30 @@ void pci_bus_put(struct pci_bus *bus); (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \ 0) +static inline int pcie_link_speed_to_mbps(enum pci_bus_speed speed) +{ + switch (speed) { + case PCIE_SPEED_2_5GT: + return 2500; + case PCIE_SPEED_5_0GT: + return 5000; + case PCIE_SPEED_8_0GT: + return 8000; + case PCIE_SPEED_16_0GT: + return 16000; + case PCIE_SPEED_32_0GT: + return 32000; + case PCIE_SPEED_64_0GT: + return 64000; + default: + break; + } + + return -EINVAL; +} + +#define PCIE_MBS2FREQ(speed) (pcie_link_speed_to_mbps(speed) * 1000) + const char *pci_speed_string(enum pci_bus_speed speed); enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev); enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);