Commit 9cfe745e authored by Michal Nazarewicz's avatar Michal Nazarewicz Committed by Greg Kroah-Hartman

usb: gadget: mass_storage: optional SCSI WRITE FUA bit

The nofua parameter (optionally ignore SCSI WRITE FUA) was added
to the File Storage Gadget some time ago.  This patch adds the
same functionality to the Mass Storage Function.
Signed-off-by: default avatarMichal Nazarewicz <m.nazarewicz@samsung.com>
Cc: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 452ee0eb
...@@ -73,6 +73,8 @@ ...@@ -73,6 +73,8 @@
* being removable. * being removable.
* ->cdrom Flag specifying that LUN shall be reported as * ->cdrom Flag specifying that LUN shall be reported as
* being a CD-ROM. * being a CD-ROM.
* ->nofua Flag specifying that FUA flag in SCSI WRITE(10,12)
* commands for this LUN shall be ignored.
* *
* lun_name_format A printf-like format for names of the LUN * lun_name_format A printf-like format for names of the LUN
* devices. This determines how the * devices. This determines how the
...@@ -127,6 +129,8 @@ ...@@ -127,6 +129,8 @@
* Default true, boolean for removable media. * Default true, boolean for removable media.
* cdrom=b[,b...] Default false, boolean for whether to emulate * cdrom=b[,b...] Default false, boolean for whether to emulate
* a CD-ROM drive. * a CD-ROM drive.
* nofua=b[,b...] Default false, booleans for ignore FUA flag
* in SCSI WRITE(10,12) commands
* luns=N Default N = number of filenames, number of * luns=N Default N = number of filenames, number of
* LUNs to support. * LUNs to support.
* stall Default determined according to the type of * stall Default determined according to the type of
...@@ -409,6 +413,7 @@ struct fsg_config { ...@@ -409,6 +413,7 @@ struct fsg_config {
char ro; char ro;
char removable; char removable;
char cdrom; char cdrom;
char nofua;
} luns[FSG_MAX_LUNS]; } luns[FSG_MAX_LUNS];
const char *lun_name_format; const char *lun_name_format;
...@@ -887,7 +892,7 @@ static int do_write(struct fsg_common *common) ...@@ -887,7 +892,7 @@ static int do_write(struct fsg_common *common)
curlun->sense_data = SS_INVALID_FIELD_IN_CDB; curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
return -EINVAL; return -EINVAL;
} }
if (common->cmnd[1] & 0x08) { /* FUA */ if (!curlun->nofua && (common->cmnd[1] & 0x08)) { /* FUA */
spin_lock(&curlun->filp->f_lock); spin_lock(&curlun->filp->f_lock);
curlun->filp->f_flags |= O_SYNC; curlun->filp->f_flags |= O_SYNC;
spin_unlock(&curlun->filp->f_lock); spin_unlock(&curlun->filp->f_lock);
...@@ -2662,6 +2667,7 @@ static int fsg_main_thread(void *common_) ...@@ -2662,6 +2667,7 @@ static int fsg_main_thread(void *common_)
/* Write permission is checked per LUN in store_*() functions. */ /* Write permission is checked per LUN in store_*() functions. */
static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro); static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, fsg_store_nofua);
static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file); static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
...@@ -2766,6 +2772,9 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, ...@@ -2766,6 +2772,9 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
if (rc) if (rc)
goto error_luns; goto error_luns;
rc = device_create_file(&curlun->dev, &dev_attr_file); rc = device_create_file(&curlun->dev, &dev_attr_file);
if (rc)
goto error_luns;
rc = device_create_file(&curlun->dev, &dev_attr_nofua);
if (rc) if (rc)
goto error_luns; goto error_luns;
...@@ -2911,6 +2920,7 @@ static void fsg_common_release(struct kref *ref) ...@@ -2911,6 +2920,7 @@ static void fsg_common_release(struct kref *ref)
/* In error recovery common->nluns may be zero. */ /* In error recovery common->nluns may be zero. */
for (; i; --i, ++lun) { for (; i; --i, ++lun) {
device_remove_file(&lun->dev, &dev_attr_nofua);
device_remove_file(&lun->dev, &dev_attr_ro); device_remove_file(&lun->dev, &dev_attr_ro);
device_remove_file(&lun->dev, &dev_attr_file); device_remove_file(&lun->dev, &dev_attr_file);
fsg_lun_close(lun); fsg_lun_close(lun);
...@@ -3069,8 +3079,10 @@ struct fsg_module_parameters { ...@@ -3069,8 +3079,10 @@ struct fsg_module_parameters {
int ro[FSG_MAX_LUNS]; int ro[FSG_MAX_LUNS];
int removable[FSG_MAX_LUNS]; int removable[FSG_MAX_LUNS];
int cdrom[FSG_MAX_LUNS]; int cdrom[FSG_MAX_LUNS];
int nofua[FSG_MAX_LUNS];
unsigned int file_count, ro_count, removable_count, cdrom_count; unsigned int file_count, ro_count, removable_count, cdrom_count;
unsigned int nofua_count;
unsigned int luns; /* nluns */ unsigned int luns; /* nluns */
int stall; /* can_stall */ int stall; /* can_stall */
}; };
...@@ -3096,6 +3108,8 @@ struct fsg_module_parameters { ...@@ -3096,6 +3108,8 @@ struct fsg_module_parameters {
"true to simulate removable media"); \ "true to simulate removable media"); \
_FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \ _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
"true to simulate CD-ROM instead of disk"); \ "true to simulate CD-ROM instead of disk"); \
_FSG_MODULE_PARAM_ARRAY(prefix, params, nofua, bool, \
"true to ignore SCSI WRITE(10,12) FUA bit"); \
_FSG_MODULE_PARAM(prefix, params, luns, uint, \ _FSG_MODULE_PARAM(prefix, params, luns, uint, \
"number of LUNs"); \ "number of LUNs"); \
_FSG_MODULE_PARAM(prefix, params, stall, bool, \ _FSG_MODULE_PARAM(prefix, params, stall, bool, \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment