]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge branch 'for-next' of git://gitorious.org/usb/usb into usb-next
authorGreg Kroah-Hartman <gregkh@suse.de>
Sun, 18 Sep 2011 08:42:59 +0000 (01:42 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Sun, 18 Sep 2011 08:45:29 +0000 (01:45 -0700)
* 'for-next' of git://gitorious.org/usb/usb: (47 commits)
  usb: musb: Enable DMA mode1 RX for transfers without short packets
  usb: musb: fix build breakage
  usb: gadget: audio: queue wLength-sized requests
  usb: gadget: audio: actually support both speeds
  usb: gadget: storage: make FSG_NUM_BUFFERS variable size
  USB: gadget: storage: remove alignment assumption
  usb: gadget: storage: adapt logic block size to bound block devices
  usb: dwc3: gadget: improve debug on link state change
  usb: dwc3: omap: set idle and standby modes
  usb: dwc3: ep0: introduce ep0_expect_in flag
  usb: dwc3: ep0: giveback requests on stall_and_restart
  usb: dwc3: gadget: drop the useless dma_sync_single* calls
  usb: dwc3: gadget: fix GCTL programming
  usb: dwc3: define ScaleDown macro helper
  usb: dwc3: Fix definition of DWC3_GCTL_U2RSTECN
  usb: dwc3: gadget: do not map/unmap ZLP transfers
  usb: dwc3: omap: fix IRQ handling
  usb: dwc3: omap: change IRQ name to dwc3-omap
  usb: dwc3: add module.h to dwc3-omap.c and core.c
  usb: dwc3: omap: distinguish between SW and HW modes
  ...

1  2 
drivers/usb/gadget/file_storage.c
drivers/usb/gadget/storage_common.c
drivers/usb/musb/musb_gadget.c

index 4ac8084b579c135c275c164be12bb8fd53fc9fe7,4b9797d07a67bc8af1b8325baf9ae1d4cb1c2d1f..12ac30b21ba6a93854829f5b61434397454719fd
@@@ -69,8 -69,7 +69,7 @@@
   * each LUN would be settable independently as a disk drive or a CD-ROM
   * drive, but currently all LUNs have to be the same type.  The CD-ROM
   * emulation includes a single data track and no audio tracks; hence there
-  * need be only one backing file per LUN.  Note also that the CD-ROM block
-  * length is set to 512 rather than the more common value 2048.
+  * need be only one backing file per LUN.
   *
   * Requirements are modest; only a bulk-in and a bulk-out endpoint are
   * needed (an interrupt-out endpoint is also needed for CBI).  The memory
@@@ -461,7 -460,6 +460,6 @@@ struct fsg_dev 
  
        struct fsg_buffhd       *next_buffhd_to_fill;
        struct fsg_buffhd       *next_buffhd_to_drain;
-       struct fsg_buffhd       buffhds[FSG_NUM_BUFFERS];
  
        int                     thread_wakeup_needed;
        struct completion       thread_notifier;
        unsigned int            nluns;
        struct fsg_lun          *luns;
        struct fsg_lun          *curlun;
+       /* Must be the last entry */
+       struct fsg_buffhd       buffhds[];
  };
  
  typedef void (*fsg_routine_t)(struct fsg_dev *);
@@@ -1136,7 -1136,6 +1136,6 @@@ static int do_read(struct fsg_dev *fsg
        u32                     amount_left;
        loff_t                  file_offset, file_offset_tmp;
        unsigned int            amount;
-       unsigned int            partial_page;
        ssize_t                 nread;
  
        /* Get the starting Logical Block Address and check that it's
                curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
                return -EINVAL;
        }
-       file_offset = ((loff_t) lba) << 9;
+       file_offset = ((loff_t) lba) << curlun->blkbits;
  
        /* Carry out the file reads */
        amount_left = fsg->data_size_from_cmnd;
                 * Try to read the remaining amount.
                 * But don't read more than the buffer size.
                 * And don't try to read past the end of the file.
-                * Finally, if we're not at a page boundary, don't read past
-                *      the next page.
-                * If this means reading 0 then we were asked to read past
-                *      the end of file. */
+                */
                amount = min((unsigned int) amount_left, mod_data.buflen);
                amount = min((loff_t) amount,
                                curlun->file_length - file_offset);
-               partial_page = file_offset & (PAGE_CACHE_SIZE - 1);
-               if (partial_page > 0)
-                       amount = min(amount, (unsigned int) PAGE_CACHE_SIZE -
-                                       partial_page);
  
                /* Wait for the next buffer to become available */
                bh = fsg->next_buffhd_to_fill;
                if (amount == 0) {
                        curlun->sense_data =
                                        SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-                       curlun->sense_data_info = file_offset >> 9;
+                       curlun->sense_data_info = file_offset >> curlun->blkbits;
                        curlun->info_valid = 1;
                        bh->inreq->length = 0;
                        bh->state = BUF_STATE_FULL;
                } else if (nread < amount) {
                        LDBG(curlun, "partial file read: %d/%u\n",
                                        (int) nread, amount);
-                       nread -= (nread & 511); // Round down to a block
+                       nread = round_down(nread, curlun->blksize);
                }
                file_offset  += nread;
                amount_left  -= nread;
                fsg->residue -= nread;
+               /* Except at the end of the transfer, nread will be
+                * equal to the buffer size, which is divisible by the
+                * bulk-in maxpacket size.
+                */
                bh->inreq->length = nread;
                bh->state = BUF_STATE_FULL;
  
                /* If an error occurred, report it and its position */
                if (nread < amount) {
                        curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
-                       curlun->sense_data_info = file_offset >> 9;
+                       curlun->sense_data_info = file_offset >> curlun->blkbits;
                        curlun->info_valid = 1;
                        break;
                }
@@@ -1262,7 -1259,6 +1259,6 @@@ static int do_write(struct fsg_dev *fsg
        u32                     amount_left_to_req, amount_left_to_write;
        loff_t                  usb_offset, file_offset, file_offset_tmp;
        unsigned int            amount;
-       unsigned int            partial_page;
        ssize_t                 nwritten;
        int                     rc;
  
  
        /* Carry out the file writes */
        get_some_more = 1;
-       file_offset = usb_offset = ((loff_t) lba) << 9;
+       file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
        amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  
        while (amount_left_to_write > 0) {
                if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  
                        /* Figure out how much we want to get:
-                        * Try to get the remaining amount.
-                        * But don't get more than the buffer size.
-                        * And don't try to go past the end of the file.
-                        * If we're not at a page boundary,
-                        *      don't go past the next page.
-                        * If this means getting 0, then we were asked
-                        *      to write past the end of file.
-                        * Finally, round down to a block boundary. */
+                        * Try to get the remaining amount,
+                        * but not more than the buffer size.
+                        */
                        amount = min(amount_left_to_req, mod_data.buflen);
-                       amount = min((loff_t) amount, curlun->file_length -
-                                       usb_offset);
-                       partial_page = usb_offset & (PAGE_CACHE_SIZE - 1);
-                       if (partial_page > 0)
-                               amount = min(amount,
-       (unsigned int) PAGE_CACHE_SIZE - partial_page);
-                       if (amount == 0) {
+                       /* Beyond the end of the backing file? */
+                       if (usb_offset >= curlun->file_length) {
                                get_some_more = 0;
                                curlun->sense_data =
                                        SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-                               curlun->sense_data_info = usb_offset >> 9;
+                               curlun->sense_data_info = usb_offset >> curlun->blkbits;
                                curlun->info_valid = 1;
                                continue;
                        }
-                       amount -= (amount & 511);
-                       if (amount == 0) {
-                               /* Why were we were asked to transfer a
-                                * partial block? */
-                               get_some_more = 0;
-                               continue;
-                       }
  
                        /* Get the next buffer */
                        usb_offset += amount;
                        if (amount_left_to_req == 0)
                                get_some_more = 0;
  
-                       /* amount is always divisible by 512, hence by
-                        * the bulk-out maxpacket size */
+                       /* Except at the end of the transfer, amount will be
+                        * equal to the buffer size, which is divisible by
+                        * the bulk-out maxpacket size.
+                        */
                        bh->outreq->length = bh->bulk_out_intended_length =
                                        amount;
                        bh->outreq->short_not_ok = 1;
                        /* Did something go wrong with the transfer? */
                        if (bh->outreq->status != 0) {
                                curlun->sense_data = SS_COMMUNICATION_FAILURE;
-                               curlun->sense_data_info = file_offset >> 9;
+                               curlun->sense_data_info = file_offset >> curlun->blkbits;
                                curlun->info_valid = 1;
                                break;
                        }
                                amount = curlun->file_length - file_offset;
                        }
  
+                       /* Don't write a partial block */
+                       amount = round_down(amount, curlun->blksize);
+                       if (amount == 0)
+                               goto empty_write;
                        /* Perform the write */
                        file_offset_tmp = file_offset;
                        nwritten = vfs_write(curlun->filp,
                        } else if (nwritten < amount) {
                                LDBG(curlun, "partial file write: %d/%u\n",
                                                (int) nwritten, amount);
-                               nwritten -= (nwritten & 511);
-                                               // Round down to a block
+                               nwritten = round_down(nwritten, curlun->blksize);
                        }
                        file_offset += nwritten;
                        amount_left_to_write -= nwritten;
                        /* If an error occurred, report it and its position */
                        if (nwritten < amount) {
                                curlun->sense_data = SS_WRITE_ERROR;
-                               curlun->sense_data_info = file_offset >> 9;
+                               curlun->sense_data_info = file_offset >> curlun->blkbits;
                                curlun->info_valid = 1;
                                break;
                        }
  
+  empty_write:
                        /* Did the host decide to stop early? */
                        if (bh->outreq->actual != bh->outreq->length) {
                                fsg->short_packet_received = 1;
@@@ -1500,8 -1485,8 +1485,8 @@@ static int do_verify(struct fsg_dev *fs
                return -EIO;            // No default reply
  
        /* Prepare to carry out the file verify */
-       amount_left = verification_length << 9;
-       file_offset = ((loff_t) lba) << 9;
+       amount_left = verification_length << curlun->blkbits;
+       file_offset = ((loff_t) lba) << curlun->blkbits;
  
        /* Write out all the dirty buffers before invalidating them */
        fsg_lun_fsync_sub(curlun);
                 * Try to read the remaining amount, but not more than
                 * the buffer size.
                 * And don't try to read past the end of the file.
-                * If this means reading 0 then we were asked to read
-                * past the end of file. */
+                */
                amount = min((unsigned int) amount_left, mod_data.buflen);
                amount = min((loff_t) amount,
                                curlun->file_length - file_offset);
                if (amount == 0) {
                        curlun->sense_data =
                                        SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
-                       curlun->sense_data_info = file_offset >> 9;
+                       curlun->sense_data_info = file_offset >> curlun->blkbits;
                        curlun->info_valid = 1;
                        break;
                }
                } else if (nread < amount) {
                        LDBG(curlun, "partial file verify: %d/%u\n",
                                        (int) nread, amount);
-                       nread -= (nread & 511); // Round down to a sector
+                       nread = round_down(nread, curlun->blksize);
                }
                if (nread == 0) {
                        curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
-                       curlun->sense_data_info = file_offset >> 9;
+                       curlun->sense_data_info = file_offset >> curlun->blkbits;
                        curlun->info_valid = 1;
                        break;
                }
@@@ -1668,7 -1652,7 +1652,7 @@@ static int do_read_capacity(struct fsg_
  
        put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
                                                /* Max logical block */
-       put_unaligned_be32(512, &buf[4]);       /* Block length */
+       put_unaligned_be32(curlun->blksize, &buf[4]);   /* Block length */
        return 8;
  }
  
@@@ -1890,7 -1874,7 +1874,7 @@@ static int do_read_format_capacities(st
  
        put_unaligned_be32(curlun->num_sectors, &buf[0]);
                                                /* Number of blocks */
-       put_unaligned_be32(512, &buf[4]);       /* Block length */
+       put_unaligned_be32(curlun->blksize, &buf[4]);   /* Block length */
        buf[4] = 0x02;                          /* Current capacity */
        return 12;
  }
@@@ -1983,8 -1967,10 +1967,10 @@@ static int throw_away_data(struct fsg_d
                        amount = min(fsg->usb_amount_left,
                                        (u32) mod_data.buflen);
  
-                       /* amount is always divisible by 512, hence by
-                        * the bulk-out maxpacket size */
+                       /* Except at the end of the transfer, amount will be
+                        * equal to the buffer size, which is divisible by
+                        * the bulk-out maxpacket size.
+                        */
                        bh->outreq->length = bh->bulk_out_intended_length =
                                        amount;
                        bh->outreq->short_not_ok = 1;
@@@ -2415,7 -2401,7 +2401,7 @@@ static int do_scsi_command(struct fsg_d
  
        case READ_6:
                i = fsg->cmnd[4];
-               fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
+               fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << fsg->curlun->blkbits;
                if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
                                (7<<1) | (1<<4), 1,
                                "READ(6)")) == 0)
  
        case READ_10:
                fsg->data_size_from_cmnd =
-                               get_unaligned_be16(&fsg->cmnd[7]) << 9;
+                               get_unaligned_be16(&fsg->cmnd[7]) << fsg->curlun->blkbits;
                if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
                                (1<<1) | (0xf<<2) | (3<<7), 1,
                                "READ(10)")) == 0)
  
        case READ_12:
                fsg->data_size_from_cmnd =
-                               get_unaligned_be32(&fsg->cmnd[6]) << 9;
+                               get_unaligned_be32(&fsg->cmnd[6]) << fsg->curlun->blkbits;
                if ((reply = check_command(fsg, 12, DATA_DIR_TO_HOST,
                                (1<<1) | (0xf<<2) | (0xf<<6), 1,
                                "READ(12)")) == 0)
  
        case WRITE_6:
                i = fsg->cmnd[4];
-               fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
+               fsg->data_size_from_cmnd = (i == 0 ? 256 : i) << fsg->curlun->blkbits;
                if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
                                (7<<1) | (1<<4), 1,
                                "WRITE(6)")) == 0)
  
        case WRITE_10:
                fsg->data_size_from_cmnd =
-                               get_unaligned_be16(&fsg->cmnd[7]) << 9;
+                               get_unaligned_be16(&fsg->cmnd[7]) << fsg->curlun->blkbits;
                if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
                                (1<<1) | (0xf<<2) | (3<<7), 1,
                                "WRITE(10)")) == 0)
  
        case WRITE_12:
                fsg->data_size_from_cmnd =
-                               get_unaligned_be32(&fsg->cmnd[6]) << 9;
+                               get_unaligned_be32(&fsg->cmnd[6]) << fsg->curlun->blkbits;
                if ((reply = check_command(fsg, 12, DATA_DIR_FROM_HOST,
                                (1<<1) | (0xf<<2) | (0xf<<6), 1,
                                "WRITE(12)")) == 0)
@@@ -2752,7 -2738,7 +2738,7 @@@ static int do_set_interface(struct fsg_
  
  reset:
        /* Deallocate the requests */
-       for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
+       for (i = 0; i < fsg_num_buffers; ++i) {
                struct fsg_buffhd *bh = &fsg->buffhds[i];
  
                if (bh->inreq) {
        }
  
        /* Allocate the requests */
-       for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
+       for (i = 0; i < fsg_num_buffers; ++i) {
                struct fsg_buffhd       *bh = &fsg->buffhds[i];
  
                if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
@@@ -2862,10 -2848,17 +2848,10 @@@ static int do_set_config(struct fsg_de
                fsg->config = new_config;
                if ((rc = do_set_interface(fsg, 0)) != 0)
                        fsg->config = 0;        // Reset on errors
 -              else {
 -                      char *speed;
 -
 -                      switch (fsg->gadget->speed) {
 -                      case USB_SPEED_LOW:     speed = "low";  break;
 -                      case USB_SPEED_FULL:    speed = "full"; break;
 -                      case USB_SPEED_HIGH:    speed = "high"; break;
 -                      default:                speed = "?";    break;
 -                      }
 -                      INFO(fsg, "%s speed config #%d\n", speed, fsg->config);
 -              }
 +              else
 +                      INFO(fsg, "%s config #%d\n",
 +                           usb_speed_string(fsg->gadget->speed),
 +                           fsg->config);
        }
        return rc;
  }
@@@ -2902,7 -2895,7 +2888,7 @@@ static void handle_exception(struct fsg
        /* Cancel all the pending transfers */
        if (fsg->intreq_busy)
                usb_ep_dequeue(fsg->intr_in, fsg->intreq);
-       for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
+       for (i = 0; i < fsg_num_buffers; ++i) {
                bh = &fsg->buffhds[i];
                if (bh->inreq_busy)
                        usb_ep_dequeue(fsg->bulk_in, bh->inreq);
        /* Wait until everything is idle */
        for (;;) {
                num_active = fsg->intreq_busy;
-               for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
+               for (i = 0; i < fsg_num_buffers; ++i) {
                        bh = &fsg->buffhds[i];
                        num_active += bh->inreq_busy + bh->outreq_busy;
                }
         * state, and the exception.  Then invoke the handler. */
        spin_lock_irq(&fsg->lock);
  
-       for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
+       for (i = 0; i < fsg_num_buffers; ++i) {
                bh = &fsg->buffhds[i];
                bh->state = BUF_STATE_EMPTY;
        }
@@@ -3165,7 -3158,7 +3151,7 @@@ static void /* __init_or_exit */ fsg_un
        }
  
        /* Free the data buffers */
-       for (i = 0; i < FSG_NUM_BUFFERS; ++i)
+       for (i = 0; i < fsg_num_buffers; ++i)
                kfree(fsg->buffhds[i].buf);
  
        /* Free the request and buffer for endpoint 0 */
@@@ -3453,7 -3446,7 +3439,7 @@@ static int __init fsg_bind(struct usb_g
        req->complete = ep0_complete;
  
        /* Allocate the data buffers */
-       for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
+       for (i = 0; i < fsg_num_buffers; ++i) {
                struct fsg_buffhd       *bh = &fsg->buffhds[i];
  
                /* Allocate for the bulk-in endpoint.  We assume that
                        goto out;
                bh->next = bh + 1;
        }
-       fsg->buffhds[FSG_NUM_BUFFERS - 1].next = &fsg->buffhds[0];
+       fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  
        /* This should reflect the actual gadget power source */
        usb_gadget_set_selfpowered(gadget);
@@@ -3580,7 -3573,9 +3566,9 @@@ static int __init fsg_alloc(void
  {
        struct fsg_dev          *fsg;
  
-       fsg = kzalloc(sizeof *fsg, GFP_KERNEL);
+       fsg = kzalloc(sizeof *fsg +
+                     fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
        if (!fsg)
                return -ENOMEM;
        spin_lock_init(&fsg->lock);
@@@ -3598,6 -3593,10 +3586,10 @@@ static int __init fsg_init(void
        int             rc;
        struct fsg_dev  *fsg;
  
+       rc = fsg_num_buffers_validate();
+       if (rc != 0)
+               return rc;
        if ((rc = fsg_alloc()) != 0)
                return rc;
        fsg = the_fsg;
index 571d9730fca9e5a024e5f6b460bd521107b0f41a,9fd379998608d1f72c3b33c9a4f240cb9475e951..523626274c0f9bfc0f490eb6f575ece95677718c
@@@ -9,6 -9,15 +9,6 @@@
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
 - *
 - * This program is distributed in the hope that it will be useful,
 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 - * GNU General Public License for more details.
 - *
 - * You should have received a copy of the GNU General Public License
 - * along with this program; if not, write to the Free Software
 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  
   * characters rather then a pointer to void.
   */
  
+ /*
+  * When USB_GADGET_DEBUG_FILES is defined the module param num_buffers
+  * sets the number of pipeline buffers (length of the fsg_buffhd array).
+  * The valid range of num_buffers is: num >= 2 && num <= 4.
+  */
  
  #include <linux/usb/storage.h>
  #include <scsi/scsi.h>
@@@ -238,6 -253,8 +244,8 @@@ struct fsg_lun 
        u32             sense_data_info;
        u32             unit_attention_data;
  
+       unsigned int    blkbits;        /* Bits of logical block size of bound block device */
+       unsigned int    blksize;        /* logical block size of bound block device */
        struct device   dev;
  };
  
@@@ -253,8 -270,31 +261,31 @@@ static struct fsg_lun *fsg_lun_from_dev
  #define EP0_BUFSIZE   256
  #define DELAYED_STATUS        (EP0_BUFSIZE + 999)     /* An impossibly large value */
  
- /* Number of buffers we will use.  2 is enough for double-buffering */
- #define FSG_NUM_BUFFERS       2
+ #ifdef CONFIG_USB_GADGET_DEBUG_FILES
+ static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
+ module_param_named(num_buffers, fsg_num_buffers, uint, S_IRUGO);
+ MODULE_PARM_DESC(num_buffers, "Number of pipeline buffers");
+ #else
+ /*
+  * Number of buffers we will use.
+  * 2 is usually enough for good buffering pipeline
+  */
+ #define fsg_num_buffers       CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
+ #endif /* CONFIG_USB_DEBUG */
+ /* check if fsg_num_buffers is within a valid range */
+ static inline int fsg_num_buffers_validate(void)
+ {
+       if (fsg_num_buffers >= 2 && fsg_num_buffers <= 4)
+               return 0;
+       pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
+              fsg_num_buffers, 2 ,4);
+       return -EINVAL;
+ }
  
  /* Default size of buffer length. */
  #define FSG_BUFLEN    ((u32)16384)
@@@ -571,13 -611,24 +602,24 @@@ static int fsg_lun_open(struct fsg_lun 
                rc = (int) size;
                goto out;
        }
-       num_sectors = size >> 9;        /* File size in 512-byte blocks */
+       if (curlun->cdrom) {
+               curlun->blksize = 2048;
+               curlun->blkbits = 11;
+       } else if (inode->i_bdev) {
+               curlun->blksize = bdev_logical_block_size(inode->i_bdev);
+               curlun->blkbits = blksize_bits(curlun->blksize);
+       } else {
+               curlun->blksize = 512;
+               curlun->blkbits = 9;
+       }
+       num_sectors = size >> curlun->blkbits; /* File size in logic-block-size blocks */
        min_sectors = 1;
        if (curlun->cdrom) {
-               num_sectors &= ~3;      /* Reduce to a multiple of 2048 */
-               min_sectors = 300*4;    /* Smallest track is 300 frames */
-               if (num_sectors >= 256*60*75*4) {
-                       num_sectors = (256*60*75 - 1) * 4;
+               min_sectors = 300;      /* Smallest track is 300 frames */
+               if (num_sectors >= 256*60*75) {
+                       num_sectors = 256*60*75 - 1;
                        LINFO(curlun, "file too big: %s\n", filename);
                        LINFO(curlun, "using only first %d blocks\n",
                                        (int) num_sectors);
index 3f79e7f9a9eef9bc561ac32e2df68b188dc86d61,82434dde6e99b6c7546313ac66135df50d83d234..b08b9cad85a2018faf4bf48f51cfa380af3e47ed
@@@ -634,6 -634,7 +634,7 @@@ static void rxstate(struct musb *musb, 
        u16                     len;
        u16                     csr = musb_readw(epio, MUSB_RXCSR);
        struct musb_hw_ep       *hw_ep = &musb->endpoints[epnum];
+       u8                      use_mode_1;
  
        if (hw_ep->is_shared_fifo)
                musb_ep = &hw_ep->ep_in;
  
        if (csr & MUSB_RXCSR_RXPKTRDY) {
                len = musb_readw(epio, MUSB_RXCOUNT);
+               /*
+                * Enable Mode 1 on RX transfers only when short_not_ok flag
+                * is set. Currently short_not_ok flag is set only from
+                * file_storage and f_mass_storage drivers
+                */
+               if (request->short_not_ok && len == musb_ep->packet_sz)
+                       use_mode_1 = 1;
+               else
+                       use_mode_1 = 0;
                if (request->actual < request->length) {
  #ifdef CONFIG_USB_INVENTRA_DMA
                        if (is_buffer_mapped(req)) {
         * then becomes usable as a runtime "use mode 1" hint...
         */
  
-                               csr |= MUSB_RXCSR_DMAENAB;
- #ifdef USE_MODE1
-                               csr |= MUSB_RXCSR_AUTOCLEAR;
-                               /* csr |= MUSB_RXCSR_DMAMODE; */
-                               /* this special sequence (enabling and then
-                                * disabling MUSB_RXCSR_DMAMODE) is required
-                                * to get DMAReq to activate
-                                */
-                               musb_writew(epio, MUSB_RXCSR,
-                                       csr | MUSB_RXCSR_DMAMODE);
- #else
-                               if (!musb_ep->hb_mult &&
-                                       musb_ep->hw_ep->rx_double_buffered)
+                               /* Experimental: Mode1 works with mass storage use cases */
+                               if (use_mode_1) {
                                        csr |= MUSB_RXCSR_AUTOCLEAR;
- #endif
-                               musb_writew(epio, MUSB_RXCSR, csr);
+                                       musb_writew(epio, MUSB_RXCSR, csr);
+                                       csr |= MUSB_RXCSR_DMAENAB;
+                                       musb_writew(epio, MUSB_RXCSR, csr);
+                                       /*
+                                        * this special sequence (enabling and then
+                                        * disabling MUSB_RXCSR_DMAMODE) is required
+                                        * to get DMAReq to activate
+                                        */
+                                       musb_writew(epio, MUSB_RXCSR,
+                                               csr | MUSB_RXCSR_DMAMODE);
+                                       musb_writew(epio, MUSB_RXCSR, csr);
+                               } else {
+                                       if (!musb_ep->hb_mult &&
+                                               musb_ep->hw_ep->rx_double_buffered)
+                                               csr |= MUSB_RXCSR_AUTOCLEAR;
+                                       csr |= MUSB_RXCSR_DMAENAB;
+                                       musb_writew(epio, MUSB_RXCSR, csr);
+                               }
  
                                if (request->actual < request->length) {
                                        int transfer_size = 0;
- #ifdef USE_MODE1
-                                       transfer_size = min(request->length - request->actual,
-                                                       channel->max_len);
- #else
-                                       transfer_size = min(request->length - request->actual,
-                                                       (unsigned)len);
- #endif
-                                       if (transfer_size <= musb_ep->packet_sz)
-                                               musb_ep->dma->desired_mode = 0;
-                                       else
+                                       if (use_mode_1) {
+                                               transfer_size = min(request->length - request->actual,
+                                                               channel->max_len);
                                                musb_ep->dma->desired_mode = 1;
+                                       } else {
+                                               transfer_size = min(request->length - request->actual,
+                                                               (unsigned)len);
+                                               musb_ep->dma->desired_mode = 0;
+                                       }
  
                                        use_dma = c->channel_program(
                                                        channel,
@@@ -1856,7 -1873,6 +1873,7 @@@ int __init musb_gadget_setup(struct mus
  
        return 0;
  err:
 +      musb->g.dev.parent = NULL;
        device_unregister(&musb->g.dev);
        return status;
  }
  void musb_gadget_cleanup(struct musb *musb)
  {
        usb_del_gadget_udc(&musb->g);
 -      device_unregister(&musb->g.dev);
 +      if (musb->g.dev.parent)
 +              device_unregister(&musb->g.dev);
  }
  
  /*