From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39D1B194087 for ; Tue, 30 Jul 2024 08:39:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722328786; cv=none; b=OhXYTPG0q1IO4uerM5ByJKCkosfH5A+2M9gTQCLxZ0ByKnZ15zLYOALQuPSSBI39RwNllp8YTVOuSojPJvpUeOuo3f8ZwtKK9aUPlqTabgG9bIkD/HEgCNfHDxPdkzNdl9PgsasQS8C2tpU71NUicJBFCFgeJBBTTGLSfjhUFrY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722328786; c=relaxed/simple; bh=kpdQG6yB98uaLHzj03tYd/l6KR69dRR6ZSb3cvXgUII=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=PxHp4x5IRR0Cc5bfKaDTLIeBWX4zvQpxkfQ3/hzjGlkYznuf4YH1eDdCyUIITHQyUD8ApL1sQpv0z4/sV3wcLLhE0KuJ8cRisvzzXG/47pXid+bBjKhDdrZls6cck9w3EpdDZvN/WC9qidHsjqTvsP2MTgBRuJSw7K+E1AHrXk0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=G2xEQgme; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="G2xEQgme" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-428243f928cso3639985e9.3 for ; Tue, 30 Jul 2024 01:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722328782; x=1722933582; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=/mAglCNUGdccjoyEA9UGpBCtWXf2TmguD9tkOS0Mdk4=; b=G2xEQgme/6jjeKuVjTWqJKnJkUu8DWsbdCIIzgBQT1QQJV76Q9uobo9ML8Iwu79uhr tXTaiL7E9uMpSsTNzz1ZdZHjvDpRJhlhuDQHNfqbxFLXnnmCb+HD5ozDI4zkq4yhBcO1 uD89gt4Oh1tCo1WJDKrkaH6RQBTtuTxXnRXutvnt5MaRUNPORNpflKqQR/Ef0Tph8NEY 1vglvvzISGLIGEiLgyXswvoq48FqdBXgX7QnZLLbIAA5XQpX1rQJM3VXWFprGnpzXjNR glhiAf3kn/B6Ho7kd0s9gy45hKFpOAMr6B45YH5i0w0Pgw1BgIpWYfVRwsoy0ztB0Bxl /6tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722328782; x=1722933582; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/mAglCNUGdccjoyEA9UGpBCtWXf2TmguD9tkOS0Mdk4=; b=VzvpVMSwMHHJSPqU1j3vmHuvw2yMtUtGyAjGAf2Mu/Jwj1v9UCsHadurzRF4wckMix 47sqdAmvzCoB2b8EQlUtM+/YQEkY1PLsQ6SigFsZ6pWuwnG4wHAmeTbC7mZYUvkO1dpX BvhDll9ylsfyQ2hBYuJ4fG7mFdDiw2n0vT5DD0zSnSTul/ag7ACG6DAkOt7+I+Fzm8ha q1I4xY6yxeATHqFOCl0EmDPgXG6F739G6ip52nrlEtTdsKdx6947Q7U+UXxvsRA+sbOM Vf1yAQMqPNWnDO42x/IbHR2xy7jibuMbHHqlBJ+aC+sW4DZg1Dj8Qq9PIaRckTwcd1in /09g== X-Gm-Message-State: AOJu0Ywe8VZs/xscykmb9r6dJCd6sNJij77UjyhdKwZeEay1BKf+y0hk m0JN/0VO8ud3FHYMGvHFGipbpMlAr5l0H004v1i95a54rZiSIsZ+pYkMVG6IIys= X-Google-Smtp-Source: AGHT+IENMcR5jIX/gXj+EPZjFabTgRcbsQcgq6YQWbyvsrf9KC5wqYnfeWPzcHlh/nwwHxI3zHhcMQ== X-Received: by 2002:a05:600c:458f:b0:428:16a0:1c3d with SMTP id 5b1f17b1804b1-42816a07e88mr61865585e9.19.1722328782375; Tue, 30 Jul 2024 01:39:42 -0700 (PDT) Received: from [192.168.1.20] ([178.197.219.137]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4281c79ea02sm72099245e9.46.2024.07.30.01.39.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jul 2024 01:39:41 -0700 (PDT) Message-ID: Date: Tue, 30 Jul 2024 10:39:40 +0200 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] soundwire: stream: fix programming slave ports for non-continous port maps From: Krzysztof Kozlowski To: Pierre-Louis Bossart , Vinod Koul , Bard Liao , Sanyog Kale , Shreyas NC , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org References: <20240729140157.326450-1-krzysztof.kozlowski@linaro.org> <095d7119-8221-450a-9616-2df6a0df4c77@linux.intel.com> <22b20ad7-8a25-4cb2-a24e-d6841b219977@linaro.org> Content-Language: en-US Autocrypt: add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sUkjheOD4BfWEcVUqa+XdUEciwG/SgNyxBZepj41oVq FPSVE+Ni2tNrW/e16b8mgXNngHSnbsr6pAIXZH3qFW+4TKPMGZ2rZ6zITrMip+12jgw4mGjy 5y06JZvA02rZT2k9aa7i9dUUFggaanI09jNGbRA/ABEBAAHCwXwEGAEKACYCGwwWIQSb0H4O DFH41ZZ3t1Qbk0N9O0FimwUCYDzvagUJFF+UtgAKCRAbk0N9O0Fim9JzD/0auoGtUu4mgnna oEEpQEOjgT7l9TVuO3Qa/SeH+E0m55y5Fjpp6ZToc481za3xAcxK/BtIX5Wn1mQ6+szfrJQ6 59y2io437BeuWIRjQniSxHz1kgtFECiV30yHRgOoQlzUea7FgsnuWdstgfWi6LxstswEzxLZ Sj1EqpXYZE4uLjh6dW292sO+j4LEqPYr53hyV4I2LPmptPE9Rb9yCTAbSUlzgjiyyjuXhcwM qf3lzsm02y7Ooq+ERVKiJzlvLd9tSe4jRx6Z6LMXhB21fa5DGs/tHAcUF35hSJrvMJzPT/+u /oVmYDFZkbLlqs2XpWaVCo2jv8+iHxZZ9FL7F6AHFzqEFdqGnJQqmEApiRqH6b4jRBOgJ+cY qc+rJggwMQcJL9F+oDm3wX47nr6jIsEB5ZftdybIzpMZ5V9v45lUwmdnMrSzZVgC4jRGXzsU EViBQt2CopXtHtYfPAO5nAkIvKSNp3jmGxZw4aTc5xoAZBLo0OV+Ezo71pg3AYvq0a3/oGRG KQ06ztUMRrj8eVtpImjsWCd0bDWRaaR4vqhCHvAG9iWXZu4qh3ipie2Y0oSJygcZT7H3UZxq fyYKiqEmRuqsvv6dcbblD8ZLkz1EVZL6djImH5zc5x8qpVxlA0A0i23v5QvN00m6G9NFF0Le D2GYIS41Kv4Isx2dEFh+/Q== In-Reply-To: <22b20ad7-8a25-4cb2-a24e-d6841b219977@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 30/07/2024 10:23, Krzysztof Kozlowski wrote: > On 29/07/2024 16:25, Pierre-Louis Bossart wrote: >> >> >> On 7/29/24 16:01, Krzysztof Kozlowski wrote: >>> Two bitmasks in 'struct sdw_slave_prop' - 'source_ports' and >>> 'sink_ports' - define which ports to program in >>> sdw_program_slave_port_params(). The masks are used to get the >>> appropriate data port properties ('struct sdw_get_slave_dpn_prop') from >>> an array. >>> >>> Bitmasks can be non-continuous or can start from index different than 0, >>> thus when looking for matching port property for given port, we must >>> iterate over mask bits, not from 0 up to number of ports. >>> >>> This fixes allocation and programming slave ports, when a source or sink >>> masks start from further index. >>> >>> Fixes: f8101c74aa54 ("soundwire: Add Master and Slave port programming") >>> Cc: >>> Signed-off-by: Krzysztof Kozlowski >> >> This is a valid change to optimize how the port are accessed. >> >> But the commit message is not completely clear, the allocation in >> mipi_disco.c is not modified and I don't think there's anything that >> would crash. If there are non-contiguous ports, we will still allocate >> space that will not be initialized/used. >> >> /* Allocate memory for set bits in port lists */ >> nval = hweight32(prop->source_ports); >> prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval, >> sizeof(*prop->src_dpn_prop), >> GFP_KERNEL); >> if (!prop->src_dpn_prop) >> return -ENOMEM; >> >> /* Read dpn properties for source port(s) */ >> sdw_slave_read_dpn(slave, prop->src_dpn_prop, nval, >> prop->source_ports, "source"); >> >> IOW, this is a valid change, but it's an optimization, not a fix in the >> usual sense of 'kernel oops otherwise'. >> >> Am I missing something? >> >> BTW, the notion of DPn is that n > 0. DP0 is a special case with >> different properties, BIT(0) cannot be set for either of the sink/source >> port bitmask. > > I think we speak about two different things. port num > 1, that's > correct. But index for src_dpn_prop array is something different. Look > at mipi-disco sdw_slave_read_dpn(): > > 173 u32 bit, i = 0; > ... > 178 addr = ports; > 179 /* valid ports are 1 to 14 so apply mask */ > 180 addr &= GENMASK(14, 1); > 181 > 182 for_each_set_bit(bit, &addr, 32) { > ... > 186 dpn[i].num = bit; > > > so dpn[0..i] = 1..n > where i is also the bit in the mask. > > Similar implementation was done in Qualcomm wsa and wcd codecs like: > array indexed from 0: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/sound/soc/codecs/wcd938x-sdw.c?h=v6.11-rc1#n51 > > genmask from 0, with a mistake: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/sound/soc/codecs/wcd938x-sdw.c?h=v6.11-rc1#n1255 > > The mistake I corrected here: > https://lore.kernel.org/all/20240726-asoc-wcd-wsa-swr-ports-genmask-v1-0-d4d7a8b56f05@linaro.org/ > > To summarize, the mask does not denote port numbers (1...14) but indices > of the dpn array which are from 0..whatever (usually -1 from port number). > Let me also complete this with a real life example of my work in progress. I want to use same dpn_prop array for sink and source ports and use different masks. The code in progress is: https://git.codelinaro.org/krzysztof.kozlowski/linux/-/commit/ef709a0e8ab2498751305367e945df18d7a05c78#6f965d7b74e712a5cfcbc1cca407b85443a66bac_2147_2157 Without this patch, I get -EINVAL from sdw_get_slave_dpn_prop(): soundwire sdw-master-1-0: Program transport params failed: -22 Best regards, Krzysztof