diff mbox series

[v2,03/11] usb: gadget: add anonymous definition in struct usb_ep

Message ID 20230911112446.1791-4-quic_linyyuan@quicinc.com
State New
Headers show
Series usb: gadget: reduce usb gadget trace event buffer usage | expand

Commit Message

Linyu Yuan Sept. 11, 2023, 11:24 a.m. UTC
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

 include/linux/usb/gadget.h | 74 +++++++++++++++++++++++++++++---------
 1 file changed, 58 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 045ebd4637c5..8529d49ed05d 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -175,13 +175,13 @@  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;
+} __packed;
 
 #define USB_EP_CAPS_TYPE_CONTROL     0x01
 #define USB_EP_CAPS_TYPE_ISO         0x02
@@ -211,6 +211,11 @@  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
+ * @epnum: trace event purpose
+ * @u1: trace event purpose
+ * @u2: 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.
@@ -240,19 +245,56 @@  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;
+			u32	max_streams:16;
+			u32	mult:2;
+			u32	maxburst:5;
+		} __packed;
+		struct {
+			u32	dw1;
+			u32	dw2;
+		};
+#define		USB_EP_MAXPACKET(n)		((n) & 0xffff)
+#define		USB_EP_MAXPACKET_LIMIT(n)	(((n) >> 16) & 0xffff)
+#define		USB_EP_MAX_STREAMS(n)		((n) & 0xffff)
+#define		USB_EP_MULT(n)			(((n) >> 16) & 0x3)
+#define		USB_EP_MAXBURST(n)		(((n) >> 18) & 0x1f)
+	};
+	union {
+		struct {
+			union {
+				struct usb_ep_caps	caps;
+				u8			u1;
+			};
+			union {
+				struct {
+					u8		claimed:1;
+					u8		enabled:1;
+				} __packed;
+				u8			u2;
+			};
+			u8				address;
+			u8				epnum;
+		} __packed;
+		u32	dw3;
+#define		USB_EP_NUM(n)		(((n) >> 24) & 0xff)
+#define		USB_EP_DIR_BI(n)	((((n) >> 4) & 0x3) == 0x3)
+#define		USB_EP_DIR_IN(n)	(((n) >> 4) & 0x1)
+	};
 	const struct usb_endpoint_descriptor	*desc;
 	const struct usb_ss_ep_comp_descriptor	*comp_desc;
 };
 
+/* NOTE: it need UDC set epnum and dir info when init endpoints */
+#define USB_EP_NAME(n) \
+	({char __s[9]; /* max 8: ep127out */\
+	snprintf(__s, 9, "ep%d%s", USB_EP_NUM(n), \
+		USB_EP_DIR_BI(n) ? "" : (USB_EP_DIR_IN(n) ? "in" : "out"));\
+	__s; })
+
 /*-------------------------------------------------------------------------*/
 
 #if IS_ENABLED(CONFIG_USB_GADGET)