forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/net/ethernet/alteon/acenic.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * acenic.c: Linux driver for the Alteon AceNIC Gigabit Ethernet card
34 * and other Tigon based cards.
....@@ -11,11 +12,6 @@
1112 * setup, please subscribe to the lists if you have any questions
1213 * about the driver. Send mail to linux-acenic-help@sunsite.auc.dk to
1314 * see how to subscribe.
14
- *
15
- * This program is free software; you can redistribute it and/or modify
16
- * it under the terms of the GNU General Public License as published by
17
- * the Free Software Foundation; either version 2 of the License, or
18
- * (at your option) any later version.
1915 *
2016 * Additional credits:
2117 * Pete Wyckoff <wyckoff@ca.sandia.gov>: Initial Linux/Alpha and trace
....@@ -441,7 +437,7 @@
441437 .set_link_ksettings = ace_set_link_ksettings,
442438 };
443439
444
-static void ace_watchdog(struct net_device *dev);
440
+static void ace_watchdog(struct net_device *dev, unsigned int txqueue);
445441
446442 static const struct net_device_ops ace_netdev_ops = {
447443 .ndo_open = ace_open,
....@@ -469,6 +465,7 @@
469465 SET_NETDEV_DEV(dev, &pdev->dev);
470466
471467 ap = netdev_priv(dev);
468
+ ap->ndev = dev;
472469 ap->pdev = pdev;
473470 ap->name = pci_name(pdev);
474471
....@@ -551,7 +548,7 @@
551548 ap->name);
552549 break;
553550 }
554
- /* Fall through */
551
+ fallthrough;
555552 case PCI_VENDOR_ID_SGI:
556553 printk(KERN_INFO "%s: SGI AceNIC ", ap->name);
557554 break;
....@@ -646,9 +643,8 @@
646643
647644 ringp = &ap->skb->rx_std_skbuff[i];
648645 mapping = dma_unmap_addr(ringp, mapping);
649
- pci_unmap_page(ap->pdev, mapping,
650
- ACE_STD_BUFSIZE,
651
- PCI_DMA_FROMDEVICE);
646
+ dma_unmap_page(&ap->pdev->dev, mapping,
647
+ ACE_STD_BUFSIZE, DMA_FROM_DEVICE);
652648
653649 ap->rx_std_ring[i].size = 0;
654650 ap->skb->rx_std_skbuff[i].skb = NULL;
....@@ -666,9 +662,9 @@
666662
667663 ringp = &ap->skb->rx_mini_skbuff[i];
668664 mapping = dma_unmap_addr(ringp,mapping);
669
- pci_unmap_page(ap->pdev, mapping,
665
+ dma_unmap_page(&ap->pdev->dev, mapping,
670666 ACE_MINI_BUFSIZE,
671
- PCI_DMA_FROMDEVICE);
667
+ DMA_FROM_DEVICE);
672668
673669 ap->rx_mini_ring[i].size = 0;
674670 ap->skb->rx_mini_skbuff[i].skb = NULL;
....@@ -685,9 +681,8 @@
685681
686682 ringp = &ap->skb->rx_jumbo_skbuff[i];
687683 mapping = dma_unmap_addr(ringp, mapping);
688
- pci_unmap_page(ap->pdev, mapping,
689
- ACE_JUMBO_BUFSIZE,
690
- PCI_DMA_FROMDEVICE);
684
+ dma_unmap_page(&ap->pdev->dev, mapping,
685
+ ACE_JUMBO_BUFSIZE, DMA_FROM_DEVICE);
691686
692687 ap->rx_jumbo_ring[i].size = 0;
693688 ap->skb->rx_jumbo_skbuff[i].skb = NULL;
....@@ -717,8 +712,8 @@
717712 RX_JUMBO_RING_ENTRIES +
718713 RX_MINI_RING_ENTRIES +
719714 RX_RETURN_RING_ENTRIES));
720
- pci_free_consistent(ap->pdev, size, ap->rx_std_ring,
721
- ap->rx_ring_base_dma);
715
+ dma_free_coherent(&ap->pdev->dev, size, ap->rx_std_ring,
716
+ ap->rx_ring_base_dma);
722717 ap->rx_std_ring = NULL;
723718 ap->rx_jumbo_ring = NULL;
724719 ap->rx_mini_ring = NULL;
....@@ -726,31 +721,30 @@
726721 }
727722 if (ap->evt_ring != NULL) {
728723 size = (sizeof(struct event) * EVT_RING_ENTRIES);
729
- pci_free_consistent(ap->pdev, size, ap->evt_ring,
730
- ap->evt_ring_dma);
724
+ dma_free_coherent(&ap->pdev->dev, size, ap->evt_ring,
725
+ ap->evt_ring_dma);
731726 ap->evt_ring = NULL;
732727 }
733728 if (ap->tx_ring != NULL && !ACE_IS_TIGON_I(ap)) {
734729 size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
735
- pci_free_consistent(ap->pdev, size, ap->tx_ring,
736
- ap->tx_ring_dma);
730
+ dma_free_coherent(&ap->pdev->dev, size, ap->tx_ring,
731
+ ap->tx_ring_dma);
737732 }
738733 ap->tx_ring = NULL;
739734
740735 if (ap->evt_prd != NULL) {
741
- pci_free_consistent(ap->pdev, sizeof(u32),
742
- (void *)ap->evt_prd, ap->evt_prd_dma);
736
+ dma_free_coherent(&ap->pdev->dev, sizeof(u32),
737
+ (void *)ap->evt_prd, ap->evt_prd_dma);
743738 ap->evt_prd = NULL;
744739 }
745740 if (ap->rx_ret_prd != NULL) {
746
- pci_free_consistent(ap->pdev, sizeof(u32),
747
- (void *)ap->rx_ret_prd,
748
- ap->rx_ret_prd_dma);
741
+ dma_free_coherent(&ap->pdev->dev, sizeof(u32),
742
+ (void *)ap->rx_ret_prd, ap->rx_ret_prd_dma);
749743 ap->rx_ret_prd = NULL;
750744 }
751745 if (ap->tx_csm != NULL) {
752
- pci_free_consistent(ap->pdev, sizeof(u32),
753
- (void *)ap->tx_csm, ap->tx_csm_dma);
746
+ dma_free_coherent(&ap->pdev->dev, sizeof(u32),
747
+ (void *)ap->tx_csm, ap->tx_csm_dma);
754748 ap->tx_csm = NULL;
755749 }
756750 }
....@@ -767,8 +761,8 @@
767761 RX_MINI_RING_ENTRIES +
768762 RX_RETURN_RING_ENTRIES));
769763
770
- ap->rx_std_ring = pci_alloc_consistent(ap->pdev, size,
771
- &ap->rx_ring_base_dma);
764
+ ap->rx_std_ring = dma_alloc_coherent(&ap->pdev->dev, size,
765
+ &ap->rx_ring_base_dma, GFP_KERNEL);
772766 if (ap->rx_std_ring == NULL)
773767 goto fail;
774768
....@@ -778,7 +772,8 @@
778772
779773 size = (sizeof(struct event) * EVT_RING_ENTRIES);
780774
781
- ap->evt_ring = pci_alloc_consistent(ap->pdev, size, &ap->evt_ring_dma);
775
+ ap->evt_ring = dma_alloc_coherent(&ap->pdev->dev, size,
776
+ &ap->evt_ring_dma, GFP_KERNEL);
782777
783778 if (ap->evt_ring == NULL)
784779 goto fail;
....@@ -790,25 +785,25 @@
790785 if (!ACE_IS_TIGON_I(ap)) {
791786 size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
792787
793
- ap->tx_ring = pci_alloc_consistent(ap->pdev, size,
794
- &ap->tx_ring_dma);
788
+ ap->tx_ring = dma_alloc_coherent(&ap->pdev->dev, size,
789
+ &ap->tx_ring_dma, GFP_KERNEL);
795790
796791 if (ap->tx_ring == NULL)
797792 goto fail;
798793 }
799794
800
- ap->evt_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
801
- &ap->evt_prd_dma);
795
+ ap->evt_prd = dma_alloc_coherent(&ap->pdev->dev, sizeof(u32),
796
+ &ap->evt_prd_dma, GFP_KERNEL);
802797 if (ap->evt_prd == NULL)
803798 goto fail;
804799
805
- ap->rx_ret_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
806
- &ap->rx_ret_prd_dma);
800
+ ap->rx_ret_prd = dma_alloc_coherent(&ap->pdev->dev, sizeof(u32),
801
+ &ap->rx_ret_prd_dma, GFP_KERNEL);
807802 if (ap->rx_ret_prd == NULL)
808803 goto fail;
809804
810
- ap->tx_csm = pci_alloc_consistent(ap->pdev, sizeof(u32),
811
- &ap->tx_csm_dma);
805
+ ap->tx_csm = dma_alloc_coherent(&ap->pdev->dev, sizeof(u32),
806
+ &ap->tx_csm_dma, GFP_KERNEL);
812807 if (ap->tx_csm == NULL)
813808 goto fail;
814809
....@@ -834,8 +829,8 @@
834829 ace_free_descriptors(dev);
835830
836831 if (ap->info)
837
- pci_free_consistent(ap->pdev, sizeof(struct ace_info),
838
- ap->info, ap->info_dma);
832
+ dma_free_coherent(&ap->pdev->dev, sizeof(struct ace_info),
833
+ ap->info, ap->info_dma);
839834 kfree(ap->skb);
840835 kfree(ap->trace_buf);
841836
....@@ -1133,9 +1128,9 @@
11331128 /*
11341129 * Configure DMA attributes.
11351130 */
1136
- if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
1131
+ if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
11371132 ap->pci_using_dac = 1;
1138
- } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
1133
+ } else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
11391134 ap->pci_using_dac = 0;
11401135 } else {
11411136 ecode = -ENODEV;
....@@ -1147,8 +1142,8 @@
11471142 * and the control blocks for the transmit and receive rings
11481143 * as they need to be setup once and for all.
11491144 */
1150
- if (!(info = pci_alloc_consistent(ap->pdev, sizeof(struct ace_info),
1151
- &ap->info_dma))) {
1145
+ if (!(info = dma_alloc_coherent(&ap->pdev->dev, sizeof(struct ace_info),
1146
+ &ap->info_dma, GFP_KERNEL))) {
11521147 ecode = -EAGAIN;
11531148 goto init_error;
11541149 }
....@@ -1157,7 +1152,7 @@
11571152 /*
11581153 * Get the memory for the skb rings.
11591154 */
1160
- if (!(ap->skb = kmalloc(sizeof(struct ace_skb), GFP_KERNEL))) {
1155
+ if (!(ap->skb = kzalloc(sizeof(struct ace_skb), GFP_KERNEL))) {
11611156 ecode = -EAGAIN;
11621157 goto init_error;
11631158 }
....@@ -1177,9 +1172,6 @@
11771172 ap->last_std_rx = 0;
11781173 ap->last_mini_rx = 0;
11791174 #endif
1180
-
1181
- memset(ap->info, 0, sizeof(struct ace_info));
1182
- memset(ap->skb, 0, sizeof(struct ace_skb));
11831175
11841176 ecode = ace_load_firmware(dev);
11851177 if (ecode)
....@@ -1546,7 +1538,7 @@
15461538 }
15471539
15481540
1549
-static void ace_watchdog(struct net_device *data)
1541
+static void ace_watchdog(struct net_device *data, unsigned int txqueue)
15501542 {
15511543 struct net_device *dev = data;
15521544 struct ace_private *ap = netdev_priv(dev);
....@@ -1571,10 +1563,10 @@
15711563 }
15721564
15731565
1574
-static void ace_tasklet(unsigned long arg)
1566
+static void ace_tasklet(struct tasklet_struct *t)
15751567 {
1576
- struct net_device *dev = (struct net_device *) arg;
1577
- struct ace_private *ap = netdev_priv(dev);
1568
+ struct ace_private *ap = from_tasklet(ap, t, ace_tasklet);
1569
+ struct net_device *dev = ap->ndev;
15781570 int cur_size;
15791571
15801572 cur_size = atomic_read(&ap->cur_rx_bufs);
....@@ -1650,10 +1642,10 @@
16501642 if (!skb)
16511643 break;
16521644
1653
- mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
1645
+ mapping = dma_map_page(&ap->pdev->dev,
1646
+ virt_to_page(skb->data),
16541647 offset_in_page(skb->data),
1655
- ACE_STD_BUFSIZE,
1656
- PCI_DMA_FROMDEVICE);
1648
+ ACE_STD_BUFSIZE, DMA_FROM_DEVICE);
16571649 ap->skb->rx_std_skbuff[idx].skb = skb;
16581650 dma_unmap_addr_set(&ap->skb->rx_std_skbuff[idx],
16591651 mapping, mapping);
....@@ -1711,10 +1703,10 @@
17111703 if (!skb)
17121704 break;
17131705
1714
- mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
1706
+ mapping = dma_map_page(&ap->pdev->dev,
1707
+ virt_to_page(skb->data),
17151708 offset_in_page(skb->data),
1716
- ACE_MINI_BUFSIZE,
1717
- PCI_DMA_FROMDEVICE);
1709
+ ACE_MINI_BUFSIZE, DMA_FROM_DEVICE);
17181710 ap->skb->rx_mini_skbuff[idx].skb = skb;
17191711 dma_unmap_addr_set(&ap->skb->rx_mini_skbuff[idx],
17201712 mapping, mapping);
....@@ -1767,10 +1759,10 @@
17671759 if (!skb)
17681760 break;
17691761
1770
- mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
1762
+ mapping = dma_map_page(&ap->pdev->dev,
1763
+ virt_to_page(skb->data),
17711764 offset_in_page(skb->data),
1772
- ACE_JUMBO_BUFSIZE,
1773
- PCI_DMA_FROMDEVICE);
1765
+ ACE_JUMBO_BUFSIZE, DMA_FROM_DEVICE);
17741766 ap->skb->rx_jumbo_skbuff[idx].skb = skb;
17751767 dma_unmap_addr_set(&ap->skb->rx_jumbo_skbuff[idx],
17761768 mapping, mapping);
....@@ -1981,10 +1973,8 @@
19811973
19821974 skb = rip->skb;
19831975 rip->skb = NULL;
1984
- pci_unmap_page(ap->pdev,
1985
- dma_unmap_addr(rip, mapping),
1986
- mapsize,
1987
- PCI_DMA_FROMDEVICE);
1976
+ dma_unmap_page(&ap->pdev->dev, dma_unmap_addr(rip, mapping),
1977
+ mapsize, DMA_FROM_DEVICE);
19881978 skb_put(skb, retdesc->size);
19891979
19901980 /*
....@@ -2050,16 +2040,17 @@
20502040 skb = info->skb;
20512041
20522042 if (dma_unmap_len(info, maplen)) {
2053
- pci_unmap_page(ap->pdev, dma_unmap_addr(info, mapping),
2043
+ dma_unmap_page(&ap->pdev->dev,
2044
+ dma_unmap_addr(info, mapping),
20542045 dma_unmap_len(info, maplen),
2055
- PCI_DMA_TODEVICE);
2046
+ DMA_TO_DEVICE);
20562047 dma_unmap_len_set(info, maplen, 0);
20572048 }
20582049
20592050 if (skb) {
20602051 dev->stats.tx_packets++;
20612052 dev->stats.tx_bytes += skb->len;
2062
- dev_kfree_skb_irq(skb);
2053
+ dev_consume_skb_irq(skb);
20632054 info->skb = NULL;
20642055 }
20652056
....@@ -2279,7 +2270,7 @@
22792270 /*
22802271 * Setup the bottom half rx ring refill handler
22812272 */
2282
- tasklet_init(&ap->ace_tasklet, ace_tasklet, (unsigned long)dev);
2273
+ tasklet_setup(&ap->ace_tasklet, ace_tasklet);
22832274 return 0;
22842275 }
22852276
....@@ -2341,9 +2332,10 @@
23412332 } else
23422333 memset(ap->tx_ring + i, 0,
23432334 sizeof(struct tx_desc));
2344
- pci_unmap_page(ap->pdev, dma_unmap_addr(info, mapping),
2335
+ dma_unmap_page(&ap->pdev->dev,
2336
+ dma_unmap_addr(info, mapping),
23452337 dma_unmap_len(info, maplen),
2346
- PCI_DMA_TODEVICE);
2338
+ DMA_TO_DEVICE);
23472339 dma_unmap_len_set(info, maplen, 0);
23482340 }
23492341 if (skb) {
....@@ -2373,9 +2365,9 @@
23732365 dma_addr_t mapping;
23742366 struct tx_ring_info *info;
23752367
2376
- mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
2377
- offset_in_page(skb->data),
2378
- skb->len, PCI_DMA_TODEVICE);
2368
+ mapping = dma_map_page(&ap->pdev->dev, virt_to_page(skb->data),
2369
+ offset_in_page(skb->data), skb->len,
2370
+ DMA_TO_DEVICE);
23792371
23802372 info = ap->skb->tx_skbuff + idx;
23812373 info->skb = tail;
....@@ -2703,9 +2695,8 @@
27032695 struct ace_private *ap = netdev_priv(dev);
27042696
27052697 strlcpy(info->driver, "acenic", sizeof(info->driver));
2706
- snprintf(info->version, sizeof(info->version), "%i.%i.%i",
2707
- ap->firmware_major, ap->firmware_minor,
2708
- ap->firmware_fix);
2698
+ snprintf(info->fw_version, sizeof(info->version), "%i.%i.%i",
2699
+ ap->firmware_major, ap->firmware_minor, ap->firmware_fix);
27092700
27102701 if (ap->pdev)
27112702 strlcpy(info->bus_info, pci_name(ap->pdev),