Skip to content

Commit

Permalink
cnic: Add functions to allocate and free UIO rings
Browse files Browse the repository at this point in the history
These functions are needed to free up memory when the rings are no longer
needed.

Reviewed-by: Eddie Wai <eddie.wai@broadcom.com>
Reviewed-by: Bhanu Prakash Gollapudi <bprakash@broadcom.com>
Signed-off-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Michael Chan authored and David S. Miller committed Sep 10, 2012
1 parent b6069a9 commit 74dd0c4
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions drivers/net/ethernet/broadcom/cnic.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,10 +823,8 @@ static void cnic_free_context(struct cnic_dev *dev)
}
}

static void __cnic_free_uio(struct cnic_uio_dev *udev)
static void __cnic_free_uio_rings(struct cnic_uio_dev *udev)
{
uio_unregister_device(&udev->cnic_uinfo);

if (udev->l2_buf) {
dma_free_coherent(&udev->pdev->dev, udev->l2_buf_size,
udev->l2_buf, udev->l2_buf_map);
Expand All @@ -839,6 +837,14 @@ static void __cnic_free_uio(struct cnic_uio_dev *udev)
udev->l2_ring = NULL;
}

}

static void __cnic_free_uio(struct cnic_uio_dev *udev)
{
uio_unregister_device(&udev->cnic_uinfo);

__cnic_free_uio_rings(udev);

pci_dev_put(udev->pdev);
kfree(udev);
}
Expand Down Expand Up @@ -996,6 +1002,34 @@ static int cnic_alloc_kcq(struct cnic_dev *dev, struct kcq_info *info,
return 0;
}

static int __cnic_alloc_uio_rings(struct cnic_uio_dev *udev, int pages)
{
struct cnic_local *cp = udev->dev->cnic_priv;

if (udev->l2_ring)
return 0;

udev->l2_ring_size = pages * BCM_PAGE_SIZE;
udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size,
&udev->l2_ring_map,
GFP_KERNEL | __GFP_COMP);
if (!udev->l2_ring)
return -ENOMEM;

udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size;
udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size);
udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size,
&udev->l2_buf_map,
GFP_KERNEL | __GFP_COMP);
if (!udev->l2_buf) {
__cnic_free_uio_rings(udev);
return -ENOMEM;
}

return 0;

}

static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)
{
struct cnic_local *cp = dev->cnic_priv;
Expand All @@ -1020,20 +1054,9 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)

udev->dev = dev;
udev->pdev = dev->pcidev;
udev->l2_ring_size = pages * BCM_PAGE_SIZE;
udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size,
&udev->l2_ring_map,
GFP_KERNEL | __GFP_COMP);
if (!udev->l2_ring)
goto err_udev;

udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size;
udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size);
udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size,
&udev->l2_buf_map,
GFP_KERNEL | __GFP_COMP);
if (!udev->l2_buf)
goto err_dma;
if (__cnic_alloc_uio_rings(udev, pages))
goto err_udev;

write_lock(&cnic_dev_lock);
list_add(&udev->list, &cnic_udev_list);
Expand All @@ -1044,9 +1067,7 @@ static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)
cp->udev = udev;

return 0;
err_dma:
dma_free_coherent(&udev->pdev->dev, udev->l2_ring_size,
udev->l2_ring, udev->l2_ring_map);

err_udev:
kfree(udev);
return -ENOMEM;
Expand Down

0 comments on commit 74dd0c4

Please sign in to comment.