usbnet.c (805aaa29fa3c5afb26cb42f440f40d3f7f5c4bdc) usbnet.c (777baa4711c6b8373f4e03a3a558d44a6b046d7a)
1/*
2 * USB Network driver infrastructure
3 * Copyright (C) 2000-2005 by David Brownell
4 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 209 unchanged lines hidden (view full) ---

218
219
220/*-------------------------------------------------------------------------
221 *
222 * Network Device Driver (peer link to "Host Device", from USB host)
223 *
224 *-------------------------------------------------------------------------*/
225
1/*
2 * USB Network driver infrastructure
3 * Copyright (C) 2000-2005 by David Brownell
4 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 209 unchanged lines hidden (view full) ---

218
219
220/*-------------------------------------------------------------------------
221 *
222 * Network Device Driver (peer link to "Host Device", from USB host)
223 *
224 *-------------------------------------------------------------------------*/
225
226static int usbnet_change_mtu (struct net_device *net, int new_mtu)
226int usbnet_change_mtu (struct net_device *net, int new_mtu)
227{
228 struct usbnet *dev = netdev_priv(net);
229 int ll_mtu = new_mtu + net->hard_header_len;
230 int old_hard_mtu = dev->hard_mtu;
231 int old_rx_urb_size = dev->rx_urb_size;
232
233 if (new_mtu <= 0)
234 return -EINVAL;

--- 6 unchanged lines hidden (view full) ---

241 if (dev->rx_urb_size == old_hard_mtu) {
242 dev->rx_urb_size = dev->hard_mtu;
243 if (dev->rx_urb_size > old_rx_urb_size)
244 usbnet_unlink_rx_urbs(dev);
245 }
246
247 return 0;
248}
227{
228 struct usbnet *dev = netdev_priv(net);
229 int ll_mtu = new_mtu + net->hard_header_len;
230 int old_hard_mtu = dev->hard_mtu;
231 int old_rx_urb_size = dev->rx_urb_size;
232
233 if (new_mtu <= 0)
234 return -EINVAL;

--- 6 unchanged lines hidden (view full) ---

241 if (dev->rx_urb_size == old_hard_mtu) {
242 dev->rx_urb_size = dev->hard_mtu;
243 if (dev->rx_urb_size > old_rx_urb_size)
244 usbnet_unlink_rx_urbs(dev);
245 }
246
247 return 0;
248}
249EXPORT_SYMBOL_GPL(usbnet_change_mtu);
249
250/*-------------------------------------------------------------------------*/
251
252/* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
253 * completion callbacks. 2.5 should have fixed those bugs...
254 */
255
256static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_head *list)

--- 278 unchanged lines hidden (view full) ---

535 }
536}
537EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
538
539/*-------------------------------------------------------------------------*/
540
541// precondition: never called in_interrupt
542
250
251/*-------------------------------------------------------------------------*/
252
253/* some LK 2.4 HCDs oopsed if we freed or resubmitted urbs from
254 * completion callbacks. 2.5 should have fixed those bugs...
255 */
256
257static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_head *list)

--- 278 unchanged lines hidden (view full) ---

536 }
537}
538EXPORT_SYMBOL_GPL(usbnet_unlink_rx_urbs);
539
540/*-------------------------------------------------------------------------*/
541
542// precondition: never called in_interrupt
543
543static int usbnet_stop (struct net_device *net)
544int usbnet_stop (struct net_device *net)
544{
545 struct usbnet *dev = netdev_priv(net);
546 int temp;
547 DECLARE_WAIT_QUEUE_HEAD_ONSTACK (unlink_wakeup);
548 DECLARE_WAITQUEUE (wait, current);
549
550 netif_stop_queue (net);
551

--- 27 unchanged lines hidden (view full) ---

579 */
580 dev->flags = 0;
581 del_timer_sync (&dev->delay);
582 tasklet_kill (&dev->bh);
583 usb_autopm_put_interface(dev->intf);
584
585 return 0;
586}
545{
546 struct usbnet *dev = netdev_priv(net);
547 int temp;
548 DECLARE_WAIT_QUEUE_HEAD_ONSTACK (unlink_wakeup);
549 DECLARE_WAITQUEUE (wait, current);
550
551 netif_stop_queue (net);
552

--- 27 unchanged lines hidden (view full) ---

580 */
581 dev->flags = 0;
582 del_timer_sync (&dev->delay);
583 tasklet_kill (&dev->bh);
584 usb_autopm_put_interface(dev->intf);
585
586 return 0;
587}
588EXPORT_SYMBOL_GPL(usbnet_stop);
587
588/*-------------------------------------------------------------------------*/
589
590// posts reads, and enables write queuing
591
592// precondition: never called in_interrupt
593
589
590/*-------------------------------------------------------------------------*/
591
592// posts reads, and enables write queuing
593
594// precondition: never called in_interrupt
595
594static int usbnet_open (struct net_device *net)
596int usbnet_open (struct net_device *net)
595{
596 struct usbnet *dev = netdev_priv(net);
597 int retval;
598 struct driver_info *info = dev->driver_info;
599
600 if ((retval = usb_autopm_get_interface(dev->intf)) < 0) {
601 if (netif_msg_ifup (dev))
602 devinfo (dev,

--- 58 unchanged lines hidden (view full) ---

661 // delay posting reads until we're fully open
662 tasklet_schedule (&dev->bh);
663 return retval;
664done:
665 usb_autopm_put_interface(dev->intf);
666done_nopm:
667 return retval;
668}
597{
598 struct usbnet *dev = netdev_priv(net);
599 int retval;
600 struct driver_info *info = dev->driver_info;
601
602 if ((retval = usb_autopm_get_interface(dev->intf)) < 0) {
603 if (netif_msg_ifup (dev))
604 devinfo (dev,

--- 58 unchanged lines hidden (view full) ---

663 // delay posting reads until we're fully open
664 tasklet_schedule (&dev->bh);
665 return retval;
666done:
667 usb_autopm_put_interface(dev->intf);
668done_nopm:
669 return retval;
670}
671EXPORT_SYMBOL_GPL(usbnet_open);
669
670/*-------------------------------------------------------------------------*/
671
672/* ethtool methods; minidrivers may need to add some more, but
673 * they'll probably want to use this base set.
674 */
675
676int usbnet_get_settings (struct net_device *net, struct ethtool_cmd *cmd)

--- 218 unchanged lines hidden (view full) ---

895
896 urb->dev = NULL;
897 entry->state = tx_done;
898 defer_bh(dev, skb, &dev->txq);
899}
900
901/*-------------------------------------------------------------------------*/
902
672
673/*-------------------------------------------------------------------------*/
674
675/* ethtool methods; minidrivers may need to add some more, but
676 * they'll probably want to use this base set.
677 */
678
679int usbnet_get_settings (struct net_device *net, struct ethtool_cmd *cmd)

--- 218 unchanged lines hidden (view full) ---

898
899 urb->dev = NULL;
900 entry->state = tx_done;
901 defer_bh(dev, skb, &dev->txq);
902}
903
904/*-------------------------------------------------------------------------*/
905
903static void usbnet_tx_timeout (struct net_device *net)
906void usbnet_tx_timeout (struct net_device *net)
904{
905 struct usbnet *dev = netdev_priv(net);
906
907 unlink_urbs (dev, &dev->txq);
908 tasklet_schedule (&dev->bh);
909
910 // FIXME: device recovery -- reset?
911}
907{
908 struct usbnet *dev = netdev_priv(net);
909
910 unlink_urbs (dev, &dev->txq);
911 tasklet_schedule (&dev->bh);
912
913 // FIXME: device recovery -- reset?
914}
915EXPORT_SYMBOL_GPL(usbnet_tx_timeout);
912
913/*-------------------------------------------------------------------------*/
914
916
917/*-------------------------------------------------------------------------*/
918
915static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
919int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
916{
917 struct usbnet *dev = netdev_priv(net);
918 int length;
919 int retval = NET_XMIT_SUCCESS;
920 struct urb *urb = NULL;
921 struct skb_data *entry;
922 struct driver_info *info = dev->driver_info;
923 unsigned long flags;

--- 66 unchanged lines hidden (view full) ---

990 dev_kfree_skb_any (skb);
991 usb_free_urb (urb);
992 } else if (netif_msg_tx_queued (dev)) {
993 devdbg (dev, "> tx, len %d, type 0x%x",
994 length, skb->protocol);
995 }
996 return retval;
997}
920{
921 struct usbnet *dev = netdev_priv(net);
922 int length;
923 int retval = NET_XMIT_SUCCESS;
924 struct urb *urb = NULL;
925 struct skb_data *entry;
926 struct driver_info *info = dev->driver_info;
927 unsigned long flags;

--- 66 unchanged lines hidden (view full) ---

994 dev_kfree_skb_any (skb);
995 usb_free_urb (urb);
996 } else if (netif_msg_tx_queued (dev)) {
997 devdbg (dev, "> tx, len %d, type 0x%x",
998 length, skb->protocol);
999 }
1000 return retval;
1001}
1002EXPORT_SYMBOL_GPL(usbnet_start_xmit);
998
1003
999
1000/*-------------------------------------------------------------------------*/
1001
1002// tasklet (work deferred from completions, in_irq) or timer
1003
1004static void usbnet_bh (unsigned long param)
1005{
1006 struct usbnet *dev = (struct usbnet *) param;
1007 struct sk_buff *skb;

--- 89 unchanged lines hidden (view full) ---

1097 if (dev->driver_info->unbind)
1098 dev->driver_info->unbind (dev, intf);
1099
1100 free_netdev(net);
1101 usb_put_dev (xdev);
1102}
1103EXPORT_SYMBOL_GPL(usbnet_disconnect);
1104
1004/*-------------------------------------------------------------------------*/
1005
1006// tasklet (work deferred from completions, in_irq) or timer
1007
1008static void usbnet_bh (unsigned long param)
1009{
1010 struct usbnet *dev = (struct usbnet *) param;
1011 struct sk_buff *skb;

--- 89 unchanged lines hidden (view full) ---

1101 if (dev->driver_info->unbind)
1102 dev->driver_info->unbind (dev, intf);
1103
1104 free_netdev(net);
1105 usb_put_dev (xdev);
1106}
1107EXPORT_SYMBOL_GPL(usbnet_disconnect);
1108
1109static const struct net_device_ops usbnet_netdev_ops = {
1110 .ndo_open = usbnet_open,
1111 .ndo_stop = usbnet_stop,
1112 .ndo_start_xmit = usbnet_start_xmit,
1113 .ndo_tx_timeout = usbnet_tx_timeout,
1114 .ndo_change_mtu = usbnet_change_mtu,
1115 .ndo_set_mac_address = eth_mac_addr,
1116 .ndo_validate_addr = eth_validate_addr,
1117};
1105
1106/*-------------------------------------------------------------------------*/
1107
1108// precondition: never called in_interrupt
1109
1110int
1111usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1112{

--- 53 unchanged lines hidden (view full) ---

1166 dev->hard_mtu = net->mtu + net->hard_header_len;
1167#if 0
1168// dma_supported() is deeply broken on almost all architectures
1169 // possible with some EHCI controllers
1170 if (dma_supported (&udev->dev, DMA_64BIT_MASK))
1171 net->features |= NETIF_F_HIGHDMA;
1172#endif
1173
1118
1119/*-------------------------------------------------------------------------*/
1120
1121// precondition: never called in_interrupt
1122
1123int
1124usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1125{

--- 53 unchanged lines hidden (view full) ---

1179 dev->hard_mtu = net->mtu + net->hard_header_len;
1180#if 0
1181// dma_supported() is deeply broken on almost all architectures
1182 // possible with some EHCI controllers
1183 if (dma_supported (&udev->dev, DMA_64BIT_MASK))
1184 net->features |= NETIF_F_HIGHDMA;
1185#endif
1186
1174 net->change_mtu = usbnet_change_mtu;
1187 net->netdev_ops = &usbnet_netdev_ops;
1188#ifdef CONFIG_COMPAT_NET_DEV_OPS
1175 net->hard_start_xmit = usbnet_start_xmit;
1176 net->open = usbnet_open;
1177 net->stop = usbnet_stop;
1189 net->hard_start_xmit = usbnet_start_xmit;
1190 net->open = usbnet_open;
1191 net->stop = usbnet_stop;
1178 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
1179 net->tx_timeout = usbnet_tx_timeout;
1192 net->tx_timeout = usbnet_tx_timeout;
1193#endif
1194 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
1180 net->ethtool_ops = &usbnet_ethtool_ops;
1181
1182 // allow device-specific bind/init procedures
1183 // NOTE net->name still not usable ...
1184 if (info->bind) {
1185 status = info->bind (dev, udev);
1186 if (status < 0)
1187 goto out1;

--- 128 unchanged lines hidden ---
1195 net->ethtool_ops = &usbnet_ethtool_ops;
1196
1197 // allow device-specific bind/init procedures
1198 // NOTE net->name still not usable ...
1199 if (info->bind) {
1200 status = info->bind (dev, udev);
1201 if (status < 0)
1202 goto out1;

--- 128 unchanged lines hidden ---