Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8a39efa authored by Mayank Rana's avatar Mayank Rana
Browse files

dwc3: gadget: Improve TX FIFO resize functionality



This change considers USB device speed to set max_packet size
instead of provided max_packet value from USB function driver.
It doesn't resize ep0IN TxFIFO, and starts with ep1IN TxFIFO only.

Change-Id: Ifce63f5a8570f79bad1e5d3ae6f5d580c34046b5
Signed-off-by: default avatarMayank Rana <mrana@codeaurora.org>
parent 4e73469f
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
	int		mdwidth;
	int		num;
	int		num_eps;
	int		max_packet;
	struct usb_composite_dev *cdev = get_gadget_data(&dwc->gadget);

	if (!(cdev && cdev->config) || !dwc->needs_fifo_resize)
@@ -194,14 +195,28 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
	/* MDWIDTH is represented in bits, we need it in bytes */
	mdwidth >>= 3;

	dev_dbg(dwc->dev, "%s: num eps: %d\n", __func__, num_eps);
	if (dwc->gadget.speed == USB_SPEED_FULL) {
		max_packet = 64;
	} else if (dwc->gadget.speed == USB_SPEED_HIGH) {
		max_packet = 512;
	} else if (dwc->gadget.speed == USB_SPEED_SUPER) {
		max_packet = 1024;
	} else {
		dev_warn(dwc->dev, "USB speed (%d) is not valid.\n",
						dwc->gadget.speed);
		return -EINVAL;
	}

	last_fifo_depth = (dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)) & 0xFFFF);
	dev_dbg(dwc->dev, "%s: num eps:%d max_packet:%d last_fifo_depth:%04x\n",
				__func__, num_eps, max_packet, last_fifo_depth);

	for (num = 0; num < num_eps; num++) {
	/* Don't resize ep0IN TxFIFO, start with ep1IN only. */
	for (num = 1; num < num_eps; num++) {
		/* bit0 indicates direction; 1 means IN ep */
		struct dwc3_ep	*dep = dwc->eps[(num << 1) | 1];
		int		mult = 1;
		int		tmp;
		int		max_packet = 1024;

		if (!(dep->flags & DWC3_EP_ENABLED)) {
			dev_warn(dwc->dev, "ep%dIn not enabled", num);
@@ -213,18 +228,8 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
				usb_endpoint_xfer_bulk(dep->endpoint.desc))
				|| usb_endpoint_xfer_isoc(dep->endpoint.desc))
			mult = 3;
		/*
		 * REVISIT: the following assumes we will always have enough
		 * space available on the FIFO RAM for all possible use cases.
		 * Make sure that's true somehow and change FIFO allocation
		 * accordingly.
		 *
		 * If we have Bulk (burst only) or Isochronous endpoints, we
		 * want them to be able to be very, very fast. So we're giving
		 * those endpoints a fifo_size which is enough for 3 full
		 * packets
		 */
		tmp = mult * (dep->endpoint.maxpacket + mdwidth);

		tmp = mult * (max_packet + mdwidth);
resize_fifo:
		tmp += mdwidth;

@@ -232,7 +237,7 @@ resize_fifo:

		fifo_size |= (last_fifo_depth << 16);

		dev_vdbg(dwc->dev, "%s: Fifo Addr %04x Size %d\n",
		dev_dbg(dwc->dev, "%s: Fifo Addr %04x Size %d\n",
				dep->name, last_fifo_depth, fifo_size & 0xffff);

		last_fifo_depth += (fifo_size & 0xffff);