Re: Consistent PCI - API change needed

From: Jakub Jelinek (jakub@redhat.com)
Date: Sat Feb 12 2000 - 02:43:22 EST


On Fri, Feb 11, 2000 at 04:33:07PM -0800, David S. Miller wrote:
> From: Russell King <rmk@arm.linux.org.uk>
> Date: Fri, 11 Feb 2000 22:37:22 +0000 (GMT)
>
> I've just been reviewing the changes to 3c59x.c, and have noticed
> the following line of code:
>
> vp->rx_ring = (void *)(((long)vp->priv_addr + 15) & ~15);
>
> Can someone explain the purpose of this please?
>
> The rx ring needs to be 16-byte aligned, so 15 bytes of slop are
> added the to allocation size and it is aligned here.

Sorry, it should go. It was in the original driver before dynamic DMA was
put it, and as i386 pci_alloc_consistent used kmalloc at the time I was
hacking it, I kept it in. When Linus later asked for pci_alloc_consistent to
use gfp, I forgot about it.
The Documentation/DMA-mapping.txt is right on it, pci_alloc_consistent has
to ensure at least PAGE_SIZE alignment.

Here is the patch (removes to unnecessary structure members so it is nice):

--- linux/drivers/net/3c59x.c.jj Sat Feb 12 08:23:38 2000
+++ linux/drivers/net/3c59x.c Sat Feb 12 08:27:17 2000
@@ -402,8 +402,6 @@ struct vortex_private {
         struct sk_buff* rx_skbuff[RX_RING_SIZE];
         struct sk_buff* tx_skbuff[TX_RING_SIZE];
         struct net_device *next_module;
- void *priv_addr;
- dma_addr_t ring_dma;
         unsigned int cur_rx, cur_tx; /* The next free ring entry */
         unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
         struct net_device_stats stats;
@@ -768,13 +766,11 @@ static struct net_device *vortex_probe1(
         vp->pci_devfn = pdev == NULL ? 0 : pdev->devfn;
         vp->pdev = pdev;
 
- vp->priv_addr = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
- + sizeof(struct boom_tx_desc) * TX_RING_SIZE
- + 15, &vp->ring_dma);
- /* Make sure rings are 16 byte aligned. */
- vp->rx_ring = (void *)(((long)vp->priv_addr + 15) & ~15);
+ /* Makes sure rings are at least 16 byte aligned. */
+ vp->rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
+ + sizeof(struct boom_tx_desc) * TX_RING_SIZE,
+ &vp->rx_ring_dma);
         vp->tx_ring = (struct boom_tx_desc *)(vp->rx_ring + RX_RING_SIZE);
- vp->rx_ring_dma = (vp->ring_dma + 15) & ~15;
         vp->tx_ring_dma = vp->rx_ring_dma + sizeof(struct boom_rx_desc) * RX_RING_SIZE;
 
         /* The lower four bits are the media type. */
@@ -2061,7 +2057,7 @@ static void __exit vortex_cleanup_module
                 kfree(root_vortex_dev);
                 pci_free_consistent(vp->pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
                                             + sizeof(struct boom_tx_desc) * TX_RING_SIZE
- + 15, vp->priv_addr, vp->ring_dma);
+ + 15, vp->rx_ring, vp->rx_ring_dma);
                 kfree(vp);
                 root_vortex_dev = next_dev;
         }

Cheers,
    Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.43 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Feb 15 2000 - 21:00:22 EST