From patchwork Mon Sep 6 11:27:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12476821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6BA2C433F5 for ; Mon, 6 Sep 2021 11:27:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9676F60FBF for ; Mon, 6 Sep 2021 11:27:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237454AbhIFL2y (ORCPT ); Mon, 6 Sep 2021 07:28:54 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:41197 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234323AbhIFL2x (ORCPT ); Mon, 6 Sep 2021 07:28:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1630927669; x=1662463669; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tpxjbdn7wyxmcwO7JjDLFRAFM8X8qALV1qys2NEDpbE=; b=EbNKWz5ydDSlD2Gy376csVyrGGvfixjDH+MANgbE14f/kjnX3r1xqjo/ uiPxT0xhk8v7SyUT3O4gURYTlTBJg8eeJBG0+t5G5eWo334AIaNidU4QN WFKtbXCc0e8/sk2OajITfptatT3Pf+TVCi0/Two0kHR9vNddUVk5x9jI0 s=; Received: from ironmsg08-lv.qualcomm.com ([10.47.202.152]) by alexa-out.qualcomm.com with ESMTP; 06 Sep 2021 04:27:49 -0700 X-QCInternal: smtphost Received: from nalasex01b.na.qualcomm.com ([10.47.209.197]) by ironmsg08-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2021 04:27:49 -0700 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Mon, 6 Sep 2021 04:27:47 -0700 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Linyu Yuan Subject: [PATCH v4 1/3] usb: gadget: configfs: avoid list move operation of usb_function Date: Mon, 6 Sep 2021 19:27:39 +0800 Message-ID: <1630927661-11307-2-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630927661-11307-1-git-send-email-quic_linyyuan@quicinc.com> References: <1630927661-11307-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org add a new list which link all usb_function at configfs layers, it means that after link a function a configuration, from configfs layer, we can still found all functions, it will allow trace all functions from configfs. Reported-by: kernel test robot Signed-off-by: Linyu Yuan --- v2: fix unused cfg variable warning v3: add struct inside configfs.c v4: no change drivers/usb/gadget/configfs.c | 52 ++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 477e72a..88d6bcc 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -58,6 +58,11 @@ static inline struct gadget_info *to_gadget_info(struct config_item *item) return container_of(to_config_group(item), struct gadget_info, group); } +struct config_usb_function { + struct list_head list; + struct usb_function *f; +}; + struct config_usb_cfg { struct config_group group; struct config_group strings_group; @@ -420,7 +425,7 @@ static int config_usb_cfg_link( struct usb_function_instance *fi = container_of(group, struct usb_function_instance, group); struct usb_function_instance *a_fi; - struct usb_function *f; + struct config_usb_function *cf; int ret; mutex_lock(&gi->lock); @@ -438,21 +443,29 @@ static int config_usb_cfg_link( goto out; } - list_for_each_entry(f, &cfg->func_list, list) { - if (f->fi == fi) { + list_for_each_entry(cf, &cfg->func_list, list) { + if (cf->f->fi == fi) { ret = -EEXIST; goto out; } } - f = usb_get_function(fi); - if (IS_ERR(f)) { - ret = PTR_ERR(f); + cf = kzalloc(sizeof(*cf), GFP_KERNEL); + if (!cf) { + ret = -ENOMEM; + goto out; + } + INIT_LIST_HEAD(&cf->list); + + cf->f = usb_get_function(fi); + if (IS_ERR(cf->f)) { + ret = PTR_ERR(cf->f); + kfree(cf); goto out; } /* stash the function until we bind it to the gadget */ - list_add_tail(&f->list, &cfg->func_list); + list_add_tail(&cf->list, &cfg->func_list); ret = 0; out: mutex_unlock(&gi->lock); @@ -470,7 +483,7 @@ static void config_usb_cfg_unlink( struct config_group *group = to_config_group(usb_func_ci); struct usb_function_instance *fi = container_of(group, struct usb_function_instance, group); - struct usb_function *f; + struct config_usb_function *cf; /* * ideally I would like to forbid to unlink functions while a gadget is @@ -483,10 +496,11 @@ static void config_usb_cfg_unlink( unregister_gadget(gi); WARN_ON(gi->composite.gadget_driver.udc_name); - list_for_each_entry(f, &cfg->func_list, list) { - if (f->fi == fi) { - list_del(&f->list); - usb_put_function(f); + list_for_each_entry(cf, &cfg->func_list, list) { + if (cf->f->fi == fi) { + list_del(&cf->list); + usb_put_function(cf->f); + kfree(cf); mutex_unlock(&gi->lock); return; } @@ -1263,7 +1277,7 @@ static void purge_configs_funcs(struct gadget_info *gi) list_for_each_entry_safe_reverse(f, tmp, &c->functions, list) { - list_move(&f->list, &cfg->func_list); + list_del(&f->list); if (f->unbind) { dev_dbg(&gi->cdev.gadget->dev, "unbind function '%s'/%p\n", @@ -1371,8 +1385,7 @@ static int configfs_composite_bind(struct usb_gadget *gadget, /* Go through all configs, attach all functions */ list_for_each_entry(c, &gi->cdev.configs, list) { struct config_usb_cfg *cfg; - struct usb_function *f; - struct usb_function *tmp; + struct config_usb_function *cf, *tmp; struct gadget_config_name *cn; if (gadget_is_otg(gadget)) @@ -1396,13 +1409,10 @@ static int configfs_composite_bind(struct usb_gadget *gadget, c->iConfiguration = s[0].id; } - list_for_each_entry_safe(f, tmp, &cfg->func_list, list) { - list_del(&f->list); - ret = usb_add_function(c, f); - if (ret) { - list_add(&f->list, &cfg->func_list); + list_for_each_entry_safe(cf, tmp, &cfg->func_list, list) { + ret = usb_add_function(c, cf->f); + if (ret) goto err_purge_funcs; - } } ret = usb_gadget_check_config(cdev->gadget); if (ret) From patchwork Mon Sep 6 11:27:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12476823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63538C433EF for ; Mon, 6 Sep 2021 11:27:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D06560FBF for ; Mon, 6 Sep 2021 11:27:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238264AbhIFL24 (ORCPT ); Mon, 6 Sep 2021 07:28:56 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:41197 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234323AbhIFL24 (ORCPT ); Mon, 6 Sep 2021 07:28:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1630927672; x=1662463672; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eIAMMBuDhSWC/qjUh6+8nowHYz3d7LJiEygLtxkKlQU=; b=DiiKF/EWK8W+Bfprbl0k1gFo1yKVPwAhhbfnaAfrG13baA/mB6yLOHTY PYPPo4U89v0QbHeJuvE5V2sarFR5kfweYOQHbvJA8IDwZvb1MQhCVsECf +6BUGafJ6XvfCwvMYrzC4S4+fujR6qKXNHk4EHz5zab2AV2yCB9Hi6aw5 A=; Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 06 Sep 2021 04:27:52 -0700 X-QCInternal: smtphost Received: from nalasex01b.na.qualcomm.com ([10.47.209.197]) by ironmsg09-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2021 04:27:52 -0700 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Mon, 6 Sep 2021 04:27:50 -0700 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Linyu Yuan Subject: [PATCH v4 2/3] usb: gadget: configfs: add gadget_info for config group Date: Mon, 6 Sep 2021 19:27:40 +0800 Message-ID: <1630927661-11307-3-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630927661-11307-1-git-send-email-quic_linyyuan@quicinc.com> References: <1630927661-11307-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org add gadget_info pointer in struct config_usb_cfg to allow common gadget info trace from configfs layer. Signed-off-by: Linyu Yuan --- v2: no change v3: change struct inside configfs.c v4: no change drivers/usb/gadget/configfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 88d6bcc..f766756 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -70,6 +70,7 @@ struct config_usb_cfg { struct usb_configuration c; struct list_head func_list; struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1]; + struct gadget_info *gi; }; static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item) @@ -418,8 +419,7 @@ static int config_usb_cfg_link( struct config_item *usb_func_ci) { struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci); - struct usb_composite_dev *cdev = cfg->c.cdev; - struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev); + struct gadget_info *gi = cfg->gi; struct config_group *group = to_config_group(usb_func_ci); struct usb_function_instance *fi = container_of(group, @@ -477,8 +477,7 @@ static void config_usb_cfg_unlink( struct config_item *usb_func_ci) { struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci); - struct usb_composite_dev *cdev = cfg->c.cdev; - struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev); + struct gadget_info *gi = cfg->gi; struct config_group *group = to_config_group(usb_func_ci); struct usb_function_instance *fi = container_of(group, @@ -717,6 +716,7 @@ static struct config_group *config_desc_make( cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); if (!cfg) return ERR_PTR(-ENOMEM); + cfg->gi = gi; cfg->c.label = kstrdup(buf, GFP_KERNEL); if (!cfg->c.label) { ret = -ENOMEM; From patchwork Mon Sep 6 11:27:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linyu Yuan X-Patchwork-Id: 12476825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4EA4C433EF for ; Mon, 6 Sep 2021 11:27:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3F6260F43 for ; Mon, 6 Sep 2021 11:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238850AbhIFL27 (ORCPT ); Mon, 6 Sep 2021 07:28:59 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:57366 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234323AbhIFL26 (ORCPT ); Mon, 6 Sep 2021 07:28:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1630927675; x=1662463675; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DkScUZbo3DAiUBuhXNO1inQy2bWAI2hdsuadQEdOJzE=; b=tRua2WL2FGoGOUIFkZTafttVLcJ8zNbPVJ6Db9subF5nqCErTeFQCSpK SZw/MXK6uiPLFNPIYFd1E07gasL0D65ZCkhTph5eMnnCU1dTtD1CzQ9Qd pCf7DIs9qNYB0byq8XEO6xcTrTrJWwys0haY6GdW5yWaBKOoEh/+aUZVm c=; Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 06 Sep 2021 04:27:54 -0700 X-QCInternal: smtphost Received: from nalasex01b.na.qualcomm.com ([10.47.209.197]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2021 04:27:54 -0700 Received: from linyyuan-gv.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Mon, 6 Sep 2021 04:27:52 -0700 From: Linyu Yuan To: Felipe Balbi , Greg Kroah-Hartman CC: , Linyu Yuan Subject: [PATCH v4 3/3] usb: gadget: configfs: add some trace event Date: Mon, 6 Sep 2021 19:27:41 +0800 Message-ID: <1630927661-11307-4-git-send-email-quic_linyyuan@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1630927661-11307-1-git-send-email-quic_linyyuan@quicinc.com> References: <1630927661-11307-1-git-send-email-quic_linyyuan@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org add UDC, cfg link/unlink and some attributes trace to better trace gadget issues. Suggested-by: Felipe Balbi Signed-off-by: Linyu Yuan --- v3: build trace inside configfs.c v4: no change drivers/usb/gadget/configfs.c | 54 ++++++++++++ drivers/usb/gadget/configfs_trace.h | 167 ++++++++++++++++++++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 drivers/usb/gadget/configfs_trace.h diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index f766756..509daf5 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -103,6 +103,42 @@ struct gadget_config_name { struct list_head list; }; +#define MAX_CONFIGURAITON_STR_LEN 512 + +static char *config_trace_string(struct gadget_info *gi) +{ + struct usb_configuration *uc; + struct config_usb_cfg *cfg; + struct config_usb_function *cf; + static char trs[MAX_CONFIGURAITON_STR_LEN]; + size_t len = MAX_CONFIGURAITON_STR_LEN; + int n = 0; + + trs[0] = '\0'; + + list_for_each_entry(uc, &gi->cdev.configs, list) { + cfg = container_of(uc, struct config_usb_cfg, c); + + n += scnprintf(trs + n, len - n, + "group:%s,bConfigurationValue:%d,bmAttributes:%d," + "MaxPower:%d,", + config_item_name(&cfg->group.cg_item), + uc->bConfigurationValue, + uc->bmAttributes, + uc->MaxPower); + + n += scnprintf(trs + n, len - n, "function:["); + list_for_each_entry(cf, &cfg->func_list, list) + n += scnprintf(trs + n, len - n, "%s", cf->f->name); + n += scnprintf(trs + n, len - n, "},"); + } + + return trs; +} + +#define CREATE_TRACE_POINTS +#include "configfs_trace.h" + #define USB_MAX_STRING_WITH_NULL_LEN (USB_MAX_STRING_LEN+1) static int usb_string_copy(const char *s, char **s_copy) @@ -210,6 +246,7 @@ static ssize_t gadget_dev_desc_bcdDevice_store(struct config_item *item, if (ret) return ret; + trace_gadget_dev_desc_bcdDevice_store(to_gadget_info(item)); to_gadget_info(item)->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice); return len; } @@ -228,6 +265,7 @@ static ssize_t gadget_dev_desc_bcdUSB_store(struct config_item *item, return ret; to_gadget_info(item)->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB); + trace_gadget_dev_desc_bcdUSB_store(to_gadget_info(item)); return len; } @@ -240,6 +278,7 @@ static ssize_t gadget_dev_desc_UDC_show(struct config_item *item, char *page) mutex_lock(&gi->lock); udc_name = gi->composite.gadget_driver.udc_name; ret = sprintf(page, "%s\n", udc_name ?: ""); + trace_gadget_dev_desc_UDC_show(gi); mutex_unlock(&gi->lock); return ret; @@ -249,6 +288,7 @@ static int unregister_gadget(struct gadget_info *gi) { int ret; + trace_unregister_gadget(gi); if (!gi->composite.gadget_driver.udc_name) return -ENODEV; @@ -276,6 +316,8 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item, if (name[len - 1] == '\n') name[len - 1] = '\0'; + trace_gadget_dev_desc_UDC_store(gi); + mutex_lock(&gi->lock); if (!strlen(name)) { @@ -296,6 +338,8 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item, } } mutex_unlock(&gi->lock); + + trace_gadget_dev_desc_UDC_store(gi); return len; err: kfree(name); @@ -308,6 +352,7 @@ static ssize_t gadget_dev_desc_max_speed_show(struct config_item *item, { enum usb_device_speed speed = to_gadget_info(item)->composite.max_speed; + trace_gadget_dev_desc_max_speed_show(to_gadget_info(item)); return sprintf(page, "%s\n", usb_speed_string(speed)); } @@ -337,6 +382,8 @@ static ssize_t gadget_dev_desc_max_speed_store(struct config_item *item, gi->composite.gadget_driver.max_speed = gi->composite.max_speed; + trace_gadget_dev_desc_max_speed_store(gi); + mutex_unlock(&gi->lock); return len; err: @@ -468,6 +515,7 @@ static int config_usb_cfg_link( list_add_tail(&cf->list, &cfg->func_list); ret = 0; out: + trace_config_usb_cfg_link(gi); mutex_unlock(&gi->lock); return ret; } @@ -500,10 +548,12 @@ static void config_usb_cfg_unlink( list_del(&cf->list); usb_put_function(cf->f); kfree(cf); + trace_config_usb_cfg_unlink(gi); mutex_unlock(&gi->lock); return; } } + trace_config_usb_cfg_unlink(gi); mutex_unlock(&gi->lock); WARN(1, "Unable to locate function to unbind\n"); } @@ -518,6 +568,7 @@ static struct configfs_item_operations gadget_config_item_ops = { static ssize_t gadget_config_desc_MaxPower_show(struct config_item *item, char *page) { + trace_gadget_config_desc_MaxPower_show(to_config_usb_cfg(item)->gi); return sprintf(page, "%u\n", to_config_usb_cfg(item)->c.MaxPower); } @@ -532,12 +583,14 @@ static ssize_t gadget_config_desc_MaxPower_store(struct config_item *item, if (DIV_ROUND_UP(val, 8) > 0xff) return -ERANGE; to_config_usb_cfg(item)->c.MaxPower = val; + trace_gadget_config_desc_MaxPower_store(to_config_usb_cfg(item)->gi); return len; } static ssize_t gadget_config_desc_bmAttributes_show(struct config_item *item, char *page) { + trace_gadget_config_desc_bmAttributes_show(to_config_usb_cfg(item)->gi); return sprintf(page, "0x%02x\n", to_config_usb_cfg(item)->c.bmAttributes); } @@ -556,6 +609,7 @@ static ssize_t gadget_config_desc_bmAttributes_store(struct config_item *item, USB_CONFIG_ATT_WAKEUP)) return -EINVAL; to_config_usb_cfg(item)->c.bmAttributes = val; + trace_gadget_config_desc_bmAttributes_store(to_config_usb_cfg(item)->gi); return len; } diff --git a/drivers/usb/gadget/configfs_trace.h b/drivers/usb/gadget/configfs_trace.h new file mode 100644 index 0000000..04df1b9 --- /dev/null +++ b/drivers/usb/gadget/configfs_trace.h @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM configfs_gadget + +#if !defined(__GADGET_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define __GADGET_TRACE_H + +#include + +DECLARE_EVENT_CLASS(log_gadget_info, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi), + TP_STRUCT__entry( + /* gadget_info */ + __string(gi_group, config_item_name(&gi->group.cg_item)) + __field(bool, unbind) + __field(bool, use_os_desc) + __field(char, b_vendor_code) + + /* usb_composite_dev */ + __field(bool, suspended) + __field(bool, setup_pending) + __field(bool, os_desc_pending) + __field(unsigned, deactivations) + __field(int, delayed_status) + __field(__le16, bcdUSB) + __field(__le16, bcdDevice) + __string(config, gi->cdev.config) + + /* usb_composite_driver */ + __field(unsigned, max_speed) + __field(bool, needs_serial) + + /* usb_gadget_driver */ + __string(udc_name, gi->composite.gadget_driver.udc_name) + ), + TP_fast_assign( + __assign_str(gi_group, config_item_name(&gi->group.cg_item)); + __entry->unbind = gi->unbind; + __entry->use_os_desc = gi->use_os_desc; + __entry->b_vendor_code = gi->b_vendor_code; + + __entry->suspended = gi->cdev.suspended; + __entry->setup_pending = gi->cdev.setup_pending; + __entry->os_desc_pending = gi->cdev.os_desc_pending; + __entry->deactivations = gi->cdev.deactivations; + __entry->delayed_status = gi->cdev.delayed_status; + __entry->bcdUSB = le16_to_cpu(gi->cdev.desc.bcdUSB); + __entry->bcdDevice = le16_to_cpu(gi->cdev.desc.bcdDevice); + __assign_str(config, config_trace_string(gi)); + + __entry->max_speed = gi->composite.max_speed; + __entry->needs_serial = gi->composite.needs_serial; + + __assign_str(udc_name, gi->composite.gadget_driver.udc_name); + ), + TP_printk("gi_group:%s,unbind:%d,use_os_desc:%d,b_vendor_code:%d," + " - " + "suspended:%d,setup_pending:%d," + "os_desc_pending:%d,deactivations:%d,delayed_status:%d," + "bcdUSB:%04x,bcdDevice:%04x,config:%s," + " - " + "max_speed:%d,needs_serial:%d," + " - " + "udc_name:%s", + + __get_str(gi_group), + __entry->unbind, + __entry->use_os_desc, + __entry->b_vendor_code, + + __entry->suspended, + __entry->setup_pending, + __entry->os_desc_pending, + __entry->deactivations, + __entry->delayed_status, + __entry->bcdUSB, + __entry->bcdDevice, + __get_str(config), + + __entry->max_speed, + __entry->needs_serial, + + __get_str(udc_name) + ) +); + +DEFINE_EVENT(log_gadget_info, gadget_dev_desc_bcdDevice_store, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_dev_desc_bcdUSB_store, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_dev_desc_UDC_show, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, unregister_gadget, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_dev_desc_UDC_store, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_dev_desc_max_speed_show, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_dev_desc_max_speed_store, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, config_usb_cfg_link, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, config_usb_cfg_unlink, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_config_desc_MaxPower_show, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_config_desc_MaxPower_store, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_config_desc_bmAttributes_show, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +DEFINE_EVENT(log_gadget_info, gadget_config_desc_bmAttributes_store, + TP_PROTO(struct gadget_info *gi), + TP_ARGS(gi) +); + +#endif /* __GADGET_TRACE_H */ + +/* this part has to be here */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH ../../drivers/usb/gadget + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE configfs_trace + +#include