Commit 3daebfbe authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by David S. Miller

net: tulip: convert to devres

Works fine on my HP C3600:

[  274.452394] tulip0: no phy info, aborting mtable build
[  274.499041] tulip0:  MII transceiver #1 config 1000 status 782d advertising 01e1
[  274.750691] net eth0: Digital DS21142/43 Tulip rev 65 at MMIO 0xf4008000, 00:30:6e:08:7d:21, IRQ 17
[  283.104520] net eth0: Setting full-duplex based on MII#1 link partner capability of c1e1
Signed-off-by: default avatarRolf Eike Beer <eike-kernel@sf-tec.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 382d917b
...@@ -117,7 +117,7 @@ static void tulip_build_fake_mediatable(struct tulip_private *tp) ...@@ -117,7 +117,7 @@ static void tulip_build_fake_mediatable(struct tulip_private *tp)
0x00, 0x06 /* ttm bit map */ 0x00, 0x06 /* ttm bit map */
}; };
tp->mtable = kmalloc(sizeof(struct mediatable) + tp->mtable = devm_kmalloc(&tp->pdev->pdev, sizeof(struct mediatable) +
sizeof(struct medialeaf), GFP_KERNEL); sizeof(struct medialeaf), GFP_KERNEL);
if (tp->mtable == NULL) if (tp->mtable == NULL)
...@@ -224,7 +224,8 @@ void tulip_parse_eeprom(struct net_device *dev) ...@@ -224,7 +224,8 @@ void tulip_parse_eeprom(struct net_device *dev)
return; return;
} }
mtable = kmalloc(struct_size(mtable, mleaf, count), GFP_KERNEL); mtable = devm_kmalloc(&tp->pdev->dev, struct_size(mtable, mleaf, count),
GFP_KERNEL);
if (mtable == NULL) if (mtable == NULL)
return; /* Horrible, impossible failure. */ return; /* Horrible, impossible failure. */
last_mediatable = tp->mtable = mtable; last_mediatable = tp->mtable = mtable;
......
...@@ -1389,7 +1389,7 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1389,7 +1389,7 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
* And back to business * And back to business
*/ */
i = pci_enable_device(pdev); i = pcim_enable_device(pdev);
if (i) { if (i) {
pr_err("Cannot enable tulip board #%d, aborting\n", board_idx); pr_err("Cannot enable tulip board #%d, aborting\n", board_idx);
return i; return i;
...@@ -1398,11 +1398,9 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1398,11 +1398,9 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
irq = pdev->irq; irq = pdev->irq;
/* alloc_etherdev ensures aligned and zeroed private structures */ /* alloc_etherdev ensures aligned and zeroed private structures */
dev = alloc_etherdev (sizeof (*tp)); dev = devm_alloc_etherdev(&pdev->dev, sizeof(*tp));
if (!dev) { if (!dev)
pci_disable_device(pdev);
return -ENOMEM; return -ENOMEM;
}
SET_NETDEV_DEV(dev, &pdev->dev); SET_NETDEV_DEV(dev, &pdev->dev);
if (pci_resource_len (pdev, 0) < tulip_tbl[chip_idx].io_size) { if (pci_resource_len (pdev, 0) < tulip_tbl[chip_idx].io_size) {
...@@ -1410,18 +1408,18 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1410,18 +1408,18 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
pci_name(pdev), pci_name(pdev),
(unsigned long long)pci_resource_len (pdev, 0), (unsigned long long)pci_resource_len (pdev, 0),
(unsigned long long)pci_resource_start (pdev, 0)); (unsigned long long)pci_resource_start (pdev, 0));
goto err_out_free_netdev; return -ENODEV;
} }
/* grab all resources from both PIO and MMIO regions, as we /* grab all resources from both PIO and MMIO regions, as we
* don't want anyone else messing around with our hardware */ * don't want anyone else messing around with our hardware */
if (pci_request_regions (pdev, DRV_NAME)) if (pci_request_regions(pdev, DRV_NAME))
goto err_out_free_netdev; return -ENODEV;
ioaddr = pci_iomap(pdev, TULIP_BAR, tulip_tbl[chip_idx].io_size); ioaddr = pcim_iomap(pdev, TULIP_BAR, tulip_tbl[chip_idx].io_size);
if (!ioaddr) if (!ioaddr)
goto err_out_free_res; return -ENODEV;
/* /*
* initialize private data structure 'tp' * initialize private data structure 'tp'
...@@ -1430,12 +1428,12 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1430,12 +1428,12 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
tp = netdev_priv(dev); tp = netdev_priv(dev);
tp->dev = dev; tp->dev = dev;
tp->rx_ring = dma_alloc_coherent(&pdev->dev, tp->rx_ring = dmam_alloc_coherent(&pdev->dev,
sizeof(struct tulip_rx_desc) * RX_RING_SIZE + sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
sizeof(struct tulip_tx_desc) * TX_RING_SIZE, sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
&tp->rx_ring_dma, GFP_KERNEL); &tp->rx_ring_dma, GFP_KERNEL);
if (!tp->rx_ring) if (!tp->rx_ring)
goto err_out_mtable; return -ENODEV;
tp->tx_ring = (struct tulip_tx_desc *)(tp->rx_ring + RX_RING_SIZE); tp->tx_ring = (struct tulip_tx_desc *)(tp->rx_ring + RX_RING_SIZE);
tp->tx_ring_dma = tp->rx_ring_dma + sizeof(struct tulip_rx_desc) * RX_RING_SIZE; tp->tx_ring_dma = tp->rx_ring_dma + sizeof(struct tulip_rx_desc) * RX_RING_SIZE;
...@@ -1695,8 +1693,9 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1695,8 +1693,9 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
#endif #endif
dev->ethtool_ops = &ops; dev->ethtool_ops = &ops;
if (register_netdev(dev)) i = register_netdev(dev);
goto err_out_free_ring; if (i)
return i;
pci_set_drvdata(pdev, dev); pci_set_drvdata(pdev, dev);
...@@ -1771,24 +1770,6 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1771,24 +1770,6 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
tulip_set_power_state (tp, 0, 1); tulip_set_power_state (tp, 0, 1);
return 0; return 0;
err_out_free_ring:
dma_free_coherent(&pdev->dev,
sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
tp->rx_ring, tp->rx_ring_dma);
err_out_mtable:
kfree (tp->mtable);
pci_iounmap(pdev, ioaddr);
err_out_free_res:
pci_release_regions (pdev);
err_out_free_netdev:
free_netdev (dev);
pci_disable_device(pdev);
return -ENODEV;
} }
...@@ -1888,24 +1869,11 @@ static int __maybe_unused tulip_resume(struct device *dev_d) ...@@ -1888,24 +1869,11 @@ static int __maybe_unused tulip_resume(struct device *dev_d)
static void tulip_remove_one(struct pci_dev *pdev) static void tulip_remove_one(struct pci_dev *pdev)
{ {
struct net_device *dev = pci_get_drvdata (pdev); struct net_device *dev = pci_get_drvdata (pdev);
struct tulip_private *tp;
if (!dev) if (!dev)
return; return;
tp = netdev_priv(dev);
unregister_netdev(dev); unregister_netdev(dev);
dma_free_coherent(&pdev->dev,
sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
tp->rx_ring, tp->rx_ring_dma);
kfree (tp->mtable);
pci_iounmap(pdev, tp->base_addr);
free_netdev (dev);
pci_release_regions (pdev);
pci_disable_device(pdev);
/* pci_power_off (pdev, -1); */
} }
#ifdef CONFIG_NET_POLL_CONTROLLER #ifdef CONFIG_NET_POLL_CONTROLLER
......
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