| .. | .. |
|---|
| 30 | 30 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 31 | 31 | |
|---|
| 32 | 32 | #define DRV_NAME "de2104x" |
|---|
| 33 | | -#define DRV_VERSION "0.7" |
|---|
| 34 | 33 | #define DRV_RELDATE "Mar 17, 2004" |
|---|
| 35 | 34 | |
|---|
| 36 | 35 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 52 | 51 | #include <linux/uaccess.h> |
|---|
| 53 | 52 | #include <asm/unaligned.h> |
|---|
| 54 | 53 | |
|---|
| 55 | | -/* These identify the driver base version and may not be removed. */ |
|---|
| 56 | | -static char version[] = |
|---|
| 57 | | -"PCI Ethernet driver v" DRV_VERSION " (" DRV_RELDATE ")"; |
|---|
| 58 | | - |
|---|
| 59 | 54 | MODULE_AUTHOR("Jeff Garzik <jgarzik@pobox.com>"); |
|---|
| 60 | 55 | MODULE_DESCRIPTION("Intel/Digital 21040/1 series PCI Ethernet driver"); |
|---|
| 61 | 56 | MODULE_LICENSE("GPL"); |
|---|
| 62 | | -MODULE_VERSION(DRV_VERSION); |
|---|
| 63 | 57 | |
|---|
| 64 | 58 | static int debug = -1; |
|---|
| 65 | 59 | module_param (debug, int, 0); |
|---|
| .. | .. |
|---|
| 417 | 411 | if (status & DescOwn) |
|---|
| 418 | 412 | break; |
|---|
| 419 | 413 | |
|---|
| 420 | | - len = ((status >> 16) & 0x7ff) - 4; |
|---|
| 414 | + /* the length is actually a 15 bit value here according |
|---|
| 415 | + * to Table 4-1 in the DE2104x spec so mask is 0x7fff |
|---|
| 416 | + */ |
|---|
| 417 | + len = ((status >> 16) & 0x7fff) - 4; |
|---|
| 421 | 418 | mapping = de->rx_skb[rx_tail].mapping; |
|---|
| 422 | 419 | |
|---|
| 423 | 420 | if (unlikely(drop)) { |
|---|
| .. | .. |
|---|
| 446 | 443 | } |
|---|
| 447 | 444 | |
|---|
| 448 | 445 | if (!copying_skb) { |
|---|
| 449 | | - pci_unmap_single(de->pdev, mapping, |
|---|
| 450 | | - buflen, PCI_DMA_FROMDEVICE); |
|---|
| 446 | + dma_unmap_single(&de->pdev->dev, mapping, buflen, |
|---|
| 447 | + DMA_FROM_DEVICE); |
|---|
| 451 | 448 | skb_put(skb, len); |
|---|
| 452 | 449 | |
|---|
| 453 | 450 | mapping = |
|---|
| 454 | 451 | de->rx_skb[rx_tail].mapping = |
|---|
| 455 | | - pci_map_single(de->pdev, copy_skb->data, |
|---|
| 456 | | - buflen, PCI_DMA_FROMDEVICE); |
|---|
| 452 | + dma_map_single(&de->pdev->dev, copy_skb->data, |
|---|
| 453 | + buflen, DMA_FROM_DEVICE); |
|---|
| 457 | 454 | de->rx_skb[rx_tail].skb = copy_skb; |
|---|
| 458 | 455 | } else { |
|---|
| 459 | | - pci_dma_sync_single_for_cpu(de->pdev, mapping, len, PCI_DMA_FROMDEVICE); |
|---|
| 456 | + dma_sync_single_for_cpu(&de->pdev->dev, mapping, len, |
|---|
| 457 | + DMA_FROM_DEVICE); |
|---|
| 460 | 458 | skb_reserve(copy_skb, RX_OFFSET); |
|---|
| 461 | 459 | skb_copy_from_linear_data(skb, skb_put(copy_skb, len), |
|---|
| 462 | 460 | len); |
|---|
| 463 | | - pci_dma_sync_single_for_device(de->pdev, mapping, len, PCI_DMA_FROMDEVICE); |
|---|
| 461 | + dma_sync_single_for_device(&de->pdev->dev, mapping, |
|---|
| 462 | + len, DMA_FROM_DEVICE); |
|---|
| 464 | 463 | |
|---|
| 465 | 464 | /* We'll reuse the original ring buffer. */ |
|---|
| 466 | 465 | skb = copy_skb; |
|---|
| .. | .. |
|---|
| 557 | 556 | goto next; |
|---|
| 558 | 557 | |
|---|
| 559 | 558 | if (unlikely(skb == DE_SETUP_SKB)) { |
|---|
| 560 | | - pci_unmap_single(de->pdev, de->tx_skb[tx_tail].mapping, |
|---|
| 561 | | - sizeof(de->setup_frame), PCI_DMA_TODEVICE); |
|---|
| 559 | + dma_unmap_single(&de->pdev->dev, |
|---|
| 560 | + de->tx_skb[tx_tail].mapping, |
|---|
| 561 | + sizeof(de->setup_frame), |
|---|
| 562 | + DMA_TO_DEVICE); |
|---|
| 562 | 563 | goto next; |
|---|
| 563 | 564 | } |
|---|
| 564 | 565 | |
|---|
| 565 | | - pci_unmap_single(de->pdev, de->tx_skb[tx_tail].mapping, |
|---|
| 566 | | - skb->len, PCI_DMA_TODEVICE); |
|---|
| 566 | + dma_unmap_single(&de->pdev->dev, de->tx_skb[tx_tail].mapping, |
|---|
| 567 | + skb->len, DMA_TO_DEVICE); |
|---|
| 567 | 568 | |
|---|
| 568 | 569 | if (status & LastFrag) { |
|---|
| 569 | 570 | if (status & TxError) { |
|---|
| .. | .. |
|---|
| 585 | 586 | netif_dbg(de, tx_done, de->dev, |
|---|
| 586 | 587 | "tx done, slot %d\n", tx_tail); |
|---|
| 587 | 588 | } |
|---|
| 588 | | - dev_kfree_skb_irq(skb); |
|---|
| 589 | + dev_consume_skb_irq(skb); |
|---|
| 589 | 590 | } |
|---|
| 590 | 591 | |
|---|
| 591 | 592 | next: |
|---|
| .. | .. |
|---|
| 623 | 624 | txd = &de->tx_ring[entry]; |
|---|
| 624 | 625 | |
|---|
| 625 | 626 | len = skb->len; |
|---|
| 626 | | - mapping = pci_map_single(de->pdev, skb->data, len, PCI_DMA_TODEVICE); |
|---|
| 627 | + mapping = dma_map_single(&de->pdev->dev, skb->data, len, |
|---|
| 628 | + DMA_TO_DEVICE); |
|---|
| 627 | 629 | if (entry == (DE_TX_RING_SIZE - 1)) |
|---|
| 628 | 630 | flags |= RingEnd; |
|---|
| 629 | 631 | if (!tx_free || (tx_free == (DE_TX_RING_SIZE / 2))) |
|---|
| .. | .. |
|---|
| 766 | 768 | |
|---|
| 767 | 769 | de->tx_skb[entry].skb = DE_SETUP_SKB; |
|---|
| 768 | 770 | de->tx_skb[entry].mapping = mapping = |
|---|
| 769 | | - pci_map_single (de->pdev, de->setup_frame, |
|---|
| 770 | | - sizeof (de->setup_frame), PCI_DMA_TODEVICE); |
|---|
| 771 | + dma_map_single(&de->pdev->dev, de->setup_frame, |
|---|
| 772 | + sizeof(de->setup_frame), DMA_TO_DEVICE); |
|---|
| 771 | 773 | |
|---|
| 772 | 774 | /* Put the setup frame on the Tx list. */ |
|---|
| 773 | 775 | txd = &de->tx_ring[entry]; |
|---|
| .. | .. |
|---|
| 1282 | 1284 | if (!skb) |
|---|
| 1283 | 1285 | goto err_out; |
|---|
| 1284 | 1286 | |
|---|
| 1285 | | - de->rx_skb[i].mapping = pci_map_single(de->pdev, |
|---|
| 1286 | | - skb->data, de->rx_buf_sz, PCI_DMA_FROMDEVICE); |
|---|
| 1287 | + de->rx_skb[i].mapping = dma_map_single(&de->pdev->dev, |
|---|
| 1288 | + skb->data, |
|---|
| 1289 | + de->rx_buf_sz, |
|---|
| 1290 | + DMA_FROM_DEVICE); |
|---|
| 1287 | 1291 | de->rx_skb[i].skb = skb; |
|---|
| 1288 | 1292 | |
|---|
| 1289 | 1293 | de->rx_ring[i].opts1 = cpu_to_le32(DescOwn); |
|---|
| .. | .. |
|---|
| 1316 | 1320 | |
|---|
| 1317 | 1321 | static int de_alloc_rings (struct de_private *de) |
|---|
| 1318 | 1322 | { |
|---|
| 1319 | | - de->rx_ring = pci_alloc_consistent(de->pdev, DE_RING_BYTES, &de->ring_dma); |
|---|
| 1323 | + de->rx_ring = dma_alloc_coherent(&de->pdev->dev, DE_RING_BYTES, |
|---|
| 1324 | + &de->ring_dma, GFP_KERNEL); |
|---|
| 1320 | 1325 | if (!de->rx_ring) |
|---|
| 1321 | 1326 | return -ENOMEM; |
|---|
| 1322 | 1327 | de->tx_ring = &de->rx_ring[DE_RX_RING_SIZE]; |
|---|
| .. | .. |
|---|
| 1336 | 1341 | |
|---|
| 1337 | 1342 | for (i = 0; i < DE_RX_RING_SIZE; i++) { |
|---|
| 1338 | 1343 | if (de->rx_skb[i].skb) { |
|---|
| 1339 | | - pci_unmap_single(de->pdev, de->rx_skb[i].mapping, |
|---|
| 1340 | | - de->rx_buf_sz, PCI_DMA_FROMDEVICE); |
|---|
| 1344 | + dma_unmap_single(&de->pdev->dev, |
|---|
| 1345 | + de->rx_skb[i].mapping, de->rx_buf_sz, |
|---|
| 1346 | + DMA_FROM_DEVICE); |
|---|
| 1341 | 1347 | dev_kfree_skb(de->rx_skb[i].skb); |
|---|
| 1342 | 1348 | } |
|---|
| 1343 | 1349 | } |
|---|
| .. | .. |
|---|
| 1347 | 1353 | if ((skb) && (skb != DE_DUMMY_SKB)) { |
|---|
| 1348 | 1354 | if (skb != DE_SETUP_SKB) { |
|---|
| 1349 | 1355 | de->dev->stats.tx_dropped++; |
|---|
| 1350 | | - pci_unmap_single(de->pdev, |
|---|
| 1351 | | - de->tx_skb[i].mapping, |
|---|
| 1352 | | - skb->len, PCI_DMA_TODEVICE); |
|---|
| 1356 | + dma_unmap_single(&de->pdev->dev, |
|---|
| 1357 | + de->tx_skb[i].mapping, |
|---|
| 1358 | + skb->len, DMA_TO_DEVICE); |
|---|
| 1353 | 1359 | dev_kfree_skb(skb); |
|---|
| 1354 | 1360 | } else { |
|---|
| 1355 | | - pci_unmap_single(de->pdev, |
|---|
| 1356 | | - de->tx_skb[i].mapping, |
|---|
| 1357 | | - sizeof(de->setup_frame), |
|---|
| 1358 | | - PCI_DMA_TODEVICE); |
|---|
| 1361 | + dma_unmap_single(&de->pdev->dev, |
|---|
| 1362 | + de->tx_skb[i].mapping, |
|---|
| 1363 | + sizeof(de->setup_frame), |
|---|
| 1364 | + DMA_TO_DEVICE); |
|---|
| 1359 | 1365 | } |
|---|
| 1360 | 1366 | } |
|---|
| 1361 | 1367 | } |
|---|
| .. | .. |
|---|
| 1367 | 1373 | static void de_free_rings (struct de_private *de) |
|---|
| 1368 | 1374 | { |
|---|
| 1369 | 1375 | de_clean_rings(de); |
|---|
| 1370 | | - pci_free_consistent(de->pdev, DE_RING_BYTES, de->rx_ring, de->ring_dma); |
|---|
| 1376 | + dma_free_coherent(&de->pdev->dev, DE_RING_BYTES, de->rx_ring, |
|---|
| 1377 | + de->ring_dma); |
|---|
| 1371 | 1378 | de->rx_ring = NULL; |
|---|
| 1372 | 1379 | de->tx_ring = NULL; |
|---|
| 1373 | 1380 | } |
|---|
| .. | .. |
|---|
| 1436 | 1443 | return 0; |
|---|
| 1437 | 1444 | } |
|---|
| 1438 | 1445 | |
|---|
| 1439 | | -static void de_tx_timeout (struct net_device *dev) |
|---|
| 1446 | +static void de_tx_timeout (struct net_device *dev, unsigned int txqueue) |
|---|
| 1440 | 1447 | { |
|---|
| 1441 | 1448 | struct de_private *de = netdev_priv(dev); |
|---|
| 1442 | 1449 | const int irq = de->pdev->irq; |
|---|
| .. | .. |
|---|
| 1600 | 1607 | struct de_private *de = netdev_priv(dev); |
|---|
| 1601 | 1608 | |
|---|
| 1602 | 1609 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
|---|
| 1603 | | - strlcpy(info->version, DRV_VERSION, sizeof(info->version)); |
|---|
| 1604 | 1610 | strlcpy(info->bus_info, pci_name(de->pdev), sizeof(info->bus_info)); |
|---|
| 1605 | 1611 | } |
|---|
| 1606 | 1612 | |
|---|
| .. | .. |
|---|
| 1977 | 1983 | |
|---|
| 1978 | 1984 | board_idx++; |
|---|
| 1979 | 1985 | |
|---|
| 1980 | | -#ifndef MODULE |
|---|
| 1981 | | - if (board_idx == 0) |
|---|
| 1982 | | - pr_info("%s\n", version); |
|---|
| 1983 | | -#endif |
|---|
| 1984 | | - |
|---|
| 1985 | 1986 | /* allocate a new ethernet device structure, and fill in defaults */ |
|---|
| 1986 | 1987 | dev = alloc_etherdev(sizeof(struct de_private)); |
|---|
| 1987 | 1988 | if (!dev) |
|---|
| .. | .. |
|---|
| 2039 | 2040 | } |
|---|
| 2040 | 2041 | |
|---|
| 2041 | 2042 | /* remap CSR registers */ |
|---|
| 2042 | | - regs = ioremap_nocache(pciaddr, DE_REGS_SIZE); |
|---|
| 2043 | + regs = ioremap(pciaddr, DE_REGS_SIZE); |
|---|
| 2043 | 2044 | if (!regs) { |
|---|
| 2044 | 2045 | rc = -EIO; |
|---|
| 2045 | 2046 | pr_err("Cannot map PCI MMIO (%llx@%lx) on pci dev %s\n", |
|---|
| .. | .. |
|---|
| 2114 | 2115 | free_netdev(dev); |
|---|
| 2115 | 2116 | } |
|---|
| 2116 | 2117 | |
|---|
| 2117 | | -#ifdef CONFIG_PM |
|---|
| 2118 | | - |
|---|
| 2119 | | -static int de_suspend (struct pci_dev *pdev, pm_message_t state) |
|---|
| 2118 | +static int __maybe_unused de_suspend(struct device *dev_d) |
|---|
| 2120 | 2119 | { |
|---|
| 2121 | | - struct net_device *dev = pci_get_drvdata (pdev); |
|---|
| 2120 | + struct pci_dev *pdev = to_pci_dev(dev_d); |
|---|
| 2121 | + struct net_device *dev = pci_get_drvdata(pdev); |
|---|
| 2122 | 2122 | struct de_private *de = netdev_priv(dev); |
|---|
| 2123 | 2123 | |
|---|
| 2124 | 2124 | rtnl_lock(); |
|---|
| .. | .. |
|---|
| 2145 | 2145 | de_clean_rings(de); |
|---|
| 2146 | 2146 | |
|---|
| 2147 | 2147 | de_adapter_sleep(de); |
|---|
| 2148 | | - pci_disable_device(pdev); |
|---|
| 2149 | 2148 | } else { |
|---|
| 2150 | 2149 | netif_device_detach(dev); |
|---|
| 2151 | 2150 | } |
|---|
| .. | .. |
|---|
| 2153 | 2152 | return 0; |
|---|
| 2154 | 2153 | } |
|---|
| 2155 | 2154 | |
|---|
| 2156 | | -static int de_resume (struct pci_dev *pdev) |
|---|
| 2155 | +static int __maybe_unused de_resume(struct device *dev_d) |
|---|
| 2157 | 2156 | { |
|---|
| 2158 | | - struct net_device *dev = pci_get_drvdata (pdev); |
|---|
| 2157 | + struct pci_dev *pdev = to_pci_dev(dev_d); |
|---|
| 2158 | + struct net_device *dev = pci_get_drvdata(pdev); |
|---|
| 2159 | 2159 | struct de_private *de = netdev_priv(dev); |
|---|
| 2160 | | - int retval = 0; |
|---|
| 2161 | 2160 | |
|---|
| 2162 | 2161 | rtnl_lock(); |
|---|
| 2163 | 2162 | if (netif_device_present(dev)) |
|---|
| 2164 | 2163 | goto out; |
|---|
| 2165 | 2164 | if (!netif_running(dev)) |
|---|
| 2166 | 2165 | goto out_attach; |
|---|
| 2167 | | - if ((retval = pci_enable_device(pdev))) { |
|---|
| 2168 | | - netdev_err(dev, "pci_enable_device failed in resume\n"); |
|---|
| 2169 | | - goto out; |
|---|
| 2170 | | - } |
|---|
| 2171 | 2166 | pci_set_master(pdev); |
|---|
| 2172 | 2167 | de_init_rings(de); |
|---|
| 2173 | 2168 | de_init_hw(de); |
|---|
| .. | .. |
|---|
| 2178 | 2173 | return 0; |
|---|
| 2179 | 2174 | } |
|---|
| 2180 | 2175 | |
|---|
| 2181 | | -#endif /* CONFIG_PM */ |
|---|
| 2176 | +static SIMPLE_DEV_PM_OPS(de_pm_ops, de_suspend, de_resume); |
|---|
| 2182 | 2177 | |
|---|
| 2183 | 2178 | static struct pci_driver de_driver = { |
|---|
| 2184 | 2179 | .name = DRV_NAME, |
|---|
| 2185 | 2180 | .id_table = de_pci_tbl, |
|---|
| 2186 | 2181 | .probe = de_init_one, |
|---|
| 2187 | 2182 | .remove = de_remove_one, |
|---|
| 2188 | | -#ifdef CONFIG_PM |
|---|
| 2189 | | - .suspend = de_suspend, |
|---|
| 2190 | | - .resume = de_resume, |
|---|
| 2191 | | -#endif |
|---|
| 2183 | + .driver.pm = &de_pm_ops, |
|---|
| 2192 | 2184 | }; |
|---|
| 2193 | 2185 | |
|---|
| 2194 | 2186 | static int __init de_init (void) |
|---|
| 2195 | 2187 | { |
|---|
| 2196 | | -#ifdef MODULE |
|---|
| 2197 | | - pr_info("%s\n", version); |
|---|
| 2198 | | -#endif |
|---|
| 2199 | 2188 | return pci_register_driver(&de_driver); |
|---|
| 2200 | 2189 | } |
|---|
| 2201 | 2190 | |
|---|