hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/include/linux/usb/gadget.h
....@@ -4,7 +4,8 @@
44 *
55 * We call the USB code inside a Linux-based peripheral device a "gadget"
66 * driver, except for the hardware-specific bus glue. One USB host can
7
- * master many USB gadgets, but the gadgets are only slaved to one host.
7
+ * talk to many USB gadgets, but the gadgets are only able to communicate
8
+ * to one host.
89 *
910 *
1011 * (C) Copyright 2002-2004 by David Brownell
....@@ -43,6 +44,8 @@
4344 * @num_mapped_sgs: number of SG entries mapped to DMA (internal)
4445 * @length: Length of that data
4546 * @stream_id: The stream id, when USB3.0 bulk streams are being used
47
+ * @is_last: Indicates if this is the last request of a stream_id before
48
+ * switching to a different stream (required for DWC3 controllers).
4649 * @no_interrupt: If true, hints that no completion irq is needed.
4750 * Helpful sometimes with deep request queues that are handled
4851 * directly by DMA controllers.
....@@ -76,7 +79,6 @@
7679 * Note that for writes (IN transfers) some data bytes may still
7780 * reside in a device-side FIFO when the request is reported as
7881 * complete.
79
- * @udc_priv: Vendor private data in usage by the UDC.
8082 *
8183 * These are allocated/freed through the endpoint they're used with. The
8284 * hardware's driver can add extra per-request data to the memory it returns,
....@@ -106,6 +108,7 @@
106108 unsigned num_mapped_sgs;
107109
108110 unsigned stream_id:16;
111
+ unsigned is_last:1;
109112 unsigned no_interrupt:1;
110113 unsigned zero:1;
111114 unsigned short_not_ok:1;
....@@ -120,56 +123,8 @@
120123
121124 int status;
122125 unsigned actual;
123
- unsigned int udc_priv;
124
-};
125126
126
-/*
127
- * @buf_base_addr: Base pointer to buffer allocated for each GSI enabled EP.
128
- * TRBs point to buffers that are split from this pool. The size of the
129
- * buffer is num_bufs times buf_len. num_bufs and buf_len are determined
130
- based on desired performance and aggregation size.
131
- * @dma: DMA address corresponding to buf_base_addr.
132
- * @num_bufs: Number of buffers associated with the GSI enabled EP. This
133
- * corresponds to the number of non-zlp TRBs allocated for the EP.
134
- * The value is determined based on desired performance for the EP.
135
- * @buf_len: Size of each individual buffer is determined based on aggregation
136
- * negotiated as per the protocol. In case of no aggregation supported by
137
- * the protocol, we use default values.
138
- * @db_reg_phs_addr_lsb: IPA channel doorbell register's physical address LSB
139
- * @mapped_db_reg_phs_addr_lsb: doorbell LSB IOVA address mapped with IOMMU
140
- * @db_reg_phs_addr_msb: IPA channel doorbell register's physical address MSB
141
- * @sgt_trb_xfer_ring: USB TRB ring related sgtable entries
142
- * @sgt_data_buff: Data buffer related sgtable entries
143
- * @dev: pointer to the DMA-capable dwc device
144
- */
145
-struct usb_gsi_request {
146
- void *buf_base_addr;
147
- dma_addr_t dma;
148
- size_t num_bufs;
149
- size_t buf_len;
150
- u32 db_reg_phs_addr_lsb;
151
- dma_addr_t mapped_db_reg_phs_addr_lsb;
152
- u32 db_reg_phs_addr_msb;
153
- struct sg_table sgt_trb_xfer_ring;
154
- struct sg_table sgt_data_buff;
155
- struct device *dev;
156
-};
157
-
158
-enum gsi_ep_op {
159
- GSI_EP_OP_CONFIG = 0,
160
- GSI_EP_OP_STARTXFER,
161
- GSI_EP_OP_STORE_DBL_INFO,
162
- GSI_EP_OP_ENABLE_GSI,
163
- GSI_EP_OP_UPDATEXFER,
164
- GSI_EP_OP_RING_DB,
165
- GSI_EP_OP_ENDXFER,
166
- GSI_EP_OP_GET_CH_INFO,
167
- GSI_EP_OP_GET_XFER_IDX,
168
- GSI_EP_OP_PREPARE_TRBS,
169
- GSI_EP_OP_FREE_TRBS,
170
- GSI_EP_OP_SET_CLR_BLOCK_DBL,
171
- GSI_EP_OP_CHECK_FOR_SUSPEND,
172
- GSI_EP_OP_DISABLE,
127
+ ANDROID_KABI_RESERVE(1);
173128 };
174129
175130 /*-------------------------------------------------------------------------*/
....@@ -200,9 +155,8 @@
200155
201156 int (*fifo_status) (struct usb_ep *ep);
202157 void (*fifo_flush) (struct usb_ep *ep);
203
- int (*gsi_ep_op) (struct usb_ep *ep, void *op_data,
204
- enum gsi_ep_op op);
205158
159
+ ANDROID_KABI_RESERVE(1);
206160 };
207161
208162 /**
....@@ -243,11 +197,6 @@
243197 .dir_out = !!(_dir & USB_EP_CAPS_DIR_OUT), \
244198 }
245199
246
-enum ep_type {
247
- EP_TYPE_NORMAL = 0,
248
- EP_TYPE_GSI,
249
-};
250
-
251200 /**
252201 * struct usb_ep - device side representation of USB endpoint
253202 * @name:identifier for the endpoint, such as "ep-a" or "ep9in-bulk"
....@@ -273,12 +222,6 @@
273222 * enabled and remains valid until the endpoint is disabled.
274223 * @comp_desc: In case of SuperSpeed support, this is the endpoint companion
275224 * descriptor that is used to configure the endpoint
276
- * @ep_type: Used to specify type of EP eg. normal vs h/w accelerated.
277
- * @ep_num: Used EP number
278
- * @ep_intr_num: Interrupter number for EP.
279
- * @endless: In case where endless transfer is being initiated, this is set
280
- * to disable usb event interrupt for few events.
281
- * @transfer_type: Used to specify transfer type of EP.
282225 *
283226 * the bus controller driver lists all the general purpose endpoints in
284227 * gadget->ep_list. the control endpoint (gadget->ep0) is not in that list,
....@@ -302,13 +245,8 @@
302245 u8 address;
303246 const struct usb_endpoint_descriptor *desc;
304247 const struct usb_ss_ep_comp_descriptor *comp_desc;
305
- enum ep_type ep_type;
306
- u8 ep_num;
307
- u8 ep_intr_num;
308
- bool endless;
309
-#ifdef CONFIG_ARCH_ROCKCHIP
310
- u8 transfer_type;
311
-#endif
248
+
249
+ ANDROID_KABI_RESERVE(1);
312250 };
313251
314252 /*-------------------------------------------------------------------------*/
....@@ -326,8 +264,6 @@
326264 int usb_ep_set_wedge(struct usb_ep *ep);
327265 int usb_ep_fifo_status(struct usb_ep *ep);
328266 void usb_ep_fifo_flush(struct usb_ep *ep);
329
-int usb_gsi_ep_op(struct usb_ep *ep,
330
- struct usb_gsi_request *req, enum gsi_ep_op op);
331267 #else
332268 static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep,
333269 unsigned maxpacket_limit)
....@@ -357,10 +293,6 @@
357293 { return 0; }
358294 static inline void usb_ep_fifo_flush(struct usb_ep *ep)
359295 { }
360
-
361
-static inline int usb_gsi_ep_op(struct usb_ep *ep,
362
- struct usb_gsi_request *req, enum gsi_ep_op op)
363
-{ return 0; }
364296 #endif /* USB_GADGET */
365297
366298 /*-------------------------------------------------------------------------*/
....@@ -370,6 +302,9 @@
370302 #define USB_DEFAULT_U1_DEV_EXIT_LAT 0x01 /* Less then 1 microsec */
371303 __le16 bU2DevExitLat; /* U2 Device exit Latency */
372304 #define USB_DEFAULT_U2_DEV_EXIT_LAT 0x1F4 /* Less then 500 microsec */
305
+ __u8 besl_baseline; /* Recommended baseline BESL (0-15) */
306
+ __u8 besl_deep; /* Recommended deep BESL (0-15) */
307
+#define USB_DEFAULT_BESL_UNSPECIFIED 0xFF /* No recommended value */
373308 };
374309
375310
....@@ -383,26 +318,34 @@
383318 struct usb_gadget_ops {
384319 int (*get_frame)(struct usb_gadget *);
385320 int (*wakeup)(struct usb_gadget *);
386
- int (*func_wakeup)(struct usb_gadget *g, int interface_id);
387321 int (*set_selfpowered) (struct usb_gadget *, int is_selfpowered);
388322 int (*vbus_session) (struct usb_gadget *, int is_active);
389323 int (*vbus_draw) (struct usb_gadget *, unsigned mA);
390324 int (*pullup) (struct usb_gadget *, int is_on);
391325 int (*ioctl)(struct usb_gadget *,
392326 unsigned code, unsigned long param);
393
- void (*get_config_params)(struct usb_dcd_config_params *);
327
+ void (*get_config_params)(struct usb_gadget *,
328
+ struct usb_dcd_config_params *);
394329 int (*udc_start)(struct usb_gadget *,
395330 struct usb_gadget_driver *);
396331 int (*udc_stop)(struct usb_gadget *);
397332 void (*udc_set_speed)(struct usb_gadget *, enum usb_device_speed);
333
+ void (*udc_set_ssp_rate)(struct usb_gadget *gadget,
334
+ enum usb_ssp_rate rate);
335
+ void (*udc_async_callbacks)(struct usb_gadget *gadget, bool enable);
398336 struct usb_ep *(*match_ep)(struct usb_gadget *,
399337 struct usb_endpoint_descriptor *,
400338 struct usb_ss_ep_comp_descriptor *);
401
- int (*restart)(struct usb_gadget *g);
339
+ int (*check_config)(struct usb_gadget *gadget);
340
+
341
+ ANDROID_KABI_RESERVE(1);
342
+ ANDROID_KABI_RESERVE(2);
343
+ ANDROID_KABI_RESERVE(3);
344
+ ANDROID_KABI_RESERVE(4);
402345 };
403346
404347 /**
405
- * struct usb_gadget - represents a usb slave device
348
+ * struct usb_gadget - represents a usb device
406349 * @work: (internal use) Workqueue to be used for sysfs_notify()
407350 * @udc: struct usb_udc pointer for this gadget
408351 * @ops: Function pointers used to access hardware-specific operations.
....@@ -412,6 +355,10 @@
412355 * @speed: Speed of current connection to USB host.
413356 * @max_speed: Maximal speed the UDC can handle. UDC must support this
414357 * and all slower speeds.
358
+ * @ssp_rate: Current connected SuperSpeed Plus signaling rate and lane count.
359
+ * @max_ssp_rate: Maximum SuperSpeed Plus signaling rate and lane count the UDC
360
+ * can handle. The UDC must support this and all slower speeds and lower
361
+ * number of lanes.
415362 * @state: the state we are now (attached, suspended, configured, etc)
416363 * @name: Identifies the controller hardware type. Used in diagnostics
417364 * and sometimes configuration.
....@@ -450,9 +397,7 @@
450397 * @connected: True if gadget is connected.
451398 * @lpm_capable: If the gadget max_speed is FULL or HIGH, this flag
452399 * indicates that it supports LPM as per the LPM ECN & errata.
453
- * @remote_wakeup: Indicates if the host has enabled the remote_wakeup
454
- * feature.
455
- * @uvc_enabled: True if uvc function is enabled.
400
+ * @irq: the interrupt number for device controller.
456401 *
457402 * Gadgets have a mostly-portable "gadget driver" implementing device
458403 * functions, handling all usb configurations and interfaces. Gadget
....@@ -481,6 +426,11 @@
481426 struct list_head ep_list; /* of usb_ep */
482427 enum usb_device_speed speed;
483428 enum usb_device_speed max_speed;
429
+
430
+ /* USB SuperSpeed Plus only */
431
+ enum usb_ssp_rate ssp_rate;
432
+ enum usb_ssp_rate max_ssp_rate;
433
+
484434 enum usb_device_state state;
485435 const char *name;
486436 struct device dev;
....@@ -507,8 +457,7 @@
507457 unsigned deactivated:1;
508458 unsigned connected:1;
509459 unsigned lpm_capable:1;
510
- unsigned remote_wakeup:1;
511
- unsigned uvc_enabled:1;
460
+ int irq;
512461
513462 ANDROID_KABI_RESERVE(1);
514463 ANDROID_KABI_RESERVE(2);
....@@ -517,6 +466,7 @@
517466 };
518467 #define work_to_gadget(w) (container_of((w), struct usb_gadget, work))
519468
469
+/* Interface to the device model */
520470 static inline void set_gadget_data(struct usb_gadget *gadget, void *data)
521471 { dev_set_drvdata(&gadget->dev, data); }
522472 static inline void *get_gadget_data(struct usb_gadget *gadget)
....@@ -525,6 +475,26 @@
525475 {
526476 return container_of(dev, struct usb_gadget, dev);
527477 }
478
+static inline struct usb_gadget *usb_get_gadget(struct usb_gadget *gadget)
479
+{
480
+ get_device(&gadget->dev);
481
+ return gadget;
482
+}
483
+static inline void usb_put_gadget(struct usb_gadget *gadget)
484
+{
485
+ put_device(&gadget->dev);
486
+}
487
+extern void usb_initialize_gadget(struct device *parent,
488
+ struct usb_gadget *gadget, void (*release)(struct device *dev));
489
+extern int usb_add_gadget(struct usb_gadget *gadget);
490
+extern void usb_del_gadget(struct usb_gadget *gadget);
491
+
492
+/* Legacy device-model interface */
493
+extern int usb_add_gadget_udc_release(struct device *parent,
494
+ struct usb_gadget *gadget, void (*release)(struct device *dev));
495
+extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
496
+extern void usb_del_gadget_udc(struct usb_gadget *gadget);
497
+extern char *usb_get_gadget_udc_name(void);
528498
529499 /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */
530500 #define gadget_for_each_ep(tmp, gadget) \
....@@ -647,7 +617,6 @@
647617 #if IS_ENABLED(CONFIG_USB_GADGET)
648618 int usb_gadget_frame_number(struct usb_gadget *gadget);
649619 int usb_gadget_wakeup(struct usb_gadget *gadget);
650
-int usb_gadget_func_wakeup(struct usb_gadget *gadget, int interface_id);
651620 int usb_gadget_set_selfpowered(struct usb_gadget *gadget);
652621 int usb_gadget_clear_selfpowered(struct usb_gadget *gadget);
653622 int usb_gadget_vbus_connect(struct usb_gadget *gadget);
....@@ -657,13 +626,11 @@
657626 int usb_gadget_disconnect(struct usb_gadget *gadget);
658627 int usb_gadget_deactivate(struct usb_gadget *gadget);
659628 int usb_gadget_activate(struct usb_gadget *gadget);
629
+int usb_gadget_check_config(struct usb_gadget *gadget);
660630 #else
661631 static inline int usb_gadget_frame_number(struct usb_gadget *gadget)
662632 { return 0; }
663633 static inline int usb_gadget_wakeup(struct usb_gadget *gadget)
664
-{ return 0; }
665
-static inline int usb_gadget_func_wakeup(struct usb_gadget *gadget,
666
- int interface_id)
667634 { return 0; }
668635 static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget)
669636 { return 0; }
....@@ -683,12 +650,14 @@
683650 { return 0; }
684651 static inline int usb_gadget_activate(struct usb_gadget *gadget)
685652 { return 0; }
653
+static inline int usb_gadget_check_config(struct usb_gadget *gadget)
654
+{ return 0; }
686655 #endif /* CONFIG_USB_GADGET */
687656
688657 /*-------------------------------------------------------------------------*/
689658
690659 /**
691
- * struct usb_gadget_driver - driver for usb 'slave' devices
660
+ * struct usb_gadget_driver - driver for usb gadget devices
692661 * @function: String describing the gadget's function
693662 * @max_speed: Highest speed the driver handles.
694663 * @setup: Invoked for ep0 control requests that aren't handled by
....@@ -816,15 +785,9 @@
816785 * it will first disconnect(). The driver is also requested
817786 * to unbind() and clean up any device state, before this procedure
818787 * finally returns. It's expected that the unbind() functions
819
- * will in in exit sections, so may not be linked in some kernels.
788
+ * will be in exit sections, so may not be linked in some kernels.
820789 */
821790 int usb_gadget_unregister_driver(struct usb_gadget_driver *driver);
822
-
823
-extern int usb_add_gadget_udc_release(struct device *parent,
824
- struct usb_gadget *gadget, void (*release)(struct device *dev));
825
-extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
826
-extern void usb_del_gadget_udc(struct usb_gadget *gadget);
827
-extern char *usb_get_gadget_udc_name(void);
828791
829792 /*-------------------------------------------------------------------------*/
830793
....@@ -858,11 +821,14 @@
858821
859822 struct usb_gadget_string_container {
860823 struct list_head list;
861
- u8 *stash[0];
824
+ u8 *stash[];
862825 };
863826
864827 /* put descriptor for string with that id into buf (buflen >= 256) */
865828 int usb_gadget_get_string(const struct usb_gadget_strings *table, int id, u8 *buf);
829
+
830
+/* check if the given language identifier is valid */
831
+bool usb_validate_langid(u16 langid);
866832
867833 /*-------------------------------------------------------------------------*/
868834
....@@ -901,11 +867,6 @@
901867 struct usb_gadget *gadget);
902868 int usb_otg_descriptor_init(struct usb_gadget *gadget,
903869 struct usb_descriptor_header *otg_desc);
904
-/*-------------------------------------------------------------------------*/
905
-
906
-int usb_func_ep_queue(struct usb_function *func, struct usb_ep *ep,
907
- struct usb_request *req, gfp_t gfp_flags);
908
-
909870 /*-------------------------------------------------------------------------*/
910871
911872 /* utility to simplify map/unmap of usb_requests to/from DMA */
....@@ -987,8 +948,5 @@
987948 extern void usb_ep_autoconfig_release(struct usb_ep *);
988949
989950 extern void usb_ep_autoconfig_reset(struct usb_gadget *);
990
-extern struct usb_ep *usb_ep_autoconfig_by_name(struct usb_gadget *gadget,
991
- struct usb_endpoint_descriptor *desc,
992
- const char *ep_name);
993951
994952 #endif /* __LINUX_USB_GADGET_H */