Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: add a inline function gether_bitrate()

In function ecm_bitrate(), it is not support report bit rate for super
speed plus mode, but it can use same bit rate value defined in ncm and
rndis.

Add a common inline function gether_bitrate() which report different for
all possible speeds, it can be used by ecm, ncm and rndis, also remove
old function from them.

Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Link: https://lore.kernel.org/r/20230803091053.9714-3-quic_linyyuan@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Linyu Yuan and committed by
Greg Kroah-Hartman
8165763f 98102ae1

+18 -44
+2 -13
drivers/usb/gadget/function/f_ecm.c
··· 65 65 return container_of(f, struct f_ecm, port.func); 66 66 } 67 67 68 - /* peak (theoretical) bulk transfer rate in bits-per-second */ 69 - static inline unsigned ecm_bitrate(struct usb_gadget *g) 70 - { 71 - if (g->speed == USB_SPEED_SUPER) 72 - return 13 * 1024 * 8 * 1000 * 8; 73 - else if (g->speed == USB_SPEED_HIGH) 74 - return 13 * 512 * 8 * 1000 * 8; 75 - else 76 - return 19 * 64 * 1 * 1000 * 8; 77 - } 78 - 79 68 /*-------------------------------------------------------------------------*/ 80 69 81 70 /* ··· 400 411 401 412 /* SPEED_CHANGE data is up/down speeds in bits/sec */ 402 413 data = req->buf + sizeof *event; 403 - data[0] = cpu_to_le32(ecm_bitrate(cdev->gadget)); 414 + data[0] = cpu_to_le32(gether_bitrate(cdev->gadget)); 404 415 data[1] = data[0]; 405 416 406 - DBG(cdev, "notify speed %d\n", ecm_bitrate(cdev->gadget)); 417 + DBG(cdev, "notify speed %d\n", gether_bitrate(cdev->gadget)); 407 418 ecm->notify_state = ECM_NOTIFY_NONE; 408 419 break; 409 420 }
+2 -17
drivers/usb/gadget/function/f_ncm.c
··· 80 80 return container_of(f, struct f_ncm, port.func); 81 81 } 82 82 83 - /* peak (theoretical) bulk transfer rate in bits-per-second */ 84 - static inline unsigned ncm_bitrate(struct usb_gadget *g) 85 - { 86 - if (!g) 87 - return 0; 88 - else if (g->speed >= USB_SPEED_SUPER_PLUS) 89 - return 4250000000U; 90 - else if (g->speed == USB_SPEED_SUPER) 91 - return 3750000000U; 92 - else if (g->speed == USB_SPEED_HIGH) 93 - return 13 * 512 * 8 * 1000 * 8; 94 - else 95 - return 19 * 64 * 1 * 1000 * 8; 96 - } 97 - 98 83 /*-------------------------------------------------------------------------*/ 99 84 100 85 /* ··· 561 576 562 577 /* SPEED_CHANGE data is up/down speeds in bits/sec */ 563 578 data = req->buf + sizeof *event; 564 - data[0] = cpu_to_le32(ncm_bitrate(cdev->gadget)); 579 + data[0] = cpu_to_le32(gether_bitrate(cdev->gadget)); 565 580 data[1] = data[0]; 566 581 567 - DBG(cdev, "notify speed %u\n", ncm_bitrate(cdev->gadget)); 582 + DBG(cdev, "notify speed %u\n", gether_bitrate(cdev->gadget)); 568 583 ncm->notify_state = NCM_NOTIFY_CONNECT; 569 584 break; 570 585 }
+1 -14
drivers/usb/gadget/function/f_rndis.c
··· 84 84 return container_of(f, struct f_rndis, port.func); 85 85 } 86 86 87 - /* peak (theoretical) bulk transfer rate in bits-per-second */ 88 - static unsigned int bitrate(struct usb_gadget *g) 89 - { 90 - if (g->speed >= USB_SPEED_SUPER_PLUS) 91 - return 4250000000U; 92 - if (g->speed == USB_SPEED_SUPER) 93 - return 3750000000U; 94 - else if (g->speed == USB_SPEED_HIGH) 95 - return 13 * 512 * 8 * 1000 * 8; 96 - else 97 - return 19 * 64 * 1 * 1000 * 8; 98 - } 99 - 100 87 /*-------------------------------------------------------------------------*/ 101 88 102 89 /* ··· 627 640 DBG(cdev, "%s\n", __func__); 628 641 629 642 rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 630 - bitrate(cdev->gadget) / 100); 643 + gether_bitrate(cdev->gadget) / 100); 631 644 rndis_signal_connect(rndis->params); 632 645 } 633 646
+13
drivers/usb/gadget/function/u_ether.h
··· 279 279 return true; 280 280 } 281 281 282 + /* peak (theoretical) bulk transfer rate in bits-per-second */ 283 + static inline unsigned int gether_bitrate(struct usb_gadget *g) 284 + { 285 + if (g->speed >= USB_SPEED_SUPER_PLUS) 286 + return 4250000000U; 287 + if (g->speed == USB_SPEED_SUPER) 288 + return 3750000000U; 289 + else if (g->speed == USB_SPEED_HIGH) 290 + return 13 * 512 * 8 * 1000 * 8; 291 + else 292 + return 19 * 64 * 1 * 1000 * 8; 293 + } 294 + 282 295 #endif /* __U_ETHER_H */