aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/netdevice.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/netdevice.h')
-rw-r--r--include/linux/netdevice.h232
1 files changed, 159 insertions, 73 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 5a96a1a406e9..9ea8d6dfe540 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -39,9 +39,11 @@
39 39
40#include <linux/device.h> 40#include <linux/device.h>
41#include <linux/percpu.h> 41#include <linux/percpu.h>
42#include <linux/rculist.h>
42#include <linux/dmaengine.h> 43#include <linux/dmaengine.h>
43#include <linux/workqueue.h> 44#include <linux/workqueue.h>
44 45
46#include <linux/ethtool.h>
45#include <net/net_namespace.h> 47#include <net/net_namespace.h>
46#include <net/dsa.h> 48#include <net/dsa.h>
47#ifdef CONFIG_DCB 49#ifdef CONFIG_DCB
@@ -49,7 +51,6 @@
49#endif 51#endif
50 52
51struct vlan_group; 53struct vlan_group;
52struct ethtool_ops;
53struct netpoll_info; 54struct netpoll_info;
54/* 802.11 specific */ 55/* 802.11 specific */
55struct wireless_dev; 56struct wireless_dev;
@@ -210,6 +211,19 @@ struct dev_addr_list
210#define dmi_users da_users 211#define dmi_users da_users
211#define dmi_gusers da_gusers 212#define dmi_gusers da_gusers
212 213
214struct netdev_hw_addr {
215 struct list_head list;
216 unsigned char addr[MAX_ADDR_LEN];
217 unsigned char type;
218#define NETDEV_HW_ADDR_T_LAN 1
219#define NETDEV_HW_ADDR_T_SAN 2
220#define NETDEV_HW_ADDR_T_SLAVE 3
221#define NETDEV_HW_ADDR_T_UNICAST 4
222 int refcount;
223 bool synced;
224 struct rcu_head rcu_head;
225};
226
213struct hh_cache 227struct hh_cache
214{ 228{
215 struct hh_cache *hh_next; /* Next entry */ 229 struct hh_cache *hh_next; /* Next entry */
@@ -447,12 +461,25 @@ enum netdev_queue_state_t
447}; 461};
448 462
449struct netdev_queue { 463struct netdev_queue {
464/*
465 * read mostly part
466 */
450 struct net_device *dev; 467 struct net_device *dev;
451 struct Qdisc *qdisc; 468 struct Qdisc *qdisc;
452 unsigned long state; 469 unsigned long state;
453 spinlock_t _xmit_lock;
454 int xmit_lock_owner;
455 struct Qdisc *qdisc_sleeping; 470 struct Qdisc *qdisc_sleeping;
471/*
472 * write mostly part
473 */
474 spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
475 int xmit_lock_owner;
476 /*
477 * please use this field instead of dev->trans_start
478 */
479 unsigned long trans_start;
480 unsigned long tx_bytes;
481 unsigned long tx_packets;
482 unsigned long tx_dropped;
456} ____cacheline_aligned_in_smp; 483} ____cacheline_aligned_in_smp;
457 484
458 485
@@ -670,7 +697,9 @@ struct net_device
670#define NETIF_F_GRO 16384 /* Generic receive offload */ 697#define NETIF_F_GRO 16384 /* Generic receive offload */
671#define NETIF_F_LRO 32768 /* large receive offload */ 698#define NETIF_F_LRO 32768 /* large receive offload */
672 699
700/* the GSO_MASK reserves bits 16 through 23 */
673#define NETIF_F_FCOE_CRC (1 << 24) /* FCoE CRC32 */ 701#define NETIF_F_FCOE_CRC (1 << 24) /* FCoE CRC32 */
702#define NETIF_F_SCTP_CSUM (1 << 25) /* SCTP checksum offload */
674 703
675 /* Segmentation offload features */ 704 /* Segmentation offload features */
676#define NETIF_F_GSO_SHIFT 16 705#define NETIF_F_GSO_SHIFT 16
@@ -747,10 +776,11 @@ struct net_device
747 unsigned char addr_len; /* hardware address length */ 776 unsigned char addr_len; /* hardware address length */
748 unsigned short dev_id; /* for shared network cards */ 777 unsigned short dev_id; /* for shared network cards */
749 778
750 spinlock_t addr_list_lock; 779 struct list_head uc_list; /* Secondary unicast mac
751 struct dev_addr_list *uc_list; /* Secondary unicast mac addresses */ 780 addresses */
752 int uc_count; /* Number of installed ucasts */ 781 int uc_count; /* Number of installed ucasts */
753 int uc_promisc; 782 int uc_promisc;
783 spinlock_t addr_list_lock;
754 struct dev_addr_list *mc_list; /* Multicast mac addresses */ 784 struct dev_addr_list *mc_list; /* Multicast mac addresses */
755 int mc_count; /* Number of installed mcasts */ 785 int mc_count; /* Number of installed mcasts */
756 unsigned int promiscuity; 786 unsigned int promiscuity;
@@ -776,8 +806,11 @@ struct net_device
776 */ 806 */
777 unsigned long last_rx; /* Time of last Rx */ 807 unsigned long last_rx; /* Time of last Rx */
778 /* Interface address info used in eth_type_trans() */ 808 /* Interface address info used in eth_type_trans() */
779 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address, (before bcast 809 unsigned char *dev_addr; /* hw address, (before bcast
780 because most packets are unicast) */ 810 because most packets are
811 unicast) */
812
813 struct list_head dev_addr_list; /* list of device hw addresses */
781 814
782 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ 815 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
783 816
@@ -797,6 +830,11 @@ struct net_device
797 * One part is mostly used on xmit path (device) 830 * One part is mostly used on xmit path (device)
798 */ 831 */
799 /* These may be needed for future network-power-down code. */ 832 /* These may be needed for future network-power-down code. */
833
834 /*
835 * trans_start here is expensive for high speed devices on SMP,
836 * please use netdev_queue->trans_start instead.
837 */
800 unsigned long trans_start; /* Time (in jiffies) of last Tx */ 838 unsigned long trans_start; /* Time (in jiffies) of last Tx */
801 839
802 int watchdog_timeo; /* used by dev_watchdog() */ 840 int watchdog_timeo; /* used by dev_watchdog() */
@@ -867,49 +905,10 @@ struct net_device
867 /* max exchange id for FCoE LRO by ddp */ 905 /* max exchange id for FCoE LRO by ddp */
868 unsigned int fcoe_ddp_xid; 906 unsigned int fcoe_ddp_xid;
869#endif 907#endif
870
871#ifdef CONFIG_COMPAT_NET_DEV_OPS
872 struct {
873 int (*init)(struct net_device *dev);
874 void (*uninit)(struct net_device *dev);
875 int (*open)(struct net_device *dev);
876 int (*stop)(struct net_device *dev);
877 int (*hard_start_xmit) (struct sk_buff *skb,
878 struct net_device *dev);
879 u16 (*select_queue)(struct net_device *dev,
880 struct sk_buff *skb);
881 void (*change_rx_flags)(struct net_device *dev,
882 int flags);
883 void (*set_rx_mode)(struct net_device *dev);
884 void (*set_multicast_list)(struct net_device *dev);
885 int (*set_mac_address)(struct net_device *dev,
886 void *addr);
887 int (*validate_addr)(struct net_device *dev);
888 int (*do_ioctl)(struct net_device *dev,
889 struct ifreq *ifr, int cmd);
890 int (*set_config)(struct net_device *dev,
891 struct ifmap *map);
892 int (*change_mtu)(struct net_device *dev, int new_mtu);
893 int (*neigh_setup)(struct net_device *dev,
894 struct neigh_parms *);
895 void (*tx_timeout) (struct net_device *dev);
896 struct net_device_stats* (*get_stats)(struct net_device *dev);
897 void (*vlan_rx_register)(struct net_device *dev,
898 struct vlan_group *grp);
899 void (*vlan_rx_add_vid)(struct net_device *dev,
900 unsigned short vid);
901 void (*vlan_rx_kill_vid)(struct net_device *dev,
902 unsigned short vid);
903#ifdef CONFIG_NET_POLL_CONTROLLER
904 void (*poll_controller)(struct net_device *dev);
905#endif
906 };
907#endif
908}; 908};
909#define to_net_dev(d) container_of(d, struct net_device, dev) 909#define to_net_dev(d) container_of(d, struct net_device, dev)
910 910
911#define NETDEV_ALIGN 32 911#define NETDEV_ALIGN 32
912#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)
913 912
914static inline 913static inline
915struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev, 914struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
@@ -980,9 +979,7 @@ static inline bool netdev_uses_trailer_tags(struct net_device *dev)
980 */ 979 */
981static inline void *netdev_priv(const struct net_device *dev) 980static inline void *netdev_priv(const struct net_device *dev)
982{ 981{
983 return (char *)dev + ((sizeof(struct net_device) 982 return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
984 + NETDEV_ALIGN_CONST)
985 & ~NETDEV_ALIGN_CONST);
986} 983}
987 984
988/* Set the sysfs physical device reference for the network logical device 985/* Set the sysfs physical device reference for the network logical device
@@ -1012,6 +1009,12 @@ void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
1012void netif_napi_del(struct napi_struct *napi); 1009void netif_napi_del(struct napi_struct *napi);
1013 1010
1014struct napi_gro_cb { 1011struct napi_gro_cb {
1012 /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */
1013 void *frag0;
1014
1015 /* Length of frag0. */
1016 unsigned int frag0_len;
1017
1015 /* This indicates where we are processing relative to skb->data. */ 1018 /* This indicates where we are processing relative to skb->data. */
1016 int data_offset; 1019 int data_offset;
1017 1020
@@ -1047,14 +1050,6 @@ struct packet_type {
1047 struct list_head list; 1050 struct list_head list;
1048}; 1051};
1049 1052
1050struct napi_gro_fraginfo {
1051 skb_frag_t frags[MAX_SKB_FRAGS];
1052 unsigned int nr_frags;
1053 unsigned int ip_summed;
1054 unsigned int len;
1055 __wsum csum;
1056};
1057
1058#include <linux/interrupt.h> 1053#include <linux/interrupt.h>
1059#include <linux/notifier.h> 1054#include <linux/notifier.h>
1060 1055
@@ -1119,9 +1114,9 @@ extern int dev_restart(struct net_device *dev);
1119#ifdef CONFIG_NETPOLL_TRAP 1114#ifdef CONFIG_NETPOLL_TRAP
1120extern int netpoll_trap(void); 1115extern int netpoll_trap(void);
1121#endif 1116#endif
1122extern void *skb_gro_header(struct sk_buff *skb, unsigned int hlen);
1123extern int skb_gro_receive(struct sk_buff **head, 1117extern int skb_gro_receive(struct sk_buff **head,
1124 struct sk_buff *skb); 1118 struct sk_buff *skb);
1119extern void skb_gro_reset_offset(struct sk_buff *skb);
1125 1120
1126static inline unsigned int skb_gro_offset(const struct sk_buff *skb) 1121static inline unsigned int skb_gro_offset(const struct sk_buff *skb)
1127{ 1122{
@@ -1138,16 +1133,34 @@ static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len)
1138 NAPI_GRO_CB(skb)->data_offset += len; 1133 NAPI_GRO_CB(skb)->data_offset += len;
1139} 1134}
1140 1135
1141static inline void skb_gro_reset_offset(struct sk_buff *skb) 1136static inline void *skb_gro_header_fast(struct sk_buff *skb,
1137 unsigned int offset)
1142{ 1138{
1143 NAPI_GRO_CB(skb)->data_offset = 0; 1139 return NAPI_GRO_CB(skb)->frag0 + offset;
1140}
1141
1142static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen)
1143{
1144 return NAPI_GRO_CB(skb)->frag0_len < hlen;
1145}
1146
1147static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
1148 unsigned int offset)
1149{
1150 NAPI_GRO_CB(skb)->frag0 = NULL;
1151 NAPI_GRO_CB(skb)->frag0_len = 0;
1152 return pskb_may_pull(skb, hlen) ? skb->data + offset : NULL;
1144} 1153}
1145 1154
1146static inline void *skb_gro_mac_header(struct sk_buff *skb) 1155static inline void *skb_gro_mac_header(struct sk_buff *skb)
1147{ 1156{
1148 return skb_mac_header(skb) < skb->data ? skb_mac_header(skb) : 1157 return NAPI_GRO_CB(skb)->frag0 ?: skb_mac_header(skb);
1149 page_address(skb_shinfo(skb)->frags[0].page) + 1158}
1150 skb_shinfo(skb)->frags[0].page_offset; 1159
1160static inline void *skb_gro_network_header(struct sk_buff *skb)
1161{
1162 return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
1163 skb_network_offset(skb);
1151} 1164}
1152 1165
1153static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev, 1166static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
@@ -1442,12 +1455,18 @@ extern int napi_gro_receive(struct napi_struct *napi,
1442 struct sk_buff *skb); 1455 struct sk_buff *skb);
1443extern void napi_reuse_skb(struct napi_struct *napi, 1456extern void napi_reuse_skb(struct napi_struct *napi,
1444 struct sk_buff *skb); 1457 struct sk_buff *skb);
1445extern struct sk_buff * napi_fraginfo_skb(struct napi_struct *napi, 1458extern struct sk_buff * napi_get_frags(struct napi_struct *napi);
1446 struct napi_gro_fraginfo *info);
1447extern int napi_frags_finish(struct napi_struct *napi, 1459extern int napi_frags_finish(struct napi_struct *napi,
1448 struct sk_buff *skb, int ret); 1460 struct sk_buff *skb, int ret);
1449extern int napi_gro_frags(struct napi_struct *napi, 1461extern struct sk_buff * napi_frags_skb(struct napi_struct *napi);
1450 struct napi_gro_fraginfo *info); 1462extern int napi_gro_frags(struct napi_struct *napi);
1463
1464static inline void napi_free_frags(struct napi_struct *napi)
1465{
1466 kfree_skb(napi->skb);
1467 napi->skb = NULL;
1468}
1469
1451extern void netif_nit_deliver(struct sk_buff *skb); 1470extern void netif_nit_deliver(struct sk_buff *skb);
1452extern int dev_valid_name(const char *name); 1471extern int dev_valid_name(const char *name);
1453extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *); 1472extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *);
@@ -1514,6 +1533,8 @@ static inline int netif_carrier_ok(const struct net_device *dev)
1514 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state); 1533 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
1515} 1534}
1516 1535
1536extern unsigned long dev_trans_start(struct net_device *dev);
1537
1517extern void __netdev_watchdog_up(struct net_device *dev); 1538extern void __netdev_watchdog_up(struct net_device *dev);
1518 1539
1519extern void netif_carrier_on(struct net_device *dev); 1540extern void netif_carrier_on(struct net_device *dev);
@@ -1671,6 +1692,12 @@ static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
1671 spin_unlock_bh(&txq->_xmit_lock); 1692 spin_unlock_bh(&txq->_xmit_lock);
1672} 1693}
1673 1694
1695static inline void txq_trans_update(struct netdev_queue *txq)
1696{
1697 if (txq->xmit_lock_owner != -1)
1698 txq->trans_start = jiffies;
1699}
1700
1674/** 1701/**
1675 * netif_tx_lock - grab network device transmit lock 1702 * netif_tx_lock - grab network device transmit lock
1676 * @dev: network device 1703 * @dev: network device
@@ -1778,6 +1805,13 @@ static inline void netif_addr_unlock_bh(struct net_device *dev)
1778 spin_unlock_bh(&dev->addr_list_lock); 1805 spin_unlock_bh(&dev->addr_list_lock);
1779} 1806}
1780 1807
1808/*
1809 * dev_addr_list walker. Should be used only for read access. Call with
1810 * rcu_read_lock held.
1811 */
1812#define for_each_dev_addr(dev, ha) \
1813 list_for_each_entry_rcu(ha, &dev->dev_addr_list, list)
1814
1781/* These functions live elsewhere (drivers/net/net_init.c, but related) */ 1815/* These functions live elsewhere (drivers/net/net_init.c, but related) */
1782 1816
1783extern void ether_setup(struct net_device *dev); 1817extern void ether_setup(struct net_device *dev);
@@ -1790,11 +1824,24 @@ extern struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
1790 alloc_netdev_mq(sizeof_priv, name, setup, 1) 1824 alloc_netdev_mq(sizeof_priv, name, setup, 1)
1791extern int register_netdev(struct net_device *dev); 1825extern int register_netdev(struct net_device *dev);
1792extern void unregister_netdev(struct net_device *dev); 1826extern void unregister_netdev(struct net_device *dev);
1827
1828/* Functions used for device addresses handling */
1829extern int dev_addr_add(struct net_device *dev, unsigned char *addr,
1830 unsigned char addr_type);
1831extern int dev_addr_del(struct net_device *dev, unsigned char *addr,
1832 unsigned char addr_type);
1833extern int dev_addr_add_multiple(struct net_device *to_dev,
1834 struct net_device *from_dev,
1835 unsigned char addr_type);
1836extern int dev_addr_del_multiple(struct net_device *to_dev,
1837 struct net_device *from_dev,
1838 unsigned char addr_type);
1839
1793/* Functions used for secondary unicast and multicast support */ 1840/* Functions used for secondary unicast and multicast support */
1794extern void dev_set_rx_mode(struct net_device *dev); 1841extern void dev_set_rx_mode(struct net_device *dev);
1795extern void __dev_set_rx_mode(struct net_device *dev); 1842extern void __dev_set_rx_mode(struct net_device *dev);
1796extern int dev_unicast_delete(struct net_device *dev, void *addr, int alen); 1843extern int dev_unicast_delete(struct net_device *dev, void *addr);
1797extern int dev_unicast_add(struct net_device *dev, void *addr, int alen); 1844extern int dev_unicast_add(struct net_device *dev, void *addr);
1798extern int dev_unicast_sync(struct net_device *to, struct net_device *from); 1845extern int dev_unicast_sync(struct net_device *to, struct net_device *from);
1799extern void dev_unicast_unsync(struct net_device *to, struct net_device *from); 1846extern void dev_unicast_unsync(struct net_device *to, struct net_device *from);
1800extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all); 1847extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
@@ -1856,15 +1903,14 @@ static inline int net_gso_ok(int features, int gso_type)
1856 1903
1857static inline int skb_gso_ok(struct sk_buff *skb, int features) 1904static inline int skb_gso_ok(struct sk_buff *skb, int features)
1858{ 1905{
1859 return net_gso_ok(features, skb_shinfo(skb)->gso_type); 1906 return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
1907 (!skb_has_frags(skb) || (features & NETIF_F_FRAGLIST));
1860} 1908}
1861 1909
1862static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) 1910static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb)
1863{ 1911{
1864 return skb_is_gso(skb) && 1912 return skb_is_gso(skb) &&
1865 (!skb_gso_ok(skb, dev->features) || 1913 (!skb_gso_ok(skb, dev->features) ||
1866 (skb_shinfo(skb)->frag_list &&
1867 !(dev->features & NETIF_F_FRAGLIST)) ||
1868 unlikely(skb->ip_summed != CHECKSUM_PARTIAL)); 1914 unlikely(skb->ip_summed != CHECKSUM_PARTIAL));
1869} 1915}
1870 1916
@@ -1874,6 +1920,16 @@ static inline void netif_set_gso_max_size(struct net_device *dev,
1874 dev->gso_max_size = size; 1920 dev->gso_max_size = size;
1875} 1921}
1876 1922
1923static inline void skb_bond_set_mac_by_master(struct sk_buff *skb,
1924 struct net_device *master)
1925{
1926 if (skb->pkt_type == PACKET_HOST) {
1927 u16 *dest = (u16 *) eth_hdr(skb)->h_dest;
1928
1929 memcpy(dest, master->dev_addr, ETH_ALEN);
1930 }
1931}
1932
1877/* On bonding slaves other than the currently active slave, suppress 1933/* On bonding slaves other than the currently active slave, suppress
1878 * duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and 1934 * duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and
1879 * ARP on active-backup slaves with arp_validate enabled. 1935 * ARP on active-backup slaves with arp_validate enabled.
@@ -1887,6 +1943,14 @@ static inline int skb_bond_should_drop(struct sk_buff *skb)
1887 if (master->priv_flags & IFF_MASTER_ARPMON) 1943 if (master->priv_flags & IFF_MASTER_ARPMON)
1888 dev->last_rx = jiffies; 1944 dev->last_rx = jiffies;
1889 1945
1946 if ((master->priv_flags & IFF_MASTER_ALB) && master->br_port) {
1947 /* Do address unmangle. The local destination address
1948 * will be always the one master has. Provides the right
1949 * functionality in a bridge.
1950 */
1951 skb_bond_set_mac_by_master(skb, master);
1952 }
1953
1890 if (dev->priv_flags & IFF_SLAVE_INACTIVE) { 1954 if (dev->priv_flags & IFF_SLAVE_INACTIVE) {
1891 if ((dev->priv_flags & IFF_SLAVE_NEEDARP) && 1955 if ((dev->priv_flags & IFF_SLAVE_NEEDARP) &&
1892 skb->protocol == __cpu_to_be16(ETH_P_ARP)) 1956 skb->protocol == __cpu_to_be16(ETH_P_ARP))
@@ -1908,6 +1972,28 @@ static inline int skb_bond_should_drop(struct sk_buff *skb)
1908} 1972}
1909 1973
1910extern struct pernet_operations __net_initdata loopback_net_ops; 1974extern struct pernet_operations __net_initdata loopback_net_ops;
1975
1976static inline int dev_ethtool_get_settings(struct net_device *dev,
1977 struct ethtool_cmd *cmd)
1978{
1979 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
1980 return -EOPNOTSUPP;
1981 return dev->ethtool_ops->get_settings(dev, cmd);
1982}
1983
1984static inline u32 dev_ethtool_get_rx_csum(struct net_device *dev)
1985{
1986 if (!dev->ethtool_ops || !dev->ethtool_ops->get_rx_csum)
1987 return 0;
1988 return dev->ethtool_ops->get_rx_csum(dev);
1989}
1990
1991static inline u32 dev_ethtool_get_flags(struct net_device *dev)
1992{
1993 if (!dev->ethtool_ops || !dev->ethtool_ops->get_flags)
1994 return 0;
1995 return dev->ethtool_ops->get_flags(dev);
1996}
1911#endif /* __KERNEL__ */ 1997#endif /* __KERNEL__ */
1912 1998
1913#endif /* _LINUX_DEV_H */ 1999#endif /* _LINUX_NETDEVICE_H */