aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/ether.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/ether.c')
-rw-r--r--drivers/usb/gadget/ether.c63
1 files changed, 41 insertions, 22 deletions
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 078daa026718..366dc0a9e52c 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -23,7 +23,6 @@
23// #define DEBUG 1 23// #define DEBUG 1
24// #define VERBOSE 24// #define VERBOSE
25 25
26#include <linux/config.h>
27#include <linux/module.h> 26#include <linux/module.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/delay.h> 28#include <linux/delay.h>
@@ -118,6 +117,8 @@ struct eth_dev {
118 struct usb_ep *in_ep, *out_ep, *status_ep; 117 struct usb_ep *in_ep, *out_ep, *status_ep;
119 const struct usb_endpoint_descriptor 118 const struct usb_endpoint_descriptor
120 *in, *out, *status; 119 *in, *out, *status;
120
121 spinlock_t req_lock;
121 struct list_head tx_reqs, rx_reqs; 122 struct list_head tx_reqs, rx_reqs;
122 123
123 struct net_device *net; 124 struct net_device *net;
@@ -261,7 +262,7 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
261#define DEV_CONFIG_CDC 262#define DEV_CONFIG_CDC
262#endif 263#endif
263 264
264#ifdef CONFIG_USB_GADGET_MUSBHDRC 265#ifdef CONFIG_USB_GADGET_MUSB_HDRC
265#define DEV_CONFIG_CDC 266#define DEV_CONFIG_CDC
266#endif 267#endif
267 268
@@ -1067,21 +1068,31 @@ static void eth_reset_config (struct eth_dev *dev)
1067 */ 1068 */
1068 if (dev->in) { 1069 if (dev->in) {
1069 usb_ep_disable (dev->in_ep); 1070 usb_ep_disable (dev->in_ep);
1071 spin_lock(&dev->req_lock);
1070 while (likely (!list_empty (&dev->tx_reqs))) { 1072 while (likely (!list_empty (&dev->tx_reqs))) {
1071 req = container_of (dev->tx_reqs.next, 1073 req = container_of (dev->tx_reqs.next,
1072 struct usb_request, list); 1074 struct usb_request, list);
1073 list_del (&req->list); 1075 list_del (&req->list);
1076
1077 spin_unlock(&dev->req_lock);
1074 usb_ep_free_request (dev->in_ep, req); 1078 usb_ep_free_request (dev->in_ep, req);
1079 spin_lock(&dev->req_lock);
1075 } 1080 }
1081 spin_unlock(&dev->req_lock);
1076 } 1082 }
1077 if (dev->out) { 1083 if (dev->out) {
1078 usb_ep_disable (dev->out_ep); 1084 usb_ep_disable (dev->out_ep);
1085 spin_lock(&dev->req_lock);
1079 while (likely (!list_empty (&dev->rx_reqs))) { 1086 while (likely (!list_empty (&dev->rx_reqs))) {
1080 req = container_of (dev->rx_reqs.next, 1087 req = container_of (dev->rx_reqs.next,
1081 struct usb_request, list); 1088 struct usb_request, list);
1082 list_del (&req->list); 1089 list_del (&req->list);
1090
1091 spin_unlock(&dev->req_lock);
1083 usb_ep_free_request (dev->out_ep, req); 1092 usb_ep_free_request (dev->out_ep, req);
1093 spin_lock(&dev->req_lock);
1084 } 1094 }
1095 spin_unlock(&dev->req_lock);
1085 } 1096 }
1086 1097
1087 if (dev->status) { 1098 if (dev->status) {
@@ -1660,9 +1671,9 @@ enomem:
1660 if (retval) { 1671 if (retval) {
1661 DEBUG (dev, "rx submit --> %d\n", retval); 1672 DEBUG (dev, "rx submit --> %d\n", retval);
1662 dev_kfree_skb_any (skb); 1673 dev_kfree_skb_any (skb);
1663 spin_lock (&dev->lock); 1674 spin_lock(&dev->req_lock);
1664 list_add (&req->list, &dev->rx_reqs); 1675 list_add (&req->list, &dev->rx_reqs);
1665 spin_unlock (&dev->lock); 1676 spin_unlock(&dev->req_lock);
1666 } 1677 }
1667 return retval; 1678 return retval;
1668} 1679}
@@ -1731,8 +1742,9 @@ quiesce:
1731 dev_kfree_skb_any (skb); 1742 dev_kfree_skb_any (skb);
1732 if (!netif_running (dev->net)) { 1743 if (!netif_running (dev->net)) {
1733clean: 1744clean:
1734 /* nobody reading rx_reqs, so no dev->lock */ 1745 spin_lock(&dev->req_lock);
1735 list_add (&req->list, &dev->rx_reqs); 1746 list_add (&req->list, &dev->rx_reqs);
1747 spin_unlock(&dev->req_lock);
1736 req = NULL; 1748 req = NULL;
1737 } 1749 }
1738 if (req) 1750 if (req)
@@ -1783,15 +1795,18 @@ static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags)
1783{ 1795{
1784 int status; 1796 int status;
1785 1797
1798 spin_lock(&dev->req_lock);
1786 status = prealloc (&dev->tx_reqs, dev->in_ep, n, gfp_flags); 1799 status = prealloc (&dev->tx_reqs, dev->in_ep, n, gfp_flags);
1787 if (status < 0) 1800 if (status < 0)
1788 goto fail; 1801 goto fail;
1789 status = prealloc (&dev->rx_reqs, dev->out_ep, n, gfp_flags); 1802 status = prealloc (&dev->rx_reqs, dev->out_ep, n, gfp_flags);
1790 if (status < 0) 1803 if (status < 0)
1791 goto fail; 1804 goto fail;
1792 return 0; 1805 goto done;
1793fail: 1806fail:
1794 DEBUG (dev, "can't alloc requests\n"); 1807 DEBUG (dev, "can't alloc requests\n");
1808done:
1809 spin_unlock(&dev->req_lock);
1795 return status; 1810 return status;
1796} 1811}
1797 1812
@@ -1801,21 +1816,21 @@ static void rx_fill (struct eth_dev *dev, gfp_t gfp_flags)
1801 unsigned long flags; 1816 unsigned long flags;
1802 1817
1803 /* fill unused rxq slots with some skb */ 1818 /* fill unused rxq slots with some skb */
1804 spin_lock_irqsave (&dev->lock, flags); 1819 spin_lock_irqsave(&dev->req_lock, flags);
1805 while (!list_empty (&dev->rx_reqs)) { 1820 while (!list_empty (&dev->rx_reqs)) {
1806 req = container_of (dev->rx_reqs.next, 1821 req = container_of (dev->rx_reqs.next,
1807 struct usb_request, list); 1822 struct usb_request, list);
1808 list_del_init (&req->list); 1823 list_del_init (&req->list);
1809 spin_unlock_irqrestore (&dev->lock, flags); 1824 spin_unlock_irqrestore(&dev->req_lock, flags);
1810 1825
1811 if (rx_submit (dev, req, gfp_flags) < 0) { 1826 if (rx_submit (dev, req, gfp_flags) < 0) {
1812 defer_kevent (dev, WORK_RX_MEMORY); 1827 defer_kevent (dev, WORK_RX_MEMORY);
1813 return; 1828 return;
1814 } 1829 }
1815 1830
1816 spin_lock_irqsave (&dev->lock, flags); 1831 spin_lock_irqsave(&dev->req_lock, flags);
1817 } 1832 }
1818 spin_unlock_irqrestore (&dev->lock, flags); 1833 spin_unlock_irqrestore(&dev->req_lock, flags);
1819} 1834}
1820 1835
1821static void eth_work (void *_dev) 1836static void eth_work (void *_dev)
@@ -1849,9 +1864,9 @@ static void tx_complete (struct usb_ep *ep, struct usb_request *req)
1849 } 1864 }
1850 dev->stats.tx_packets++; 1865 dev->stats.tx_packets++;
1851 1866
1852 spin_lock (&dev->lock); 1867 spin_lock(&dev->req_lock);
1853 list_add (&req->list, &dev->tx_reqs); 1868 list_add (&req->list, &dev->tx_reqs);
1854 spin_unlock (&dev->lock); 1869 spin_unlock(&dev->req_lock);
1855 dev_kfree_skb_any (skb); 1870 dev_kfree_skb_any (skb);
1856 1871
1857 atomic_dec (&dev->tx_qlen); 1872 atomic_dec (&dev->tx_qlen);
@@ -1897,12 +1912,12 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1897 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */ 1912 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */
1898 } 1913 }
1899 1914
1900 spin_lock_irqsave (&dev->lock, flags); 1915 spin_lock_irqsave(&dev->req_lock, flags);
1901 req = container_of (dev->tx_reqs.next, struct usb_request, list); 1916 req = container_of (dev->tx_reqs.next, struct usb_request, list);
1902 list_del (&req->list); 1917 list_del (&req->list);
1903 if (list_empty (&dev->tx_reqs)) 1918 if (list_empty (&dev->tx_reqs))
1904 netif_stop_queue (net); 1919 netif_stop_queue (net);
1905 spin_unlock_irqrestore (&dev->lock, flags); 1920 spin_unlock_irqrestore(&dev->req_lock, flags);
1906 1921
1907 /* no buffer copies needed, unless the network stack did it 1922 /* no buffer copies needed, unless the network stack did it
1908 * or the hardware can't use skb buffers. 1923 * or the hardware can't use skb buffers.
@@ -1956,11 +1971,11 @@ static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
1956drop: 1971drop:
1957 dev->stats.tx_dropped++; 1972 dev->stats.tx_dropped++;
1958 dev_kfree_skb_any (skb); 1973 dev_kfree_skb_any (skb);
1959 spin_lock_irqsave (&dev->lock, flags); 1974 spin_lock_irqsave(&dev->req_lock, flags);
1960 if (list_empty (&dev->tx_reqs)) 1975 if (list_empty (&dev->tx_reqs))
1961 netif_start_queue (net); 1976 netif_start_queue (net);
1962 list_add (&req->list, &dev->tx_reqs); 1977 list_add (&req->list, &dev->tx_reqs);
1963 spin_unlock_irqrestore (&dev->lock, flags); 1978 spin_unlock_irqrestore(&dev->req_lock, flags);
1964 } 1979 }
1965 return 0; 1980 return 0;
1966} 1981}
@@ -1999,7 +2014,7 @@ rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req)
1999static int rndis_control_ack (struct net_device *net) 2014static int rndis_control_ack (struct net_device *net)
2000{ 2015{
2001 struct eth_dev *dev = netdev_priv(net); 2016 struct eth_dev *dev = netdev_priv(net);
2002 u32 length; 2017 int length;
2003 struct usb_request *resp = dev->stat_req; 2018 struct usb_request *resp = dev->stat_req;
2004 2019
2005 /* in case RNDIS calls this after disconnect */ 2020 /* in case RNDIS calls this after disconnect */
@@ -2132,7 +2147,7 @@ eth_req_free (struct usb_ep *ep, struct usb_request *req)
2132} 2147}
2133 2148
2134 2149
2135static void __exit 2150static void /* __init_or_exit */
2136eth_unbind (struct usb_gadget *gadget) 2151eth_unbind (struct usb_gadget *gadget)
2137{ 2152{
2138 struct eth_dev *dev = get_gadget_data (gadget); 2153 struct eth_dev *dev = get_gadget_data (gadget);
@@ -2159,7 +2174,7 @@ eth_unbind (struct usb_gadget *gadget)
2159 set_gadget_data (gadget, NULL); 2174 set_gadget_data (gadget, NULL);
2160} 2175}
2161 2176
2162static u8 __init nibble (unsigned char c) 2177static u8 __devinit nibble (unsigned char c)
2163{ 2178{
2164 if (likely (isdigit (c))) 2179 if (likely (isdigit (c)))
2165 return c - '0'; 2180 return c - '0';
@@ -2169,7 +2184,7 @@ static u8 __init nibble (unsigned char c)
2169 return 0; 2184 return 0;
2170} 2185}
2171 2186
2172static int __init get_ether_addr(const char *str, u8 *dev_addr) 2187static int __devinit get_ether_addr(const char *str, u8 *dev_addr)
2173{ 2188{
2174 if (str) { 2189 if (str) {
2175 unsigned i; 2190 unsigned i;
@@ -2190,7 +2205,7 @@ static int __init get_ether_addr(const char *str, u8 *dev_addr)
2190 return 1; 2205 return 1;
2191} 2206}
2192 2207
2193static int __init 2208static int __devinit
2194eth_bind (struct usb_gadget *gadget) 2209eth_bind (struct usb_gadget *gadget)
2195{ 2210{
2196 struct eth_dev *dev; 2211 struct eth_dev *dev;
@@ -2215,6 +2230,9 @@ eth_bind (struct usb_gadget *gadget)
2215 if (gadget_is_pxa (gadget)) { 2230 if (gadget_is_pxa (gadget)) {
2216 /* pxa doesn't support altsettings */ 2231 /* pxa doesn't support altsettings */
2217 cdc = 0; 2232 cdc = 0;
2233 } else if (gadget_is_musbhdrc(gadget)) {
2234 /* reduce tx dma overhead by avoiding special cases */
2235 zlp = 0;
2218 } else if (gadget_is_sh(gadget)) { 2236 } else if (gadget_is_sh(gadget)) {
2219 /* sh doesn't support multiple interfaces or configs */ 2237 /* sh doesn't support multiple interfaces or configs */
2220 cdc = 0; 2238 cdc = 0;
@@ -2379,6 +2397,7 @@ autoconf_fail:
2379 return status; 2397 return status;
2380 dev = netdev_priv(net); 2398 dev = netdev_priv(net);
2381 spin_lock_init (&dev->lock); 2399 spin_lock_init (&dev->lock);
2400 spin_lock_init (&dev->req_lock);
2382 INIT_WORK (&dev->work, eth_work, dev); 2401 INIT_WORK (&dev->work, eth_work, dev);
2383 INIT_LIST_HEAD (&dev->tx_reqs); 2402 INIT_LIST_HEAD (&dev->tx_reqs);
2384 INIT_LIST_HEAD (&dev->rx_reqs); 2403 INIT_LIST_HEAD (&dev->rx_reqs);
@@ -2548,7 +2567,7 @@ static struct usb_gadget_driver eth_driver = {
2548 2567
2549 .function = (char *) driver_desc, 2568 .function = (char *) driver_desc,
2550 .bind = eth_bind, 2569 .bind = eth_bind,
2551 .unbind = __exit_p(eth_unbind), 2570 .unbind = eth_unbind,
2552 2571
2553 .setup = eth_setup, 2572 .setup = eth_setup,
2554 .disconnect = eth_disconnect, 2573 .disconnect = eth_disconnect,