diff options
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/f_phonet.c | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c index f4eff7ca0d36..d2de10b9dc4b 100644 --- a/drivers/usb/gadget/f_phonet.c +++ b/drivers/usb/gadget/f_phonet.c | |||
@@ -35,6 +35,10 @@ | |||
35 | #include "u_phonet.h" | 35 | #include "u_phonet.h" |
36 | 36 | ||
37 | #define PN_MEDIA_USB 0x1B | 37 | #define PN_MEDIA_USB 0x1B |
38 | #define MAXPACKET 512 | ||
39 | #if (PAGE_SIZE % MAXPACKET) | ||
40 | #error MAXPACKET must divide PAGE_SIZE! | ||
41 | #endif | ||
38 | 42 | ||
39 | /*-------------------------------------------------------------------------*/ | 43 | /*-------------------------------------------------------------------------*/ |
40 | 44 | ||
@@ -45,6 +49,10 @@ struct phonet_port { | |||
45 | 49 | ||
46 | struct f_phonet { | 50 | struct f_phonet { |
47 | struct usb_function function; | 51 | struct usb_function function; |
52 | struct { | ||
53 | struct sk_buff *skb; | ||
54 | spinlock_t lock; | ||
55 | } rx; | ||
48 | struct net_device *dev; | 56 | struct net_device *dev; |
49 | struct usb_ep *in_ep, *out_ep; | 57 | struct usb_ep *in_ep, *out_ep; |
50 | 58 | ||
@@ -52,7 +60,7 @@ struct f_phonet { | |||
52 | struct usb_request *out_reqv[0]; | 60 | struct usb_request *out_reqv[0]; |
53 | }; | 61 | }; |
54 | 62 | ||
55 | static int phonet_rxq_size = 2; | 63 | static int phonet_rxq_size = 17; |
56 | 64 | ||
57 | static inline struct f_phonet *func_to_pn(struct usb_function *f) | 65 | static inline struct f_phonet *func_to_pn(struct usb_function *f) |
58 | { | 66 | { |
@@ -138,7 +146,7 @@ pn_hs_sink_desc = { | |||
138 | 146 | ||
139 | .bEndpointAddress = USB_DIR_OUT, | 147 | .bEndpointAddress = USB_DIR_OUT, |
140 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | 148 | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
141 | .wMaxPacketSize = cpu_to_le16(512), | 149 | .wMaxPacketSize = cpu_to_le16(MAXPACKET), |
142 | }; | 150 | }; |
143 | 151 | ||
144 | static struct usb_endpoint_descriptor | 152 | static struct usb_endpoint_descriptor |
@@ -298,21 +306,21 @@ static void pn_net_setup(struct net_device *dev) | |||
298 | static int | 306 | static int |
299 | pn_rx_submit(struct f_phonet *fp, struct usb_request *req, gfp_t gfp_flags) | 307 | pn_rx_submit(struct f_phonet *fp, struct usb_request *req, gfp_t gfp_flags) |
300 | { | 308 | { |
301 | struct sk_buff *skb; | 309 | struct net_device *dev = fp->dev; |
302 | const size_t size = fp->dev->mtu; | 310 | struct page *page; |
303 | int err; | 311 | int err; |
304 | 312 | ||
305 | skb = alloc_skb(size, gfp_flags); | 313 | page = __netdev_alloc_page(dev, gfp_flags); |
306 | if (!skb) | 314 | if (!page) |
307 | return -ENOMEM; | 315 | return -ENOMEM; |
308 | 316 | ||
309 | req->buf = skb->data; | 317 | req->buf = page_address(page); |
310 | req->length = size; | 318 | req->length = PAGE_SIZE; |
311 | req->context = skb; | 319 | req->context = page; |
312 | 320 | ||
313 | err = usb_ep_queue(fp->out_ep, req, gfp_flags); | 321 | err = usb_ep_queue(fp->out_ep, req, gfp_flags); |
314 | if (unlikely(err)) | 322 | if (unlikely(err)) |
315 | dev_kfree_skb_any(skb); | 323 | netdev_free_page(dev, page); |
316 | return err; | 324 | return err; |
317 | } | 325 | } |
318 | 326 | ||
@@ -320,25 +328,37 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req) | |||
320 | { | 328 | { |
321 | struct f_phonet *fp = ep->driver_data; | 329 | struct f_phonet *fp = ep->driver_data; |
322 | struct net_device *dev = fp->dev; | 330 | struct net_device *dev = fp->dev; |
323 | struct sk_buff *skb = req->context; | 331 | struct page *page = req->context; |
332 | struct sk_buff *skb; | ||
333 | unsigned long flags; | ||
324 | int status = req->status; | 334 | int status = req->status; |
325 | 335 | ||
326 | switch (status) { | 336 | switch (status) { |
327 | case 0: | 337 | case 0: |
328 | if (unlikely(!netif_running(dev))) | 338 | spin_lock_irqsave(&fp->rx.lock, flags); |
329 | break; | 339 | skb = fp->rx.skb; |
330 | if (unlikely(req->actual < 1)) | 340 | if (!skb) |
341 | skb = fp->rx.skb = netdev_alloc_skb(dev, 12); | ||
342 | if (req->actual < req->length) /* Last fragment */ | ||
343 | fp->rx.skb = NULL; | ||
344 | spin_unlock_irqrestore(&fp->rx.lock, flags); | ||
345 | |||
346 | if (unlikely(!skb)) | ||
331 | break; | 347 | break; |
332 | skb_put(skb, req->actual); | 348 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, 0, |
333 | skb->protocol = htons(ETH_P_PHONET); | 349 | req->actual); |
334 | skb_reset_mac_header(skb); | 350 | page = NULL; |
335 | __skb_pull(skb, 1); | 351 | |
336 | skb->dev = dev; | 352 | if (req->actual < req->length) { /* Last fragment */ |
337 | dev->stats.rx_packets++; | 353 | skb->protocol = htons(ETH_P_PHONET); |
338 | dev->stats.rx_bytes += skb->len; | 354 | skb_reset_mac_header(skb); |
339 | 355 | pskb_pull(skb, 1); | |
340 | netif_rx(skb); | 356 | skb->dev = dev; |
341 | skb = NULL; | 357 | dev->stats.rx_packets++; |
358 | dev->stats.rx_bytes += skb->len; | ||
359 | |||
360 | netif_rx(skb); | ||
361 | } | ||
342 | break; | 362 | break; |
343 | 363 | ||
344 | /* Do not resubmit in these cases: */ | 364 | /* Do not resubmit in these cases: */ |
@@ -356,8 +376,8 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req) | |||
356 | break; | 376 | break; |
357 | } | 377 | } |
358 | 378 | ||
359 | if (skb) | 379 | if (page) |
360 | dev_kfree_skb_any(skb); | 380 | netdev_free_page(dev, page); |
361 | if (req) | 381 | if (req) |
362 | pn_rx_submit(fp, req, GFP_ATOMIC); | 382 | pn_rx_submit(fp, req, GFP_ATOMIC); |
363 | } | 383 | } |
@@ -375,6 +395,10 @@ static void __pn_reset(struct usb_function *f) | |||
375 | 395 | ||
376 | usb_ep_disable(fp->out_ep); | 396 | usb_ep_disable(fp->out_ep); |
377 | usb_ep_disable(fp->in_ep); | 397 | usb_ep_disable(fp->in_ep); |
398 | if (fp->rx.skb) { | ||
399 | dev_kfree_skb_irq(fp->rx.skb); | ||
400 | fp->rx.skb = NULL; | ||
401 | } | ||
378 | } | 402 | } |
379 | 403 | ||
380 | static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt) | 404 | static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt) |
@@ -573,6 +597,7 @@ int __init phonet_bind_config(struct usb_configuration *c) | |||
573 | fp->function.set_alt = pn_set_alt; | 597 | fp->function.set_alt = pn_set_alt; |
574 | fp->function.get_alt = pn_get_alt; | 598 | fp->function.get_alt = pn_get_alt; |
575 | fp->function.disable = pn_disconnect; | 599 | fp->function.disable = pn_disconnect; |
600 | spin_lock_init(&fp->rx.lock); | ||
576 | 601 | ||
577 | err = usb_add_function(c, &fp->function); | 602 | err = usb_add_function(c, &fp->function); |
578 | if (err) | 603 | if (err) |