net: add netif_tx_napi_add()
authorEric Dumazet <edumazet@google.com>
Wed, 18 Nov 2015 14:31:00 +0000 (06:31 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 Nov 2015 21:17:41 +0000 (16:17 -0500)
netif_tx_napi_add() is a variant of netif_napi_add()

It should be used by drivers that use a napi structure
to exclusively poll TX.

We do not want to add this kind of napi in napi_hash[] in following
patches, adding generic busy polling to all NAPI drivers.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
12 files changed:
drivers/net/ethernet/broadcom/bcmsysport.c
drivers/net/ethernet/broadcom/genet/bcmgenet.c
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c
drivers/net/ethernet/freescale/gianfar.c
drivers/net/ethernet/mellanox/mlx4/en_cq.c
drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
drivers/net/ethernet/rocker/rocker.c
drivers/net/ethernet/ti/cpsw.c
drivers/net/ethernet/ti/netcp_core.c
drivers/net/wireless/ath/wil6210/netdev.c
include/linux/netdevice.h
net/core/dev.c

index 8581063..993c780 100644 (file)
@@ -1216,7 +1216,7 @@ static int bcm_sysport_init_tx_ring(struct bcm_sysport_priv *priv,
        /* Initialize SW view of the ring */
        spin_lock_init(&ring->lock);
        ring->priv = priv;
-       netif_napi_add(priv->netdev, &ring->napi, bcm_sysport_tx_poll, 64);
+       netif_tx_napi_add(priv->netdev, &ring->napi, bcm_sysport_tx_poll, 64);
        ring->index = index;
        ring->size = size;
        ring->alloc_size = ring->size;
index 17f017a..b15a60d 100644 (file)
@@ -2041,11 +2041,11 @@ static void bcmgenet_init_tx_napi(struct bcmgenet_priv *priv)
 
        for (i = 0; i < priv->hw_params->tx_queues; ++i) {
                ring = &priv->tx_rings[i];
-               netif_napi_add(priv->dev, &ring->napi, bcmgenet_tx_poll, 64);
+               netif_tx_napi_add(priv->dev, &ring->napi, bcmgenet_tx_poll, 64);
        }
 
        ring = &priv->tx_rings[DESC_INDEX];
-       netif_napi_add(priv->dev, &ring->napi, bcmgenet_tx_poll, 64);
+       netif_tx_napi_add(priv->dev, &ring->napi, bcmgenet_tx_poll, 64);
 }
 
 static void bcmgenet_enable_tx_napi(struct bcmgenet_priv *priv)
index cf8e546..48a9c17 100644 (file)
@@ -1050,7 +1050,7 @@ static int fs_enet_probe(struct platform_device *ofdev)
        ndev->netdev_ops = &fs_enet_netdev_ops;
        ndev->watchdog_timeo = 2 * HZ;
        netif_napi_add(ndev, &fep->napi, fs_enet_rx_napi, fpi->napi_weight);
-       netif_napi_add(ndev, &fep->napi_tx, fs_enet_tx_napi, 2);
+       netif_tx_napi_add(ndev, &fep->napi_tx, fs_enet_tx_napi, 2);
 
        ndev->ethtool_ops = &fs_ethtool_ops;
 
index 3e6b9b4..c8bc43e 100644 (file)
@@ -1347,12 +1347,12 @@ static int gfar_probe(struct platform_device *ofdev)
                if (priv->poll_mode == GFAR_SQ_POLLING) {
                        netif_napi_add(dev, &priv->gfargrp[i].napi_rx,
                                       gfar_poll_rx_sq, GFAR_DEV_WEIGHT);
-                       netif_napi_add(dev, &priv->gfargrp[i].napi_tx,
+                       netif_tx_napi_add(dev, &priv->gfargrp[i].napi_tx,
                                       gfar_poll_tx_sq, 2);
                } else {
                        netif_napi_add(dev, &priv->gfargrp[i].napi_rx,
                                       gfar_poll_rx, GFAR_DEV_WEIGHT);
-                       netif_napi_add(dev, &priv->gfargrp[i].napi_tx,
+                       netif_tx_napi_add(dev, &priv->gfargrp[i].napi_tx,
                                       gfar_poll_tx, 2);
                }
        }
index eb8a498..3a6176f 100644 (file)
@@ -156,8 +156,8 @@ int mlx4_en_activate_cq(struct mlx4_en_priv *priv, struct mlx4_en_cq *cq,
        cq->mcq.event = mlx4_en_cq_event;
 
        if (cq->is_tx) {
-               netif_napi_add(cq->dev, &cq->napi, mlx4_en_poll_tx_cq,
-                              NAPI_POLL_WEIGHT);
+               netif_tx_napi_add(cq->dev, &cq->napi, mlx4_en_poll_tx_cq,
+                                 NAPI_POLL_WEIGHT);
        } else {
                netif_napi_add(cq->dev, &cq->napi, mlx4_en_poll_rx_cq, 64);
                napi_hash_add(&cq->napi);
index d4b5085..7bd6f25 100644 (file)
@@ -1604,7 +1604,7 @@ int qlcnic_82xx_napi_add(struct qlcnic_adapter *adapter,
        if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
                for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
                        tx_ring = &adapter->tx_ring[ring];
-                       netif_napi_add(netdev, &tx_ring->napi, qlcnic_tx_poll,
+                       netif_tx_napi_add(netdev, &tx_ring->napi, qlcnic_tx_poll,
                                       NAPI_POLL_WEIGHT);
                }
        }
@@ -2135,7 +2135,7 @@ int qlcnic_83xx_napi_add(struct qlcnic_adapter *adapter,
            !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
                for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
                        tx_ring = &adapter->tx_ring[ring];
-                       netif_napi_add(netdev, &tx_ring->napi,
+                       netif_tx_napi_add(netdev, &tx_ring->napi,
                                       qlcnic_83xx_msix_tx_poll,
                                       NAPI_POLL_WEIGHT);
                }
index e9f2349..a4ab71d 100644 (file)
@@ -4998,7 +4998,7 @@ static int rocker_probe_port(struct rocker *rocker, unsigned int port_number)
        dev->netdev_ops = &rocker_port_netdev_ops;
        dev->ethtool_ops = &rocker_port_ethtool_ops;
        dev->switchdev_ops = &rocker_port_switchdev_ops;
-       netif_napi_add(dev, &rocker_port->napi_tx, rocker_port_poll_tx,
+       netif_tx_napi_add(dev, &rocker_port->napi_tx, rocker_port_poll_tx,
                       NAPI_POLL_WEIGHT);
        netif_napi_add(dev, &rocker_port->napi_rx, rocker_port_poll_rx,
                       NAPI_POLL_WEIGHT);
index 48b92c9..15322c0 100644 (file)
@@ -2469,7 +2469,7 @@ static int cpsw_probe(struct platform_device *pdev)
        ndev->netdev_ops = &cpsw_netdev_ops;
        ndev->ethtool_ops = &cpsw_ethtool_ops;
        netif_napi_add(ndev, &priv->napi_rx, cpsw_rx_poll, CPSW_POLL_WEIGHT);
-       netif_napi_add(ndev, &priv->napi_tx, cpsw_tx_poll, CPSW_POLL_WEIGHT);
+       netif_tx_napi_add(ndev, &priv->napi_tx, cpsw_tx_poll, CPSW_POLL_WEIGHT);
 
        /* register the network device */
        SET_NETDEV_DEV(ndev, &pdev->dev);
index 37b9b39..e5e20e7 100644 (file)
@@ -1990,7 +1990,7 @@ static int netcp_create_interface(struct netcp_device *netcp_device,
 
        /* NAPI register */
        netif_napi_add(ndev, &netcp->rx_napi, netcp_rx_poll, NETCP_NAPI_WEIGHT);
-       netif_napi_add(ndev, &netcp->tx_napi, netcp_tx_poll, NETCP_NAPI_WEIGHT);
+       netif_tx_napi_add(ndev, &netcp->tx_napi, netcp_tx_poll, NETCP_NAPI_WEIGHT);
 
        /* Register the network device */
        ndev->dev_id            = 0;
index e3b3c8f..56aaa2d 100644 (file)
@@ -183,7 +183,7 @@ void *wil_if_alloc(struct device *dev)
 
        netif_napi_add(ndev, &wil->napi_rx, wil6210_netdev_poll_rx,
                       WIL6210_NAPI_BUDGET);
-       netif_napi_add(ndev, &wil->napi_tx, wil6210_netdev_poll_tx,
+       netif_tx_napi_add(ndev, &wil->napi_tx, wil6210_netdev_poll_tx,
                       WIL6210_NAPI_BUDGET);
 
        netif_tx_stop_all_queues(ndev);
index 2020a89..838935d 100644 (file)
@@ -326,7 +326,8 @@ enum {
        NAPI_STATE_SCHED,       /* Poll is scheduled */
        NAPI_STATE_DISABLE,     /* Disable pending */
        NAPI_STATE_NPSVC,       /* Netpoll - don't dequeue from poll_list */
-       NAPI_STATE_HASHED,      /* In NAPI hash */
+       NAPI_STATE_HASHED,      /* In NAPI hash (busy polling possible) */
+       NAPI_STATE_NO_BUSY_POLL,/* Do not add in napi_hash, no busy polling */
 };
 
 enum gro_result {
@@ -1938,6 +1939,26 @@ static inline void *netdev_priv(const struct net_device *dev)
 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
                    int (*poll)(struct napi_struct *, int), int weight);
 
+/**
+ *     netif_tx_napi_add - initialize a napi context
+ *     @dev:  network device
+ *     @napi: napi context
+ *     @poll: polling function
+ *     @weight: default weight
+ *
+ * This variant of netif_napi_add() should be used from drivers using NAPI
+ * to exclusively poll a TX queue.
+ * This will avoid we add it into napi_hash[], thus polluting this hash table.
+ */
+static inline void netif_tx_napi_add(struct net_device *dev,
+                                    struct napi_struct *napi,
+                                    int (*poll)(struct napi_struct *, int),
+                                    int weight)
+{
+       set_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state);
+       netif_napi_add(dev, napi, poll, weight);
+}
+
 /**
  *  netif_napi_del - remove a napi context
  *  @napi: napi context
index 83b4874..ff58a8b 100644 (file)
@@ -4737,7 +4737,8 @@ EXPORT_SYMBOL(sk_busy_loop);
 
 void napi_hash_add(struct napi_struct *napi)
 {
-       if (test_and_set_bit(NAPI_STATE_HASHED, &napi->state))
+       if (test_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state) ||
+           test_and_set_bit(NAPI_STATE_HASHED, &napi->state))
                return;
 
        spin_lock(&napi_hash_lock);