aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-09-11 07:52:51 -0400
committerDavid S. Miller <davem@davemloft.net>2008-09-11 07:52:51 -0400
commit90079ce89aa65e17f36ac2b09110720c51d874f4 (patch)
tree3ea630f89d77fb404cebe235d0a83516dae087f5 /drivers/net
parenta40c24a13366e324bc0ff8c3bb107db89312c984 (diff)
tg3: Use SKB DMA helper functions for TX.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/tg3.c88
-rw-r--r--drivers/net/tg3.h1
2 files changed, 31 insertions, 58 deletions
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 71d2c5cfdad9..355e8bcf6fed 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -3861,10 +3861,7 @@ static void tg3_tx(struct tg3 *tp)
3861 return; 3861 return;
3862 } 3862 }
3863 3863
3864 pci_unmap_single(tp->pdev, 3864 skb_dma_unmap(&tp->pdev->dev, skb, DMA_TO_DEVICE);
3865 pci_unmap_addr(ri, mapping),
3866 skb_headlen(skb),
3867 PCI_DMA_TODEVICE);
3868 3865
3869 ri->skb = NULL; 3866 ri->skb = NULL;
3870 3867
@@ -3874,12 +3871,6 @@ static void tg3_tx(struct tg3 *tp)
3874 ri = &tp->tx_buffers[sw_idx]; 3871 ri = &tp->tx_buffers[sw_idx];
3875 if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) 3872 if (unlikely(ri->skb != NULL || sw_idx == hw_idx))
3876 tx_bug = 1; 3873 tx_bug = 1;
3877
3878 pci_unmap_page(tp->pdev,
3879 pci_unmap_addr(ri, mapping),
3880 skb_shinfo(skb)->frags[i].size,
3881 PCI_DMA_TODEVICE);
3882
3883 sw_idx = NEXT_TX(sw_idx); 3874 sw_idx = NEXT_TX(sw_idx);
3884 } 3875 }
3885 3876
@@ -4633,12 +4624,13 @@ static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
4633 } else { 4624 } else {
4634 /* New SKB is guaranteed to be linear. */ 4625 /* New SKB is guaranteed to be linear. */
4635 entry = *start; 4626 entry = *start;
4636 new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, 4627 ret = skb_dma_map(&tp->pdev->dev, new_skb, DMA_TO_DEVICE);
4637 PCI_DMA_TODEVICE); 4628 new_addr = skb_shinfo(new_skb)->dma_maps[0];
4629
4638 /* Make sure new skb does not cross any 4G boundaries. 4630 /* Make sure new skb does not cross any 4G boundaries.
4639 * Drop the packet if it does. 4631 * Drop the packet if it does.
4640 */ 4632 */
4641 if (tg3_4g_overflow_test(new_addr, new_skb->len)) { 4633 if (ret || tg3_4g_overflow_test(new_addr, new_skb->len)) {
4642 ret = -1; 4634 ret = -1;
4643 dev_kfree_skb(new_skb); 4635 dev_kfree_skb(new_skb);
4644 new_skb = NULL; 4636 new_skb = NULL;
@@ -4652,18 +4644,8 @@ static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
4652 /* Now clean up the sw ring entries. */ 4644 /* Now clean up the sw ring entries. */
4653 i = 0; 4645 i = 0;
4654 while (entry != last_plus_one) { 4646 while (entry != last_plus_one) {
4655 int len;
4656
4657 if (i == 0)
4658 len = skb_headlen(skb);
4659 else
4660 len = skb_shinfo(skb)->frags[i-1].size;
4661 pci_unmap_single(tp->pdev,
4662 pci_unmap_addr(&tp->tx_buffers[entry], mapping),
4663 len, PCI_DMA_TODEVICE);
4664 if (i == 0) { 4647 if (i == 0) {
4665 tp->tx_buffers[entry].skb = new_skb; 4648 tp->tx_buffers[entry].skb = new_skb;
4666 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, new_addr);
4667 } else { 4649 } else {
4668 tp->tx_buffers[entry].skb = NULL; 4650 tp->tx_buffers[entry].skb = NULL;
4669 } 4651 }
@@ -4671,6 +4653,7 @@ static int tigon3_dma_hwbug_workaround(struct tg3 *tp, struct sk_buff *skb,
4671 i++; 4653 i++;
4672 } 4654 }
4673 4655
4656 skb_dma_unmap(&tp->pdev->dev, skb, DMA_TO_DEVICE);
4674 dev_kfree_skb(skb); 4657 dev_kfree_skb(skb);
4675 4658
4676 return ret; 4659 return ret;
@@ -4705,8 +4688,9 @@ static void tg3_set_txd(struct tg3 *tp, int entry,
4705static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) 4688static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
4706{ 4689{
4707 struct tg3 *tp = netdev_priv(dev); 4690 struct tg3 *tp = netdev_priv(dev);
4708 dma_addr_t mapping;
4709 u32 len, entry, base_flags, mss; 4691 u32 len, entry, base_flags, mss;
4692 struct skb_shared_info *sp;
4693 dma_addr_t mapping;
4710 4694
4711 len = skb_headlen(skb); 4695 len = skb_headlen(skb);
4712 4696
@@ -4765,11 +4749,16 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
4765 (vlan_tx_tag_get(skb) << 16)); 4749 (vlan_tx_tag_get(skb) << 16));
4766#endif 4750#endif
4767 4751
4768 /* Queue skb data, a.k.a. the main skb fragment. */ 4752 if (skb_dma_map(&tp->pdev->dev, skb, DMA_TO_DEVICE)) {
4769 mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); 4753 dev_kfree_skb(skb);
4754 goto out_unlock;
4755 }
4756
4757 sp = skb_shinfo(skb);
4758
4759 mapping = sp->dma_maps[0];
4770 4760
4771 tp->tx_buffers[entry].skb = skb; 4761 tp->tx_buffers[entry].skb = skb;
4772 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
4773 4762
4774 tg3_set_txd(tp, entry, mapping, len, base_flags, 4763 tg3_set_txd(tp, entry, mapping, len, base_flags,
4775 (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); 4764 (skb_shinfo(skb)->nr_frags == 0) | (mss << 1));
@@ -4785,13 +4774,8 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
4785 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 4774 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
4786 4775
4787 len = frag->size; 4776 len = frag->size;
4788 mapping = pci_map_page(tp->pdev, 4777 mapping = sp->dma_maps[i + 1];
4789 frag->page,
4790 frag->page_offset,
4791 len, PCI_DMA_TODEVICE);
4792
4793 tp->tx_buffers[entry].skb = NULL; 4778 tp->tx_buffers[entry].skb = NULL;
4794 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
4795 4779
4796 tg3_set_txd(tp, entry, mapping, len, 4780 tg3_set_txd(tp, entry, mapping, len,
4797 base_flags, (i == last) | (mss << 1)); 4781 base_flags, (i == last) | (mss << 1));
@@ -4859,9 +4843,10 @@ tg3_tso_bug_end:
4859static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev) 4843static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
4860{ 4844{
4861 struct tg3 *tp = netdev_priv(dev); 4845 struct tg3 *tp = netdev_priv(dev);
4862 dma_addr_t mapping;
4863 u32 len, entry, base_flags, mss; 4846 u32 len, entry, base_flags, mss;
4847 struct skb_shared_info *sp;
4864 int would_hit_hwbug; 4848 int would_hit_hwbug;
4849 dma_addr_t mapping;
4865 4850
4866 len = skb_headlen(skb); 4851 len = skb_headlen(skb);
4867 4852
@@ -4942,11 +4927,16 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
4942 (vlan_tx_tag_get(skb) << 16)); 4927 (vlan_tx_tag_get(skb) << 16));
4943#endif 4928#endif
4944 4929
4945 /* Queue skb data, a.k.a. the main skb fragment. */ 4930 if (skb_dma_map(&tp->pdev->dev, skb, DMA_TO_DEVICE)) {
4946 mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); 4931 dev_kfree_skb(skb);
4932 goto out_unlock;
4933 }
4934
4935 sp = skb_shinfo(skb);
4936
4937 mapping = sp->dma_maps[0];
4947 4938
4948 tp->tx_buffers[entry].skb = skb; 4939 tp->tx_buffers[entry].skb = skb;
4949 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
4950 4940
4951 would_hit_hwbug = 0; 4941 would_hit_hwbug = 0;
4952 4942
@@ -4969,13 +4959,9 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
4969 skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; 4959 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
4970 4960
4971 len = frag->size; 4961 len = frag->size;
4972 mapping = pci_map_page(tp->pdev, 4962 mapping = sp->dma_maps[i + 1];
4973 frag->page,
4974 frag->page_offset,
4975 len, PCI_DMA_TODEVICE);
4976 4963
4977 tp->tx_buffers[entry].skb = NULL; 4964 tp->tx_buffers[entry].skb = NULL;
4978 pci_unmap_addr_set(&tp->tx_buffers[entry], mapping, mapping);
4979 4965
4980 if (tg3_4g_overflow_test(mapping, len)) 4966 if (tg3_4g_overflow_test(mapping, len))
4981 would_hit_hwbug = 1; 4967 would_hit_hwbug = 1;
@@ -5128,7 +5114,6 @@ static void tg3_free_rings(struct tg3 *tp)
5128 for (i = 0; i < TG3_TX_RING_SIZE; ) { 5114 for (i = 0; i < TG3_TX_RING_SIZE; ) {
5129 struct tx_ring_info *txp; 5115 struct tx_ring_info *txp;
5130 struct sk_buff *skb; 5116 struct sk_buff *skb;
5131 int j;
5132 5117
5133 txp = &tp->tx_buffers[i]; 5118 txp = &tp->tx_buffers[i];
5134 skb = txp->skb; 5119 skb = txp->skb;
@@ -5138,22 +5123,11 @@ static void tg3_free_rings(struct tg3 *tp)
5138 continue; 5123 continue;
5139 } 5124 }
5140 5125
5141 pci_unmap_single(tp->pdev, 5126 skb_dma_unmap(&tp->pdev->dev, skb, DMA_TO_DEVICE);
5142 pci_unmap_addr(txp, mapping),
5143 skb_headlen(skb),
5144 PCI_DMA_TODEVICE);
5145 txp->skb = NULL;
5146 5127
5147 i++; 5128 txp->skb = NULL;
5148 5129
5149 for (j = 0; j < skb_shinfo(skb)->nr_frags; j++) { 5130 i += skb_shinfo(skb)->nr_frags + 1;
5150 txp = &tp->tx_buffers[i & (TG3_TX_RING_SIZE - 1)];
5151 pci_unmap_page(tp->pdev,
5152 pci_unmap_addr(txp, mapping),
5153 skb_shinfo(skb)->frags[j].size,
5154 PCI_DMA_TODEVICE);
5155 i++;
5156 }
5157 5131
5158 dev_kfree_skb_any(skb); 5132 dev_kfree_skb_any(skb);
5159 } 5133 }
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index f5b8cab8d4b5..6c7b5e303dbb 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2197,7 +2197,6 @@ struct ring_info {
2197 2197
2198struct tx_ring_info { 2198struct tx_ring_info {
2199 struct sk_buff *skb; 2199 struct sk_buff *skb;
2200 DECLARE_PCI_UNMAP_ADDR(mapping)
2201 u32 prev_vlan_tag; 2200 u32 prev_vlan_tag;
2202}; 2201};
2203 2202