usb: gadget: use working speed to calcaulate network bitrate and qlen

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>
This commit is contained in:
Linyu Yuan 2023-08-03 17:10:47 +08:00 committed by Greg Kroah-Hartman
parent 0c2dfb3ea6
commit 98102ae154
4 changed files with 10 additions and 11 deletions

View 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 */ /* peak (theoretical) bulk transfer rate in bits-per-second */
static inline unsigned ecm_bitrate(struct usb_gadget *g) 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; 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; return 13 * 512 * 8 * 1000 * 8;
else else
return 19 * 64 * 1 * 1000 * 8; return 19 * 64 * 1 * 1000 * 8;

View File

@ -85,11 +85,11 @@ static inline unsigned ncm_bitrate(struct usb_gadget *g)
{ {
if (!g) if (!g)
return 0; return 0;
else if (gadget_is_superspeed(g) && g->speed >= USB_SPEED_SUPER_PLUS) else if (g->speed >= USB_SPEED_SUPER_PLUS)
return 4250000000U; return 4250000000U;
else if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) else if (g->speed == USB_SPEED_SUPER)
return 3750000000U; 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; return 13 * 512 * 8 * 1000 * 8;
else else
return 19 * 64 * 1 * 1000 * 8; return 19 * 64 * 1 * 1000 * 8;

View 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 */ /* peak (theoretical) bulk transfer rate in bits-per-second */
static unsigned int bitrate(struct usb_gadget *g) 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; return 4250000000U;
if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER) if (g->speed == USB_SPEED_SUPER)
return 3750000000U; 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; return 13 * 512 * 8 * 1000 * 8;
else else
return 19 * 64 * 1 * 1000 * 8; return 19 * 64 * 1 * 1000 * 8;

View File

@ -93,11 +93,10 @@ struct eth_dev {
#define DEFAULT_QLEN 2 /* double buffering by default */ #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) static inline int qlen(struct usb_gadget *gadget, unsigned qmult)
{ {
if (gadget_is_dualspeed(gadget) && (gadget->speed == USB_SPEED_HIGH || if (gadget->speed == USB_SPEED_HIGH || gadget->speed >= USB_SPEED_SUPER)
gadget->speed >= USB_SPEED_SUPER))
return qmult * DEFAULT_QLEN; return qmult * DEFAULT_QLEN;
else else
return DEFAULT_QLEN; return DEFAULT_QLEN;