Commit 64c42f69 authored by Andi Kleen's avatar Andi Kleen Committed by Jeff Garzik

[netdrvr] Fix IOMMU overflow checking in s2io.c

s2io has IOMMU overflow checking, but unfortunately it is wrong.

It didn't use the standard macros, which meant that it only worked
on POWER and SPARC because only those define DMA_ERROR_CODE. Convert it to
use the standard macros instead.

I also commented two more bugs in the IOMMU handling. It assumes
that 0 DMA addresses cannot happen, but that's not true in all IOMMU setups.
The information if a buffer has been already mapped needs to be stored
elsewhere.

Didn't fix those because it needs careful checking of the buffer handling
by the maintainers.

Cc: ram.vepa@neterion.com
Cc: santosh.rastapur@neterion.com
Cc: sivakumar.subramani@neterion.com
Cc: sreenivasa.honnur@neterion.com
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Signed-off-by: default avatarJeff Garzik <jgarzik@redhat.com>
parent 581abbc2
...@@ -2625,9 +2625,7 @@ static int fill_rx_buffers(struct ring_info *ring) ...@@ -2625,9 +2625,7 @@ static int fill_rx_buffers(struct ring_info *ring)
rxdp1->Buffer0_ptr = pci_map_single rxdp1->Buffer0_ptr = pci_map_single
(ring->pdev, skb->data, size - NET_IP_ALIGN, (ring->pdev, skb->data, size - NET_IP_ALIGN,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
if( (rxdp1->Buffer0_ptr == 0) || if(pci_dma_mapping_error(rxdp1->Buffer0_ptr))
(rxdp1->Buffer0_ptr ==
DMA_ERROR_CODE))
goto pci_map_failed; goto pci_map_failed;
rxdp->Control_2 = rxdp->Control_2 =
...@@ -2657,6 +2655,7 @@ static int fill_rx_buffers(struct ring_info *ring) ...@@ -2657,6 +2655,7 @@ static int fill_rx_buffers(struct ring_info *ring)
skb->data = (void *) (unsigned long)tmp; skb->data = (void *) (unsigned long)tmp;
skb_reset_tail_pointer(skb); skb_reset_tail_pointer(skb);
/* AK: check is wrong. 0 can be valid dma address */
if (!(rxdp3->Buffer0_ptr)) if (!(rxdp3->Buffer0_ptr))
rxdp3->Buffer0_ptr = rxdp3->Buffer0_ptr =
pci_map_single(ring->pdev, ba->ba_0, pci_map_single(ring->pdev, ba->ba_0,
...@@ -2665,8 +2664,7 @@ static int fill_rx_buffers(struct ring_info *ring) ...@@ -2665,8 +2664,7 @@ static int fill_rx_buffers(struct ring_info *ring)
pci_dma_sync_single_for_device(ring->pdev, pci_dma_sync_single_for_device(ring->pdev,
(dma_addr_t) rxdp3->Buffer0_ptr, (dma_addr_t) rxdp3->Buffer0_ptr,
BUF0_LEN, PCI_DMA_FROMDEVICE); BUF0_LEN, PCI_DMA_FROMDEVICE);
if( (rxdp3->Buffer0_ptr == 0) || if (pci_dma_mapping_error(rxdp3->Buffer0_ptr))
(rxdp3->Buffer0_ptr == DMA_ERROR_CODE))
goto pci_map_failed; goto pci_map_failed;
rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN); rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
...@@ -2681,18 +2679,17 @@ static int fill_rx_buffers(struct ring_info *ring) ...@@ -2681,18 +2679,17 @@ static int fill_rx_buffers(struct ring_info *ring)
(ring->pdev, skb->data, ring->mtu + 4, (ring->pdev, skb->data, ring->mtu + 4,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
if( (rxdp3->Buffer2_ptr == 0) || if (pci_dma_mapping_error(rxdp3->Buffer2_ptr))
(rxdp3->Buffer2_ptr == DMA_ERROR_CODE))
goto pci_map_failed; goto pci_map_failed;
/* AK: check is wrong */
if (!rxdp3->Buffer1_ptr) if (!rxdp3->Buffer1_ptr)
rxdp3->Buffer1_ptr = rxdp3->Buffer1_ptr =
pci_map_single(ring->pdev, pci_map_single(ring->pdev,
ba->ba_1, BUF1_LEN, ba->ba_1, BUF1_LEN,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
if( (rxdp3->Buffer1_ptr == 0) || if (pci_dma_mapping_error(rxdp3->Buffer1_ptr)) {
(rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
pci_unmap_single pci_unmap_single
(ring->pdev, (ring->pdev,
(dma_addr_t)(unsigned long) (dma_addr_t)(unsigned long)
...@@ -4264,16 +4261,14 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -4264,16 +4261,14 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
txdp->Buffer_Pointer = pci_map_single(sp->pdev, txdp->Buffer_Pointer = pci_map_single(sp->pdev,
fifo->ufo_in_band_v, fifo->ufo_in_band_v,
sizeof(u64), PCI_DMA_TODEVICE); sizeof(u64), PCI_DMA_TODEVICE);
if((txdp->Buffer_Pointer == 0) || if (pci_dma_mapping_error(txdp->Buffer_Pointer))
(txdp->Buffer_Pointer == DMA_ERROR_CODE))
goto pci_map_failed; goto pci_map_failed;
txdp++; txdp++;
} }
txdp->Buffer_Pointer = pci_map_single txdp->Buffer_Pointer = pci_map_single
(sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE); (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
if((txdp->Buffer_Pointer == 0) || if (pci_dma_mapping_error(txdp->Buffer_Pointer))
(txdp->Buffer_Pointer == DMA_ERROR_CODE))
goto pci_map_failed; goto pci_map_failed;
txdp->Host_Control = (unsigned long) skb; txdp->Host_Control = (unsigned long) skb;
...@@ -6884,10 +6879,8 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, ...@@ -6884,10 +6879,8 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
pci_map_single( sp->pdev, (*skb)->data, pci_map_single( sp->pdev, (*skb)->data,
size - NET_IP_ALIGN, size - NET_IP_ALIGN,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
if( (rxdp1->Buffer0_ptr == 0) || if (pci_dma_mapping_error(rxdp1->Buffer0_ptr))
(rxdp1->Buffer0_ptr == DMA_ERROR_CODE)) {
goto memalloc_failed; goto memalloc_failed;
}
rxdp->Host_Control = (unsigned long) (*skb); rxdp->Host_Control = (unsigned long) (*skb);
} }
} else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) { } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) {
...@@ -6913,15 +6906,12 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, ...@@ -6913,15 +6906,12 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
pci_map_single(sp->pdev, (*skb)->data, pci_map_single(sp->pdev, (*skb)->data,
dev->mtu + 4, dev->mtu + 4,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
if( (rxdp3->Buffer2_ptr == 0) || if (pci_dma_mapping_error(rxdp3->Buffer2_ptr))
(rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) {
goto memalloc_failed; goto memalloc_failed;
}
rxdp3->Buffer0_ptr = *temp0 = rxdp3->Buffer0_ptr = *temp0 =
pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN, pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
if( (rxdp3->Buffer0_ptr == 0) || if (pci_dma_mapping_error(rxdp3->Buffer0_ptr)) {
(rxdp3->Buffer0_ptr == DMA_ERROR_CODE)) {
pci_unmap_single (sp->pdev, pci_unmap_single (sp->pdev,
(dma_addr_t)rxdp3->Buffer2_ptr, (dma_addr_t)rxdp3->Buffer2_ptr,
dev->mtu + 4, PCI_DMA_FROMDEVICE); dev->mtu + 4, PCI_DMA_FROMDEVICE);
...@@ -6933,8 +6923,7 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp, ...@@ -6933,8 +6923,7 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
rxdp3->Buffer1_ptr = *temp1 = rxdp3->Buffer1_ptr = *temp1 =
pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN, pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
PCI_DMA_FROMDEVICE); PCI_DMA_FROMDEVICE);
if( (rxdp3->Buffer1_ptr == 0) || if (pci_dma_mapping_error(rxdp3->Buffer1_ptr)) {
(rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
pci_unmap_single (sp->pdev, pci_unmap_single (sp->pdev,
(dma_addr_t)rxdp3->Buffer0_ptr, (dma_addr_t)rxdp3->Buffer0_ptr,
BUF0_LEN, PCI_DMA_FROMDEVICE); BUF0_LEN, PCI_DMA_FROMDEVICE);
......
...@@ -75,10 +75,6 @@ static int debug_level = ERR_DBG; ...@@ -75,10 +75,6 @@ static int debug_level = ERR_DBG;
/* DEBUG message print. */ /* DEBUG message print. */
#define DBG_PRINT(dbg_level, args...) if(!(debug_level<dbg_level)) printk(args) #define DBG_PRINT(dbg_level, args...) if(!(debug_level<dbg_level)) printk(args)
#ifndef DMA_ERROR_CODE
#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
#endif
/* Protocol assist features of the NIC */ /* Protocol assist features of the NIC */
#define L3_CKSUM_OK 0xFFFF #define L3_CKSUM_OK 0xFFFF
#define L4_CKSUM_OK 0xFFFF #define L4_CKSUM_OK 0xFFFF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment