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

Commit c2d771db authored by Matt Wagantall's avatar Matt Wagantall
Browse files

Revert "HACK: usb: gadget: fix android composite driver build"



This reverts commit 0fdc146d.

In preparation for merging lsk-v3.18-15.07-android into msm-3.18,
revert LSK changes to the android composite gadget driver which were
already present in another form on msm-3.18.

This avoids resolution of some fairly nasty merge conflicts caused by
msm-3.18 having slight different versions of the changes, and issues
due to additional changes to this code in msm-3.18 that are missing
in LSK.

Change-Id: I5e015565c56c3e1060326b265c0c386d54311252
Signed-off-by: default avatarMatt Wagantall <mattw@codeaurora.org>
parent b0477f5f
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -410,6 +410,24 @@ config USB_CONFIGFS_UEVENT
	  state changes. The gadget can be in any of the following
	  three states: "CONNECTED/DISCONNECTED/CONFIGURED"

config USB_G_ANDROID
	boolean "Android Composite Gadget"
	select USB_F_ACM
	select USB_LIBCOMPOSITE
	select USB_U_SERIAL
	help
	  The Android Composite Gadget supports multiple USB
	  functions: adb, acm, mass storage, mtp, accessory
	  and rndis.
	  Each function can be configured and enabled/disabled
	  dynamically from userspace through a sysfs interface.

config USB_ANDROID_RNDIS_DWORD_ALIGNED
	boolean "Use double word aligned"
	depends on USB_G_ANDROID
	help
		Provides dword aligned for DMA controller.

source "drivers/usb/gadget/legacy/Kconfig"

endchoice
+4 −0
Original line number Diff line number Diff line
@@ -9,4 +9,8 @@ obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
libcomposite-y			:= usbstring.o config.o epautoconf.o
libcomposite-y			+= composite.o functions.o configfs.o u_f.o

g_android-y			:= android.o

obj-$(CONFIG_USB_GADGET)	+= udc/ function/ legacy/

obj-$(CONFIG_USB_G_ANDROID)	+= g_android.o
+47 −88
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@

#include "f_fs.c"
#include "f_audio_source.c"
#include "f_mass_storage.c"
#include "f_mtp.c"
#include "f_accessory.c"
#define USB_ETH_RNDIS y
@@ -39,8 +40,6 @@
#include "rndis.c"
#include "u_ether.c"

USB_ETHERNET_MODULE_PARAMETERS();

MODULE_AUTHOR("Mike Lockwood");
MODULE_DESCRIPTION("Android Composite USB Driver");
MODULE_LICENSE("GPL");
@@ -117,22 +116,6 @@ static char manufacturer_string[256];
static char product_string[256];
static char serial_string[256];

/*---Copied from configfs.c to let this composite driver build---*/
static struct class *android_class;
static struct device *android_device;
static int index;

struct device *create_function_device(char *name)
{
        if (android_device && !IS_ERR(android_device))
                return device_create(android_class, android_device,
                        MKDEV(0, index++), NULL, name);
        else
                return ERR_PTR(-EINVAL);
}
EXPORT_SYMBOL_GPL(create_function_device);
/*---------------------------------------------------------------*/

/* String Table */
static struct usb_string strings_dev[] = {
	[STRING_MANUFACTURER_IDX].s = manufacturer_string,
@@ -616,7 +599,7 @@ rndis_function_bind_config(struct android_usb_function *f,
		rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2],
		rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]);

	dev = gether_setup_name(c->cdev->gadget,dev_addr, host_addr, rndis->ethaddr, qmult, "rndis");
	dev = gether_setup_name(c->cdev->gadget, rndis->ethaddr, "rndis");
	if (IS_ERR(dev)) {
		ret = PTR_ERR(dev);
		pr_err("%s: gether_setup failed\n", __func__);
@@ -766,59 +749,47 @@ static struct android_usb_function rndis_function = {
};


#define MAX_MS_INSTANCES 1
struct mass_storage_function_config {
	int instances;
	int instances_on;
	struct usb_function *f_ms[MAX_MS_INSTANCES];
	struct usb_function_instance *f_ms_inst[MAX_MS_INSTANCES];
	struct fsg_config fsg;
	struct fsg_common *common;
};

static int mass_storage_function_init(struct android_usb_function *f,
					struct usb_composite_dev *cdev)
{
	struct mass_storage_function_config *config;
	int i;
	int ret;
	struct fsg_common *common;
	int err;

	config = kzalloc(sizeof(struct mass_storage_function_config),
								GFP_KERNEL);
	if (!config)
		return -ENOMEM;
	f->config = config;

	for (i = 0; i < MAX_MS_INSTANCES; i++) {
		config->f_ms_inst[i] = usb_get_function_instance("mass_storage");
		if (IS_ERR(config->f_ms_inst[i])) {
			ret = PTR_ERR(config->f_ms_inst[i]);
			goto err_usb_get_function_instance;
		}
		config->f_ms[i] = usb_get_function(config->f_ms_inst[i]);
		if (IS_ERR(config->f_ms[i])) {
			ret = PTR_ERR(config->f_ms[i]);
			goto err_usb_get_function;
	config->fsg.nluns = 1;
	config->fsg.luns[0].removable = 1;

	common = fsg_common_init(NULL, cdev, &config->fsg);
	if (IS_ERR(common)) {
		kfree(config);
		return PTR_ERR(common);
	}

	err = sysfs_create_link(&f->dev->kobj,
				&common->luns[0].dev.kobj,
				"lun");
	if (err) {
		kfree(config);
		return err;
	}

	config->common = common;
	f->config = config;
	return 0;
err_usb_get_function_instance:
	while (i-- > 0) {
		usb_put_function(config->f_ms[i]);
err_usb_get_function:
		usb_put_function_instance(config->f_ms_inst[i]);
	}
	return ret;
}

static void mass_storage_function_cleanup(struct android_usb_function *f)
{
	struct mass_storage_function_config *config = f->config;
	int i;

	for (i = 0; i < MAX_MS_INSTANCES; i++) {
		usb_put_function(config->f_ms[i]);
		usb_put_function_instance(config->f_ms_inst[i]);
	}
	kfree(f->config);
	f->config = NULL;
}
@@ -827,34 +798,7 @@ static int mass_storage_function_bind_config(struct android_usb_function *f,
						struct usb_configuration *c)
{
	struct mass_storage_function_config *config = f->config;
	int ret = 0;
	int i;

	config->instances_on = config->instances;
	for (i = 0; i < config->instances_on; i++) {
		ret = usb_add_function(c, config->f_ms[i]);
		if (ret) {
			pr_err("Could not bind ms%u config\n", i);
			goto err_usb_add_function;
		}
	}

	return 0;

err_usb_add_function:
	while (i-- > 0)
		usb_remove_function(c, config->f_ms[i]);
	return ret;
}

static void mass_storage_function_unbind_config(struct android_usb_function *f,
				struct usb_configuration *c)
{
	int i;
	struct mass_storage_function_config *config = f->config;

	for (i = 0; i < config->instances_on; i++)
		usb_remove_function(c, config->f_ms[i]);
	return fsg_bind_config(c->cdev, c, config->common);
}

static ssize_t mass_storage_inquiry_show(struct device *dev,
@@ -862,7 +806,7 @@ static ssize_t mass_storage_inquiry_show(struct device *dev,
{
	struct android_usb_function *f = dev_get_drvdata(dev);
	struct mass_storage_function_config *config = f->config;
	return sprintf(buf, "%d\n", config->instances);
	return sprintf(buf, "%s\n", config->common->inquiry_string);
}

static ssize_t mass_storage_inquiry_store(struct device *dev,
@@ -870,12 +814,10 @@ static ssize_t mass_storage_inquiry_store(struct device *dev,
{
	struct android_usb_function *f = dev_get_drvdata(dev);
	struct mass_storage_function_config *config = f->config;
	int value;

	sscanf(buf, "%d", &value);
	if (value > MAX_MS_INSTANCES)
		value = MAX_MS_INSTANCES;
	config->instances = value;
	if (size >= sizeof(config->common->inquiry_string))
		return -EINVAL;
	if (sscanf(buf, "%s", config->common->inquiry_string) != 1)
		return -EINVAL;
	return size;
}

@@ -965,6 +907,23 @@ static void audio_source_function_unbind_config(struct android_usb_function *f,
	config->device = -1;
}

static ssize_t audio_source_pcm_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct android_usb_function *f = dev_get_drvdata(dev);
	struct audio_source_config *config = f->config;

	/* print PCM card and device numbers */
	return sprintf(buf, "%d %d\n", config->card, config->device);
}

static DEVICE_ATTR(pcm, S_IRUGO, audio_source_pcm_show, NULL);

static struct device_attribute *audio_source_function_attributes[] = {
	&dev_attr_pcm,
	NULL
};

static struct android_usb_function audio_source_function = {
	.name		= "audio_source",
	.init		= audio_source_function_init,
+0 −86
Original line number Diff line number Diff line
@@ -86,15 +86,12 @@ ffs_setup_state_clear_cancelled(struct ffs_data *ffs)
		cmpxchg(&ffs->setup_state, FFS_SETUP_CANCELLED, FFS_NO_SETUP);
}

static void ffs_func_free(struct ffs_function *func);

static void ffs_func_eps_disable(struct ffs_function *func);
static int __must_check ffs_func_eps_enable(struct ffs_function *func);

static int ffs_func_bind(struct usb_configuration *,
			 struct usb_function *);
static void old_ffs_func_unbind(struct usb_configuration *,
				struct usb_function *);
static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned);
static void ffs_func_disable(struct usb_function *);
static int ffs_func_setup(struct usb_function *,
@@ -1619,71 +1616,6 @@ static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
	kfree(epfiles);
}

static int functionfs_bind_config(struct usb_composite_dev *cdev,
				   struct usb_configuration *c,
				   struct ffs_data *ffs)
{
	struct ffs_function *func;
	int ret;

	ENTER();

	func = kzalloc(sizeof *func, GFP_KERNEL);
	if (unlikely(!func))
		return -ENOMEM;

	func->function.name    = "Function FS Gadget";
	func->function.strings = ffs->stringtabs;

	func->function.bind    = ffs_func_bind;
	func->function.unbind  = old_ffs_func_unbind;
	func->function.set_alt = ffs_func_set_alt;
	func->function.disable = ffs_func_disable;
	func->function.setup   = ffs_func_setup;
	func->function.suspend = ffs_func_suspend;
	func->function.resume  = ffs_func_resume;

	func->conf   = c;
	func->gadget = cdev->gadget;
	func->ffs = ffs;
	ffs_data_get(ffs);

	ret = usb_add_function(c, &func->function);
	if (unlikely(ret))
		ffs_func_free(func);

	return ret;
}

static void ffs_func_free(struct ffs_function *func)
{
	struct ffs_ep *ep         = func->eps;
	unsigned count            = func->ffs->eps_count;
	unsigned long flags;

	ENTER();

	/* cleanup after autoconfig */
	spin_lock_irqsave(&func->ffs->eps_lock, flags);
	do {
		if (ep->ep && ep->req)
			usb_ep_free_request(ep->ep, ep->req);
		ep->req = NULL;
		++ep;
	} while (--count);
	spin_unlock_irqrestore(&func->ffs->eps_lock, flags);

	ffs_data_put(func->ffs);

	kfree(func->eps);
	/*
	 * eps and interfaces_nums are allocated in the same chunk so
	 * only one free is required.  Descriptors are also allocated
	 * in the same chunk.
	 */

	kfree(func);
}

static void ffs_func_eps_disable(struct ffs_function *func)
{
@@ -2956,24 +2888,6 @@ static int ffs_func_bind(struct usb_configuration *c,

/* Other USB function hooks *************************************************/

static void old_ffs_func_unbind(struct usb_configuration *c,
				struct usb_function *f)
{
	struct ffs_function *func = ffs_func_from_usb(f);
	struct ffs_data *ffs = func->ffs;

	ENTER();

	if (ffs->func == func) {
		ffs_func_eps_disable(func);
		ffs->func = NULL;
	}

	ffs_event_add(ffs, FUNCTIONFS_UNBIND);

	ffs_func_free(func);
}

static int ffs_func_set_alt(struct usb_function *f,
			    unsigned interface, unsigned alt)
{
+0 −56
Original line number Diff line number Diff line
@@ -870,62 +870,6 @@ fail:
	return status;
}

static void
rndis_old_unbind(struct usb_configuration *c, struct usb_function *f)
{
	struct f_rndis          *rndis = func_to_rndis(f);

	rndis_deregister(rndis->config);

	usb_free_all_descriptors(f);

	kfree(rndis->notify_req->buf);
	usb_ep_free_request(rndis->notify, rndis->notify_req);

	kfree(rndis);
}

int
rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
		u32 vendorID, const char *manufacturer, struct eth_dev *dev)
{
	struct f_rndis  *rndis;
	int             status;

	/* allocate and initialize one new instance */
	status = -ENOMEM;
	rndis = kzalloc(sizeof *rndis, GFP_KERNEL);
	if (!rndis)
		goto fail;

	memcpy(rndis->ethaddr, ethaddr, ETH_ALEN);
	rndis->vendorID = vendorID;
	rndis->manufacturer = manufacturer;

	rndis->port.ioport = dev;
	/* RNDIS activates when the host changes this filter */
	rndis->port.cdc_filter = 0;

	/* RNDIS has special (and complex) framing */
	rndis->port.header_len = sizeof(struct rndis_packet_msg_type);
	rndis->port.wrap = rndis_add_header;
	rndis->port.unwrap = rndis_rm_hdr;

	rndis->port.func.name = "rndis";
	/* descriptors are per-instance copies */
	rndis->port.func.bind = rndis_bind;
	rndis->port.func.unbind = rndis_old_unbind;
	rndis->port.func.set_alt = rndis_set_alt;
	rndis->port.func.setup = rndis_setup;
	rndis->port.func.disable = rndis_disable;

	status = usb_add_function(c, &rndis->port.func);
	if (status)
		kfree(rndis);
fail:
	return status;
}

void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net)
{
	struct f_rndis_opts *opts;
Loading