| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | A Davicom DM9102/DM9102A/DM9102A+DM9801/DM9102A+DM9802 NIC fast |
|---|
| 3 | 4 | ethernet driver for Linux. |
|---|
| 4 | 5 | Copyright (C) 1997 Sten Wang |
|---|
| 5 | 6 | |
|---|
| 6 | | - This program is free software; you can redistribute it and/or |
|---|
| 7 | | - modify it under the terms of the GNU General Public License |
|---|
| 8 | | - as published by the Free Software Foundation; either version 2 |
|---|
| 9 | | - of the License, or (at your option) any later version. |
|---|
| 10 | | - |
|---|
| 11 | | - This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - GNU General Public License for more details. |
|---|
| 15 | 7 | |
|---|
| 16 | 8 | DAVICOM Web-Site: www.davicom.com.tw |
|---|
| 17 | 9 | |
|---|
| .. | .. |
|---|
| 64 | 56 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 65 | 57 | |
|---|
| 66 | 58 | #define DRV_NAME "dmfe" |
|---|
| 67 | | -#define DRV_VERSION "1.36.4" |
|---|
| 68 | | -#define DRV_RELDATE "2002-01-17" |
|---|
| 69 | 59 | |
|---|
| 70 | 60 | #include <linux/module.h> |
|---|
| 71 | 61 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 288 | 278 | }; |
|---|
| 289 | 279 | |
|---|
| 290 | 280 | /* Global variable declaration ----------------------------- */ |
|---|
| 291 | | -static int printed_version; |
|---|
| 292 | | -static const char version[] = |
|---|
| 293 | | - "Davicom DM9xxx net driver, version " DRV_VERSION " (" DRV_RELDATE ")"; |
|---|
| 294 | | - |
|---|
| 295 | 281 | static int dmfe_debug; |
|---|
| 296 | 282 | static unsigned char dmfe_media_mode = DMFE_AUTO; |
|---|
| 297 | 283 | static u32 dmfe_cr6_user_set; |
|---|
| .. | .. |
|---|
| 372 | 358 | |
|---|
| 373 | 359 | DMFE_DBUG(0, "dmfe_init_one()", 0); |
|---|
| 374 | 360 | |
|---|
| 375 | | - if (!printed_version++) |
|---|
| 376 | | - pr_info("%s\n", version); |
|---|
| 377 | | - |
|---|
| 378 | 361 | /* |
|---|
| 379 | 362 | * SPARC on-board DM910x chips should be handled by the main |
|---|
| 380 | 363 | * tulip driver, except for early DM9100s. |
|---|
| .. | .. |
|---|
| 397 | 380 | return -ENOMEM; |
|---|
| 398 | 381 | SET_NETDEV_DEV(dev, &pdev->dev); |
|---|
| 399 | 382 | |
|---|
| 400 | | - if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
|---|
| 383 | + if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { |
|---|
| 401 | 384 | pr_warn("32-bit PCI DMA not available\n"); |
|---|
| 402 | 385 | err = -ENODEV; |
|---|
| 403 | 386 | goto err_out_free; |
|---|
| .. | .. |
|---|
| 439 | 422 | db = netdev_priv(dev); |
|---|
| 440 | 423 | |
|---|
| 441 | 424 | /* Allocate Tx/Rx descriptor memory */ |
|---|
| 442 | | - db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) * |
|---|
| 443 | | - DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr); |
|---|
| 425 | + db->desc_pool_ptr = dma_alloc_coherent(&pdev->dev, |
|---|
| 426 | + sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, |
|---|
| 427 | + &db->desc_pool_dma_ptr, GFP_KERNEL); |
|---|
| 444 | 428 | if (!db->desc_pool_ptr) { |
|---|
| 445 | 429 | err = -ENOMEM; |
|---|
| 446 | 430 | goto err_out_res; |
|---|
| 447 | 431 | } |
|---|
| 448 | 432 | |
|---|
| 449 | | - db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC * |
|---|
| 450 | | - TX_DESC_CNT + 4, &db->buf_pool_dma_ptr); |
|---|
| 433 | + db->buf_pool_ptr = dma_alloc_coherent(&pdev->dev, |
|---|
| 434 | + TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 435 | + &db->buf_pool_dma_ptr, GFP_KERNEL); |
|---|
| 451 | 436 | if (!db->buf_pool_ptr) { |
|---|
| 452 | 437 | err = -ENOMEM; |
|---|
| 453 | 438 | goto err_out_free_desc; |
|---|
| .. | .. |
|---|
| 509 | 494 | err_out_unmap: |
|---|
| 510 | 495 | pci_iounmap(pdev, db->ioaddr); |
|---|
| 511 | 496 | err_out_free_buf: |
|---|
| 512 | | - pci_free_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 513 | | - db->buf_pool_ptr, db->buf_pool_dma_ptr); |
|---|
| 497 | + dma_free_coherent(&pdev->dev, TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 498 | + db->buf_pool_ptr, db->buf_pool_dma_ptr); |
|---|
| 514 | 499 | err_out_free_desc: |
|---|
| 515 | | - pci_free_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, |
|---|
| 516 | | - db->desc_pool_ptr, db->desc_pool_dma_ptr); |
|---|
| 500 | + dma_free_coherent(&pdev->dev, |
|---|
| 501 | + sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, |
|---|
| 502 | + db->desc_pool_ptr, db->desc_pool_dma_ptr); |
|---|
| 517 | 503 | err_out_res: |
|---|
| 518 | 504 | pci_release_regions(pdev); |
|---|
| 519 | 505 | err_out_disable: |
|---|
| .. | .. |
|---|
| 536 | 522 | |
|---|
| 537 | 523 | unregister_netdev(dev); |
|---|
| 538 | 524 | pci_iounmap(db->pdev, db->ioaddr); |
|---|
| 539 | | - pci_free_consistent(db->pdev, sizeof(struct tx_desc) * |
|---|
| 540 | | - DESC_ALL_CNT + 0x20, db->desc_pool_ptr, |
|---|
| 541 | | - db->desc_pool_dma_ptr); |
|---|
| 542 | | - pci_free_consistent(db->pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 543 | | - db->buf_pool_ptr, db->buf_pool_dma_ptr); |
|---|
| 525 | + dma_free_coherent(&db->pdev->dev, |
|---|
| 526 | + sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20, |
|---|
| 527 | + db->desc_pool_ptr, db->desc_pool_dma_ptr); |
|---|
| 528 | + dma_free_coherent(&db->pdev->dev, |
|---|
| 529 | + TX_BUF_ALLOC * TX_DESC_CNT + 4, |
|---|
| 530 | + db->buf_pool_ptr, db->buf_pool_dma_ptr); |
|---|
| 544 | 531 | pci_release_regions(pdev); |
|---|
| 545 | 532 | free_netdev(dev); /* free board information */ |
|---|
| 546 | 533 | } |
|---|
| .. | .. |
|---|
| 972 | 959 | db->rx_avail_cnt--; |
|---|
| 973 | 960 | db->interval_rx_cnt++; |
|---|
| 974 | 961 | |
|---|
| 975 | | - pci_unmap_single(db->pdev, le32_to_cpu(rxptr->rdes2), |
|---|
| 976 | | - RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE); |
|---|
| 962 | + dma_unmap_single(&db->pdev->dev, le32_to_cpu(rxptr->rdes2), |
|---|
| 963 | + RX_ALLOC_SIZE, DMA_FROM_DEVICE); |
|---|
| 977 | 964 | |
|---|
| 978 | 965 | if ( (rdes0 & 0x300) != 0x300) { |
|---|
| 979 | 966 | /* A packet without First/Last flag */ |
|---|
| .. | .. |
|---|
| 1089 | 1076 | struct dmfe_board_info *np = netdev_priv(dev); |
|---|
| 1090 | 1077 | |
|---|
| 1091 | 1078 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
|---|
| 1092 | | - strlcpy(info->version, DRV_VERSION, sizeof(info->version)); |
|---|
| 1093 | 1079 | strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info)); |
|---|
| 1094 | 1080 | } |
|---|
| 1095 | 1081 | |
|---|
| .. | .. |
|---|
| 1347 | 1333 | |
|---|
| 1348 | 1334 | if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) { |
|---|
| 1349 | 1335 | rxptr->rx_skb_ptr = skb; |
|---|
| 1350 | | - rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, |
|---|
| 1351 | | - skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) ); |
|---|
| 1336 | + rxptr->rdes2 = cpu_to_le32(dma_map_single(&db->pdev->dev, skb->data, |
|---|
| 1337 | + RX_ALLOC_SIZE, DMA_FROM_DEVICE)); |
|---|
| 1352 | 1338 | wmb(); |
|---|
| 1353 | 1339 | rxptr->rdes0 = cpu_to_le32(0x80000000); |
|---|
| 1354 | 1340 | db->rx_avail_cnt++; |
|---|
| .. | .. |
|---|
| 1562 | 1548 | if ( ( skb = netdev_alloc_skb(dev, RX_ALLOC_SIZE) ) == NULL ) |
|---|
| 1563 | 1549 | break; |
|---|
| 1564 | 1550 | rxptr->rx_skb_ptr = skb; /* FIXME (?) */ |
|---|
| 1565 | | - rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data, |
|---|
| 1566 | | - RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) ); |
|---|
| 1551 | + rxptr->rdes2 = cpu_to_le32(dma_map_single(&db->pdev->dev, skb->data, |
|---|
| 1552 | + RX_ALLOC_SIZE, DMA_FROM_DEVICE)); |
|---|
| 1567 | 1553 | wmb(); |
|---|
| 1568 | 1554 | rxptr->rdes0 = cpu_to_le32(0x80000000); |
|---|
| 1569 | 1555 | rxptr = rxptr->next_rx_desc; |
|---|
| .. | .. |
|---|
| 2099 | 2085 | }; |
|---|
| 2100 | 2086 | MODULE_DEVICE_TABLE(pci, dmfe_pci_tbl); |
|---|
| 2101 | 2087 | |
|---|
| 2102 | | - |
|---|
| 2103 | | -#ifdef CONFIG_PM |
|---|
| 2104 | | -static int dmfe_suspend(struct pci_dev *pci_dev, pm_message_t state) |
|---|
| 2088 | +static int __maybe_unused dmfe_suspend(struct device *dev_d) |
|---|
| 2105 | 2089 | { |
|---|
| 2106 | | - struct net_device *dev = pci_get_drvdata(pci_dev); |
|---|
| 2090 | + struct net_device *dev = dev_get_drvdata(dev_d); |
|---|
| 2107 | 2091 | struct dmfe_board_info *db = netdev_priv(dev); |
|---|
| 2108 | 2092 | void __iomem *ioaddr = db->ioaddr; |
|---|
| 2109 | | - u32 tmp; |
|---|
| 2110 | 2093 | |
|---|
| 2111 | 2094 | /* Disable upper layer interface */ |
|---|
| 2112 | 2095 | netif_device_detach(dev); |
|---|
| .. | .. |
|---|
| 2123 | 2106 | dmfe_free_rxbuffer(db); |
|---|
| 2124 | 2107 | |
|---|
| 2125 | 2108 | /* Enable WOL */ |
|---|
| 2126 | | - pci_read_config_dword(pci_dev, 0x40, &tmp); |
|---|
| 2127 | | - tmp &= ~(DMFE_WOL_LINKCHANGE|DMFE_WOL_MAGICPACKET); |
|---|
| 2128 | | - |
|---|
| 2129 | | - if (db->wol_mode & WAKE_PHY) |
|---|
| 2130 | | - tmp |= DMFE_WOL_LINKCHANGE; |
|---|
| 2131 | | - if (db->wol_mode & WAKE_MAGIC) |
|---|
| 2132 | | - tmp |= DMFE_WOL_MAGICPACKET; |
|---|
| 2133 | | - |
|---|
| 2134 | | - pci_write_config_dword(pci_dev, 0x40, tmp); |
|---|
| 2135 | | - |
|---|
| 2136 | | - pci_enable_wake(pci_dev, PCI_D3hot, 1); |
|---|
| 2137 | | - pci_enable_wake(pci_dev, PCI_D3cold, 1); |
|---|
| 2138 | | - |
|---|
| 2139 | | - /* Power down device*/ |
|---|
| 2140 | | - pci_save_state(pci_dev); |
|---|
| 2141 | | - pci_set_power_state(pci_dev, pci_choose_state (pci_dev, state)); |
|---|
| 2109 | + device_wakeup_enable(dev_d); |
|---|
| 2142 | 2110 | |
|---|
| 2143 | 2111 | return 0; |
|---|
| 2144 | 2112 | } |
|---|
| 2145 | 2113 | |
|---|
| 2146 | | -static int dmfe_resume(struct pci_dev *pci_dev) |
|---|
| 2114 | +static int __maybe_unused dmfe_resume(struct device *dev_d) |
|---|
| 2147 | 2115 | { |
|---|
| 2148 | | - struct net_device *dev = pci_get_drvdata(pci_dev); |
|---|
| 2149 | | - u32 tmp; |
|---|
| 2150 | | - |
|---|
| 2151 | | - pci_set_power_state(pci_dev, PCI_D0); |
|---|
| 2152 | | - pci_restore_state(pci_dev); |
|---|
| 2116 | + struct net_device *dev = dev_get_drvdata(dev_d); |
|---|
| 2153 | 2117 | |
|---|
| 2154 | 2118 | /* Re-initialize DM910X board */ |
|---|
| 2155 | 2119 | dmfe_init_dm910x(dev); |
|---|
| 2156 | 2120 | |
|---|
| 2157 | 2121 | /* Disable WOL */ |
|---|
| 2158 | | - pci_read_config_dword(pci_dev, 0x40, &tmp); |
|---|
| 2159 | | - |
|---|
| 2160 | | - tmp &= ~(DMFE_WOL_LINKCHANGE | DMFE_WOL_MAGICPACKET); |
|---|
| 2161 | | - pci_write_config_dword(pci_dev, 0x40, tmp); |
|---|
| 2162 | | - |
|---|
| 2163 | | - pci_enable_wake(pci_dev, PCI_D3hot, 0); |
|---|
| 2164 | | - pci_enable_wake(pci_dev, PCI_D3cold, 0); |
|---|
| 2122 | + device_wakeup_disable(dev_d); |
|---|
| 2165 | 2123 | |
|---|
| 2166 | 2124 | /* Restart upper layer interface */ |
|---|
| 2167 | 2125 | netif_device_attach(dev); |
|---|
| 2168 | 2126 | |
|---|
| 2169 | 2127 | return 0; |
|---|
| 2170 | 2128 | } |
|---|
| 2171 | | -#else |
|---|
| 2172 | | -#define dmfe_suspend NULL |
|---|
| 2173 | | -#define dmfe_resume NULL |
|---|
| 2174 | | -#endif |
|---|
| 2129 | + |
|---|
| 2130 | +static SIMPLE_DEV_PM_OPS(dmfe_pm_ops, dmfe_suspend, dmfe_resume); |
|---|
| 2175 | 2131 | |
|---|
| 2176 | 2132 | static struct pci_driver dmfe_driver = { |
|---|
| 2177 | 2133 | .name = "dmfe", |
|---|
| 2178 | 2134 | .id_table = dmfe_pci_tbl, |
|---|
| 2179 | 2135 | .probe = dmfe_init_one, |
|---|
| 2180 | 2136 | .remove = dmfe_remove_one, |
|---|
| 2181 | | - .suspend = dmfe_suspend, |
|---|
| 2182 | | - .resume = dmfe_resume |
|---|
| 2137 | + .driver.pm = &dmfe_pm_ops, |
|---|
| 2183 | 2138 | }; |
|---|
| 2184 | 2139 | |
|---|
| 2185 | 2140 | MODULE_AUTHOR("Sten Wang, sten_wang@davicom.com.tw"); |
|---|
| 2186 | 2141 | MODULE_DESCRIPTION("Davicom DM910X fast ethernet driver"); |
|---|
| 2187 | 2142 | MODULE_LICENSE("GPL"); |
|---|
| 2188 | | -MODULE_VERSION(DRV_VERSION); |
|---|
| 2189 | 2143 | |
|---|
| 2190 | 2144 | module_param(debug, int, 0); |
|---|
| 2191 | 2145 | module_param(mode, byte, 0); |
|---|
| .. | .. |
|---|
| 2211 | 2165 | static int __init dmfe_init_module(void) |
|---|
| 2212 | 2166 | { |
|---|
| 2213 | 2167 | int rc; |
|---|
| 2214 | | - |
|---|
| 2215 | | - pr_info("%s\n", version); |
|---|
| 2216 | | - printed_version = 1; |
|---|
| 2217 | 2168 | |
|---|
| 2218 | 2169 | DMFE_DBUG(0, "init_module() ", debug); |
|---|
| 2219 | 2170 | |
|---|