diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2008-11-20 00:32:24 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-11-20 00:32:24 -0500 |
commit | d314774cf2cd5dfeb39a00d37deee65d4c627927 (patch) | |
tree | 1c7778b509cea814aa2b7115949667941037d07c /include/linux/netdevice.h | |
parent | 6b41e7dd90c6a628ab5fb8d781302d60a243b2ce (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>
Diffstat (limited to 'include/linux/netdevice.h')
-rw-r--r-- | include/linux/netdevice.h | 232 |
1 files changed, 168 insertions, 64 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 | */ | ||
536 | struct 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 | ||