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

Commit 73716a26 authored by Vamsi Krishna's avatar Vamsi Krishna
Browse files

usb: dwc3: gadget: Set txfifo for all eps in usb configuration



Resize txfifo function currently configures txfifo for enabled
endpoints. In most cases endpoints are enabled by function drivers
after usb host selects the configuration. Some functions like ecm
and ncm have two interfaces (control and data) and data interface
are enabled only after the configuration is selected and may not have
proper correct txfifo settings. To avoid this issue, configure the
txfifo for all IN endpoints in the selected usb configuration,
regardless of ep enabled status.

Change-Id: I4fe32f338b6f63904dcdc08bdd03dcb093bfd73d
Signed-off-by: default avatarVamsi Krishna <vskrishn@codeaurora.org>
parent d81481d4
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@
#include <linux/vmalloc.h>

#include <linux/usb/ch9.h>
#include <linux/usb/composite.h>
#include <linux/usb/gadget.h>
#include <linux/usb/otg.h>

@@ -191,30 +192,34 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
	int		fifo_size;
	int		mdwidth;
	int		num;
	int		num_eps;
	struct usb_composite_dev *cdev = get_gadget_data(&dwc->gadget);

	if (!dwc->needs_fifo_resize)
		return 0;

	/* gadget.num_eps never be greater than dwc->num_in_eps */
	num_eps = min_t(int, dwc->num_in_eps,
			cdev->config->num_ineps_used + 1);
	ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7);
	mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);

	/* MDWIDTH is represented in bits, we need it in bytes */
	mdwidth >>= 3;

	/*
	 * FIXME For now we will only allocate 1 wMaxPacketSize space
	 * for each enabled endpoint, later patches will come to
	 * improve this algorithm so that we better use the internal
	 * FIFO space. Also consider the case where TxFIFO RAM space
	 * may change dynamically based on the USB configuration.
	 */
	for (num = 0; num < dwc->num_in_eps; num++) {
	dev_dbg(dwc->dev, "%s: num eps: %d\n", __func__, num_eps);

	for (num = 0; num < num_eps; num++) {
		struct dwc3_ep	*dep = dwc->eps[(num << 1) | 1];
		int		mult = 1;
		int		tmp;
		int		max_packet = 1024;

		if (!(dep->flags & DWC3_EP_ENABLED))
			continue;
		if (!(dep->flags & DWC3_EP_ENABLED)) {
			dev_warn(dwc->dev, "ep%dIn not enabled", num);
			tmp = max_packet + mdwidth;
			goto resize_fifo;
		}

		if (((dep->endpoint.maxburst > 1) &&
				usb_endpoint_xfer_bulk(dep->endpoint.desc))
@@ -250,6 +255,7 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
				tmp = mult * (1024 + mdwidth);
		}

resize_fifo:
		tmp += mdwidth;

		fifo_size = DIV_ROUND_UP(tmp, mdwidth);
+6 −0
Original line number Diff line number Diff line
@@ -723,6 +723,8 @@ static int set_config(struct usb_composite_dev *cdev,
		goto done;

	cdev->config = c;
	c->num_ineps_used = 0;
	c->num_outeps_used = 0;

	/* Initialize all interfaces by setting them to altsetting zero. */
	for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) {
@@ -760,6 +762,10 @@ static int set_config(struct usb_composite_dev *cdev,
			addr = ((ep->bEndpointAddress & 0x80) >> 3)
			     |  (ep->bEndpointAddress & 0x0f);
			set_bit(addr, f->endpoints);
			if (usb_endpoint_dir_in(ep))
				c->num_ineps_used++;
			else
				c->num_outeps_used++;
		}

		result = f->set_alt(f, tmp, 0);
+4 −0
Original line number Diff line number Diff line
@@ -260,6 +260,10 @@ struct usb_configuration {
	unsigned		highspeed:1;
	unsigned		fullspeed:1;
	struct usb_function	*interface[MAX_CONFIG_INTERFACES];

	/* number of in and out eps used in this configuration */
	int			num_ineps_used;
	int			num_outeps_used;
};

int usb_add_config(struct usb_composite_dev *,