Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1325350

[PATCH v4 37/43] usb: gadget: f_mass_storage: conversion to new API

From Robert Baldyga <r.baldyga@samsung.com>
Newsgroups linux.kernel
Subject [PATCH v4 37/43] usb: gadget: f_mass_storage: conversion to new API
Date 2016-02-03 13:50 +0100
Message-ID <qY52H-212-29@gated-at.bofh.it> (permalink)
References <qY52F-212-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Generate descriptors in new format and attach them to USB function in
prep_descs(). Change set_alt() implementation and implement clear_alt()
operation. Remove boilerplate code.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/gadget/function/f_mass_storage.c | 91 +++++++++-------------------
 drivers/usb/gadget/function/storage_common.c | 29 ---------
 drivers/usb/gadget/function/storage_common.h |  3 -
 3 files changed, 29 insertions(+), 94 deletions(-)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 223ccf8..fa2326f 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -233,6 +233,17 @@ static const char fsg_string_interface[] = "Mass Storage";
 #include "storage_common.h"
 #include "f_mass_storage.h"
 
+USB_COMPOSITE_ENDPOINT(ep_in, &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
+                &fsg_ss_bulk_in_desc, &fsg_ss_bulk_in_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_out, &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
+                &fsg_ss_bulk_out_desc, &fsg_ss_bulk_out_comp_desc);
+
+USB_COMPOSITE_ALTSETTING(intf0alt0, &fsg_intf_desc, &ep_in, &ep_out);
+
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+
+USB_COMPOSITE_DESCRIPTORS(fsg_descs, &intf0);
+
 /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
 static struct usb_string		fsg_strings[] = {
 	{FSG_STRING_INTERFACE,		fsg_string_interface},
@@ -325,8 +336,6 @@ struct fsg_dev {
 	struct usb_gadget	*gadget;	/* Copy of cdev->gadget */
 	struct fsg_common	*common;
 
-	u16			interface_number;
-
 	unsigned int		bulk_in_enabled:1;
 	unsigned int		bulk_out_enabled:1;
 
@@ -522,7 +531,7 @@ static int fsg_setup(struct usb_function *f,
 		if (ctrl->bRequestType !=
 		    (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
 			break;
-		if (w_index != fsg->interface_number || w_value != 0 ||
+		if (w_index != usb_get_interface_id(f, 0) || w_value != 0 ||
 				w_length != 0)
 			return -EDOM;
 
@@ -538,7 +547,7 @@ static int fsg_setup(struct usb_function *f,
 		if (ctrl->bRequestType !=
 		    (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
 			break;
-		if (w_index != fsg->interface_number || w_value != 0 ||
+		if (w_index != usb_get_interface_id(f, 0) || w_value != 0 ||
 				w_length != 1)
 			return -EDOM;
 		VDBG(fsg, "get max LUN\n");
@@ -2328,19 +2337,27 @@ reset:
 static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
 {
 	struct fsg_dev *fsg = fsg_from_func(f);
+
+	fsg->bulk_in = usb_function_get_ep(f, intf, 0);
+	if (!fsg->bulk_in)
+		return -ENODEV;
+
+	fsg->bulk_out = usb_function_get_ep(f, intf, 1);
+	if (!fsg->bulk_out)
+		return -ENODEV;
+
 	fsg->common->new_fsg = fsg;
 	raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
 	return USB_GADGET_DELAYED_STATUS;
 }
 
-static void fsg_disable(struct usb_function *f)
+static void fsg_clear_alt(struct usb_function *f, unsigned intf, unsigned alt)
 {
 	struct fsg_dev *fsg = fsg_from_func(f);
 	fsg->common->new_fsg = NULL;
 	raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
 }
 
-
 /*-------------------------------------------------------------------------*/
 
 static void handle_exception(struct fsg_common *common)
@@ -3025,13 +3042,11 @@ static void fsg_common_release(struct kref *ref)
 
 /*-------------------------------------------------------------------------*/
 
-static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
+static int fsg_prep_descs(struct usb_function *f)
 {
 	struct fsg_dev		*fsg = fsg_from_func(f);
 	struct fsg_common	*common = fsg->common;
-	struct usb_gadget	*gadget = c->cdev->gadget;
-	int			i;
-	struct usb_ep		*ep;
+	struct usb_gadget	*gadget = f->config->cdev->gadget;
 	unsigned		max_burst;
 	int			ret;
 	struct fsg_opts		*opts;
@@ -3045,7 +3060,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
 
 	opts = fsg_opts_from_func_inst(f->fi);
 	if (!opts->no_configfs) {
-		ret = fsg_common_set_cdev(fsg->common, c->cdev,
+		ret = fsg_common_set_cdev(fsg->common, f->config->cdev,
 					  fsg->common->can_stall);
 		if (ret)
 			return ret;
@@ -3057,58 +3072,12 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
 
 	fsg->gadget = gadget;
 
-	/* New interface */
-	i = usb_interface_id(c, f);
-	if (i < 0)
-		goto fail;
-	fsg_intf_desc.bInterfaceNumber = i;
-	fsg->interface_number = i;
-
-	/* Find all the endpoints we will use */
-	ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
-	if (!ep)
-		goto autoconf_fail;
-	fsg->bulk_in = ep;
-
-	ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
-	if (!ep)
-		goto autoconf_fail;
-	fsg->bulk_out = ep;
-
-	/* Assume endpoint addresses are the same for both speeds */
-	fsg_hs_bulk_in_desc.bEndpointAddress =
-		fsg_fs_bulk_in_desc.bEndpointAddress;
-	fsg_hs_bulk_out_desc.bEndpointAddress =
-		fsg_fs_bulk_out_desc.bEndpointAddress;
-
 	/* Calculate bMaxBurst, we know packet size is 1024 */
 	max_burst = min_t(unsigned, FSG_BUFLEN / 1024, 15);
-
-	fsg_ss_bulk_in_desc.bEndpointAddress =
-		fsg_fs_bulk_in_desc.bEndpointAddress;
 	fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
-
-	fsg_ss_bulk_out_desc.bEndpointAddress =
-		fsg_fs_bulk_out_desc.bEndpointAddress;
 	fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
 
-	ret = usb_assign_descriptors(f, fsg_fs_function, fsg_hs_function,
-			fsg_ss_function);
-	if (ret)
-		goto autoconf_fail;
-
-	return 0;
-
-autoconf_fail:
-	ERROR(fsg, "unable to autoconfigure all endpoints\n");
-	i = -ENOTSUPP;
-fail:
-	/* terminate the thread */
-	if (fsg->common->state != FSG_STATE_TERMINATED) {
-		raise_exception(fsg->common, FSG_STATE_EXIT);
-		wait_for_completion(&fsg->common->thread_notifier);
-	}
-	return i;
+	return usb_function_set_descs(f, &fsg_descs);
 }
 
 /****************************** ALLOCATE FUNCTION *************************/
@@ -3125,8 +3094,6 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
 		/* FIXME: make interruptible or killable somehow? */
 		wait_event(common->fsg_wait, common->fsg != fsg);
 	}
-
-	usb_free_all_descriptors(&fsg->function);
 }
 
 static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item)
@@ -3529,11 +3496,11 @@ static struct usb_function *fsg_alloc(struct usb_function_instance *fi)
 	mutex_unlock(&opts->lock);
 
 	fsg->function.name	= FSG_DRIVER_DESC;
-	fsg->function.bind	= fsg_bind;
+	fsg->function.prep_descs	= fsg_prep_descs;
 	fsg->function.unbind	= fsg_unbind;
 	fsg->function.setup	= fsg_setup;
 	fsg->function.set_alt	= fsg_set_alt;
-	fsg->function.disable	= fsg_disable;
+	fsg->function.clear_alt	= fsg_clear_alt;
 	fsg->function.free_func	= fsg_free;
 
 	fsg->common               = common;
diff --git a/drivers/usb/gadget/function/storage_common.c b/drivers/usb/gadget/function/storage_common.c
index d626830..94f23814 100644
--- a/drivers/usb/gadget/function/storage_common.c
+++ b/drivers/usb/gadget/function/storage_common.c
@@ -70,15 +70,6 @@ struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = {
 };
 EXPORT_SYMBOL_GPL(fsg_fs_bulk_out_desc);
 
-struct usb_descriptor_header *fsg_fs_function[] = {
-	(struct usb_descriptor_header *) &fsg_intf_desc,
-	(struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
-	(struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
-	NULL,
-};
-EXPORT_SYMBOL_GPL(fsg_fs_function);
-
-
 /*
  * USB 2.0 devices need to expose both high speed and full speed
  * descriptors, unless they only run at full speed.
@@ -108,15 +99,6 @@ struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = {
 };
 EXPORT_SYMBOL_GPL(fsg_hs_bulk_out_desc);
 
-
-struct usb_descriptor_header *fsg_hs_function[] = {
-	(struct usb_descriptor_header *) &fsg_intf_desc,
-	(struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
-	(struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
-	NULL,
-};
-EXPORT_SYMBOL_GPL(fsg_hs_function);
-
 struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = {
 	.bLength =		USB_DT_ENDPOINT_SIZE,
 	.bDescriptorType =	USB_DT_ENDPOINT,
@@ -153,17 +135,6 @@ struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = {
 };
 EXPORT_SYMBOL_GPL(fsg_ss_bulk_out_comp_desc);
 
-struct usb_descriptor_header *fsg_ss_function[] = {
-	(struct usb_descriptor_header *) &fsg_intf_desc,
-	(struct usb_descriptor_header *) &fsg_ss_bulk_in_desc,
-	(struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc,
-	(struct usb_descriptor_header *) &fsg_ss_bulk_out_desc,
-	(struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc,
-	NULL,
-};
-EXPORT_SYMBOL_GPL(fsg_ss_function);
-
-
  /*-------------------------------------------------------------------------*/
 
 /*
diff --git a/drivers/usb/gadget/function/storage_common.h b/drivers/usb/gadget/function/storage_common.h
index c3544e6..f5d9146 100644
--- a/drivers/usb/gadget/function/storage_common.h
+++ b/drivers/usb/gadget/function/storage_common.h
@@ -190,17 +190,14 @@ extern struct usb_interface_descriptor fsg_intf_desc;
 
 extern struct usb_endpoint_descriptor fsg_fs_bulk_in_desc;
 extern struct usb_endpoint_descriptor fsg_fs_bulk_out_desc;
-extern struct usb_descriptor_header *fsg_fs_function[];
 
 extern struct usb_endpoint_descriptor fsg_hs_bulk_in_desc;
 extern struct usb_endpoint_descriptor fsg_hs_bulk_out_desc;
-extern struct usb_descriptor_header *fsg_hs_function[];
 
 extern struct usb_endpoint_descriptor fsg_ss_bulk_in_desc;
 extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc;
 extern struct usb_endpoint_descriptor fsg_ss_bulk_out_desc;
 extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc;
-extern struct usb_descriptor_header *fsg_ss_function[];
 
 void fsg_lun_close(struct fsg_lun *curlun);
 int fsg_lun_open(struct fsg_lun *curlun, const char *filename);
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/43] usb: gadget: composite: introduce new function API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 10/43] usb: gadget: composite: handle vendor descs Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 16/43] usb: gadget: composite: add usb_function_get_ep()  function Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 24/43] usb: gadget: f_rndis: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 18/43] usb: gadget: composite: usb_get_endpoint_address()  function Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 06/43] usb: gadget: composite: introduce new descriptors  format Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
    Re: [PATCH v4 06/43] usb: gadget: composite: introduce new  descriptors format kbuild test robot <lkp@intel.com> - 2016-02-04 06:20 +0100
  [PATCH v4 15/43] usb: gadget: composite: handle get_alt() automatically Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 04/43] usb: gadget: configfs: fix error path Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 37/43] usb: gadget: f_mass_storage: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 23/43] usb: gadget: f_ecm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 02/43] usb: gadget: f_sourcesink: free requests in  sourcesink_disable() Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 13/43] usb: gadget: composite: enable eps before calling  set_alt() callback Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 32/43] usb: gadget: f_obex: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 20/43] usb: gadget: configfs: add new composite API support Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 27/43] usb: gadget: f_acm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 26/43] usb: gadget: f_hid: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 30/43] usb: gadget: f_printer: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 08/43] usb: gadget: composite: introduce new USB function ops Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 35/43] usb: gadget: f_uac1: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 31/43] usb: gadget: f_serial: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 42/43] Documentation: update uvc configfs interface  description Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 43/43] usb: gadget: f_uvc: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 25/43] usb: gadget: f_hid: handle requests lifetime properly Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 03/43] usb: gadget: f_loopback: free requests in  loopback_disable() Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 38/43] usb: gadget: u_serial: remove  usb_ep_enable()/usb_ep_disable() Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 34/43] usb: gadget: f_subset: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 29/43] usb: gadget: f_ncm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 22/43] usb: gadget: f_sourcesink: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 39/43] usb: gadget: u_ether: remove  usb_ep_enable()/usb_ep_disable() Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 40/43] usb: gadget: uvc: fix typo in UVCG_OPTS_ATTR() macro Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 36/43] usb: gadget: f_uac2: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 41/43] usb: gadget: uvc: simplify descriptors generation Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
  [PATCH v4 09/43] usb: gadget: composite: handle function bind Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
    Re: [PATCH v4 09/43] usb: gadget: composite: handle function bind kbuild test robot <lkp@intel.com> - 2016-02-04 06:50 +0100
  [PATCH v4 01/43] usb: gadget: f_sourcesink: make ISO altset  user-selectable Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
  [PATCH v4 12/43] usb: gadget: composite: disable eps before calling  disable() callback Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
  [PATCH v4 17/43] usb: gadget: composite: add usb_get_interface_id()  function Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
  [PATCH v4 19/43] usb: gadget: composite: enable adding USB functions  using new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
  [PATCH v4 05/43] usb: gadget: composite: fix recursive spinlock locking Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
  [PATCH v4 21/43] usb: gadget: f_loopback: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
  [PATCH v4 14/43] usb: gadget: composite: introduce clear_alt()  operation Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
  [PATCH v4 11/43] usb: gadget: composite: generate old descs for  compatibility Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
  [PATCH v4 07/43] usb: gadget: composite: add functions for descriptors  handling Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100

csiph-web