]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/core/dev.c
rps: Fixed build with CONFIG_SMP not enabled.
[net-next-2.6.git] / net / core / dev.c
index be9924f60ec34bafa135916455595e794a7fe86c..1a7e1d1d5ad95304830385d0775733db910f56b5 100644 (file)
@@ -1113,32 +1113,13 @@ void dev_load(struct net *net, const char *name)
 }
 EXPORT_SYMBOL(dev_load);
 
-/**
- *     dev_open        - prepare an interface for use.
- *     @dev:   device to open
- *
- *     Takes a device from down to up state. The device's private open
- *     function is invoked and then the multicast lists are loaded. Finally
- *     the device is moved into the up state and a %NETDEV_UP message is
- *     sent to the netdev notifier chain.
- *
- *     Calling this function on an active interface is a nop. On a failure
- *     a negative errno code is returned.
- */
-int dev_open(struct net_device *dev)
+static int __dev_open(struct net_device *dev)
 {
        const struct net_device_ops *ops = dev->netdev_ops;
        int ret;
 
        ASSERT_RTNL();
 
-       /*
-        *      Is it already up?
-        */
-
-       if (dev->flags & IFF_UP)
-               return 0;
-
        /*
         *      Is it even present?
         */
@@ -1187,36 +1168,57 @@ int dev_open(struct net_device *dev)
                 *      Wakeup transmit queue engine
                 */
                dev_activate(dev);
-
-               /*
-                *      ... and announce new interface.
-                */
-               call_netdevice_notifiers(NETDEV_UP, dev);
        }
 
        return ret;
 }
-EXPORT_SYMBOL(dev_open);
 
 /**
- *     dev_close - shutdown an interface.
- *     @dev: device to shutdown
+ *     dev_open        - prepare an interface for use.
+ *     @dev:   device to open
  *
- *     This function moves an active device into down state. A
- *     %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
- *     is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
- *     chain.
+ *     Takes a device from down to up state. The device's private open
+ *     function is invoked and then the multicast lists are loaded. Finally
+ *     the device is moved into the up state and a %NETDEV_UP message is
+ *     sent to the netdev notifier chain.
+ *
+ *     Calling this function on an active interface is a nop. On a failure
+ *     a negative errno code is returned.
  */
-int dev_close(struct net_device *dev)
+int dev_open(struct net_device *dev)
+{
+       int ret;
+
+       /*
+        *      Is it already up?
+        */
+       if (dev->flags & IFF_UP)
+               return 0;
+
+       /*
+        *      Open device
+        */
+       ret = __dev_open(dev);
+       if (ret < 0)
+               return ret;
+
+       /*
+        *      ... and announce new interface.
+        */
+       rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
+       call_netdevice_notifiers(NETDEV_UP, dev);
+
+       return ret;
+}
+EXPORT_SYMBOL(dev_open);
+
+static int __dev_close(struct net_device *dev)
 {
        const struct net_device_ops *ops = dev->netdev_ops;
-       ASSERT_RTNL();
 
+       ASSERT_RTNL();
        might_sleep();
 
-       if (!(dev->flags & IFF_UP))
-               return 0;
-
        /*
         *      Tell people we are going down, so that they can
         *      prepare to death, when device is still operating.
@@ -1252,14 +1254,34 @@ int dev_close(struct net_device *dev)
        dev->flags &= ~IFF_UP;
 
        /*
-        * Tell people we are down
+        *      Shutdown NET_DMA
         */
-       call_netdevice_notifiers(NETDEV_DOWN, dev);
+       net_dmaengine_put();
+
+       return 0;
+}
+
+/**
+ *     dev_close - shutdown an interface.
+ *     @dev: device to shutdown
+ *
+ *     This function moves an active device into down state. A
+ *     %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device
+ *     is then deactivated and finally a %NETDEV_DOWN is sent to the notifier
+ *     chain.
+ */
+int dev_close(struct net_device *dev)
+{
+       if (!(dev->flags & IFF_UP))
+               return 0;
+
+       __dev_close(dev);
 
        /*
-        *      Shutdown NET_DMA
+        * Tell people we are down
         */
-       net_dmaengine_put();
+       rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
+       call_netdevice_notifiers(NETDEV_DOWN, dev);
 
        return 0;
 }
@@ -1448,13 +1470,10 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
        if (skb->len > (dev->mtu + dev->hard_header_len))
                return NET_RX_DROP;
 
-       skb_dst_drop(skb);
+       skb_set_dev(skb, dev);
        skb->tstamp.tv64 = 0;
        skb->pkt_type = PACKET_HOST;
        skb->protocol = eth_type_trans(skb, dev);
-       skb->mark = 0;
-       secpath_reset(skb);
-       nf_reset(skb);
        return netif_rx(skb);
 }
 EXPORT_SYMBOL_GPL(dev_forward_skb);
@@ -1614,6 +1633,36 @@ static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb)
        return false;
 }
 
+/**
+ * skb_dev_set -- assign a new device to a buffer
+ * @skb: buffer for the new device
+ * @dev: network device
+ *
+ * If an skb is owned by a device already, we have to reset
+ * all data private to the namespace a device belongs to
+ * before assigning it a new device.
+ */
+#ifdef CONFIG_NET_NS
+void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
+{
+       skb_dst_drop(skb);
+       if (skb->dev && !net_eq(dev_net(skb->dev), dev_net(dev))) {
+               secpath_reset(skb);
+               nf_reset(skb);
+               skb_init_secmark(skb);
+               skb->mark = 0;
+               skb->priority = 0;
+               skb->nf_trace = 0;
+               skb->ipvs_property = 0;
+#ifdef CONFIG_NET_SCHED
+               skb->tc_index = 0;
+#endif
+       }
+       skb->dev = dev;
+}
+EXPORT_SYMBOL(skb_set_dev);
+#endif /* CONFIG_NET_NS */
+
 /*
  * Invalidate hardware checksum when packet is to be mangled, and
  * complete checksum manually on outgoing path.
@@ -1853,6 +1902,14 @@ gso:
 
                skb->next = nskb->next;
                nskb->next = NULL;
+
+               /*
+                * If device doesnt need nskb->dst, release it right now while
+                * its hot in this cpu cache
+                */
+               if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
+                       skb_dst_drop(nskb);
+
                rc = ops->ndo_start_xmit(nskb, dev);
                if (unlikely(rc != NETDEV_TX_OK)) {
                        if (rc & ~NETDEV_TX_MASK)
@@ -1874,7 +1931,7 @@ out_kfree_skb:
        return rc;
 }
 
-static u32 skb_tx_hashrnd;
+static u32 hashrnd __read_mostly;
 
 u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb)
 {
@@ -1892,7 +1949,7 @@ u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb)
        else
                hash = skb->protocol;
 
-       hash = jhash_1word(hash, skb_tx_hashrnd);
+       hash = jhash_1word(hash, hashrnd);
 
        return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32);
 }
@@ -1902,10 +1959,9 @@ static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index)
 {
        if (unlikely(queue_index >= dev->real_num_tx_queues)) {
                if (net_ratelimit()) {
-                       WARN(1, "%s selects TX queue %d, but "
+                       netdev_warn(dev, "selects TX queue %d, but "
                             "real number of TX queues is %d\n",
-                            dev->name, queue_index,
-                            dev->real_num_tx_queues);
+                            queue_index, dev->real_num_tx_queues);
                }
                return 0;
        }
@@ -1974,6 +2030,21 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
        return rc;
 }
 
+/*
+ * Returns true if either:
+ *     1. skb has frag_list and the device doesn't support FRAGLIST, or
+ *     2. skb is fragmented and the device does not support SG, or if
+ *        at least one of fragments is in highmem and device does not
+ *        support DMA from it.
+ */
+static inline int skb_needs_linearize(struct sk_buff *skb,
+                                     struct net_device *dev)
+{
+       return (skb_has_frags(skb) && !(dev->features & NETIF_F_FRAGLIST)) ||
+              (skb_shinfo(skb)->nr_frags && (!(dev->features & NETIF_F_SG) ||
+                                             illegal_highdma(dev, skb)));
+}
+
 /**
  *     dev_queue_xmit - transmit a buffer
  *     @skb: buffer to transmit
@@ -2010,18 +2081,8 @@ int dev_queue_xmit(struct sk_buff *skb)
        if (netif_needs_gso(dev, skb))
                goto gso;
 
-       if (skb_has_frags(skb) &&
-           !(dev->features & NETIF_F_FRAGLIST) &&
-           __skb_linearize(skb))
-               goto out_kfree_skb;
-
-       /* Fragmented skb is linearized if device does not support SG,
-        * or if at least one of fragments is in highmem and device
-        * does not support DMA from it.
-        */
-       if (skb_shinfo(skb)->nr_frags &&
-           (!(dev->features & NETIF_F_SG) || illegal_highdma(dev, skb)) &&
-           __skb_linearize(skb))
+       /* Convert a paged skb to linear, if required */
+       if (skb_needs_linearize(skb, dev) && __skb_linearize(skb))
                goto out_kfree_skb;
 
        /* If packet is not checksummed and device does not support
@@ -2041,7 +2102,7 @@ gso:
        rcu_read_lock_bh();
 
        txq = dev_pick_tx(dev, skb);
-       q = rcu_dereference(txq->qdisc);
+       q = rcu_dereference_bh(txq->qdisc);
 
 #ifdef CONFIG_NET_CLS_ACT
        skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS);
@@ -2113,6 +2174,178 @@ int weight_p __read_mostly = 64;            /* old backlog weight */
 
 DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, };
 
+#ifdef CONFIG_SMP
+/*
+ * get_rps_cpu is called from netif_receive_skb and returns the target
+ * CPU from the RPS map of the receiving queue for a given skb.
+ */
+static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb)
+{
+       struct ipv6hdr *ip6;
+       struct iphdr *ip;
+       struct netdev_rx_queue *rxqueue;
+       struct rps_map *map;
+       int cpu = -1;
+       u8 ip_proto;
+       u32 addr1, addr2, ports, ihl;
+
+       rcu_read_lock();
+
+       if (skb_rx_queue_recorded(skb)) {
+               u16 index = skb_get_rx_queue(skb);
+               if (unlikely(index >= dev->num_rx_queues)) {
+                       if (net_ratelimit()) {
+                               netdev_warn(dev, "received packet on queue "
+                                   "%u, but number of RX queues is %u\n",
+                                    index, dev->num_rx_queues);
+                       }
+                       goto done;
+               }
+               rxqueue = dev->_rx + index;
+       } else
+               rxqueue = dev->_rx;
+
+       if (!rxqueue->rps_map)
+               goto done;
+
+       if (skb->rxhash)
+               goto got_hash; /* Skip hash computation on packet header */
+
+       switch (skb->protocol) {
+       case __constant_htons(ETH_P_IP):
+               if (!pskb_may_pull(skb, sizeof(*ip)))
+                       goto done;
+
+               ip = (struct iphdr *) skb->data;
+               ip_proto = ip->protocol;
+               addr1 = ip->saddr;
+               addr2 = ip->daddr;
+               ihl = ip->ihl;
+               break;
+       case __constant_htons(ETH_P_IPV6):
+               if (!pskb_may_pull(skb, sizeof(*ip6)))
+                       goto done;
+
+               ip6 = (struct ipv6hdr *) skb->data;
+               ip_proto = ip6->nexthdr;
+               addr1 = ip6->saddr.s6_addr32[3];
+               addr2 = ip6->daddr.s6_addr32[3];
+               ihl = (40 >> 2);
+               break;
+       default:
+               goto done;
+       }
+       ports = 0;
+       switch (ip_proto) {
+       case IPPROTO_TCP:
+       case IPPROTO_UDP:
+       case IPPROTO_DCCP:
+       case IPPROTO_ESP:
+       case IPPROTO_AH:
+       case IPPROTO_SCTP:
+       case IPPROTO_UDPLITE:
+               if (pskb_may_pull(skb, (ihl * 4) + 4))
+                       ports = *((u32 *) (skb->data + (ihl * 4)));
+               break;
+
+       default:
+               break;
+       }
+
+       skb->rxhash = jhash_3words(addr1, addr2, ports, hashrnd);
+       if (!skb->rxhash)
+               skb->rxhash = 1;
+
+got_hash:
+       map = rcu_dereference(rxqueue->rps_map);
+       if (map) {
+               u16 tcpu = map->cpus[((u64) skb->rxhash * map->len) >> 32];
+
+               if (cpu_online(tcpu)) {
+                       cpu = tcpu;
+                       goto done;
+               }
+       }
+
+done:
+       rcu_read_unlock();
+       return cpu;
+}
+
+/*
+ * This structure holds the per-CPU mask of CPUs for which IPIs are scheduled
+ * to be sent to kick remote softirq processing.  There are two masks since
+ * the sending of IPIs must be done with interrupts enabled.  The select field
+ * indicates the current mask that enqueue_backlog uses to schedule IPIs.
+ * select is flipped before net_rps_action is called while still under lock,
+ * net_rps_action then uses the non-selected mask to send the IPIs and clears
+ * it without conflicting with enqueue_backlog operation.
+ */
+struct rps_remote_softirq_cpus {
+       cpumask_t mask[2];
+       int select;
+};
+static DEFINE_PER_CPU(struct rps_remote_softirq_cpus, rps_remote_softirq_cpus);
+
+/* Called from hardirq (IPI) context */
+static void trigger_softirq(void *data)
+{
+       struct softnet_data *queue = data;
+       __napi_schedule(&queue->backlog);
+       __get_cpu_var(netdev_rx_stat).received_rps++;
+}
+#endif /* CONFIG_SMP */
+
+/*
+ * enqueue_to_backlog is called to queue an skb to a per CPU backlog
+ * queue (may be a remote CPU queue).
+ */
+static int enqueue_to_backlog(struct sk_buff *skb, int cpu)
+{
+       struct softnet_data *queue;
+       unsigned long flags;
+
+       queue = &per_cpu(softnet_data, cpu);
+
+       local_irq_save(flags);
+       __get_cpu_var(netdev_rx_stat).total++;
+
+       spin_lock(&queue->input_pkt_queue.lock);
+       if (queue->input_pkt_queue.qlen <= netdev_max_backlog) {
+               if (queue->input_pkt_queue.qlen) {
+enqueue:
+                       __skb_queue_tail(&queue->input_pkt_queue, skb);
+                       spin_unlock_irqrestore(&queue->input_pkt_queue.lock,
+                           flags);
+                       return NET_RX_SUCCESS;
+               }
+
+               /* Schedule NAPI for backlog device */
+               if (napi_schedule_prep(&queue->backlog)) {
+#ifdef CONFIG_SMP
+                       if (cpu != smp_processor_id()) {
+                               struct rps_remote_softirq_cpus *rcpus =
+                                   &__get_cpu_var(rps_remote_softirq_cpus);
+
+                               cpu_set(cpu, rcpus->mask[rcpus->select]);
+                               __raise_softirq_irqoff(NET_RX_SOFTIRQ);
+                       } else
+                               __napi_schedule(&queue->backlog);
+#else
+                       __napi_schedule(&queue->backlog);
+#endif
+               }
+               goto enqueue;
+       }
+
+       spin_unlock(&queue->input_pkt_queue.lock);
+
+       __get_cpu_var(netdev_rx_stat).dropped++;
+       local_irq_restore(flags);
+
+       kfree_skb(skb);
+       return NET_RX_DROP;
+}
 
 /**
  *     netif_rx        -       post buffer to the network code
@@ -2131,8 +2364,7 @@ DEFINE_PER_CPU(struct netif_rx_stats, netdev_rx_stat) = { 0, };
 
 int netif_rx(struct sk_buff *skb)
 {
-       struct softnet_data *queue;
-       unsigned long flags;
+       int cpu;
 
        /* if netpoll wants it, pretend we never saw it */
        if (netpoll_rx(skb))
@@ -2141,31 +2373,15 @@ int netif_rx(struct sk_buff *skb)
        if (!skb->tstamp.tv64)
                net_timestamp(skb);
 
-       /*
-        * The code is rearranged so that the path is the most
-        * short when CPU is congested, but is still operating.
-        */
-       local_irq_save(flags);
-       queue = &__get_cpu_var(softnet_data);
-
-       __get_cpu_var(netdev_rx_stat).total++;
-       if (queue->input_pkt_queue.qlen <= netdev_max_backlog) {
-               if (queue->input_pkt_queue.qlen) {
-enqueue:
-                       __skb_queue_tail(&queue->input_pkt_queue, skb);
-                       local_irq_restore(flags);
-                       return NET_RX_SUCCESS;
-               }
-
-               napi_schedule(&queue->backlog);
-               goto enqueue;
-       }
-
-       __get_cpu_var(netdev_rx_stat).dropped++;
-       local_irq_restore(flags);
+#ifdef CONFIG_SMP
+       cpu = get_rps_cpu(skb->dev, skb);
+       if (cpu < 0)
+               cpu = smp_processor_id();
+#else
+       cpu = smp_processor_id();
+#endif
 
-       kfree_skb(skb);
-       return NET_RX_DROP;
+       return enqueue_to_backlog(skb, cpu);
 }
 EXPORT_SYMBOL(netif_rx);
 
@@ -2402,26 +2618,12 @@ void netif_nit_deliver(struct sk_buff *skb)
        rcu_read_unlock();
 }
 
-/**
- *     netif_receive_skb - process receive buffer from network
- *     @skb: buffer to process
- *
- *     netif_receive_skb() is the main receive data processing function.
- *     It always succeeds. The buffer may be dropped during processing
- *     for congestion control or by the protocol layers.
- *
- *     This function may only be called from softirq context and interrupts
- *     should be enabled.
- *
- *     Return values (usually ignored):
- *     NET_RX_SUCCESS: no congestion
- *     NET_RX_DROP: packet was dropped
- */
-int netif_receive_skb(struct sk_buff *skb)
+int __netif_receive_skb(struct sk_buff *skb)
 {
        struct packet_type *ptype, *pt_prev;
        struct net_device *orig_dev;
        struct net_device *null_or_orig;
+       struct net_device *null_or_bond;
        int ret = NET_RX_DROP;
        __be16 type;
 
@@ -2487,12 +2689,24 @@ ncls:
        if (!skb)
                goto out;
 
+       /*
+        * Make sure frames received on VLAN interfaces stacked on
+        * bonding interfaces still make their way to any base bonding
+        * device that may have registered for a specific ptype.  The
+        * handler may have to adjust skb->dev and orig_dev.
+        */
+       null_or_bond = NULL;
+       if ((skb->dev->priv_flags & IFF_802_1Q_VLAN) &&
+           (vlan_dev_real_dev(skb->dev)->priv_flags & IFF_BONDING)) {
+               null_or_bond = vlan_dev_real_dev(skb->dev);
+       }
+
        type = skb->protocol;
        list_for_each_entry_rcu(ptype,
                        &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) {
-               if (ptype->type == type &&
-                   (ptype->dev == null_or_orig || ptype->dev == skb->dev ||
-                    ptype->dev == orig_dev)) {
+               if (ptype->type == type && (ptype->dev == null_or_orig ||
+                    ptype->dev == skb->dev || ptype->dev == orig_dev ||
+                    ptype->dev == null_or_bond)) {
                        if (pt_prev)
                                ret = deliver_skb(skb, pt_prev, orig_dev);
                        pt_prev = ptype;
@@ -2513,6 +2727,37 @@ out:
        rcu_read_unlock();
        return ret;
 }
+
+/**
+ *     netif_receive_skb - process receive buffer from network
+ *     @skb: buffer to process
+ *
+ *     netif_receive_skb() is the main receive data processing function.
+ *     It always succeeds. The buffer may be dropped during processing
+ *     for congestion control or by the protocol layers.
+ *
+ *     This function may only be called from softirq context and interrupts
+ *     should be enabled.
+ *
+ *     Return values (usually ignored):
+ *     NET_RX_SUCCESS: no congestion
+ *     NET_RX_DROP: packet was dropped
+ */
+int netif_receive_skb(struct sk_buff *skb)
+{
+#ifdef CONFIG_SMP
+       int cpu;
+
+       cpu = get_rps_cpu(skb->dev, skb);
+
+       if (cpu < 0)
+               return __netif_receive_skb(skb);
+       else
+               return enqueue_to_backlog(skb, cpu);
+#else
+       return __netif_receive_skb(skb);
+#endif
+}
 EXPORT_SYMBOL(netif_receive_skb);
 
 /* Network device is going away, flush any packets still pending  */
@@ -2561,7 +2806,7 @@ out:
        return netif_receive_skb(skb);
 }
 
-void napi_gro_flush(struct napi_struct *napi)
+static void napi_gro_flush(struct napi_struct *napi)
 {
        struct sk_buff *skb, *next;
 
@@ -2574,7 +2819,6 @@ void napi_gro_flush(struct napi_struct *napi)
        napi->gro_count = 0;
        napi->gro_list = NULL;
 }
-EXPORT_SYMBOL(napi_gro_flush);
 
 enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
 {
@@ -2761,7 +3005,7 @@ gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *skb,
        switch (ret) {
        case GRO_NORMAL:
        case GRO_HELD:
-               skb->protocol = eth_type_trans(skb, napi->dev);
+               skb->protocol = eth_type_trans(skb, skb->dev);
 
                if (ret == GRO_HELD)
                        skb_gro_pull(skb, -ETH_HLEN);
@@ -2840,16 +3084,16 @@ static int process_backlog(struct napi_struct *napi, int quota)
        do {
                struct sk_buff *skb;
 
-               local_irq_disable();
+               spin_lock_irq(&queue->input_pkt_queue.lock);
                skb = __skb_dequeue(&queue->input_pkt_queue);
                if (!skb) {
                        __napi_complete(napi);
-                       local_irq_enable();
+                       spin_unlock_irq(&queue->input_pkt_queue.lock);
                        break;
                }
-               local_irq_enable();
+               spin_unlock_irq(&queue->input_pkt_queue.lock);
 
-               netif_receive_skb(skb);
+               __netif_receive_skb(skb);
        } while (++work < quota && jiffies == start_time);
 
        return work;
@@ -2938,6 +3182,24 @@ void netif_napi_del(struct napi_struct *napi)
 }
 EXPORT_SYMBOL(netif_napi_del);
 
+#ifdef CONFIG_SMP
+/*
+ * net_rps_action sends any pending IPI's for rps.  This is only called from
+ * softirq and interrupts must be enabled.
+ */
+static void net_rps_action(cpumask_t *mask)
+{
+       int cpu;
+
+       /* Send pending IPI's to kick RPS processing on remote cpus. */
+       for_each_cpu_mask_nr(cpu, *mask) {
+               struct softnet_data *queue = &per_cpu(softnet_data, cpu);
+               if (cpu_online(cpu))
+                       __smp_call_function_single(cpu, &queue->csd, 0);
+       }
+       cpus_clear(*mask);
+}
+#endif
 
 static void net_rx_action(struct softirq_action *h)
 {
@@ -2945,6 +3207,10 @@ static void net_rx_action(struct softirq_action *h)
        unsigned long time_limit = jiffies + 2;
        int budget = netdev_budget;
        void *have;
+#ifdef CONFIG_SMP
+       int select;
+       struct rps_remote_softirq_cpus *rcpus;
+#endif
 
        local_irq_disable();
 
@@ -2966,7 +3232,7 @@ static void net_rx_action(struct softirq_action *h)
                 * entries to the tail of this list, and only ->poll()
                 * calls can remove this head entry from the list.
                 */
-               n = list_entry(list->next, struct napi_struct, poll_list);
+               n = list_first_entry(list, struct napi_struct, poll_list);
 
                have = netpoll_poll_lock(n);
 
@@ -3007,7 +3273,17 @@ static void net_rx_action(struct softirq_action *h)
                netpoll_poll_unlock(have);
        }
 out:
+#ifdef CONFIG_SMP
+       rcpus = &__get_cpu_var(rps_remote_softirq_cpus);
+       select = rcpus->select;
+       rcpus->select ^= 1;
+
+       local_irq_enable();
+
+       net_rps_action(&rcpus->mask[select]);
+#else
        local_irq_enable();
+#endif
 
 #ifdef CONFIG_NET_DMA
        /*
@@ -3185,7 +3461,7 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
 {
        const struct net_device_stats *stats = dev_get_stats(dev);
 
-       seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
+       seq_printf(seq, "%6s: %7lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
                   "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
                   dev->name, stats->rx_bytes, stats->rx_packets,
                   stats->rx_errors,
@@ -3253,10 +3529,10 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
 {
        struct netif_rx_stats *s = v;
 
-       seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
+       seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
                   s->total, s->dropped, s->time_squeeze, 0,
                   0, 0, 0, 0, /* was fastroute */
-                  s->cpu_collision);
+                  s->cpu_collision, s->received_rps);
        return 0;
 }
 
@@ -3640,10 +3916,10 @@ void __dev_set_rx_mode(struct net_device *dev)
                /* Unicast addresses changes may only happen under the rtnl,
                 * therefore calling __dev_set_promiscuity here is safe.
                 */
-               if (dev->uc.count > 0 && !dev->uc_promisc) {
+               if (!netdev_uc_empty(dev) && !dev->uc_promisc) {
                        __dev_set_promiscuity(dev, 1);
                        dev->uc_promisc = 1;
-               } else if (dev->uc.count == 0 && dev->uc_promisc) {
+               } else if (netdev_uc_empty(dev) && dev->uc_promisc) {
                        __dev_set_promiscuity(dev, -1);
                        dev->uc_promisc = 0;
                }
@@ -4211,7 +4487,7 @@ static void dev_addr_discard(struct net_device *dev)
        netif_addr_lock_bh(dev);
 
        __dev_addr_discard(&dev->mc_list);
-       dev->mc_count = 0;
+       netdev_mc_count(dev) = 0;
 
        netif_addr_unlock_bh(dev);
 }
@@ -4247,18 +4523,10 @@ unsigned dev_get_flags(const struct net_device *dev)
 }
 EXPORT_SYMBOL(dev_get_flags);
 
-/**
- *     dev_change_flags - change device settings
- *     @dev: device
- *     @flags: device state flags
- *
- *     Change settings on device based state flags. The flags are
- *     in the userspace exported format.
- */
-int dev_change_flags(struct net_device *dev, unsigned flags)
+int __dev_change_flags(struct net_device *dev, unsigned int flags)
 {
-       int ret, changes;
        int old_flags = dev->flags;
+       int ret;
 
        ASSERT_RTNL();
 
@@ -4289,17 +4557,12 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
 
        ret = 0;
        if ((old_flags ^ flags) & IFF_UP) {     /* Bit is different  ? */
-               ret = ((old_flags & IFF_UP) ? dev_close : dev_open)(dev);
+               ret = ((old_flags & IFF_UP) ? __dev_close : __dev_open)(dev);
 
                if (!ret)
                        dev_set_rx_mode(dev);
        }
 
-       if (dev->flags & IFF_UP &&
-           ((old_flags ^ dev->flags) & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI |
-                                         IFF_VOLATILE)))
-               call_netdevice_notifiers(NETDEV_CHANGE, dev);
-
        if ((flags ^ dev->gflags) & IFF_PROMISC) {
                int inc = (flags & IFF_PROMISC) ? 1 : -1;
 
@@ -4318,11 +4581,47 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
                dev_set_allmulti(dev, inc);
        }
 
-       /* Exclude state transition flags, already notified */
-       changes = (old_flags ^ dev->flags) & ~(IFF_UP | IFF_RUNNING);
+       return ret;
+}
+
+void __dev_notify_flags(struct net_device *dev, unsigned int old_flags)
+{
+       unsigned int changes = dev->flags ^ old_flags;
+
+       if (changes & IFF_UP) {
+               if (dev->flags & IFF_UP)
+                       call_netdevice_notifiers(NETDEV_UP, dev);
+               else
+                       call_netdevice_notifiers(NETDEV_DOWN, dev);
+       }
+
+       if (dev->flags & IFF_UP &&
+           (changes & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI | IFF_VOLATILE)))
+               call_netdevice_notifiers(NETDEV_CHANGE, dev);
+}
+
+/**
+ *     dev_change_flags - change device settings
+ *     @dev: device
+ *     @flags: device state flags
+ *
+ *     Change settings on device based state flags. The flags are
+ *     in the userspace exported format.
+ */
+int dev_change_flags(struct net_device *dev, unsigned flags)
+{
+       int ret, changes;
+       int old_flags = dev->flags;
+
+       ret = __dev_change_flags(dev, flags);
+       if (ret < 0)
+               return ret;
+
+       changes = old_flags ^ dev->flags;
        if (changes)
                rtmsg_ifinfo(RTM_NEWLINK, dev, changes);
 
+       __dev_notify_flags(dev, old_flags);
        return ret;
 }
 EXPORT_SYMBOL(dev_change_flags);
@@ -4813,6 +5112,10 @@ static void rollback_registered_many(struct list_head *head)
                */
                call_netdevice_notifiers(NETDEV_UNREGISTER, dev);
 
+               if (!dev->rtnl_link_ops ||
+                   dev->rtnl_link_state == RTNL_LINK_INITIALIZED)
+                       rtmsg_ifinfo(RTM_DELLINK, dev, ~0U);
+
                /*
                 *      Flush the unicast and multicast chains
                 */
@@ -4830,7 +5133,7 @@ static void rollback_registered_many(struct list_head *head)
        }
 
        /* Process any work delayed until the end of the batch */
-       dev = list_entry(head->next, struct net_device, unreg_list);
+       dev = list_first_entry(head, struct net_device, unreg_list);
        call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev);
 
        synchronize_net();
@@ -4966,6 +5269,23 @@ int register_netdevice(struct net_device *dev)
 
        dev->iflink = -1;
 
+       if (!dev->num_rx_queues) {
+               /*
+                * Allocate a single RX queue if driver never called
+                * alloc_netdev_mq
+                */
+
+               dev->_rx = kzalloc(sizeof(struct netdev_rx_queue), GFP_KERNEL);
+               if (!dev->_rx) {
+                       ret = -ENOMEM;
+                       goto out;
+               }
+
+               dev->_rx->first = dev->_rx;
+               atomic_set(&dev->_rx->count, 1);
+               dev->num_rx_queues = 1;
+       }
+
        /* Init, if this function is available */
        if (dev->netdev_ops->ndo_init) {
                ret = dev->netdev_ops->ndo_init(dev);
@@ -5039,7 +5359,9 @@ int register_netdevice(struct net_device *dev)
         *      Prevent userspace races by waiting until the network
         *      device is fully setup before sending notifications.
         */
-       rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
+       if (!dev->rtnl_link_ops ||
+           dev->rtnl_link_state == RTNL_LINK_INITIALIZED)
+               rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
 
 out:
        return ret;
@@ -5216,7 +5538,7 @@ void netdev_run_todo(void)
 
        while (!list_empty(&list)) {
                struct net_device *dev
-                       = list_entry(list.next, struct net_device, todo_list);
+                       = list_first_entry(&list, struct net_device, todo_list);
                list_del(&dev->todo_list);
 
                if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
@@ -5321,9 +5643,11 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
                void (*setup)(struct net_device *), unsigned int queue_count)
 {
        struct netdev_queue *tx;
+       struct netdev_rx_queue *rx;
        struct net_device *dev;
        size_t alloc_size;
        struct net_device *p;
+       int i;
 
        BUG_ON(strlen(name) >= sizeof(dev->name));
 
@@ -5349,11 +5673,27 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
                goto free_p;
        }
 
+       rx = kcalloc(queue_count, sizeof(struct netdev_rx_queue), GFP_KERNEL);
+       if (!rx) {
+               printk(KERN_ERR "alloc_netdev: Unable to allocate "
+                      "rx queues.\n");
+               goto free_tx;
+       }
+
+       atomic_set(&rx->count, queue_count);
+
+       /*
+        * Set a pointer to first element in the array which holds the
+        * reference count.
+        */
+       for (i = 0; i < queue_count; i++)
+               rx[i].first = rx;
+
        dev = PTR_ALIGN(p, NETDEV_ALIGN);
        dev->padded = (char *)dev - (char *)p;
 
        if (dev_addr_init(dev))
-               goto free_tx;
+               goto free_rx;
 
        dev_unicast_init(dev);
 
@@ -5363,10 +5703,15 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
        dev->num_tx_queues = queue_count;
        dev->real_num_tx_queues = queue_count;
 
+       dev->_rx = rx;
+       dev->num_rx_queues = queue_count;
+
        dev->gso_max_size = GSO_MAX_SIZE;
 
        netdev_init_queues(dev);
 
+       INIT_LIST_HEAD(&dev->ethtool_ntuple_list.list);
+       dev->ethtool_ntuple_list.count = 0;
        INIT_LIST_HEAD(&dev->napi_list);
        INIT_LIST_HEAD(&dev->unreg_list);
        INIT_LIST_HEAD(&dev->link_watch_list);
@@ -5375,9 +5720,10 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
        strcpy(dev->name, name);
        return dev;
 
+free_rx:
+       kfree(rx);
 free_tx:
        kfree(tx);
-
 free_p:
        kfree(p);
        return NULL;
@@ -5403,6 +5749,9 @@ void free_netdev(struct net_device *dev)
        /* Flush device addresses */
        dev_addr_flush(dev);
 
+       /* Clear ethtool n-tuple list */
+       ethtool_ntuple_flush(dev);
+
        list_for_each_entry_safe(p, n, &dev->napi_list, dev_list)
                netif_napi_del(p);
 
@@ -5877,6 +6226,12 @@ static int __init net_dev_init(void)
                queue->completion_queue = NULL;
                INIT_LIST_HEAD(&queue->poll_list);
 
+#ifdef CONFIG_SMP
+               queue->csd.func = trigger_softirq;
+               queue->csd.info = queue;
+               queue->csd.flags = 0;
+#endif
+
                queue->backlog.poll = process_backlog;
                queue->backlog.weight = weight_p;
                queue->backlog.gro_list = NULL;
@@ -5915,7 +6270,7 @@ subsys_initcall(net_dev_init);
 
 static int __init initialize_hashrnd(void)
 {
-       get_random_bytes(&skb_tx_hashrnd, sizeof(skb_tx_hashrnd));
+       get_random_bytes(&hashrnd, sizeof(hashrnd));
        return 0;
 }