Skip to content

Commit 8165763

Browse files
Linyu Yuangregkh
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 98102ae commit 8165763

File tree

4 files changed

+18
-44
lines changed

4 files changed

+18
-44
lines changed

drivers/usb/gadget/function/f_ecm.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,6 @@ static inline struct f_ecm *func_to_ecm(struct usb_function *f)
6565
return container_of(f, struct f_ecm, port.func);
6666
}
6767

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-
7968
/*-------------------------------------------------------------------------*/
8069

8170
/*
@@ -411,10 +400,10 @@ static void ecm_do_notify(struct f_ecm *ecm)
411400

412401
/* SPEED_CHANGE data is up/down speeds in bits/sec */
413402
data = req->buf + sizeof *event;
414-
data[0] = cpu_to_le32(ecm_bitrate(cdev->gadget));
403+
data[0] = cpu_to_le32(gether_bitrate(cdev->gadget));
415404
data[1] = data[0];
416405

417-
DBG(cdev, "notify speed %d\n", ecm_bitrate(cdev->gadget));
406+
DBG(cdev, "notify speed %d\n", gether_bitrate(cdev->gadget));
418407
ecm->notify_state = ECM_NOTIFY_NONE;
419408
break;
420409
}

drivers/usb/gadget/function/f_ncm.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,6 @@ static inline struct f_ncm *func_to_ncm(struct usb_function *f)
8080
return container_of(f, struct f_ncm, port.func);
8181
}
8282

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-
9883
/*-------------------------------------------------------------------------*/
9984

10085
/*
@@ -576,10 +561,10 @@ static void ncm_do_notify(struct f_ncm *ncm)
576561

577562
/* SPEED_CHANGE data is up/down speeds in bits/sec */
578563
data = req->buf + sizeof *event;
579-
data[0] = cpu_to_le32(ncm_bitrate(cdev->gadget));
564+
data[0] = cpu_to_le32(gether_bitrate(cdev->gadget));
580565
data[1] = data[0];
581566

582-
DBG(cdev, "notify speed %u\n", ncm_bitrate(cdev->gadget));
567+
DBG(cdev, "notify speed %u\n", gether_bitrate(cdev->gadget));
583568
ncm->notify_state = NCM_NOTIFY_CONNECT;
584569
break;
585570
}

drivers/usb/gadget/function/f_rndis.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,6 @@ static inline struct f_rndis *func_to_rndis(struct usb_function *f)
8484
return container_of(f, struct f_rndis, port.func);
8585
}
8686

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-
10087
/*-------------------------------------------------------------------------*/
10188

10289
/*
@@ -640,7 +627,7 @@ static void rndis_open(struct gether *geth)
640627
DBG(cdev, "%s\n", __func__);
641628

642629
rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3,
643-
bitrate(cdev->gadget) / 100);
630+
gether_bitrate(cdev->gadget) / 100);
644631
rndis_signal_connect(rndis->params);
645632
}
646633

drivers/usb/gadget/function/u_ether.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,17 @@ static inline bool can_support_ecm(struct usb_gadget *gadget)
279279
return true;
280280
}
281281

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+
282295
#endif /* __U_ETHER_H */

0 commit comments

Comments
 (0)