ibmvnic: Update TX pool initialization routine
authorThomas Falcon <tlfalcon@linux.vnet.ibm.com>
Sat, 17 Mar 2018 01:00:27 +0000 (20:00 -0500)
committerDavid S. Miller <davem@davemloft.net>
Sun, 18 Mar 2018 00:12:39 +0000 (20:12 -0400)
Introduce function that initializes one TX pool. Use that to
create each pool entry in both the standard TX pool and TSO
pool arrays.

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

index 258d54e3a6169eb7e6c5ce28693c6b8e8c90bc9b..2bb5d562dde16a3c777b4332b7554472c807b3be 100644 (file)
@@ -635,13 +635,43 @@ static void release_tx_pools(struct ibmvnic_adapter *adapter)
        adapter->num_active_tx_pools = 0;
 }
 
        adapter->num_active_tx_pools = 0;
 }
 
+static int init_one_tx_pool(struct net_device *netdev,
+                           struct ibmvnic_tx_pool *tx_pool,
+                           int num_entries, int buf_size)
+{
+       struct ibmvnic_adapter *adapter = netdev_priv(netdev);
+       int i;
+
+       tx_pool->tx_buff = kcalloc(num_entries,
+                                  sizeof(struct ibmvnic_tx_buff),
+                                  GFP_KERNEL);
+       if (!tx_pool->tx_buff)
+               return -1;
+
+       if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
+                                num_entries * buf_size))
+               return -1;
+
+       tx_pool->free_map = kcalloc(num_entries, sizeof(int), GFP_KERNEL);
+       if (!tx_pool->free_map)
+               return -1;
+
+       for (i = 0; i < num_entries; i++)
+               tx_pool->free_map[i] = i;
+
+       tx_pool->consumer_index = 0;
+       tx_pool->producer_index = 0;
+       tx_pool->num_buffers = num_entries;
+       tx_pool->buf_size = buf_size;
+
+       return 0;
+}
+
 static int init_tx_pools(struct net_device *netdev)
 {
        struct ibmvnic_adapter *adapter = netdev_priv(netdev);
 static int init_tx_pools(struct net_device *netdev)
 {
        struct ibmvnic_adapter *adapter = netdev_priv(netdev);
-       struct device *dev = &adapter->vdev->dev;
-       struct ibmvnic_tx_pool *tx_pool;
        int tx_subcrqs;
        int tx_subcrqs;
-       int i, j;
+       int i, rc;
 
        tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
        adapter->tx_pool = kcalloc(tx_subcrqs,
 
        tx_subcrqs = be32_to_cpu(adapter->login_rsp_buf->num_txsubm_subcrqs);
        adapter->tx_pool = kcalloc(tx_subcrqs,
@@ -649,53 +679,29 @@ static int init_tx_pools(struct net_device *netdev)
        if (!adapter->tx_pool)
                return -1;
 
        if (!adapter->tx_pool)
                return -1;
 
+       adapter->tso_pool = kcalloc(tx_subcrqs,
+                                   sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
+       if (!adapter->tso_pool)
+               return -1;
+
        adapter->num_active_tx_pools = tx_subcrqs;
 
        for (i = 0; i < tx_subcrqs; i++) {
        adapter->num_active_tx_pools = tx_subcrqs;
 
        for (i = 0; i < tx_subcrqs; i++) {
-               tx_pool = &adapter->tx_pool[i];
-
-               netdev_dbg(adapter->netdev,
-                          "Initializing tx_pool[%d], %lld buffs\n",
-                          i, adapter->req_tx_entries_per_subcrq);
-
-               tx_pool->tx_buff = kcalloc(adapter->req_tx_entries_per_subcrq,
-                                          sizeof(struct ibmvnic_tx_buff),
-                                          GFP_KERNEL);
-               if (!tx_pool->tx_buff) {
-                       dev_err(dev, "tx pool buffer allocation failed\n");
-                       release_tx_pools(adapter);
-                       return -1;
-               }
-
-               if (alloc_long_term_buff(adapter, &tx_pool->long_term_buff,
-                                        adapter->req_tx_entries_per_subcrq *
-                                        (adapter->req_mtu + VLAN_HLEN))) {
-                       release_tx_pools(adapter);
-                       return -1;
-               }
-
-               /* alloc TSO ltb */
-               if (alloc_long_term_buff(adapter, &tx_pool->tso_ltb,
-                                        IBMVNIC_TSO_BUFS *
-                                        IBMVNIC_TSO_BUF_SZ)) {
+               rc = init_one_tx_pool(netdev, &adapter->tx_pool[i],
+                                     adapter->req_tx_entries_per_subcrq,
+                                     adapter->req_mtu + VLAN_HLEN);
+               if (rc) {
                        release_tx_pools(adapter);
                        release_tx_pools(adapter);
-                       return -1;
+                       return rc;
                }
 
                }
 
-               tx_pool->tso_index = 0;
-
-               tx_pool->free_map = kcalloc(adapter->req_tx_entries_per_subcrq,
-                                           sizeof(int), GFP_KERNEL);
-               if (!tx_pool->free_map) {
+               init_one_tx_pool(netdev, &adapter->tso_pool[i],
+                                IBMVNIC_TSO_BUFS,
+                                IBMVNIC_TSO_BUF_SZ);
+               if (rc) {
                        release_tx_pools(adapter);
                        release_tx_pools(adapter);
-                       return -1;
+                       return rc;
                }
                }
-
-               for (j = 0; j < adapter->req_tx_entries_per_subcrq; j++)
-                       tx_pool->free_map[j] = j;
-
-               tx_pool->consumer_index = 0;
-               tx_pool->producer_index = 0;
        }
 
        return 0;
        }
 
        return 0;