forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/net/ethernet/marvell/pxa168_eth.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * PXA168 ethernet driver.
34 * Most of the code is derived from mv643xx ethernet driver.
....@@ -7,19 +8,6 @@
78 * Zhangfei Gao <zgao6@marvell.com>
89 * Philip Rakity <prakity@marvell.com>
910 * Mark Brown <markb@marvell.com>
10
- *
11
- * This program is free software; you can redistribute it and/or
12
- * modify it under the terms of the GNU General Public License
13
- * as published by the Free Software Foundation; either version 2
14
- * of the License, or (at your option) any later version.
15
- *
16
- * This program is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU General Public License
22
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
2311 */
2412
2513 #include <linux/bitops.h>
....@@ -43,8 +31,8 @@
4331 #include <linux/types.h>
4432 #include <linux/udp.h>
4533 #include <linux/workqueue.h>
34
+#include <linux/pgtable.h>
4635
47
-#include <asm/pgtable.h>
4836 #include <asm/cacheflush.h>
4937
5038 #define DRIVER_NAME "pxa168-eth"
....@@ -201,6 +189,7 @@
201189 };
202190
203191 struct pxa168_eth_private {
192
+ struct platform_device *pdev;
204193 int port_num; /* User Ethernet port number */
205194 int phy_addr;
206195 int phy_speed;
....@@ -331,7 +320,7 @@
331320 used_rx_desc = pep->rx_used_desc_q;
332321 p_used_rx_desc = &pep->p_rx_desc_area[used_rx_desc];
333322 size = skb_end_pointer(skb) - skb->data;
334
- p_used_rx_desc->buf_ptr = dma_map_single(NULL,
323
+ p_used_rx_desc->buf_ptr = dma_map_single(&pep->pdev->dev,
335324 skb->data,
336325 size,
337326 DMA_FROM_DEVICE);
....@@ -557,9 +546,9 @@
557546 * table is full.
558547 */
559548 if (!pep->htpr) {
560
- pep->htpr = dma_zalloc_coherent(pep->dev->dev.parent,
561
- HASH_ADDR_TABLE_SIZE,
562
- &pep->htpr_dma, GFP_KERNEL);
549
+ pep->htpr = dma_alloc_coherent(pep->dev->dev.parent,
550
+ HASH_ADDR_TABLE_SIZE,
551
+ &pep->htpr_dma, GFP_KERNEL);
563552 if (!pep->htpr)
564553 return -ENOMEM;
565554 } else {
....@@ -743,7 +732,7 @@
743732 netdev_err(dev, "Error in TX\n");
744733 dev->stats.tx_errors++;
745734 }
746
- dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE);
735
+ dma_unmap_single(&pep->pdev->dev, addr, count, DMA_TO_DEVICE);
747736 if (skb)
748737 dev_kfree_skb_irq(skb);
749738 released++;
....@@ -753,7 +742,7 @@
753742 return released;
754743 }
755744
756
-static void pxa168_eth_tx_timeout(struct net_device *dev)
745
+static void pxa168_eth_tx_timeout(struct net_device *dev, unsigned int txqueue)
757746 {
758747 struct pxa168_eth_private *pep = netdev_priv(dev);
759748
....@@ -805,7 +794,7 @@
805794 if (rx_next_curr_desc == rx_used_desc)
806795 pep->rx_resource_err = 1;
807796 pep->rx_desc_count--;
808
- dma_unmap_single(NULL, rx_desc->buf_ptr,
797
+ dma_unmap_single(&pep->pdev->dev, rx_desc->buf_ptr,
809798 rx_desc->buf_size,
810799 DMA_FROM_DEVICE);
811800 received_packets++;
....@@ -988,8 +977,8 @@
988977 cmd.base.phy_address = pep->phy_addr;
989978 cmd.base.speed = pep->phy_speed;
990979 cmd.base.duplex = pep->phy_duplex;
991
- ethtool_convert_legacy_u32_to_link_mode(cmd.link_modes.advertising,
992
- PHY_BASIC_FEATURES);
980
+ bitmap_copy(cmd.link_modes.advertising, PHY_BASIC_FEATURES,
981
+ __ETHTOOL_LINK_MODE_MASK_NBITS);
993982 cmd.base.autoneg = AUTONEG_ENABLE;
994983
995984 if (cmd.base.speed != 0)
....@@ -1044,9 +1033,9 @@
10441033 pep->rx_desc_count = 0;
10451034 size = pep->rx_ring_size * sizeof(struct rx_desc);
10461035 pep->rx_desc_area_size = size;
1047
- pep->p_rx_desc_area = dma_zalloc_coherent(pep->dev->dev.parent, size,
1048
- &pep->rx_desc_dma,
1049
- GFP_KERNEL);
1036
+ pep->p_rx_desc_area = dma_alloc_coherent(pep->dev->dev.parent, size,
1037
+ &pep->rx_desc_dma,
1038
+ GFP_KERNEL);
10501039 if (!pep->p_rx_desc_area)
10511040 goto out;
10521041
....@@ -1103,9 +1092,9 @@
11031092 pep->tx_desc_count = 0;
11041093 size = pep->tx_ring_size * sizeof(struct tx_desc);
11051094 pep->tx_desc_area_size = size;
1106
- pep->p_tx_desc_area = dma_zalloc_coherent(pep->dev->dev.parent, size,
1107
- &pep->tx_desc_dma,
1108
- GFP_KERNEL);
1095
+ pep->p_tx_desc_area = dma_alloc_coherent(pep->dev->dev.parent, size,
1096
+ &pep->tx_desc_dma,
1097
+ GFP_KERNEL);
11091098 if (!pep->p_tx_desc_area)
11101099 goto out;
11111100 /* Initialize the next_desc_ptr links in the Tx descriptors ring */
....@@ -1198,11 +1187,10 @@
11981187
11991188 static int pxa168_eth_change_mtu(struct net_device *dev, int mtu)
12001189 {
1201
- int retval;
12021190 struct pxa168_eth_private *pep = netdev_priv(dev);
12031191
12041192 dev->mtu = mtu;
1205
- retval = set_port_config_ext(pep);
1193
+ set_port_config_ext(pep);
12061194
12071195 if (!netif_running(dev))
12081196 return 0;
....@@ -1274,7 +1262,8 @@
12741262 length = skb->len;
12751263 pep->tx_skb[tx_index] = skb;
12761264 desc->byte_cnt = length;
1277
- desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
1265
+ desc->buf_ptr = dma_map_single(&pep->pdev->dev, skb->data, length,
1266
+ DMA_TO_DEVICE);
12781267
12791268 skb_tx_timestamp(skb);
12801269
....@@ -1354,15 +1343,6 @@
13541343 return 0;
13551344 }
13561345
1357
-static int pxa168_eth_do_ioctl(struct net_device *dev, struct ifreq *ifr,
1358
- int cmd)
1359
-{
1360
- if (dev->phydev)
1361
- return phy_mii_ioctl(dev->phydev, ifr, cmd);
1362
-
1363
- return -EOPNOTSUPP;
1364
-}
1365
-
13661346 #ifdef CONFIG_NET_POLL_CONTROLLER
13671347 static void pxa168_eth_netpoll(struct net_device *dev)
13681348 {
....@@ -1397,7 +1377,7 @@
13971377 .ndo_set_rx_mode = pxa168_eth_set_rx_mode,
13981378 .ndo_set_mac_address = pxa168_eth_set_mac_address,
13991379 .ndo_validate_addr = eth_validate_addr,
1400
- .ndo_do_ioctl = pxa168_eth_do_ioctl,
1380
+ .ndo_do_ioctl = phy_do_ioctl,
14011381 .ndo_change_mtu = pxa168_eth_change_mtu,
14021382 .ndo_tx_timeout = pxa168_eth_tx_timeout,
14031383 #ifdef CONFIG_NET_POLL_CONTROLLER
....@@ -1435,10 +1415,9 @@
14351415 pep->dev = dev;
14361416 pep->clk = clk;
14371417
1438
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1439
- pep->base = devm_ioremap_resource(&pdev->dev, res);
1418
+ pep->base = devm_platform_ioremap_resource(pdev, 0);
14401419 if (IS_ERR(pep->base)) {
1441
- err = -ENOMEM;
1420
+ err = PTR_ERR(pep->base);
14421421 goto err_netdev;
14431422 }
14441423
....@@ -1459,7 +1438,7 @@
14591438 if (pdev->dev.of_node)
14601439 mac_addr = of_get_mac_address(pdev->dev.of_node);
14611440
1462
- if (mac_addr && is_valid_ether_addr(mac_addr)) {
1441
+ if (!IS_ERR_OR_NULL(mac_addr)) {
14631442 ether_addr_copy(dev->dev_addr, mac_addr);
14641443 } else {
14651444 /* try reading the mac address, if set by the bootloader */
....@@ -1500,8 +1479,10 @@
15001479 goto err_netdev;
15011480 }
15021481 of_property_read_u32(np, "reg", &pep->phy_addr);
1503
- pep->phy_intf = of_get_phy_mode(pdev->dev.of_node);
15041482 of_node_put(np);
1483
+ err = of_get_phy_mode(pdev->dev.of_node, &pep->phy_intf);
1484
+ if (err && err != -ENODEV)
1485
+ goto err_netdev;
15051486 }
15061487
15071488 /* Hardware supports only 3 ports */
....@@ -1528,6 +1509,7 @@
15281509 if (err)
15291510 goto err_free_mdio;
15301511
1512
+ pep->pdev = pdev;
15311513 SET_NETDEV_DEV(dev, &pdev->dev);
15321514 pxa168_init_hw(pep);
15331515 err = register_netdev(dev);
....@@ -1558,10 +1540,8 @@
15581540 }
15591541 if (dev->phydev)
15601542 phy_disconnect(dev->phydev);
1561
- if (pep->clk) {
1562
- clk_disable_unprepare(pep->clk);
1563
- }
15641543
1544
+ clk_disable_unprepare(pep->clk);
15651545 mdiobus_unregister(pep->smi_bus);
15661546 mdiobus_free(pep->smi_bus);
15671547 cancel_work_sync(&pep->tx_timeout_task);