diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2011-03-25 11:46:27 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-04-13 19:24:06 -0400 |
commit | ee81b3e086c907a3347b15ef219a24fc8bf900f6 (patch) | |
tree | 6ab1d90bc0ab2282c86dc332e97edf8df60559c9 /drivers/usb/gadget | |
parent | edf847decc4159128041d2a81f8d93e6eb567ecb (diff) |
USB: g_file_storage: don't send padding when stall=n
This patch (as1455) removes the extra padding sent by g_file_storage
and g_mass_storage when the gadget wants to send less data than
requested by the host and isn't allowed to halt the bulk-IN endpoint.
Although the Bulk-Only Transport specification requires the padding to
be present, it isn't truly needed since the transfer will be terminated
by a short packet anyway. Furthermore, many existing devices don't
bother to send any padding.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Acked-By: Michal Nazarewicz <mina86@mina86.com>
CC: Roger Quadros <roger.quadros@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/f_mass_storage.c | 54 | ||||
-rw-r--r-- | drivers/usb/gadget/file_storage.c | 53 |
2 files changed, 23 insertions, 84 deletions
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 125587ac5d0b..98d6b39061d2 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c | |||
@@ -1569,37 +1569,6 @@ static int wedge_bulk_in_endpoint(struct fsg_dev *fsg) | |||
1569 | return rc; | 1569 | return rc; |
1570 | } | 1570 | } |
1571 | 1571 | ||
1572 | static int pad_with_zeros(struct fsg_dev *fsg) | ||
1573 | { | ||
1574 | struct fsg_buffhd *bh = fsg->common->next_buffhd_to_fill; | ||
1575 | u32 nkeep = bh->inreq->length; | ||
1576 | u32 nsend; | ||
1577 | int rc; | ||
1578 | |||
1579 | bh->state = BUF_STATE_EMPTY; /* For the first iteration */ | ||
1580 | fsg->common->usb_amount_left = nkeep + fsg->common->residue; | ||
1581 | while (fsg->common->usb_amount_left > 0) { | ||
1582 | |||
1583 | /* Wait for the next buffer to be free */ | ||
1584 | while (bh->state != BUF_STATE_EMPTY) { | ||
1585 | rc = sleep_thread(fsg->common); | ||
1586 | if (rc) | ||
1587 | return rc; | ||
1588 | } | ||
1589 | |||
1590 | nsend = min(fsg->common->usb_amount_left, FSG_BUFLEN); | ||
1591 | memset(bh->buf + nkeep, 0, nsend - nkeep); | ||
1592 | bh->inreq->length = nsend; | ||
1593 | bh->inreq->zero = 0; | ||
1594 | start_transfer(fsg, fsg->bulk_in, bh->inreq, | ||
1595 | &bh->inreq_busy, &bh->state); | ||
1596 | bh = fsg->common->next_buffhd_to_fill = bh->next; | ||
1597 | fsg->common->usb_amount_left -= nsend; | ||
1598 | nkeep = 0; | ||
1599 | } | ||
1600 | return 0; | ||
1601 | } | ||
1602 | |||
1603 | static int throw_away_data(struct fsg_common *common) | 1572 | static int throw_away_data(struct fsg_common *common) |
1604 | { | 1573 | { |
1605 | struct fsg_buffhd *bh; | 1574 | struct fsg_buffhd *bh; |
@@ -1686,6 +1655,10 @@ static int finish_reply(struct fsg_common *common) | |||
1686 | if (common->data_size == 0) { | 1655 | if (common->data_size == 0) { |
1687 | /* Nothing to send */ | 1656 | /* Nothing to send */ |
1688 | 1657 | ||
1658 | /* Don't know what to do if common->fsg is NULL */ | ||
1659 | } else if (!fsg_is_set(common)) { | ||
1660 | rc = -EIO; | ||
1661 | |||
1689 | /* If there's no residue, simply send the last buffer */ | 1662 | /* If there's no residue, simply send the last buffer */ |
1690 | } else if (common->residue == 0) { | 1663 | } else if (common->residue == 0) { |
1691 | bh->inreq->zero = 0; | 1664 | bh->inreq->zero = 0; |
@@ -1694,24 +1667,19 @@ static int finish_reply(struct fsg_common *common) | |||
1694 | common->next_buffhd_to_fill = bh->next; | 1667 | common->next_buffhd_to_fill = bh->next; |
1695 | 1668 | ||
1696 | /* | 1669 | /* |
1697 | * For Bulk-only, if we're allowed to stall then send the | 1670 | * For Bulk-only, mark the end of the data with a short |
1698 | * short packet and halt the bulk-in endpoint. If we can't | 1671 | * packet. If we are allowed to stall, halt the bulk-in |
1699 | * stall, pad out the remaining data with 0's. | 1672 | * endpoint. (Note: This violates the Bulk-Only Transport |
1673 | * specification, which requires us to pad the data if we | ||
1674 | * don't halt the endpoint. Presumably nobody will mind.) | ||
1700 | */ | 1675 | */ |
1701 | } else if (common->can_stall) { | 1676 | } else { |
1702 | bh->inreq->zero = 1; | 1677 | bh->inreq->zero = 1; |
1703 | if (!start_in_transfer(common, bh)) | 1678 | if (!start_in_transfer(common, bh)) |
1704 | /* Don't know what to do if | ||
1705 | * common->fsg is NULL */ | ||
1706 | rc = -EIO; | 1679 | rc = -EIO; |
1707 | common->next_buffhd_to_fill = bh->next; | 1680 | common->next_buffhd_to_fill = bh->next; |
1708 | if (common->fsg) | 1681 | if (common->can_stall) |
1709 | rc = halt_bulk_in_endpoint(common->fsg); | 1682 | rc = halt_bulk_in_endpoint(common->fsg); |
1710 | } else if (fsg_is_set(common)) { | ||
1711 | rc = pad_with_zeros(common->fsg); | ||
1712 | } else { | ||
1713 | /* Don't know what to do if common->fsg is NULL */ | ||
1714 | rc = -EIO; | ||
1715 | } | 1683 | } |
1716 | break; | 1684 | break; |
1717 | 1685 | ||
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c index d04e0e6b019d..aebfb81f3ba4 100644 --- a/drivers/usb/gadget/file_storage.c +++ b/drivers/usb/gadget/file_storage.c | |||
@@ -1932,37 +1932,6 @@ static int wedge_bulk_in_endpoint(struct fsg_dev *fsg) | |||
1932 | return rc; | 1932 | return rc; |
1933 | } | 1933 | } |
1934 | 1934 | ||
1935 | static int pad_with_zeros(struct fsg_dev *fsg) | ||
1936 | { | ||
1937 | struct fsg_buffhd *bh = fsg->next_buffhd_to_fill; | ||
1938 | u32 nkeep = bh->inreq->length; | ||
1939 | u32 nsend; | ||
1940 | int rc; | ||
1941 | |||
1942 | bh->state = BUF_STATE_EMPTY; // For the first iteration | ||
1943 | fsg->usb_amount_left = nkeep + fsg->residue; | ||
1944 | while (fsg->usb_amount_left > 0) { | ||
1945 | |||
1946 | /* Wait for the next buffer to be free */ | ||
1947 | while (bh->state != BUF_STATE_EMPTY) { | ||
1948 | rc = sleep_thread(fsg); | ||
1949 | if (rc) | ||
1950 | return rc; | ||
1951 | } | ||
1952 | |||
1953 | nsend = min(fsg->usb_amount_left, (u32) mod_data.buflen); | ||
1954 | memset(bh->buf + nkeep, 0, nsend - nkeep); | ||
1955 | bh->inreq->length = nsend; | ||
1956 | bh->inreq->zero = 0; | ||
1957 | start_transfer(fsg, fsg->bulk_in, bh->inreq, | ||
1958 | &bh->inreq_busy, &bh->state); | ||
1959 | bh = fsg->next_buffhd_to_fill = bh->next; | ||
1960 | fsg->usb_amount_left -= nsend; | ||
1961 | nkeep = 0; | ||
1962 | } | ||
1963 | return 0; | ||
1964 | } | ||
1965 | |||
1966 | static int throw_away_data(struct fsg_dev *fsg) | 1935 | static int throw_away_data(struct fsg_dev *fsg) |
1967 | { | 1936 | { |
1968 | struct fsg_buffhd *bh; | 1937 | struct fsg_buffhd *bh; |
@@ -2066,18 +2035,20 @@ static int finish_reply(struct fsg_dev *fsg) | |||
2066 | } | 2035 | } |
2067 | } | 2036 | } |
2068 | 2037 | ||
2069 | /* For Bulk-only, if we're allowed to stall then send the | 2038 | /* |
2070 | * short packet and halt the bulk-in endpoint. If we can't | 2039 | * For Bulk-only, mark the end of the data with a short |
2071 | * stall, pad out the remaining data with 0's. */ | 2040 | * packet. If we are allowed to stall, halt the bulk-in |
2041 | * endpoint. (Note: This violates the Bulk-Only Transport | ||
2042 | * specification, which requires us to pad the data if we | ||
2043 | * don't halt the endpoint. Presumably nobody will mind.) | ||
2044 | */ | ||
2072 | else { | 2045 | else { |
2073 | if (mod_data.can_stall) { | 2046 | bh->inreq->zero = 1; |
2074 | bh->inreq->zero = 1; | 2047 | start_transfer(fsg, fsg->bulk_in, bh->inreq, |
2075 | start_transfer(fsg, fsg->bulk_in, bh->inreq, | 2048 | &bh->inreq_busy, &bh->state); |
2076 | &bh->inreq_busy, &bh->state); | 2049 | fsg->next_buffhd_to_fill = bh->next; |
2077 | fsg->next_buffhd_to_fill = bh->next; | 2050 | if (mod_data.can_stall) |
2078 | rc = halt_bulk_in_endpoint(fsg); | 2051 | rc = halt_bulk_in_endpoint(fsg); |
2079 | } else | ||
2080 | rc = pad_with_zeros(fsg); | ||
2081 | } | 2052 | } |
2082 | break; | 2053 | break; |
2083 | 2054 | ||