.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * PXA168 ethernet driver. |
---|
3 | 4 | * Most of the code is derived from mv643xx ethernet driver. |
---|
.. | .. |
---|
7 | 8 | * Zhangfei Gao <zgao6@marvell.com> |
---|
8 | 9 | * Philip Rakity <prakity@marvell.com> |
---|
9 | 10 | * 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/>. |
---|
23 | 11 | */ |
---|
24 | 12 | |
---|
25 | 13 | #include <linux/bitops.h> |
---|
.. | .. |
---|
43 | 31 | #include <linux/types.h> |
---|
44 | 32 | #include <linux/udp.h> |
---|
45 | 33 | #include <linux/workqueue.h> |
---|
| 34 | +#include <linux/pgtable.h> |
---|
46 | 35 | |
---|
47 | | -#include <asm/pgtable.h> |
---|
48 | 36 | #include <asm/cacheflush.h> |
---|
49 | 37 | |
---|
50 | 38 | #define DRIVER_NAME "pxa168-eth" |
---|
.. | .. |
---|
201 | 189 | }; |
---|
202 | 190 | |
---|
203 | 191 | struct pxa168_eth_private { |
---|
| 192 | + struct platform_device *pdev; |
---|
204 | 193 | int port_num; /* User Ethernet port number */ |
---|
205 | 194 | int phy_addr; |
---|
206 | 195 | int phy_speed; |
---|
.. | .. |
---|
331 | 320 | used_rx_desc = pep->rx_used_desc_q; |
---|
332 | 321 | p_used_rx_desc = &pep->p_rx_desc_area[used_rx_desc]; |
---|
333 | 322 | 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, |
---|
335 | 324 | skb->data, |
---|
336 | 325 | size, |
---|
337 | 326 | DMA_FROM_DEVICE); |
---|
.. | .. |
---|
557 | 546 | * table is full. |
---|
558 | 547 | */ |
---|
559 | 548 | 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); |
---|
563 | 552 | if (!pep->htpr) |
---|
564 | 553 | return -ENOMEM; |
---|
565 | 554 | } else { |
---|
.. | .. |
---|
743 | 732 | netdev_err(dev, "Error in TX\n"); |
---|
744 | 733 | dev->stats.tx_errors++; |
---|
745 | 734 | } |
---|
746 | | - dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE); |
---|
| 735 | + dma_unmap_single(&pep->pdev->dev, addr, count, DMA_TO_DEVICE); |
---|
747 | 736 | if (skb) |
---|
748 | 737 | dev_kfree_skb_irq(skb); |
---|
749 | 738 | released++; |
---|
.. | .. |
---|
753 | 742 | return released; |
---|
754 | 743 | } |
---|
755 | 744 | |
---|
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) |
---|
757 | 746 | { |
---|
758 | 747 | struct pxa168_eth_private *pep = netdev_priv(dev); |
---|
759 | 748 | |
---|
.. | .. |
---|
805 | 794 | if (rx_next_curr_desc == rx_used_desc) |
---|
806 | 795 | pep->rx_resource_err = 1; |
---|
807 | 796 | pep->rx_desc_count--; |
---|
808 | | - dma_unmap_single(NULL, rx_desc->buf_ptr, |
---|
| 797 | + dma_unmap_single(&pep->pdev->dev, rx_desc->buf_ptr, |
---|
809 | 798 | rx_desc->buf_size, |
---|
810 | 799 | DMA_FROM_DEVICE); |
---|
811 | 800 | received_packets++; |
---|
.. | .. |
---|
988 | 977 | cmd.base.phy_address = pep->phy_addr; |
---|
989 | 978 | cmd.base.speed = pep->phy_speed; |
---|
990 | 979 | 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); |
---|
993 | 982 | cmd.base.autoneg = AUTONEG_ENABLE; |
---|
994 | 983 | |
---|
995 | 984 | if (cmd.base.speed != 0) |
---|
.. | .. |
---|
1044 | 1033 | pep->rx_desc_count = 0; |
---|
1045 | 1034 | size = pep->rx_ring_size * sizeof(struct rx_desc); |
---|
1046 | 1035 | 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); |
---|
1050 | 1039 | if (!pep->p_rx_desc_area) |
---|
1051 | 1040 | goto out; |
---|
1052 | 1041 | |
---|
.. | .. |
---|
1103 | 1092 | pep->tx_desc_count = 0; |
---|
1104 | 1093 | size = pep->tx_ring_size * sizeof(struct tx_desc); |
---|
1105 | 1094 | 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); |
---|
1109 | 1098 | if (!pep->p_tx_desc_area) |
---|
1110 | 1099 | goto out; |
---|
1111 | 1100 | /* Initialize the next_desc_ptr links in the Tx descriptors ring */ |
---|
.. | .. |
---|
1198 | 1187 | |
---|
1199 | 1188 | static int pxa168_eth_change_mtu(struct net_device *dev, int mtu) |
---|
1200 | 1189 | { |
---|
1201 | | - int retval; |
---|
1202 | 1190 | struct pxa168_eth_private *pep = netdev_priv(dev); |
---|
1203 | 1191 | |
---|
1204 | 1192 | dev->mtu = mtu; |
---|
1205 | | - retval = set_port_config_ext(pep); |
---|
| 1193 | + set_port_config_ext(pep); |
---|
1206 | 1194 | |
---|
1207 | 1195 | if (!netif_running(dev)) |
---|
1208 | 1196 | return 0; |
---|
.. | .. |
---|
1274 | 1262 | length = skb->len; |
---|
1275 | 1263 | pep->tx_skb[tx_index] = skb; |
---|
1276 | 1264 | 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); |
---|
1278 | 1267 | |
---|
1279 | 1268 | skb_tx_timestamp(skb); |
---|
1280 | 1269 | |
---|
.. | .. |
---|
1354 | 1343 | return 0; |
---|
1355 | 1344 | } |
---|
1356 | 1345 | |
---|
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 | | - |
---|
1366 | 1346 | #ifdef CONFIG_NET_POLL_CONTROLLER |
---|
1367 | 1347 | static void pxa168_eth_netpoll(struct net_device *dev) |
---|
1368 | 1348 | { |
---|
.. | .. |
---|
1397 | 1377 | .ndo_set_rx_mode = pxa168_eth_set_rx_mode, |
---|
1398 | 1378 | .ndo_set_mac_address = pxa168_eth_set_mac_address, |
---|
1399 | 1379 | .ndo_validate_addr = eth_validate_addr, |
---|
1400 | | - .ndo_do_ioctl = pxa168_eth_do_ioctl, |
---|
| 1380 | + .ndo_do_ioctl = phy_do_ioctl, |
---|
1401 | 1381 | .ndo_change_mtu = pxa168_eth_change_mtu, |
---|
1402 | 1382 | .ndo_tx_timeout = pxa168_eth_tx_timeout, |
---|
1403 | 1383 | #ifdef CONFIG_NET_POLL_CONTROLLER |
---|
.. | .. |
---|
1435 | 1415 | pep->dev = dev; |
---|
1436 | 1416 | pep->clk = clk; |
---|
1437 | 1417 | |
---|
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); |
---|
1440 | 1419 | if (IS_ERR(pep->base)) { |
---|
1441 | | - err = -ENOMEM; |
---|
| 1420 | + err = PTR_ERR(pep->base); |
---|
1442 | 1421 | goto err_netdev; |
---|
1443 | 1422 | } |
---|
1444 | 1423 | |
---|
.. | .. |
---|
1459 | 1438 | if (pdev->dev.of_node) |
---|
1460 | 1439 | mac_addr = of_get_mac_address(pdev->dev.of_node); |
---|
1461 | 1440 | |
---|
1462 | | - if (mac_addr && is_valid_ether_addr(mac_addr)) { |
---|
| 1441 | + if (!IS_ERR_OR_NULL(mac_addr)) { |
---|
1463 | 1442 | ether_addr_copy(dev->dev_addr, mac_addr); |
---|
1464 | 1443 | } else { |
---|
1465 | 1444 | /* try reading the mac address, if set by the bootloader */ |
---|
.. | .. |
---|
1500 | 1479 | goto err_netdev; |
---|
1501 | 1480 | } |
---|
1502 | 1481 | of_property_read_u32(np, "reg", &pep->phy_addr); |
---|
1503 | | - pep->phy_intf = of_get_phy_mode(pdev->dev.of_node); |
---|
1504 | 1482 | 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; |
---|
1505 | 1486 | } |
---|
1506 | 1487 | |
---|
1507 | 1488 | /* Hardware supports only 3 ports */ |
---|
.. | .. |
---|
1528 | 1509 | if (err) |
---|
1529 | 1510 | goto err_free_mdio; |
---|
1530 | 1511 | |
---|
| 1512 | + pep->pdev = pdev; |
---|
1531 | 1513 | SET_NETDEV_DEV(dev, &pdev->dev); |
---|
1532 | 1514 | pxa168_init_hw(pep); |
---|
1533 | 1515 | err = register_netdev(dev); |
---|
.. | .. |
---|
1558 | 1540 | } |
---|
1559 | 1541 | if (dev->phydev) |
---|
1560 | 1542 | phy_disconnect(dev->phydev); |
---|
1561 | | - if (pep->clk) { |
---|
1562 | | - clk_disable_unprepare(pep->clk); |
---|
1563 | | - } |
---|
1564 | 1543 | |
---|
| 1544 | + clk_disable_unprepare(pep->clk); |
---|
1565 | 1545 | mdiobus_unregister(pep->smi_bus); |
---|
1566 | 1546 | mdiobus_free(pep->smi_bus); |
---|
1567 | 1547 | cancel_work_sync(&pep->tx_timeout_task); |
---|