aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2009-09-14 14:26:05 -0400
committerRafael J. Wysocki <rjw@sisk.pl>2009-09-14 14:26:05 -0400
commitac8d513a6801c8636922ccf4f30211810c9a56ce (patch)
tree83ba584487a6a612c8fcf2563c28c0263df35ba2 /drivers/usb
parentbf992fa2bc1ad1bb2aeb0bdfadb43f236b9297fd (diff)
parent99bc47067910f7070e65ee318a6dd79a2371f1e5 (diff)
Merge branch 'master' into for-linus
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/f_phonet.c93
-rw-r--r--drivers/usb/gadget/u_ether.c11
2 files changed, 60 insertions, 44 deletions
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index 96fb118355b0..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
46struct f_phonet { 50struct 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
55static int phonet_rxq_size = 2; 63static int phonet_rxq_size = 17;
56 64
57static inline struct f_phonet *func_to_pn(struct usb_function *f) 65static 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
144static struct usb_endpoint_descriptor 152static struct usb_endpoint_descriptor
@@ -256,25 +264,15 @@ out:
256 dev_kfree_skb(skb); 264 dev_kfree_skb(skb);
257 dev->stats.tx_dropped++; 265 dev->stats.tx_dropped++;
258 } 266 }
259 return 0; 267 return NETDEV_TX_OK;
260} 268}
261 269
262static int pn_net_mtu(struct net_device *dev, int new_mtu) 270static int pn_net_mtu(struct net_device *dev, int new_mtu)
263{ 271{
264 struct phonet_port *port = netdev_priv(dev);
265 unsigned long flags;
266 int err = -EBUSY;
267
268 if ((new_mtu < PHONET_MIN_MTU) || (new_mtu > PHONET_MAX_MTU)) 272 if ((new_mtu < PHONET_MIN_MTU) || (new_mtu > PHONET_MAX_MTU))
269 return -EINVAL; 273 return -EINVAL;
270 274 dev->mtu = new_mtu;
271 spin_lock_irqsave(&port->lock, flags); 275 return 0;
272 if (!netif_carrier_ok(dev)) {
273 dev->mtu = new_mtu;
274 err = 0;
275 }
276 spin_unlock_irqrestore(&port->lock, flags);
277 return err;
278} 276}
279 277
280static const struct net_device_ops pn_netdev_ops = { 278static const struct net_device_ops pn_netdev_ops = {
@@ -308,21 +306,21 @@ static void pn_net_setup(struct net_device *dev)
308static int 306static int
309pn_rx_submit(struct f_phonet *fp, struct usb_request *req, gfp_t gfp_flags) 307pn_rx_submit(struct f_phonet *fp, struct usb_request *req, gfp_t gfp_flags)
310{ 308{
311 struct sk_buff *skb; 309 struct net_device *dev = fp->dev;
312 const size_t size = fp->dev->mtu; 310 struct page *page;
313 int err; 311 int err;
314 312
315 skb = alloc_skb(size, gfp_flags); 313 page = __netdev_alloc_page(dev, gfp_flags);
316 if (!skb) 314 if (!page)
317 return -ENOMEM; 315 return -ENOMEM;
318 316
319 req->buf = skb->data; 317 req->buf = page_address(page);
320 req->length = size; 318 req->length = PAGE_SIZE;
321 req->context = skb; 319 req->context = page;
322 320
323 err = usb_ep_queue(fp->out_ep, req, gfp_flags); 321 err = usb_ep_queue(fp->out_ep, req, gfp_flags);
324 if (unlikely(err)) 322 if (unlikely(err))
325 dev_kfree_skb_any(skb); 323 netdev_free_page(dev, page);
326 return err; 324 return err;
327} 325}
328 326
@@ -330,25 +328,37 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req)
330{ 328{
331 struct f_phonet *fp = ep->driver_data; 329 struct f_phonet *fp = ep->driver_data;
332 struct net_device *dev = fp->dev; 330 struct net_device *dev = fp->dev;
333 struct sk_buff *skb = req->context; 331 struct page *page = req->context;
332 struct sk_buff *skb;
333 unsigned long flags;
334 int status = req->status; 334 int status = req->status;
335 335
336 switch (status) { 336 switch (status) {
337 case 0: 337 case 0:
338 if (unlikely(!netif_running(dev))) 338 spin_lock_irqsave(&fp->rx.lock, flags);
339 break; 339 skb = fp->rx.skb;
340 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))
341 break; 347 break;
342 skb_put(skb, req->actual); 348 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, 0,
343 skb->protocol = htons(ETH_P_PHONET); 349 req->actual);
344 skb_reset_mac_header(skb); 350 page = NULL;
345 __skb_pull(skb, 1); 351
346 skb->dev = dev; 352 if (req->actual < req->length) { /* Last fragment */
347 dev->stats.rx_packets++; 353 skb->protocol = htons(ETH_P_PHONET);
348 dev->stats.rx_bytes += skb->len; 354 skb_reset_mac_header(skb);
349 355 pskb_pull(skb, 1);
350 netif_rx(skb); 356 skb->dev = dev;
351 skb = NULL; 357 dev->stats.rx_packets++;
358 dev->stats.rx_bytes += skb->len;
359
360 netif_rx(skb);
361 }
352 break; 362 break;
353 363
354 /* Do not resubmit in these cases: */ 364 /* Do not resubmit in these cases: */
@@ -366,8 +376,8 @@ static void pn_rx_complete(struct usb_ep *ep, struct usb_request *req)
366 break; 376 break;
367 } 377 }
368 378
369 if (skb) 379 if (page)
370 dev_kfree_skb_any(skb); 380 netdev_free_page(dev, page);
371 if (req) 381 if (req)
372 pn_rx_submit(fp, req, GFP_ATOMIC); 382 pn_rx_submit(fp, req, GFP_ATOMIC);
373} 383}
@@ -385,6 +395,10 @@ static void __pn_reset(struct usb_function *f)
385 395
386 usb_ep_disable(fp->out_ep); 396 usb_ep_disable(fp->out_ep);
387 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 }
388} 402}
389 403
390static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt) 404static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
@@ -583,6 +597,7 @@ int __init phonet_bind_config(struct usb_configuration *c)
583 fp->function.set_alt = pn_set_alt; 597 fp->function.set_alt = pn_set_alt;
584 fp->function.get_alt = pn_get_alt; 598 fp->function.get_alt = pn_get_alt;
585 fp->function.disable = pn_disconnect; 599 fp->function.disable = pn_disconnect;
600 spin_lock_init(&fp->rx.lock);
586 601
587 err = usb_add_function(c, &fp->function); 602 err = usb_add_function(c, &fp->function);
588 if (err) 603 if (err)
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 016f63b39028..c66521953917 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -181,7 +181,7 @@ static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
181 * - ... probably more ethtool ops 181 * - ... probably more ethtool ops
182 */ 182 */
183 183
184static struct ethtool_ops ops = { 184static const struct ethtool_ops ops = {
185 .get_drvinfo = eth_get_drvinfo, 185 .get_drvinfo = eth_get_drvinfo,
186 .get_link = ethtool_op_get_link, 186 .get_link = ethtool_op_get_link,
187}; 187};
@@ -465,7 +465,8 @@ static inline int is_promisc(u16 cdc_filter)
465 return cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS; 465 return cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS;
466} 466}
467 467
468static int eth_start_xmit(struct sk_buff *skb, struct net_device *net) 468static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
469 struct net_device *net)
469{ 470{
470 struct eth_dev *dev = netdev_priv(net); 471 struct eth_dev *dev = netdev_priv(net);
471 int length = skb->len; 472 int length = skb->len;
@@ -487,7 +488,7 @@ static int eth_start_xmit(struct sk_buff *skb, struct net_device *net)
487 488
488 if (!in) { 489 if (!in) {
489 dev_kfree_skb_any(skb); 490 dev_kfree_skb_any(skb);
490 return 0; 491 return NETDEV_TX_OK;
491 } 492 }
492 493
493 /* apply outgoing CDC or RNDIS filters */ 494 /* apply outgoing CDC or RNDIS filters */
@@ -506,7 +507,7 @@ static int eth_start_xmit(struct sk_buff *skb, struct net_device *net)
506 type = USB_CDC_PACKET_TYPE_ALL_MULTICAST; 507 type = USB_CDC_PACKET_TYPE_ALL_MULTICAST;
507 if (!(cdc_filter & type)) { 508 if (!(cdc_filter & type)) {
508 dev_kfree_skb_any(skb); 509 dev_kfree_skb_any(skb);
509 return 0; 510 return NETDEV_TX_OK;
510 } 511 }
511 } 512 }
512 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */ 513 /* ignores USB_CDC_PACKET_TYPE_DIRECTED */
@@ -586,7 +587,7 @@ drop:
586 list_add(&req->list, &dev->tx_reqs); 587 list_add(&req->list, &dev->tx_reqs);
587 spin_unlock_irqrestore(&dev->req_lock, flags); 588 spin_unlock_irqrestore(&dev->req_lock, flags);
588 } 589 }
589 return 0; 590 return NETDEV_TX_OK;
590} 591}
591 592
592/*-------------------------------------------------------------------------*/ 593/*-------------------------------------------------------------------------*/