From: Linyu Yuan <quic_linyyuan@quicinc.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
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>,
<linux-usb@vger.kernel.org>
Subject: Re: [PATCH v3 01/10] usb: gadget: add anonymous definition in struct usb_gadget
Date: Thu, 14 Sep 2023 09:08:04 +0800 [thread overview]
Message-ID: <be818ccf-96fd-2fa0-8f95-1f49e3aa2dfc@quicinc.com> (raw)
In-Reply-To: <ef99b328-926c-4696-83bf-9ccd6a38984e@rowland.harvard.edu>
On 9/14/2023 12:02 AM, Alan Stern wrote:
> On Wed, Sep 13, 2023 at 11:46:12AM +0800, Linyu Yuan wrote:
>> but Alan Stern have one comment, do it mean the bit position number is not
>> expect and we can't use it ?
>>
>> @Alan Stern , BIT(0), BIT(1) is not the member we expect ?
> They might not be. If you can avoid making this assumption, you should.
i don't know if it is true or not, seem some driver expect there is no
hole for this kind of bit field definition.
>
>>> This macro usage is a real mess. Can't you find a better way to do it?
>>>
>>> For instance, in the code that parses the trace buffer, define a
>>> temporary usb_gadget structure and copy the dw1 field from the trace
>>> buffer to the temporary structure. Then you can access the fields in
>>> that structure directly by their original names, with no macros.
>> do it same idea just move it outside of gadget.h ?
> Keep the anonymous union in gadget.h, but get rid of the macros.
do you expect below ?
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -357,6 +357,7 @@ struct usb_gadget_ops {
* @in_epnum: last used in ep number
* @mA: last set mA value
* @otg_caps: OTG capabilities of this gadget.
+ * @dw1: trace event purpose
* @sg_supported: true if we can handle scatter-gather
* @is_otg: True if the USB device port uses a Mini-AB jack, so that the
* gadget driver must provide a USB OTG descriptor.
@@ -432,30 +433,88 @@ struct usb_gadget {
unsigned mA;
struct usb_otg_caps *otg_caps;
- unsigned sg_supported:1;
- unsigned is_otg:1;
- unsigned is_a_peripheral:1;
- unsigned b_hnp_enable:1;
- unsigned a_hnp_support:1;
- unsigned a_alt_hnp_support:1;
- unsigned hnp_polling_support:1;
- unsigned host_request_flag:1;
- unsigned quirk_ep_out_aligned_size:1;
- unsigned quirk_altset_not_supp:1;
- unsigned quirk_stall_not_supp:1;
- unsigned quirk_zlp_not_supp:1;
- unsigned quirk_avoids_skb_reserve:1;
- unsigned is_selfpowered:1;
- unsigned deactivated:1;
- unsigned connected:1;
- unsigned lpm_capable:1;
- unsigned wakeup_capable:1;
- unsigned wakeup_armed:1;
+ union {
+ struct {
+ unsigned sg_supported:1;
+ unsigned is_otg:1;
+ unsigned is_a_peripheral:1;
+ unsigned b_hnp_enable:1;
+ unsigned a_hnp_support:1;
+ unsigned a_alt_hnp_support:1;
+ unsigned hnp_polling_support:1;
+ unsigned host_request_flag:1;
+ unsigned quirk_ep_out_aligned_size:1;
+ unsigned quirk_altset_not_supp:1;
+ unsigned quirk_stall_not_supp:1;
+ unsigned quirk_zlp_not_supp:1;
+ unsigned quirk_avoids_skb_reserve:1;
+ unsigned is_selfpowered:1;
+ unsigned deactivated:1;
+ unsigned connected:1;
+ unsigned lpm_capable:1;
+ unsigned wakeup_capable:1;
+ unsigned wakeup_armed:1;
+ } __packed;
+
+ u32 dw1;
+ } __aligned(4);
int irq;
int id_number;
};
#define work_to_gadget(w) (container_of((w), struct usb_gadget,
work))
+#define USB_GADGET_BITFIELD(field) \
+static inline u32 usb_gadget_bit_##field(u32 dw1) \
+{ \
+ union { \
+ struct { \
+ u32 sg_supported:1; \
+ u32 is_otg:1; \
+ u32 is_a_peripheral:1; \
+ u32 b_hnp_enable:1; \
+ u32 a_hnp_support:1; \
+ u32 a_alt_hnp_support:1; \
+ u32 hnp_polling_support:1; \
+ u32 host_request_flag:1; \
+ u32 quirk_ep_out_aligned_size:1; \
+ u32 quirk_altset_not_supp:1; \
+ u32 quirk_stall_not_supp:1; \
+ u32 quirk_zlp_not_supp:1; \
+ u32 quirk_avoids_skb_reserve:1; \
+ u32 is_selfpowered:1; \
+ u32 deactivated:1; \
+ u32 connected:1; \
+ u32 lpm_capable:1; \
+ u32 wakeup_capable:1; \
+ u32 wakeup_armed:1; \
+ } __packed; \
+ u32 dw1; \
+ } __aligned(4) u; \
+ BUILD_BUG_ON(sizeof(u) != 4); \
+ u.dw1 = dw1; \
+ return u.field; \
+}
+
+USB_GADGET_BITFIELD(sg_supported)
+USB_GADGET_BITFIELD(is_otg)
+USB_GADGET_BITFIELD(is_a_peripheral)
+USB_GADGET_BITFIELD(b_hnp_enable)
+USB_GADGET_BITFIELD(a_hnp_support)
+USB_GADGET_BITFIELD(a_alt_hnp_support)
+USB_GADGET_BITFIELD(hnp_polling_support)
+USB_GADGET_BITFIELD(host_request_flag)
+USB_GADGET_BITFIELD(quirk_ep_out_aligned_size)
+USB_GADGET_BITFIELD(quirk_altset_not_supp)
+USB_GADGET_BITFIELD(quirk_stall_not_supp)
+USB_GADGET_BITFIELD(quirk_zlp_not_supp)
+USB_GADGET_BITFIELD(quirk_avoids_skb_reserve)
+USB_GADGET_BITFIELD(is_selfpowered)
+USB_GADGET_BITFIELD(deactivated)
+USB_GADGET_BITFIELD(connected)
+USB_GADGET_BITFIELD(lpm_capable)
+USB_GADGET_BITFIELD(wakeup_capable)
+USB_GADGET_BITFIELD(wakeup_armed)
+
>
> Alan Stern
next prev parent reply other threads:[~2023-09-14 1:09 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 [this message]
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 ` [PATCH v3 03/10] usb: gadget: add anonymous definition in struct usb_ep Linyu Yuan
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=be818ccf-96fd-2fa0-8f95-1f49e3aa2dfc@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=stern@rowland.harvard.edu \
--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