From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073819; b=d/rwwqy5gSrRUVTA8hSVzrCHJlS6sju2YTjheCXqzHyx33IXZV/Dqswe5QIlqqH0jKkx B3O/hnDRXW6h+Qe58AD5Nu90el7xzMS6+7KX+zyTT4JQ/gqc9m87a+/h2UMT9KOe8SLeM RcyicE/vso59yRiz76qjk9iPOOv8jEbgYCCIAFQu52gIR8Mjo/IM/3AvRIkHFFCcfIcwC DP1XuMM4nKdigv+ia0usavsLBwL3MQuydY+OE2M2AQUfj5BoO+K4X+/VArGWM1rfgBl8Q Q08inkQ94s5M4lGBiEpdQcyeElXpHxLuLpn03jR3hIcYnBkDiEfG4JyAQLylGpCHp9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073819; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Authority-Analysis:X-Proofpoint-Spam-Info: X-Proofpoint-GUID:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=5/FrKsGahA+B1P78BToKPUBey5i8SjbBdB9sdPhe2v4=; b=HnX6hdUkY//8EREvkd4hNAtQCioYGc3Z2xvId7a46jxMHeDCrNJWjMtCYUN73DzjEfjl GC3ln1KSkz4VD8rt1aJpghY19ap3A7tchXrYRxXfgkkVKkDkVuly2yhBeJsqaaUlcLLVq SI6Vo2NmA1+MpVnk/+xk5C5tUoglDEk106ZEH0xT96YX3XbXQiOjhDgIxDAUsS38on4Mv YsORPRUWD/EqziOqUsFjb55RUWaV+YcW62WMQlt456XEUL5+twGowE5idtH+N+1622nBu /EMLNRQ9+LXWpl1S1fDo0aDDgolxpWDxinTcSmBZcu9rsrXpixxqMUlu66wyXD87XvA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=pGx1sDTr; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=IP0uTt2d; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1499F606A68D for ; Mon, 30 Nov 2026 21:23:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1499F606A68D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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.a=rsa-sha256 header.s=qcppdkim1 header.b=pGx1sDTr; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=IP0uTt2d Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUKwQSd3812014 for ; Mon, 30 Nov 2026 21:23:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=5/FrKsGahA+ B1P78BToKPUBey5i8SjbBdB9sdPhe2v4=; b=pGx1sDTrFsZxpkzxBaryqUhoMde CUouD6dxMmvmI8tfl8u2iG5RreGTKX9tkgePdYxHIvQ1iCZAGE8MCQeJRigdqxqf MTdoDgbEfkkNQXXTDyAe6NVJlYGp6KhoQdDK+HEqFd5kN4mB13xdLYrxUJHCI8wQ M2iwoP9iwQLWhJfOOEpdP5oiWOOwA4RUzJTZNKuatCQvzHkGH3JeD/xYbecPJhWP bUt+zwiMg+la5Xj3tD9bHxHVmEEFNlEv60g4PH2+XxgHWr3SLZXuC3Zt63iTNZgD 4FEwtIUNqLtXeUD+FyaczdYBDwR0uH7DOSd2UW47a5VssvfjrEBLL2AFhfw== Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9gnbg2mn-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 30 Nov 2026 21:23:38 +0000 (GMT) Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-92134f1eb00so146422526d6.0 for ; Mon, 30 Nov 2026 13:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796073817; x=1796678617; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5/FrKsGahA+B1P78BToKPUBey5i8SjbBdB9sdPhe2v4=; b=IP0uTt2dvk5INqQsAbh7rWBNzzKmIfyw2yh0/zWtZz3GZV/b517ax0K2b4qmLDLaeZ 0BLU36ti7jw3jlbVV0DEfHNLkJ7iePqEESpgxsc5VmDh2GuzllAEh7ed6j4DXqVHNNF6 gT2efbs6OpVp+LuT02Pr0GUKmlevc3KjW6n6HE77KBjDEZwXMv62l+0y9bpo3pVABQAo kq9w2yErhGJJsR9U9W8rmmnaY7P8szRkpzRMUcAhXhEBaqCvTaW7M6tGTakRRPvK5Vt8 b6Ndze9dudfdaPySY2LW3oLaF/YhN22a4TXhGjADmNcdjel98tkRPpJTeabZJhuKjD/d NUTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073817; x=1796678617; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5/FrKsGahA+B1P78BToKPUBey5i8SjbBdB9sdPhe2v4=; b=N5HtnOwtCS18lbc2U1Mn3jDOT0m5qfXFWFFkc3wN0zn7PYRrAw73Y+DE5YfyLkHoso pp26gT8Jz2X7aBY7tCjoe+4qNtdfQf/grFaYLtkjA0ENhSRmkfCuZ7j/ltY9pB69mOQL roJAAhH0TABc4X7ik02fD2SEPQ9kt/QPHdXCqriWdNLuEZaTOf0xhzVhhVXvN5QeIYYi NOBAPgZ9nuLYPBQGnumk4SPuNFInIGFCo9+6CH7QNesHcoSSqw2wxNkN6qblVDvV9hxe Ekbtjc2xHpdyXsGgn/bYfUeTS/RtXEoXfvvStekeH0nb+jrrkWeiA7uJNf8ucyhG+kiv JFyg== X-Forwarded-Encrypted: i=1; AL+hErG+VdV2Ztm6f0eFJ2tolQF1YN9XFeaHUWTu8uQ5rrI421TfNoVHSIRQC/aLQlM0Sz1LHy/2KOeXyuSWHm4=@vger.kernel.org X-Gm-Message-State: APuU4Z+bCFixzPTzcoz6HOu0qmHaifjOifFnS6xM0YvslVxu+Nr6hMYb krUK0nRukqNaHjGdT2qS5f3ijUgvqL55EiOJg5+m76drpzqMlVMza9m2ZFFYzJcGfJwajzmLd9K YFrhMXzl9U6NVpm7gVFLUuOLi1CvPNXmiptFd2QQY6CtG25JlvXFkU7QnjS3+ZRzCIZE= X-Gm-Gg: AZFdTZfl6jqF+CaYKCTC8kGB3FP77+xj9Reyv3b3YfPba2agZAzB8NxzkkD3aXf1Snl eum5WWtDB/ynGvMlHANMdAx4lOK+q9G9b0gDoPgWFu0nM4aWOO2jLgMZgZ6kyrJCDEefrkEGlay QCBSurmtkigL/RCnhZHG6BBucL1u1YgV2N8oXEECB76+Z2lQO8BUjbVJk8wQ/B5c1NG3uFstKwm wgptwkzkk8Qd1pAXnd48nYl79KzwhT4ukxXdolLOUo2KsWgneBw9PMhRv1t8x9oYIcb6m2oMsD8 HGtj/t1Demy6K4E0SuDTZE7zMNe9cj/bihMrk1s96r0PJKTYUp1jEUaNHq2xRWiwwSutpUN1Yjh 5kTRwKtFG7NRi+Wb7oFGd0kaFtlw7sOe8zutHjjFgoYOS4RxZMuCcbDsA7lewbHdx X-Received: by 2002:a05:620a:4013:b0:949:5e61:97f with SMTP id af79cd13be357-949bab6e361mr6476635085a.69.1796073817135; Mon, 30 Nov 2026 13:23:37 -0800 (PST) X-Received: by 2002:a05:620a:4013:b0:949:5e61:97f with SMTP id af79cd13be357-949bab6e361mr6476628785a.69.1796073816624; Mon, 30 Nov 2026 13:23:36 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm792580515e9.0.2026.11.30.13.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:23:35 -0800 (PST) From: Srinivas Kandagatla To: Mark Brown Cc: Srinivas Kandagatla , Ravi Hothi , Jaroslav Kysela , Liam Girdwood , Takashi Iwai , Pierre-Louis Bossart , Kuninori Morimoto , Bjorn Andersson , Konrad Dybcio , Abel Vesa , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Ravi Hothi Subject: [PATCH v3 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Date: Mon, 30 Nov 2026 21:22:49 +0000 Message-ID: <20261130212258.7376-16-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com> References: <20261130212258.7376-1-srinivas.kandagatla@oss.qualcomm.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authority-Analysis: v=2.4 cv=Y9BtIReN c=1 sm=1 tr=0 ts=6b0de95a cx=c_pps a=oc9J++0uMp73DTRD5QyR2A==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=OAJap1ZGhMVArrtS6vMA:9 a=iYH6xdkBrDN1Jqds4HTS:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfX3G600ypswNJp iCCNHdKSmVhc1rpbva1S2S0SnJ8ImykuNARLrhfLGi+qvg0F5Nj8hKsZttgNccBrLYBJtZrNLWc 42M91bwj5e6D0i15I/dVY+4DER5kcTg= X-Proofpoint-GUID: yJoqofgXVLXL9sh1_YwRR-lYOUwGMH72 X-Proofpoint-ORIG-GUID: yJoqofgXVLXL9sh1_YwRR-lYOUwGMH72 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTMwMDA4NiBTYWx0ZWRfX/BPj3EM7l7OU VNYt4dhfBzSFnr5J4bcbn7UNpP8gsltR7bzbqHyG3M0strYS/aXDT20vPJqSgSofiB/NKYrS+kk h8jjnIRgBqYpyLIUj8ORERm4HwB8WwzgvJ0u50PU8/P/QZnGtVzO2HWKlKzw7k0qD6zMs79znic 0nP+GLkKAmewKVk2pXZeero9ux6pNQCXU1xoDDPprJcMdHkedUSzZVUDD6NlXeH9/fQj9tiSzpk OY/75PCrjR+wpehHZ68Z6LJkfrmgUPBp5j9VSu7thpB7K5DZCL0jSnIomiDwhvay4T7un1F0D8q xKSRA3tok8ECxaLc4UJ7Q/vZHfpKQmrtvrW5/k01wJR//y8WAdKNJt+CbqfhWeY3VW30qsGBgbu luoaCvYpx2gcc5vu4dfycIybTjaPgtiXIDVsojncNWIb3ZqrOVhfgqDYJ2KQwWiW5Qyhc+DnOtl CDtXca50RYicn4nncoA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-30_05,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 phishscore=0 adultscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611300086 From: Ravi Hothi The speaker protection modules need tuning parameters from the topology cfg blob, which is never sent to the DSP. Send it once the module is configured, in small SET_CFG commands split on parameter boundaries, with each payload padded to 8 bytes as the DSP expects. Every record is checked against the end of the blob, and a malformed blob is rejected. A blob not laid out as parameter records is sent whole. Signed-off-by: Ravi Hothi Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/qdsp6/audioreach.c | 139 ++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c index 070100627809..436d33ea568e 100644 --- a/sound/soc/qcom/qdsp6/audioreach.c +++ b/sound/soc/qcom/qdsp6/audioreach.c @@ -1949,6 +1949,141 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph, return rc; } +/* Keep each SET_CFG small; a larger single parameter is sent on its own */ +#define AR_SP_CFG_MAX_CHUNK_BYTES 512 + +static int audioreach_speaker_protection_send_chunk(struct q6apm_graph *graph, + const char *tag, + const void *data, int size, + int chunk_idx) +{ + int rc; + + struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_apm_cmd_pkt(size, APM_CMD_SET_CFG, 0); + if (IS_ERR(pkt)) + return PTR_ERR(pkt); + + memcpy((void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE, data, size); + + rc = q6apm_send_cmd_sync(graph->apm, pkt, 0); + if (rc) + dev_err(graph->dev, "%s cfg blob: chunk %d (%d bytes) failed: %d\n", + tag, chunk_idx, size, rc); + else + dev_dbg(graph->dev, "%s cfg blob: chunk %d (%d bytes) sent\n", + tag, chunk_idx, size); + + return rc; +} + +/* + * Walk the parameter records of a cfg blob. Each starts with the module's + * instance id and a param_size, followed by its payload and optional zero + * padding; a parameter smaller than a word may come without a payload word. + * Each record is checked against the end of the blob. With @dst, the records + * are copied there with their payload padded to 8 bytes, as the DSP expects. + * Returns the packed size, or -EINVAL if the blob is malformed. + */ +static int audioreach_sp_cfg_walk(const u32 *word, u32 num_words, u32 iid, + u32 first, u32 *next, u8 *dst, u32 max_bytes) +{ + u32 pos = first, bytes = 0; + + while (pos < num_words) { + u32 param_size, payload_words, avail, rec_bytes; + + if (word[pos] != iid || num_words - pos < 4) + return -EINVAL; + + param_size = word[pos + 2]; + avail = (num_words - pos - 4) * sizeof(u32); + if (param_size < sizeof(u32) && avail && word[pos + 4] == iid) { + payload_words = 0; + } else { + if (param_size > avail) + return -EINVAL; + payload_words = DIV_ROUND_UP(param_size, sizeof(u32)); + } + + rec_bytes = APM_MODULE_PARAM_DATA_SIZE + ALIGN(param_size, 8); + if (bytes && bytes + rec_bytes > max_bytes) + break; + + if (dst) { + memcpy(dst + bytes, &word[pos], APM_MODULE_PARAM_DATA_SIZE); + memset(dst + bytes + APM_MODULE_PARAM_DATA_SIZE, 0, + rec_bytes - APM_MODULE_PARAM_DATA_SIZE); + memcpy(dst + bytes + APM_MODULE_PARAM_DATA_SIZE, &word[pos + 4], + min(param_size, payload_words * (u32)sizeof(u32))); + } + bytes += rec_bytes; + + pos += 4 + payload_words; + while (pos < num_words && !word[pos]) + pos++; + } + + if (next) + *next = pos; + return bytes; +} + +static int audioreach_speaker_protection_send_static_cfg(struct q6apm_graph *graph, + const struct audioreach_module *module, + const char *tag) +{ + u32 size, num_words, pos = 0; + const u32 *word; + int total, rc = 0, chunk = 0; + + if (!module->data || !module->data->size) + return 0; + + size = le32_to_cpu(module->data->size); + word = (const u32 *)module->data->data; + num_words = size / sizeof(u32); + + /* Not laid out as parameter records, so send it as the topology built it */ + if (size % sizeof(u32) || !num_words || word[0] != module->instance_id) + return audioreach_speaker_protection_send_chunk(graph, tag, word, size, 0); + + total = audioreach_sp_cfg_walk(word, num_words, module->instance_id, 0, + NULL, NULL, U32_MAX); + if (total < 0) { + dev_err(graph->dev, "%s cfg blob is malformed\n", tag); + return total; + } + + u8 *packed __free(kfree) = kmalloc(total, GFP_KERNEL); + if (!packed) + return -ENOMEM; + + while (pos < num_words && !rc) { + int bytes = audioreach_sp_cfg_walk(word, num_words, module->instance_id, + pos, &pos, packed, + AR_SP_CFG_MAX_CHUNK_BYTES); + if (bytes <= 0) + return bytes ? bytes : -EINVAL; + + rc = audioreach_speaker_protection_send_chunk(graph, tag, packed, bytes, + chunk++); + } + + return rc; +} + +static int audioreach_speaker_protection_static_cfg(struct q6apm_graph *graph, + const struct audioreach_module *module) +{ + return audioreach_speaker_protection_send_static_cfg(graph, module, "SP"); +} + +static int audioreach_speaker_protection_vi_static_cfg(struct q6apm_graph *graph, + const struct audioreach_module *module) +{ + return audioreach_speaker_protection_send_static_cfg(graph, module, "VI"); +} + int audioreach_set_media_format(struct q6apm_graph *graph, const struct audioreach_module *module, const struct audioreach_module_config *cfg) @@ -2002,12 +2137,16 @@ int audioreach_set_media_format(struct q6apm_graph *graph, break; case MODULE_ID_SPEAKER_PROTECTION: rc = audioreach_speaker_protection(graph, module); + if (!rc) + rc = audioreach_speaker_protection_static_cfg(graph, module); if (!rc) rc = audioreach_module_enable(graph, module, true); break; case MODULE_ID_SPEAKER_PROTECTION_VI: rc = audioreach_speaker_protection_vi(graph, module, cfg); + if (!rc) + rc = audioreach_speaker_protection_vi_static_cfg(graph, module); if (!rc) rc = audioreach_module_enable(graph, module, true); -- 2.53.0