forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/net/ethernet/dec/tulip/tulip_core.c
....@@ -12,13 +12,6 @@
1212 #define pr_fmt(fmt) "tulip: " fmt
1313
1414 #define DRV_NAME "tulip"
15
-#ifdef CONFIG_TULIP_NAPI
16
-#define DRV_VERSION "1.1.15-NAPI" /* Keep at least for test */
17
-#else
18
-#define DRV_VERSION "1.1.15"
19
-#endif
20
-#define DRV_RELDATE "Feb 27, 2007"
21
-
2215
2316 #include <linux/module.h>
2417 #include <linux/pci.h>
....@@ -36,9 +29,6 @@
3629 #ifdef CONFIG_SPARC
3730 #include <asm/prom.h>
3831 #endif
39
-
40
-static char version[] =
41
- "Linux Tulip driver version " DRV_VERSION " (" DRV_RELDATE ")\n";
4232
4333 /* A few user-configurable values. */
4434
....@@ -109,7 +99,6 @@
10999 MODULE_AUTHOR("The Linux Kernel Team");
110100 MODULE_DESCRIPTION("Digital 21*4* Tulip ethernet driver");
111101 MODULE_LICENSE("GPL");
112
-MODULE_VERSION(DRV_VERSION);
113102 module_param(tulip_debug, int, 0);
114103 module_param(max_interrupt_work, int, 0);
115104 module_param(rx_copybreak, int, 0);
....@@ -255,7 +244,7 @@
255244 const char tulip_media_cap[32] =
256245 {0,0,0,16, 3,19,16,24, 27,4,7,5, 0,20,23,20, 28,31,0,0, };
257246
258
-static void tulip_tx_timeout(struct net_device *dev);
247
+static void tulip_tx_timeout(struct net_device *dev, unsigned int txqueue);
259248 static void tulip_init_ring(struct net_device *dev);
260249 static void tulip_free_ring(struct net_device *dev);
261250 static netdev_tx_t tulip_start_xmit(struct sk_buff *skb,
....@@ -361,9 +350,9 @@
361350 *setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
362351 *setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
363352
364
- mapping = pci_map_single(tp->pdev, tp->setup_frame,
353
+ mapping = dma_map_single(&tp->pdev->dev, tp->setup_frame,
365354 sizeof(tp->setup_frame),
366
- PCI_DMA_TODEVICE);
355
+ DMA_TO_DEVICE);
367356 tp->tx_buffers[tp->cur_tx].skb = NULL;
368357 tp->tx_buffers[tp->cur_tx].mapping = mapping;
369358
....@@ -534,7 +523,7 @@
534523 }
535524
536525
537
-static void tulip_tx_timeout(struct net_device *dev)
526
+static void tulip_tx_timeout(struct net_device *dev, unsigned int txqueue)
538527 {
539528 struct tulip_private *tp = netdev_priv(dev);
540529 void __iomem *ioaddr = tp->base_addr;
....@@ -641,8 +630,8 @@
641630 tp->rx_buffers[i].skb = skb;
642631 if (skb == NULL)
643632 break;
644
- mapping = pci_map_single(tp->pdev, skb->data,
645
- PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
633
+ mapping = dma_map_single(&tp->pdev->dev, skb->data,
634
+ PKT_BUF_SZ, DMA_FROM_DEVICE);
646635 tp->rx_buffers[i].mapping = mapping;
647636 tp->rx_ring[i].status = cpu_to_le32(DescOwned); /* Owned by Tulip chip */
648637 tp->rx_ring[i].buffer1 = cpu_to_le32(mapping);
....@@ -675,8 +664,8 @@
675664 entry = tp->cur_tx % TX_RING_SIZE;
676665
677666 tp->tx_buffers[entry].skb = skb;
678
- mapping = pci_map_single(tp->pdev, skb->data,
679
- skb->len, PCI_DMA_TODEVICE);
667
+ mapping = dma_map_single(&tp->pdev->dev, skb->data, skb->len,
668
+ DMA_TO_DEVICE);
680669 tp->tx_buffers[entry].mapping = mapping;
681670 tp->tx_ring[entry].buffer1 = cpu_to_le32(mapping);
682671
....@@ -727,16 +716,17 @@
727716 if (tp->tx_buffers[entry].skb == NULL) {
728717 /* test because dummy frames not mapped */
729718 if (tp->tx_buffers[entry].mapping)
730
- pci_unmap_single(tp->pdev,
731
- tp->tx_buffers[entry].mapping,
732
- sizeof(tp->setup_frame),
733
- PCI_DMA_TODEVICE);
719
+ dma_unmap_single(&tp->pdev->dev,
720
+ tp->tx_buffers[entry].mapping,
721
+ sizeof(tp->setup_frame),
722
+ DMA_TO_DEVICE);
734723 continue;
735724 }
736725
737
- pci_unmap_single(tp->pdev, tp->tx_buffers[entry].mapping,
738
- tp->tx_buffers[entry].skb->len,
739
- PCI_DMA_TODEVICE);
726
+ dma_unmap_single(&tp->pdev->dev,
727
+ tp->tx_buffers[entry].mapping,
728
+ tp->tx_buffers[entry].skb->len,
729
+ DMA_TO_DEVICE);
740730
741731 /* Free the original skb. */
742732 dev_kfree_skb_irq(tp->tx_buffers[entry].skb);
....@@ -806,8 +796,8 @@
806796 /* An invalid address. */
807797 tp->rx_ring[i].buffer1 = cpu_to_le32(0xBADF00D0);
808798 if (skb) {
809
- pci_unmap_single(tp->pdev, mapping, PKT_BUF_SZ,
810
- PCI_DMA_FROMDEVICE);
799
+ dma_unmap_single(&tp->pdev->dev, mapping, PKT_BUF_SZ,
800
+ DMA_FROM_DEVICE);
811801 dev_kfree_skb (skb);
812802 }
813803 }
....@@ -816,8 +806,9 @@
816806 struct sk_buff *skb = tp->tx_buffers[i].skb;
817807
818808 if (skb != NULL) {
819
- pci_unmap_single(tp->pdev, tp->tx_buffers[i].mapping,
820
- skb->len, PCI_DMA_TODEVICE);
809
+ dma_unmap_single(&tp->pdev->dev,
810
+ tp->tx_buffers[i].mapping, skb->len,
811
+ DMA_TO_DEVICE);
821812 dev_kfree_skb (skb);
822813 }
823814 tp->tx_buffers[i].skb = NULL;
....@@ -868,7 +859,6 @@
868859 {
869860 struct tulip_private *np = netdev_priv(dev);
870861 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
871
- strlcpy(info->version, DRV_VERSION, sizeof(info->version));
872862 strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
873863 }
874864
....@@ -923,7 +913,7 @@
923913 data->phy_id = 1;
924914 else
925915 return -ENODEV;
926
- /* Fall through */
916
+ fallthrough;
927917
928918 case SIOCGMIIREG: /* Read MII PHY register. */
929919 if (data->phy_id == 32 && (tp->flags & HAS_NWAY)) {
....@@ -1161,9 +1151,10 @@
11611151
11621152 tp->tx_buffers[entry].skb = NULL;
11631153 tp->tx_buffers[entry].mapping =
1164
- pci_map_single(tp->pdev, tp->setup_frame,
1154
+ dma_map_single(&tp->pdev->dev,
1155
+ tp->setup_frame,
11651156 sizeof(tp->setup_frame),
1166
- PCI_DMA_TODEVICE);
1157
+ DMA_TO_DEVICE);
11671158 /* Put the setup frame on the Tx list. */
11681159 if (entry == TX_RING_SIZE-1)
11691160 tx_flags |= DESC_RING_WRAP; /* Wrap ring. */
....@@ -1289,7 +1280,7 @@
12891280 #endif
12901281 };
12911282
1292
-const struct pci_device_id early_486_chipsets[] = {
1283
+static const struct pci_device_id early_486_chipsets[] = {
12931284 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82424) },
12941285 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496) },
12951286 { },
....@@ -1313,11 +1304,6 @@
13131304 const char *chip_name = tulip_tbl[chip_idx].chip_name;
13141305 unsigned int eeprom_missing = 0;
13151306 unsigned int force_csr0 = 0;
1316
-
1317
-#ifndef MODULE
1318
- if (tulip_debug > 0)
1319
- printk_once(KERN_INFO "%s", version);
1320
-#endif
13211307
13221308 board_idx++;
13231309
....@@ -1410,8 +1396,10 @@
14101396
14111397 /* alloc_etherdev ensures aligned and zeroed private structures */
14121398 dev = alloc_etherdev (sizeof (*tp));
1413
- if (!dev)
1399
+ if (!dev) {
1400
+ pci_disable_device(pdev);
14141401 return -ENOMEM;
1402
+ }
14151403
14161404 SET_NETDEV_DEV(dev, &pdev->dev);
14171405 if (pci_resource_len (pdev, 0) < tulip_tbl[chip_idx].io_size) {
....@@ -1439,10 +1427,10 @@
14391427 tp = netdev_priv(dev);
14401428 tp->dev = dev;
14411429
1442
- tp->rx_ring = pci_alloc_consistent(pdev,
1443
- sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
1444
- sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
1445
- &tp->rx_ring_dma);
1430
+ tp->rx_ring = dma_alloc_coherent(&pdev->dev,
1431
+ sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
1432
+ sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
1433
+ &tp->rx_ring_dma, GFP_KERNEL);
14461434 if (!tp->rx_ring)
14471435 goto err_out_mtable;
14481436 tp->tx_ring = (struct tulip_tx_desc *)(tp->rx_ring + RX_RING_SIZE);
....@@ -1774,10 +1762,10 @@
17741762 return 0;
17751763
17761764 err_out_free_ring:
1777
- pci_free_consistent (pdev,
1778
- sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
1779
- sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
1780
- tp->rx_ring, tp->rx_ring_dma);
1765
+ dma_free_coherent(&pdev->dev,
1766
+ sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
1767
+ sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
1768
+ tp->rx_ring, tp->rx_ring_dma);
17811769
17821770 err_out_mtable:
17831771 kfree (tp->mtable);
....@@ -1788,6 +1776,7 @@
17881776
17891777 err_out_free_netdev:
17901778 free_netdev (dev);
1779
+ pci_disable_device(pdev);
17911780 return -ENODEV;
17921781 }
17931782
....@@ -1800,14 +1789,13 @@
18001789 void __iomem *ioaddr = tp->base_addr;
18011790
18021791 if (tp->flags & COMET_PM) {
1803
-
18041792 unsigned int tmp;
1805
-
1793
+
18061794 tmp = ioread32(ioaddr + CSR18);
18071795 tmp &= ~(comet_csr18_pmes_sticky | comet_csr18_apm_mode | comet_csr18_d3a);
18081796 tmp |= comet_csr18_pm_mode;
18091797 iowrite32(tmp, ioaddr + CSR18);
1810
-
1798
+
18111799 /* Set the Wake-up Control/Status Register to the given WOL options*/
18121800 tmp = ioread32(ioaddr + CSR13);
18131801 tmp &= ~(comet_csr13_linkoffe | comet_csr13_linkone | comet_csr13_wfre | comet_csr13_lsce | comet_csr13_mpre);
....@@ -1821,13 +1809,9 @@
18211809 }
18221810 }
18231811
1824
-#ifdef CONFIG_PM
1825
-
1826
-
1827
-static int tulip_suspend (struct pci_dev *pdev, pm_message_t state)
1812
+static int __maybe_unused tulip_suspend(struct device *dev_d)
18281813 {
1829
- pci_power_t pstate;
1830
- struct net_device *dev = pci_get_drvdata(pdev);
1814
+ struct net_device *dev = dev_get_drvdata(dev_d);
18311815 struct tulip_private *tp = netdev_priv(dev);
18321816
18331817 if (!dev)
....@@ -1843,44 +1827,26 @@
18431827 free_irq(tp->pdev->irq, dev);
18441828
18451829 save_state:
1846
- pci_save_state(pdev);
1847
- pci_disable_device(pdev);
1848
- pstate = pci_choose_state(pdev, state);
1849
- if (state.event == PM_EVENT_SUSPEND && pstate != PCI_D0) {
1850
- int rc;
1851
-
1852
- tulip_set_wolopts(pdev, tp->wolinfo.wolopts);
1853
- rc = pci_enable_wake(pdev, pstate, tp->wolinfo.wolopts);
1854
- if (rc)
1855
- pr_err("pci_enable_wake failed (%d)\n", rc);
1856
- }
1857
- pci_set_power_state(pdev, pstate);
1830
+ tulip_set_wolopts(to_pci_dev(dev_d), tp->wolinfo.wolopts);
1831
+ device_set_wakeup_enable(dev_d, !!tp->wolinfo.wolopts);
18581832
18591833 return 0;
18601834 }
18611835
1862
-
1863
-static int tulip_resume(struct pci_dev *pdev)
1836
+static int __maybe_unused tulip_resume(struct device *dev_d)
18641837 {
1865
- struct net_device *dev = pci_get_drvdata(pdev);
1838
+ struct pci_dev *pdev = to_pci_dev(dev_d);
1839
+ struct net_device *dev = dev_get_drvdata(dev_d);
18661840 struct tulip_private *tp = netdev_priv(dev);
18671841 void __iomem *ioaddr = tp->base_addr;
1868
- int retval;
18691842 unsigned int tmp;
1843
+ int retval = 0;
18701844
18711845 if (!dev)
18721846 return -EINVAL;
18731847
1874
- pci_set_power_state(pdev, PCI_D0);
1875
- pci_restore_state(pdev);
1876
-
18771848 if (!netif_running(dev))
18781849 return 0;
1879
-
1880
- if ((retval = pci_enable_device(pdev))) {
1881
- pr_err("pci_enable_device failed in resume\n");
1882
- return retval;
1883
- }
18841850
18851851 retval = request_irq(pdev->irq, tulip_interrupt, IRQF_SHARED,
18861852 dev->name, dev);
....@@ -1890,8 +1856,7 @@
18901856 }
18911857
18921858 if (tp->flags & COMET_PM) {
1893
- pci_enable_wake(pdev, PCI_D3hot, 0);
1894
- pci_enable_wake(pdev, PCI_D3cold, 0);
1859
+ device_set_wakeup_enable(dev_d, 0);
18951860
18961861 /* Clear the PMES flag */
18971862 tmp = ioread32(ioaddr + CSR20);
....@@ -1909,9 +1874,6 @@
19091874 return 0;
19101875 }
19111876
1912
-#endif /* CONFIG_PM */
1913
-
1914
-
19151877 static void tulip_remove_one(struct pci_dev *pdev)
19161878 {
19171879 struct net_device *dev = pci_get_drvdata (pdev);
....@@ -1922,10 +1884,10 @@
19221884
19231885 tp = netdev_priv(dev);
19241886 unregister_netdev(dev);
1925
- pci_free_consistent (pdev,
1926
- sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
1927
- sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
1928
- tp->rx_ring, tp->rx_ring_dma);
1887
+ dma_free_coherent(&pdev->dev,
1888
+ sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
1889
+ sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
1890
+ tp->rx_ring, tp->rx_ring_dma);
19291891 kfree (tp->mtable);
19301892 pci_iounmap(pdev, tp->base_addr);
19311893 free_netdev (dev);
....@@ -1955,24 +1917,19 @@
19551917 }
19561918 #endif
19571919
1920
+static SIMPLE_DEV_PM_OPS(tulip_pm_ops, tulip_suspend, tulip_resume);
1921
+
19581922 static struct pci_driver tulip_driver = {
19591923 .name = DRV_NAME,
19601924 .id_table = tulip_pci_tbl,
19611925 .probe = tulip_init_one,
19621926 .remove = tulip_remove_one,
1963
-#ifdef CONFIG_PM
1964
- .suspend = tulip_suspend,
1965
- .resume = tulip_resume,
1966
-#endif /* CONFIG_PM */
1927
+ .driver.pm = &tulip_pm_ops,
19671928 };
19681929
19691930
19701931 static int __init tulip_init (void)
19711932 {
1972
-#ifdef MODULE
1973
- pr_info("%s", version);
1974
-#endif
1975
-
19761933 if (!csr0) {
19771934 pr_warn("tulip: unknown CPU architecture, using default csr0\n");
19781935 /* default to 8 longword cache line alignment */