Skip to content

Commit

Permalink
ibmvnic: Update TX pool initialization routine
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Thomas Falcon authored and David S. Miller committed Mar 18, 2018
1 parent fb79421 commit 3205306
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions drivers/net/ethernet/ibm/ibmvnic.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,67 +635,73 @@ static void release_tx_pools(struct ibmvnic_adapter *adapter)
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);
struct device *dev = &adapter->vdev->dev;
struct ibmvnic_tx_pool *tx_pool;
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,
sizeof(struct ibmvnic_tx_pool), GFP_KERNEL);
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++) {
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);
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);
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;
Expand Down

0 comments on commit 3205306

Please sign in to comment.