From: Linyu Yuan <quic_linyyuan@quicinc.com>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Peter Chen <peter.chen@kernel.org>,
Pawel Laszczak <pawell@cadence.com>,
Roger Quadros <rogerq@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Chunfeng Yun <chunfeng.yun@mediatek.com>,
Neal Liu <neal_liu@aspeedtech.com>,
"Cristian Birsan" <cristian.birsan@microchip.com>,
Bin Liu <b-liu@ti.com>, "Kevin Cernekee" <cernekee@gmail.com>,
Justin Chen <justin.chen@broadcom.com>,
"Al Cooper" <alcooperx@gmail.com>, Li Yang <leoyang.li@nxp.com>,
"Vladimir Zapolskiy" <vz@mleia.com>,
Daniel Mack <daniel@zonque.org>,
Haojian Zhuang <haojian.zhuang@gmail.com>,
Robert Jarzmik <robert.jarzmik@free.fr>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
Herve Codina <herve.codina@bootlin.com>,
hierry Reding <thierry.reding@gmail.com>,
Jonathan Hunter <jonathanh@nvidia.com>,
Michal Simek <michal.simek@amd.com>,
Rui Miguel Silva <rui.silva@linaro.org>,
Valentina Manea <valentina.manea.m@gmail.com>,
"Shuah Khan" <shuah@kernel.org>, Hongren Zheng <i@zenithal.me>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>, Linyu Yuan <quic_linyyuan@quicinc.com>
Subject: [PATCH v3 03/10] usb: gadget: add anonymous definition in struct usb_ep
Date: Tue, 12 Sep 2023 18:44:48 +0800 [thread overview]
Message-ID: <20230912104455.7737-4-quic_linyyuan@quicinc.com> (raw)
In-Reply-To: <20230912104455.7737-1-quic_linyyuan@quicinc.com>
Some UDC trace event will save usb endpoint information, but it will use
one int size buffer to save one bit information of usb endpoint, so more
than one int buffer to save several bit fields which is not good.
Add some anonymous union have three u32 members which can be used by trace
event during fast assign stage to reduce trace buffer usage, and add
related macro to extract bit fields from u32 members for later trace event
output state usage.
Also move exist maxpacket and other bit field into anonymous struct which
inside anonymous union and Change them from unsigned to u32 type.
Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
---
v2: no change
v3: change method to extract bit field
include/linux/usb/gadget.h | 106 +++++++++++++++++++++++++++++++------
1 file changed, 90 insertions(+), 16 deletions(-)
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index a1717c633942..1b63843f5c31 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -194,13 +194,14 @@ struct usb_ep_ops {
* @dir_out:Endpoint supports OUT direction.
*/
struct usb_ep_caps {
- unsigned type_control:1;
- unsigned type_iso:1;
- unsigned type_bulk:1;
- unsigned type_int:1;
- unsigned dir_in:1;
- unsigned dir_out:1;
-};
+ u8 type_control:1;
+ u8 type_iso:1;
+ u8 type_bulk:1;
+ u8 type_int:1;
+ u8 dir_in:1;
+ u8 dir_out:1;
+ u8 reserve:2;
+} __packed;
#define USB_EP_CAPS_TYPE_CONTROL 0x01
#define USB_EP_CAPS_TYPE_ISO 0x02
@@ -230,6 +231,9 @@ struct usb_ep_caps {
* @caps:The structure describing types and directions supported by endpoint.
* @enabled: The current endpoint enabled/disabled state.
* @claimed: True if this endpoint is claimed by a function.
+ * @dw1: trace event purpose
+ * @dw2: trace event purpose
+ * @dw3: trace event purpose
* @maxpacket:The maximum packet size used on this endpoint. The initial
* value can sometimes be reduced (hardware allowing), according to
* the endpoint descriptor used to configure the endpoint.
@@ -259,19 +263,89 @@ struct usb_ep {
const char *name;
const struct usb_ep_ops *ops;
struct list_head ep_list;
- struct usb_ep_caps caps;
- bool claimed;
- bool enabled;
- unsigned maxpacket:16;
- unsigned maxpacket_limit:16;
- unsigned max_streams:16;
- unsigned mult:2;
- unsigned maxburst:5;
- u8 address;
+ union {
+ struct {
+ u32 maxpacket:16;
+ u32 maxpacket_limit:16;
+ } __packed;
+ u32 dw1;
+ } __aligned(4);
+ union {
+ struct {
+ u32 max_streams:16;
+ u32 mult:2;
+ u32 maxburst:5;
+ } __packed;
+ u32 dw2;
+ } __aligned(4);
+ union {
+ struct {
+ struct usb_ep_caps caps;
+ u8 claimed:1;
+ u8 enabled:1;
+ u8 address;
+ } __packed;
+ u32 dw3;
+ } __aligned(4);
const struct usb_endpoint_descriptor *desc;
const struct usb_ss_ep_comp_descriptor *comp_desc;
};
+#define USB_EP_DW1_BITFIELD(n, name) \
+ ({\
+ union {\
+ struct {\
+ u32 maxpacket:16;\
+ u32 maxpacket_limit:16;\
+ } __packed;\
+ u32 dw1;\
+ } __aligned(4) __e_u_##name;\
+ u32 __e_##name;\
+ BUILD_BUG_ON(sizeof(__e_u_##name) != 4);\
+ __e_u_##name.dw1 = (n); __e_##name = __e_u_##name.name;\
+ __e_##name; })
+
+#define USB_EP_MAXPACKET(n) USB_EP_DW1_BITFIELD((n), maxpacket)
+#define USB_EP_MAXPACKET_LIMIT(n) USB_EP_DW1_BITFIELD((n), maxpacket_limit)
+
+#define USB_EP_DW2_BITFIELD(n, name) \
+ ({\
+ union {\
+ struct {\
+ u32 max_streams:16;\
+ u32 mult:2;\
+ u32 maxburst:5;\
+ } __packed;\
+ u32 dw2;\
+ } __aligned(4) __e_u_##name;\
+ u32 __e_##name; \
+ BUILD_BUG_ON(sizeof(__e_u_##name) != 4);\
+ __e_u_##name.dw2 = (n); __e_##name = __e_u_##name.name;\
+ __e_##name; })
+
+#define USB_EP_MAX_STREAMS(n) USB_EP_DW2_BITFIELD((n), max_streams)
+#define USB_EP_MULT(n) USB_EP_DW2_BITFIELD((n), mult)
+#define USB_EP_MAXBURST(n) USB_EP_DW2_BITFIELD((n), maxburst)
+
+
+#define USB_EP_NAME(n) \
+ ({char __s[9]; /* max 8: ep127out */ \
+ union {\
+ struct {\
+ struct usb_ep_caps caps;\
+ u8 claimed:1;\
+ u8 enabled:1;\
+ u8 address;\
+ } __packed;\
+ u32 dw3;\
+ } __aligned(4) __e_u_##name;\
+ BUILD_BUG_ON(sizeof(__e_u_##name) != 4);\
+ __e_u_##name.dw3 = (n);\
+ snprintf(__s, 9, "ep%d%s", __e_u_##name.address, \
+ (__e_u_##name.caps.dir_in && __e_u_##name.caps.dir_out) ? "" : \
+ __e_u_##name.caps.dir_in ? "in" : "out");\
+ __s; })
+
/*-------------------------------------------------------------------------*/
#if IS_ENABLED(CONFIG_USB_GADGET)
--
2.17.1
next prev parent reply other threads:[~2023-09-12 10:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 10:44 [PATCH v3 00/10] usb: gadget: reduce usb gadget trace event buffer usage Linyu Yuan
2023-09-12 10:44 ` [PATCH v3 01/10] usb: gadget: add anonymous definition in struct usb_gadget Linyu Yuan
2023-09-12 11:09 ` Greg Kroah-Hartman
2023-09-13 3:46 ` Linyu Yuan
2023-09-13 16:02 ` Alan Stern
2023-09-14 1:08 ` Linyu Yuan
2023-09-14 2:16 ` Alan Stern
2023-09-14 2:25 ` Linyu Yuan
2023-09-14 3:44 ` Linyu Yuan
2023-09-12 15:32 ` Alan Stern
2023-09-13 4:16 ` Linyu Yuan
2023-09-12 10:44 ` [PATCH v3 02/10] usb: gadget: add anonymous definition in struct usb_request Linyu Yuan
2023-09-12 10:44 ` Linyu Yuan [this message]
2023-09-12 10:44 ` [PATCH v3 04/10] usb: udc: trace: reduce buffer usage of trace event Linyu Yuan
2023-09-12 10:44 ` [PATCH v3 05/10] usb: cdns3: cdnsp: " Linyu Yuan
2023-09-12 10:44 ` [PATCH v3 06/10] usb: cdns3: trace: " Linyu Yuan
2023-09-12 10:44 ` [PATCH v3 07/10] usb: dwc3: " Linyu Yuan
2023-09-12 10:44 ` [PATCH v3 08/10] usb: cdns2: " Linyu Yuan
2023-09-12 10:44 ` [PATCH v3 09/10] usb: mtu3: " Linyu Yuan
2023-09-12 10:44 ` [PATCH v3 10/10] usb: musb: " Linyu Yuan
2023-09-12 11:09 ` Greg Kroah-Hartman
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=20230912104455.7737-4-quic_linyyuan@quicinc.com \
--to=quic_linyyuan@quicinc.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=alcooperx@gmail.com \
--cc=b-liu@ti.com \
--cc=cernekee@gmail.com \
--cc=chunfeng.yun@mediatek.com \
--cc=cristian.birsan@microchip.com \
--cc=daniel@zonque.org \
--cc=gregkh@linuxfoundation.org \
--cc=haojian.zhuang@gmail.com \
--cc=herve.codina@bootlin.com \
--cc=i@zenithal.me \
--cc=jonathanh@nvidia.com \
--cc=justin.chen@broadcom.com \
--cc=leoyang.li@nxp.com \
--cc=linus.walleij@linaro.org \
--cc=linux-usb@vger.kernel.org \
--cc=michal.simek@amd.com \
--cc=neal_liu@aspeedtech.com \
--cc=p.zabel@pengutronix.de \
--cc=pawell@cadence.com \
--cc=peter.chen@kernel.org \
--cc=robert.jarzmik@free.fr \
--cc=rogerq@kernel.org \
--cc=rui.silva@linaro.org \
--cc=shuah@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=valentina.manea.m@gmail.com \
--cc=vz@mleia.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