linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Mark Brown <broonie@kernel.org>
Cc: andy.gross@linaro.org, linux-arm-msm@vger.kernel.org,
	alsa-devel@alsa-project.org, david.brown@linaro.org,
	robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.com,
	plai@codeaurora.org, bgoswami@codeaurora.org, perex@perex.cz,
	tiwai@suse.com, linux-soc@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, rohkumar@qti.qualcomm.com,
	spatakok@qti.qualcomm.com
Subject: Re: [PATCH v3 05/25] ASoC: qcom: qdsp6: Add support to Q6AFE
Date: Fri, 2 Mar 2018 13:13:17 +0000	[thread overview]
Message-ID: <66d37327-b8ea-0da5-3e05-435cec5d84ab@linaro.org> (raw)
In-Reply-To: <20180301205940.GR12864@sirena.org.uk>

Thanks for the review comments,

On 01/03/18 20:59, Mark Brown wrote:
> On Tue, Feb 13, 2018 at 04:58:17PM +0000, srinivas.kandagatla@linaro.org wrote:
> 
>> +// SPDX-License-Identifier: GPL-2.0
>> +#ifndef __DT_BINDINGS_Q6_AFE_H__
>> +#define __DT_BINDINGS_Q6_AFE_H__
>> +
>> +/* Audio Front End (AFE) Ports */
>> +#define AFE_PORT_HDMI_RX	8
>> +
>> +#endif /* __DT_BINDINGS_Q6_AFE_H__ */
> 
> Please use a C++ comment here as well for consistency, it looks more
> intentional.
> 
Yep, I will fix such occurrences in next version.

>> +config SND_SOC_QDSP6_AFE
>> +	tristate
>> +	default n
>> +
> 
> n is the default anyway, no need to specify it (I know some uses already
> slipped through here but it'd be better to fix those).
> 
>> index 000000000000..0a5af06bb50e
>> --- /dev/null
>> +++ b/sound/soc/qcom/qdsp6/q6afe.c
>> @@ -0,0 +1,520 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (c) 2011-2017, The Linux Foundation
>> + * Copyright (c) 2018, Linaro Limited
>> + */
> 
Yep, I will fix this, I think I picked this up variant while this was 
still being discussed. I will fix all such occurrences.

> Same here with the comment, just make the whole comment a C++ comment
> rather than having one comment using both styles.  Similar things apply
> elsewhere.
> 
>> +/* Port map of index vs real hw port ids */
>> +static struct afe_port_map port_maps[AFE_PORT_MAX] = {
>> +	[AFE_PORT_HDMI_RX] = { AFE_PORT_ID_MULTICHAN_HDMI_RX,
>> +				AFE_PORT_HDMI_RX, 1, 1},
>> +};
> 
> Is this not device specific in any way?  It looks likely to be.
It is specific to Audio firmware build.
AFAIK, DSP port IDs are consistent across a given range of AVS firmware 
builds. So far I have seen them not change in any of the B family SoCs.
However on older A family SOCs these are very different numbers. Which 
is where ADSP version info would help select correct map.

> 
>> +static struct q6afe_port *afe_find_port(struct q6afe *afe, int token)
>> +{
>> +	struct q6afe_port *p = NULL;
>> +
>> +	spin_lock(&afe->port_list_lock);
>> +	list_for_each_entry(p, &afe->port_list, node)
>> +		if (p->token == token)
>> +			break;
>> +
>> +	spin_unlock(&afe->port_list_lock);
> 
> Why do we need to lock the port list, what are we protecting it against?

This is just to protect the list from anyone deleting this.

Its very rare but the use case could be somelike the adsp is up and we 
are in the middle of finding a port and then adsp went down or crashed 
we would delete an entry in the list.

> We don't write here which suggests either there's some kind of race
> condition in this lookup or the lock is not doing anything.
> 
>> +static int afe_callback(struct apr_device *adev,
>> +			struct apr_client_message *data)
>> +{
>> +	struct q6afe *afe = dev_get_drvdata(&adev->dev);
>> +	struct aprv2_ibasic_rsp_result_t *res;
>> +	struct q6afe_port *port;
>> +
>> +	if (!data->payload_size)
>> +		return 0;
>> +
>> +	res = data->payload;
>> +	if (data->opcode == APR_BASIC_RSP_RESULT) {
>> +		if (res->status) {
> 
> Shouldn't we use a switch statement here in case we want to handle
> something else?

Yep, I will fix this.

> 
>> +		switch (res->opcode) {
>> +		case AFE_PORT_CMD_SET_PARAM_V2:
>> +		case AFE_PORT_CMD_DEVICE_STOP:
>> +		case AFE_PORT_CMD_DEVICE_START:
>> +			afe->state = AFE_CMD_RESP_AVAIL;
>> +			port = afe_find_port(afe, data->token);
>> +			if (port)
>> +				wake_up(&port->wait);
> 
> No locking here?  It seems a bit odd that the AFE global state is being
> set to say there's a response available but we wake a specific port.
> 

This callback is invoked in interrupt context and sends are serialized 
at afe level.

Yep, It does not make sense to have a global state, I will fix this by 
making this state specific to port.

>> +	ret = apr_send_pkt(afe->apr, data);
>> +	if (ret < 0) {
>> +		dev_err(afe->dev, "packet not transmitted\n");
>> +		ret = -EINVAL;
>> +		goto err;
> 
> Why squash the error code here?  We don't even print it.
Will fix this in next version.
> 
>> +	}
>> +
>> +	ret = wait_event_timeout(*wait, (afe->state == AFE_CMD_RESP_AVAIL),
>> +				 msecs_to_jiffies(TIMEOUT_MS));
>> +	if (!ret) {
>> +		ret = -ETIMEDOUT;
>> +	} else if (afe->status > 0) {
>> +		dev_err(afe->dev, "DSP returned error[%s]\n",
>> +		       q6dsp_strerror(afe->status));
>> +		ret = q6dsp_errno(afe->status);
> 
> If we time out here and the DSP delivers a response later it looks like
> we'll get data corruption - the DSP will happily deliver the response
> into shared state.
> 
If I make this state specific to port, we could handle this case much 
cleanly.

>> +static int afe_port_start(struct q6afe_port *port,
>> +			  union afe_port_config *afe_config)
>> +{
>> +	struct afe_audioif_config_command config = {0,};
>> +	struct q6afe *afe = port->afe;
>> +	int port_id = port->id;
>> +	int ret, param_id = port->cfg_type;
>> +
>> +	config.port = *afe_config;
>> +
>> +	ret  = q6afe_port_set_param_v2(port, &config, param_id,
>> +				       sizeof(*afe_config));
>> +	if (ret) {
>> +		dev_err(afe->dev, "AFE enable for port 0x%x failed %d\n",
>> +			port_id, ret);
>> +		return ret;
>> +	}
>> +	return afe_send_cmd_port_start(port);
> 
> Why not just inline this function here?  It appears to have only this
> user.
Will do that.

> 
>> +	int index = 0;
> 
> We set index to 0...
does not make sense, will remove this initialization.
>> +
>> +	port_id = port->id;
>> +	index = port->token;
> 
> ...the unconditionally overwrite it?
> 
>> +/**
>> + * q6afe_port_start() - Start a afe port
>> + *
>> + * @port: Instance of port to start
>> + *
>> + * Return: Will be an negative on packet size on success.
>> + */
>> +int q6afe_port_start(struct q6afe_port *port)
>> +{
>> +	return afe_port_start(port, &port->port_cfg);
>> +}
>> +EXPORT_SYMBOL_GPL(q6afe_port_start);
> 
> This is the third level of wrapper for the port start command in this
> file.  Do we *really* need all these wrappers?

Intention here is that we have plans to support different version of 
ADSP, on A family this command is different, so having this wrapper 
would help tackle this use-case.
> 
>> +struct q6afe_port *q6afe_port_get_from_id(struct device *dev, int id)
>> +{
> 
>> +	port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
>> +	if (!port)
>> +		return ERR_PTR(-ENOMEM);
> 
> The _port_get_ function is allocating data but...
> 
>> +/**
>> + * q6afe_port_put() - Release port reference
>> + *
>> + * @port: Instance of port to put
>> + */
>> +void q6afe_port_put(struct q6afe_port *port)
>> +{
>> +	struct q6afe *afe = port->afe;
>> +
>> +	spin_lock(&afe->port_list_lock);
>> +	list_del(&port->node);
>> +	spin_unlock(&afe->port_list_lock);
>> +}
>> +EXPORT_SYMBOL_GPL(q6afe_port_put);
> 
> ...the _port_put() function isn't freeing it.  That seems leaky.  I'm

Yes, I can probably free it here instead of depending on device core to 
do that.

> also a bit worried about this being a spinlock that we're using for
> allocation, and not even spin_lock_irqsave().  Presumably this is
> protecting against interrupts otherwise we'd not need a spinlock but
> for that to work we'd need the _irqsave()?
Yes, I need to use _irqsave/restore variant here, Will fix that in next 
version,
> 
Thanks,
Srini

  reply	other threads:[~2018-03-02 13:13 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13 16:58 [PATCH v3 00/25] ASoC: qcom: Add support to QDSP based Audio srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 01/25] dt-bindings: soc: qcom: Add bindings for APR bus srinivas.kandagatla
2018-02-13 23:12   ` Rob Herring
2018-02-14  9:13     ` Srinivas Kandagatla
2018-02-18 23:04       ` Rob Herring
2018-02-20  9:33         ` Srinivas Kandagatla
2018-02-22  0:14           ` Rob Herring
2018-02-22 10:03             ` Srinivas Kandagatla
2018-02-28 18:55               ` Srinivas Kandagatla
2018-03-01 20:34               ` Mark Brown
2018-03-02 13:13                 ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 02/25] soc: qcom: add support to APR bus driver srinivas.kandagatla
2018-02-19  3:08   ` Rob Herring
2018-02-20  9:33     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 03/25] ASoC: qcom: qdsp6: Add common qdsp6 helper functions srinivas.kandagatla
2018-03-01 21:04   ` Mark Brown
2018-02-13 16:58 ` [PATCH v3 04/25] dt-bindings: sound: qcom: Add bindings for q6afe srinivas.kandagatla
2018-03-01 20:41   ` Mark Brown
2018-02-13 16:58 ` [PATCH v3 05/25] ASoC: qcom: qdsp6: Add support to Q6AFE srinivas.kandagatla
2018-02-19 10:30   ` [alsa-devel] " Rohit Kumar
2018-02-20  9:34     ` Srinivas Kandagatla
2018-03-01 20:42     ` Mark Brown
2018-03-01 20:59   ` Mark Brown
2018-03-02 13:13     ` Srinivas Kandagatla [this message]
2018-03-02 17:54       ` Mark Brown
2018-03-02 18:51         ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 06/25] dt-bindings: sound: qcom: Add bindings for q6adm srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 07/25] ASoC: qcom: qdsp6: Add support to Q6ADM srinivas.kandagatla
2018-03-01 21:24   ` Mark Brown
2018-03-06  9:26     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 08/25] dt-bindings: sound: qcom: Add bindings for q6asm srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 09/25] ASoC: qcom: qdsp6: Add support to Q6ASM srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 10/25] ASoC: qcom: q6asm: Add support to memory map and unmap srinivas.kandagatla
2018-03-01 21:28   ` Mark Brown
2018-03-06  9:26     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 11/25] ASoC: qcom: q6asm: add support to audio stream apis srinivas.kandagatla
2018-03-01 21:33   ` Mark Brown
2018-03-06  9:26     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 12/25] ASoC: qcom: qdsp6: Add support to Q6CORE srinivas.kandagatla
2018-02-19 10:33   ` [alsa-devel] " Rohit Kumar
2018-02-13 16:58 ` [PATCH v3 13/25] ASoC: qcom: qdsp6: Add support to q6routing driver srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 14/25] ASoC: qcom: qdsp6: Add support to q6afe dai driver srinivas.kandagatla
2018-02-19 10:32   ` [alsa-devel] " Rohit Kumar
2018-02-20  9:36     ` Srinivas Kandagatla
2018-03-02 12:50   ` Mark Brown
2018-03-02 13:52     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 15/25] ASoC: qcom: qdsp6: Add support to q6asm " srinivas.kandagatla
2018-02-21 11:14   ` [alsa-devel] " Rohit Kumar
2018-02-22 11:16     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 16/25] ASoC: qcom: q6afe: add SLIMBus port Support srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 17/25] ASoC: qcom: q6afe-dai: add support to slim afe dais srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 18/25] ASoC: qcom: q6routing: add support to all SLIMBus Mixers srinivas.kandagatla
2018-05-21 15:47   ` Applied "ASoC: qdsp6: q6routing: Add support to all SLIMBus Mixers" to the asoc tree Mark Brown
2018-02-13 16:58 ` [PATCH v3 19/25] ASoC: qcom: q6afe: add support to MI2S ports srinivas.kandagatla
2018-03-07  9:35   ` [alsa-devel] " Rohit Kumar
2018-02-13 16:58 ` [PATCH v3 20/25] ASoC: qcom: q6afe: add support to MI2S sysclks srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 21/25] ASoC: qcom: q6afe-dai: add support to 4 MI2S ports srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 22/25] ASoC: qcom: q6routing: add support to MI2S Mixers srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 23/25] dt-bindings: sound: qcom: Add devicetree bindings for apq8096 srinivas.kandagatla
2018-02-13 16:58 ` [PATCH v3 24/25] ASoC: qcom: apq8096: Add db820c machine driver srinivas.kandagatla
2018-02-22 11:00   ` [alsa-devel] " Rohit Kumar
2018-02-22 11:13     ` Srinivas Kandagatla
2018-02-13 16:58 ` [PATCH v3 25/25] arm64: dts: msm8996: db820c: Add sound card support srinivas.kandagatla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=66d37327-b8ea-0da5-3e05-435cec5d84ab@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=andy.gross@linaro.org \
    --cc=bgoswami@codeaurora.org \
    --cc=broonie@kernel.org \
    --cc=david.brown@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-soc@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=perex@perex.cz \
    --cc=plai@codeaurora.org \
    --cc=robh+dt@kernel.org \
    --cc=rohkumar@qti.qualcomm.com \
    --cc=spatakok@qti.qualcomm.com \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).