Commit 7f3bb7f5 authored by Christoph Hellwig's avatar Christoph Hellwig
Browse files

sgiseeq: convert to dma_alloc_noncoherent



Use the new non-coherent DMA API including proper ownership transfers.
This includes adding additional calls to dma_sync_desc_dev as the
old syncing was rather ad-hoc.

Thanks to Thomas Bogendoerfer for debugging the ownership transfer
issues.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Tested-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
parent 00718b23
Loading
Loading
Loading
Loading
+18 −10
Original line number Diff line number Diff line
@@ -112,14 +112,18 @@ struct sgiseeq_private {

static inline void dma_sync_desc_cpu(struct net_device *dev, void *addr)
{
	dma_cache_sync(dev->dev.parent, addr, sizeof(struct sgiseeq_rx_desc),
		       DMA_FROM_DEVICE);
	struct sgiseeq_private *sp = netdev_priv(dev);

	dma_sync_single_for_cpu(dev->dev.parent, VIRT_TO_DMA(sp, addr),
			sizeof(struct sgiseeq_rx_desc), DMA_BIDIRECTIONAL);
}

static inline void dma_sync_desc_dev(struct net_device *dev, void *addr)
{
	dma_cache_sync(dev->dev.parent, addr, sizeof(struct sgiseeq_rx_desc),
		       DMA_TO_DEVICE);
	struct sgiseeq_private *sp = netdev_priv(dev);

	dma_sync_single_for_device(dev->dev.parent, VIRT_TO_DMA(sp, addr),
			sizeof(struct sgiseeq_rx_desc), DMA_BIDIRECTIONAL);
}

static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
@@ -403,6 +407,8 @@ memory_squeeze:
		rd = &sp->rx_desc[sp->rx_new];
		dma_sync_desc_cpu(dev, rd);
	}
	dma_sync_desc_dev(dev, rd);

	dma_sync_desc_cpu(dev, &sp->rx_desc[orig_end]);
	sp->rx_desc[orig_end].rdma.cntinfo &= ~(HPCDMA_EOR);
	dma_sync_desc_dev(dev, &sp->rx_desc[orig_end]);
@@ -443,6 +449,7 @@ static inline void kick_tx(struct net_device *dev,
		dma_sync_desc_cpu(dev, td);
	}
	if (td->tdma.cntinfo & HPCDMA_XIU) {
		dma_sync_desc_dev(dev, td);
		hregs->tx_ndptr = VIRT_TO_DMA(sp, td);
		hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
	}
@@ -476,6 +483,7 @@ static inline void sgiseeq_tx(struct net_device *dev, struct sgiseeq_private *sp
		if (!(td->tdma.cntinfo & (HPCDMA_XIU)))
			break;
		if (!(td->tdma.cntinfo & (HPCDMA_ETXD))) {
			dma_sync_desc_dev(dev, td);
			if (!(status & HPC3_ETXCTRL_ACTIVE)) {
				hregs->tx_ndptr = VIRT_TO_DMA(sp, td);
				hregs->tx_ctrl = HPC3_ETXCTRL_ACTIVE;
@@ -740,8 +748,8 @@ static int sgiseeq_probe(struct platform_device *pdev)
	sp = netdev_priv(dev);

	/* Make private data page aligned */
	sr = dma_alloc_attrs(&pdev->dev, sizeof(*sp->srings), &sp->srings_dma,
			     GFP_KERNEL, DMA_ATTR_NON_CONSISTENT);
	sr = dma_alloc_noncoherent(&pdev->dev, sizeof(*sp->srings),
			&sp->srings_dma, DMA_BIDIRECTIONAL, GFP_KERNEL);
	if (!sr) {
		printk(KERN_ERR "Sgiseeq: Page alloc failed, aborting.\n");
		err = -ENOMEM;
@@ -802,8 +810,8 @@ static int sgiseeq_probe(struct platform_device *pdev)
	return 0;

err_out_free_attrs:
	dma_free_attrs(&pdev->dev, sizeof(*sp->srings), sp->srings,
		       sp->srings_dma, DMA_ATTR_NON_CONSISTENT);
	dma_free_noncoherent(&pdev->dev, sizeof(*sp->srings), sp->srings,
		       sp->srings_dma, DMA_BIDIRECTIONAL);
err_out_free_dev:
	free_netdev(dev);

@@ -817,8 +825,8 @@ static int sgiseeq_remove(struct platform_device *pdev)
	struct sgiseeq_private *sp = netdev_priv(dev);

	unregister_netdev(dev);
	dma_free_attrs(&pdev->dev, sizeof(*sp->srings), sp->srings,
		       sp->srings_dma, DMA_ATTR_NON_CONSISTENT);
	dma_free_noncoherent(&pdev->dev, sizeof(*sp->srings), sp->srings,
		       sp->srings_dma, DMA_BIDIRECTIONAL);
	free_netdev(dev);

	return 0;