net/core/dev.c
changeset 2 d1f6d8b6f81c
parent 0 aa628870c1d3
equal deleted inserted replaced
1:0056487c491e 2:d1f6d8b6f81c
   106 #include <net/checksum.h>
   106 #include <net/checksum.h>
   107 #include <linux/highmem.h>
   107 #include <linux/highmem.h>
   108 #include <linux/init.h>
   108 #include <linux/init.h>
   109 #include <linux/kmod.h>
   109 #include <linux/kmod.h>
   110 #include <linux/module.h>
   110 #include <linux/module.h>
   111 #include <linux/kallsyms.h>
       
   112 #include <linux/netpoll.h>
   111 #include <linux/netpoll.h>
   113 #include <linux/rcupdate.h>
   112 #include <linux/rcupdate.h>
   114 #include <linux/delay.h>
   113 #include <linux/delay.h>
   115 #include <net/wext.h>
   114 #include <net/wext.h>
   116 #include <net/iw_handler.h>
   115 #include <net/iw_handler.h>
   128 #include <linux/jhash.h>
   127 #include <linux/jhash.h>
   129 #include <linux/random.h>
   128 #include <linux/random.h>
   130 
   129 
   131 #include "net-sysfs.h"
   130 #include "net-sysfs.h"
   132 
   131 
       
   132 /* Instead of increasing this, you should create a hash table. */
       
   133 #define MAX_GRO_SKBS 8
       
   134 
       
   135 /* This should be increased if a protocol with a bigger head is added. */
       
   136 #define GRO_MAX_HEAD (MAX_HEADER + 128)
       
   137 
   133 /*
   138 /*
   134  *	The list of packet types we will receive (as opposed to discard)
   139  *	The list of packet types we will receive (as opposed to discard)
   135  *	and the routines to invoke.
   140  *	and the routines to invoke.
   136  *
   141  *
   137  *	Why 16. Because with 16 the only overlap we get on a hash of the
   142  *	Why 16. Because with 16 the only overlap we get on a hash of the
   162 #define PTYPE_HASH_MASK	(PTYPE_HASH_SIZE - 1)
   167 #define PTYPE_HASH_MASK	(PTYPE_HASH_SIZE - 1)
   163 
   168 
   164 static DEFINE_SPINLOCK(ptype_lock);
   169 static DEFINE_SPINLOCK(ptype_lock);
   165 static struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
   170 static struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
   166 static struct list_head ptype_all __read_mostly;	/* Taps */
   171 static struct list_head ptype_all __read_mostly;	/* Taps */
   167 
       
   168 #ifdef CONFIG_NET_DMA
       
   169 struct net_dma {
       
   170 	struct dma_client client;
       
   171 	spinlock_t lock;
       
   172 	cpumask_t channel_mask;
       
   173 	struct dma_chan **channels;
       
   174 };
       
   175 
       
   176 static enum dma_state_client
       
   177 netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
       
   178 	enum dma_state state);
       
   179 
       
   180 static struct net_dma net_dma = {
       
   181 	.client = {
       
   182 		.event_callback = netdev_dma_event,
       
   183 	},
       
   184 };
       
   185 #endif
       
   186 
   172 
   187 /*
   173 /*
   188  * The @dev_base_head list is protected by @dev_base_lock and the rtnl
   174  * The @dev_base_head list is protected by @dev_base_lock and the rtnl
   189  * semaphore.
   175  * semaphore.
   190  *
   176  *
   279 	 ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI,
   265 	 ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI,
   280 	 ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE,
   266 	 ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE,
   281 	 ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET,
   267 	 ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET,
   282 	 ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL,
   268 	 ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL,
   283 	 ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211,
   269 	 ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211,
   284 	 ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_VOID,
   270 	 ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET,
   285 	 ARPHRD_NONE};
   271 	 ARPHRD_PHONET_PIPE, ARPHRD_VOID, ARPHRD_NONE};
   286 
   272 
   287 static const char *netdev_lock_name[] =
   273 static const char *netdev_lock_name[] =
   288 	{"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25",
   274 	{"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25",
   289 	 "_xmit_PRONET", "_xmit_CHAOS", "_xmit_IEEE802", "_xmit_ARCNET",
   275 	 "_xmit_PRONET", "_xmit_CHAOS", "_xmit_IEEE802", "_xmit_ARCNET",
   290 	 "_xmit_APPLETLK", "_xmit_DLCI", "_xmit_ATM", "_xmit_METRICOM",
   276 	 "_xmit_APPLETLK", "_xmit_DLCI", "_xmit_ATM", "_xmit_METRICOM",
   296 	 "_xmit_SKIP", "_xmit_LOOPBACK", "_xmit_LOCALTLK", "_xmit_FDDI",
   282 	 "_xmit_SKIP", "_xmit_LOOPBACK", "_xmit_LOCALTLK", "_xmit_FDDI",
   297 	 "_xmit_BIF", "_xmit_SIT", "_xmit_IPDDP", "_xmit_IPGRE",
   283 	 "_xmit_BIF", "_xmit_SIT", "_xmit_IPDDP", "_xmit_IPGRE",
   298 	 "_xmit_PIMREG", "_xmit_HIPPI", "_xmit_ASH", "_xmit_ECONET",
   284 	 "_xmit_PIMREG", "_xmit_HIPPI", "_xmit_ASH", "_xmit_ECONET",
   299 	 "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL",
   285 	 "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL",
   300 	 "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211",
   286 	 "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211",
   301 	 "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_VOID",
   287 	 "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_PHONET",
   302 	 "_xmit_NONE"};
   288 	 "_xmit_PHONET_PIPE", "_xmit_VOID", "_xmit_NONE"};
   303 
   289 
   304 static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
   290 static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
   305 static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)];
   291 static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)];
   306 
   292 
   307 static inline unsigned short netdev_lock_pos(unsigned short dev_type)
   293 static inline unsigned short netdev_lock_pos(unsigned short dev_type)
   922 		return -EEXIST;
   908 		return -EEXIST;
   923 	else
   909 	else
   924 		strlcpy(dev->name, newname, IFNAMSIZ);
   910 		strlcpy(dev->name, newname, IFNAMSIZ);
   925 
   911 
   926 rollback:
   912 rollback:
   927 	ret = device_rename(&dev->dev, dev->name);
   913 	/* For now only devices in the initial network namespace
   928 	if (ret) {
   914 	 * are in sysfs.
   929 		memcpy(dev->name, oldname, IFNAMSIZ);
   915 	 */
   930 		return ret;
   916 	if (net == &init_net) {
       
   917 		ret = device_rename(&dev->dev, dev->name);
       
   918 		if (ret) {
       
   919 			memcpy(dev->name, oldname, IFNAMSIZ);
       
   920 			return ret;
       
   921 		}
   931 	}
   922 	}
   932 
   923 
   933 	write_lock_bh(&dev_base_lock);
   924 	write_lock_bh(&dev_base_lock);
   934 	hlist_del(&dev->name_hlist);
   925 	hlist_del(&dev->name_hlist);
   935 	hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name));
   926 	hlist_add_head(&dev->name_hlist, dev_name_hash(net, dev->name));
  1053  *	Calling this function on an active interface is a nop. On a failure
  1044  *	Calling this function on an active interface is a nop. On a failure
  1054  *	a negative errno code is returned.
  1045  *	a negative errno code is returned.
  1055  */
  1046  */
  1056 int dev_open(struct net_device *dev)
  1047 int dev_open(struct net_device *dev)
  1057 {
  1048 {
       
  1049 	const struct net_device_ops *ops = dev->netdev_ops;
  1058 	int ret = 0;
  1050 	int ret = 0;
  1059 
  1051 
  1060 	ASSERT_RTNL();
  1052 	ASSERT_RTNL();
  1061 
  1053 
  1062 	/*
  1054 	/*
  1075 	/*
  1067 	/*
  1076 	 *	Call device private open method
  1068 	 *	Call device private open method
  1077 	 */
  1069 	 */
  1078 	set_bit(__LINK_STATE_START, &dev->state);
  1070 	set_bit(__LINK_STATE_START, &dev->state);
  1079 
  1071 
  1080 	if (dev->validate_addr)
  1072 	if (ops->ndo_validate_addr)
  1081 		ret = dev->validate_addr(dev);
  1073 		ret = ops->ndo_validate_addr(dev);
  1082 
  1074 
  1083 	if (!ret && dev->open)
  1075 	if (!ret && ops->ndo_open)
  1084 		ret = dev->open(dev);
  1076 		ret = ops->ndo_open(dev);
  1085 
  1077 
  1086 	/*
  1078 	/*
  1087 	 *	If it went open OK then:
  1079 	 *	If it went open OK then:
  1088 	 */
  1080 	 */
  1089 
  1081 
  1094 		 *	Set the flags.
  1086 		 *	Set the flags.
  1095 		 */
  1087 		 */
  1096 		dev->flags |= IFF_UP;
  1088 		dev->flags |= IFF_UP;
  1097 
  1089 
  1098 		/*
  1090 		/*
       
  1091 		 *	Enable NET_DMA
       
  1092 		 */
       
  1093 		net_dmaengine_get();
       
  1094 
       
  1095 		/*
  1099 		 *	Initialize multicasting status
  1096 		 *	Initialize multicasting status
  1100 		 */
  1097 		 */
  1101 		dev_set_rx_mode(dev);
  1098 		dev_set_rx_mode(dev);
  1102 
  1099 
  1103 		/*
  1100 		/*
  1123  *	is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
  1120  *	is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
  1124  *	chain.
  1121  *	chain.
  1125  */
  1122  */
  1126 int dev_close(struct net_device *dev)
  1123 int dev_close(struct net_device *dev)
  1127 {
  1124 {
       
  1125 	const struct net_device_ops *ops = dev->netdev_ops;
  1128 	ASSERT_RTNL();
  1126 	ASSERT_RTNL();
  1129 
  1127 
  1130 	might_sleep();
  1128 	might_sleep();
  1131 
  1129 
  1132 	if (!(dev->flags & IFF_UP))
  1130 	if (!(dev->flags & IFF_UP))
  1155 	 *	Only if device is UP
  1153 	 *	Only if device is UP
  1156 	 *
  1154 	 *
  1157 	 *	We allow it to be called even after a DETACH hot-plug
  1155 	 *	We allow it to be called even after a DETACH hot-plug
  1158 	 *	event.
  1156 	 *	event.
  1159 	 */
  1157 	 */
  1160 	if (dev->stop)
  1158 	if (ops->ndo_stop)
  1161 		dev->stop(dev);
  1159 		ops->ndo_stop(dev);
  1162 
  1160 
  1163 	/*
  1161 	/*
  1164 	 *	Device is now down.
  1162 	 *	Device is now down.
  1165 	 */
  1163 	 */
  1166 
  1164 
  1168 
  1166 
  1169 	/*
  1167 	/*
  1170 	 * Tell people we are down
  1168 	 * Tell people we are down
  1171 	 */
  1169 	 */
  1172 	call_netdevice_notifiers(NETDEV_DOWN, dev);
  1170 	call_netdevice_notifiers(NETDEV_DOWN, dev);
       
  1171 
       
  1172 	/*
       
  1173 	 *	Shutdown NET_DMA
       
  1174 	 */
       
  1175 	net_dmaengine_put();
  1173 
  1176 
  1174 	return 0;
  1177 	return 0;
  1175 }
  1178 }
  1176 
  1179 
  1177 
  1180 
  1525 	struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT);
  1528 	struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT);
  1526 	struct packet_type *ptype;
  1529 	struct packet_type *ptype;
  1527 	__be16 type = skb->protocol;
  1530 	__be16 type = skb->protocol;
  1528 	int err;
  1531 	int err;
  1529 
  1532 
  1530 	BUG_ON(skb_shinfo(skb)->frag_list);
       
  1531 
       
  1532 	skb_reset_mac_header(skb);
  1533 	skb_reset_mac_header(skb);
  1533 	skb->mac_len = skb->network_header - skb->mac_header;
  1534 	skb->mac_len = skb->network_header - skb->mac_header;
  1534 	__skb_pull(skb, skb->mac_len);
  1535 	__skb_pull(skb, skb->mac_len);
  1535 
  1536 
  1536 	if (WARN_ON(skb->ip_summed != CHECKSUM_PARTIAL)) {
  1537 	if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
       
  1538 		struct net_device *dev = skb->dev;
       
  1539 		struct ethtool_drvinfo info = {};
       
  1540 
       
  1541 		if (dev && dev->ethtool_ops && dev->ethtool_ops->get_drvinfo)
       
  1542 			dev->ethtool_ops->get_drvinfo(dev, &info);
       
  1543 
       
  1544 		WARN(1, "%s: caps=(0x%lx, 0x%lx) len=%d data_len=%d "
       
  1545 			"ip_summed=%d",
       
  1546 		     info.driver, dev ? dev->features : 0L,
       
  1547 		     skb->sk ? skb->sk->sk_route_caps : 0L,
       
  1548 		     skb->len, skb->data_len, skb->ip_summed);
       
  1549 
  1537 		if (skb_header_cloned(skb) &&
  1550 		if (skb_header_cloned(skb) &&
  1538 		    (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
  1551 		    (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC)))
  1539 			return ERR_PTR(err);
  1552 			return ERR_PTR(err);
  1540 	}
  1553 	}
  1541 
  1554 
  1652 }
  1665 }
  1653 
  1666 
  1654 int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
  1667 int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
  1655 			struct netdev_queue *txq)
  1668 			struct netdev_queue *txq)
  1656 {
  1669 {
       
  1670 	const struct net_device_ops *ops = dev->netdev_ops;
       
  1671 
       
  1672 	prefetch(&dev->netdev_ops->ndo_start_xmit);
  1657 	if (likely(!skb->next)) {
  1673 	if (likely(!skb->next)) {
  1658 		if (!list_empty(&ptype_all))
  1674 		if (!list_empty(&ptype_all))
  1659 			dev_queue_xmit_nit(skb, dev);
  1675 			dev_queue_xmit_nit(skb, dev);
  1660 
  1676 
  1661 		if (netif_needs_gso(dev, skb)) {
  1677 		if (netif_needs_gso(dev, skb)) {
  1663 				goto out_kfree_skb;
  1679 				goto out_kfree_skb;
  1664 			if (skb->next)
  1680 			if (skb->next)
  1665 				goto gso;
  1681 				goto gso;
  1666 		}
  1682 		}
  1667 
  1683 
  1668 		return dev->hard_start_xmit(skb, dev);
  1684 		return ops->ndo_start_xmit(skb, dev);
  1669 	}
  1685 	}
  1670 
  1686 
  1671 gso:
  1687 gso:
  1672 	do {
  1688 	do {
  1673 		struct sk_buff *nskb = skb->next;
  1689 		struct sk_buff *nskb = skb->next;
  1674 		int rc;
  1690 		int rc;
  1675 
  1691 
  1676 		skb->next = nskb->next;
  1692 		skb->next = nskb->next;
  1677 		nskb->next = NULL;
  1693 		nskb->next = NULL;
  1678 		rc = dev->hard_start_xmit(nskb, dev);
  1694 		rc = ops->ndo_start_xmit(nskb, dev);
  1679 		if (unlikely(rc)) {
  1695 		if (unlikely(rc)) {
  1680 			nskb->next = skb->next;
  1696 			nskb->next = skb->next;
  1681 			skb->next = nskb;
  1697 			skb->next = nskb;
  1682 			return rc;
  1698 			return rc;
  1683 		}
  1699 		}
  1747 }
  1763 }
  1748 
  1764 
  1749 static struct netdev_queue *dev_pick_tx(struct net_device *dev,
  1765 static struct netdev_queue *dev_pick_tx(struct net_device *dev,
  1750 					struct sk_buff *skb)
  1766 					struct sk_buff *skb)
  1751 {
  1767 {
       
  1768 	const struct net_device_ops *ops = dev->netdev_ops;
  1752 	u16 queue_index = 0;
  1769 	u16 queue_index = 0;
  1753 
  1770 
  1754 	if (dev->select_queue)
  1771 	if (ops->ndo_select_queue)
  1755 		queue_index = dev->select_queue(dev, skb);
  1772 		queue_index = ops->ndo_select_queue(dev, skb);
  1756 	else if (dev->real_num_tx_queues > 1)
  1773 	else if (dev->real_num_tx_queues > 1)
  1757 		queue_index = simple_tx_hash(dev, skb);
  1774 		queue_index = simple_tx_hash(dev, skb);
  1758 
  1775 
  1759 	skb_set_queue_mapping(skb, queue_index);
  1776 	skb_set_queue_mapping(skb, queue_index);
  1760 	return netdev_get_tx_queue(dev, queue_index);
  1777 	return netdev_get_tx_queue(dev, queue_index);
  2248 
  2265 
  2249 	pt_prev = NULL;
  2266 	pt_prev = NULL;
  2250 
  2267 
  2251 	rcu_read_lock();
  2268 	rcu_read_lock();
  2252 
  2269 
  2253 	/* Don't receive packets in an exiting network namespace */
       
  2254 	if (!net_alive(dev_net(skb->dev)))
       
  2255 		goto out;
       
  2256 
       
  2257 #ifdef CONFIG_NET_CLS_ACT
  2270 #ifdef CONFIG_NET_CLS_ACT
  2258 	if (skb->tc_verd & TC_NCLS) {
  2271 	if (skb->tc_verd & TC_NCLS) {
  2259 		skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
  2272 		skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
  2260 		goto ncls;
  2273 		goto ncls;
  2261 	}
  2274 	}
  2323 			__skb_unlink(skb, &queue->input_pkt_queue);
  2336 			__skb_unlink(skb, &queue->input_pkt_queue);
  2324 			kfree_skb(skb);
  2337 			kfree_skb(skb);
  2325 		}
  2338 		}
  2326 }
  2339 }
  2327 
  2340 
       
  2341 static int napi_gro_complete(struct sk_buff *skb)
       
  2342 {
       
  2343 	struct packet_type *ptype;
       
  2344 	__be16 type = skb->protocol;
       
  2345 	struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK];
       
  2346 	int err = -ENOENT;
       
  2347 
       
  2348 	if (NAPI_GRO_CB(skb)->count == 1)
       
  2349 		goto out;
       
  2350 
       
  2351 	rcu_read_lock();
       
  2352 	list_for_each_entry_rcu(ptype, head, list) {
       
  2353 		if (ptype->type != type || ptype->dev || !ptype->gro_complete)
       
  2354 			continue;
       
  2355 
       
  2356 		err = ptype->gro_complete(skb);
       
  2357 		break;
       
  2358 	}
       
  2359 	rcu_read_unlock();
       
  2360 
       
  2361 	if (err) {
       
  2362 		WARN_ON(&ptype->list == head);
       
  2363 		kfree_skb(skb);
       
  2364 		return NET_RX_SUCCESS;
       
  2365 	}
       
  2366 
       
  2367 out:
       
  2368 	skb_shinfo(skb)->gso_size = 0;
       
  2369 	__skb_push(skb, -skb_network_offset(skb));
       
  2370 	return netif_receive_skb(skb);
       
  2371 }
       
  2372 
       
  2373 void napi_gro_flush(struct napi_struct *napi)
       
  2374 {
       
  2375 	struct sk_buff *skb, *next;
       
  2376 
       
  2377 	for (skb = napi->gro_list; skb; skb = next) {
       
  2378 		next = skb->next;
       
  2379 		skb->next = NULL;
       
  2380 		napi_gro_complete(skb);
       
  2381 	}
       
  2382 
       
  2383 	napi->gro_list = NULL;
       
  2384 }
       
  2385 EXPORT_SYMBOL(napi_gro_flush);
       
  2386 
       
  2387 int dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
       
  2388 {
       
  2389 	struct sk_buff **pp = NULL;
       
  2390 	struct packet_type *ptype;
       
  2391 	__be16 type = skb->protocol;
       
  2392 	struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK];
       
  2393 	int count = 0;
       
  2394 	int same_flow;
       
  2395 	int mac_len;
       
  2396 	int free;
       
  2397 
       
  2398 	if (!(skb->dev->features & NETIF_F_GRO))
       
  2399 		goto normal;
       
  2400 
       
  2401 	if (skb_is_gso(skb) || skb_shinfo(skb)->frag_list)
       
  2402 		goto normal;
       
  2403 
       
  2404 	rcu_read_lock();
       
  2405 	list_for_each_entry_rcu(ptype, head, list) {
       
  2406 		struct sk_buff *p;
       
  2407 
       
  2408 		if (ptype->type != type || ptype->dev || !ptype->gro_receive)
       
  2409 			continue;
       
  2410 
       
  2411 		skb_reset_network_header(skb);
       
  2412 		mac_len = skb->network_header - skb->mac_header;
       
  2413 		skb->mac_len = mac_len;
       
  2414 		NAPI_GRO_CB(skb)->same_flow = 0;
       
  2415 		NAPI_GRO_CB(skb)->flush = 0;
       
  2416 		NAPI_GRO_CB(skb)->free = 0;
       
  2417 
       
  2418 		for (p = napi->gro_list; p; p = p->next) {
       
  2419 			count++;
       
  2420 
       
  2421 			if (!NAPI_GRO_CB(p)->same_flow)
       
  2422 				continue;
       
  2423 
       
  2424 			if (p->mac_len != mac_len ||
       
  2425 			    memcmp(skb_mac_header(p), skb_mac_header(skb),
       
  2426 				   mac_len))
       
  2427 				NAPI_GRO_CB(p)->same_flow = 0;
       
  2428 		}
       
  2429 
       
  2430 		pp = ptype->gro_receive(&napi->gro_list, skb);
       
  2431 		break;
       
  2432 	}
       
  2433 	rcu_read_unlock();
       
  2434 
       
  2435 	if (&ptype->list == head)
       
  2436 		goto normal;
       
  2437 
       
  2438 	same_flow = NAPI_GRO_CB(skb)->same_flow;
       
  2439 	free = NAPI_GRO_CB(skb)->free;
       
  2440 
       
  2441 	if (pp) {
       
  2442 		struct sk_buff *nskb = *pp;
       
  2443 
       
  2444 		*pp = nskb->next;
       
  2445 		nskb->next = NULL;
       
  2446 		napi_gro_complete(nskb);
       
  2447 		count--;
       
  2448 	}
       
  2449 
       
  2450 	if (same_flow)
       
  2451 		goto ok;
       
  2452 
       
  2453 	if (NAPI_GRO_CB(skb)->flush || count >= MAX_GRO_SKBS) {
       
  2454 		__skb_push(skb, -skb_network_offset(skb));
       
  2455 		goto normal;
       
  2456 	}
       
  2457 
       
  2458 	NAPI_GRO_CB(skb)->count = 1;
       
  2459 	skb_shinfo(skb)->gso_size = skb->len;
       
  2460 	skb->next = napi->gro_list;
       
  2461 	napi->gro_list = skb;
       
  2462 
       
  2463 ok:
       
  2464 	return free;
       
  2465 
       
  2466 normal:
       
  2467 	return -1;
       
  2468 }
       
  2469 EXPORT_SYMBOL(dev_gro_receive);
       
  2470 
       
  2471 static int __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
       
  2472 {
       
  2473 	struct sk_buff *p;
       
  2474 
       
  2475 	for (p = napi->gro_list; p; p = p->next) {
       
  2476 		NAPI_GRO_CB(p)->same_flow = 1;
       
  2477 		NAPI_GRO_CB(p)->flush = 0;
       
  2478 	}
       
  2479 
       
  2480 	return dev_gro_receive(napi, skb);
       
  2481 }
       
  2482 
       
  2483 int napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
       
  2484 {
       
  2485 	if (netpoll_receive_skb(skb))
       
  2486 		return NET_RX_DROP;
       
  2487 
       
  2488 	switch (__napi_gro_receive(napi, skb)) {
       
  2489 	case -1:
       
  2490 		return netif_receive_skb(skb);
       
  2491 
       
  2492 	case 1:
       
  2493 		kfree_skb(skb);
       
  2494 		break;
       
  2495 	}
       
  2496 
       
  2497 	return NET_RX_SUCCESS;
       
  2498 }
       
  2499 EXPORT_SYMBOL(napi_gro_receive);
       
  2500 
       
  2501 void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
       
  2502 {
       
  2503 	__skb_pull(skb, skb_headlen(skb));
       
  2504 	skb_reserve(skb, NET_IP_ALIGN - skb_headroom(skb));
       
  2505 
       
  2506 	napi->skb = skb;
       
  2507 }
       
  2508 EXPORT_SYMBOL(napi_reuse_skb);
       
  2509 
       
  2510 struct sk_buff *napi_fraginfo_skb(struct napi_struct *napi,
       
  2511 				  struct napi_gro_fraginfo *info)
       
  2512 {
       
  2513 	struct net_device *dev = napi->dev;
       
  2514 	struct sk_buff *skb = napi->skb;
       
  2515 
       
  2516 	napi->skb = NULL;
       
  2517 
       
  2518 	if (!skb) {
       
  2519 		skb = netdev_alloc_skb(dev, GRO_MAX_HEAD + NET_IP_ALIGN);
       
  2520 		if (!skb)
       
  2521 			goto out;
       
  2522 
       
  2523 		skb_reserve(skb, NET_IP_ALIGN);
       
  2524 	}
       
  2525 
       
  2526 	BUG_ON(info->nr_frags > MAX_SKB_FRAGS);
       
  2527 	skb_shinfo(skb)->nr_frags = info->nr_frags;
       
  2528 	memcpy(skb_shinfo(skb)->frags, info->frags, sizeof(info->frags));
       
  2529 
       
  2530 	skb->data_len = info->len;
       
  2531 	skb->len += info->len;
       
  2532 	skb->truesize += info->len;
       
  2533 
       
  2534 	if (!pskb_may_pull(skb, ETH_HLEN)) {
       
  2535 		napi_reuse_skb(napi, skb);
       
  2536 		skb = NULL;
       
  2537 		goto out;
       
  2538 	}
       
  2539 
       
  2540 	skb->protocol = eth_type_trans(skb, dev);
       
  2541 
       
  2542 	skb->ip_summed = info->ip_summed;
       
  2543 	skb->csum = info->csum;
       
  2544 
       
  2545 out:
       
  2546 	return skb;
       
  2547 }
       
  2548 EXPORT_SYMBOL(napi_fraginfo_skb);
       
  2549 
       
  2550 int napi_gro_frags(struct napi_struct *napi, struct napi_gro_fraginfo *info)
       
  2551 {
       
  2552 	struct sk_buff *skb = napi_fraginfo_skb(napi, info);
       
  2553 	int err = NET_RX_DROP;
       
  2554 
       
  2555 	if (!skb)
       
  2556 		goto out;
       
  2557 
       
  2558 	if (netpoll_receive_skb(skb))
       
  2559 		goto out;
       
  2560 
       
  2561 	err = NET_RX_SUCCESS;
       
  2562 
       
  2563 	switch (__napi_gro_receive(napi, skb)) {
       
  2564 	case -1:
       
  2565 		return netif_receive_skb(skb);
       
  2566 
       
  2567 	case 0:
       
  2568 		goto out;
       
  2569 	}
       
  2570 
       
  2571 	napi_reuse_skb(napi, skb);
       
  2572 
       
  2573 out:
       
  2574 	return err;
       
  2575 }
       
  2576 EXPORT_SYMBOL(napi_gro_frags);
       
  2577 
  2328 static int process_backlog(struct napi_struct *napi, int quota)
  2578 static int process_backlog(struct napi_struct *napi, int quota)
  2329 {
  2579 {
  2330 	int work = 0;
  2580 	int work = 0;
  2331 	struct softnet_data *queue = &__get_cpu_var(softnet_data);
  2581 	struct softnet_data *queue = &__get_cpu_var(softnet_data);
  2332 	unsigned long start_time = jiffies;
  2582 	unsigned long start_time = jiffies;
  2342 			local_irq_enable();
  2592 			local_irq_enable();
  2343 			break;
  2593 			break;
  2344 		}
  2594 		}
  2345 		local_irq_enable();
  2595 		local_irq_enable();
  2346 
  2596 
  2347 		netif_receive_skb(skb);
  2597 		napi_gro_receive(napi, skb);
  2348 	} while (++work < quota && jiffies == start_time);
  2598 	} while (++work < quota && jiffies == start_time);
       
  2599 
       
  2600 	napi_gro_flush(napi);
  2349 
  2601 
  2350 	return work;
  2602 	return work;
  2351 }
  2603 }
  2352 
  2604 
  2353 /**
  2605 /**
  2365 	__raise_softirq_irqoff(NET_RX_SOFTIRQ);
  2617 	__raise_softirq_irqoff(NET_RX_SOFTIRQ);
  2366 	local_irq_restore(flags);
  2618 	local_irq_restore(flags);
  2367 }
  2619 }
  2368 EXPORT_SYMBOL(__napi_schedule);
  2620 EXPORT_SYMBOL(__napi_schedule);
  2369 
  2621 
       
  2622 void __napi_complete(struct napi_struct *n)
       
  2623 {
       
  2624 	BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
       
  2625 	BUG_ON(n->gro_list);
       
  2626 
       
  2627 	list_del(&n->poll_list);
       
  2628 	smp_mb__before_clear_bit();
       
  2629 	clear_bit(NAPI_STATE_SCHED, &n->state);
       
  2630 }
       
  2631 EXPORT_SYMBOL(__napi_complete);
       
  2632 
       
  2633 void napi_complete(struct napi_struct *n)
       
  2634 {
       
  2635 	unsigned long flags;
       
  2636 
       
  2637 	/*
       
  2638 	 * don't let napi dequeue from the cpu poll list
       
  2639 	 * just in case its running on a different cpu
       
  2640 	 */
       
  2641 	if (unlikely(test_bit(NAPI_STATE_NPSVC, &n->state)))
       
  2642 		return;
       
  2643 
       
  2644 	napi_gro_flush(n);
       
  2645 	local_irq_save(flags);
       
  2646 	__napi_complete(n);
       
  2647 	local_irq_restore(flags);
       
  2648 }
       
  2649 EXPORT_SYMBOL(napi_complete);
       
  2650 
       
  2651 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
       
  2652 		    int (*poll)(struct napi_struct *, int), int weight)
       
  2653 {
       
  2654 	INIT_LIST_HEAD(&napi->poll_list);
       
  2655 	napi->gro_list = NULL;
       
  2656 	napi->skb = NULL;
       
  2657 	napi->poll = poll;
       
  2658 	napi->weight = weight;
       
  2659 	list_add(&napi->dev_list, &dev->napi_list);
       
  2660 	napi->dev = dev;
       
  2661 #ifdef CONFIG_NETPOLL
       
  2662 	spin_lock_init(&napi->poll_lock);
       
  2663 	napi->poll_owner = -1;
       
  2664 #endif
       
  2665 	set_bit(NAPI_STATE_SCHED, &napi->state);
       
  2666 }
       
  2667 EXPORT_SYMBOL(netif_napi_add);
       
  2668 
       
  2669 void netif_napi_del(struct napi_struct *napi)
       
  2670 {
       
  2671 	struct sk_buff *skb, *next;
       
  2672 
       
  2673 	list_del_init(&napi->dev_list);
       
  2674 	kfree(napi->skb);
       
  2675 
       
  2676 	for (skb = napi->gro_list; skb; skb = next) {
       
  2677 		next = skb->next;
       
  2678 		skb->next = NULL;
       
  2679 		kfree_skb(skb);
       
  2680 	}
       
  2681 
       
  2682 	napi->gro_list = NULL;
       
  2683 }
       
  2684 EXPORT_SYMBOL(netif_napi_del);
       
  2685 
  2370 
  2686 
  2371 static void net_rx_action(struct softirq_action *h)
  2687 static void net_rx_action(struct softirq_action *h)
  2372 {
  2688 {
  2373 	struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
  2689 	struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
  2374 	unsigned long start_time = jiffies;
  2690 	unsigned long time_limit = jiffies + 2;
  2375 	int budget = netdev_budget;
  2691 	int budget = netdev_budget;
  2376 	void *have;
  2692 	void *have;
  2377 
  2693 
  2378 	local_irq_disable();
  2694 	local_irq_disable();
  2379 
  2695 
  2380 	while (!list_empty(list)) {
  2696 	while (!list_empty(list)) {
  2381 		struct napi_struct *n;
  2697 		struct napi_struct *n;
  2382 		int work, weight;
  2698 		int work, weight;
  2383 
  2699 
  2384 		/* If softirq window is exhuasted then punt.
  2700 		/* If softirq window is exhuasted then punt.
  2385 		 *
  2701 		 * Allow this to run for 2 jiffies since which will allow
  2386 		 * Note that this is a slight policy change from the
  2702 		 * an average latency of 1.5/HZ.
  2387 		 * previous NAPI code, which would allow up to 2
       
  2388 		 * jiffies to pass before breaking out.  The test
       
  2389 		 * used to be "jiffies - start_time > 1".
       
  2390 		 */
  2703 		 */
  2391 		if (unlikely(budget <= 0 || jiffies != start_time))
  2704 		if (unlikely(budget <= 0 || time_after(jiffies, time_limit)))
  2392 			goto softnet_break;
  2705 			goto softnet_break;
  2393 
  2706 
  2394 		local_irq_enable();
  2707 		local_irq_enable();
  2395 
  2708 
  2396 		/* Even though interrupts have been re-enabled, this
  2709 		/* Even though interrupts have been re-enabled, this
  2440 #ifdef CONFIG_NET_DMA
  2753 #ifdef CONFIG_NET_DMA
  2441 	/*
  2754 	/*
  2442 	 * There may not be any more sk_buffs coming right now, so push
  2755 	 * There may not be any more sk_buffs coming right now, so push
  2443 	 * any pending DMA copies to hardware
  2756 	 * any pending DMA copies to hardware
  2444 	 */
  2757 	 */
  2445 	if (!cpus_empty(net_dma.channel_mask)) {
  2758 	dma_issue_pending_all();
  2446 		int chan_idx;
       
  2447 		for_each_cpu_mask_nr(chan_idx, net_dma.channel_mask) {
       
  2448 			struct dma_chan *chan = net_dma.channels[chan_idx];
       
  2449 			if (chan)
       
  2450 				dma_async_memcpy_issue_pending(chan);
       
  2451 		}
       
  2452 	}
       
  2453 #endif
  2759 #endif
  2454 
  2760 
  2455 	return;
  2761 	return;
  2456 
  2762 
  2457 softnet_break:
  2763 softnet_break:
  2613 	read_unlock(&dev_base_lock);
  2919 	read_unlock(&dev_base_lock);
  2614 }
  2920 }
  2615 
  2921 
  2616 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
  2922 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
  2617 {
  2923 {
  2618 	struct net_device_stats *stats = dev->get_stats(dev);
  2924 	const struct net_device_stats *stats = dev_get_stats(dev);
  2619 
  2925 
  2620 	seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
  2926 	seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
  2621 		   "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
  2927 		   "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
  2622 		   dev->name, stats->rx_bytes, stats->rx_packets,
  2928 		   dev->name, stats->rx_bytes, stats->rx_packets,
  2623 		   stats->rx_errors,
  2929 		   stats->rx_errors,
  2795 	__releases(RCU)
  3101 	__releases(RCU)
  2796 {
  3102 {
  2797 	rcu_read_unlock();
  3103 	rcu_read_unlock();
  2798 }
  3104 }
  2799 
  3105 
  2800 static void ptype_seq_decode(struct seq_file *seq, void *sym)
       
  2801 {
       
  2802 #ifdef CONFIG_KALLSYMS
       
  2803 	unsigned long offset = 0, symsize;
       
  2804 	const char *symname;
       
  2805 	char *modname;
       
  2806 	char namebuf[128];
       
  2807 
       
  2808 	symname = kallsyms_lookup((unsigned long)sym, &symsize, &offset,
       
  2809 				  &modname, namebuf);
       
  2810 
       
  2811 	if (symname) {
       
  2812 		char *delim = ":";
       
  2813 
       
  2814 		if (!modname)
       
  2815 			modname = delim = "";
       
  2816 		seq_printf(seq, "%s%s%s%s+0x%lx", delim, modname, delim,
       
  2817 			   symname, offset);
       
  2818 		return;
       
  2819 	}
       
  2820 #endif
       
  2821 
       
  2822 	seq_printf(seq, "[%p]", sym);
       
  2823 }
       
  2824 
       
  2825 static int ptype_seq_show(struct seq_file *seq, void *v)
  3106 static int ptype_seq_show(struct seq_file *seq, void *v)
  2826 {
  3107 {
  2827 	struct packet_type *pt = v;
  3108 	struct packet_type *pt = v;
  2828 
  3109 
  2829 	if (v == SEQ_START_TOKEN)
  3110 	if (v == SEQ_START_TOKEN)
  2832 		if (pt->type == htons(ETH_P_ALL))
  3113 		if (pt->type == htons(ETH_P_ALL))
  2833 			seq_puts(seq, "ALL ");
  3114 			seq_puts(seq, "ALL ");
  2834 		else
  3115 		else
  2835 			seq_printf(seq, "%04x", ntohs(pt->type));
  3116 			seq_printf(seq, "%04x", ntohs(pt->type));
  2836 
  3117 
  2837 		seq_printf(seq, " %-8s ",
  3118 		seq_printf(seq, " %-8s %pF\n",
  2838 			   pt->dev ? pt->dev->name : "");
  3119 			   pt->dev ? pt->dev->name : "", pt->func);
  2839 		ptype_seq_decode(seq,  pt->func);
       
  2840 		seq_putc(seq, '\n');
       
  2841 	}
  3120 	}
  2842 
  3121 
  2843 	return 0;
  3122 	return 0;
  2844 }
  3123 }
  2845 
  3124 
  2952 	return 0;
  3231 	return 0;
  2953 }
  3232 }
  2954 
  3233 
  2955 static void dev_change_rx_flags(struct net_device *dev, int flags)
  3234 static void dev_change_rx_flags(struct net_device *dev, int flags)
  2956 {
  3235 {
  2957 	if (dev->flags & IFF_UP && dev->change_rx_flags)
  3236 	const struct net_device_ops *ops = dev->netdev_ops;
  2958 		dev->change_rx_flags(dev, flags);
  3237 
       
  3238 	if ((dev->flags & IFF_UP) && ops->ndo_change_rx_flags)
       
  3239 		ops->ndo_change_rx_flags(dev, flags);
  2959 }
  3240 }
  2960 
  3241 
  2961 static int __dev_set_promiscuity(struct net_device *dev, int inc)
  3242 static int __dev_set_promiscuity(struct net_device *dev, int inc)
  2962 {
  3243 {
  2963 	unsigned short old_flags = dev->flags;
  3244 	unsigned short old_flags = dev->flags;
       
  3245 	uid_t uid;
       
  3246 	gid_t gid;
  2964 
  3247 
  2965 	ASSERT_RTNL();
  3248 	ASSERT_RTNL();
  2966 
  3249 
  2967 	dev->flags |= IFF_PROMISC;
  3250 	dev->flags |= IFF_PROMISC;
  2968 	dev->promiscuity += inc;
  3251 	dev->promiscuity += inc;
  2983 	}
  3266 	}
  2984 	if (dev->flags != old_flags) {
  3267 	if (dev->flags != old_flags) {
  2985 		printk(KERN_INFO "device %s %s promiscuous mode\n",
  3268 		printk(KERN_INFO "device %s %s promiscuous mode\n",
  2986 		       dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
  3269 		       dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
  2987 							       "left");
  3270 							       "left");
  2988 		if (audit_enabled)
  3271 		if (audit_enabled) {
       
  3272 			current_uid_gid(&uid, &gid);
  2989 			audit_log(current->audit_context, GFP_ATOMIC,
  3273 			audit_log(current->audit_context, GFP_ATOMIC,
  2990 				AUDIT_ANOM_PROMISCUOUS,
  3274 				AUDIT_ANOM_PROMISCUOUS,
  2991 				"dev=%s prom=%d old_prom=%d auid=%u uid=%u gid=%u ses=%u",
  3275 				"dev=%s prom=%d old_prom=%d auid=%u uid=%u gid=%u ses=%u",
  2992 				dev->name, (dev->flags & IFF_PROMISC),
  3276 				dev->name, (dev->flags & IFF_PROMISC),
  2993 				(old_flags & IFF_PROMISC),
  3277 				(old_flags & IFF_PROMISC),
  2994 				audit_get_loginuid(current),
  3278 				audit_get_loginuid(current),
  2995 				current->uid, current->gid,
  3279 				uid, gid,
  2996 				audit_get_sessionid(current));
  3280 				audit_get_sessionid(current));
       
  3281 		}
  2997 
  3282 
  2998 		dev_change_rx_flags(dev, IFF_PROMISC);
  3283 		dev_change_rx_flags(dev, IFF_PROMISC);
  2999 	}
  3284 	}
  3000 	return 0;
  3285 	return 0;
  3001 }
  3286 }
  3073  *	filtering it is put in promiscuous mode while unicast addresses
  3358  *	filtering it is put in promiscuous mode while unicast addresses
  3074  *	are present.
  3359  *	are present.
  3075  */
  3360  */
  3076 void __dev_set_rx_mode(struct net_device *dev)
  3361 void __dev_set_rx_mode(struct net_device *dev)
  3077 {
  3362 {
       
  3363 	const struct net_device_ops *ops = dev->netdev_ops;
       
  3364 
  3078 	/* dev_open will call this function so the list will stay sane. */
  3365 	/* dev_open will call this function so the list will stay sane. */
  3079 	if (!(dev->flags&IFF_UP))
  3366 	if (!(dev->flags&IFF_UP))
  3080 		return;
  3367 		return;
  3081 
  3368 
  3082 	if (!netif_device_present(dev))
  3369 	if (!netif_device_present(dev))
  3083 		return;
  3370 		return;
  3084 
  3371 
  3085 	if (dev->set_rx_mode)
  3372 	if (ops->ndo_set_rx_mode)
  3086 		dev->set_rx_mode(dev);
  3373 		ops->ndo_set_rx_mode(dev);
  3087 	else {
  3374 	else {
  3088 		/* Unicast addresses changes may only happen under the rtnl,
  3375 		/* Unicast addresses changes may only happen under the rtnl,
  3089 		 * therefore calling __dev_set_promiscuity here is safe.
  3376 		 * therefore calling __dev_set_promiscuity here is safe.
  3090 		 */
  3377 		 */
  3091 		if (dev->uc_count > 0 && !dev->uc_promisc) {
  3378 		if (dev->uc_count > 0 && !dev->uc_promisc) {
  3094 		} else if (dev->uc_count == 0 && dev->uc_promisc) {
  3381 		} else if (dev->uc_count == 0 && dev->uc_promisc) {
  3095 			__dev_set_promiscuity(dev, -1);
  3382 			__dev_set_promiscuity(dev, -1);
  3096 			dev->uc_promisc = 0;
  3383 			dev->uc_promisc = 0;
  3097 		}
  3384 		}
  3098 
  3385 
  3099 		if (dev->set_multicast_list)
  3386 		if (ops->ndo_set_multicast_list)
  3100 			dev->set_multicast_list(dev);
  3387 			ops->ndo_set_multicast_list(dev);
  3101 	}
  3388 	}
  3102 }
  3389 }
  3103 
  3390 
  3104 void dev_set_rx_mode(struct net_device *dev)
  3391 void dev_set_rx_mode(struct net_device *dev)
  3105 {
  3392 {
  3454  *
  3741  *
  3455  *	Change the maximum transfer size of the network device.
  3742  *	Change the maximum transfer size of the network device.
  3456  */
  3743  */
  3457 int dev_set_mtu(struct net_device *dev, int new_mtu)
  3744 int dev_set_mtu(struct net_device *dev, int new_mtu)
  3458 {
  3745 {
       
  3746 	const struct net_device_ops *ops = dev->netdev_ops;
  3459 	int err;
  3747 	int err;
  3460 
  3748 
  3461 	if (new_mtu == dev->mtu)
  3749 	if (new_mtu == dev->mtu)
  3462 		return 0;
  3750 		return 0;
  3463 
  3751 
  3467 
  3755 
  3468 	if (!netif_device_present(dev))
  3756 	if (!netif_device_present(dev))
  3469 		return -ENODEV;
  3757 		return -ENODEV;
  3470 
  3758 
  3471 	err = 0;
  3759 	err = 0;
  3472 	if (dev->change_mtu)
  3760 	if (ops->ndo_change_mtu)
  3473 		err = dev->change_mtu(dev, new_mtu);
  3761 		err = ops->ndo_change_mtu(dev, new_mtu);
  3474 	else
  3762 	else
  3475 		dev->mtu = new_mtu;
  3763 		dev->mtu = new_mtu;
       
  3764 
  3476 	if (!err && dev->flags & IFF_UP)
  3765 	if (!err && dev->flags & IFF_UP)
  3477 		call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
  3766 		call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
  3478 	return err;
  3767 	return err;
  3479 }
  3768 }
  3480 
  3769 
  3485  *
  3774  *
  3486  *	Change the hardware (MAC) address of the device
  3775  *	Change the hardware (MAC) address of the device
  3487  */
  3776  */
  3488 int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
  3777 int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
  3489 {
  3778 {
       
  3779 	const struct net_device_ops *ops = dev->netdev_ops;
  3490 	int err;
  3780 	int err;
  3491 
  3781 
  3492 	if (!dev->set_mac_address)
  3782 	if (!ops->ndo_set_mac_address)
  3493 		return -EOPNOTSUPP;
  3783 		return -EOPNOTSUPP;
  3494 	if (sa->sa_family != dev->type)
  3784 	if (sa->sa_family != dev->type)
  3495 		return -EINVAL;
  3785 		return -EINVAL;
  3496 	if (!netif_device_present(dev))
  3786 	if (!netif_device_present(dev))
  3497 		return -ENODEV;
  3787 		return -ENODEV;
  3498 	err = dev->set_mac_address(dev, sa);
  3788 	err = ops->ndo_set_mac_address(dev, sa);
  3499 	if (!err)
  3789 	if (!err)
  3500 		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
  3790 		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
  3501 	return err;
  3791 	return err;
  3502 }
  3792 }
  3503 
  3793 
  3573  */
  3863  */
  3574 static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
  3864 static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
  3575 {
  3865 {
  3576 	int err;
  3866 	int err;
  3577 	struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
  3867 	struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
       
  3868 	const struct net_device_ops *ops;
  3578 
  3869 
  3579 	if (!dev)
  3870 	if (!dev)
  3580 		return -ENODEV;
  3871 		return -ENODEV;
       
  3872 
       
  3873 	ops = dev->netdev_ops;
  3581 
  3874 
  3582 	switch (cmd) {
  3875 	switch (cmd) {
  3583 		case SIOCSIFFLAGS:	/* Set interface flags */
  3876 		case SIOCSIFFLAGS:	/* Set interface flags */
  3584 			return dev_change_flags(dev, ifr->ifr_flags);
  3877 			return dev_change_flags(dev, ifr->ifr_flags);
  3585 
  3878 
  3600 			       min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
  3893 			       min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
  3601 			call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
  3894 			call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
  3602 			return 0;
  3895 			return 0;
  3603 
  3896 
  3604 		case SIOCSIFMAP:
  3897 		case SIOCSIFMAP:
  3605 			if (dev->set_config) {
  3898 			if (ops->ndo_set_config) {
  3606 				if (!netif_device_present(dev))
  3899 				if (!netif_device_present(dev))
  3607 					return -ENODEV;
  3900 					return -ENODEV;
  3608 				return dev->set_config(dev, &ifr->ifr_map);
  3901 				return ops->ndo_set_config(dev, &ifr->ifr_map);
  3609 			}
  3902 			}
  3610 			return -EOPNOTSUPP;
  3903 			return -EOPNOTSUPP;
  3611 
  3904 
  3612 		case SIOCADDMULTI:
  3905 		case SIOCADDMULTI:
  3613 			if ((!dev->set_multicast_list && !dev->set_rx_mode) ||
  3906 			if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) ||
  3614 			    ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
  3907 			    ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
  3615 				return -EINVAL;
  3908 				return -EINVAL;
  3616 			if (!netif_device_present(dev))
  3909 			if (!netif_device_present(dev))
  3617 				return -ENODEV;
  3910 				return -ENODEV;
  3618 			return dev_mc_add(dev, ifr->ifr_hwaddr.sa_data,
  3911 			return dev_mc_add(dev, ifr->ifr_hwaddr.sa_data,
  3619 					  dev->addr_len, 1);
  3912 					  dev->addr_len, 1);
  3620 
  3913 
  3621 		case SIOCDELMULTI:
  3914 		case SIOCDELMULTI:
  3622 			if ((!dev->set_multicast_list && !dev->set_rx_mode) ||
  3915 			if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) ||
  3623 			    ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
  3916 			    ifr->ifr_hwaddr.sa_family != AF_UNSPEC)
  3624 				return -EINVAL;
  3917 				return -EINVAL;
  3625 			if (!netif_device_present(dev))
  3918 			if (!netif_device_present(dev))
  3626 				return -ENODEV;
  3919 				return -ENODEV;
  3627 			return dev_mc_delete(dev, ifr->ifr_hwaddr.sa_data,
  3920 			return dev_mc_delete(dev, ifr->ifr_hwaddr.sa_data,
  3655 			    cmd == SIOCSMIIREG ||
  3948 			    cmd == SIOCSMIIREG ||
  3656 			    cmd == SIOCBRADDIF ||
  3949 			    cmd == SIOCBRADDIF ||
  3657 			    cmd == SIOCBRDELIF ||
  3950 			    cmd == SIOCBRDELIF ||
  3658 			    cmd == SIOCWANDEV) {
  3951 			    cmd == SIOCWANDEV) {
  3659 				err = -EOPNOTSUPP;
  3952 				err = -EOPNOTSUPP;
  3660 				if (dev->do_ioctl) {
  3953 				if (ops->ndo_do_ioctl) {
  3661 					if (netif_device_present(dev))
  3954 					if (netif_device_present(dev))
  3662 						err = dev->do_ioctl(dev, ifr,
  3955 						err = ops->ndo_do_ioctl(dev, ifr, cmd);
  3663 								    cmd);
       
  3664 					else
  3956 					else
  3665 						err = -ENODEV;
  3957 						err = -ENODEV;
  3666 				}
  3958 				}
  3667 			} else
  3959 			} else
  3668 				err = -EINVAL;
  3960 				err = -EINVAL;
  3919 	/*
  4211 	/*
  3920 	 *	Flush the unicast and multicast chains
  4212 	 *	Flush the unicast and multicast chains
  3921 	 */
  4213 	 */
  3922 	dev_addr_discard(dev);
  4214 	dev_addr_discard(dev);
  3923 
  4215 
  3924 	if (dev->uninit)
  4216 	if (dev->netdev_ops->ndo_uninit)
  3925 		dev->uninit(dev);
  4217 		dev->netdev_ops->ndo_uninit(dev);
  3926 
  4218 
  3927 	/* Notifier chain MUST detach us from master device. */
  4219 	/* Notifier chain MUST detach us from master device. */
  3928 	WARN_ON(dev->master);
  4220 	WARN_ON(dev->master);
  3929 
  4221 
  3930 	/* Remove entries from kobject tree */
  4222 	/* Remove entries from kobject tree */
  3988 
  4280 
  3989 	return features;
  4281 	return features;
  3990 }
  4282 }
  3991 EXPORT_SYMBOL(netdev_fix_features);
  4283 EXPORT_SYMBOL(netdev_fix_features);
  3992 
  4284 
       
  4285 /* Some devices need to (re-)set their netdev_ops inside
       
  4286  * ->init() or similar.  If that happens, we have to setup
       
  4287  * the compat pointers again.
       
  4288  */
       
  4289 void netdev_resync_ops(struct net_device *dev)
       
  4290 {
       
  4291 #ifdef CONFIG_COMPAT_NET_DEV_OPS
       
  4292 	const struct net_device_ops *ops = dev->netdev_ops;
       
  4293 
       
  4294 	dev->init = ops->ndo_init;
       
  4295 	dev->uninit = ops->ndo_uninit;
       
  4296 	dev->open = ops->ndo_open;
       
  4297 	dev->change_rx_flags = ops->ndo_change_rx_flags;
       
  4298 	dev->set_rx_mode = ops->ndo_set_rx_mode;
       
  4299 	dev->set_multicast_list = ops->ndo_set_multicast_list;
       
  4300 	dev->set_mac_address = ops->ndo_set_mac_address;
       
  4301 	dev->validate_addr = ops->ndo_validate_addr;
       
  4302 	dev->do_ioctl = ops->ndo_do_ioctl;
       
  4303 	dev->set_config = ops->ndo_set_config;
       
  4304 	dev->change_mtu = ops->ndo_change_mtu;
       
  4305 	dev->neigh_setup = ops->ndo_neigh_setup;
       
  4306 	dev->tx_timeout = ops->ndo_tx_timeout;
       
  4307 	dev->get_stats = ops->ndo_get_stats;
       
  4308 	dev->vlan_rx_register = ops->ndo_vlan_rx_register;
       
  4309 	dev->vlan_rx_add_vid = ops->ndo_vlan_rx_add_vid;
       
  4310 	dev->vlan_rx_kill_vid = ops->ndo_vlan_rx_kill_vid;
       
  4311 #ifdef CONFIG_NET_POLL_CONTROLLER
       
  4312 	dev->poll_controller = ops->ndo_poll_controller;
       
  4313 #endif
       
  4314 #endif
       
  4315 }
       
  4316 EXPORT_SYMBOL(netdev_resync_ops);
       
  4317 
  3993 /**
  4318 /**
  3994  *	register_netdevice	- register a network device
  4319  *	register_netdevice	- register a network device
  3995  *	@dev: device to register
  4320  *	@dev: device to register
  3996  *
  4321  *
  3997  *	Take a completed network device structure and add it to the kernel
  4322  *	Take a completed network device structure and add it to the kernel
  4010 int register_netdevice(struct net_device *dev)
  4335 int register_netdevice(struct net_device *dev)
  4011 {
  4336 {
  4012 	struct hlist_head *head;
  4337 	struct hlist_head *head;
  4013 	struct hlist_node *p;
  4338 	struct hlist_node *p;
  4014 	int ret;
  4339 	int ret;
  4015 	struct net *net;
  4340 	struct net *net = dev_net(dev);
  4016 
  4341 
  4017 	BUG_ON(dev_boot_phase);
  4342 	BUG_ON(dev_boot_phase);
  4018 	ASSERT_RTNL();
  4343 	ASSERT_RTNL();
  4019 
  4344 
  4020 	might_sleep();
  4345 	might_sleep();
  4021 
  4346 
  4022 	/* When net_device's are persistent, this will be fatal. */
  4347 	/* When net_device's are persistent, this will be fatal. */
  4023 	BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
  4348 	BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
  4024 	BUG_ON(!dev_net(dev));
  4349 	BUG_ON(!net);
  4025 	net = dev_net(dev);
       
  4026 
  4350 
  4027 	spin_lock_init(&dev->addr_list_lock);
  4351 	spin_lock_init(&dev->addr_list_lock);
  4028 	netdev_set_addr_lockdep_class(dev);
  4352 	netdev_set_addr_lockdep_class(dev);
  4029 	netdev_init_queue_locks(dev);
  4353 	netdev_init_queue_locks(dev);
  4030 
  4354 
  4031 	dev->iflink = -1;
  4355 	dev->iflink = -1;
  4032 
  4356 
       
  4357 #ifdef CONFIG_COMPAT_NET_DEV_OPS
       
  4358 	/* Netdevice_ops API compatiability support.
       
  4359 	 * This is temporary until all network devices are converted.
       
  4360 	 */
       
  4361 	if (dev->netdev_ops) {
       
  4362 		netdev_resync_ops(dev);
       
  4363 	} else {
       
  4364 		char drivername[64];
       
  4365 		pr_info("%s (%s): not using net_device_ops yet\n",
       
  4366 			dev->name, netdev_drivername(dev, drivername, 64));
       
  4367 
       
  4368 		/* This works only because net_device_ops and the
       
  4369 		   compatiablity structure are the same. */
       
  4370 		dev->netdev_ops = (void *) &(dev->init);
       
  4371 	}
       
  4372 #endif
       
  4373 
  4033 	/* Init, if this function is available */
  4374 	/* Init, if this function is available */
  4034 	if (dev->init) {
  4375 	if (dev->netdev_ops->ndo_init) {
  4035 		ret = dev->init(dev);
  4376 		ret = dev->netdev_ops->ndo_init(dev);
  4036 		if (ret) {
  4377 		if (ret) {
  4037 			if (ret > 0)
  4378 			if (ret > 0)
  4038 				ret = -EIO;
  4379 				ret = -EIO;
  4039 			goto out;
  4380 			goto out;
  4040 		}
  4381 		}
  4108 
  4449 
  4109 out:
  4450 out:
  4110 	return ret;
  4451 	return ret;
  4111 
  4452 
  4112 err_uninit:
  4453 err_uninit:
  4113 	if (dev->uninit)
  4454 	if (dev->netdev_ops->ndo_uninit)
  4114 		dev->uninit(dev);
  4455 		dev->netdev_ops->ndo_uninit(dev);
  4115 	goto out;
  4456 	goto out;
  4116 }
  4457 }
       
  4458 
       
  4459 /**
       
  4460  *	init_dummy_netdev	- init a dummy network device for NAPI
       
  4461  *	@dev: device to init
       
  4462  *
       
  4463  *	This takes a network device structure and initialize the minimum
       
  4464  *	amount of fields so it can be used to schedule NAPI polls without
       
  4465  *	registering a full blown interface. This is to be used by drivers
       
  4466  *	that need to tie several hardware interfaces to a single NAPI
       
  4467  *	poll scheduler due to HW limitations.
       
  4468  */
       
  4469 int init_dummy_netdev(struct net_device *dev)
       
  4470 {
       
  4471 	/* Clear everything. Note we don't initialize spinlocks
       
  4472 	 * are they aren't supposed to be taken by any of the
       
  4473 	 * NAPI code and this dummy netdev is supposed to be
       
  4474 	 * only ever used for NAPI polls
       
  4475 	 */
       
  4476 	memset(dev, 0, sizeof(struct net_device));
       
  4477 
       
  4478 	/* make sure we BUG if trying to hit standard
       
  4479 	 * register/unregister code path
       
  4480 	 */
       
  4481 	dev->reg_state = NETREG_DUMMY;
       
  4482 
       
  4483 	/* initialize the ref count */
       
  4484 	atomic_set(&dev->refcnt, 1);
       
  4485 
       
  4486 	/* NAPI wants this */
       
  4487 	INIT_LIST_HEAD(&dev->napi_list);
       
  4488 
       
  4489 	/* a dummy interface is started by default */
       
  4490 	set_bit(__LINK_STATE_PRESENT, &dev->state);
       
  4491 	set_bit(__LINK_STATE_START, &dev->state);
       
  4492 
       
  4493 	return 0;
       
  4494 }
       
  4495 EXPORT_SYMBOL_GPL(init_dummy_netdev);
       
  4496 
  4117 
  4497 
  4118 /**
  4498 /**
  4119  *	register_netdev	- register a network device
  4499  *	register_netdev	- register a network device
  4120  *	@dev: device to register
  4500  *	@dev: device to register
  4121  *
  4501  *
  4265 		/* Free network device */
  4645 		/* Free network device */
  4266 		kobject_put(&dev->dev.kobj);
  4646 		kobject_put(&dev->dev.kobj);
  4267 	}
  4647 	}
  4268 }
  4648 }
  4269 
  4649 
  4270 static struct net_device_stats *internal_stats(struct net_device *dev)
  4650 /**
  4271 {
  4651  *	dev_get_stats	- get network device statistics
  4272 	return &dev->stats;
  4652  *	@dev: device to get statistics from
  4273 }
  4653  *
       
  4654  *	Get network statistics from device. The device driver may provide
       
  4655  *	its own method by setting dev->netdev_ops->get_stats; otherwise
       
  4656  *	the internal statistics structure is used.
       
  4657  */
       
  4658 const struct net_device_stats *dev_get_stats(struct net_device *dev)
       
  4659  {
       
  4660 	const struct net_device_ops *ops = dev->netdev_ops;
       
  4661 
       
  4662 	if (ops->ndo_get_stats)
       
  4663 		return ops->ndo_get_stats(dev);
       
  4664 	else
       
  4665 		return &dev->stats;
       
  4666 }
       
  4667 EXPORT_SYMBOL(dev_get_stats);
  4274 
  4668 
  4275 static void netdev_init_one_queue(struct net_device *dev,
  4669 static void netdev_init_one_queue(struct net_device *dev,
  4276 				  struct netdev_queue *queue,
  4670 				  struct netdev_queue *queue,
  4277 				  void *_unused)
  4671 				  void *_unused)
  4278 {
  4672 {
  4337 
  4731 
  4338 	dev->_tx = tx;
  4732 	dev->_tx = tx;
  4339 	dev->num_tx_queues = queue_count;
  4733 	dev->num_tx_queues = queue_count;
  4340 	dev->real_num_tx_queues = queue_count;
  4734 	dev->real_num_tx_queues = queue_count;
  4341 
  4735 
  4342 	if (sizeof_priv) {
       
  4343 		dev->priv = ((char *)dev +
       
  4344 			     ((sizeof(struct net_device) + NETDEV_ALIGN_CONST)
       
  4345 			      & ~NETDEV_ALIGN_CONST));
       
  4346 	}
       
  4347 
       
  4348 	dev->gso_max_size = GSO_MAX_SIZE;
  4736 	dev->gso_max_size = GSO_MAX_SIZE;
  4349 
  4737 
  4350 	netdev_init_queues(dev);
  4738 	netdev_init_queues(dev);
  4351 
  4739 
  4352 	dev->get_stats = internal_stats;
  4740 	INIT_LIST_HEAD(&dev->napi_list);
  4353 	netpoll_netdev_init(dev);
       
  4354 	setup(dev);
  4741 	setup(dev);
  4355 	strcpy(dev->name, name);
  4742 	strcpy(dev->name, name);
  4356 	return dev;
  4743 	return dev;
  4357 }
  4744 }
  4358 EXPORT_SYMBOL(alloc_netdev_mq);
  4745 EXPORT_SYMBOL(alloc_netdev_mq);
  4365  * 	interface. The reference to the device object is released.
  4752  * 	interface. The reference to the device object is released.
  4366  *	If this is the last reference then it will be freed.
  4753  *	If this is the last reference then it will be freed.
  4367  */
  4754  */
  4368 void free_netdev(struct net_device *dev)
  4755 void free_netdev(struct net_device *dev)
  4369 {
  4756 {
       
  4757 	struct napi_struct *p, *n;
       
  4758 
  4370 	release_net(dev_net(dev));
  4759 	release_net(dev_net(dev));
  4371 
  4760 
  4372 	kfree(dev->_tx);
  4761 	kfree(dev->_tx);
       
  4762 
       
  4763 	list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
       
  4764 		netif_napi_del(p);
  4373 
  4765 
  4374 	/*  Compatibility with error handling in drivers */
  4766 	/*  Compatibility with error handling in drivers */
  4375 	if (dev->reg_state == NETREG_UNINITIALIZED) {
  4767 	if (dev->reg_state == NETREG_UNINITIALIZED) {
  4376 		kfree((char *)dev - dev->padded);
  4768 		kfree((char *)dev - dev->padded);
  4377 		return;
  4769 		return;
  4460 
  4852 
  4461 	/* Don't allow namespace local devices to be moved. */
  4853 	/* Don't allow namespace local devices to be moved. */
  4462 	err = -EINVAL;
  4854 	err = -EINVAL;
  4463 	if (dev->features & NETIF_F_NETNS_LOCAL)
  4855 	if (dev->features & NETIF_F_NETNS_LOCAL)
  4464 		goto out;
  4856 		goto out;
       
  4857 
       
  4858 #ifdef CONFIG_SYSFS
       
  4859 	/* Don't allow real devices to be moved when sysfs
       
  4860 	 * is enabled.
       
  4861 	 */
       
  4862 	err = -EINVAL;
       
  4863 	if (dev->dev.parent)
       
  4864 		goto out;
       
  4865 #endif
  4465 
  4866 
  4466 	/* Ensure the device has been registrered */
  4867 	/* Ensure the device has been registrered */
  4467 	err = -EINVAL;
  4868 	err = -EINVAL;
  4468 	if (dev->reg_state != NETREG_REGISTERED)
  4869 	if (dev->reg_state != NETREG_REGISTERED)
  4469 		goto out;
  4870 		goto out;
  4518 	/*
  4919 	/*
  4519 	 *	Flush the unicast and multicast chains
  4920 	 *	Flush the unicast and multicast chains
  4520 	 */
  4921 	 */
  4521 	dev_addr_discard(dev);
  4922 	dev_addr_discard(dev);
  4522 
  4923 
       
  4924 	netdev_unregister_kobject(dev);
       
  4925 
  4523 	/* Actually switch the network namespace */
  4926 	/* Actually switch the network namespace */
  4524 	dev_net_set(dev, net);
  4927 	dev_net_set(dev, net);
  4525 
  4928 
  4526 	/* Assign the new device name */
  4929 	/* Assign the new device name */
  4527 	if (destname != dev->name)
  4930 	if (destname != dev->name)
  4534 		if (iflink)
  4937 		if (iflink)
  4535 			dev->iflink = dev->ifindex;
  4938 			dev->iflink = dev->ifindex;
  4536 	}
  4939 	}
  4537 
  4940 
  4538 	/* Fixup kobjects */
  4941 	/* Fixup kobjects */
  4539 	netdev_unregister_kobject(dev);
       
  4540 	err = netdev_register_kobject(dev);
  4942 	err = netdev_register_kobject(dev);
  4541 	WARN_ON(err);
  4943 	WARN_ON(err);
  4542 
  4944 
  4543 	/* Add the device back in the hashes */
  4945 	/* Add the device back in the hashes */
  4544 	list_netdevice(dev);
  4946 	list_netdevice(dev);
  4594 		netif_rx(skb);
  4996 		netif_rx(skb);
  4595 
  4997 
  4596 	return NOTIFY_OK;
  4998 	return NOTIFY_OK;
  4597 }
  4999 }
  4598 
  5000 
  4599 #ifdef CONFIG_NET_DMA
       
  4600 /**
       
  4601  * net_dma_rebalance - try to maintain one DMA channel per CPU
       
  4602  * @net_dma: DMA client and associated data (lock, channels, channel_mask)
       
  4603  *
       
  4604  * This is called when the number of channels allocated to the net_dma client
       
  4605  * changes.  The net_dma client tries to have one DMA channel per CPU.
       
  4606  */
       
  4607 
       
  4608 static void net_dma_rebalance(struct net_dma *net_dma)
       
  4609 {
       
  4610 	unsigned int cpu, i, n, chan_idx;
       
  4611 	struct dma_chan *chan;
       
  4612 
       
  4613 	if (cpus_empty(net_dma->channel_mask)) {
       
  4614 		for_each_online_cpu(cpu)
       
  4615 			rcu_assign_pointer(per_cpu(softnet_data, cpu).net_dma, NULL);
       
  4616 		return;
       
  4617 	}
       
  4618 
       
  4619 	i = 0;
       
  4620 	cpu = first_cpu(cpu_online_map);
       
  4621 
       
  4622 	for_each_cpu_mask_nr(chan_idx, net_dma->channel_mask) {
       
  4623 		chan = net_dma->channels[chan_idx];
       
  4624 
       
  4625 		n = ((num_online_cpus() / cpus_weight(net_dma->channel_mask))
       
  4626 		   + (i < (num_online_cpus() %
       
  4627 			cpus_weight(net_dma->channel_mask)) ? 1 : 0));
       
  4628 
       
  4629 		while(n) {
       
  4630 			per_cpu(softnet_data, cpu).net_dma = chan;
       
  4631 			cpu = next_cpu(cpu, cpu_online_map);
       
  4632 			n--;
       
  4633 		}
       
  4634 		i++;
       
  4635 	}
       
  4636 }
       
  4637 
       
  4638 /**
       
  4639  * netdev_dma_event - event callback for the net_dma_client
       
  4640  * @client: should always be net_dma_client
       
  4641  * @chan: DMA channel for the event
       
  4642  * @state: DMA state to be handled
       
  4643  */
       
  4644 static enum dma_state_client
       
  4645 netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
       
  4646 	enum dma_state state)
       
  4647 {
       
  4648 	int i, found = 0, pos = -1;
       
  4649 	struct net_dma *net_dma =
       
  4650 		container_of(client, struct net_dma, client);
       
  4651 	enum dma_state_client ack = DMA_DUP; /* default: take no action */
       
  4652 
       
  4653 	spin_lock(&net_dma->lock);
       
  4654 	switch (state) {
       
  4655 	case DMA_RESOURCE_AVAILABLE:
       
  4656 		for (i = 0; i < nr_cpu_ids; i++)
       
  4657 			if (net_dma->channels[i] == chan) {
       
  4658 				found = 1;
       
  4659 				break;
       
  4660 			} else if (net_dma->channels[i] == NULL && pos < 0)
       
  4661 				pos = i;
       
  4662 
       
  4663 		if (!found && pos >= 0) {
       
  4664 			ack = DMA_ACK;
       
  4665 			net_dma->channels[pos] = chan;
       
  4666 			cpu_set(pos, net_dma->channel_mask);
       
  4667 			net_dma_rebalance(net_dma);
       
  4668 		}
       
  4669 		break;
       
  4670 	case DMA_RESOURCE_REMOVED:
       
  4671 		for (i = 0; i < nr_cpu_ids; i++)
       
  4672 			if (net_dma->channels[i] == chan) {
       
  4673 				found = 1;
       
  4674 				pos = i;
       
  4675 				break;
       
  4676 			}
       
  4677 
       
  4678 		if (found) {
       
  4679 			ack = DMA_ACK;
       
  4680 			cpu_clear(pos, net_dma->channel_mask);
       
  4681 			net_dma->channels[i] = NULL;
       
  4682 			net_dma_rebalance(net_dma);
       
  4683 		}
       
  4684 		break;
       
  4685 	default:
       
  4686 		break;
       
  4687 	}
       
  4688 	spin_unlock(&net_dma->lock);
       
  4689 
       
  4690 	return ack;
       
  4691 }
       
  4692 
       
  4693 /**
       
  4694  * netdev_dma_register - register the networking subsystem as a DMA client
       
  4695  */
       
  4696 static int __init netdev_dma_register(void)
       
  4697 {
       
  4698 	net_dma.channels = kzalloc(nr_cpu_ids * sizeof(struct net_dma),
       
  4699 								GFP_KERNEL);
       
  4700 	if (unlikely(!net_dma.channels)) {
       
  4701 		printk(KERN_NOTICE
       
  4702 				"netdev_dma: no memory for net_dma.channels\n");
       
  4703 		return -ENOMEM;
       
  4704 	}
       
  4705 	spin_lock_init(&net_dma.lock);
       
  4706 	dma_cap_set(DMA_MEMCPY, net_dma.client.cap_mask);
       
  4707 	dma_async_client_register(&net_dma.client);
       
  4708 	dma_async_client_chan_request(&net_dma.client);
       
  4709 	return 0;
       
  4710 }
       
  4711 
       
  4712 #else
       
  4713 static int __init netdev_dma_register(void) { return -ENODEV; }
       
  4714 #endif /* CONFIG_NET_DMA */
       
  4715 
  5001 
  4716 /**
  5002 /**
  4717  *	netdev_increment_features - increment feature set by one
  5003  *	netdev_increment_features - increment feature set by one
  4718  *	@all: current feature set
  5004  *	@all: current feature set
  4719  *	@one: new feature set
  5005  *	@one: new feature set
  4827 	.exit = netdev_exit,
  5113 	.exit = netdev_exit,
  4828 };
  5114 };
  4829 
  5115 
  4830 static void __net_exit default_device_exit(struct net *net)
  5116 static void __net_exit default_device_exit(struct net *net)
  4831 {
  5117 {
  4832 	struct net_device *dev, *next;
  5118 	struct net_device *dev;
  4833 	/*
  5119 	/*
  4834 	 * Push all migratable of the network devices back to the
  5120 	 * Push all migratable of the network devices back to the
  4835 	 * initial network namespace
  5121 	 * initial network namespace
  4836 	 */
  5122 	 */
  4837 	rtnl_lock();
  5123 	rtnl_lock();
  4838 	for_each_netdev_safe(net, dev, next) {
  5124 restart:
       
  5125 	for_each_netdev(net, dev) {
  4839 		int err;
  5126 		int err;
  4840 		char fb_name[IFNAMSIZ];
  5127 		char fb_name[IFNAMSIZ];
  4841 
  5128 
  4842 		/* Ignore unmoveable devices (i.e. loopback) */
  5129 		/* Ignore unmoveable devices (i.e. loopback) */
  4843 		if (dev->features & NETIF_F_NETNS_LOCAL)
  5130 		if (dev->features & NETIF_F_NETNS_LOCAL)
  4844 			continue;
  5131 			continue;
       
  5132 
       
  5133 		/* Delete virtual devices */
       
  5134 		if (dev->rtnl_link_ops && dev->rtnl_link_ops->dellink) {
       
  5135 			dev->rtnl_link_ops->dellink(dev);
       
  5136 			goto restart;
       
  5137 		}
  4845 
  5138 
  4846 		/* Push remaing network devices to init_net */
  5139 		/* Push remaing network devices to init_net */
  4847 		snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
  5140 		snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
  4848 		err = dev_change_net_namespace(dev, &init_net, fb_name);
  5141 		err = dev_change_net_namespace(dev, &init_net, fb_name);
  4849 		if (err) {
  5142 		if (err) {
  4850 			printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n",
  5143 			printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n",
  4851 				__func__, dev->name, err);
  5144 				__func__, dev->name, err);
  4852 			BUG();
  5145 			BUG();
  4853 		}
  5146 		}
       
  5147 		goto restart;
  4854 	}
  5148 	}
  4855 	rtnl_unlock();
  5149 	rtnl_unlock();
  4856 }
  5150 }
  4857 
  5151 
  4858 static struct pernet_operations __net_initdata default_device_ops = {
  5152 static struct pernet_operations __net_initdata default_device_ops = {
  4887 		INIT_LIST_HEAD(&ptype_base[i]);
  5181 		INIT_LIST_HEAD(&ptype_base[i]);
  4888 
  5182 
  4889 	if (register_pernet_subsys(&netdev_net_ops))
  5183 	if (register_pernet_subsys(&netdev_net_ops))
  4890 		goto out;
  5184 		goto out;
  4891 
  5185 
  4892 	if (register_pernet_device(&default_device_ops))
       
  4893 		goto out;
       
  4894 
       
  4895 	/*
  5186 	/*
  4896 	 *	Initialise the packet receive queues.
  5187 	 *	Initialise the packet receive queues.
  4897 	 */
  5188 	 */
  4898 
  5189 
  4899 	for_each_possible_cpu(i) {
  5190 	for_each_possible_cpu(i) {
  4904 		queue->completion_queue = NULL;
  5195 		queue->completion_queue = NULL;
  4905 		INIT_LIST_HEAD(&queue->poll_list);
  5196 		INIT_LIST_HEAD(&queue->poll_list);
  4906 
  5197 
  4907 		queue->backlog.poll = process_backlog;
  5198 		queue->backlog.poll = process_backlog;
  4908 		queue->backlog.weight = weight_p;
  5199 		queue->backlog.weight = weight_p;
  4909 	}
  5200 		queue->backlog.gro_list = NULL;
  4910 
  5201 	}
  4911 	netdev_dma_register();
       
  4912 
  5202 
  4913 	dev_boot_phase = 0;
  5203 	dev_boot_phase = 0;
       
  5204 
       
  5205 	/* The loopback device is special if any other network devices
       
  5206 	 * is present in a network namespace the loopback device must
       
  5207 	 * be present. Since we now dynamically allocate and free the
       
  5208 	 * loopback device ensure this invariant is maintained by
       
  5209 	 * keeping the loopback device as the first device on the
       
  5210 	 * list of network devices.  Ensuring the loopback devices
       
  5211 	 * is the first device that appears and the last network device
       
  5212 	 * that disappears.
       
  5213 	 */
       
  5214 	if (register_pernet_device(&loopback_net_ops))
       
  5215 		goto out;
       
  5216 
       
  5217 	if (register_pernet_device(&default_device_ops))
       
  5218 		goto out;
  4914 
  5219 
  4915 	open_softirq(NET_TX_SOFTIRQ, net_tx_action);
  5220 	open_softirq(NET_TX_SOFTIRQ, net_tx_action);
  4916 	open_softirq(NET_RX_SOFTIRQ, net_rx_action);
  5221 	open_softirq(NET_RX_SOFTIRQ, net_rx_action);
  4917 
  5222 
  4918 	hotcpu_notifier(dev_cpu_callback, 0);
  5223 	hotcpu_notifier(dev_cpu_callback, 0);