aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>2013-10-09 04:05:53 -0400
committerFelipe Balbi <balbi@ti.com>2013-10-10 11:21:47 -0400
commitbd528d4e699b212a763eecda9cacffb4b85a5fe6 (patch)
treeecb585092a6e4375d94639e8fe2a934ee87e4b99
parent8502d66d33704d66d29c715ba5e91192b554cef0 (diff)
usb: gadget: f_mass_storage: make sysfs interface optional
When configfs is in place, the luns will not be represented in sysfs, so there will be no struct device associated with a lun. In order to maintain compatibility and allow configfs adoption sysfs is made optional in this patch. As a consequence some debug macros need to be adjusted. Two new fields are added to struct fsg_lun: name and name_pfx. The "name" is for storing a string which is presented to the user instead of the dev_name. The "name_pfx", if non-NULL, is prepended to the "name" at printing time. The name_pfx is for a future lun.0, which will be a default group in mass_storage.<name>. By design at USB function configfs group's creation time its name is not known (but instead set a bit later in drivers/usb/gadget/configfs.c:function_make) and it is this name that serves the purpose of the said name prefix. So instead of copying a yet-unknown string a pointer to it is stored in struct fsg_lun. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r--drivers/usb/gadget/f_mass_storage.c51
-rw-r--r--drivers/usb/gadget/f_mass_storage.h2
-rw-r--r--drivers/usb/gadget/storage_common.h20
3 files changed, 59 insertions, 14 deletions
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 59a12c168cc5..7034d9c8363f 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -299,6 +299,7 @@ struct fsg_common {
299 unsigned int short_packet_received:1; 299 unsigned int short_packet_received:1;
300 unsigned int bad_lun_okay:1; 300 unsigned int bad_lun_okay:1;
301 unsigned int running:1; 301 unsigned int running:1;
302 unsigned int sysfs:1;
302 303
303 int thread_wakeup_needed; 304 int thread_wakeup_needed;
304 struct completion thread_notifier; 305 struct completion thread_notifier;
@@ -2642,6 +2643,11 @@ static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
2642 return -EINVAL; 2643 return -EINVAL;
2643} 2644}
2644 2645
2646void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs)
2647{
2648 common->sysfs = sysfs;
2649}
2650
2645static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n) 2651static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
2646{ 2652{
2647 if (buffhds) { 2653 if (buffhds) {
@@ -2654,6 +2660,34 @@ static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
2654 } 2660 }
2655} 2661}
2656 2662
2663static inline void fsg_common_remove_sysfs(struct fsg_lun *lun)
2664{
2665 device_remove_file(&lun->dev, &dev_attr_nofua);
2666 /*
2667 * device_remove_file() =>
2668 *
2669 * here the attr (e.g. dev_attr_ro) is only used to be passed to:
2670 *
2671 * sysfs_remove_file() =>
2672 *
2673 * here e.g. both dev_attr_ro_cdrom and dev_attr_ro are in
2674 * the same namespace and
2675 * from here only attr->name is passed to:
2676 *
2677 * sysfs_hash_and_remove()
2678 *
2679 * attr->name is the same for dev_attr_ro_cdrom and
2680 * dev_attr_ro
2681 * attr->name is the same for dev_attr_file and
2682 * dev_attr_file_nonremovable
2683 *
2684 * so we don't differentiate between removing e.g. dev_attr_ro_cdrom
2685 * and dev_attr_ro
2686 */
2687 device_remove_file(&lun->dev, &dev_attr_ro);
2688 device_remove_file(&lun->dev, &dev_attr_file);
2689}
2690
2657struct fsg_common *fsg_common_init(struct fsg_common *common, 2691struct fsg_common *fsg_common_init(struct fsg_common *common,
2658 struct usb_composite_dev *cdev, 2692 struct usb_composite_dev *cdev,
2659 struct fsg_config *cfg) 2693 struct fsg_config *cfg)
@@ -2687,6 +2721,8 @@ struct fsg_common *fsg_common_init(struct fsg_common *common,
2687 memset(common, 0, sizeof *common); 2721 memset(common, 0, sizeof *common);
2688 common->free_storage_on_release = 0; 2722 common->free_storage_on_release = 0;
2689 } 2723 }
2724 fsg_common_set_sysfs(common, true);
2725 common->state = FSG_STATE_IDLE;
2690 2726
2691 common->fsg_num_buffers = cfg->fsg_num_buffers; 2727 common->fsg_num_buffers = cfg->fsg_num_buffers;
2692 common->buffhds = kcalloc(common->fsg_num_buffers, 2728 common->buffhds = kcalloc(common->fsg_num_buffers,
@@ -2746,6 +2782,7 @@ struct fsg_common *fsg_common_init(struct fsg_common *common,
2746 /* curlun->dev.driver = &fsg_driver.driver; XXX */ 2782 /* curlun->dev.driver = &fsg_driver.driver; XXX */
2747 dev_set_drvdata(&curlun->dev, &common->filesem); 2783 dev_set_drvdata(&curlun->dev, &common->filesem);
2748 dev_set_name(&curlun->dev, "lun%d", i); 2784 dev_set_name(&curlun->dev, "lun%d", i);
2785 curlun->name = dev_name(&curlun->dev);
2749 2786
2750 rc = device_register(&curlun->dev); 2787 rc = device_register(&curlun->dev);
2751 if (rc) { 2788 if (rc) {
@@ -2892,17 +2929,11 @@ static void fsg_common_release(struct kref *ref)
2892 struct fsg_lun *lun = *lun_it; 2929 struct fsg_lun *lun = *lun_it;
2893 if (!lun) 2930 if (!lun)
2894 continue; 2931 continue;
2895 device_remove_file(&lun->dev, &dev_attr_nofua); 2932 if (common->sysfs)
2896 device_remove_file(&lun->dev, 2933 fsg_common_remove_sysfs(lun);
2897 lun->cdrom
2898 ? &dev_attr_ro_cdrom
2899 : &dev_attr_ro);
2900 device_remove_file(&lun->dev,
2901 lun->removable
2902 ? &dev_attr_file
2903 : &dev_attr_file_nonremovable);
2904 fsg_lun_close(lun); 2934 fsg_lun_close(lun);
2905 device_unregister(&lun->dev); 2935 if (common->sysfs)
2936 device_unregister(&lun->dev);
2906 kfree(lun); 2937 kfree(lun);
2907 } 2938 }
2908 2939
diff --git a/drivers/usb/gadget/f_mass_storage.h b/drivers/usb/gadget/f_mass_storage.h
index b64761d836f6..1b88eae75283 100644
--- a/drivers/usb/gadget/f_mass_storage.h
+++ b/drivers/usb/gadget/f_mass_storage.h
@@ -102,6 +102,8 @@ struct fsg_common *fsg_common_init(struct fsg_common *common,
102 struct usb_composite_dev *cdev, 102 struct usb_composite_dev *cdev,
103 struct fsg_config *cfg); 103 struct fsg_config *cfg);
104 104
105void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs);
106
105void fsg_config_from_params(struct fsg_config *cfg, 107void fsg_config_from_params(struct fsg_config *cfg,
106 const struct fsg_module_parameters *params, 108 const struct fsg_module_parameters *params,
107 unsigned int fsg_num_buffers); 109 unsigned int fsg_num_buffers);
diff --git a/drivers/usb/gadget/storage_common.h b/drivers/usb/gadget/storage_common.h
index 1fcda2bfef6c..d8cc090aca35 100644
--- a/drivers/usb/gadget/storage_common.h
+++ b/drivers/usb/gadget/storage_common.h
@@ -17,10 +17,20 @@
17#define VLDBG(lun, fmt, args...) do { } while (0) 17#define VLDBG(lun, fmt, args...) do { } while (0)
18#endif /* VERBOSE_DEBUG */ 18#endif /* VERBOSE_DEBUG */
19 19
20#define LDBG(lun, fmt, args...) dev_dbg(&(lun)->dev, fmt, ## args) 20#define _LMSG(func, lun, fmt, args...) \
21#define LERROR(lun, fmt, args...) dev_err(&(lun)->dev, fmt, ## args) 21 do { \
22#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) 22 if ((lun)->name_pfx && *(lun)->name_pfx) \
23#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) 23 func("%s/%s: " fmt, *(lun)->name_pfx, \
24 (lun)->name, ## args); \
25 else \
26 func("%s: " fmt, (lun)->name, ## args); \
27 } while (0)
28
29#define LDBG(lun, fmt, args...) _LMSG(pr_debug, lun, fmt, ## args)
30#define LERROR(lun, fmt, args...) _LMSG(pr_err, lun, fmt, ## args)
31#define LWARN(lun, fmt, args...) _LMSG(pr_warn, lun, fmt, ## args)
32#define LINFO(lun, fmt, args...) _LMSG(pr_info, lun, fmt, ## args)
33
24 34
25#ifdef DUMP_MSGS 35#ifdef DUMP_MSGS
26 36
@@ -100,6 +110,8 @@ struct fsg_lun {
100 of bound block device */ 110 of bound block device */
101 unsigned int blksize; /* logical block size of bound block device */ 111 unsigned int blksize; /* logical block size of bound block device */
102 struct device dev; 112 struct device dev;
113 const char *name; /* "lun.name" */
114 const char **name_pfx; /* "function.name" */
103}; 115};
104 116
105static inline bool fsg_lun_is_open(struct fsg_lun *curlun) 117static inline bool fsg_lun_is_open(struct fsg_lun *curlun)