By making that configurable on Kconfig, we won't
need to modify source code when we want to change
the way f_mass_storage behaves for a specific
product.

Signed-off-by: Felipe Balbi <[email protected]>
---
 drivers/usb/gadget/Kconfig          | 15 +++++++++++++++
 drivers/usb/gadget/f_mass_storage.c | 17 ++++++++++-------
 drivers/usb/gadget/storage_common.h |  3 ---
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 0ae2e65..f3b9702 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -127,6 +127,21 @@ config USB_GADGET_STORAGE_NUM_BUFFERS
           a module parameter as well.
           If unsure, say 2.
 
+config USB_GADGET_STORAGE_BUFLEN
+       int "Size of each storage pipeline buffer"
+       range 4096 131072
+       default 16384
+       help
+         For USB2-based device controllers, 16KiB of buffer space is
+         usually enough to maintain the HW FIFOs full during an entire
+         session.
+
+         When dealing with USB3 device controllers, however, 16KiB is
+         not enough.
+
+         Change this to match your device requirements. If unsure, say
+         16384.
+
 #
 # USB Peripheral Controller Support
 #
diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index a03ba2c..fee97c9 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -675,7 +675,7 @@ static int do_read(struct fsg_common *common)
                 * But don't read more than the buffer size.
                 * And don't try to read past the end of the file.
                 */
-               amount = min(amount_left, FSG_BUFLEN);
+               amount = min_t(u32, amount_left, 
CONFIG_USB_GADGET_STORAGE_BUFLEN);
                amount = min((loff_t)amount,
                             curlun->file_length - file_offset);
 
@@ -825,7 +825,8 @@ static int do_write(struct fsg_common *common)
                         * Try to get the remaining amount,
                         * but not more than the buffer size.
                         */
-                       amount = min(amount_left_to_req, FSG_BUFLEN);
+                       amount = min_t(u32, amount_left_to_req,
+                                       CONFIG_USB_GADGET_STORAGE_BUFLEN);
 
                        /* Beyond the end of the backing file? */
                        if (usb_offset >= curlun->file_length) {
@@ -1029,7 +1030,8 @@ static int do_verify(struct fsg_common *common)
                 * the buffer size.
                 * And don't try to read past the end of the file.
                 */
-               amount = min(amount_left, FSG_BUFLEN);
+               amount = min_t(u32, amount_left,
+                               CONFIG_USB_GADGET_STORAGE_BUFLEN);
                amount = min((loff_t)amount,
                             curlun->file_length - file_offset);
                if (amount == 0) {
@@ -1260,7 +1262,7 @@ static int do_mode_sense(struct fsg_common *common, 
struct fsg_buffhd *bh)
        } else {                        /* MODE_SENSE_10 */
                buf[3] = (curlun->ro ? 0x80 : 0x00);            /* WP, DPOFUA */
                buf += 8;
-               limit = 65535;          /* Should really be FSG_BUFLEN */
+               limit = 65535;          /* Should really be 
CONFIG_USB_GADGET_STORAGE_BUFLEN */
        }
 
        /* No block descriptors */
@@ -1487,7 +1489,8 @@ static int throw_away_data(struct fsg_common *common)
                bh = common->next_buffhd_to_fill;
                if (bh->state == BUF_STATE_EMPTY
                 && common->usb_amount_left > 0) {
-                       amount = min(common->usb_amount_left, FSG_BUFLEN);
+                       amount = min_t(u32, common->usb_amount_left,
+                                       CONFIG_USB_GADGET_STORAGE_BUFLEN);
 
                        /*
                         * Except at the end of the transfer, amount will be
@@ -2721,7 +2724,7 @@ int fsg_common_set_num_buffers(struct fsg_common *common, 
unsigned int n)
                bh->next = bh + 1;
                ++bh;
 buffhds_first_it:
-               bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
+               bh->buf = kmalloc(CONFIG_USB_GADGET_STORAGE_BUFLEN, GFP_KERNEL);
                if (unlikely(!bh->buf))
                        goto error_release;
        } while (--i);
@@ -3146,7 +3149,7 @@ static int fsg_bind(struct usb_configuration *c, struct 
usb_function *f)
                fsg_fs_bulk_out_desc.bEndpointAddress;
 
        /* Calculate bMaxBurst, we know packet size is 1024 */
-       max_burst = min_t(unsigned, FSG_BUFLEN / 1024, 15);
+       max_burst = min_t(u32, CONFIG_USB_GADGET_STORAGE_BUFLEN / 1024, 15);
 
        fsg_ss_bulk_in_desc.bEndpointAddress =
                fsg_fs_bulk_in_desc.bEndpointAddress;
diff --git a/drivers/usb/gadget/storage_common.h 
b/drivers/usb/gadget/storage_common.h
index c74c2fd..4610260 100644
--- a/drivers/usb/gadget/storage_common.h
+++ b/drivers/usb/gadget/storage_common.h
@@ -123,9 +123,6 @@ static inline bool fsg_lun_is_open(struct fsg_lun *curlun)
 #define EP0_BUFSIZE    256
 #define DELAYED_STATUS (EP0_BUFSIZE + 999)     /* An impossibly large value */
 
-/* Default size of buffer length. */
-#define FSG_BUFLEN     ((u32)16384)
-
 /* Maximal number of LUNs supported in mass storage function */
 #define FSG_MAX_LUNS   8
 
-- 
1.8.4.GIT

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to