From patchwork Mon Feb 17 06:34:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Chaitanya Chundru X-Patchwork-Id: 866231 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 786A718F2C3 for ; Mon, 17 Feb 2025 06:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774071; cv=none; b=S3zAmmuspDQ7MscIrfDkPAveYk3vWai887HreFjxpUYdjy9myM9QfNHnJg93vGilMzY4/bNaPArvhjNps7YQbJdPNwU1zHBOtdpVRaVmMrepoyi+VAzrrXTSMVxXSyEzUFykfpdfllrjVVjqipqTFnLNaisGt2Jv81mhjYXBtQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774071; c=relaxed/simple; bh=UOzsnW0yk1kCZhcOHUKzAXiM1zBrG/5KAYYsM43pKTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j1GkpKc+qd0E63rP7KE81n51QqKFUt0rILhVQyRgXsAn/FARSy56jouJRYq7VdodTjgG/mx7fSGDuhmYnNsjJVWvgu3PqRWFckwqvHbpc4hYeXOAfsMkDzorHN3Gt6MNiDzMjxuHuilyPxPh1hcpazOdoR6DmQcqCcCAge5zaHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=KSKAXbxI; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="KSKAXbxI" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51H037X3003819 for ; Mon, 17 Feb 2025 06:34:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= RfJAtknnM5Ix1H9l/tiQteK3hWDYQBja8j0ciMMbYFw=; b=KSKAXbxIm4a6mDsk OJLRGFuMB+06LODX2+xrvDCLH7scwZEMQTDuz0wfRLxCPcY2QI8XiDl1nNDRSb0T bzxvI/YD9ojp8KhC7Cz4o6QOtfwKoOgv6qv0Rlu3tE6uGEHDXlScsZVxu46tRXNb rr2QHxm/HURXIEQcGxqRSDYcOo7C6/jxQ5+58/+mxVKTY3ACga+pEexjSZEF1tu5 YsQbjVmyxzGVdqDUNw1MM3tbHUdyRSyAhoniJbOzjsU5lRbqKkYK8cf2iUEFQJbG nUAL4JU2dsox7nTTNEBKMmDjT3R8+S5c+MM4FmTpvkFC38tq2pHRzOtgk5ZIfSPD wEUAAg== Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44ut7s0pjr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 17 Feb 2025 06:34:29 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-220d8aa893dso56883255ad.3 for ; Sun, 16 Feb 2025 22:34:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739774068; x=1740378868; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RfJAtknnM5Ix1H9l/tiQteK3hWDYQBja8j0ciMMbYFw=; b=ETEIi8sI6da7Ie1M6xV3QyJShQaEqdHoC2RBpwpadNUuYHkOLKWH0nqMdor+40E3Dx GazvMqIPG92vuCCYVTNqkdtuO703E7lMGU2y6MGj9xwR95OqcrCs3igY1y6Zxew4Zz1p KRNLAeR8XwYRhJpKWt8jMCC6gOXilGLyi8jb609CVodWRfwouPozK2rrpxkOHAfyN1Gc evgqUOI8rtJcnSF1FIlaPyJwrkDz6x9tDAwbNpjd5PjkQZEDVxzSTFvferBhuBdhDW07 k1D0AX44yJ5+RkWYD5+u8SYVrHSAkhH2um38u/YulFJ7NthzVwJP7zPCVo84ZQYToXay NggQ== X-Forwarded-Encrypted: i=1; AJvYcCXvVZk+BpFXxtR9K8u3qXdfofi8A7xuo9g2qnoSznC3OXUncedSUsN3vVXfnAnZsZcn8vsT5oar8AfHDmp4@vger.kernel.org X-Gm-Message-State: AOJu0YxIZmljfq7GdRBuiNsubx6w4nedMDkCsCyEIN7amFqIolPg5TaL YrmgjfDlcnMIkdiIX5Qf38QxJAPc75xEOKP0CVgbu59KaoOE4aWJGcKRggGfDw7gV4nZ4VX0roE JlHs2Jtn6av2B2jHejfrLblYnbUO4txpeBMMRlud/FfxHKsWX/1LyIbuaYGZy7xRW X-Gm-Gg: ASbGncvWSgsdYejhl9OTDwvudEaPsxTLvqmQI40MMCyTjhKWvAw5pfy7Mm+7dCPZ1mI Cw6QfHmYJtY75B5FMaDzp9871onykFol5QgevnN2efZ0nJfp/eca5HZvBpMC0N8rG5f0bcEAATk uoSTaasmcDOIjz3ux34MPFNCfWki/DoEGNsA0fNK5ZG4jbBZtx3zd0R8pQ0nO/Y5E5lk6GJeV/i gxlzYKdKctxU/LUVaO4qUPXNjS8Mb6DBJ814TXIZol2v9+qja+iXb7cW64N9j6Zch008fYlgN5n uUYZxFH5cdF6QjQQI63b/EJ3HHzOH2S+cVvAfz1v X-Received: by 2002:a05:6a21:2d87:b0:1ee:43c3:9bfa with SMTP id adf61e73a8af0-1ee8cc16ab5mr16622899637.35.1739774068511; Sun, 16 Feb 2025 22:34:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZ7gToBq7D4VtpV2EASi1+JDe5Y5Jkt/4aGWzWeA8pKMBeCH8FZhkAAVk6ksqeb0q+oCvNuA== X-Received: by 2002:a05:6a21:2d87:b0:1ee:43c3:9bfa with SMTP id adf61e73a8af0-1ee8cc16ab5mr16622835637.35.1739774067507; Sun, 16 Feb 2025 22:34:27 -0800 (PST) Received: from hu-krichai-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73263b79287sm3771800b3a.29.2025.02.16.22.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2025 22:34:27 -0800 (PST) From: Krishna Chaitanya Chundru Date: Mon, 17 Feb 2025 12:04:09 +0530 Subject: [PATCH 2/8] PCI/bwctrl: Add support to scale bandwidth before & after link re-training Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-mhi_bw_up-v1-2-9bad1e42bdb1@oss.qualcomm.com> References: <20250217-mhi_bw_up-v1-0-9bad1e42bdb1@oss.qualcomm.com> In-Reply-To: <20250217-mhi_bw_up-v1-0-9bad1e42bdb1@oss.qualcomm.com> To: Bjorn Helgaas , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Jingoo Han , Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Johannes Berg , Jeff Johnson Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, mhi@lists.linux.dev, linux-wireless@vger.kernel.org, ath11k@lists.infradead.org, quic_jjohnson@quicinc.com, quic_pyarlaga@quicinc.com, quic_vbadigan@quicinc.com, quic_vpernami@quicinc.com, quic_mrana@quicinc.com, Krishna Chaitanya Chundru X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1739774050; l=3068; i=krishna.chundru@oss.qualcomm.com; s=20230907; h=from:subject:message-id; bh=UOzsnW0yk1kCZhcOHUKzAXiM1zBrG/5KAYYsM43pKTM=; b=xi2H5j+IGrnLH2KW01vOyRK0v1mmhX6st6biV7Tank1/vHMoUUt8rpVtOT60WK8uXuBhj8yK3 8x2ATQZIgedBNLlXYuqyCQVT/znFmyy+9q/E+GmWNi3TPK/ehbPnrMA X-Developer-Key: i=krishna.chundru@oss.qualcomm.com; a=ed25519; pk=10CL2pdAKFyzyOHbfSWHCD0X0my7CXxj8gJScmn1FAg= X-Proofpoint-GUID: ywJ-4szzEs_hKGp0lDs3hN59_ep3Z0Iv X-Proofpoint-ORIG-GUID: ywJ-4szzEs_hKGp0lDs3hN59_ep3Z0Iv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-17_03,2025-02-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502170056 If the driver wants to move to higher data rate/speed than the current data rate then the controller driver may need to change certain votes so that link may come up at requested data rate/speed like QCOM PCIe controllers need to change their RPMh (Resource Power Manager-hardened) state. Once link retraining is done controller drivers needs to adjust their votes based on the final data rate. Some controllers also may need to update their bandwidth voting like ICC bw votings etc. So, add pre_scale_bus_bw() & post_scale_bus_bw() op to call before & after the link re-train. In case of PCIe switch, if there is a request to change target speed for a downstream port then no need to call these function ops as these are outside the scope of the controller drivers. Signed-off-by: Krishna Chaitanya Chundru --- drivers/pci/pcie/bwctrl.c | 15 +++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/drivers/pci/pcie/bwctrl.c b/drivers/pci/pcie/bwctrl.c index 0a5e7efbce2c..e3faa4d1f935 100644 --- a/drivers/pci/pcie/bwctrl.c +++ b/drivers/pci/pcie/bwctrl.c @@ -161,6 +161,8 @@ static int pcie_bwctrl_change_speed(struct pci_dev *port, u16 target_speed, bool int pcie_set_target_speed(struct pci_dev *port, enum pci_bus_speed speed_req, bool use_lt) { + struct pci_host_bridge *host = pci_find_host_bridge(port->bus); + bool is_root = pci_is_root_bus(port->bus); struct pci_bus *bus = port->subordinate; u16 target_speed; int ret; @@ -173,6 +175,16 @@ int pcie_set_target_speed(struct pci_dev *port, enum pci_bus_speed speed_req, target_speed = pcie_bwctrl_select_speed(port, speed_req); + /* + * The controller driver may need to be scaled for targeted speed + * otherwise link might not come up at requested speed. + */ + if (is_root && host->ops->pre_scale_bus_bw) { + ret = host->ops->pre_scale_bus_bw(host->bus, target_speed); + if (ret) + return ret; + } + scoped_guard(rwsem_read, &pcie_bwctrl_setspeed_rwsem) { struct pcie_bwctrl_data *data = port->link_bwctrl; @@ -197,6 +209,9 @@ int pcie_set_target_speed(struct pci_dev *port, enum pci_bus_speed speed_req, !list_empty(&bus->devices)) ret = -EAGAIN; + if (is_root && host->ops->post_scale_bus_bw) + host->ops->post_scale_bus_bw(host->bus, pci_bus_speed2lnkctl2(bus->cur_bus_speed)); + return ret; } diff --git a/include/linux/pci.h b/include/linux/pci.h index 47b31ad724fa..58f1de626c37 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -804,6 +804,8 @@ struct pci_ops { void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where); int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val); int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val); + int (*pre_scale_bus_bw)(struct pci_bus *bus, int target_speed); + void (*post_scale_bus_bw)(struct pci_bus *bus, int current_speed); }; /* From patchwork Mon Feb 17 06:34:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Chaitanya Chundru X-Patchwork-Id: 866230 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 EF77E19E82A for ; Mon, 17 Feb 2025 06:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774082; cv=none; b=e7qGzsfsGxv7qkozsMpI3kJW68HAuS+jLFcavYlCxuB5K5aTCnVGxy0uy9WRRnL9EJKzWuPuhOUid6fId4wIZIht6x2kT85gvU0CvsWdboEmDoVd++WCfoWk5sO6LwXgS2t3XUp7/i8YNXHBJ/1AmsoXEyYorbNRKKueLxdeI2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774082; c=relaxed/simple; bh=0G/XG/YxFU6rag6WMJ+nAr2rfc55DQyaEL7pfp0M3cA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BBX0QWGWdk7HQjG/kk+9k34f/v52HmCtM+HHvwIqVmXDJEW23q5COwzwkB/8QVj5klrrvA9UnXW+IXI/5/2rd4daZ4eCxh/CbH4rx3iiZWHmTjGP6BliZvs7kGTkkslkQz9pAmYa7hqHRc+j5blCKOrcYpeG2vCm1I/amSQy9DU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=ZPunaYbj; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="ZPunaYbj" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51H0378x003821 for ; Mon, 17 Feb 2025 06:34:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= q1NDvwgjsJKCHcz2zk+2Dmi/QW8Mawbbd+wgtBUmftM=; b=ZPunaYbj4TIqMFz0 T3LRCGPJk17W1qhvXE63JJeWaIgGUAdJhkRTqmXbjhVx4RZ9SQNEFoEYFG8PtH1P 28slha4pYfrQeOKWOd2t6eu23DpA2pXW196TmKNY6h6kkjH8ZRgF9fNi6TQNjR7h 96DHuKFGpqbuowOW9gyH5odARl1rpmFwXTuELIIZ6eKiM9JpPPWXfFL5/nvnfyIu wxxnm9W3JSPCZ+INrVGKcQNmZ6C22prHhLCkJdtAnZ9agXca9nXFD33NymbiP+7c voMmrf6SUvIzuey3sNHDqN2bufJAUCihixw83cHFGRbPOWXKPlH7YU/3ksT9qZrM YAmWqw== Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44ut7s0pkf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 17 Feb 2025 06:34:40 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2fc404aaed5so5983241a91.3 for ; Sun, 16 Feb 2025 22:34:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739774079; x=1740378879; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q1NDvwgjsJKCHcz2zk+2Dmi/QW8Mawbbd+wgtBUmftM=; b=cH/X/3r05DCev836eYhSHks0mdwoe/w0ngSr68b//FOxSRRjVBHw3gHHAor37h9hLk QygJ4Z/8JiyNBtnNq11KmSTdb1HNJ5RHcQHSsQQ3YstCipCc+dTzHM1Yc2Lb9LVPpP1O 2B8+7WNK2UxYzWL6c8EPIGMFQ3ba94YTqaY+Uy8bp+FzM6ADTpP05MAM80NoJhEjBms3 12d8kmGb90FILXF5cyzb0IInoeMuSeueqBa0tynordtzWbcWe9nyZyIsMyNTi/b5etdV 16VgPKKDddF+DFTZMOhosXH9HTfain77NKwuCBvWZT+GCkvxtUZAaNjX3EuWGbWzquXi fJ4w== X-Forwarded-Encrypted: i=1; AJvYcCVR6qtcZ23yuvf/HK2TDSk2/9z92TCUP1j1x2Vi3yZm0GlMJEZgNPuXHuO6sLGx0ak/j0P2qgIjV9n2j9e6@vger.kernel.org X-Gm-Message-State: AOJu0Yz0GN1mR3rSa7ja1jAC+19DnBBZEBWNsp4wiom80SycoScbR7IG BPRcMy15VrinpBcLO7Vmh3S4voPwystQRxgTTdcKQzzaZ5WlcHeNxe/riErxC4NS9bGj1H44bto Gno9o5elJCAwrCzLb+39gwiMlSaBKpDBBeqtdYau8SpZcaBJNydtV1OPMNyANVv+O X-Gm-Gg: ASbGncsirM4EOm1PTxsytHqXCQhNYiOqvCb1OP4skA/HV0YQLip0t/xzHxtv74TEteN cemz232Wu8tf6SYKCdihKeI0YdTN9Nyb4BK+SmAR8egI+fw45HX8kuSXKG/anC+qluzKiSxzkLf NW1qNo8D4OXjIkeUg8L78J5MssSYkEt0LSQX7kAvCn28y2jxKrcp06sY7Gj1CyqNC5UCxCR0j6e Fg+35QB45ZFLtm5UrYGOBABqV6TWlGFNiC5pKdSUCTOuSgB24NrVG609aFtkqLctKVznVa+hoJt WZloPRS8fYSchq9BgI4mlV2gMyu7D3Ey8oaqkHVL X-Received: by 2002:a05:6a00:2447:b0:732:7fc1:92b with SMTP id d2e1a72fcca58-7327fc109efmr3075245b3a.14.1739774079202; Sun, 16 Feb 2025 22:34:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHo0N15+Zd6Zvn9MgmFe3O8zvUpQANFOb3oxcmBBPbKXDnoGvy/IogEzYji+ZVTk5wsJ02f0w== X-Received: by 2002:a05:6a00:2447:b0:732:7fc1:92b with SMTP id d2e1a72fcca58-7327fc109efmr3075222b3a.14.1739774078806; Sun, 16 Feb 2025 22:34:38 -0800 (PST) Received: from hu-krichai-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73263b79287sm3771800b3a.29.2025.02.16.22.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2025 22:34:38 -0800 (PST) From: Krishna Chaitanya Chundru Date: Mon, 17 Feb 2025 12:04:11 +0530 Subject: [PATCH 4/8] PCI: dwc: qcom: Update ICC & OPP votes based upon the requested speed Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-mhi_bw_up-v1-4-9bad1e42bdb1@oss.qualcomm.com> References: <20250217-mhi_bw_up-v1-0-9bad1e42bdb1@oss.qualcomm.com> In-Reply-To: <20250217-mhi_bw_up-v1-0-9bad1e42bdb1@oss.qualcomm.com> To: Bjorn Helgaas , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Jingoo Han , Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Johannes Berg , Jeff Johnson Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, mhi@lists.linux.dev, linux-wireless@vger.kernel.org, ath11k@lists.infradead.org, quic_jjohnson@quicinc.com, quic_pyarlaga@quicinc.com, quic_vbadigan@quicinc.com, quic_vpernami@quicinc.com, quic_mrana@quicinc.com, Krishna Chaitanya Chundru X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1739774050; l=4852; i=krishna.chundru@oss.qualcomm.com; s=20230907; h=from:subject:message-id; bh=0G/XG/YxFU6rag6WMJ+nAr2rfc55DQyaEL7pfp0M3cA=; b=Hv/Cj81cpzxIilICVPcYYxPIKptPd12BGfcSJ+l3Y8rH9BsZmDsiq3nLW5/vP+pOP5tdLvy7T nSrKxG7A+K/Bkp3+j4W6kGPcRka5O/GhV7R4Fhb2BVuY4JowhVuxifs X-Developer-Key: i=krishna.chundru@oss.qualcomm.com; a=ed25519; pk=10CL2pdAKFyzyOHbfSWHCD0X0my7CXxj8gJScmn1FAg= X-Proofpoint-GUID: WaqyYtBxFky7T1r0kj14clQZngNXMpdD X-Proofpoint-ORIG-GUID: WaqyYtBxFky7T1r0kj14clQZngNXMpdD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-17_03,2025-02-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502170056 QCOM PCIe controllers needs to disable ASPM before initiating link re-train. So as part of pre_bw_scale() disable ASPM and as part of post_scale_bus_bw() enable ASPM back. Update ICC & OPP votes based on the requested speed so that RPMh votes gets updated based on the speed. Bring out the core logic from qcom_pcie_icc_opp_update() to new function qcom_pcie_set_icc_opp(). Signed-off-by: Krishna Chaitanya Chundru --- drivers/pci/controller/dwc/pcie-qcom.c | 105 +++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 26 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index e4d3366ead1f..a39d4c5d7992 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -1294,10 +1294,88 @@ static void qcom_pcie_host_post_init(struct dw_pcie_rp *pp) pcie->cfg->ops->host_post_init(pcie); } +static int qcom_pcie_set_icc_opp(struct qcom_pcie *pcie, int speed, int width) +{ + struct dw_pcie *pci = pcie->pci; + unsigned long freq_kbps; + struct dev_pm_opp *opp; + int ret, freq_mbps; + + if (pcie->icc_mem) { + ret = icc_set_bw(pcie->icc_mem, 0, + width * QCOM_PCIE_LINK_SPEED_TO_BW(speed)); + if (ret) { + dev_err(pci->dev, "Failed to set bandwidth for PCIe-MEM interconnect path: %d\n", + ret); + } + } else if (pcie->use_pm_opp) { + freq_mbps = pcie_dev_speed_mbps(pcie_link_speed[speed]); + if (freq_mbps < 0) + return -EINVAL; + + freq_kbps = freq_mbps * KILO; + opp = dev_pm_opp_find_freq_exact(pci->dev, freq_kbps * width, + true); + if (!IS_ERR(opp)) { + ret = dev_pm_opp_set_opp(pci->dev, opp); + if (ret) + dev_err(pci->dev, "Failed to set OPP for freq (%lu): %d\n", + freq_kbps * width, ret); + dev_pm_opp_put(opp); + } + } + + return ret; +} + +static int qcom_pcie_scale_bw(struct dw_pcie_rp *pp, int speed) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct qcom_pcie *pcie = to_qcom_pcie(pci); + u32 offset, status, width; + + offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + status = readw(pci->dbi_base + offset + PCI_EXP_LNKSTA); + + width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status); + + return qcom_pcie_set_icc_opp(pcie, speed, width); +} + +static int qcom_pcie_enable_disable_aspm(struct pci_dev *pdev, void *userdata) +{ + bool *enable = userdata; + + if (*enable) + pci_enable_link_state_locked(pdev, PCIE_LINK_STATE_ALL); + else + pci_disable_link_state_locked(pdev, PCIE_LINK_STATE_ALL); + + return 0; +} + +static void qcom_pcie_host_post_scale_bus_bw(struct dw_pcie_rp *pp, int current_speed) +{ + bool enable = true; + + pci_walk_bus(pp->bridge->bus, qcom_pcie_enable_disable_aspm, &enable); + qcom_pcie_scale_bw(pp, current_speed); +} + +static int qcom_pcie_host_pre_scale_bus_bw(struct dw_pcie_rp *pp, int target_speed) +{ + bool enable = false; + + pci_walk_bus(pp->bridge->bus, qcom_pcie_enable_disable_aspm, &enable); + return qcom_pcie_scale_bw(pp, target_speed); +} + static const struct dw_pcie_host_ops qcom_pcie_dw_ops = { .init = qcom_pcie_host_init, .deinit = qcom_pcie_host_deinit, .post_init = qcom_pcie_host_post_init, + .pre_scale_bus_bw = qcom_pcie_host_pre_scale_bus_bw, + .post_scale_bus_bw = qcom_pcie_host_post_scale_bus_bw, }; /* Qcom IP rev.: 2.1.0 Synopsys IP rev.: 4.01a */ @@ -1478,9 +1556,6 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie) { u32 offset, status, width, speed; struct dw_pcie *pci = pcie->pci; - unsigned long freq_kbps; - struct dev_pm_opp *opp; - int ret, freq_mbps; offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); status = readw(pci->dbi_base + offset + PCI_EXP_LNKSTA); @@ -1492,29 +1567,7 @@ static void qcom_pcie_icc_opp_update(struct qcom_pcie *pcie) speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, status); width = FIELD_GET(PCI_EXP_LNKSTA_NLW, status); - if (pcie->icc_mem) { - ret = icc_set_bw(pcie->icc_mem, 0, - width * QCOM_PCIE_LINK_SPEED_TO_BW(speed)); - if (ret) { - dev_err(pci->dev, "Failed to set bandwidth for PCIe-MEM interconnect path: %d\n", - ret); - } - } else if (pcie->use_pm_opp) { - freq_mbps = pcie_dev_speed_mbps(pcie_link_speed[speed]); - if (freq_mbps < 0) - return; - - freq_kbps = freq_mbps * KILO; - opp = dev_pm_opp_find_freq_exact(pci->dev, freq_kbps * width, - true); - if (!IS_ERR(opp)) { - ret = dev_pm_opp_set_opp(pci->dev, opp); - if (ret) - dev_err(pci->dev, "Failed to set OPP for freq (%lu): %d\n", - freq_kbps * width, ret); - dev_pm_opp_put(opp); - } - } + qcom_pcie_set_icc_opp(pcie, speed, width); } static int qcom_pcie_link_transition_count(struct seq_file *s, void *data) From patchwork Mon Feb 17 06:34:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Chaitanya Chundru X-Patchwork-Id: 866229 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 76F001A9B4D for ; Mon, 17 Feb 2025 06:34:53 +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=1739774095; cv=none; b=ui+hjjouLqctJg2CVsN98ye3sIogA9NoqZcSbRvXRxGL7/7nxGtZ+Wh1c9bkczMQilmD/zQUs/pGiLC7rUQkIhdUthb66hoAoPcMaAG4BIBSKVoBxguH+YAPIAFZtlzA746QpGFcd2xSbzx/il2nLbLYlaT4BPm8i1qMRYAFpH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774095; c=relaxed/simple; bh=nQTMGV1JQaMucymyZJUx5EnzHD0lju6ffwxVQx+mFJk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KBxfpMFSHBNRyLapOa+AONzbT5h8g2viSjP93vvhYGRPt0cQebLGX8rM5eKwHOmPf9rIQ/Tsqq8n7Mtx80lcmNdw0YQ/pTzsx4kPjuU2A1jU83Bu/aNp2iw4TAe/hlGAeQ+E3IujnAD4ZINazfCz3pKZOpIsNn3NdesFJiGPYw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=K/VOJkB+; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="K/VOJkB+" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51H036mh026277 for ; Mon, 17 Feb 2025 06:34:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ZrMOQi+DVqBOmzjnheRuPjgMJkKNWYaJ1Sz2mjbO69g=; b=K/VOJkB+9vefYUpr FMQ8NDxsLTmXVJF2XvX59EzpHzqJ/5NIeDKzjm64iIpUs0wtyNQUXsfrpeGn11AY oxHpAEYvtwKuT8HIxI5nclZoHVRdS8HTX+Ruixo0AMH/3+RFktBWkpZafOwIO+i+ zITmpUG7OC9MjKHp39LrmjbNM6raOEBd8mwz+kjEraQ/2dvvNquzmPQwCmHNXoFQ +Fg7U1MvfQi5ZPfirYgCQQ7EgQGMPe0d0qxPy1PnJIQNuhHRsaJGXNTQ1mQR19bv RwpYAvyOntK9YvKxEcLGiNyriEWKhLU+vRBrMLYbwknkiOaoXrlawYZYk1WD/TNr SMrmRw== Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44ut7trpvg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 17 Feb 2025 06:34:52 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2fc5a9f18afso2204470a91.1 for ; Sun, 16 Feb 2025 22:34:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739774091; x=1740378891; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZrMOQi+DVqBOmzjnheRuPjgMJkKNWYaJ1Sz2mjbO69g=; b=iWrsH0d/PixbGzHJK21h1K4oBUYlIBV3+7T4172pfbspswxX360MIi6GlIxVSoUP50 rI4nULicA/hgADEhv1n069fniSyAN8dygoWXi2i0ZUY+b+Yk7SaxaSBMdBpbB2yZh3k+ Kfs6ry7/5yA7AiXwXO7d6dyxJp+blPT2q7ltfLDw29UrCEZPVhEWNsNrnnJCDKivYUCZ UhIXZDcPKfDdFPZ9bmp11x229/us73SkqXD4gYcG5FEpPNHKkGFoi85kQIs8WcW0Zz9O FC3p7SsDXobVGyvmZbV1jvr/xH6nQppez6NIY88Z8yln+EW2kikfpdRO3741PLqJeME4 dIzQ== X-Forwarded-Encrypted: i=1; AJvYcCWP2XqAoWh8V5e3noQjmKZJ79pj6Wb8bmI1vrDDrEql/aa0eFpfxYNBG7qwfrnBTjVfuRplYCf9rFpnhZL3@vger.kernel.org X-Gm-Message-State: AOJu0Yz4W4J31rTAyuu2MXOviVDu3xRs8ipKhiLNZbBkgGOW3zCtodur YHI/z3XVL7frBhpQ4X6fyQlAVItJxl0oX0lXnRysPxJL/Pz1SMqPt/tYy6bnF99UXS44ortIp4F JIC5McEcHxQaNKV36yHQUAiNzD1zINAhjLOJtcrQMnI95/XMqT2C/emu9yag/et/y X-Gm-Gg: ASbGncub6BrWk9SM1NvM37Gka5nnX46YzVk6XlYwSIGEHE6TZFcl9JzxeM6f81phSEi UHDEIVeA6Mp5RLODcG+oGPjPLVj6cW/VsijtnJHpq6SwnhW0Exw0aVJa9Y5bZyAX8kJQqfB/Fda 1S7cenr/G4K98U/hiAWfRCT2pXVb1Goc23FR8RBjCrn+hNXNQbt9NJC8d/EQF5zUvdiZDTF6AJY YqrGWBVkHo8nS8t4z4EsHOI9EsCxpXTDpU1coCK5ZnzLV9ufHHG7rUxqZz+P2ouwAUFdfpeBaRc ERMo8lxrlTYwzM+vGQxiK1xbdeakwU2hAHFWpCPt X-Received: by 2002:a05:6a21:6182:b0:1ee:7054:178b with SMTP id adf61e73a8af0-1ee8cba4dfamr14111414637.33.1739774090563; Sun, 16 Feb 2025 22:34:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0zo6VXvd8RLUB1awzCncZPUhHTy4KpTgLnLwWOq7JvhJ09djyatWubQ6CnvJNLbFyc3KFrw== X-Received: by 2002:a05:6a21:6182:b0:1ee:7054:178b with SMTP id adf61e73a8af0-1ee8cba4dfamr14111375637.33.1739774090135; Sun, 16 Feb 2025 22:34:50 -0800 (PST) Received: from hu-krichai-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73263b79287sm3771800b3a.29.2025.02.16.22.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2025 22:34:49 -0800 (PST) From: Krishna Chaitanya Chundru Date: Mon, 17 Feb 2025 12:04:13 +0530 Subject: [PATCH 6/8] bus: mhi: host: Add support for Bandwidth scale Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-mhi_bw_up-v1-6-9bad1e42bdb1@oss.qualcomm.com> References: <20250217-mhi_bw_up-v1-0-9bad1e42bdb1@oss.qualcomm.com> In-Reply-To: <20250217-mhi_bw_up-v1-0-9bad1e42bdb1@oss.qualcomm.com> To: Bjorn Helgaas , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Jingoo Han , Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Johannes Berg , Jeff Johnson Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, mhi@lists.linux.dev, linux-wireless@vger.kernel.org, ath11k@lists.infradead.org, quic_jjohnson@quicinc.com, quic_pyarlaga@quicinc.com, quic_vbadigan@quicinc.com, quic_vpernami@quicinc.com, quic_mrana@quicinc.com, Krishna Chaitanya Chundru X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1739774050; l=14810; i=krishna.chundru@oss.qualcomm.com; s=20230907; h=from:subject:message-id; bh=nQTMGV1JQaMucymyZJUx5EnzHD0lju6ffwxVQx+mFJk=; b=VtHdORpyAkNBNDUy2z4PR8sHf36ghGI6Oi1CrJMoEyej2yk/IZkZ/iJdLTgOfbJnOx7ovZM8h ma1pSMZVnIBBs7pf4CKKFP1YTlotMT7wNsb3rV946QAorrRni8oUHdi X-Developer-Key: i=krishna.chundru@oss.qualcomm.com; a=ed25519; pk=10CL2pdAKFyzyOHbfSWHCD0X0my7CXxj8gJScmn1FAg= X-Proofpoint-ORIG-GUID: xMgSLFGQnu2fcKQLvU6J_QFOfYxpD9Po X-Proofpoint-GUID: xMgSLFGQnu2fcKQLvU6J_QFOfYxpD9Po X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-17_03,2025-02-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 malwarescore=0 impostorscore=0 clxscore=1015 phishscore=0 adultscore=0 spamscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502170056 As per MHI spec sec 14, MHI supports bandwidth scaling to reduce power consumption. MHI bandwidth scaling is advertised in devices that contain the bandwidth scaling capability registers. If enabled, the device aggregates bandwidth requirements and sends them to the host in the form of an event. After the host performs the bandwidth switch, it sends an acknowledgment by ringing a doorbell. if the host supports bandwidth scaling events, then it must set BW_CFG.ENABLED bit, set BW_CFG.DB_CHAN_ID to the channel ID to the doorbell that will be used by the host to communicate the bandwidth scaling status and BW_CFG.ER_INDEX to the index for the event ring to which the device should send bandwidth scaling request in the bandwidth scaling capability register. As part of mmio init check if the bw scale capability is present or not, if present advertise host supports bw scale by setting all the required fields. MHI layer will only forward the bw scaling request to the controller driver, it is responsibility of the controller driver to do actual bw scaling and then pass status to the MHI. MHI will response back to the device based up on the status of the bw scale received. Add a new get_misc_doorbell() to get doorbell for misc capabilities to use the doorbell with mhi events like MHI BW scale etc. Use workqueue & mutex for the bw scale events as the pci_set_target_speed() which will called by the mhi controller driver can sleep. Signed-off-by: Krishna Chaitanya Chundru --- drivers/bus/mhi/common.h | 14 ++++++ drivers/bus/mhi/host/init.c | 64 ++++++++++++++++++++++++- drivers/bus/mhi/host/internal.h | 7 ++- drivers/bus/mhi/host/main.c | 102 +++++++++++++++++++++++++++++++++++++++- drivers/bus/mhi/host/pm.c | 10 +++- include/linux/mhi.h | 13 +++++ 6 files changed, 204 insertions(+), 6 deletions(-) diff --git a/drivers/bus/mhi/common.h b/drivers/bus/mhi/common.h index eedac801b800..b900199fab10 100644 --- a/drivers/bus/mhi/common.h +++ b/drivers/bus/mhi/common.h @@ -208,6 +208,20 @@ #define MHI_RSCTRE_DATA_DWORD1 cpu_to_le32(FIELD_PREP(GENMASK(23, 16), \ MHI_PKT_TYPE_COALESCING)) +/* MHI Bandwidth scaling offsets */ +#define BW_SCALE_CFG_OFFSET (0x04) +#define BW_SCALE_CFG_CHAN_DB_ID_SHIFT (25) +#define BW_SCALE_CFG_ENABLED_MASK BIT(24) +#define BW_SCALE_CFG_ENABLED_SHIFT (24) +#define BW_SCALE_CFG_ER_ID_SHIFT (19) + +#define BW_SCALE_CAP_ID (3) +#define MHI_TRE_GET_EV_BW_REQ_SEQ(tre) (((tre)->dword[0] >> 8) & 0xFF) + +#define MHI_BW_SCALE_RESULT(status, seq) (((status) & 0xF) << 8 | \ + ((seq) & 0xFF)) +#define MHI_BW_SCALE_NACK 0xF + enum mhi_pkt_type { MHI_PKT_TYPE_INVALID = 0x0, MHI_PKT_TYPE_NOOP_CMD = 0x1, diff --git a/drivers/bus/mhi/host/init.c b/drivers/bus/mhi/host/init.c index 0b14b665ed15..f15c79f85d13 100644 --- a/drivers/bus/mhi/host/init.c +++ b/drivers/bus/mhi/host/init.c @@ -496,10 +496,56 @@ static int mhi_get_capability_offset(struct mhi_controller *mhi_cntrl, u32 capab return -ENXIO; } +/* to be used only if a single event ring with the type is present */ +static int mhi_get_er_index(struct mhi_controller *mhi_cntrl, + enum mhi_er_data_type type) +{ + struct mhi_event *mhi_event = mhi_cntrl->mhi_event; + int i; + + /* find event ring for requested type */ + for (i = 0; i < mhi_cntrl->total_ev_rings; i++, mhi_event++) { + if (mhi_event->data_type == type) + return mhi_event->er_index; + } + + return -ENOENT; +} + +static int mhi_init_bw_scale(struct mhi_controller *mhi_cntrl, + int bw_scale_db) +{ + struct device *dev = &mhi_cntrl->mhi_dev->dev; + u32 bw_cfg_offset, val = 0; + int ret, er_index; + + ret = mhi_get_capability_offset(mhi_cntrl, BW_SCALE_CAP_ID, + &bw_cfg_offset); + if (ret) + return ret; + + /* No ER configured to support BW scale */ + er_index = mhi_get_er_index(mhi_cntrl, MHI_ER_BW_SCALE); + if (er_index < 0) + return er_index; + + bw_cfg_offset += BW_SCALE_CFG_OFFSET; + + /* advertise host support */ + val = ((bw_scale_db << BW_SCALE_CFG_CHAN_DB_ID_SHIFT) | + BW_SCALE_CFG_ENABLED_MASK | (er_index << BW_SCALE_CFG_ER_ID_SHIFT)); + mhi_write_reg(mhi_cntrl, mhi_cntrl->regs, bw_cfg_offset, val); + + dev_info(dev, "Bandwidth scaling setup complete. Event ring:%d\n", + er_index); + + return 0; +} + int mhi_init_mmio(struct mhi_controller *mhi_cntrl) { u32 val; - int i, ret; + int i, ret, doorbell; struct mhi_chan *mhi_chan; struct mhi_event *mhi_event; void __iomem *base = mhi_cntrl->regs; @@ -633,6 +679,16 @@ int mhi_init_mmio(struct mhi_controller *mhi_cntrl) return ret; } + if (mhi_cntrl->get_misc_doorbell) + doorbell = mhi_cntrl->get_misc_doorbell(mhi_cntrl, MHI_ER_BW_SCALE); + + if (doorbell > 0) { + ret = mhi_init_bw_scale(mhi_cntrl, doorbell); + if (!ret) + mhi_cntrl->bw_scale_db = base + val + (8 * doorbell); + else + dev_warn(dev, "BW scale setup failure\n"); + } return 0; } @@ -778,6 +834,9 @@ static int parse_ev_cfg(struct mhi_controller *mhi_cntrl, case MHI_ER_CTRL: mhi_event->process_event = mhi_process_ctrl_ev_ring; break; + case MHI_ER_BW_SCALE: + mhi_event->process_event = mhi_process_bw_scale_ev_ring; + break; default: dev_err(dev, "Event Ring type not supported\n"); goto error_ev_cfg; @@ -1012,9 +1071,12 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, mhi_event->mhi_cntrl = mhi_cntrl; spin_lock_init(&mhi_event->lock); + mutex_init(&mhi_event->mutex); if (mhi_event->data_type == MHI_ER_CTRL) tasklet_init(&mhi_event->task, mhi_ctrl_ev_task, (ulong)mhi_event); + else if (mhi_event->data_type == MHI_ER_BW_SCALE) + INIT_WORK(&mhi_event->work, mhi_process_ev_work); else tasklet_init(&mhi_event->task, mhi_ev_task, (ulong)mhi_event); diff --git a/drivers/bus/mhi/host/internal.h b/drivers/bus/mhi/host/internal.h index 3134f111be35..bf7c6a7c9383 100644 --- a/drivers/bus/mhi/host/internal.h +++ b/drivers/bus/mhi/host/internal.h @@ -241,6 +241,8 @@ struct mhi_event { struct mhi_ring ring; struct db_cfg db_cfg; struct tasklet_struct task; + struct work_struct work; + struct mutex mutex; spinlock_t lock; int (*process_event)(struct mhi_controller *mhi_cntrl, struct mhi_event *mhi_event, @@ -403,7 +405,8 @@ int mhi_process_data_event_ring(struct mhi_controller *mhi_cntrl, struct mhi_event *mhi_event, u32 event_quota); int mhi_process_ctrl_ev_ring(struct mhi_controller *mhi_cntrl, struct mhi_event *mhi_event, u32 event_quota); - +int mhi_process_bw_scale_ev_ring(struct mhi_controller *mhi_cntrl, + struct mhi_event *mhi_event, u32 event_quota); /* ISR handlers */ irqreturn_t mhi_irq_handler(int irq_number, void *dev); irqreturn_t mhi_intvec_threaded_handler(int irq_number, void *dev); @@ -419,5 +422,5 @@ void mhi_unmap_single_no_bb(struct mhi_controller *mhi_cntrl, struct mhi_buf_info *buf_info); void mhi_unmap_single_use_bb(struct mhi_controller *mhi_cntrl, struct mhi_buf_info *buf_info); - +void mhi_process_ev_work(struct work_struct *work); #endif /* _MHI_INT_H */ diff --git a/drivers/bus/mhi/host/main.c b/drivers/bus/mhi/host/main.c index 4de75674f193..a6732bbead44 100644 --- a/drivers/bus/mhi/host/main.c +++ b/drivers/bus/mhi/host/main.c @@ -472,7 +472,10 @@ irqreturn_t mhi_irq_handler(int irq_number, void *dev) if (mhi_dev) mhi_notify(mhi_dev, MHI_CB_PENDING_DATA); } else { - tasklet_schedule(&mhi_event->task); + if (mhi_event->data_type == MHI_ER_BW_SCALE) + queue_work(mhi_cntrl->hiprio_wq, &mhi_event->work); + else + tasklet_schedule(&mhi_event->task); } return IRQ_HANDLED; @@ -1049,6 +1052,103 @@ int mhi_process_data_event_ring(struct mhi_controller *mhi_cntrl, return count; } +/* dedicated bw scale event ring processing */ +int mhi_process_bw_scale_ev_ring(struct mhi_controller *mhi_cntrl, + struct mhi_event *mhi_event, u32 event_quota) +{ + struct mhi_event_ctxt *er_ctxt = &mhi_cntrl->mhi_ctxt->er_ctxt[mhi_event->er_index]; + struct device *dev = &mhi_cntrl->mhi_dev->dev; + struct mhi_ring *ev_ring = &mhi_event->ring; + dma_addr_t ptr = le64_to_cpu(er_ctxt->rp); + u32 response = MHI_BW_SCALE_NACK; + struct mhi_ring_element *dev_rp; + struct mhi_link_info link_info; + int ret = -EINVAL; + + if (unlikely(MHI_EVENT_ACCESS_INVALID(mhi_cntrl->pm_state))) { + ret = -EIO; + goto exit_bw_scale_process; + } + + if (!MHI_IN_MISSION_MODE(mhi_cntrl->ee)) + goto exit_bw_scale_process; + + if (!is_valid_ring_ptr(ev_ring, ptr)) { + dev_err(dev, + "Event ring rp points outside of the event ring\n"); + ret = -EIO; + goto exit_bw_scale_process; + } + + dev_rp = mhi_to_virtual(ev_ring, ptr); + + /* if rp points to base, we need to wrap it around */ + if (dev_rp == ev_ring->base) + dev_rp = ev_ring->base + ev_ring->len; + dev_rp--; + + /* fast forward to currently processed element and recycle er */ + ev_ring->rp = dev_rp; + ev_ring->wp = dev_rp - 1; + if (ev_ring->wp < ev_ring->base) + ev_ring->wp = ev_ring->base + ev_ring->len - ev_ring->el_size; + mhi_recycle_ev_ring_element(mhi_cntrl, ev_ring); + + if (WARN_ON(MHI_TRE_GET_EV_TYPE(dev_rp) != MHI_PKT_TYPE_BW_REQ_EVENT)) { + dev_err(dev, "!BW SCALE REQ event\n"); + goto exit_bw_scale_process; + } + + link_info.target_link_speed = MHI_TRE_GET_EV_LINKSPEED(dev_rp); + link_info.target_link_width = MHI_TRE_GET_EV_LINKWIDTH(dev_rp); + link_info.sequence_num = MHI_TRE_GET_EV_BW_REQ_SEQ(dev_rp); + + dev_info(dev, "Received BW_REQ with seq:%d link speed:0x%x width:0x%x\n", + link_info.sequence_num, + link_info.target_link_speed, + link_info.target_link_width); + + /* bring host and device out of suspended states */ + ret = mhi_device_get_sync(mhi_cntrl->mhi_dev); + if (ret) + goto exit_bw_scale_process; + + mhi_cntrl->runtime_get(mhi_cntrl); + + ret = mhi_cntrl->bw_scale(mhi_cntrl, &link_info); + if (!ret) + response = 0; + + response = MHI_BW_SCALE_RESULT(response, link_info.sequence_num); + + write_lock_bh(&mhi_cntrl->pm_lock); + mhi_write_reg(mhi_cntrl, mhi_cntrl->bw_scale_db, 0, response); + write_unlock_bh(&mhi_cntrl->pm_lock); + + mhi_cntrl->runtime_put(mhi_cntrl); + mhi_device_put(mhi_cntrl->mhi_dev); + +exit_bw_scale_process: + dev_info(dev, "exit er_index:%u ret:%d\n", mhi_event->er_index, ret); + + return ret; +} + +void mhi_process_ev_work(struct work_struct *work) +{ + struct mhi_event *mhi_event = container_of(work, struct mhi_event, + work); + + struct mhi_controller *mhi_cntrl = mhi_event->mhi_cntrl; + + if (unlikely(MHI_EVENT_ACCESS_INVALID(mhi_cntrl->pm_state))) + return; + + mutex_lock(&mhi_event->mutex); + mhi_event->process_event(mhi_cntrl, mhi_event, U32_MAX); + mutex_unlock(&mhi_event->mutex); +} + void mhi_ev_task(unsigned long data) { struct mhi_event *mhi_event = (struct mhi_event *)data; diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c index 11c0e751f223..9c848ca582f0 100644 --- a/drivers/bus/mhi/host/pm.c +++ b/drivers/bus/mhi/host/pm.c @@ -523,7 +523,10 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl, if (mhi_event->offload_ev) continue; disable_irq(mhi_cntrl->irq[mhi_event->irq]); - tasklet_kill(&mhi_event->task); + if (mhi_event->data_type == MHI_ER_BW_SCALE) + cancel_work_sync(&mhi_event->work); + else + tasklet_kill(&mhi_event->task); } /* Release lock and wait for all pending threads to complete */ @@ -670,7 +673,10 @@ static void mhi_pm_sys_error_transition(struct mhi_controller *mhi_cntrl) for (i = 0; i < mhi_cntrl->total_ev_rings; i++, mhi_event++) { if (mhi_event->offload_ev) continue; - tasklet_kill(&mhi_event->task); + if (mhi_event->data_type == MHI_ER_BW_SCALE) + cancel_work_sync(&mhi_event->work); + else + tasklet_kill(&mhi_event->task); } /* Release lock and wait for all pending threads to complete */ diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 059dc94d20bb..d9bf88c35d14 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -102,10 +102,12 @@ struct image_info { * struct mhi_link_info - BW requirement * target_link_speed - Link speed as defined by TLS bits in LinkControl reg * target_link_width - Link width as defined by NLW bits in LinkStatus reg + * sequence_num - used by device to track bw requests sent to host */ struct mhi_link_info { unsigned int target_link_speed; unsigned int target_link_width; + int sequence_num; }; /** @@ -183,10 +185,12 @@ enum mhi_ch_ee_mask { * enum mhi_er_data_type - Event ring data types * @MHI_ER_DATA: Only client data over this ring * @MHI_ER_CTRL: MHI control data and client data + * @MHI_ER_BW_SCALE: MHI controller bandwidth scale functionality */ enum mhi_er_data_type { MHI_ER_DATA, MHI_ER_CTRL, + MHI_ER_BW_SCALE, }; /** @@ -299,6 +303,7 @@ struct mhi_controller_config { * @bhi: Points to base of MHI BHI register space * @bhie: Points to base of MHI BHIe register space * @wake_db: MHI WAKE doorbell register address + * @wake_db: MHI BW_SCALE doorbell register address * @iova_start: IOMMU starting address for data (required) * @iova_stop: IOMMU stop address for data (required) * @fw_image: Firmware image name for normal booting (optional) @@ -355,6 +360,8 @@ struct mhi_controller_config { * @write_reg: Write a MHI register via the physical link (required) * @reset: Controller specific reset function (optional) * @edl_trigger: CB function to trigger EDL mode (optional) + * @get_misc_doobell: function to get doorbell used for MISC feature like BW scale etc (optional) + * @bw_scale: CB function for passing BW scale info (optional) * @buffer_len: Bounce buffer length * @index: Index of the MHI controller instance * @bounce_buf: Use of bounce buffer @@ -376,6 +383,7 @@ struct mhi_controller { void __iomem *bhi; void __iomem *bhie; void __iomem *wake_db; + void __iomem *bw_scale_db; dma_addr_t iova_start; dma_addr_t iova_stop; @@ -440,6 +448,11 @@ struct mhi_controller { void (*reset)(struct mhi_controller *mhi_cntrl); int (*edl_trigger)(struct mhi_controller *mhi_cntrl); + int (*get_misc_doorbell)(struct mhi_controller *mhi_cntrl, + enum mhi_er_data_type type); + int (*bw_scale)(struct mhi_controller *mhi_cntrl, + struct mhi_link_info *link_info); + size_t buffer_len; int index; bool bounce_buf; From patchwork Mon Feb 17 06:34:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Chaitanya Chundru X-Patchwork-Id: 866228 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 B6BA51AA795 for ; Mon, 17 Feb 2025 06:35:04 +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=1739774106; cv=none; b=rgNRmRx4RTlyepn2pEszgMnsf3ysi0uO0GqBZJ99vSG/QrwsTinV4W44MnEBiOIIq7Re7BddIG8mJwafpFYOrv24Nb53DiJ1126rHkIZUTAq3csaXL2CcM9YwJdMPhn470uo75jD2e+T87jpRWFXcuSheytQguVtq/OZX8Czq90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739774106; c=relaxed/simple; bh=RBJ8SVlEdgIi33jmgw1hem9IHbgCNgZQ5wzw7AEiy5g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XhAJCHZa51SugIHvK0fb3wyFLOgW15uNHLGjrWlCp61IQ2LV1mTNOdoWWCzWzd4a7GxBew5K0hmWs391prDI4kkppdcbCSm4NhynVjmfckAUpwy4eGimkui3Ug7dDOOp5tlI4jdW6pI8LzpSov2fzrTfgjMm8PdROVQzgb/TMk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=X6lW/RTl; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="X6lW/RTl" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51H03W9h017528 for ; Mon, 17 Feb 2025 06:35:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 7UDfNKFG393gXzpXTFQgYOudK9v3C70LFzGo8/QFzEw=; b=X6lW/RTlx2B4mUbJ uyievDNAqxoSk16rOKKN3tfTS1jtAA1M86yfRcxjS+cKlCs5dL38lO7em5vnOxMK H0Mwkk15WZUQupLdfsM9wDvYh7KVUZ6JpDMpEbaf92GHRwtnpHFQ9a8+EkrT2dwu HVH7G1R93EzIj48YhL/RTrtFyJBGR9pZ8n/JdfoZ0L8g1xhZPi2QSPqmQ3c2HxmP wTgM3ruL2HVT4zLS2EN5+c0Ts0kj/xkezaWIvYLckN4so39dVtAjoAXghjdLvSUw +JvH84+iIKhyTaSLTtZYCeVWyexJ6hl5ErLIJe25g9VlHe61AijS1sdrsSJg2Wzx P/urvw== Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 44ut7urpyk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 17 Feb 2025 06:35:03 +0000 (GMT) Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-2fc3e239675so6633391a91.0 for ; Sun, 16 Feb 2025 22:35:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739774102; x=1740378902; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7UDfNKFG393gXzpXTFQgYOudK9v3C70LFzGo8/QFzEw=; b=uH/048mQawBz/qiPA96OxKdsrU12rQFYtOpPOv3NCKvsQ9KMCEE3neClj9ir7HUkbR IiHGkHZ/7J999RkYgxQKMtzmL666DysU8Ymo17HHG/l6FS8c14ghjOPO7RoQTyJlUQ7l NtrIA0Lqveb+6syNFCEVVlO2oO1GqiFj6asJxqC4vwZ9/r0fHMWA8Aj6xDEgZCETyI01 yB6y+exjLy82jf3u5Ippg/kwrDHlLk+d3ibTkqXzJVOZ0Hi8ei7xD1RMNi6M030mD3R1 Qfm+cPYxcoBU+Mz3E6WZTaSTcM4Uyuw8cfJVOYM+IV99wseKZPS4Hc/UqRbyEqh5DPhW 4Biw== X-Forwarded-Encrypted: i=1; AJvYcCXGvffbiFDxIuQpl880hCDxNBVspJNaXzCxSGKEJISUvEE8XqLbVUzy00KmkHVfhsXmosgZFJnqS9YnZ21H@vger.kernel.org X-Gm-Message-State: AOJu0Yw/FYwTd3cNqjY+mI/sMuOxLChoBTogZL6UogaGu4XmO+Tn+5uf YJ3CVKgIKsHUg+ubLzB9XqdihelBMUHiJUtz+WLzI3QgzGAmBWpdA3I7Y7jRRraSRO/dmssarq5 vHzRM/fDDa82GpXmcR0GaxE3L0T1H/16jm0HYxvdojQ7nud2cFCOQqtLZ0sFaoPbn X-Gm-Gg: ASbGncu4dHlqSOaogu3dRX4qbuC2qLwLbXZuo58iZ5WMHgwU1ySuEDliZ3Ac89ci8xc 7unNpqDxeh94kaFyGW6uvw8cEDRNlOYVpIp/jUgXjgk3hczFRebyQmTx0B0plFhXOyStKG8l8uD Ruw8oCEtBfth/zNkZY+A+BKWaqeBt4qTAmE98ipKmY4TAVnYT10Jgg8xrqs3Drq8avuqoA7T3oX 3bK6vSx3uSA+YWnRTHh54hykUYh/EL1ATQJgTnhzpk+B9sb0LUqeQ9nGNV/tGjqGbmmbBdHT9ri Zu9iXyiPALsdVfnp79bMrzh/6VMeYmzYvsUMy4iq X-Received: by 2002:a05:6a00:4b16:b0:732:1eb2:7bf3 with SMTP id d2e1a72fcca58-7326190da79mr13548566b3a.21.1739774101998; Sun, 16 Feb 2025 22:35:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IELGz3GfyEeU6Trxoq5KbbF54Mp2aAMym3Xjbg6o2A/BhSQ+4SDY7/QVTEr7x4pCB17FhXW0A== X-Received: by 2002:a05:6a00:4b16:b0:732:1eb2:7bf3 with SMTP id d2e1a72fcca58-7326190da79mr13548522b3a.21.1739774101600; Sun, 16 Feb 2025 22:35:01 -0800 (PST) Received: from hu-krichai-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73263b79287sm3771800b3a.29.2025.02.16.22.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2025 22:35:01 -0800 (PST) From: Krishna Chaitanya Chundru Date: Mon, 17 Feb 2025 12:04:15 +0530 Subject: [PATCH 8/8] wifi: ath11k: add support for MHI bandwidth scaling Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-mhi_bw_up-v1-8-9bad1e42bdb1@oss.qualcomm.com> References: <20250217-mhi_bw_up-v1-0-9bad1e42bdb1@oss.qualcomm.com> In-Reply-To: <20250217-mhi_bw_up-v1-0-9bad1e42bdb1@oss.qualcomm.com> To: Bjorn Helgaas , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Jingoo Han , Manivannan Sadhasivam , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Johannes Berg , Jeff Johnson Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, mhi@lists.linux.dev, linux-wireless@vger.kernel.org, ath11k@lists.infradead.org, quic_jjohnson@quicinc.com, quic_pyarlaga@quicinc.com, quic_vbadigan@quicinc.com, quic_vpernami@quicinc.com, quic_mrana@quicinc.com, Krishna Chaitanya Chundru , Miaoqing Pan X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1739774050; l=2713; i=krishna.chundru@oss.qualcomm.com; s=20230907; h=from:subject:message-id; bh=b+t07/zpN1OKXOmnB0/fJYpVmV3Y/hIRHKddZUlsHzc=; b=VEDY9epxk1pHB6IUS9ig0ZBJnc9Og8yA0SyFxac0uwlu+rLcCA8hWDA3dBuU+0yAWzPuxnCwM jPTL5VNdQzuAtFkqpfGWxw/zT4ul1ZBck4W3SG6iKqrfNgd56e/GdnW X-Developer-Key: i=krishna.chundru@oss.qualcomm.com; a=ed25519; pk=10CL2pdAKFyzyOHbfSWHCD0X0my7CXxj8gJScmn1FAg= X-Proofpoint-GUID: cDb4zgrY28KVjVOMTH709ln70iIjQ_to X-Proofpoint-ORIG-GUID: cDb4zgrY28KVjVOMTH709ln70iIjQ_to X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-17_03,2025-02-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 malwarescore=0 bulkscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502170056 From: Miaoqing Pan Add support for MHI bandwidth scaling, which will reduce power consumption if WLAN operates with lower bandwidth. This feature is only enabled for QCA6390. Tested-on: WCN6855 hw2.1 PCI WLAN.HSP.1.1-04546-QCAHSPSWPL_V1_V2_SILICONZ_IOE-1 Signed-off-by: Miaoqing Pan --- drivers/net/wireless/ath/ath11k/mhi.c | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/net/wireless/ath/ath11k/mhi.c b/drivers/net/wireless/ath/ath11k/mhi.c index 6e45f464a429..03cdbe93949a 100644 --- a/drivers/net/wireless/ath/ath11k/mhi.c +++ b/drivers/net/wireless/ath/ath11k/mhi.c @@ -20,6 +20,7 @@ #define MHI_TIMEOUT_DEFAULT_MS 20000 #define RDDM_DUMP_SIZE 0x420000 #define MHI_CB_INVALID 0xff +#define MHI_BW_SCALE_CHAN_DB 126 static const struct mhi_channel_config ath11k_mhi_channels_qca6390[] = { { @@ -73,6 +74,17 @@ static struct mhi_event_config ath11k_mhi_events_qca6390[] = { .client_managed = false, .offload_channel = false, }, + { + .num_elements = 8, + .irq_moderation_ms = 0, + .irq = 1, + .mode = MHI_DB_BRST_DISABLE, + .data_type = MHI_ER_BW_SCALE, + .priority = 2, + .hardware_event = false, + .client_managed = false, + .offload_channel = false, + }, }; static const struct mhi_controller_config ath11k_mhi_config_qca6390 = { @@ -313,6 +325,33 @@ static void ath11k_mhi_op_write_reg(struct mhi_controller *mhi_cntrl, writel(val, addr); } +static int ath11k_mhi_op_get_misc_doorbell(struct mhi_controller *mhi_cntrl, + enum mhi_er_data_type type) +{ + if (type == MHI_ER_BW_SCALE) + return MHI_BW_SCALE_CHAN_DB; + + return -EINVAL; +} + +static int ath11k_mhi_op_bw_scale(struct mhi_controller *mhi_cntrl, + struct mhi_link_info *link_info) +{ + struct ath11k_base *ab = dev_get_drvdata(mhi_cntrl->cntrl_dev); + struct pci_dev *pci_dev = to_pci_dev(ab->dev); + struct pci_dev *pdev; + u8 speed = pcie_link_speed[link_info->target_link_speed]; + + if (!pci_dev) + return -EINVAL; + + pdev = pci_upstream_bridge(pci_dev); + if (!pdev) + return -ENODEV; + + return pcie_set_target_speed(pdev, speed, true); +} + static int ath11k_mhi_read_addr_from_dt(struct mhi_controller *mhi_ctrl) { struct device_node *np; @@ -389,6 +428,8 @@ int ath11k_mhi_register(struct ath11k_pci *ab_pci) mhi_ctrl->status_cb = ath11k_mhi_op_status_cb; mhi_ctrl->read_reg = ath11k_mhi_op_read_reg; mhi_ctrl->write_reg = ath11k_mhi_op_write_reg; + mhi_ctrl->bw_scale = ath11k_mhi_op_bw_scale; + mhi_ctrl->get_misc_doorbell = ath11k_mhi_op_get_misc_doorbell; switch (ab->hw_rev) { case ATH11K_HW_QCN9074_HW10: