forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/usb/gadget/udc/dummy_hcd.c
....@@ -14,7 +14,7 @@
1414 * Linux-USB host controller driver. USB traffic is simulated; there's
1515 * no need for USB hardware. Use this with two other drivers:
1616 *
17
- * - Gadget driver, responding to requests (slave);
17
+ * - Gadget driver, responding to requests (device);
1818 * - Host-side device driver, as already familiar in Linux.
1919 *
2020 * Having this all in one kernel can help some stages of development,
....@@ -261,7 +261,7 @@
261261 spinlock_t lock;
262262
263263 /*
264
- * SLAVE/GADGET side support
264
+ * DEVICE/GADGET side support
265265 */
266266 struct dummy_ep ep[DUMMY_ENDPOINTS];
267267 int address;
....@@ -276,7 +276,7 @@
276276 unsigned pullup:1;
277277
278278 /*
279
- * MASTER/HOST side support
279
+ * HOST side support
280280 */
281281 struct dummy_hcd *hs_hcd;
282282 struct dummy_hcd *ss_hcd;
....@@ -323,7 +323,7 @@
323323
324324 /*-------------------------------------------------------------------------*/
325325
326
-/* SLAVE/GADGET SIDE UTILITY ROUTINES */
326
+/* DEVICE/GADGET SIDE UTILITY ROUTINES */
327327
328328 /* called with spinlock held */
329329 static void nuke(struct dummy *dum, struct dummy_ep *ep)
....@@ -427,6 +427,7 @@
427427
428428 /* caller must hold lock */
429429 static void set_link_state(struct dummy_hcd *dum_hcd)
430
+ __must_hold(&dum->lock)
430431 {
431432 struct dummy *dum = dum_hcd->dum;
432433 unsigned int power_bit;
....@@ -485,7 +486,7 @@
485486
486487 /*-------------------------------------------------------------------------*/
487488
488
-/* SLAVE/GADGET SIDE DRIVER
489
+/* DEVICE/GADGET SIDE DRIVER
489490 *
490491 * This only tracks gadget state. All the work is done when the host
491492 * side tries some (emulated) i/o operation. Real device controller
....@@ -566,12 +567,12 @@
566567 if (max <= 1024)
567568 break;
568569 /* save a return statement */
569
- /* fall through */
570
+ fallthrough;
570571 case USB_SPEED_FULL:
571572 if (max <= 64)
572573 break;
573574 /* save a return statement */
574
- /* fall through */
575
+ fallthrough;
575576 default:
576577 if (max <= 8)
577578 break;
....@@ -589,7 +590,7 @@
589590 if (max <= 1024)
590591 break;
591592 /* save a return statement */
592
- /* fall through */
593
+ fallthrough;
593594 case USB_SPEED_FULL:
594595 if (max <= 1023)
595596 break;
....@@ -618,21 +619,7 @@
618619 _ep->name,
619620 desc->bEndpointAddress & 0x0f,
620621 (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out",
621
- ({ char *val;
622
- switch (usb_endpoint_type(desc)) {
623
- case USB_ENDPOINT_XFER_BULK:
624
- val = "bulk";
625
- break;
626
- case USB_ENDPOINT_XFER_ISOC:
627
- val = "iso";
628
- break;
629
- case USB_ENDPOINT_XFER_INT:
630
- val = "intr";
631
- break;
632
- default:
633
- val = "ctrl";
634
- break;
635
- } val; }),
622
+ usb_ep_type_string(usb_endpoint_type(desc)),
636623 max, ep->stream_en ? "enabled" : "disabled");
637624
638625 /* at this point real hardware should be NAKing transfers
....@@ -985,7 +972,7 @@
985972 * hardware can be built with discrete components, so the gadget API doesn't
986973 * require that assumption.
987974 *
988
- * For this emulator, it might be convenient to create a usb slave device
975
+ * For this emulator, it might be convenient to create a usb device
989976 * for each driver that registers: just add to a big root hub.
990977 */
991978
....@@ -1009,7 +996,7 @@
1009996 }
1010997
1011998 /*
1012
- * SLAVE side init ... the layer above hardware, which
999
+ * DEVICE side init ... the layer above hardware, which
10131000 * can't enumerate without help from the driver we're binding.
10141001 */
10151002
....@@ -1155,7 +1142,7 @@
11551142 .suspend = dummy_udc_suspend,
11561143 .resume = dummy_udc_resume,
11571144 .driver = {
1158
- .name = (char *) gadget_name,
1145
+ .name = gadget_name,
11591146 },
11601147 };
11611148
....@@ -1171,7 +1158,7 @@
11711158 return index;
11721159 }
11731160
1174
-/* MASTER/HOST SIDE DRIVER
1161
+/* HOST SIDE DRIVER
11751162 *
11761163 * this uses the hcd framework to hook up to host side drivers.
11771164 * its root hub will only have one device, otherwise it acts like
....@@ -1601,7 +1588,7 @@
16011588
16021589 /**
16031590 * handle_control_request() - handles all control transfers
1604
- * @dum: pointer to dummy (the_controller)
1591
+ * @dum_hcd: pointer to dummy (the_controller)
16051592 * @urb: the urb request to handle
16061593 * @setup: pointer to the setup data for a USB device control
16071594 * request
....@@ -1963,7 +1950,7 @@
19631950 * this almost certainly polls too fast.
19641951 */
19651952 limit = max(limit, periodic_bytes(dum, ep));
1966
- /* FALLTHROUGH */
1953
+ fallthrough;
19671954
19681955 default:
19691956 treat_control_like_bulk:
....@@ -2134,9 +2121,21 @@
21342121 dum_hcd->port_status &= ~USB_PORT_STAT_POWER;
21352122 set_link_state(dum_hcd);
21362123 break;
2137
- default:
2124
+ case USB_PORT_FEAT_ENABLE:
2125
+ case USB_PORT_FEAT_C_ENABLE:
2126
+ case USB_PORT_FEAT_C_SUSPEND:
2127
+ /* Not allowed for USB-3 */
2128
+ if (hcd->speed == HCD_USB3)
2129
+ goto error;
2130
+ fallthrough;
2131
+ case USB_PORT_FEAT_C_CONNECTION:
2132
+ case USB_PORT_FEAT_C_RESET:
21382133 dum_hcd->port_status &= ~(1 << wValue);
21392134 set_link_state(dum_hcd);
2135
+ break;
2136
+ default:
2137
+ /* Disallow INDICATOR and C_OVER_CURRENT */
2138
+ goto error;
21402139 }
21412140 break;
21422141 case GetHubDescriptor:
....@@ -2272,19 +2271,22 @@
22722271 "supported for USB 2.0 roothub\n");
22732272 goto error;
22742273 }
2275
- /* FALLS THROUGH */
2274
+ fallthrough;
22762275 case USB_PORT_FEAT_RESET:
2276
+ if (!(dum_hcd->port_status & USB_PORT_STAT_CONNECTION))
2277
+ break;
22772278 /* if it's already enabled, disable */
22782279 if (hcd->speed == HCD_USB3) {
2279
- dum_hcd->port_status = 0;
22802280 dum_hcd->port_status =
22812281 (USB_SS_PORT_STAT_POWER |
22822282 USB_PORT_STAT_CONNECTION |
22832283 USB_PORT_STAT_RESET);
2284
- } else
2284
+ } else {
22852285 dum_hcd->port_status &= ~(USB_PORT_STAT_ENABLE
22862286 | USB_PORT_STAT_LOW_SPEED
22872287 | USB_PORT_STAT_HIGH_SPEED);
2288
+ dum_hcd->port_status |= USB_PORT_STAT_RESET;
2289
+ }
22882290 /*
22892291 * We want to reset device status. All but the
22902292 * Self powered feature
....@@ -2296,19 +2298,19 @@
22962298 * interval? Is it still 50msec as for HS?
22972299 */
22982300 dum_hcd->re_timeout = jiffies + msecs_to_jiffies(50);
2299
- /* FALLS THROUGH */
2300
- default:
2301
- if (hcd->speed == HCD_USB3) {
2302
- if ((dum_hcd->port_status &
2303
- USB_SS_PORT_STAT_POWER) != 0) {
2304
- dum_hcd->port_status |= (1 << wValue);
2305
- }
2306
- } else
2307
- if ((dum_hcd->port_status &
2308
- USB_PORT_STAT_POWER) != 0) {
2309
- dum_hcd->port_status |= (1 << wValue);
2310
- }
23112301 set_link_state(dum_hcd);
2302
+ break;
2303
+ case USB_PORT_FEAT_C_CONNECTION:
2304
+ case USB_PORT_FEAT_C_RESET:
2305
+ case USB_PORT_FEAT_C_ENABLE:
2306
+ case USB_PORT_FEAT_C_SUSPEND:
2307
+ /* Not allowed for USB-3, and ignored for USB-2 */
2308
+ if (hcd->speed == HCD_USB3)
2309
+ goto error;
2310
+ break;
2311
+ default:
2312
+ /* Disallow TEST, INDICATOR, and C_OVER_CURRENT */
2313
+ goto error;
23122314 }
23132315 break;
23142316 case GetPortErrorCount:
....@@ -2471,8 +2473,8 @@
24712473 struct dummy_hcd *dum_hcd = hcd_to_dummy_hcd(hcd);
24722474
24732475 /*
2474
- * MASTER side init ... we emulate a root hub that'll only ever
2475
- * talk to one device (the slave side). Also appears in sysfs,
2476
+ * HOST side init ... we emulate a root hub that'll only ever
2477
+ * talk to one device (the gadget side). Also appears in sysfs,
24762478 * just like more familiar pci-based HCDs.
24772479 */
24782480 if (!usb_hcd_is_primary_hcd(hcd))
....@@ -2741,7 +2743,7 @@
27412743 .suspend = dummy_hcd_suspend,
27422744 .resume = dummy_hcd_resume,
27432745 .driver = {
2744
- .name = (char *) driver_name,
2746
+ .name = driver_name,
27452747 },
27462748 };
27472749