[RFC] usb: gadget: start to drop endpoint naming conventions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi folks,

as we all know naming conventions are fragile and easy to break. We've
had weird endpoint naming conventions for far too long in the gadget
framework.

I'm trying to come up with means to get rid of that and, one of the
ideas, was to add transfer support flags to our struct usb_ep which gets
initialized by the UDC driver. Then ep_matches() can use those flags to
check if it should return that endpoint or not.

The ***UNFINISHED*** patch below does just that and shows an example of
how to initialize such flags on dwc3. Please go over it and let me know
what you guys think.

From: Felipe Balbi <balbi@xxxxxx>

usb: gadget: add transfer support flags for struct usb_ep

NYET-Signed-off-by: Felipe Balbi <balbi@xxxxxx>
---

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f168eae..0bc3621 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1655,6 +1655,9 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc,
 		if (epnum == 0 || epnum == 1) {
 			dep->endpoint.maxpacket = 512;
 			dep->endpoint.maxburst = 1;
+
+			dep->endpoint.supports_control = true;
+
 			dep->endpoint.ops = &dwc3_gadget_ep0_ops;
 			if (!epnum)
 				dwc->gadget.ep0 = &dep->endpoint;
@@ -1663,6 +1666,12 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc,
 
 			dep->endpoint.maxpacket = 1024;
 			dep->endpoint.max_streams = 15;
+
+			dep->endpoint.supports_bulk = true;
+			dep->endpoint.supports_control = true;
+			dep->endpoint.supports_interrupt = true;
+			dep->endpoint.supports_isochronous = true;
+
 			dep->endpoint.ops = &dwc3_gadget_ep_ops;
 			list_add_tail(&dep->endpoint.ep_list,
 					&dwc->gadget.ep_list);
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index a777f7b..bf72538 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -57,6 +57,27 @@ ep_matches (
 	if (NULL != ep->driver_data)
 		return 0;
 
+	/* first try with transfer support flags */
+	type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
+	switch (type) {
+	case USB_ENDPOINT_XFER_CONTROL:
+		if (ep->supports_control)
+			return 0;
+		break;
+	case USB_ENDPOINT_XFER_BULK:
+		if (ep->supports_bulk)
+			return 0;
+		break;
+	case USB_ENDPOINT_XFER_INT:
+		if (ep->supports_interrupt)
+			return 0;
+		break;
+	case USB_ENDPOINT_XFER_ISOC:
+		if (ep->supports_isochronous)
+			return 0;
+		break;
+	}
+
 	/* only support ep0 for portable CONTROL traffic */
 	type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
 	if (USB_ENDPOINT_XFER_CONTROL == type)
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 942ef5e..ed62527 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -159,6 +159,13 @@ struct usb_ep_ops {
  *	enabled and remains valid until the endpoint is disabled.
  * @comp_desc: In case of SuperSpeed support, this is the endpoint companion
  *	descriptor that is used to configure the endpoint
+ * @supports_isochronous: tells the framework this endpoint supports isochronous
+ *	transfers
+ * @supports_interrupt: tells the framework this endpoint supports interrupt
+ *	transfers
+ * @supports_bulk: tells the framework this endpoint supports bulk transfers
+ * @supports_control: tells the framework this endpoint supports control
+ *	transfers
  *
  * the bus controller driver lists all the general purpose endpoints in
  * gadget->ep_list.  the control endpoint (gadget->ep0) is not in that list,
@@ -177,6 +184,11 @@ struct usb_ep {
 	u8			address;
 	const struct usb_endpoint_descriptor	*desc;
 	const struct usb_ss_ep_comp_descriptor	*comp_desc;
+
+	unsigned		supports_isochronous:1;
+	unsigned		supports_interrupt:1;
+	unsigned		supports_control:1;
+	unsigned		supports_bulk:1;
 };
 
 /*-------------------------------------------------------------------------*/

-- 
balbi

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux