forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/net/ethernet/marvell/sky2.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * New driver for Marvell Yukon 2 chipset.
34 * Based on earlier sk98lin, and skge driver.
....@@ -7,19 +8,6 @@
78 * those should be done at higher levels.
89 *
910 * Copyright (C) 2005 Stephen Hemminger <shemminger@osdl.org>
10
- *
11
- * This program is free software; you can redistribute it and/or modify
12
- * it under the terms of the GNU General Public License as published by
13
- * the Free Software Foundation; either version 2 of the License.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
2311 */
2412
2513 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -1139,9 +1127,6 @@
11391127 /* Make sure write' to descriptors are complete before we tell hardware */
11401128 wmb();
11411129 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx);
1142
-
1143
- /* Synchronize I/O on since next processor may write to tail */
1144
- mmiowb();
11451130 }
11461131
11471132
....@@ -1224,8 +1209,9 @@
12241209 struct sk_buff *skb = re->skb;
12251210 int i;
12261211
1227
- re->data_addr = pci_map_single(pdev, skb->data, size, PCI_DMA_FROMDEVICE);
1228
- if (pci_dma_mapping_error(pdev, re->data_addr))
1212
+ re->data_addr = dma_map_single(&pdev->dev, skb->data, size,
1213
+ DMA_FROM_DEVICE);
1214
+ if (dma_mapping_error(&pdev->dev, re->data_addr))
12291215 goto mapping_error;
12301216
12311217 dma_unmap_len_set(re, data_size, size);
....@@ -1244,13 +1230,13 @@
12441230
12451231 map_page_error:
12461232 while (--i >= 0) {
1247
- pci_unmap_page(pdev, re->frag_addr[i],
1233
+ dma_unmap_page(&pdev->dev, re->frag_addr[i],
12481234 skb_frag_size(&skb_shinfo(skb)->frags[i]),
1249
- PCI_DMA_FROMDEVICE);
1235
+ DMA_FROM_DEVICE);
12501236 }
12511237
1252
- pci_unmap_single(pdev, re->data_addr, dma_unmap_len(re, data_size),
1253
- PCI_DMA_FROMDEVICE);
1238
+ dma_unmap_single(&pdev->dev, re->data_addr,
1239
+ dma_unmap_len(re, data_size), DMA_FROM_DEVICE);
12541240
12551241 mapping_error:
12561242 if (net_ratelimit())
....@@ -1264,13 +1250,13 @@
12641250 struct sk_buff *skb = re->skb;
12651251 int i;
12661252
1267
- pci_unmap_single(pdev, re->data_addr, dma_unmap_len(re, data_size),
1268
- PCI_DMA_FROMDEVICE);
1253
+ dma_unmap_single(&pdev->dev, re->data_addr,
1254
+ dma_unmap_len(re, data_size), DMA_FROM_DEVICE);
12691255
12701256 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
1271
- pci_unmap_page(pdev, re->frag_addr[i],
1257
+ dma_unmap_page(&pdev->dev, re->frag_addr[i],
12721258 skb_frag_size(&skb_shinfo(skb)->frags[i]),
1273
- PCI_DMA_FROMDEVICE);
1259
+ DMA_FROM_DEVICE);
12741260 }
12751261
12761262 /* Tell chip where to start receive checksum.
....@@ -1354,7 +1340,6 @@
13541340
13551341 /* reset the Rx prefetch unit */
13561342 sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
1357
- mmiowb();
13581343 }
13591344
13601345 /* Clean out receive buffer area, assumes receiver hardware stopped */
....@@ -1391,7 +1376,7 @@
13911376 case SIOCGMIIPHY:
13921377 data->phy_id = PHY_ADDR_MARV;
13931378
1394
- /* fallthru */
1379
+ fallthrough;
13951380 case SIOCGMIIREG: {
13961381 u16 val = 0;
13971382
....@@ -1608,10 +1593,9 @@
16081593 struct sky2_hw *hw = sky2->hw;
16091594
16101595 /* must be power of 2 */
1611
- sky2->tx_le = pci_alloc_consistent(hw->pdev,
1612
- sky2->tx_ring_size *
1613
- sizeof(struct sky2_tx_le),
1614
- &sky2->tx_le_map);
1596
+ sky2->tx_le = dma_alloc_coherent(&hw->pdev->dev,
1597
+ sky2->tx_ring_size * sizeof(struct sky2_tx_le),
1598
+ &sky2->tx_le_map, GFP_KERNEL);
16151599 if (!sky2->tx_le)
16161600 goto nomem;
16171601
....@@ -1620,8 +1604,8 @@
16201604 if (!sky2->tx_ring)
16211605 goto nomem;
16221606
1623
- sky2->rx_le = pci_zalloc_consistent(hw->pdev, RX_LE_BYTES,
1624
- &sky2->rx_le_map);
1607
+ sky2->rx_le = dma_alloc_coherent(&hw->pdev->dev, RX_LE_BYTES,
1608
+ &sky2->rx_le_map, GFP_KERNEL);
16251609 if (!sky2->rx_le)
16261610 goto nomem;
16271611
....@@ -1642,14 +1626,14 @@
16421626 sky2_rx_clean(sky2);
16431627
16441628 if (sky2->rx_le) {
1645
- pci_free_consistent(hw->pdev, RX_LE_BYTES,
1646
- sky2->rx_le, sky2->rx_le_map);
1629
+ dma_free_coherent(&hw->pdev->dev, RX_LE_BYTES, sky2->rx_le,
1630
+ sky2->rx_le_map);
16471631 sky2->rx_le = NULL;
16481632 }
16491633 if (sky2->tx_le) {
1650
- pci_free_consistent(hw->pdev,
1651
- sky2->tx_ring_size * sizeof(struct sky2_tx_le),
1652
- sky2->tx_le, sky2->tx_le_map);
1634
+ dma_free_coherent(&hw->pdev->dev,
1635
+ sky2->tx_ring_size * sizeof(struct sky2_tx_le),
1636
+ sky2->tx_le, sky2->tx_le_map);
16531637 sky2->tx_le = NULL;
16541638 }
16551639 kfree(sky2->tx_ring);
....@@ -1822,13 +1806,11 @@
18221806 static void sky2_tx_unmap(struct pci_dev *pdev, struct tx_ring_info *re)
18231807 {
18241808 if (re->flags & TX_MAP_SINGLE)
1825
- pci_unmap_single(pdev, dma_unmap_addr(re, mapaddr),
1826
- dma_unmap_len(re, maplen),
1827
- PCI_DMA_TODEVICE);
1809
+ dma_unmap_single(&pdev->dev, dma_unmap_addr(re, mapaddr),
1810
+ dma_unmap_len(re, maplen), DMA_TO_DEVICE);
18281811 else if (re->flags & TX_MAP_PAGE)
1829
- pci_unmap_page(pdev, dma_unmap_addr(re, mapaddr),
1830
- dma_unmap_len(re, maplen),
1831
- PCI_DMA_TODEVICE);
1812
+ dma_unmap_page(&pdev->dev, dma_unmap_addr(re, mapaddr),
1813
+ dma_unmap_len(re, maplen), DMA_TO_DEVICE);
18321814 re->flags = 0;
18331815 }
18341816
....@@ -1856,9 +1838,10 @@
18561838 return NETDEV_TX_BUSY;
18571839
18581840 len = skb_headlen(skb);
1859
- mapping = pci_map_single(hw->pdev, skb->data, len, PCI_DMA_TODEVICE);
1841
+ mapping = dma_map_single(&hw->pdev->dev, skb->data, len,
1842
+ DMA_TO_DEVICE);
18601843
1861
- if (pci_dma_mapping_error(hw->pdev, mapping))
1844
+ if (dma_mapping_error(&hw->pdev->dev, mapping))
18621845 goto mapping_error;
18631846
18641847 slot = sky2->tx_prod;
....@@ -2374,7 +2357,7 @@
23742357 /* Transmit timeout is only called if we are running, carrier is up
23752358 * and tx queue is full (stopped).
23762359 */
2377
-static void sky2_tx_timeout(struct net_device *dev)
2360
+static void sky2_tx_timeout(struct net_device *dev, unsigned int txqueue)
23782361 {
23792362 struct sky2_port *sky2 = netdev_priv(dev);
23802363 struct sky2_hw *hw = sky2->hw;
....@@ -2480,19 +2463,18 @@
24802463
24812464 skb = netdev_alloc_skb_ip_align(sky2->netdev, length);
24822465 if (likely(skb)) {
2483
- pci_dma_sync_single_for_cpu(sky2->hw->pdev, re->data_addr,
2484
- length, PCI_DMA_FROMDEVICE);
2466
+ dma_sync_single_for_cpu(&sky2->hw->pdev->dev, re->data_addr,
2467
+ length, DMA_FROM_DEVICE);
24852468 skb_copy_from_linear_data(re->skb, skb->data, length);
24862469 skb->ip_summed = re->skb->ip_summed;
24872470 skb->csum = re->skb->csum;
24882471 skb_copy_hash(skb, re->skb);
2489
- skb->vlan_proto = re->skb->vlan_proto;
2490
- skb->vlan_tci = re->skb->vlan_tci;
2472
+ __vlan_hwaccel_copy_tag(skb, re->skb);
24912473
2492
- pci_dma_sync_single_for_device(sky2->hw->pdev, re->data_addr,
2493
- length, PCI_DMA_FROMDEVICE);
2494
- re->skb->vlan_proto = 0;
2495
- re->skb->vlan_tci = 0;
2474
+ dma_sync_single_for_device(&sky2->hw->pdev->dev,
2475
+ re->data_addr, length,
2476
+ DMA_FROM_DEVICE);
2477
+ __vlan_hwaccel_clear_tag(re->skb);
24962478 skb_clear_hash(re->skb);
24972479 re->skb->ip_summed = CHECKSUM_NONE;
24982480 skb_put(skb, length);
....@@ -2782,7 +2764,7 @@
27822764
27832765 case OP_RXCHKSVLAN:
27842766 sky2_rx_tag(sky2, length);
2785
- /* fall through */
2767
+ fallthrough;
27862768 case OP_RXCHKS:
27872769 if (likely(dev->features & NETIF_F_RXCSUM))
27882770 sky2_rx_checksum(sky2, status);
....@@ -4418,6 +4400,10 @@
44184400 }
44194401
44204402 static const struct ethtool_ops sky2_ethtool_ops = {
4403
+ .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
4404
+ ETHTOOL_COALESCE_MAX_FRAMES |
4405
+ ETHTOOL_COALESCE_RX_USECS_IRQ |
4406
+ ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ,
44214407 .get_drvinfo = sky2_get_drvinfo,
44224408 .get_wol = sky2_get_wol,
44234409 .set_wol = sky2_set_wol,
....@@ -4624,19 +4610,7 @@
46244610 napi_enable(&hw->napi);
46254611 return 0;
46264612 }
4627
-
4628
-static int sky2_debug_open(struct inode *inode, struct file *file)
4629
-{
4630
- return single_open(file, sky2_debug_show, inode->i_private);
4631
-}
4632
-
4633
-static const struct file_operations sky2_debug_fops = {
4634
- .owner = THIS_MODULE,
4635
- .open = sky2_debug_open,
4636
- .read = seq_read,
4637
- .llseek = seq_lseek,
4638
- .release = single_release,
4639
-};
4613
+DEFINE_SHOW_ATTRIBUTE(sky2_debug);
46404614
46414615 /*
46424616 * Use network device events to create/remove/rename
....@@ -4822,8 +4796,8 @@
48224796 * 2) from internal registers set by bootloader
48234797 */
48244798 iap = of_get_mac_address(hw->pdev->dev.of_node);
4825
- if (iap)
4826
- memcpy(dev->dev_addr, iap, ETH_ALEN);
4799
+ if (!IS_ERR(iap))
4800
+ ether_addr_copy(dev->dev_addr, iap);
48274801 else
48284802 memcpy_fromio(dev->dev_addr, hw->regs + B2_MAC_1 + port * 8,
48294803 ETH_ALEN);
....@@ -4948,6 +4922,13 @@
49484922 },
49494923 },
49504924 {
4925
+ .ident = "ASUS P5W DH Deluxe",
4926
+ .matches = {
4927
+ DMI_MATCH(DMI_SYS_VENDOR, "ASUSTEK COMPUTER INC"),
4928
+ DMI_MATCH(DMI_PRODUCT_NAME, "P5W DH Deluxe"),
4929
+ },
4930
+ },
4931
+ {
49514932 .ident = "ASUS P6T",
49524933 .matches = {
49534934 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
....@@ -5004,16 +4985,16 @@
50044985 pci_set_master(pdev);
50054986
50064987 if (sizeof(dma_addr_t) > sizeof(u32) &&
5007
- !(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))) {
4988
+ !(err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)))) {
50084989 using_dac = 1;
5009
- err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
4990
+ err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
50104991 if (err < 0) {
50114992 dev_err(&pdev->dev, "unable to obtain 64 bit DMA "
50124993 "for consistent allocations\n");
50134994 goto err_out_free_regions;
50144995 }
50154996 } else {
5016
- err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
4997
+ err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
50174998 if (err) {
50184999 dev_err(&pdev->dev, "no usable DMA configuration\n");
50195000 goto err_out_free_regions;
....@@ -5045,7 +5026,7 @@
50455026 hw->pdev = pdev;
50465027 sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
50475028
5048
- hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
5029
+ hw->regs = ioremap(pci_resource_start(pdev, 0), 0x4000);
50495030 if (!hw->regs) {
50505031 dev_err(&pdev->dev, "cannot map device registers\n");
50515032 goto err_out_free_hw;
....@@ -5057,8 +5038,9 @@
50575038
50585039 /* ring for status responses */
50595040 hw->st_size = hw->ports * roundup_pow_of_two(3*RX_MAX_PENDING + TX_MAX_PENDING);
5060
- hw->st_le = pci_alloc_consistent(pdev, hw->st_size * sizeof(struct sky2_status_le),
5061
- &hw->st_dma);
5041
+ hw->st_le = dma_alloc_coherent(&pdev->dev,
5042
+ hw->st_size * sizeof(struct sky2_status_le),
5043
+ &hw->st_dma, GFP_KERNEL);
50625044 if (!hw->st_le) {
50635045 err = -ENOMEM;
50645046 goto err_out_reset;
....@@ -5123,7 +5105,7 @@
51235105 INIT_WORK(&hw->restart_work, sky2_restart);
51245106
51255107 pci_set_drvdata(pdev, hw);
5126
- pdev->d3_delay = 300;
5108
+ pdev->d3hot_delay = 300;
51275109
51285110 return 0;
51295111
....@@ -5138,8 +5120,9 @@
51385120 pci_disable_msi(pdev);
51395121 free_netdev(dev);
51405122 err_out_free_pci:
5141
- pci_free_consistent(pdev, hw->st_size * sizeof(struct sky2_status_le),
5142
- hw->st_le, hw->st_dma);
5123
+ dma_free_coherent(&pdev->dev,
5124
+ hw->st_size * sizeof(struct sky2_status_le),
5125
+ hw->st_le, hw->st_dma);
51435126 err_out_reset:
51445127 sky2_write8(hw, B0_CTST, CS_RST_SET);
51455128 err_out_iounmap:
....@@ -5183,8 +5166,9 @@
51835166
51845167 if (hw->flags & SKY2_HW_USE_MSI)
51855168 pci_disable_msi(pdev);
5186
- pci_free_consistent(pdev, hw->st_size * sizeof(struct sky2_status_le),
5187
- hw->st_le, hw->st_dma);
5169
+ dma_free_coherent(&pdev->dev,
5170
+ hw->st_size * sizeof(struct sky2_status_le),
5171
+ hw->st_le, hw->st_dma);
51885172 pci_release_regions(pdev);
51895173 pci_disable_device(pdev);
51905174
....@@ -5197,8 +5181,7 @@
51975181
51985182 static int sky2_suspend(struct device *dev)
51995183 {
5200
- struct pci_dev *pdev = to_pci_dev(dev);
5201
- struct sky2_hw *hw = pci_get_drvdata(pdev);
5184
+ struct sky2_hw *hw = dev_get_drvdata(dev);
52025185 int i;
52035186
52045187 if (!hw)