aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2008-11-20 00:32:24 -0500
committerDavid S. Miller <davem@davemloft.net>2008-11-20 00:32:24 -0500
commitd314774cf2cd5dfeb39a00d37deee65d4c627927 (patch)
tree1c7778b509cea814aa2b7115949667941037d07c
parent6b41e7dd90c6a628ab5fb8d781302d60a243b2ce (diff)
netdev: network device operations infrastructure
This patch changes the network device internal API to move adminstrative operations out of the network device structure and into a separate structure. This patch involves some hackery to maintain compatablity between the new and old model, so all 300+ drivers don't have to be changed at once. For drivers that aren't converted yet, the netdevice_ops virt function list still resides in the net_device structure. For old protocols, the new net_device_ops are copied out to the old net_device pointers. After the transistion is completed the nag message can be changed to an WARN_ON, and the compatiablity code can be made configurable. Some function pointers aren't moved: * destructor can't be in net_device_ops because it may need to be referenced after the module is unloaded. * neighbor setup is manipulated in a couple of places that need special consideration * hard_start_xmit is in the fast path for transmit. Signed-off-by: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/netdevice.h232
-rw-r--r--net/Kconfig3
-rw-r--r--net/core/dev.c109
-rw-r--r--net/core/netpoll.c7
-rw-r--r--net/core/rtnetlink.c9
-rw-r--r--net/sched/sch_generic.c4
6 files changed, 259 insertions, 105 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 12d7f4469dc9..9060f5f3517a 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -451,6 +451,131 @@ struct netdev_queue {
451 struct Qdisc *qdisc_sleeping; 451 struct Qdisc *qdisc_sleeping;
452} ____cacheline_aligned_in_smp; 452} ____cacheline_aligned_in_smp;
453 453
454
455/*
456 * This structure defines the management hooks for network devices.
457 * The following hooks can bed defined and are optonal (can be null)
458 * unless otherwise noted.
459 *
460 * int (*ndo_init)(struct net_device *dev);
461 * This function is called once when network device is registered.
462 * The network device can use this to any late stage initializaton
463 * or semantic validattion. It can fail with an error code which will
464 * be propogated back to register_netdev
465 *
466 * void (*ndo_uninit)(struct net_device *dev);
467 * This function is called when device is unregistered or when registration
468 * fails. It is not called if init fails.
469 *
470 * int (*ndo_open)(struct net_device *dev);
471 * This function is called when network device transistions to the up
472 * state.
473 *
474 * int (*ndo_stop)(struct net_device *dev);
475 * This function is called when network device transistions to the down
476 * state.
477 *
478 * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
479 * This function is called to allow device receiver to make
480 * changes to configuration when multicast or promiscious is enabled.
481 *
482 * void (*ndo_set_rx_mode)(struct net_device *dev);
483 * This function is called device changes address list filtering.
484 *
485 * void (*ndo_set_multicast_list)(struct net_device *dev);
486 * This function is called when the multicast address list changes.
487 *
488 * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
489 * This function is called when the Media Access Control address
490 * needs to be changed. If not this interface is not defined, the
491 * mac address can not be changed.
492 *
493 * int (*ndo_validate_addr)(struct net_device *dev);
494 * Test if Media Access Control address is valid for the device.
495 *
496 * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
497 * Called when a user request an ioctl which can't be handled by
498 * the generic interface code. If not defined ioctl's return
499 * not supported error code.
500 *
501 * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
502 * Used to set network devices bus interface parameters. This interface
503 * is retained for legacy reason, new devices should use the bus
504 * interface (PCI) for low level management.
505 *
506 * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
507 * Called when a user wants to change the Maximum Transfer Unit
508 * of a device. If not defined, any request to change MTU will
509 * will return an error.
510 *
511 * void (*ndo_tx_timeout) (struct net_device *dev);
512 * Callback uses when the transmitter has not made any progress
513 * for dev->watchdog ticks.
514 *
515 * struct net_device_stats* (*get_stats)(struct net_device *dev);
516 * Called when a user wants to get the network device usage
517 * statistics. If not defined, the counters in dev->stats will
518 * be used.
519 *
520 * void (*ndo_vlan_rx_register)(struct net_device *dev, struct vlan_group *grp);
521 * If device support VLAN receive accleration
522 * (ie. dev->features & NETIF_F_HW_VLAN_RX), then this function is called
523 * when vlan groups for the device changes. Note: grp is NULL
524 * if no vlan's groups are being used.
525 *
526 * void (*ndo_vlan_rx_add_vid)(struct net_device *dev, unsigned short vid);
527 * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
528 * this function is called when a VLAN id is registered.
529 *
530 * void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid);
531 * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
532 * this function is called when a VLAN id is unregistered.
533 *
534 * void (*ndo_poll_controller)(struct net_device *dev);
535 */
536struct net_device_ops {
537 int (*ndo_init)(struct net_device *dev);
538 void (*ndo_uninit)(struct net_device *dev);
539 int (*ndo_open)(struct net_device *dev);
540 int (*ndo_stop)(struct net_device *dev);
541#define HAVE_CHANGE_RX_FLAGS
542 void (*ndo_change_rx_flags)(struct net_device *dev,
543 int flags);
544#define HAVE_SET_RX_MODE
545 void (*ndo_set_rx_mode)(struct net_device *dev);
546#define HAVE_MULTICAST
547 void (*ndo_set_multicast_list)(struct net_device *dev);
548#define HAVE_SET_MAC_ADDR
549 int (*ndo_set_mac_address)(struct net_device *dev,
550 void *addr);
551#define HAVE_VALIDATE_ADDR
552 int (*ndo_validate_addr)(struct net_device *dev);
553#define HAVE_PRIVATE_IOCTL
554 int (*ndo_do_ioctl)(struct net_device *dev,
555 struct ifreq *ifr, int cmd);
556#define HAVE_SET_CONFIG
557 int (*ndo_set_config)(struct net_device *dev,
558 struct ifmap *map);
559#define HAVE_CHANGE_MTU
560 int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
561
562#define HAVE_TX_TIMEOUT
563 void (*ndo_tx_timeout) (struct net_device *dev);
564
565 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
566
567 void (*ndo_vlan_rx_register)(struct net_device *dev,
568 struct vlan_group *grp);
569 void (*ndo_vlan_rx_add_vid)(struct net_device *dev,
570 unsigned short vid);
571 void (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
572 unsigned short vid);
573#ifdef CONFIG_NET_POLL_CONTROLLER
574#define HAVE_NETDEV_POLL
575 void (*ndo_poll_controller)(struct net_device *dev);
576#endif
577};
578
454/* 579/*
455 * The DEVICE structure. 580 * The DEVICE structure.
456 * Actually, this whole structure is a big mistake. It mixes I/O 581 * Actually, this whole structure is a big mistake. It mixes I/O
@@ -498,11 +623,6 @@ struct net_device
498#ifdef CONFIG_NETPOLL 623#ifdef CONFIG_NETPOLL
499 struct list_head napi_list; 624 struct list_head napi_list;
500#endif 625#endif
501
502 /* The device initialization function. Called only once. */
503 int (*init)(struct net_device *dev);
504
505 /* ------- Fields preinitialized in Space.c finish here ------- */
506 626
507 /* Net device features */ 627 /* Net device features */
508 unsigned long features; 628 unsigned long features;
@@ -546,15 +666,13 @@ struct net_device
546 * for all in netdev_increment_features. 666 * for all in netdev_increment_features.
547 */ 667 */
548#define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \ 668#define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \
549 NETIF_F_SG | NETIF_F_HIGHDMA | \ 669 NETIF_F_SG | NETIF_F_HIGHDMA | \
550 NETIF_F_FRAGLIST) 670 NETIF_F_FRAGLIST)
551 671
552 /* Interface index. Unique device identifier */ 672 /* Interface index. Unique device identifier */
553 int ifindex; 673 int ifindex;
554 int iflink; 674 int iflink;
555 675
556
557 struct net_device_stats* (*get_stats)(struct net_device *dev);
558 struct net_device_stats stats; 676 struct net_device_stats stats;
559 677
560#ifdef CONFIG_WIRELESS_EXT 678#ifdef CONFIG_WIRELESS_EXT
@@ -564,18 +682,13 @@ struct net_device
564 /* Instance data managed by the core of Wireless Extensions. */ 682 /* Instance data managed by the core of Wireless Extensions. */
565 struct iw_public_data * wireless_data; 683 struct iw_public_data * wireless_data;
566#endif 684#endif
685 /* Management operations */
686 const struct net_device_ops *netdev_ops;
567 const struct ethtool_ops *ethtool_ops; 687 const struct ethtool_ops *ethtool_ops;
568 688
569 /* Hardware header description */ 689 /* Hardware header description */
570 const struct header_ops *header_ops; 690 const struct header_ops *header_ops;
571 691
572 /*
573 * This marks the end of the "visible" part of the structure. All
574 * fields hereafter are internal to the system, and may change at
575 * will (read: may be cleaned up at will).
576 */
577
578
579 unsigned int flags; /* interface flags (a la BSD) */ 692 unsigned int flags; /* interface flags (a la BSD) */
580 unsigned short gflags; 693 unsigned short gflags;
581 unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */ 694 unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */
@@ -634,7 +747,7 @@ struct net_device
634 unsigned long last_rx; /* Time of last Rx */ 747 unsigned long last_rx; /* Time of last Rx */
635 /* Interface address info used in eth_type_trans() */ 748 /* Interface address info used in eth_type_trans() */
636 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address, (before bcast 749 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address, (before bcast
637 because most packets are unicast) */ 750 because most packets are unicast) */
638 751
639 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ 752 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
640 753
@@ -648,6 +761,10 @@ struct net_device
648 /* Number of TX queues currently active in device */ 761 /* Number of TX queues currently active in device */
649 unsigned int real_num_tx_queues; 762 unsigned int real_num_tx_queues;
650 763
764 /* Map buffer to appropriate transmit queue */
765 u16 (*select_queue)(struct net_device *dev,
766 struct sk_buff *skb);
767
651 unsigned long tx_queue_len; /* Max frames per queue allowed */ 768 unsigned long tx_queue_len; /* Max frames per queue allowed */
652 spinlock_t tx_global_lock; 769 spinlock_t tx_global_lock;
653/* 770/*
@@ -662,9 +779,6 @@ struct net_device
662 int watchdog_timeo; /* used by dev_watchdog() */ 779 int watchdog_timeo; /* used by dev_watchdog() */
663 struct timer_list watchdog_timer; 780 struct timer_list watchdog_timer;
664 781
665/*
666 * refcnt is a very hot point, so align it on SMP
667 */
668 /* Number of references to this device */ 782 /* Number of references to this device */
669 atomic_t refcnt ____cacheline_aligned_in_smp; 783 atomic_t refcnt ____cacheline_aligned_in_smp;
670 784
@@ -683,56 +797,14 @@ struct net_device
683 NETREG_RELEASED, /* called free_netdev */ 797 NETREG_RELEASED, /* called free_netdev */
684 } reg_state; 798 } reg_state;
685 799
686 /* Called after device is detached from network. */ 800 /* Called from unregister, can be used to call free_netdev */
687 void (*uninit)(struct net_device *dev); 801 void (*destructor)(struct net_device *dev);
688 /* Called after last user reference disappears. */
689 void (*destructor)(struct net_device *dev);
690 802
691 /* Pointers to interface service routines. */ 803 int (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
692 int (*open)(struct net_device *dev);
693 int (*stop)(struct net_device *dev);
694#define HAVE_NETDEV_POLL
695#define HAVE_CHANGE_RX_FLAGS
696 void (*change_rx_flags)(struct net_device *dev,
697 int flags);
698#define HAVE_SET_RX_MODE
699 void (*set_rx_mode)(struct net_device *dev);
700#define HAVE_MULTICAST
701 void (*set_multicast_list)(struct net_device *dev);
702#define HAVE_SET_MAC_ADDR
703 int (*set_mac_address)(struct net_device *dev,
704 void *addr);
705#define HAVE_VALIDATE_ADDR
706 int (*validate_addr)(struct net_device *dev);
707#define HAVE_PRIVATE_IOCTL
708 int (*do_ioctl)(struct net_device *dev,
709 struct ifreq *ifr, int cmd);
710#define HAVE_SET_CONFIG
711 int (*set_config)(struct net_device *dev,
712 struct ifmap *map);
713#define HAVE_CHANGE_MTU
714 int (*change_mtu)(struct net_device *dev, int new_mtu);
715 804
716#define HAVE_TX_TIMEOUT
717 void (*tx_timeout) (struct net_device *dev);
718
719 void (*vlan_rx_register)(struct net_device *dev,
720 struct vlan_group *grp);
721 void (*vlan_rx_add_vid)(struct net_device *dev,
722 unsigned short vid);
723 void (*vlan_rx_kill_vid)(struct net_device *dev,
724 unsigned short vid);
725
726 int (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
727#ifdef CONFIG_NETPOLL 805#ifdef CONFIG_NETPOLL
728 struct netpoll_info *npinfo; 806 struct netpoll_info *npinfo;
729#endif 807#endif
730#ifdef CONFIG_NET_POLL_CONTROLLER
731 void (*poll_controller)(struct net_device *dev);
732#endif
733
734 u16 (*select_queue)(struct net_device *dev,
735 struct sk_buff *skb);
736 808
737#ifdef CONFIG_NET_NS 809#ifdef CONFIG_NET_NS
738 /* Network namespace this network device is inside */ 810 /* Network namespace this network device is inside */
@@ -763,6 +835,38 @@ struct net_device
763 /* for setting kernel sock attribute on TCP connection setup */ 835 /* for setting kernel sock attribute on TCP connection setup */
764#define GSO_MAX_SIZE 65536 836#define GSO_MAX_SIZE 65536
765 unsigned int gso_max_size; 837 unsigned int gso_max_size;
838
839#ifdef CONFIG_COMPAT_NET_DEV_OPS
840 struct {
841 int (*init)(struct net_device *dev);
842 void (*uninit)(struct net_device *dev);
843 int (*open)(struct net_device *dev);
844 int (*stop)(struct net_device *dev);
845 void (*change_rx_flags)(struct net_device *dev,
846 int flags);
847 void (*set_rx_mode)(struct net_device *dev);
848 void (*set_multicast_list)(struct net_device *dev);
849 int (*set_mac_address)(struct net_device *dev,
850 void *addr);
851 int (*validate_addr)(struct net_device *dev);
852 int (*do_ioctl)(struct net_device *dev,
853 struct ifreq *ifr, int cmd);
854 int (*set_config)(struct net_device *dev,
855 struct ifmap *map);
856 int (*change_mtu)(struct net_device *dev, int new_mtu);
857 void (*tx_timeout) (struct net_device *dev);
858 struct net_device_stats* (*get_stats)(struct net_device *dev);
859 void (*vlan_rx_register)(struct net_device *dev,
860 struct vlan_group *grp);
861 void (*vlan_rx_add_vid)(struct net_device *dev,
862 unsigned short vid);
863 void (*vlan_rx_kill_vid)(struct net_device *dev,
864 unsigned short vid);
865#ifdef CONFIG_NET_POLL_CONTROLLER
866 void (*poll_controller)(struct net_device *dev);
867#endif
868#endif
869 };
766}; 870};
767#define to_net_dev(d) container_of(d, struct net_device, dev) 871#define to_net_dev(d) container_of(d, struct net_device, dev)
768 872
diff --git a/net/Kconfig b/net/Kconfig
index 8c3d97ca0d96..4e2e40ba8ba6 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -32,6 +32,9 @@ config NET_NS
32 Allow user space to create what appear to be multiple instances 32 Allow user space to create what appear to be multiple instances
33 of the network stack. 33 of the network stack.
34 34
35config COMPAT_NET_DEV_OPS
36 def_bool y
37
35source "net/packet/Kconfig" 38source "net/packet/Kconfig"
36source "net/unix/Kconfig" 39source "net/unix/Kconfig"
37source "net/xfrm/Kconfig" 40source "net/xfrm/Kconfig"
diff --git a/net/core/dev.c b/net/core/dev.c
index e08c0fcd603b..ca14ab407b33 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1059,6 +1059,7 @@ void dev_load(struct net *net, const char *name)
1059 */ 1059 */
1060int dev_open(struct net_device *dev) 1060int dev_open(struct net_device *dev)
1061{ 1061{
1062 const struct net_device_ops *ops = dev->netdev_ops;
1062 int ret = 0; 1063 int ret = 0;
1063 1064
1064 ASSERT_RTNL(); 1065 ASSERT_RTNL();
@@ -1081,11 +1082,11 @@ int dev_open(struct net_device *dev)
1081 */ 1082 */
1082 set_bit(__LINK_STATE_START, &dev->state); 1083 set_bit(__LINK_STATE_START, &dev->state);
1083 1084
1084 if (dev->validate_addr) 1085 if (ops->ndo_validate_addr)
1085 ret = dev->validate_addr(dev); 1086 ret = ops->ndo_validate_addr(dev);
1086 1087
1087 if (!ret && dev->open) 1088 if (!ret && ops->ndo_open)
1088 ret = dev->open(dev); 1089 ret = ops->ndo_open(dev);
1089 1090
1090 /* 1091 /*
1091 * If it went open OK then: 1092 * If it went open OK then:
@@ -1129,6 +1130,7 @@ int dev_open(struct net_device *dev)
1129 */ 1130 */
1130int dev_close(struct net_device *dev) 1131int dev_close(struct net_device *dev)
1131{ 1132{
1133 const struct net_device_ops *ops = dev->netdev_ops;
1132 ASSERT_RTNL(); 1134 ASSERT_RTNL();
1133 1135
1134 might_sleep(); 1136 might_sleep();
@@ -1161,8 +1163,8 @@ int dev_close(struct net_device *dev)
1161 * We allow it to be called even after a DETACH hot-plug 1163 * We allow it to be called even after a DETACH hot-plug
1162 * event. 1164 * event.
1163 */ 1165 */
1164 if (dev->stop) 1166 if (ops->ndo_stop)
1165 dev->stop(dev); 1167 ops->ndo_stop(dev);
1166 1168
1167 /* 1169 /*
1168 * Device is now down. 1170 * Device is now down.
@@ -2930,8 +2932,10 @@ int netdev_set_master(struct net_device *slave, struct net_device *master)
2930 2932
2931static void dev_change_rx_flags(struct net_device *dev, int flags) 2933static void dev_change_rx_flags(struct net_device *dev, int flags)
2932{ 2934{
2933 if (dev->flags & IFF_UP && dev->change_rx_flags) 2935 const struct net_device_ops *ops = dev->netdev_ops;
2934 dev->change_rx_flags(dev, flags); 2936
2937 if ((dev->flags & IFF_UP) && ops->ndo_change_rx_flags)
2938 ops->ndo_change_rx_flags(dev, flags);
2935} 2939}
2936 2940
2937static int __dev_set_promiscuity(struct net_device *dev, int inc) 2941static int __dev_set_promiscuity(struct net_device *dev, int inc)
@@ -3051,6 +3055,8 @@ int dev_set_allmulti(struct net_device *dev, int inc)
3051 */ 3055 */
3052void __dev_set_rx_mode(struct net_device *dev) 3056void __dev_set_rx_mode(struct net_device *dev)
3053{ 3057{
3058 const struct net_device_ops *ops = dev->netdev_ops;
3059
3054 /* dev_open will call this function so the list will stay sane. */ 3060 /* dev_open will call this function so the list will stay sane. */
3055 if (!(dev->flags&IFF_UP)) 3061 if (!(dev->flags&IFF_UP))
3056 return; 3062 return;
@@ -3058,8 +3064,8 @@ void __dev_set_rx_mode(struct net_device *dev)
3058 if (!netif_device_present(dev)) 3064 if (!netif_device_present(dev))
3059 return; 3065 return;
3060 3066
3061 if (dev->set_rx_mode) 3067 if (ops->ndo_set_rx_mode)
3062 dev->set_rx_mode(dev); 3068 ops->ndo_set_rx_mode(dev);
3063 else { 3069 else {
3064 /* Unicast addresses changes may only happen under the rtnl, 3070 /* Unicast addresses changes may only happen under the rtnl,
3065 * therefore calling __dev_set_promiscuity here is safe. 3071 * therefore calling __dev_set_promiscuity here is safe.
@@ -3072,8 +3078,8 @@ void __dev_set_rx_mode(struct net_device *dev)
3072 dev->uc_promisc = 0; 3078 dev->uc_promisc = 0;
3073 } 3079 }
3074 3080
3075 if (dev->set_multicast_list) 3081 if (ops->ndo_set_multicast_list)
3076 dev->set_multicast_list(dev); 3082 ops->ndo_set_multicast_list(dev);
3077 } 3083 }
3078} 3084}
3079 3085
@@ -3432,6 +3438,7 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
3432 */ 3438 */
3433int dev_set_mtu(struct net_device *dev, int new_mtu) 3439int dev_set_mtu(struct net_device *dev, int new_mtu)
3434{ 3440{
3441 const struct net_device_ops *ops = dev->netdev_ops;
3435 int err; 3442 int err;
3436 3443
3437 if (new_mtu == dev->mtu) 3444 if (new_mtu == dev->mtu)
@@ -3445,10 +3452,11 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
3445 return -ENODEV; 3452 return -ENODEV;
3446 3453
3447 err = 0; 3454 err = 0;
3448 if (dev->change_mtu) 3455 if (ops->ndo_change_mtu)
3449 err = dev->change_mtu(dev, new_mtu); 3456 err = ops->ndo_change_mtu(dev, new_mtu);
3450 else 3457 else
3451 dev->mtu = new_mtu; 3458 dev->mtu = new_mtu;
3459
3452 if (!err && dev->flags & IFF_UP) 3460 if (!err && dev->flags & IFF_UP)
3453 call_netdevice_notifiers(NETDEV_CHANGEMTU, dev); 3461 call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
3454 return err; 3462 return err;
@@ -3463,15 +3471,16 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
3463 */ 3471 */
3464int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa) 3472int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
3465{ 3473{
3474 const struct net_device_ops *ops = dev->netdev_ops;
3466 int err; 3475 int err;
3467 3476
3468 if (!dev->set_mac_address) 3477 if (!ops->ndo_set_mac_address)
3469 return -EOPNOTSUPP; 3478 return -EOPNOTSUPP;
3470 if (sa->sa_family != dev->type) 3479 if (sa->sa_family != dev->type)
3471 return -EINVAL; 3480 return -EINVAL;
3472 if (!netif_device_present(dev)) 3481 if (!netif_device_present(dev))
3473 return -ENODEV; 3482 return -ENODEV;
3474 err = dev->set_mac_address(dev, sa); 3483 err = ops->ndo_set_mac_address(dev, sa);
3475 if (!err) 3484 if (!err)
3476 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); 3485 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
3477 return err; 3486 return err;
@@ -3551,6 +3560,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3551{ 3560{
3552 int err; 3561 int err;
3553 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); 3562 struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
3563 const struct net_device_ops *ops = dev->netdev_ops;
3554 3564
3555 if (!dev) 3565 if (!dev)
3556 return -ENODEV; 3566 return -ENODEV;
@@ -3578,15 +3588,15 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3578 return 0; 3588 return 0;
3579 3589
3580 case SIOCSIFMAP: 3590 case SIOCSIFMAP:
3581 if (dev->set_config) { 3591 if (ops->ndo_set_config) {
3582 if (!netif_device_present(dev)) 3592 if (!netif_device_present(dev))
3583 return -ENODEV; 3593 return -ENODEV;
3584 return dev->set_config(dev, &ifr->ifr_map); 3594 return ops->ndo_set_config(dev, &ifr->ifr_map);
3585 } 3595 }
3586 return -EOPNOTSUPP; 3596 return -EOPNOTSUPP;
3587 3597
3588 case SIOCADDMULTI: 3598 case SIOCADDMULTI:
3589 if ((!dev->set_multicast_list && !dev->set_rx_mode) || 3599 if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) ||
3590 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 3600 ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
3591 return -EINVAL; 3601 return -EINVAL;
3592 if (!netif_device_present(dev)) 3602 if (!netif_device_present(dev))
@@ -3595,7 +3605,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3595 dev->addr_len, 1); 3605 dev->addr_len, 1);
3596 3606
3597 case SIOCDELMULTI: 3607 case SIOCDELMULTI:
3598 if ((!dev->set_multicast_list && !dev->set_rx_mode) || 3608 if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) ||
3599 ifr->ifr_hwaddr.sa_family != AF_UNSPEC) 3609 ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
3600 return -EINVAL; 3610 return -EINVAL;
3601 if (!netif_device_present(dev)) 3611 if (!netif_device_present(dev))
@@ -3633,10 +3643,9 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
3633 cmd == SIOCBRDELIF || 3643 cmd == SIOCBRDELIF ||
3634 cmd == SIOCWANDEV) { 3644 cmd == SIOCWANDEV) {
3635 err = -EOPNOTSUPP; 3645 err = -EOPNOTSUPP;
3636 if (dev->do_ioctl) { 3646 if (ops->ndo_do_ioctl) {
3637 if (netif_device_present(dev)) 3647 if (netif_device_present(dev))
3638 err = dev->do_ioctl(dev, ifr, 3648 err = ops->ndo_do_ioctl(dev, ifr, cmd);
3639 cmd);
3640 else 3649 else
3641 err = -ENODEV; 3650 err = -ENODEV;
3642 } 3651 }
@@ -3897,8 +3906,8 @@ static void rollback_registered(struct net_device *dev)
3897 */ 3906 */
3898 dev_addr_discard(dev); 3907 dev_addr_discard(dev);
3899 3908
3900 if (dev->uninit) 3909 if (dev->netdev_ops->ndo_uninit)
3901 dev->uninit(dev); 3910 dev->netdev_ops->ndo_uninit(dev);
3902 3911
3903 /* Notifier chain MUST detach us from master device. */ 3912 /* Notifier chain MUST detach us from master device. */
3904 WARN_ON(dev->master); 3913 WARN_ON(dev->master);
@@ -3988,7 +3997,7 @@ int register_netdevice(struct net_device *dev)
3988 struct hlist_head *head; 3997 struct hlist_head *head;
3989 struct hlist_node *p; 3998 struct hlist_node *p;
3990 int ret; 3999 int ret;
3991 struct net *net; 4000 struct net *net = dev_net(dev);
3992 4001
3993 BUG_ON(dev_boot_phase); 4002 BUG_ON(dev_boot_phase);
3994 ASSERT_RTNL(); 4003 ASSERT_RTNL();
@@ -3997,8 +4006,7 @@ int register_netdevice(struct net_device *dev)
3997 4006
3998 /* When net_device's are persistent, this will be fatal. */ 4007 /* When net_device's are persistent, this will be fatal. */
3999 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); 4008 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
4000 BUG_ON(!dev_net(dev)); 4009 BUG_ON(!net);
4001 net = dev_net(dev);
4002 4010
4003 spin_lock_init(&dev->addr_list_lock); 4011 spin_lock_init(&dev->addr_list_lock);
4004 netdev_set_addr_lockdep_class(dev); 4012 netdev_set_addr_lockdep_class(dev);
@@ -4006,9 +4014,46 @@ int register_netdevice(struct net_device *dev)
4006 4014
4007 dev->iflink = -1; 4015 dev->iflink = -1;
4008 4016
4017#ifdef CONFIG_COMPAT_NET_DEV_OPS
4018 /* Netdevice_ops API compatiability support.
4019 * This is temporary until all network devices are converted.
4020 */
4021 if (dev->netdev_ops) {
4022 const struct net_device_ops *ops = dev->netdev_ops;
4023
4024 dev->init = ops->ndo_init;
4025 dev->uninit = ops->ndo_uninit;
4026 dev->open = ops->ndo_open;
4027 dev->change_rx_flags = ops->ndo_change_rx_flags;
4028 dev->set_rx_mode = ops->ndo_set_rx_mode;
4029 dev->set_multicast_list = ops->ndo_set_multicast_list;
4030 dev->set_mac_address = ops->ndo_set_mac_address;
4031 dev->validate_addr = ops->ndo_validate_addr;
4032 dev->do_ioctl = ops->ndo_do_ioctl;
4033 dev->set_config = ops->ndo_set_config;
4034 dev->change_mtu = ops->ndo_change_mtu;
4035 dev->tx_timeout = ops->ndo_tx_timeout;
4036 dev->get_stats = ops->ndo_get_stats;
4037 dev->vlan_rx_register = ops->ndo_vlan_rx_register;
4038 dev->vlan_rx_add_vid = ops->ndo_vlan_rx_add_vid;
4039 dev->vlan_rx_kill_vid = ops->ndo_vlan_rx_kill_vid;
4040#ifdef CONFIG_NET_POLL_CONTROLLER
4041 dev->poll_controller = ops->ndo_poll_controller;
4042#endif
4043 } else {
4044 char drivername[64];
4045 pr_info("%s (%s): not using net_device_ops yet\n",
4046 dev->name, netdev_drivername(dev, drivername, 64));
4047
4048 /* This works only because net_device_ops and the
4049 compatiablity structure are the same. */
4050 dev->netdev_ops = (void *) &(dev->init);
4051 }
4052#endif
4053
4009 /* Init, if this function is available */ 4054 /* Init, if this function is available */
4010 if (dev->init) { 4055 if (dev->netdev_ops->ndo_init) {
4011 ret = dev->init(dev); 4056 ret = dev->netdev_ops->ndo_init(dev);
4012 if (ret) { 4057 if (ret) {
4013 if (ret > 0) 4058 if (ret > 0)
4014 ret = -EIO; 4059 ret = -EIO;
@@ -4086,8 +4131,8 @@ out:
4086 return ret; 4131 return ret;
4087 4132
4088err_uninit: 4133err_uninit:
4089 if (dev->uninit) 4134 if (dev->netdev_ops->ndo_uninit)
4090 dev->uninit(dev); 4135 dev->netdev_ops->ndo_uninit(dev);
4091 goto out; 4136 goto out;
4092} 4137}
4093 4138
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index fc4e28e23b89..630df6034444 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -172,12 +172,13 @@ static void service_arp_queue(struct netpoll_info *npi)
172void netpoll_poll(struct netpoll *np) 172void netpoll_poll(struct netpoll *np)
173{ 173{
174 struct net_device *dev = np->dev; 174 struct net_device *dev = np->dev;
175 const struct net_device_ops *ops = dev->netdev_ops;
175 176
176 if (!dev || !netif_running(dev) || !dev->poll_controller) 177 if (!dev || !netif_running(dev) || !ops->ndo_poll_controller)
177 return; 178 return;
178 179
179 /* Process pending work on NIC */ 180 /* Process pending work on NIC */
180 dev->poll_controller(dev); 181 ops->ndo_poll_controller(dev);
181 182
182 poll_napi(dev); 183 poll_napi(dev);
183 184
@@ -694,7 +695,7 @@ int netpoll_setup(struct netpoll *np)
694 atomic_inc(&npinfo->refcnt); 695 atomic_inc(&npinfo->refcnt);
695 } 696 }
696 697
697 if (!ndev->poll_controller) { 698 if (!ndev->netdev_ops->ndo_poll_controller) {
698 printk(KERN_ERR "%s: %s doesn't support polling, aborting.\n", 699 printk(KERN_ERR "%s: %s doesn't support polling, aborting.\n",
699 np->name, np->dev_name); 700 np->name, np->dev_name);
700 err = -ENOTSUPP; 701 err = -ENOTSUPP;
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 4dfb6b4d4559..6f8e0778e565 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -762,6 +762,7 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
762static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm, 762static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
763 struct nlattr **tb, char *ifname, int modified) 763 struct nlattr **tb, char *ifname, int modified)
764{ 764{
765 const struct net_device_ops *ops = dev->netdev_ops;
765 int send_addr_notify = 0; 766 int send_addr_notify = 0;
766 int err; 767 int err;
767 768
@@ -783,7 +784,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
783 struct rtnl_link_ifmap *u_map; 784 struct rtnl_link_ifmap *u_map;
784 struct ifmap k_map; 785 struct ifmap k_map;
785 786
786 if (!dev->set_config) { 787 if (!ops->ndo_set_config) {
787 err = -EOPNOTSUPP; 788 err = -EOPNOTSUPP;
788 goto errout; 789 goto errout;
789 } 790 }
@@ -801,7 +802,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
801 k_map.dma = (unsigned char) u_map->dma; 802 k_map.dma = (unsigned char) u_map->dma;
802 k_map.port = (unsigned char) u_map->port; 803 k_map.port = (unsigned char) u_map->port;
803 804
804 err = dev->set_config(dev, &k_map); 805 err = ops->ndo_set_config(dev, &k_map);
805 if (err < 0) 806 if (err < 0)
806 goto errout; 807 goto errout;
807 808
@@ -812,7 +813,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
812 struct sockaddr *sa; 813 struct sockaddr *sa;
813 int len; 814 int len;
814 815
815 if (!dev->set_mac_address) { 816 if (!ops->ndo_set_mac_address) {
816 err = -EOPNOTSUPP; 817 err = -EOPNOTSUPP;
817 goto errout; 818 goto errout;
818 } 819 }
@@ -831,7 +832,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
831 sa->sa_family = dev->type; 832 sa->sa_family = dev->type;
832 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]), 833 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
833 dev->addr_len); 834 dev->addr_len);
834 err = dev->set_mac_address(dev, sa); 835 err = ops->ndo_set_mac_address(dev, sa);
835 kfree(sa); 836 kfree(sa);
836 if (err) 837 if (err)
837 goto errout; 838 goto errout;
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 80c8f3dbbea1..95ab55c064f1 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -224,7 +224,7 @@ static void dev_watchdog(unsigned long arg)
224 char drivername[64]; 224 char drivername[64];
225 WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit timed out\n", 225 WARN_ONCE(1, KERN_INFO "NETDEV WATCHDOG: %s (%s): transmit timed out\n",
226 dev->name, netdev_drivername(dev, drivername, 64)); 226 dev->name, netdev_drivername(dev, drivername, 64));
227 dev->tx_timeout(dev); 227 dev->netdev_ops->ndo_tx_timeout(dev);
228 } 228 }
229 if (!mod_timer(&dev->watchdog_timer, 229 if (!mod_timer(&dev->watchdog_timer,
230 round_jiffies(jiffies + 230 round_jiffies(jiffies +
@@ -239,7 +239,7 @@ static void dev_watchdog(unsigned long arg)
239 239
240void __netdev_watchdog_up(struct net_device *dev) 240void __netdev_watchdog_up(struct net_device *dev)
241{ 241{
242 if (dev->tx_timeout) { 242 if (dev->netdev_ops->ndo_tx_timeout) {
243 if (dev->watchdog_timeo <= 0) 243 if (dev->watchdog_timeo <= 0)
244 dev->watchdog_timeo = 5*HZ; 244 dev->watchdog_timeo = 5*HZ;
245 if (!mod_timer(&dev->watchdog_timer, 245 if (!mod_timer(&dev->watchdog_timer,