ibmvnic: Make napi usage dynamic
authorNathan Fontenot <nfont@linux.vnet.ibm.com>
Mon, 19 Feb 2018 19:30:39 +0000 (13:30 -0600)
committerDavid S. Miller <davem@davemloft.net>
Wed, 21 Feb 2018 19:21:48 +0000 (14:21 -0500)
In order to handle the number of rx sub crqs changing during a driver
reset, the ibmvnic driver also needs to update the number of napi.
To do this the code to init and free napi's is moved to their own
routines so they can be called during the reset process.

Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ibm/ibmvnic.c

index 33cfd277f0080edfba78284df4770b5a75856ce6..7dc67de269f5ea1649c5520bc7c77de7ebf1f0dc 100644 (file)
@@ -730,6 +730,43 @@ static void ibmvnic_napi_disable(struct ibmvnic_adapter *adapter)
        adapter->napi_enabled = false;
 }
 
+static int init_napi(struct ibmvnic_adapter *adapter)
+{
+       int i;
+
+       adapter->napi = kcalloc(adapter->req_rx_queues,
+                               sizeof(struct napi_struct), GFP_KERNEL);
+       if (!adapter->napi)
+               return -ENOMEM;
+
+       for (i = 0; i < adapter->req_rx_queues; i++) {
+               netdev_dbg(adapter->netdev, "Adding napi[%d]\n", i);
+               netif_napi_add(adapter->netdev, &adapter->napi[i],
+                              ibmvnic_poll, NAPI_POLL_WEIGHT);
+       }
+
+       return 0;
+}
+
+static void release_napi(struct ibmvnic_adapter *adapter)
+{
+       int i;
+
+       if (!adapter->napi)
+               return;
+
+       for (i = 0; i < adapter->num_active_rx_scrqs; i++) {
+               if (&adapter->napi[i]) {
+                       netdev_dbg(adapter->netdev,
+                                  "Releasing napi[%d]\n", i);
+                       netif_napi_del(&adapter->napi[i]);
+               }
+       }
+
+       kfree(adapter->napi);
+       adapter->napi = NULL;
+}
+
 static int ibmvnic_login(struct net_device *netdev)
 {
        struct ibmvnic_adapter *adapter = netdev_priv(netdev);
@@ -795,8 +832,6 @@ static void release_login_rsp_buffer(struct ibmvnic_adapter *adapter)
 
 static void release_resources(struct ibmvnic_adapter *adapter)
 {
-       int i;
-
        release_vpd_data(adapter);
 
        release_tx_pools(adapter);
@@ -805,19 +840,7 @@ static void release_resources(struct ibmvnic_adapter *adapter)
        release_stats_token(adapter);
        release_stats_buffers(adapter);
        release_error_buffers(adapter);
-
-       if (adapter->napi) {
-               for (i = 0; i < adapter->req_rx_queues; i++) {
-                       if (&adapter->napi[i]) {
-                               netdev_dbg(adapter->netdev,
-                                          "Releasing napi[%d]\n", i);
-                               netif_napi_del(&adapter->napi[i]);
-                       }
-               }
-       }
-       kfree(adapter->napi);
-       adapter->napi = NULL;
-
+       release_napi(adapter);
        release_login_rsp_buffer(adapter);
 }
 
@@ -937,7 +960,7 @@ static int ibmvnic_get_vpd(struct ibmvnic_adapter *adapter)
 static int init_resources(struct ibmvnic_adapter *adapter)
 {
        struct net_device *netdev = adapter->netdev;
-       int i, rc;
+       int rc;
 
        rc = set_real_num_queues(netdev);
        if (rc)
@@ -963,16 +986,10 @@ static int init_resources(struct ibmvnic_adapter *adapter)
        }
 
        adapter->map_id = 1;
-       adapter->napi = kcalloc(adapter->req_rx_queues,
-                               sizeof(struct napi_struct), GFP_KERNEL);
-       if (!adapter->napi)
-               return -ENOMEM;
 
-       for (i = 0; i < adapter->req_rx_queues; i++) {
-               netdev_dbg(netdev, "Adding napi[%d]\n", i);
-               netif_napi_add(netdev, &adapter->napi[i], ibmvnic_poll,
-                              NAPI_POLL_WEIGHT);
-       }
+       rc = init_napi(adapter);
+       if (rc)
+               return rc;
 
        send_map_query(adapter);
 
@@ -1687,6 +1704,9 @@ static int do_reset(struct ibmvnic_adapter *adapter,
                        init_rx_pools(netdev);
                        init_tx_pools(netdev);
 
+                       release_napi(adapter);
+                       init_napi(adapter);
+
                        adapter->num_active_tx_scrqs = adapter->req_tx_queues;
                        adapter->num_active_rx_scrqs = adapter->req_rx_queues;
                } else {