forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/net/ethernet/silan/sc92031.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* Silan SC92031 PCI Fast Ethernet Adapter driver
23 *
34 * Based on vendor drivers:
....@@ -251,7 +252,6 @@
251252 * use of mdelay() at _sc92031_reset.
252253 * Functions prefixed with _sc92031_ must be called with the lock held;
253254 * functions prefixed with sc92031_ must be called without the lock held.
254
- * Use mmiowb() before unlocking if the hardware was written to.
255255 */
256256
257257 /* Locking rules for the interrupt:
....@@ -301,6 +301,7 @@
301301
302302 /* for dev->get_stats */
303303 long rx_value;
304
+ struct net_device *ndev;
304305 };
305306
306307 /* I don't know which registers can be safely read; however, I can guess
....@@ -361,7 +362,6 @@
361362 /* stop interrupts */
362363 iowrite32(0, port_base + IntrMask);
363364 _sc92031_dummy_read(port_base);
364
- mmiowb();
365365
366366 /* wait for any concurrent interrupt/tasklet to finish */
367367 synchronize_irq(priv->pdev->irq);
....@@ -379,7 +379,6 @@
379379 wmb();
380380
381381 iowrite32(IntrBits, port_base + IntrMask);
382
- mmiowb();
383382 }
384383
385384 static void _sc92031_disable_tx_rx(struct net_device *dev)
....@@ -831,10 +830,10 @@
831830 }
832831 }
833832
834
-static void sc92031_tasklet(unsigned long data)
833
+static void sc92031_tasklet(struct tasklet_struct *t)
835834 {
836
- struct net_device *dev = (struct net_device *)data;
837
- struct sc92031_priv *priv = netdev_priv(dev);
835
+ struct sc92031_priv *priv = from_tasklet(priv, t, tasklet);
836
+ struct net_device *dev = priv->ndev;
838837 void __iomem *port_base = priv->port_base;
839838 u32 intr_status, intr_mask;
840839
....@@ -867,7 +866,6 @@
867866 rmb();
868867
869868 iowrite32(intr_mask, port_base + IntrMask);
870
- mmiowb();
871869
872870 spin_unlock(&priv->lock);
873871 }
....@@ -901,7 +899,6 @@
901899 rmb();
902900
903901 iowrite32(intr_mask, port_base + IntrMask);
904
- mmiowb();
905902
906903 return IRQ_NONE;
907904 }
....@@ -978,7 +975,6 @@
978975 iowrite32(priv->tx_bufs_dma_addr + entry * TX_BUF_SIZE,
979976 port_base + TxAddr0 + entry * 4);
980977 iowrite32(tx_status, port_base + TxStatus0 + entry * 4);
981
- mmiowb();
982978
983979 if (priv->tx_head - priv->tx_tail >= NUM_TX_DESC)
984980 netif_stop_queue(dev);
....@@ -998,15 +994,15 @@
998994 struct sc92031_priv *priv = netdev_priv(dev);
999995 struct pci_dev *pdev = priv->pdev;
1000996
1001
- priv->rx_ring = pci_alloc_consistent(pdev, RX_BUF_LEN,
1002
- &priv->rx_ring_dma_addr);
997
+ priv->rx_ring = dma_alloc_coherent(&pdev->dev, RX_BUF_LEN,
998
+ &priv->rx_ring_dma_addr, GFP_KERNEL);
1003999 if (unlikely(!priv->rx_ring)) {
10041000 err = -ENOMEM;
10051001 goto out_alloc_rx_ring;
10061002 }
10071003
1008
- priv->tx_bufs = pci_alloc_consistent(pdev, TX_BUF_TOT_LEN,
1009
- &priv->tx_bufs_dma_addr);
1004
+ priv->tx_bufs = dma_alloc_coherent(&pdev->dev, TX_BUF_TOT_LEN,
1005
+ &priv->tx_bufs_dma_addr, GFP_KERNEL);
10101006 if (unlikely(!priv->tx_bufs)) {
10111007 err = -ENOMEM;
10121008 goto out_alloc_tx_bufs;
....@@ -1024,7 +1020,6 @@
10241020 spin_lock_bh(&priv->lock);
10251021
10261022 _sc92031_reset(dev);
1027
- mmiowb();
10281023
10291024 spin_unlock_bh(&priv->lock);
10301025 sc92031_enable_interrupts(dev);
....@@ -1037,11 +1032,11 @@
10371032 return 0;
10381033
10391034 out_request_irq:
1040
- pci_free_consistent(pdev, TX_BUF_TOT_LEN, priv->tx_bufs,
1041
- priv->tx_bufs_dma_addr);
1035
+ dma_free_coherent(&pdev->dev, TX_BUF_TOT_LEN, priv->tx_bufs,
1036
+ priv->tx_bufs_dma_addr);
10421037 out_alloc_tx_bufs:
1043
- pci_free_consistent(pdev, RX_BUF_LEN, priv->rx_ring,
1044
- priv->rx_ring_dma_addr);
1038
+ dma_free_coherent(&pdev->dev, RX_BUF_LEN, priv->rx_ring,
1039
+ priv->rx_ring_dma_addr);
10451040 out_alloc_rx_ring:
10461041 return err;
10471042 }
....@@ -1060,15 +1055,14 @@
10601055
10611056 _sc92031_disable_tx_rx(dev);
10621057 _sc92031_tx_clear(dev);
1063
- mmiowb();
10641058
10651059 spin_unlock_bh(&priv->lock);
10661060
10671061 free_irq(pdev->irq, dev);
1068
- pci_free_consistent(pdev, TX_BUF_TOT_LEN, priv->tx_bufs,
1069
- priv->tx_bufs_dma_addr);
1070
- pci_free_consistent(pdev, RX_BUF_LEN, priv->rx_ring,
1071
- priv->rx_ring_dma_addr);
1062
+ dma_free_coherent(&pdev->dev, TX_BUF_TOT_LEN, priv->tx_bufs,
1063
+ priv->tx_bufs_dma_addr);
1064
+ dma_free_coherent(&pdev->dev, RX_BUF_LEN, priv->rx_ring,
1065
+ priv->rx_ring_dma_addr);
10721066
10731067 return 0;
10741068 }
....@@ -1081,12 +1075,11 @@
10811075
10821076 _sc92031_set_mar(dev);
10831077 _sc92031_set_rx_config(dev);
1084
- mmiowb();
10851078
10861079 spin_unlock_bh(&priv->lock);
10871080 }
10881081
1089
-static void sc92031_tx_timeout(struct net_device *dev)
1082
+static void sc92031_tx_timeout(struct net_device *dev, unsigned int txqueue)
10901083 {
10911084 struct sc92031_priv *priv = netdev_priv(dev);
10921085
....@@ -1098,7 +1091,6 @@
10981091 priv->tx_timeouts++;
10991092
11001093 _sc92031_reset(dev);
1101
- mmiowb();
11021094
11031095 spin_unlock(&priv->lock);
11041096
....@@ -1117,7 +1109,7 @@
11171109
11181110 disable_irq(irq);
11191111 if (sc92031_interrupt(irq, dev) != IRQ_NONE)
1120
- sc92031_tasklet((unsigned long)dev);
1112
+ sc92031_tasklet(&priv->tasklet);
11211113 enable_irq(irq);
11221114 }
11231115 #endif
....@@ -1140,7 +1132,6 @@
11401132
11411133 output_status = _sc92031_mii_read(port_base, MII_OutputStatus);
11421134 _sc92031_mii_scan(port_base);
1143
- mmiowb();
11441135
11451136 spin_unlock_bh(&priv->lock);
11461137
....@@ -1311,7 +1302,6 @@
13111302
13121303 priv->pm_config = pm_config;
13131304 iowrite32(pm_config, port_base + PMConfig);
1314
- mmiowb();
13151305
13161306 spin_unlock_bh(&priv->lock);
13171307
....@@ -1337,7 +1327,6 @@
13371327
13381328 out:
13391329 _sc92031_mii_scan(port_base);
1340
- mmiowb();
13411330
13421331 spin_unlock_bh(&priv->lock);
13431332
....@@ -1419,11 +1408,11 @@
14191408
14201409 pci_set_master(pdev);
14211410
1422
- err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
1411
+ err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
14231412 if (unlikely(err < 0))
14241413 goto out_set_dma_mask;
14251414
1426
- err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
1415
+ err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
14271416 if (unlikely(err < 0))
14281417 goto out_set_dma_mask;
14291418
....@@ -1455,10 +1444,11 @@
14551444 dev->ethtool_ops = &sc92031_ethtool_ops;
14561445
14571446 priv = netdev_priv(dev);
1447
+ priv->ndev = dev;
14581448 spin_lock_init(&priv->lock);
14591449 priv->port_base = port_base;
14601450 priv->pdev = pdev;
1461
- tasklet_init(&priv->tasklet, sc92031_tasklet, (unsigned long)dev);
1451
+ tasklet_setup(&priv->tasklet, sc92031_tasklet);
14621452 /* Fudge tasklet count so the call to sc92031_enable_interrupts at
14631453 * sc92031_open will work correctly */
14641454 tasklet_disable_nosync(&priv->tasklet);
....@@ -1511,15 +1501,13 @@
15111501 pci_disable_device(pdev);
15121502 }
15131503
1514
-static int sc92031_suspend(struct pci_dev *pdev, pm_message_t state)
1504
+static int __maybe_unused sc92031_suspend(struct device *dev_d)
15151505 {
1516
- struct net_device *dev = pci_get_drvdata(pdev);
1506
+ struct net_device *dev = dev_get_drvdata(dev_d);
15171507 struct sc92031_priv *priv = netdev_priv(dev);
15181508
1519
- pci_save_state(pdev);
1520
-
15211509 if (!netif_running(dev))
1522
- goto out;
1510
+ return 0;
15231511
15241512 netif_device_detach(dev);
15251513
....@@ -1530,32 +1518,24 @@
15301518
15311519 _sc92031_disable_tx_rx(dev);
15321520 _sc92031_tx_clear(dev);
1533
- mmiowb();
15341521
15351522 spin_unlock_bh(&priv->lock);
1536
-
1537
-out:
1538
- pci_set_power_state(pdev, pci_choose_state(pdev, state));
15391523
15401524 return 0;
15411525 }
15421526
1543
-static int sc92031_resume(struct pci_dev *pdev)
1527
+static int __maybe_unused sc92031_resume(struct device *dev_d)
15441528 {
1545
- struct net_device *dev = pci_get_drvdata(pdev);
1529
+ struct net_device *dev = dev_get_drvdata(dev_d);
15461530 struct sc92031_priv *priv = netdev_priv(dev);
15471531
1548
- pci_restore_state(pdev);
1549
- pci_set_power_state(pdev, PCI_D0);
1550
-
15511532 if (!netif_running(dev))
1552
- goto out;
1533
+ return 0;
15531534
15541535 /* Interrupts already disabled by sc92031_suspend */
15551536 spin_lock_bh(&priv->lock);
15561537
15571538 _sc92031_reset(dev);
1558
- mmiowb();
15591539
15601540 spin_unlock_bh(&priv->lock);
15611541 sc92031_enable_interrupts(dev);
....@@ -1567,7 +1547,6 @@
15671547 else
15681548 netif_tx_disable(dev);
15691549
1570
-out:
15711550 return 0;
15721551 }
15731552
....@@ -1579,13 +1558,14 @@
15791558 };
15801559 MODULE_DEVICE_TABLE(pci, sc92031_pci_device_id_table);
15811560
1561
+static SIMPLE_DEV_PM_OPS(sc92031_pm_ops, sc92031_suspend, sc92031_resume);
1562
+
15821563 static struct pci_driver sc92031_pci_driver = {
15831564 .name = SC92031_NAME,
15841565 .id_table = sc92031_pci_device_id_table,
15851566 .probe = sc92031_probe,
15861567 .remove = sc92031_remove,
1587
- .suspend = sc92031_suspend,
1588
- .resume = sc92031_resume,
1568
+ .driver.pm = &sc92031_pm_ops,
15891569 };
15901570
15911571 module_pci_driver(sc92031_pci_driver);