Re: [PATCH 32/36] usb: gadget: f_tcm: Send sense reason

Dmitry Bogdanov
2022-07-08T07:35:56Z

On Wed, Jul 06, 2022 at 04:37:43PM -0700, Thinh Nguyen wrote:
> If there's a failure, report it back to the host with a sense reason.
>
> Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> ---
> drivers/usb/gadget/function/f_tcm.c | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
> index 7162be5fdf2f..fb9b71158c4b 100644
> --- a/drivers/usb/gadget/function/f_tcm.c
> +++ b/drivers/usb/gadget/function/f_tcm.c
> @@ -669,6 +669,9 @@ static int uasp_send_read_response(struct usbg_cmd *cmd)
> pr_err("%s(%d) => %d\n", __func__, __LINE__, ret);
> }
> out:
> + if (ret)
> + transport_send_check_condition_and_sense(&cmd->se_cmd,
> + TCM_CHECK_CONDITION_UNIT_ATTENTION, 0);
> return ret;
> }
>
> @@ -711,6 +714,9 @@ static int uasp_send_write_request(struct usbg_cmd *cmd)
> }
>
> cleanup:
> + if (ret)
> + transport_send_check_condition_and_sense(&cmd->se_cmd,
> + TCM_CHECK_CONDITION_UNIT_ATTENTION, 0);
1. TCM_CHECK_CONDITION_UNIT_ATTENTION is used if some UA is allocated.
You do not have UA allocated here, so that reason is not apropriate.
2. I am not sure that it's ok to initiate sending failure response if
you cannot send a response right now.
Other fabric drivers just returns -EAGAIN in case of some lack of
resources to send a response. Then TCM Core will retry to sent that
response again.
> return ret;
> }
>
> @@ -955,7 +961,15 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req)
> return;
>
> cleanup:
> - transport_generic_free_cmd(&cmd->se_cmd, 0);
> + /* Command was aborted */
> + if (cmd->state == UASP_QUEUE_COMMAND) {
> + transport_generic_free_cmd(se_cmd, 0);
> + return;
> + }
> +
> + cmd->state = UASP_QUEUE_COMMAND;
> + transport_send_check_condition_and_sense(se_cmd,
> + TCM_CHECK_CONDITION_UNIT_ATTENTION, 0);
> }
>
> static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req)