@@ -33,17 +33,7 @@ MODULE_AUTHOR("Michal Nazarewicz");
3333MODULE_LICENSE ("GPL" );
3434
3535
36- /***************************** All the files... *****************************/
37-
38- /*
39- * kbuild is not very cooperative with respect to linking separately
40- * compiled library objects into one module. So for now we won't use
41- * separate compilation ... ensuring init/exit sections work to shrink
42- * the runtime footprint, and giving us at least some parts of what
43- * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
44- */
45- #define USB_FMS_INCLUDED
46- #include "f_mass_storage.c"
36+ #include "f_mass_storage.h"
4737
4838#include "u_ecm.h"
4939#ifdef USB_ETH_RNDIS
@@ -148,19 +138,20 @@ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
148138
149139FSG_MODULE_PARAMETERS (/* no prefix */ , fsg_mod_data );
150140
151- static struct fsg_common fsg_common ;
152-
153141static struct usb_function_instance * fi_acm ;
142+ static struct usb_function_instance * fi_msg ;
154143
155144/********** RNDIS **********/
156145
157146#ifdef USB_ETH_RNDIS
158147static struct usb_function_instance * fi_rndis ;
159148static struct usb_function * f_acm_rndis ;
160149static struct usb_function * f_rndis ;
150+ static struct usb_function * f_msg_rndis ;
161151
162152static __init int rndis_do_config (struct usb_configuration * c )
163153{
154+ struct fsg_opts * fsg_opts ;
164155 int ret ;
165156
166157 if (gadget_is_otg (c -> cdev -> gadget )) {
@@ -186,11 +177,24 @@ static __init int rndis_do_config(struct usb_configuration *c)
186177 if (ret )
187178 goto err_conf ;
188179
189- ret = fsg_bind_config (c -> cdev , c , & fsg_common );
190- if (ret < 0 )
180+ f_msg_rndis = usb_get_function (fi_msg );
181+ if (IS_ERR (f_msg_rndis )) {
182+ ret = PTR_ERR (f_msg_rndis );
191183 goto err_fsg ;
184+ }
185+
186+ fsg_opts = fsg_opts_from_func_inst (fi_msg );
187+ ret = fsg_common_run_thread (fsg_opts -> common );
188+ if (ret )
189+ goto err_run ;
190+
191+ ret = usb_add_function (c , f_msg_rndis );
192+ if (ret )
193+ goto err_run ;
192194
193195 return 0 ;
196+ err_run :
197+ usb_put_function (f_msg_rndis );
194198err_fsg :
195199 usb_remove_function (c , f_acm_rndis );
196200err_conf :
@@ -231,9 +235,11 @@ static __ref int rndis_config_register(struct usb_composite_dev *cdev)
231235static struct usb_function_instance * fi_ecm ;
232236static struct usb_function * f_acm_multi ;
233237static struct usb_function * f_ecm ;
238+ static struct usb_function * f_msg_multi ;
234239
235240static __init int cdc_do_config (struct usb_configuration * c )
236241{
242+ struct fsg_opts * fsg_opts ;
237243 int ret ;
238244
239245 if (gadget_is_otg (c -> cdev -> gadget )) {
@@ -260,11 +266,24 @@ static __init int cdc_do_config(struct usb_configuration *c)
260266 if (ret )
261267 goto err_conf ;
262268
263- ret = fsg_bind_config (c -> cdev , c , & fsg_common );
264- if (ret < 0 )
269+ f_msg_multi = usb_get_function (fi_msg );
270+ if (IS_ERR (f_msg_multi )) {
271+ ret = PTR_ERR (f_msg_multi );
265272 goto err_fsg ;
273+ }
274+
275+ fsg_opts = fsg_opts_from_func_inst (fi_msg );
276+ ret = fsg_common_run_thread (fsg_opts -> common );
277+ if (ret )
278+ goto err_run ;
279+
280+ ret = usb_add_function (c , f_msg_multi );
281+ if (ret )
282+ goto err_run ;
266283
267284 return 0 ;
285+ err_run :
286+ usb_put_function (f_msg_multi );
268287err_fsg :
269288 usb_remove_function (c , f_acm_multi );
270289err_conf :
@@ -311,6 +330,8 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
311330#ifdef USB_ETH_RNDIS
312331 struct f_rndis_opts * rndis_opts ;
313332#endif
333+ struct fsg_opts * fsg_opts ;
334+ struct fsg_config config ;
314335 int status ;
315336
316337 if (!can_support_ecm (cdev -> gadget )) {
@@ -373,41 +394,65 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
373394 }
374395
375396 /* set up mass storage function */
376- {
377- void * retp ;
378- retp = fsg_common_from_params (& fsg_common , cdev , & fsg_mod_data ,
379- fsg_num_buffers );
380- if (IS_ERR (retp )) {
381- status = PTR_ERR (retp );
382- goto fail1 ;
383- }
397+ fi_msg = usb_get_function_instance ("mass_storage" );
398+ if (IS_ERR (fi_msg )) {
399+ status = PTR_ERR (fi_msg );
400+ goto fail1 ;
384401 }
402+ fsg_config_from_params (& config , & fsg_mod_data , fsg_num_buffers );
403+ fsg_opts = fsg_opts_from_func_inst (fi_msg );
404+
405+ fsg_opts -> no_configfs = true;
406+ status = fsg_common_set_num_buffers (fsg_opts -> common , fsg_num_buffers );
407+ if (status )
408+ goto fail2 ;
409+
410+ status = fsg_common_set_nluns (fsg_opts -> common , config .nluns );
411+ if (status )
412+ goto fail_set_nluns ;
413+
414+ status = fsg_common_set_cdev (fsg_opts -> common , cdev , config .can_stall );
415+ if (status )
416+ goto fail_set_cdev ;
417+
418+ fsg_common_set_sysfs (fsg_opts -> common , true);
419+ status = fsg_common_create_luns (fsg_opts -> common , & config );
420+ if (status )
421+ goto fail_set_cdev ;
422+
423+ fsg_common_set_inquiry_string (fsg_opts -> common , config .vendor_name ,
424+ config .product_name );
385425
386426 /* allocate string IDs */
387427 status = usb_string_ids_tab (cdev , strings_dev );
388428 if (unlikely (status < 0 ))
389- goto fail2 ;
429+ goto fail_string_ids ;
390430 device_desc .iProduct = strings_dev [USB_GADGET_PRODUCT_IDX ].id ;
391431
392432 /* register configurations */
393433 status = rndis_config_register (cdev );
394434 if (unlikely (status < 0 ))
395- goto fail2 ;
435+ goto fail_string_ids ;
396436
397437 status = cdc_config_register (cdev );
398438 if (unlikely (status < 0 ))
399- goto fail2 ;
439+ goto fail_string_ids ;
400440 usb_composite_overwrite_options (cdev , & coverwrite );
401441
402442 /* we're done */
403443 dev_info (& gadget -> dev , DRIVER_DESC "\n" );
404- fsg_common_put (& fsg_common );
405444 return 0 ;
406445
407446
408447 /* error recovery */
448+ fail_string_ids :
449+ fsg_common_remove_luns (fsg_opts -> common );
450+ fail_set_cdev :
451+ fsg_common_free_luns (fsg_opts -> common );
452+ fail_set_nluns :
453+ fsg_common_free_buffers (fsg_opts -> common );
409454fail2 :
410- fsg_common_put ( & fsg_common );
455+ usb_put_function_instance ( fi_msg );
411456fail1 :
412457 usb_put_function_instance (fi_acm );
413458fail0 :
@@ -423,6 +468,13 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
423468
424469static int __exit multi_unbind (struct usb_composite_dev * cdev )
425470{
471+ #ifdef CONFIG_USB_G_MULTI_CDC
472+ usb_put_function (f_msg_multi );
473+ #endif
474+ #ifdef USB_ETH_RNDIS
475+ usb_put_function (f_msg_rndis );
476+ #endif
477+ usb_put_function_instance (fi_msg );
426478#ifdef CONFIG_USB_G_MULTI_CDC
427479 usb_put_function (f_acm_multi );
428480#endif
0 commit comments