| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* Silan SC92031 PCI Fast Ethernet Adapter driver |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Based on vendor drivers: |
|---|
| .. | .. |
|---|
| 251 | 252 | * use of mdelay() at _sc92031_reset. |
|---|
| 252 | 253 | * Functions prefixed with _sc92031_ must be called with the lock held; |
|---|
| 253 | 254 | * functions prefixed with sc92031_ must be called without the lock held. |
|---|
| 254 | | - * Use mmiowb() before unlocking if the hardware was written to. |
|---|
| 255 | 255 | */ |
|---|
| 256 | 256 | |
|---|
| 257 | 257 | /* Locking rules for the interrupt: |
|---|
| .. | .. |
|---|
| 301 | 301 | |
|---|
| 302 | 302 | /* for dev->get_stats */ |
|---|
| 303 | 303 | long rx_value; |
|---|
| 304 | + struct net_device *ndev; |
|---|
| 304 | 305 | }; |
|---|
| 305 | 306 | |
|---|
| 306 | 307 | /* I don't know which registers can be safely read; however, I can guess |
|---|
| .. | .. |
|---|
| 361 | 362 | /* stop interrupts */ |
|---|
| 362 | 363 | iowrite32(0, port_base + IntrMask); |
|---|
| 363 | 364 | _sc92031_dummy_read(port_base); |
|---|
| 364 | | - mmiowb(); |
|---|
| 365 | 365 | |
|---|
| 366 | 366 | /* wait for any concurrent interrupt/tasklet to finish */ |
|---|
| 367 | 367 | synchronize_irq(priv->pdev->irq); |
|---|
| .. | .. |
|---|
| 379 | 379 | wmb(); |
|---|
| 380 | 380 | |
|---|
| 381 | 381 | iowrite32(IntrBits, port_base + IntrMask); |
|---|
| 382 | | - mmiowb(); |
|---|
| 383 | 382 | } |
|---|
| 384 | 383 | |
|---|
| 385 | 384 | static void _sc92031_disable_tx_rx(struct net_device *dev) |
|---|
| .. | .. |
|---|
| 831 | 830 | } |
|---|
| 832 | 831 | } |
|---|
| 833 | 832 | |
|---|
| 834 | | -static void sc92031_tasklet(unsigned long data) |
|---|
| 833 | +static void sc92031_tasklet(struct tasklet_struct *t) |
|---|
| 835 | 834 | { |
|---|
| 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; |
|---|
| 838 | 837 | void __iomem *port_base = priv->port_base; |
|---|
| 839 | 838 | u32 intr_status, intr_mask; |
|---|
| 840 | 839 | |
|---|
| .. | .. |
|---|
| 867 | 866 | rmb(); |
|---|
| 868 | 867 | |
|---|
| 869 | 868 | iowrite32(intr_mask, port_base + IntrMask); |
|---|
| 870 | | - mmiowb(); |
|---|
| 871 | 869 | |
|---|
| 872 | 870 | spin_unlock(&priv->lock); |
|---|
| 873 | 871 | } |
|---|
| .. | .. |
|---|
| 901 | 899 | rmb(); |
|---|
| 902 | 900 | |
|---|
| 903 | 901 | iowrite32(intr_mask, port_base + IntrMask); |
|---|
| 904 | | - mmiowb(); |
|---|
| 905 | 902 | |
|---|
| 906 | 903 | return IRQ_NONE; |
|---|
| 907 | 904 | } |
|---|
| .. | .. |
|---|
| 978 | 975 | iowrite32(priv->tx_bufs_dma_addr + entry * TX_BUF_SIZE, |
|---|
| 979 | 976 | port_base + TxAddr0 + entry * 4); |
|---|
| 980 | 977 | iowrite32(tx_status, port_base + TxStatus0 + entry * 4); |
|---|
| 981 | | - mmiowb(); |
|---|
| 982 | 978 | |
|---|
| 983 | 979 | if (priv->tx_head - priv->tx_tail >= NUM_TX_DESC) |
|---|
| 984 | 980 | netif_stop_queue(dev); |
|---|
| .. | .. |
|---|
| 998 | 994 | struct sc92031_priv *priv = netdev_priv(dev); |
|---|
| 999 | 995 | struct pci_dev *pdev = priv->pdev; |
|---|
| 1000 | 996 | |
|---|
| 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); |
|---|
| 1003 | 999 | if (unlikely(!priv->rx_ring)) { |
|---|
| 1004 | 1000 | err = -ENOMEM; |
|---|
| 1005 | 1001 | goto out_alloc_rx_ring; |
|---|
| 1006 | 1002 | } |
|---|
| 1007 | 1003 | |
|---|
| 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); |
|---|
| 1010 | 1006 | if (unlikely(!priv->tx_bufs)) { |
|---|
| 1011 | 1007 | err = -ENOMEM; |
|---|
| 1012 | 1008 | goto out_alloc_tx_bufs; |
|---|
| .. | .. |
|---|
| 1024 | 1020 | spin_lock_bh(&priv->lock); |
|---|
| 1025 | 1021 | |
|---|
| 1026 | 1022 | _sc92031_reset(dev); |
|---|
| 1027 | | - mmiowb(); |
|---|
| 1028 | 1023 | |
|---|
| 1029 | 1024 | spin_unlock_bh(&priv->lock); |
|---|
| 1030 | 1025 | sc92031_enable_interrupts(dev); |
|---|
| .. | .. |
|---|
| 1037 | 1032 | return 0; |
|---|
| 1038 | 1033 | |
|---|
| 1039 | 1034 | 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); |
|---|
| 1042 | 1037 | 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); |
|---|
| 1045 | 1040 | out_alloc_rx_ring: |
|---|
| 1046 | 1041 | return err; |
|---|
| 1047 | 1042 | } |
|---|
| .. | .. |
|---|
| 1060 | 1055 | |
|---|
| 1061 | 1056 | _sc92031_disable_tx_rx(dev); |
|---|
| 1062 | 1057 | _sc92031_tx_clear(dev); |
|---|
| 1063 | | - mmiowb(); |
|---|
| 1064 | 1058 | |
|---|
| 1065 | 1059 | spin_unlock_bh(&priv->lock); |
|---|
| 1066 | 1060 | |
|---|
| 1067 | 1061 | 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); |
|---|
| 1072 | 1066 | |
|---|
| 1073 | 1067 | return 0; |
|---|
| 1074 | 1068 | } |
|---|
| .. | .. |
|---|
| 1081 | 1075 | |
|---|
| 1082 | 1076 | _sc92031_set_mar(dev); |
|---|
| 1083 | 1077 | _sc92031_set_rx_config(dev); |
|---|
| 1084 | | - mmiowb(); |
|---|
| 1085 | 1078 | |
|---|
| 1086 | 1079 | spin_unlock_bh(&priv->lock); |
|---|
| 1087 | 1080 | } |
|---|
| 1088 | 1081 | |
|---|
| 1089 | | -static void sc92031_tx_timeout(struct net_device *dev) |
|---|
| 1082 | +static void sc92031_tx_timeout(struct net_device *dev, unsigned int txqueue) |
|---|
| 1090 | 1083 | { |
|---|
| 1091 | 1084 | struct sc92031_priv *priv = netdev_priv(dev); |
|---|
| 1092 | 1085 | |
|---|
| .. | .. |
|---|
| 1098 | 1091 | priv->tx_timeouts++; |
|---|
| 1099 | 1092 | |
|---|
| 1100 | 1093 | _sc92031_reset(dev); |
|---|
| 1101 | | - mmiowb(); |
|---|
| 1102 | 1094 | |
|---|
| 1103 | 1095 | spin_unlock(&priv->lock); |
|---|
| 1104 | 1096 | |
|---|
| .. | .. |
|---|
| 1117 | 1109 | |
|---|
| 1118 | 1110 | disable_irq(irq); |
|---|
| 1119 | 1111 | if (sc92031_interrupt(irq, dev) != IRQ_NONE) |
|---|
| 1120 | | - sc92031_tasklet((unsigned long)dev); |
|---|
| 1112 | + sc92031_tasklet(&priv->tasklet); |
|---|
| 1121 | 1113 | enable_irq(irq); |
|---|
| 1122 | 1114 | } |
|---|
| 1123 | 1115 | #endif |
|---|
| .. | .. |
|---|
| 1140 | 1132 | |
|---|
| 1141 | 1133 | output_status = _sc92031_mii_read(port_base, MII_OutputStatus); |
|---|
| 1142 | 1134 | _sc92031_mii_scan(port_base); |
|---|
| 1143 | | - mmiowb(); |
|---|
| 1144 | 1135 | |
|---|
| 1145 | 1136 | spin_unlock_bh(&priv->lock); |
|---|
| 1146 | 1137 | |
|---|
| .. | .. |
|---|
| 1311 | 1302 | |
|---|
| 1312 | 1303 | priv->pm_config = pm_config; |
|---|
| 1313 | 1304 | iowrite32(pm_config, port_base + PMConfig); |
|---|
| 1314 | | - mmiowb(); |
|---|
| 1315 | 1305 | |
|---|
| 1316 | 1306 | spin_unlock_bh(&priv->lock); |
|---|
| 1317 | 1307 | |
|---|
| .. | .. |
|---|
| 1337 | 1327 | |
|---|
| 1338 | 1328 | out: |
|---|
| 1339 | 1329 | _sc92031_mii_scan(port_base); |
|---|
| 1340 | | - mmiowb(); |
|---|
| 1341 | 1330 | |
|---|
| 1342 | 1331 | spin_unlock_bh(&priv->lock); |
|---|
| 1343 | 1332 | |
|---|
| .. | .. |
|---|
| 1419 | 1408 | |
|---|
| 1420 | 1409 | pci_set_master(pdev); |
|---|
| 1421 | 1410 | |
|---|
| 1422 | | - err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
|---|
| 1411 | + err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 1423 | 1412 | if (unlikely(err < 0)) |
|---|
| 1424 | 1413 | goto out_set_dma_mask; |
|---|
| 1425 | 1414 | |
|---|
| 1426 | | - err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
|---|
| 1415 | + err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); |
|---|
| 1427 | 1416 | if (unlikely(err < 0)) |
|---|
| 1428 | 1417 | goto out_set_dma_mask; |
|---|
| 1429 | 1418 | |
|---|
| .. | .. |
|---|
| 1455 | 1444 | dev->ethtool_ops = &sc92031_ethtool_ops; |
|---|
| 1456 | 1445 | |
|---|
| 1457 | 1446 | priv = netdev_priv(dev); |
|---|
| 1447 | + priv->ndev = dev; |
|---|
| 1458 | 1448 | spin_lock_init(&priv->lock); |
|---|
| 1459 | 1449 | priv->port_base = port_base; |
|---|
| 1460 | 1450 | priv->pdev = pdev; |
|---|
| 1461 | | - tasklet_init(&priv->tasklet, sc92031_tasklet, (unsigned long)dev); |
|---|
| 1451 | + tasklet_setup(&priv->tasklet, sc92031_tasklet); |
|---|
| 1462 | 1452 | /* Fudge tasklet count so the call to sc92031_enable_interrupts at |
|---|
| 1463 | 1453 | * sc92031_open will work correctly */ |
|---|
| 1464 | 1454 | tasklet_disable_nosync(&priv->tasklet); |
|---|
| .. | .. |
|---|
| 1511 | 1501 | pci_disable_device(pdev); |
|---|
| 1512 | 1502 | } |
|---|
| 1513 | 1503 | |
|---|
| 1514 | | -static int sc92031_suspend(struct pci_dev *pdev, pm_message_t state) |
|---|
| 1504 | +static int __maybe_unused sc92031_suspend(struct device *dev_d) |
|---|
| 1515 | 1505 | { |
|---|
| 1516 | | - struct net_device *dev = pci_get_drvdata(pdev); |
|---|
| 1506 | + struct net_device *dev = dev_get_drvdata(dev_d); |
|---|
| 1517 | 1507 | struct sc92031_priv *priv = netdev_priv(dev); |
|---|
| 1518 | 1508 | |
|---|
| 1519 | | - pci_save_state(pdev); |
|---|
| 1520 | | - |
|---|
| 1521 | 1509 | if (!netif_running(dev)) |
|---|
| 1522 | | - goto out; |
|---|
| 1510 | + return 0; |
|---|
| 1523 | 1511 | |
|---|
| 1524 | 1512 | netif_device_detach(dev); |
|---|
| 1525 | 1513 | |
|---|
| .. | .. |
|---|
| 1530 | 1518 | |
|---|
| 1531 | 1519 | _sc92031_disable_tx_rx(dev); |
|---|
| 1532 | 1520 | _sc92031_tx_clear(dev); |
|---|
| 1533 | | - mmiowb(); |
|---|
| 1534 | 1521 | |
|---|
| 1535 | 1522 | spin_unlock_bh(&priv->lock); |
|---|
| 1536 | | - |
|---|
| 1537 | | -out: |
|---|
| 1538 | | - pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
|---|
| 1539 | 1523 | |
|---|
| 1540 | 1524 | return 0; |
|---|
| 1541 | 1525 | } |
|---|
| 1542 | 1526 | |
|---|
| 1543 | | -static int sc92031_resume(struct pci_dev *pdev) |
|---|
| 1527 | +static int __maybe_unused sc92031_resume(struct device *dev_d) |
|---|
| 1544 | 1528 | { |
|---|
| 1545 | | - struct net_device *dev = pci_get_drvdata(pdev); |
|---|
| 1529 | + struct net_device *dev = dev_get_drvdata(dev_d); |
|---|
| 1546 | 1530 | struct sc92031_priv *priv = netdev_priv(dev); |
|---|
| 1547 | 1531 | |
|---|
| 1548 | | - pci_restore_state(pdev); |
|---|
| 1549 | | - pci_set_power_state(pdev, PCI_D0); |
|---|
| 1550 | | - |
|---|
| 1551 | 1532 | if (!netif_running(dev)) |
|---|
| 1552 | | - goto out; |
|---|
| 1533 | + return 0; |
|---|
| 1553 | 1534 | |
|---|
| 1554 | 1535 | /* Interrupts already disabled by sc92031_suspend */ |
|---|
| 1555 | 1536 | spin_lock_bh(&priv->lock); |
|---|
| 1556 | 1537 | |
|---|
| 1557 | 1538 | _sc92031_reset(dev); |
|---|
| 1558 | | - mmiowb(); |
|---|
| 1559 | 1539 | |
|---|
| 1560 | 1540 | spin_unlock_bh(&priv->lock); |
|---|
| 1561 | 1541 | sc92031_enable_interrupts(dev); |
|---|
| .. | .. |
|---|
| 1567 | 1547 | else |
|---|
| 1568 | 1548 | netif_tx_disable(dev); |
|---|
| 1569 | 1549 | |
|---|
| 1570 | | -out: |
|---|
| 1571 | 1550 | return 0; |
|---|
| 1572 | 1551 | } |
|---|
| 1573 | 1552 | |
|---|
| .. | .. |
|---|
| 1579 | 1558 | }; |
|---|
| 1580 | 1559 | MODULE_DEVICE_TABLE(pci, sc92031_pci_device_id_table); |
|---|
| 1581 | 1560 | |
|---|
| 1561 | +static SIMPLE_DEV_PM_OPS(sc92031_pm_ops, sc92031_suspend, sc92031_resume); |
|---|
| 1562 | + |
|---|
| 1582 | 1563 | static struct pci_driver sc92031_pci_driver = { |
|---|
| 1583 | 1564 | .name = SC92031_NAME, |
|---|
| 1584 | 1565 | .id_table = sc92031_pci_device_id_table, |
|---|
| 1585 | 1566 | .probe = sc92031_probe, |
|---|
| 1586 | 1567 | .remove = sc92031_remove, |
|---|
| 1587 | | - .suspend = sc92031_suspend, |
|---|
| 1588 | | - .resume = sc92031_resume, |
|---|
| 1568 | + .driver.pm = &sc92031_pm_ops, |
|---|
| 1589 | 1569 | }; |
|---|
| 1590 | 1570 | |
|---|
| 1591 | 1571 | module_pci_driver(sc92031_pci_driver); |
|---|