usb: gadget: use working speed to calcaulate network bitrate and qlen
authorLinyu Yuan <quic_linyyuan@quicinc.com>
Thu, 3 Aug 2023 09:10:47 +0000 (17:10 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Aug 2023 12:48:33 +0000 (14:48 +0200)
Take ecm_bitrate() as example, it will be called after gadget device
link speed negotiation, consider code
if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER),
if a gadget device link speed is USB_SPEED_SUPER,
gadget_is_superspeed(g) must be true, or not it is a wrong
configuration of gadget max support speed.

Remove gadget_is_superspeed(g) checking should be safe, and remove other
similar operation in ncm, rndis, u_ether.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Link: https://lore.kernel.org/r/20230803091053.9714-2-quic_linyyuan@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_ecm.c
drivers/usb/gadget/function/f_ncm.c
drivers/usb/gadget/function/f_rndis.c
drivers/usb/gadget/function/u_ether.c

index c6e63ad77a404067644a118b05eb824ea1dad71f..cbe05da94bdecd8c4bec6482afb97b3177267d95 100644 (file)
@@ -68,9 +68,9 @@ static inline struct f_ecm *func_to_ecm(struct usb_function *f)
 /* peak (theoretical) bulk transfer rate in bits-per-second */
 static inline unsigned ecm_bitrate(struct usb_gadget *g)
 {
-       if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
+       if (g->speed == USB_SPEED_SUPER)
                return 13 * 1024 * 8 * 1000 * 8;
-       else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
+       else if (g->speed == USB_SPEED_HIGH)
                return 13 * 512 * 8 * 1000 * 8;
        else
                return 19 * 64 * 1 * 1000 * 8;
index 424bb3b666dbd7d545a9d9abfb835c1152b51624..e6dac5510540b44e321fb2e94349d951294912a8 100644 (file)
@@ -85,11 +85,11 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g)
 {
        if (!g)
                return 0;
-       else if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS)
+       else if (g->speed >= USB_SPEED_SUPER_PLUS)
                return 4250000000U;
-       else if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
+       else if (g->speed == USB_SPEED_SUPER)
                return 3750000000U;
-       else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
+       else if (g->speed == USB_SPEED_HIGH)
                return 13 * 512 * 8 * 1000 * 8;
        else
                return 19 *  64 * 1 * 1000 * 8;
index ee95e8f5f9d489a58735d2394eca222509da8a17..eff5d7cbce00c165e85b9e09928f17f89df960d4 100644 (file)
@@ -87,11 +87,11 @@ static inline struct f_rndis *func_to_rndis(struct usb_function *f)
 /* peak (theoretical) bulk transfer rate in bits-per-second */
 static unsigned int bitrate(struct usb_gadget *g)
 {
-       if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS)
+       if (g->speed >= USB_SPEED_SUPER_PLUS)
                return 4250000000U;
-       if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
+       if (g->speed == USB_SPEED_SUPER)
                return 3750000000U;
-       else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
+       else if (g->speed == USB_SPEED_HIGH)
                return 13 * 512 * 8 * 1000 * 8;
        else
                return 19 * 64 * 1 * 1000 * 8;
index a366abb456236c7033b6fbd1c7cfb9b4dcc1a7cf..4bb0553da6585761110c9fb8107241a0aeb8522a 100644 (file)
@@ -93,11 +93,10 @@ struct eth_dev {
 
 #define DEFAULT_QLEN   2       /* double buffering by default */
 
-/* for dual-speed hardware, use deeper queues at high/super speed */
+/* use deeper queues at high/super speed */
 static inline int qlen(struct usb_gadget *gadget, unsigned qmult)
 {
-       if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH ||
-                                           gadget->speed >= USB_SPEED_SUPER))
+       if (gadget->speed == USB_SPEED_HIGH || gadget->speed >= USB_SPEED_SUPER)
                return qmult * DEFAULT_QLEN;
        else
                return DEFAULT_QLEN;