From nobody Sun Feb 8 20:35:16 2026 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 CB79328852E for ; Thu, 29 Jan 2026 14:25:35 +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=1769696738; cv=none; b=lT5pi1mDjm3xl60AK74D2QXg3nKypEM+3lPntL/ZtpweTAnFEhErB6ULuaQheU2ZDzmdxH0pGKSnEQGtuYYEsY1f6ygq2F0EpuKKGPaqqOYMWC7ch33sFOS5LVr29FSvsy1c3LOMwXBzOzXRMdofnz5Eyx8agb8/XmxSgicM9+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769696738; c=relaxed/simple; bh=m0SivMH4qU2C480k94zrKGIj4JgPhQBQzNZ+vZrK148=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=MeYcWavX3bRYvQ8Di51e0dzz7NJ0byCgWcLWVtxWDUcAYEHBrFWIqGxwi2EREibgJA1YK4NRgiX2UWS54dZb0SsCakyJlQeX/STeEQHw5Uo0mqlzhiXVP+6jq1dqIOF5hPxR1ZNpE6bYuWZ8fuYqUwJ9VT7YsWVpKdvGh8aCUU0= 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=EpMkBqEG; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=MFi2jcUB; 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="EpMkBqEG"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="MFi2jcUB" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60TAATAD3143767 for ; Thu, 29 Jan 2026 14:25:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=oSQPqso7JiLEAC9KBcnanR cpr9Jj5fwMPnM/9PQb6kY=; b=EpMkBqEGBmcYypOuIKyAKP79ivvk65dJrb8hWF PB64KaQh0Zl72+ZCVGFL8YIy0r/KTGD2md0iI1Xrv7egZodqVDIaFY3UIf0S7eby GoTfdKpnw13jmi4U9iprKMN96zJhZg9SCHeM0+NNXDk00ZwVajY2zR+PWEJSKQJu gILGlBId9G0KdTYbV6siDsC1VzwjrZh1cE8X7mlCqXru6TFlqydgY+7opDmLbcWd IP3WyUI9wLaAibrOBpeJvYKBa08kP07NDa44KDZjRYWgE8ICeMGo3hmpcSss0q7A b0ZWSJyz2hmKJrZKJlhBYv3XIrac7VHhL6xIlxQ1p8674rjA== Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4byqpxka4g-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 29 Jan 2026 14:25:34 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-c660e51afb5so568288a12.2 for ; Thu, 29 Jan 2026 06:25:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1769696734; x=1770301534; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=oSQPqso7JiLEAC9KBcnanRcpr9Jj5fwMPnM/9PQb6kY=; b=MFi2jcUBpQygDY0mKTPrwDzkNJyLZGmaOsuz/Bsk+kDQfrIPfIrl0Os/76040UmJ1k oasjqn0XLHazxUhqc5+mzvhT9GJFiWp7hHdIS61oEhawKhcWHx4btBbU/AvyP6QcK6L8 OvUzvL3mZ4Cf3TB6V41uFYVZiskIUMcDS2xKmeOQdKwe/vSYIkSSeAQuIpWQAYrZc65R WClcCfLdbA91/Z2eouL1rEL03RFy2Ffq5CX3p/oMGCk+H36W9EXTc+R4WlLpDJsL5ZVy Gw/kYRWkaHO2wPuZhwAlSEmkwQKp60wHcCfUa9ylIEEwnBdARir3jAwtVGsxXRO1N3gi UGVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769696734; x=1770301534; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oSQPqso7JiLEAC9KBcnanRcpr9Jj5fwMPnM/9PQb6kY=; b=NtnHI5V+dzwV8hM0XtSbzLOCYXeiTEo5H63n95LnGDJ3/BlW6K51dXK1DjPQWlkiMo 8eoye5el4fXNRuJLi43MyIWyuDa804Kyl78vn3oasvGWcL53ck87frSuUqNf/bAlZuJ6 oH2TIlxevp1I7uTbvQXk9si1FHH+HdRucULvqd6DSPb8n92UJocTO3+bXEgTjUuNk8kK TnsY9Jnv18qFxeS8j4/kNheJg0bhzsOJ1b/TH7qlVykvssKAgIIM1DEJuUHPoqt1cTW1 TG9D+W2CMSK9bZd0FgUp/q7qQbCRzhBEE/NWQhZPZYhL4+2MIoE94gkYgCoLdMxeC7o0 Nc0g== X-Gm-Message-State: AOJu0YwtUgXJRFElC8Cm7fQ48IncO+NqUP2PSbN/YtMdJQ0HBKZgLKf+ NsZ1wB/ckm7aOPeVG80qIYT0ypxtgHX53iVmOt2ceyvL0wNf7wKZXJd5IbKwyjIKROWimbRUQgy /PG3Joc670Ji9bzcINNPlgYfjSud/CcfE7pxItV8yp0j+eHEF6ovLQwFOLfWi4VTmO4s= X-Gm-Gg: AZuq6aJHrQ1dpt1sptHC+Z9+L+2p2JeZtDEaRWUJzlvRNhemyt3xk/A/p790BQZuka4 L5fciNWjaByR+0AHWGwrdmR4GfdIBSVw2RnrWowQYvwdakA/oaJn+ErKYrRErll15guvreLjXFn 4x1lVRB7XesWimkTmh1H5zB1StEWj+DvA5nTRtBTvE8T2RvHYjWwF5hVvZUQExMznZnW5gbg7VF uMCtZlPq6VrSOIL9fG9CowCNq3jbhAwim8QxTKTMr2nsut12pSUIxutydd3QE35e0ffH62uiVrH 5HOG1CKxR2RdIpxDBUfx93177e94d1Pewe0A/n5bj6a3TPXimM/cJ2ESS8ah9tuxL8jdqn0uBPt /z9kXUWrr1pgFXMkClQKpPt+NXaNdmMr2rkmd05uknR1LPUoylXH4m6nzNGI3iLcEHVSzgXsq2k UnxA== X-Received: by 2002:a05:6300:14c:b0:35d:2172:6010 with SMTP id adf61e73a8af0-38ec63ca613mr9349365637.51.1769696733348; Thu, 29 Jan 2026 06:25:33 -0800 (PST) X-Received: by 2002:a05:6300:14c:b0:35d:2172:6010 with SMTP id adf61e73a8af0-38ec63ca613mr9349333637.51.1769696732726; Thu, 29 Jan 2026 06:25:32 -0800 (PST) Received: from jinlmao-gv.qualcomm.com (tpe-colo-wan-fw-bordernet.qualcomm.com. [103.229.16.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a88b4c40e1sm52999015ad.55.2026.01.29.06.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 06:25:32 -0800 (PST) From: Yingchao Deng Date: Thu, 29 Jan 2026 22:25:07 +0800 Subject: [PATCH v5] stm: class: Add MIPI OST protocol support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260129-p_ost-v5-1-2b14fff39428@oss.qualcomm.com> X-B4-Tracking: v=1; b=H4sIAMJte2kC/42Myw6CMBBFf8V0bUmfFF35H4aY0g7SRCi2SDSEf 7ewMj4SN5OcyT1nQhGCg4j2mwkFGF10vksgtxtkGt2dATubGDHCJCVM4P7k44CtJJJVQnOqOEr bPkDt7mvnWCZuXBx8eKzZUSzf98IoMMXWAFRa1UBrevAxZtebvhjftlk6S/ebxHPJNMlrS6T8J eWEst2rpJZQYQVVVv0tETC64BYEFOJTKud5fgJM2R1+QAEAAA== To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, quic_yingdeng@quicinc.com, Tingwei Zhang , Yuanfang Zhang , Jinlong Mao , Yingchao Deng X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1769696728; l=13269; i=yingchao.deng@oss.qualcomm.com; s=20251024; h=from:subject:message-id; bh=m0SivMH4qU2C480k94zrKGIj4JgPhQBQzNZ+vZrK148=; b=YM2XryB2dMSK9R4XocwGM2wFbEN9kxz9VpmPTcIeqYjaPlpSZemrsdREDfmsHSPvJmjF6mCvF eStH6QtCNncA/HcKEoIMx63jLot0+Z5QaabGhTofTRFvEkLrgJXLwcS X-Developer-Key: i=yingchao.deng@oss.qualcomm.com; a=ed25519; pk=NtBn/z8P2AMtGDeVaBWYauT/J/B0Js461LF0fOHs/u8= X-Proofpoint-GUID: 6krlRuP0brN5GoPw-dWKBc5OpEYIzRQq X-Proofpoint-ORIG-GUID: 6krlRuP0brN5GoPw-dWKBc5OpEYIzRQq X-Authority-Analysis: v=2.4 cv=dfSNHHXe c=1 sm=1 tr=0 ts=697b6dde cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=nuhDOHQX5FNHPW3J6Bj6AA==:17 a=IkcTkHD0fZMA:10 a=vUbySO9Y5rIA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=COk6AnOGAAAA:8 a=XxusR3KdFzf1ftiqTncA:9 a=QEXdDO2ut3YA:10 a=x9snwWr2DeNwDh03kgHS:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTI5MDA5OCBTYWx0ZWRfXyzBy7yjv6Sd/ CMdN02Aq1xjUZ0/rnrzbW3VdYHMF/0ymZCbOitqYrGmB9ZL4dVE2uPqU2hwgxdkv3OXEoPQqp33 Efg1SFMGZkx9t+CD7fJdaoXnJKfystRVGiF0xamxem/5H/vQ2e/MzUd0EBaIDkcQ3fk0DdLUk0T t5YMc+0i0m4m46/iv158VbB5N6pbSUajJFMgG0Hg/s51YffoloxwO3v8zDIJqY2AhGurJVK17cf vos9Rz9fzldfzYSLBd9OUyA5HU5yL3sceyJZQUS8H0a2+GbJCnMsHtvK/rGs/FzE22wiCi8hBiE ZEo2WsLGlfjmWmqUhpIRBuz2gTyLkLE/LkShj3kbai3WBpQiBoaglbU9+7c6bW7HW4ZDlJo/4Zh hF9dCP89OTc3mdsgphYAqHKZBmZqfp7/YB+IRZxSNaG9Cko8032oaicHduDna9tAAtd3MGx6GNP KBi2PiFEckqTcVjecEA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-01-29_02,2026-01-28_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 adultscore=0 clxscore=1015 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2601290098 Add MIPI OST(Open System Trace) protocol support for stm to format the traces. The OST Protocol abstracts the underlying layers from the sending and receiving applications, thus removing dependencies on the connection media and platform implementation. OST over STP packet consists of Header/Payload/End. Header is designed to include the information required by all OST packets. Information that is not shared by all packets is left to the higher layer protocols. Thus, the OST Protocol Header can be regarded as the first part of a complete OST Packet Header, while a higher layer header can be regarded as an extension designed for a specific purpose. +--------+--------+--------+--------+ | start |version |entity |protocol| +--------+--------+--------+--------+ | stm version | magic | +-----------------------------------+ | cpu | +-----------------------------------+ | timestamp | | | +-----------------------------------+ | tgid | | | +-----------------------------------+ | payload | +-----------------------------------+ | ... | end | +-----------------------------------+ In header, there will be STARTSIMPLE/VERSION/ENTITY/PROTOCOL. STARTSIMPLE is used to signal the beginning of a simplified OST protocol. The Version field is a one byte, unsigned number identifying the version of the OST Protocol. The Entity ID field is a one byte unsigned number that identifies the source. The Protocol ID field is a one byte unsigned number identifying the higher layer protocol of the OST Packet, i.e. identifying the format of the data after the OST Protocol Header. OST Control Protocol ID value represents the common control protocol, the remaining Protocol ID values may be used by any higher layer protocols capable of being transported by the OST Protocol. Co-developed-by: Tingwei Zhang Signed-off-by: Tingwei Zhang Co-developed-by: Yuanfang Zhang Signed-off-by: Yuanfang Zhang Co-developed-by: Jinlong Mao Signed-off-by: Jinlong Mao Signed-off-by: Yingchao Deng --- Changes in v5: 1. Add Co-developed-by tag. 2. Use yearless copyright for new file. - Link to v4: https://lore.kernel.org/all/20251024-p_ost-v4-1-3652a06fd055@= oss.qualcomm.com/ Changes in v4: 1. Delete unused variable 'i'. 2. Fix build error: call to undeclared function 'task_tgid_nr'. Link to v3 - https://lore.kernel.org/all/20251022071834.1658684-1-yingchao.= deng@oss.qualcomm.com/ Changes in v3: 1. Add more details about OST. 2. Delete 'entity_available' node, and 'entity' node will show available and currently selected (shown in square brackets) entity. 3. Removed the usage of config_item->ci_group->cg_subsys->su_mutex. Link to v2 - https://lore.kernel.org/all/20230419141328.37472-1-quic_jinlma= o@quicinc.com/ --- .../ABI/testing/configfs-stp-policy-p_ost | 6 + Documentation/trace/p_ost.rst | 36 ++++ drivers/hwtracing/stm/Kconfig | 14 ++ drivers/hwtracing/stm/Makefile | 2 + drivers/hwtracing/stm/p_ost.c | 236 +++++++++++++++++= ++++ 5 files changed, 294 insertions(+) diff --git a/Documentation/ABI/testing/configfs-stp-policy-p_ost b/Document= ation/ABI/testing/configfs-stp-policy-p_ost new file mode 100644 index 000000000000..3cc4b38b456e --- /dev/null +++ b/Documentation/ABI/testing/configfs-stp-policy-p_ost @@ -0,0 +1,6 @@ +What: /config/stp-policy/:p_ost.//entity +Date: Jan 2026 +KernelVersion: 6.20 +Description: + Set the entity which is to identify the source, RW. + diff --git a/Documentation/trace/p_ost.rst b/Documentation/trace/p_ost.rst new file mode 100644 index 000000000000..df93b889eb4c --- /dev/null +++ b/Documentation/trace/p_ost.rst @@ -0,0 +1,36 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +MIPI OST over STP +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The OST(Open System Trace) driver is used with STM class devices to +generate standardized trace stream. Trace sources can be identified +by different entity ids. + +CONFIG_STM_PROTO_OST is for p_ost driver enablement. Once this config +is enabled, you can select the p_ost protocol by command below: + +# mkdir /sys/kernel/config/stp-policy/stm0:p_ost.policy + +The policy name format is extended like this: + :. + +With coresight-stm device, it will be look like "stm0:p_ost.policy". + +With MIPI OST protocol driver, the attributes for each protocol node is: +# mkdir /sys/kernel/config/stp-policy/stm0:p_ost.policy/default +# ls /sys/kernel/config/stp-policy/stm0:p_ost.policy/default +channels entity masters + +The entity here is the set the entity that p_ost supports. Currently +p_ost supports ftrace, console and diag entity. + +Set entity: +# echo 'ftrace' > /sys/kernel/config/stp-policy/stm0:p_ost.policy/default/= entity + +Get available and currently selected (shown in square brackets) entity tha= t p_ost supports: +# cat /sys/kernel/config/stp-policy/stm0:p_ost.policy/default/entity +[ftrace] console diag + +See Documentation/ABI/testing/configfs-stp-policy-p_ost for more details. diff --git a/drivers/hwtracing/stm/Kconfig b/drivers/hwtracing/stm/Kconfig index eda6b11d40a1..daa4aa09f64d 100644 --- a/drivers/hwtracing/stm/Kconfig +++ b/drivers/hwtracing/stm/Kconfig @@ -40,6 +40,20 @@ config STM_PROTO_SYS_T =20 If you don't know what this is, say N. =20 +config STM_PROTO_OST + tristate "MIPI OST STM framing protocol driver" + default CONFIG_STM + help + This is an implementation of MIPI OST protocol to be used + over the STP transport. In addition to the data payload, it + also carries additional metadata for entity, better + means of trace source identification, etc. + + The receiving side must be able to decode this protocol in + addition to the MIPI STP, in order to extract the data. + + If you don't know what this is, say N. + config STM_DUMMY tristate "Dummy STM driver" help diff --git a/drivers/hwtracing/stm/Makefile b/drivers/hwtracing/stm/Makefile index 1692fcd29277..d9c8615849b9 100644 --- a/drivers/hwtracing/stm/Makefile +++ b/drivers/hwtracing/stm/Makefile @@ -5,9 +5,11 @@ stm_core-y :=3D core.o policy.o =20 obj-$(CONFIG_STM_PROTO_BASIC) +=3D stm_p_basic.o obj-$(CONFIG_STM_PROTO_SYS_T) +=3D stm_p_sys-t.o +obj-$(CONFIG_STM_PROTO_OST) +=3D stm_p_ost.o =20 stm_p_basic-y :=3D p_basic.o stm_p_sys-t-y :=3D p_sys-t.o +stm_p_ost-y :=3D p_ost.o =20 obj-$(CONFIG_STM_DUMMY) +=3D dummy_stm.o =20 diff --git a/drivers/hwtracing/stm/p_ost.c b/drivers/hwtracing/stm/p_ost.c new file mode 100644 index 000000000000..51fffa942959 --- /dev/null +++ b/drivers/hwtracing/stm/p_ost.c @@ -0,0 +1,236 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + * + * MIPI OST framing protocol for STM devices. + */ + +#include +#include +#include +#include +#include "stm.h" + +/* + * OST Base Protocol Header + * + * Position Bits Field Name + * 0 8 STARTSIMPLE + * 1 8 Version + * 2 8 Entity ID + * 3 8 protocol ID + */ +#define OST_FIELD_STARTSIMPLE 0 +#define OST_FIELD_VERSION 8 +#define OST_FIELD_ENTITY 16 +#define OST_FIELD_PROTOCOL 24 + +#define OST_TOKEN_STARTSIMPLE 0x10 +#define OST_VERSION_MIPI1 0x10 + +/* entity id to identify the source*/ +#define OST_ENTITY_FTRACE 0x01 +#define OST_ENTITY_CONSOLE 0x02 +#define OST_ENTITY_DIAG 0xEE + +#define OST_CONTROL_PROTOCOL 0x0 + +#define DATA_HEADER ((OST_TOKEN_STARTSIMPLE << OST_FIELD_STARTSIMPLE) | \ + (OST_VERSION_MIPI1 << OST_FIELD_PROTOCOL) | \ + (OST_CONTROL_PROTOCOL << OST_FIELD_PROTOCOL)) + +#define STM_MAKE_VERSION(ma, mi) (((ma) << 8) | (mi)) +#define STM_HEADER_MAGIC (0x5953) + +enum ost_entity_type { + OST_ENTITY_TYPE_NONE, + OST_ENTITY_TYPE_FTRACE, + OST_ENTITY_TYPE_CONSOLE, + OST_ENTITY_TYPE_DIAG, +}; + +static const char * const str_ost_entity_type[] =3D { + [OST_ENTITY_TYPE_NONE] =3D "none", + [OST_ENTITY_TYPE_FTRACE] =3D "ftrace", + [OST_ENTITY_TYPE_CONSOLE] =3D "console", + [OST_ENTITY_TYPE_DIAG] =3D "diag", +}; + +static const u32 ost_entity_value[] =3D { + [OST_ENTITY_TYPE_NONE] =3D 0, + [OST_ENTITY_TYPE_FTRACE] =3D OST_ENTITY_FTRACE, + [OST_ENTITY_TYPE_CONSOLE] =3D OST_ENTITY_CONSOLE, + [OST_ENTITY_TYPE_DIAG] =3D OST_ENTITY_DIAG, +}; + +struct ost_policy_node { + enum ost_entity_type entity_type; +}; + +struct ost_output { + struct ost_policy_node node; +}; + +/* Set default entity type as none */ +static void ost_policy_node_init(void *priv) +{ + struct ost_policy_node *pn =3D priv; + + pn->entity_type =3D OST_ENTITY_TYPE_NONE; +} + +static int ost_output_open(void *priv, struct stm_output *output) +{ + struct ost_policy_node *pn =3D priv; + struct ost_output *opriv; + + opriv =3D kzalloc(sizeof(*opriv), GFP_ATOMIC); + if (!opriv) + return -ENOMEM; + + memcpy(&opriv->node, pn, sizeof(opriv->node)); + output->pdrv_private =3D opriv; + return 0; +} + +static void ost_output_close(struct stm_output *output) +{ + kfree(output->pdrv_private); +} + +static ssize_t ost_t_policy_entity_show(struct config_item *item, + char *page) +{ + struct ost_policy_node *pn =3D to_pdrv_policy_node(item); + ssize_t sz =3D 0; + int i; + + for (i =3D 1; i < ARRAY_SIZE(str_ost_entity_type); i++) { + if (i =3D=3D pn->entity_type) + sz +=3D sysfs_emit_at(page, sz, "[%s] ", str_ost_entity_type[i]); + else + sz +=3D sysfs_emit_at(page, sz, "%s ", str_ost_entity_type[i]); + } + + sz +=3D sysfs_emit_at(page, sz, "\n"); + return sz; +} + +static int entity_index(const char *str) +{ + int i; + + for (i =3D 1; i < ARRAY_SIZE(str_ost_entity_type); i++) { + if (sysfs_streq(str, str_ost_entity_type[i])) + return i; + } + + return 0; +} + +static ssize_t +ost_t_policy_entity_store(struct config_item *item, const char *page, + size_t count) +{ + struct ost_policy_node *pn =3D to_pdrv_policy_node(item); + int i; + + i =3D entity_index(page); + if (i) + pn->entity_type =3D i; + else + return -EINVAL; + + return count; +} +CONFIGFS_ATTR(ost_t_policy_, entity); + +static struct configfs_attribute *ost_t_policy_attrs[] =3D { + &ost_t_policy_attr_entity, + NULL, +}; + +static ssize_t +notrace ost_write(struct stm_data *data, struct stm_output *output, + unsigned int chan, const char *buf, size_t count, + struct stm_source_data *source) +{ + struct ost_output *op =3D output->pdrv_private; + unsigned int c =3D output->channel + chan; + unsigned int m =3D output->master; + const unsigned char nil =3D 0; + u32 header =3D DATA_HEADER; + struct trc_hdr { + u16 version; + u16 magic; + u32 cpu; + u64 timestamp; + u64 tgid; + } hdr; + ssize_t sz; + + /* + * Identify the source by entity type. + * If entity type is not set, return error value. + */ + if (op->node.entity_type) + header |=3D ost_entity_value[op->node.entity_type]; + else + return -EINVAL; + + /* + * STP framing rules for OST frames: + * * the first packet of the OST frame is marked; + * * the last packet is a FLAG with timestamped tag. + */ + /* Message layout: HEADER / DATA / TAIL */ + /* HEADER */ + sz =3D data->packet(data, m, c, STP_PACKET_DATA, STP_PACKET_MARKED, + 4, (u8 *)&header); + if (sz <=3D 0) + return sz; + + /* DATA */ + hdr.version =3D STM_MAKE_VERSION(0, 3); + hdr.magic =3D STM_HEADER_MAGIC; + hdr.cpu =3D raw_smp_processor_id(); + hdr.timestamp =3D sched_clock(); + hdr.tgid =3D task_tgid_nr(current); + sz =3D stm_data_write(data, m, c, false, &hdr, sizeof(hdr)); + if (sz <=3D 0) + return sz; + + sz =3D stm_data_write(data, m, c, false, buf, count); + + /* TAIL */ + if (sz > 0) + data->packet(data, m, c, STP_PACKET_FLAG, + STP_PACKET_TIMESTAMPED, 0, &nil); + + return sz; +} + +static const struct stm_protocol_driver ost_pdrv =3D { + .owner =3D THIS_MODULE, + .name =3D "p_ost", + .write =3D ost_write, + .policy_attr =3D ost_t_policy_attrs, + .output_open =3D ost_output_open, + .output_close =3D ost_output_close, + .policy_node_init =3D ost_policy_node_init, +}; + +static int ost_stm_init(void) +{ + return stm_register_protocol(&ost_pdrv); +} +module_init(ost_stm_init); + +static void ost_stm_exit(void) +{ + stm_unregister_protocol(&ost_pdrv); +} +module_exit(ost_stm_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("MIPI Open System Trace STM framing protocol driver"); --- base-commit: efb26a23ed5f5dc3554886ab398f559dcb1de96b change-id: 20251024-p_ost-d5052b4a3173 Best regards, --=20 Yingchao Deng