| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Alchemy Au1x00 ethernet driver |
|---|
| .. | .. |
|---|
| 14 | 15 | * |
|---|
| 15 | 16 | * Author: MontaVista Software, Inc. |
|---|
| 16 | 17 | * ppopov@mvista.com or source@mvista.com |
|---|
| 17 | | - * |
|---|
| 18 | | - * ######################################################################## |
|---|
| 19 | | - * |
|---|
| 20 | | - * This program is free software; you can distribute it and/or modify it |
|---|
| 21 | | - * under the terms of the GNU General Public License (Version 2) as |
|---|
| 22 | | - * published by the Free Software Foundation. |
|---|
| 23 | | - * |
|---|
| 24 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 25 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 26 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|---|
| 27 | | - * for more details. |
|---|
| 28 | | - * |
|---|
| 29 | | - * You should have received a copy of the GNU General Public License along |
|---|
| 30 | | - * with this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 31 | | - * |
|---|
| 32 | | - * ######################################################################## |
|---|
| 33 | | - * |
|---|
| 34 | | - * |
|---|
| 35 | 18 | */ |
|---|
| 36 | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 37 | 20 | |
|---|
| .. | .. |
|---|
| 80 | 63 | NETIF_MSG_LINK) |
|---|
| 81 | 64 | |
|---|
| 82 | 65 | #define DRV_NAME "au1000_eth" |
|---|
| 83 | | -#define DRV_VERSION "1.7" |
|---|
| 84 | 66 | #define DRV_AUTHOR "Pete Popov <ppopov@embeddedalley.com>" |
|---|
| 85 | 67 | #define DRV_DESC "Au1xxx on-chip Ethernet driver" |
|---|
| 86 | 68 | |
|---|
| 87 | 69 | MODULE_AUTHOR(DRV_AUTHOR); |
|---|
| 88 | 70 | MODULE_DESCRIPTION(DRV_DESC); |
|---|
| 89 | 71 | MODULE_LICENSE("GPL"); |
|---|
| 90 | | -MODULE_VERSION(DRV_VERSION); |
|---|
| 91 | 72 | |
|---|
| 92 | 73 | /* AU1000 MAC registers and bits */ |
|---|
| 93 | 74 | #define MAC_CONTROL 0x0 |
|---|
| .. | .. |
|---|
| 260 | 241 | * ps: make sure the used irqs are configured properly in the board |
|---|
| 261 | 242 | * specific irq-map |
|---|
| 262 | 243 | */ |
|---|
| 263 | | - |
|---|
| 264 | 244 | static void au1000_enable_mac(struct net_device *dev, int force_reset) |
|---|
| 265 | 245 | { |
|---|
| 266 | 246 | unsigned long flags; |
|---|
| .. | .. |
|---|
| 564 | 544 | return PTR_ERR(phydev); |
|---|
| 565 | 545 | } |
|---|
| 566 | 546 | |
|---|
| 567 | | - /* mask with MAC supported features */ |
|---|
| 568 | | - phydev->supported &= (SUPPORTED_10baseT_Half |
|---|
| 569 | | - | SUPPORTED_10baseT_Full |
|---|
| 570 | | - | SUPPORTED_100baseT_Half |
|---|
| 571 | | - | SUPPORTED_100baseT_Full |
|---|
| 572 | | - | SUPPORTED_Autoneg |
|---|
| 573 | | - /* | SUPPORTED_Pause | SUPPORTED_Asym_Pause */ |
|---|
| 574 | | - | SUPPORTED_MII |
|---|
| 575 | | - | SUPPORTED_TP); |
|---|
| 576 | | - |
|---|
| 577 | | - phydev->advertising = phydev->supported; |
|---|
| 547 | + phy_set_max_speed(phydev, SPEED_100); |
|---|
| 578 | 548 | |
|---|
| 579 | 549 | aup->old_link = 0; |
|---|
| 580 | 550 | aup->old_speed = 0; |
|---|
| .. | .. |
|---|
| 584 | 554 | |
|---|
| 585 | 555 | return 0; |
|---|
| 586 | 556 | } |
|---|
| 587 | | - |
|---|
| 588 | 557 | |
|---|
| 589 | 558 | /* |
|---|
| 590 | 559 | * Buffer allocation/deallocation routines. The buffer descriptor returned |
|---|
| .. | .. |
|---|
| 676 | 645 | /* |
|---|
| 677 | 646 | * ethtool operations |
|---|
| 678 | 647 | */ |
|---|
| 679 | | - |
|---|
| 680 | 648 | static void |
|---|
| 681 | 649 | au1000_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
|---|
| 682 | 650 | { |
|---|
| 683 | 651 | struct au1000_private *aup = netdev_priv(dev); |
|---|
| 684 | 652 | |
|---|
| 685 | 653 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
|---|
| 686 | | - strlcpy(info->version, DRV_VERSION, sizeof(info->version)); |
|---|
| 687 | 654 | snprintf(info->bus_info, sizeof(info->bus_info), "%s %d", DRV_NAME, |
|---|
| 688 | 655 | aup->mac_id); |
|---|
| 689 | 656 | } |
|---|
| .. | .. |
|---|
| 708 | 675 | .get_link_ksettings = phy_ethtool_get_link_ksettings, |
|---|
| 709 | 676 | .set_link_ksettings = phy_ethtool_set_link_ksettings, |
|---|
| 710 | 677 | }; |
|---|
| 711 | | - |
|---|
| 712 | 678 | |
|---|
| 713 | 679 | /* |
|---|
| 714 | 680 | * Initialize the interface. |
|---|
| .. | .. |
|---|
| 950 | 916 | return retval; |
|---|
| 951 | 917 | } |
|---|
| 952 | 918 | |
|---|
| 953 | | - if (dev->phydev) { |
|---|
| 954 | | - /* cause the PHY state machine to schedule a link state check */ |
|---|
| 955 | | - dev->phydev->state = PHY_CHANGELINK; |
|---|
| 919 | + if (dev->phydev) |
|---|
| 956 | 920 | phy_start(dev->phydev); |
|---|
| 957 | | - } |
|---|
| 958 | 921 | |
|---|
| 959 | 922 | netif_start_queue(dev); |
|---|
| 960 | 923 | |
|---|
| .. | .. |
|---|
| 1044 | 1007 | * The Tx ring has been full longer than the watchdog timeout |
|---|
| 1045 | 1008 | * value. The transmitter must be hung? |
|---|
| 1046 | 1009 | */ |
|---|
| 1047 | | -static void au1000_tx_timeout(struct net_device *dev) |
|---|
| 1010 | +static void au1000_tx_timeout(struct net_device *dev, unsigned int txqueue) |
|---|
| 1048 | 1011 | { |
|---|
| 1049 | 1012 | netdev_err(dev, "au1000_tx_timeout: dev=%p\n", dev); |
|---|
| 1050 | 1013 | au1000_reset_mac(dev); |
|---|
| .. | .. |
|---|
| 1083 | 1046 | writel(reg, &aup->mac->control); |
|---|
| 1084 | 1047 | } |
|---|
| 1085 | 1048 | |
|---|
| 1086 | | -static int au1000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
|---|
| 1087 | | -{ |
|---|
| 1088 | | - if (!netif_running(dev)) |
|---|
| 1089 | | - return -EINVAL; |
|---|
| 1090 | | - |
|---|
| 1091 | | - if (!dev->phydev) |
|---|
| 1092 | | - return -EINVAL; /* PHY not controllable */ |
|---|
| 1093 | | - |
|---|
| 1094 | | - return phy_mii_ioctl(dev->phydev, rq, cmd); |
|---|
| 1095 | | -} |
|---|
| 1096 | | - |
|---|
| 1097 | 1049 | static const struct net_device_ops au1000_netdev_ops = { |
|---|
| 1098 | 1050 | .ndo_open = au1000_open, |
|---|
| 1099 | 1051 | .ndo_stop = au1000_close, |
|---|
| 1100 | 1052 | .ndo_start_xmit = au1000_tx, |
|---|
| 1101 | 1053 | .ndo_set_rx_mode = au1000_multicast_list, |
|---|
| 1102 | | - .ndo_do_ioctl = au1000_ioctl, |
|---|
| 1054 | + .ndo_do_ioctl = phy_do_ioctl_running, |
|---|
| 1103 | 1055 | .ndo_tx_timeout = au1000_tx_timeout, |
|---|
| 1104 | 1056 | .ndo_set_mac_address = eth_mac_addr, |
|---|
| 1105 | 1057 | .ndo_validate_addr = eth_validate_addr, |
|---|
| .. | .. |
|---|
| 1130 | 1082 | |
|---|
| 1131 | 1083 | irq = platform_get_irq(pdev, 0); |
|---|
| 1132 | 1084 | if (irq < 0) { |
|---|
| 1133 | | - dev_err(&pdev->dev, "failed to retrieve IRQ\n"); |
|---|
| 1134 | 1085 | err = -ENODEV; |
|---|
| 1135 | 1086 | goto out; |
|---|
| 1136 | 1087 | } |
|---|
| .. | .. |
|---|
| 1180 | 1131 | /* Allocate the data buffers |
|---|
| 1181 | 1132 | * Snooping works fine with eth on all au1xxx |
|---|
| 1182 | 1133 | */ |
|---|
| 1183 | | - aup->vaddr = (u32)dma_alloc_attrs(NULL, MAX_BUF_SIZE * |
|---|
| 1134 | + aup->vaddr = (u32)dma_alloc_coherent(&pdev->dev, MAX_BUF_SIZE * |
|---|
| 1184 | 1135 | (NUM_TX_BUFFS + NUM_RX_BUFFS), |
|---|
| 1185 | | - &aup->dma_addr, 0, |
|---|
| 1186 | | - DMA_ATTR_NON_CONSISTENT); |
|---|
| 1136 | + &aup->dma_addr, 0); |
|---|
| 1187 | 1137 | if (!aup->vaddr) { |
|---|
| 1188 | 1138 | dev_err(&pdev->dev, "failed to allocate data buffers\n"); |
|---|
| 1189 | 1139 | err = -ENOMEM; |
|---|
| .. | .. |
|---|
| 1192 | 1142 | |
|---|
| 1193 | 1143 | /* aup->mac is the base address of the MAC's registers */ |
|---|
| 1194 | 1144 | aup->mac = (struct mac_reg *) |
|---|
| 1195 | | - ioremap_nocache(base->start, resource_size(base)); |
|---|
| 1145 | + ioremap(base->start, resource_size(base)); |
|---|
| 1196 | 1146 | if (!aup->mac) { |
|---|
| 1197 | 1147 | dev_err(&pdev->dev, "failed to ioremap MAC registers\n"); |
|---|
| 1198 | 1148 | err = -ENXIO; |
|---|
| .. | .. |
|---|
| 1200 | 1150 | } |
|---|
| 1201 | 1151 | |
|---|
| 1202 | 1152 | /* Setup some variables for quick register address access */ |
|---|
| 1203 | | - aup->enable = (u32 *)ioremap_nocache(macen->start, |
|---|
| 1153 | + aup->enable = (u32 *)ioremap(macen->start, |
|---|
| 1204 | 1154 | resource_size(macen)); |
|---|
| 1205 | 1155 | if (!aup->enable) { |
|---|
| 1206 | 1156 | dev_err(&pdev->dev, "failed to ioremap MAC enable register\n"); |
|---|
| .. | .. |
|---|
| 1209 | 1159 | } |
|---|
| 1210 | 1160 | aup->mac_id = pdev->id; |
|---|
| 1211 | 1161 | |
|---|
| 1212 | | - aup->macdma = ioremap_nocache(macdma->start, resource_size(macdma)); |
|---|
| 1162 | + aup->macdma = ioremap(macdma->start, resource_size(macdma)); |
|---|
| 1213 | 1163 | if (!aup->macdma) { |
|---|
| 1214 | 1164 | dev_err(&pdev->dev, "failed to ioremap MACDMA registers\n"); |
|---|
| 1215 | 1165 | err = -ENXIO; |
|---|
| .. | .. |
|---|
| 1300 | 1250 | aup->rx_db_inuse[i] = pDB; |
|---|
| 1301 | 1251 | } |
|---|
| 1302 | 1252 | |
|---|
| 1303 | | - err = -ENODEV; |
|---|
| 1304 | 1253 | for (i = 0; i < NUM_TX_DMA; i++) { |
|---|
| 1305 | 1254 | pDB = au1000_GetFreeDB(aup); |
|---|
| 1306 | 1255 | if (!pDB) |
|---|
| .. | .. |
|---|
| 1332 | 1281 | netdev_info(dev, "Au1xx0 Ethernet found at 0x%lx, irq %d\n", |
|---|
| 1333 | 1282 | (unsigned long)base->start, irq); |
|---|
| 1334 | 1283 | |
|---|
| 1335 | | - pr_info_once("%s version %s %s\n", DRV_NAME, DRV_VERSION, DRV_AUTHOR); |
|---|
| 1336 | | - |
|---|
| 1337 | 1284 | return 0; |
|---|
| 1338 | 1285 | |
|---|
| 1339 | 1286 | err_out: |
|---|
| .. | .. |
|---|
| 1362 | 1309 | err_remap2: |
|---|
| 1363 | 1310 | iounmap(aup->mac); |
|---|
| 1364 | 1311 | err_remap1: |
|---|
| 1365 | | - dma_free_attrs(NULL, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), |
|---|
| 1366 | | - (void *)aup->vaddr, aup->dma_addr, |
|---|
| 1367 | | - DMA_ATTR_NON_CONSISTENT); |
|---|
| 1312 | + dma_free_coherent(&pdev->dev, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), |
|---|
| 1313 | + (void *)aup->vaddr, aup->dma_addr); |
|---|
| 1368 | 1314 | err_vaddr: |
|---|
| 1369 | 1315 | free_netdev(dev); |
|---|
| 1370 | 1316 | err_alloc: |
|---|
| .. | .. |
|---|
| 1396 | 1342 | if (aup->tx_db_inuse[i]) |
|---|
| 1397 | 1343 | au1000_ReleaseDB(aup, aup->tx_db_inuse[i]); |
|---|
| 1398 | 1344 | |
|---|
| 1399 | | - dma_free_attrs(NULL, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), |
|---|
| 1400 | | - (void *)aup->vaddr, aup->dma_addr, |
|---|
| 1401 | | - DMA_ATTR_NON_CONSISTENT); |
|---|
| 1345 | + dma_free_coherent(&pdev->dev, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), |
|---|
| 1346 | + (void *)aup->vaddr, aup->dma_addr); |
|---|
| 1402 | 1347 | |
|---|
| 1403 | 1348 | iounmap(aup->macdma); |
|---|
| 1404 | 1349 | iounmap(aup->mac); |
|---|