aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/tg3.c
diff options
context:
space:
mode:
authorMatt Carlson <mcarlson@broadcom.com>2010-11-24 03:31:52 -0500
committerDavid S. Miller <davem@davemloft.net>2010-11-24 14:06:20 -0500
commit4bae65c892b4ff9a2797cbfa8526a5f9aaf1b2ed (patch)
treede41062abc162898508da7cb242c090e0858d0b2 /drivers/net/tg3.c
parentb92b9040f6e4997b895b7b9c655a158354d28964 (diff)
tg3: use dma_alloc_coherent() instead of pci_alloc_consistent()
Using dma_alloc_coherent() permits to use GFP_KERNEL allocations instead of GFP_ATOMIC ones. Its better when a machine is out of memory, because this allows driver to sleep to get its memory and succeed its init, especially when allocating high order pages. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: Matt Carlson <mcarlson@broadcom.com> Reviewed-by: Michael Chan <mchan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tg3.c')
-rw-r--r--drivers/net/tg3.c73
1 files changed, 41 insertions, 32 deletions
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 75ebebc9115a..3079e1f540fd 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -6337,13 +6337,13 @@ static void tg3_rx_prodring_fini(struct tg3 *tp,
6337 kfree(tpr->rx_jmb_buffers); 6337 kfree(tpr->rx_jmb_buffers);
6338 tpr->rx_jmb_buffers = NULL; 6338 tpr->rx_jmb_buffers = NULL;
6339 if (tpr->rx_std) { 6339 if (tpr->rx_std) {
6340 pci_free_consistent(tp->pdev, TG3_RX_STD_RING_BYTES(tp), 6340 dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp),
6341 tpr->rx_std, tpr->rx_std_mapping); 6341 tpr->rx_std, tpr->rx_std_mapping);
6342 tpr->rx_std = NULL; 6342 tpr->rx_std = NULL;
6343 } 6343 }
6344 if (tpr->rx_jmb) { 6344 if (tpr->rx_jmb) {
6345 pci_free_consistent(tp->pdev, TG3_RX_JMB_RING_BYTES(tp), 6345 dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp),
6346 tpr->rx_jmb, tpr->rx_jmb_mapping); 6346 tpr->rx_jmb, tpr->rx_jmb_mapping);
6347 tpr->rx_jmb = NULL; 6347 tpr->rx_jmb = NULL;
6348 } 6348 }
6349} 6349}
@@ -6356,8 +6356,10 @@ static int tg3_rx_prodring_init(struct tg3 *tp,
6356 if (!tpr->rx_std_buffers) 6356 if (!tpr->rx_std_buffers)
6357 return -ENOMEM; 6357 return -ENOMEM;
6358 6358
6359 tpr->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_STD_RING_BYTES(tp), 6359 tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev,
6360 &tpr->rx_std_mapping); 6360 TG3_RX_STD_RING_BYTES(tp),
6361 &tpr->rx_std_mapping,
6362 GFP_KERNEL);
6361 if (!tpr->rx_std) 6363 if (!tpr->rx_std)
6362 goto err_out; 6364 goto err_out;
6363 6365
@@ -6368,9 +6370,10 @@ static int tg3_rx_prodring_init(struct tg3 *tp,
6368 if (!tpr->rx_jmb_buffers) 6370 if (!tpr->rx_jmb_buffers)
6369 goto err_out; 6371 goto err_out;
6370 6372
6371 tpr->rx_jmb = pci_alloc_consistent(tp->pdev, 6373 tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev,
6372 TG3_RX_JMB_RING_BYTES(tp), 6374 TG3_RX_JMB_RING_BYTES(tp),
6373 &tpr->rx_jmb_mapping); 6375 &tpr->rx_jmb_mapping,
6376 GFP_KERNEL);
6374 if (!tpr->rx_jmb) 6377 if (!tpr->rx_jmb)
6375 goto err_out; 6378 goto err_out;
6376 } 6379 }
@@ -6489,7 +6492,7 @@ static void tg3_free_consistent(struct tg3 *tp)
6489 struct tg3_napi *tnapi = &tp->napi[i]; 6492 struct tg3_napi *tnapi = &tp->napi[i];
6490 6493
6491 if (tnapi->tx_ring) { 6494 if (tnapi->tx_ring) {
6492 pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES, 6495 dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES,
6493 tnapi->tx_ring, tnapi->tx_desc_mapping); 6496 tnapi->tx_ring, tnapi->tx_desc_mapping);
6494 tnapi->tx_ring = NULL; 6497 tnapi->tx_ring = NULL;
6495 } 6498 }
@@ -6498,25 +6501,26 @@ static void tg3_free_consistent(struct tg3 *tp)
6498 tnapi->tx_buffers = NULL; 6501 tnapi->tx_buffers = NULL;
6499 6502
6500 if (tnapi->rx_rcb) { 6503 if (tnapi->rx_rcb) {
6501 pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp), 6504 dma_free_coherent(&tp->pdev->dev,
6502 tnapi->rx_rcb, 6505 TG3_RX_RCB_RING_BYTES(tp),
6503 tnapi->rx_rcb_mapping); 6506 tnapi->rx_rcb,
6507 tnapi->rx_rcb_mapping);
6504 tnapi->rx_rcb = NULL; 6508 tnapi->rx_rcb = NULL;
6505 } 6509 }
6506 6510
6507 tg3_rx_prodring_fini(tp, &tnapi->prodring); 6511 tg3_rx_prodring_fini(tp, &tnapi->prodring);
6508 6512
6509 if (tnapi->hw_status) { 6513 if (tnapi->hw_status) {
6510 pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE, 6514 dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE,
6511 tnapi->hw_status, 6515 tnapi->hw_status,
6512 tnapi->status_mapping); 6516 tnapi->status_mapping);
6513 tnapi->hw_status = NULL; 6517 tnapi->hw_status = NULL;
6514 } 6518 }
6515 } 6519 }
6516 6520
6517 if (tp->hw_stats) { 6521 if (tp->hw_stats) {
6518 pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats), 6522 dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats),
6519 tp->hw_stats, tp->stats_mapping); 6523 tp->hw_stats, tp->stats_mapping);
6520 tp->hw_stats = NULL; 6524 tp->hw_stats = NULL;
6521 } 6525 }
6522} 6526}
@@ -6529,9 +6533,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)
6529{ 6533{
6530 int i; 6534 int i;
6531 6535
6532 tp->hw_stats = pci_alloc_consistent(tp->pdev, 6536 tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev,
6533 sizeof(struct tg3_hw_stats), 6537 sizeof(struct tg3_hw_stats),
6534 &tp->stats_mapping); 6538 &tp->stats_mapping,
6539 GFP_KERNEL);
6535 if (!tp->hw_stats) 6540 if (!tp->hw_stats)
6536 goto err_out; 6541 goto err_out;
6537 6542
@@ -6541,9 +6546,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)
6541 struct tg3_napi *tnapi = &tp->napi[i]; 6546 struct tg3_napi *tnapi = &tp->napi[i];
6542 struct tg3_hw_status *sblk; 6547 struct tg3_hw_status *sblk;
6543 6548
6544 tnapi->hw_status = pci_alloc_consistent(tp->pdev, 6549 tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev,
6545 TG3_HW_STATUS_SIZE, 6550 TG3_HW_STATUS_SIZE,
6546 &tnapi->status_mapping); 6551 &tnapi->status_mapping,
6552 GFP_KERNEL);
6547 if (!tnapi->hw_status) 6553 if (!tnapi->hw_status)
6548 goto err_out; 6554 goto err_out;
6549 6555
@@ -6564,9 +6570,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)
6564 if (!tnapi->tx_buffers) 6570 if (!tnapi->tx_buffers)
6565 goto err_out; 6571 goto err_out;
6566 6572
6567 tnapi->tx_ring = pci_alloc_consistent(tp->pdev, 6573 tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev,
6568 TG3_TX_RING_BYTES, 6574 TG3_TX_RING_BYTES,
6569 &tnapi->tx_desc_mapping); 6575 &tnapi->tx_desc_mapping,
6576 GFP_KERNEL);
6570 if (!tnapi->tx_ring) 6577 if (!tnapi->tx_ring)
6571 goto err_out; 6578 goto err_out;
6572 } 6579 }
@@ -6599,9 +6606,10 @@ static int tg3_alloc_consistent(struct tg3 *tp)
6599 if (!i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) 6606 if (!i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS))
6600 continue; 6607 continue;
6601 6608
6602 tnapi->rx_rcb = pci_alloc_consistent(tp->pdev, 6609 tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev,
6603 TG3_RX_RCB_RING_BYTES(tp), 6610 TG3_RX_RCB_RING_BYTES(tp),
6604 &tnapi->rx_rcb_mapping); 6611 &tnapi->rx_rcb_mapping,
6612 GFP_KERNEL);
6605 if (!tnapi->rx_rcb) 6613 if (!tnapi->rx_rcb)
6606 goto err_out; 6614 goto err_out;
6607 6615
@@ -14208,7 +14216,8 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
14208 u32 *buf, saved_dma_rwctrl; 14216 u32 *buf, saved_dma_rwctrl;
14209 int ret = 0; 14217 int ret = 0;
14210 14218
14211 buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma); 14219 buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE,
14220 &buf_dma, GFP_KERNEL);
14212 if (!buf) { 14221 if (!buf) {
14213 ret = -ENOMEM; 14222 ret = -ENOMEM;
14214 goto out_nofree; 14223 goto out_nofree;
@@ -14392,7 +14401,7 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
14392 } 14401 }
14393 14402
14394out: 14403out:
14395 pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma); 14404 dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma);
14396out_nofree: 14405out_nofree:
14397 return ret; 14406 return ret;
14398} 14407}