forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/net/ethernet/dec/tulip/dmfe.c
....@@ -1,17 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 A Davicom DM9102/DM9102A/DM9102A+DM9801/DM9102A+DM9802 NIC fast
34 ethernet driver for Linux.
45 Copyright (C) 1997 Sten Wang
56
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.
157
168 DAVICOM Web-Site: www.davicom.com.tw
179
....@@ -64,8 +56,6 @@
6456 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6557
6658 #define DRV_NAME "dmfe"
67
-#define DRV_VERSION "1.36.4"
68
-#define DRV_RELDATE "2002-01-17"
6959
7060 #include <linux/module.h>
7161 #include <linux/kernel.h>
....@@ -288,10 +278,6 @@
288278 };
289279
290280 /* Global variable declaration ----------------------------- */
291
-static int printed_version;
292
-static const char version[] =
293
- "Davicom DM9xxx net driver, version " DRV_VERSION " (" DRV_RELDATE ")";
294
-
295281 static int dmfe_debug;
296282 static unsigned char dmfe_media_mode = DMFE_AUTO;
297283 static u32 dmfe_cr6_user_set;
....@@ -372,9 +358,6 @@
372358
373359 DMFE_DBUG(0, "dmfe_init_one()", 0);
374360
375
- if (!printed_version++)
376
- pr_info("%s\n", version);
377
-
378361 /*
379362 * SPARC on-board DM910x chips should be handled by the main
380363 * tulip driver, except for early DM9100s.
....@@ -397,7 +380,7 @@
397380 return -ENOMEM;
398381 SET_NETDEV_DEV(dev, &pdev->dev);
399382
400
- if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
383
+ if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
401384 pr_warn("32-bit PCI DMA not available\n");
402385 err = -ENODEV;
403386 goto err_out_free;
....@@ -439,15 +422,17 @@
439422 db = netdev_priv(dev);
440423
441424 /* 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);
444428 if (!db->desc_pool_ptr) {
445429 err = -ENOMEM;
446430 goto err_out_res;
447431 }
448432
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);
451436 if (!db->buf_pool_ptr) {
452437 err = -ENOMEM;
453438 goto err_out_free_desc;
....@@ -509,11 +494,12 @@
509494 err_out_unmap:
510495 pci_iounmap(pdev, db->ioaddr);
511496 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);
514499 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);
517503 err_out_res:
518504 pci_release_regions(pdev);
519505 err_out_disable:
....@@ -536,11 +522,12 @@
536522
537523 unregister_netdev(dev);
538524 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);
544531 pci_release_regions(pdev);
545532 free_netdev(dev); /* free board information */
546533 }
....@@ -972,8 +959,8 @@
972959 db->rx_avail_cnt--;
973960 db->interval_rx_cnt++;
974961
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);
977964
978965 if ( (rdes0 & 0x300) != 0x300) {
979966 /* A packet without First/Last flag */
....@@ -1089,7 +1076,6 @@
10891076 struct dmfe_board_info *np = netdev_priv(dev);
10901077
10911078 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
1092
- strlcpy(info->version, DRV_VERSION, sizeof(info->version));
10931079 strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
10941080 }
10951081
....@@ -1347,8 +1333,8 @@
13471333
13481334 if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) {
13491335 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));
13521338 wmb();
13531339 rxptr->rdes0 = cpu_to_le32(0x80000000);
13541340 db->rx_avail_cnt++;
....@@ -1562,8 +1548,8 @@
15621548 if ( ( skb = netdev_alloc_skb(dev, RX_ALLOC_SIZE) ) == NULL )
15631549 break;
15641550 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));
15671553 wmb();
15681554 rxptr->rdes0 = cpu_to_le32(0x80000000);
15691555 rxptr = rxptr->next_rx_desc;
....@@ -2099,14 +2085,11 @@
20992085 };
21002086 MODULE_DEVICE_TABLE(pci, dmfe_pci_tbl);
21012087
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)
21052089 {
2106
- struct net_device *dev = pci_get_drvdata(pci_dev);
2090
+ struct net_device *dev = dev_get_drvdata(dev_d);
21072091 struct dmfe_board_info *db = netdev_priv(dev);
21082092 void __iomem *ioaddr = db->ioaddr;
2109
- u32 tmp;
21102093
21112094 /* Disable upper layer interface */
21122095 netif_device_detach(dev);
....@@ -2123,69 +2106,40 @@
21232106 dmfe_free_rxbuffer(db);
21242107
21252108 /* 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);
21422110
21432111 return 0;
21442112 }
21452113
2146
-static int dmfe_resume(struct pci_dev *pci_dev)
2114
+static int __maybe_unused dmfe_resume(struct device *dev_d)
21472115 {
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);
21532117
21542118 /* Re-initialize DM910X board */
21552119 dmfe_init_dm910x(dev);
21562120
21572121 /* 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);
21652123
21662124 /* Restart upper layer interface */
21672125 netif_device_attach(dev);
21682126
21692127 return 0;
21702128 }
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);
21752131
21762132 static struct pci_driver dmfe_driver = {
21772133 .name = "dmfe",
21782134 .id_table = dmfe_pci_tbl,
21792135 .probe = dmfe_init_one,
21802136 .remove = dmfe_remove_one,
2181
- .suspend = dmfe_suspend,
2182
- .resume = dmfe_resume
2137
+ .driver.pm = &dmfe_pm_ops,
21832138 };
21842139
21852140 MODULE_AUTHOR("Sten Wang, sten_wang@davicom.com.tw");
21862141 MODULE_DESCRIPTION("Davicom DM910X fast ethernet driver");
21872142 MODULE_LICENSE("GPL");
2188
-MODULE_VERSION(DRV_VERSION);
21892143
21902144 module_param(debug, int, 0);
21912145 module_param(mode, byte, 0);
....@@ -2211,9 +2165,6 @@
22112165 static int __init dmfe_init_module(void)
22122166 {
22132167 int rc;
2214
-
2215
- pr_info("%s\n", version);
2216
- printed_version = 1;
22172168
22182169 DMFE_DBUG(0, "init_module() ", debug);
22192170