.. | .. |
---|
8 | 8 | #include <linux/crc32.h> |
---|
9 | 9 | #include <linux/microchipphy.h> |
---|
10 | 10 | #include <linux/net_tstamp.h> |
---|
| 11 | +#include <linux/of_mdio.h> |
---|
| 12 | +#include <linux/of_net.h> |
---|
11 | 13 | #include <linux/phy.h> |
---|
| 14 | +#include <linux/phy_fixed.h> |
---|
12 | 15 | #include <linux/rtnetlink.h> |
---|
13 | 16 | #include <linux/iopoll.h> |
---|
14 | 17 | #include <linux/crc16.h> |
---|
.. | .. |
---|
793 | 796 | |
---|
794 | 797 | netdev = adapter->netdev; |
---|
795 | 798 | |
---|
796 | | - /* setup auto duplex, and speed detection */ |
---|
| 799 | + /* disable auto duplex, and speed detection. Phylib does that */ |
---|
797 | 800 | data = lan743x_csr_read(adapter, MAC_CR); |
---|
798 | | - data |= MAC_CR_ADD_ | MAC_CR_ASD_; |
---|
| 801 | + data &= ~(MAC_CR_ADD_ | MAC_CR_ASD_); |
---|
799 | 802 | data |= MAC_CR_CNTR_RST_; |
---|
800 | 803 | lan743x_csr_write(adapter, MAC_CR, data); |
---|
801 | 804 | |
---|
802 | | - mac_addr_hi = lan743x_csr_read(adapter, MAC_RX_ADDRH); |
---|
803 | | - mac_addr_lo = lan743x_csr_read(adapter, MAC_RX_ADDRL); |
---|
804 | | - adapter->mac_address[0] = mac_addr_lo & 0xFF; |
---|
805 | | - adapter->mac_address[1] = (mac_addr_lo >> 8) & 0xFF; |
---|
806 | | - adapter->mac_address[2] = (mac_addr_lo >> 16) & 0xFF; |
---|
807 | | - adapter->mac_address[3] = (mac_addr_lo >> 24) & 0xFF; |
---|
808 | | - adapter->mac_address[4] = mac_addr_hi & 0xFF; |
---|
809 | | - adapter->mac_address[5] = (mac_addr_hi >> 8) & 0xFF; |
---|
| 805 | + if (!is_valid_ether_addr(adapter->mac_address)) { |
---|
| 806 | + mac_addr_hi = lan743x_csr_read(adapter, MAC_RX_ADDRH); |
---|
| 807 | + mac_addr_lo = lan743x_csr_read(adapter, MAC_RX_ADDRL); |
---|
| 808 | + adapter->mac_address[0] = mac_addr_lo & 0xFF; |
---|
| 809 | + adapter->mac_address[1] = (mac_addr_lo >> 8) & 0xFF; |
---|
| 810 | + adapter->mac_address[2] = (mac_addr_lo >> 16) & 0xFF; |
---|
| 811 | + adapter->mac_address[3] = (mac_addr_lo >> 24) & 0xFF; |
---|
| 812 | + adapter->mac_address[4] = mac_addr_hi & 0xFF; |
---|
| 813 | + adapter->mac_address[5] = (mac_addr_hi >> 8) & 0xFF; |
---|
810 | 814 | |
---|
811 | | - if (((mac_addr_hi & 0x0000FFFF) == 0x0000FFFF) && |
---|
812 | | - mac_addr_lo == 0xFFFFFFFF) { |
---|
813 | | - mac_address_valid = false; |
---|
814 | | - } else if (!is_valid_ether_addr(adapter->mac_address)) { |
---|
815 | | - mac_address_valid = false; |
---|
| 815 | + if (((mac_addr_hi & 0x0000FFFF) == 0x0000FFFF) && |
---|
| 816 | + mac_addr_lo == 0xFFFFFFFF) { |
---|
| 817 | + mac_address_valid = false; |
---|
| 818 | + } else if (!is_valid_ether_addr(adapter->mac_address)) { |
---|
| 819 | + mac_address_valid = false; |
---|
| 820 | + } |
---|
| 821 | + |
---|
| 822 | + if (!mac_address_valid) |
---|
| 823 | + eth_random_addr(adapter->mac_address); |
---|
816 | 824 | } |
---|
817 | | - |
---|
818 | | - if (!mac_address_valid) |
---|
819 | | - eth_random_addr(adapter->mac_address); |
---|
820 | 825 | lan743x_mac_set_address(adapter, adapter->mac_address); |
---|
821 | 826 | ether_addr_copy(netdev->dev_addr, adapter->mac_address); |
---|
| 827 | + |
---|
822 | 828 | return 0; |
---|
823 | 829 | } |
---|
824 | 830 | |
---|
.. | .. |
---|
916 | 922 | } |
---|
917 | 923 | |
---|
918 | 924 | static void lan743x_phy_update_flowcontrol(struct lan743x_adapter *adapter, |
---|
919 | | - u8 duplex, u16 local_adv, |
---|
920 | | - u16 remote_adv) |
---|
| 925 | + u16 local_adv, u16 remote_adv) |
---|
921 | 926 | { |
---|
922 | 927 | struct lan743x_phy *phy = &adapter->phy; |
---|
923 | 928 | u8 cap; |
---|
.. | .. |
---|
941 | 946 | { |
---|
942 | 947 | struct lan743x_adapter *adapter = netdev_priv(netdev); |
---|
943 | 948 | struct phy_device *phydev = netdev->phydev; |
---|
| 949 | + u32 data; |
---|
944 | 950 | |
---|
945 | 951 | phy_print_status(phydev); |
---|
946 | 952 | if (phydev->state == PHY_RUNNING) { |
---|
947 | | - struct ethtool_link_ksettings ksettings; |
---|
948 | 953 | int remote_advertisement = 0; |
---|
949 | 954 | int local_advertisement = 0; |
---|
950 | 955 | |
---|
951 | | - memset(&ksettings, 0, sizeof(ksettings)); |
---|
952 | | - phy_ethtool_get_link_ksettings(netdev, &ksettings); |
---|
953 | | - local_advertisement = |
---|
954 | | - ethtool_adv_to_mii_adv_t(phydev->advertising); |
---|
955 | | - remote_advertisement = |
---|
956 | | - ethtool_adv_to_mii_adv_t(phydev->lp_advertising); |
---|
| 956 | + data = lan743x_csr_read(adapter, MAC_CR); |
---|
957 | 957 | |
---|
958 | | - lan743x_phy_update_flowcontrol(adapter, |
---|
959 | | - ksettings.base.duplex, |
---|
960 | | - local_advertisement, |
---|
| 958 | + /* set interface mode */ |
---|
| 959 | + if (phy_interface_mode_is_rgmii(adapter->phy_mode)) |
---|
| 960 | + /* RGMII */ |
---|
| 961 | + data &= ~MAC_CR_MII_EN_; |
---|
| 962 | + else |
---|
| 963 | + /* GMII */ |
---|
| 964 | + data |= MAC_CR_MII_EN_; |
---|
| 965 | + |
---|
| 966 | + /* set duplex mode */ |
---|
| 967 | + if (phydev->duplex) |
---|
| 968 | + data |= MAC_CR_DPX_; |
---|
| 969 | + else |
---|
| 970 | + data &= ~MAC_CR_DPX_; |
---|
| 971 | + |
---|
| 972 | + /* set bus speed */ |
---|
| 973 | + switch (phydev->speed) { |
---|
| 974 | + case SPEED_10: |
---|
| 975 | + data &= ~MAC_CR_CFG_H_; |
---|
| 976 | + data &= ~MAC_CR_CFG_L_; |
---|
| 977 | + break; |
---|
| 978 | + case SPEED_100: |
---|
| 979 | + data &= ~MAC_CR_CFG_H_; |
---|
| 980 | + data |= MAC_CR_CFG_L_; |
---|
| 981 | + break; |
---|
| 982 | + case SPEED_1000: |
---|
| 983 | + data |= MAC_CR_CFG_H_; |
---|
| 984 | + data &= ~MAC_CR_CFG_L_; |
---|
| 985 | + break; |
---|
| 986 | + } |
---|
| 987 | + lan743x_csr_write(adapter, MAC_CR, data); |
---|
| 988 | + |
---|
| 989 | + local_advertisement = |
---|
| 990 | + linkmode_adv_to_mii_adv_t(phydev->advertising); |
---|
| 991 | + remote_advertisement = |
---|
| 992 | + linkmode_adv_to_mii_adv_t(phydev->lp_advertising); |
---|
| 993 | + |
---|
| 994 | + lan743x_phy_update_flowcontrol(adapter, local_advertisement, |
---|
961 | 995 | remote_advertisement); |
---|
962 | | - lan743x_ptp_update_latency(adapter, ksettings.base.speed); |
---|
| 996 | + lan743x_ptp_update_latency(adapter, phydev->speed); |
---|
963 | 997 | } |
---|
964 | 998 | } |
---|
965 | 999 | |
---|
.. | .. |
---|
975 | 1009 | static int lan743x_phy_open(struct lan743x_adapter *adapter) |
---|
976 | 1010 | { |
---|
977 | 1011 | struct lan743x_phy *phy = &adapter->phy; |
---|
978 | | - struct phy_device *phydev; |
---|
| 1012 | + struct phy_device *phydev = NULL; |
---|
| 1013 | + struct device_node *phynode; |
---|
979 | 1014 | struct net_device *netdev; |
---|
980 | 1015 | int ret = -EIO; |
---|
981 | | - u32 mii_adv; |
---|
982 | 1016 | |
---|
983 | 1017 | netdev = adapter->netdev; |
---|
984 | | - phydev = phy_find_first(adapter->mdiobus); |
---|
985 | | - if (!phydev) |
---|
986 | | - goto return_error; |
---|
| 1018 | + phynode = of_node_get(adapter->pdev->dev.of_node); |
---|
987 | 1019 | |
---|
988 | | - ret = phy_connect_direct(netdev, phydev, |
---|
989 | | - lan743x_phy_link_status_change, |
---|
990 | | - PHY_INTERFACE_MODE_GMII); |
---|
991 | | - if (ret) |
---|
992 | | - goto return_error; |
---|
| 1020 | + if (phynode) { |
---|
| 1021 | + /* try devicetree phy, or fixed link */ |
---|
| 1022 | + of_get_phy_mode(phynode, &adapter->phy_mode); |
---|
| 1023 | + |
---|
| 1024 | + if (of_phy_is_fixed_link(phynode)) { |
---|
| 1025 | + ret = of_phy_register_fixed_link(phynode); |
---|
| 1026 | + if (ret) { |
---|
| 1027 | + netdev_err(netdev, |
---|
| 1028 | + "cannot register fixed PHY\n"); |
---|
| 1029 | + of_node_put(phynode); |
---|
| 1030 | + goto return_error; |
---|
| 1031 | + } |
---|
| 1032 | + } |
---|
| 1033 | + phydev = of_phy_connect(netdev, phynode, |
---|
| 1034 | + lan743x_phy_link_status_change, 0, |
---|
| 1035 | + adapter->phy_mode); |
---|
| 1036 | + of_node_put(phynode); |
---|
| 1037 | + } |
---|
| 1038 | + |
---|
| 1039 | + if (!phydev) { |
---|
| 1040 | + /* try internal phy */ |
---|
| 1041 | + phydev = phy_find_first(adapter->mdiobus); |
---|
| 1042 | + if (!phydev) |
---|
| 1043 | + goto return_error; |
---|
| 1044 | + |
---|
| 1045 | + adapter->phy_mode = PHY_INTERFACE_MODE_GMII; |
---|
| 1046 | + ret = phy_connect_direct(netdev, phydev, |
---|
| 1047 | + lan743x_phy_link_status_change, |
---|
| 1048 | + adapter->phy_mode); |
---|
| 1049 | + if (ret) |
---|
| 1050 | + goto return_error; |
---|
| 1051 | + } |
---|
993 | 1052 | |
---|
994 | 1053 | /* MAC doesn't support 1000T Half */ |
---|
995 | | - phydev->supported &= ~SUPPORTED_1000baseT_Half; |
---|
| 1054 | + phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT); |
---|
996 | 1055 | |
---|
997 | 1056 | /* support both flow controls */ |
---|
| 1057 | + phy_support_asym_pause(phydev); |
---|
998 | 1058 | phy->fc_request_control = (FLOW_CTRL_RX | FLOW_CTRL_TX); |
---|
999 | | - phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
---|
1000 | | - mii_adv = (u32)mii_advertise_flowctrl(phy->fc_request_control); |
---|
1001 | | - phydev->advertising |= mii_adv_to_ethtool_adv_t(mii_adv); |
---|
1002 | 1059 | phy->fc_autoneg = phydev->autoneg; |
---|
1003 | 1060 | |
---|
1004 | 1061 | phy_start(phydev); |
---|
.. | .. |
---|
1217 | 1274 | if (!(buffer_info->flags & TX_BUFFER_INFO_FLAG_ACTIVE)) |
---|
1218 | 1275 | goto done; |
---|
1219 | 1276 | |
---|
1220 | | - descriptor_type = (descriptor->data0) & |
---|
| 1277 | + descriptor_type = le32_to_cpu(descriptor->data0) & |
---|
1221 | 1278 | TX_DESC_DATA0_DTYPE_MASK_; |
---|
1222 | 1279 | if (descriptor_type == TX_DESC_DATA0_DTYPE_DATA_) |
---|
1223 | 1280 | goto clean_up_data_descriptor; |
---|
.. | .. |
---|
1277 | 1334 | |
---|
1278 | 1335 | static void lan743x_tx_release_completed_descriptors(struct lan743x_tx *tx) |
---|
1279 | 1336 | { |
---|
1280 | | - while ((*tx->head_cpu_ptr) != (tx->last_head)) { |
---|
| 1337 | + while (le32_to_cpu(*tx->head_cpu_ptr) != (tx->last_head)) { |
---|
1281 | 1338 | lan743x_tx_release_desc(tx, tx->last_head, false); |
---|
1282 | 1339 | tx->last_head = lan743x_tx_next_index(tx, tx->last_head); |
---|
1283 | 1340 | } |
---|
.. | .. |
---|
1363 | 1420 | if (dma_mapping_error(dev, dma_ptr)) |
---|
1364 | 1421 | return -ENOMEM; |
---|
1365 | 1422 | |
---|
1366 | | - tx_descriptor->data1 = DMA_ADDR_LOW32(dma_ptr); |
---|
1367 | | - tx_descriptor->data2 = DMA_ADDR_HIGH32(dma_ptr); |
---|
1368 | | - tx_descriptor->data3 = (frame_length << 16) & |
---|
1369 | | - TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_; |
---|
| 1423 | + tx_descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(dma_ptr)); |
---|
| 1424 | + tx_descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(dma_ptr)); |
---|
| 1425 | + tx_descriptor->data3 = cpu_to_le32((frame_length << 16) & |
---|
| 1426 | + TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_); |
---|
1370 | 1427 | |
---|
1371 | 1428 | buffer_info->skb = NULL; |
---|
1372 | 1429 | buffer_info->dma_ptr = dma_ptr; |
---|
.. | .. |
---|
1407 | 1464 | tx->frame_data0 |= TX_DESC_DATA0_IOC_; |
---|
1408 | 1465 | } |
---|
1409 | 1466 | tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; |
---|
1410 | | - tx_descriptor->data0 = tx->frame_data0; |
---|
| 1467 | + tx_descriptor->data0 = cpu_to_le32(tx->frame_data0); |
---|
1411 | 1468 | |
---|
1412 | 1469 | /* move to next descriptor */ |
---|
1413 | 1470 | tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail); |
---|
.. | .. |
---|
1432 | 1489 | } |
---|
1433 | 1490 | |
---|
1434 | 1491 | static int lan743x_tx_frame_add_fragment(struct lan743x_tx *tx, |
---|
1435 | | - const struct skb_frag_struct *fragment, |
---|
| 1492 | + const skb_frag_t *fragment, |
---|
1436 | 1493 | unsigned int frame_length) |
---|
1437 | 1494 | { |
---|
1438 | 1495 | /* called only from within lan743x_tx_xmit_frame |
---|
.. | .. |
---|
1451 | 1508 | |
---|
1452 | 1509 | /* wrap up previous descriptor */ |
---|
1453 | 1510 | tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail]; |
---|
1454 | | - tx_descriptor->data0 = tx->frame_data0; |
---|
| 1511 | + tx_descriptor->data0 = cpu_to_le32(tx->frame_data0); |
---|
1455 | 1512 | |
---|
1456 | 1513 | /* move to next descriptor */ |
---|
1457 | 1514 | tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail); |
---|
.. | .. |
---|
1477 | 1534 | return -ENOMEM; |
---|
1478 | 1535 | } |
---|
1479 | 1536 | |
---|
1480 | | - tx_descriptor->data1 = DMA_ADDR_LOW32(dma_ptr); |
---|
1481 | | - tx_descriptor->data2 = DMA_ADDR_HIGH32(dma_ptr); |
---|
1482 | | - tx_descriptor->data3 = (frame_length << 16) & |
---|
1483 | | - TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_; |
---|
| 1537 | + tx_descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(dma_ptr)); |
---|
| 1538 | + tx_descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(dma_ptr)); |
---|
| 1539 | + tx_descriptor->data3 = cpu_to_le32((frame_length << 16) & |
---|
| 1540 | + TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_); |
---|
1484 | 1541 | |
---|
1485 | 1542 | buffer_info->skb = NULL; |
---|
1486 | 1543 | buffer_info->dma_ptr = dma_ptr; |
---|
.. | .. |
---|
1524 | 1581 | if (ignore_sync) |
---|
1525 | 1582 | buffer_info->flags |= TX_BUFFER_INFO_FLAG_IGNORE_SYNC; |
---|
1526 | 1583 | |
---|
1527 | | - tx_descriptor->data0 = tx->frame_data0; |
---|
| 1584 | + tx_descriptor->data0 = cpu_to_le32(tx->frame_data0); |
---|
1528 | 1585 | tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail); |
---|
1529 | 1586 | tx->last_tail = tx->frame_tail; |
---|
1530 | 1587 | |
---|
.. | .. |
---|
1605 | 1662 | goto finish; |
---|
1606 | 1663 | |
---|
1607 | 1664 | for (j = 0; j < nr_frags; j++) { |
---|
1608 | | - const struct skb_frag_struct *frag; |
---|
| 1665 | + const skb_frag_t *frag = &(skb_shinfo(skb)->frags[j]); |
---|
1609 | 1666 | |
---|
1610 | | - frag = &(skb_shinfo(skb)->frags[j]); |
---|
1611 | 1667 | if (lan743x_tx_frame_add_fragment(tx, frag, frame_length)) { |
---|
1612 | 1668 | /* upon error no need to call |
---|
1613 | 1669 | * lan743x_tx_frame_end |
---|
.. | .. |
---|
1676 | 1732 | static void lan743x_tx_ring_cleanup(struct lan743x_tx *tx) |
---|
1677 | 1733 | { |
---|
1678 | 1734 | if (tx->head_cpu_ptr) { |
---|
1679 | | - pci_free_consistent(tx->adapter->pdev, |
---|
1680 | | - sizeof(*tx->head_cpu_ptr), |
---|
1681 | | - (void *)(tx->head_cpu_ptr), |
---|
1682 | | - tx->head_dma_ptr); |
---|
| 1735 | + dma_free_coherent(&tx->adapter->pdev->dev, |
---|
| 1736 | + sizeof(*tx->head_cpu_ptr), tx->head_cpu_ptr, |
---|
| 1737 | + tx->head_dma_ptr); |
---|
1683 | 1738 | tx->head_cpu_ptr = NULL; |
---|
1684 | 1739 | tx->head_dma_ptr = 0; |
---|
1685 | 1740 | } |
---|
.. | .. |
---|
1687 | 1742 | tx->buffer_info = NULL; |
---|
1688 | 1743 | |
---|
1689 | 1744 | if (tx->ring_cpu_ptr) { |
---|
1690 | | - pci_free_consistent(tx->adapter->pdev, |
---|
1691 | | - tx->ring_allocation_size, |
---|
1692 | | - tx->ring_cpu_ptr, |
---|
1693 | | - tx->ring_dma_ptr); |
---|
| 1745 | + dma_free_coherent(&tx->adapter->pdev->dev, |
---|
| 1746 | + tx->ring_allocation_size, tx->ring_cpu_ptr, |
---|
| 1747 | + tx->ring_dma_ptr); |
---|
1694 | 1748 | tx->ring_allocation_size = 0; |
---|
1695 | 1749 | tx->ring_cpu_ptr = NULL; |
---|
1696 | 1750 | tx->ring_dma_ptr = 0; |
---|
.. | .. |
---|
1724 | 1778 | sizeof(struct lan743x_tx_descriptor), |
---|
1725 | 1779 | PAGE_SIZE); |
---|
1726 | 1780 | dma_ptr = 0; |
---|
1727 | | - cpu_ptr = pci_zalloc_consistent(tx->adapter->pdev, |
---|
1728 | | - ring_allocation_size, &dma_ptr); |
---|
| 1781 | + cpu_ptr = dma_alloc_coherent(&tx->adapter->pdev->dev, |
---|
| 1782 | + ring_allocation_size, &dma_ptr, GFP_KERNEL); |
---|
1729 | 1783 | if (!cpu_ptr) { |
---|
1730 | 1784 | ret = -ENOMEM; |
---|
1731 | 1785 | goto cleanup; |
---|
.. | .. |
---|
1742 | 1796 | } |
---|
1743 | 1797 | tx->buffer_info = (struct lan743x_tx_buffer_info *)cpu_ptr; |
---|
1744 | 1798 | dma_ptr = 0; |
---|
1745 | | - cpu_ptr = pci_zalloc_consistent(tx->adapter->pdev, |
---|
1746 | | - sizeof(*tx->head_cpu_ptr), &dma_ptr); |
---|
| 1799 | + cpu_ptr = dma_alloc_coherent(&tx->adapter->pdev->dev, |
---|
| 1800 | + sizeof(*tx->head_cpu_ptr), &dma_ptr, |
---|
| 1801 | + GFP_KERNEL); |
---|
1747 | 1802 | if (!cpu_ptr) { |
---|
1748 | 1803 | ret = -ENOMEM; |
---|
1749 | 1804 | goto cleanup; |
---|
.. | .. |
---|
1902 | 1957 | return ((++index) % rx->ring_size); |
---|
1903 | 1958 | } |
---|
1904 | 1959 | |
---|
1905 | | -static struct sk_buff *lan743x_rx_allocate_skb(struct lan743x_rx *rx) |
---|
| 1960 | +static struct sk_buff *lan743x_rx_allocate_skb(struct lan743x_rx *rx, gfp_t gfp) |
---|
1906 | 1961 | { |
---|
1907 | 1962 | int length = 0; |
---|
1908 | 1963 | |
---|
1909 | 1964 | length = (LAN743X_MAX_FRAME_SIZE + ETH_HLEN + 4 + RX_HEAD_PADDING); |
---|
1910 | 1965 | return __netdev_alloc_skb(rx->adapter->netdev, |
---|
1911 | | - length, GFP_ATOMIC | GFP_DMA); |
---|
| 1966 | + length, gfp); |
---|
| 1967 | +} |
---|
| 1968 | + |
---|
| 1969 | +static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index) |
---|
| 1970 | +{ |
---|
| 1971 | + /* update the tail once per 8 descriptors */ |
---|
| 1972 | + if ((index & 7) == 7) |
---|
| 1973 | + lan743x_csr_write(rx->adapter, RX_TAIL(rx->channel_number), |
---|
| 1974 | + index); |
---|
1912 | 1975 | } |
---|
1913 | 1976 | |
---|
1914 | 1977 | static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index, |
---|
.. | .. |
---|
1935 | 1998 | } |
---|
1936 | 1999 | |
---|
1937 | 2000 | buffer_info->buffer_length = length; |
---|
1938 | | - descriptor->data1 = DMA_ADDR_LOW32(buffer_info->dma_ptr); |
---|
1939 | | - descriptor->data2 = DMA_ADDR_HIGH32(buffer_info->dma_ptr); |
---|
| 2001 | + descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(buffer_info->dma_ptr)); |
---|
| 2002 | + descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(buffer_info->dma_ptr)); |
---|
1940 | 2003 | descriptor->data3 = 0; |
---|
1941 | | - descriptor->data0 = (RX_DESC_DATA0_OWN_ | |
---|
1942 | | - (length & RX_DESC_DATA0_BUF_LENGTH_MASK_)); |
---|
| 2004 | + descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ | |
---|
| 2005 | + (length & RX_DESC_DATA0_BUF_LENGTH_MASK_))); |
---|
1943 | 2006 | skb_reserve(buffer_info->skb, RX_HEAD_PADDING); |
---|
| 2007 | + lan743x_rx_update_tail(rx, index); |
---|
1944 | 2008 | |
---|
1945 | 2009 | return 0; |
---|
1946 | 2010 | } |
---|
.. | .. |
---|
1953 | 2017 | descriptor = &rx->ring_cpu_ptr[index]; |
---|
1954 | 2018 | buffer_info = &rx->buffer_info[index]; |
---|
1955 | 2019 | |
---|
1956 | | - descriptor->data1 = DMA_ADDR_LOW32(buffer_info->dma_ptr); |
---|
1957 | | - descriptor->data2 = DMA_ADDR_HIGH32(buffer_info->dma_ptr); |
---|
| 2020 | + descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(buffer_info->dma_ptr)); |
---|
| 2021 | + descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(buffer_info->dma_ptr)); |
---|
1958 | 2022 | descriptor->data3 = 0; |
---|
1959 | | - descriptor->data0 = (RX_DESC_DATA0_OWN_ | |
---|
| 2023 | + descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ | |
---|
1960 | 2024 | ((buffer_info->buffer_length) & |
---|
1961 | | - RX_DESC_DATA0_BUF_LENGTH_MASK_)); |
---|
| 2025 | + RX_DESC_DATA0_BUF_LENGTH_MASK_))); |
---|
| 2026 | + lan743x_rx_update_tail(rx, index); |
---|
1962 | 2027 | } |
---|
1963 | 2028 | |
---|
1964 | 2029 | static void lan743x_rx_release_ring_element(struct lan743x_rx *rx, int index) |
---|
.. | .. |
---|
1991 | 2056 | { |
---|
1992 | 2057 | struct skb_shared_hwtstamps *hwtstamps = NULL; |
---|
1993 | 2058 | int result = RX_PROCESS_RESULT_NOTHING_TO_DO; |
---|
| 2059 | + int current_head_index = le32_to_cpu(*rx->head_cpu_ptr); |
---|
1994 | 2060 | struct lan743x_rx_buffer_info *buffer_info; |
---|
1995 | 2061 | struct lan743x_rx_descriptor *descriptor; |
---|
1996 | | - int current_head_index = -1; |
---|
1997 | 2062 | int extension_index = -1; |
---|
1998 | 2063 | int first_index = -1; |
---|
1999 | 2064 | int last_index = -1; |
---|
2000 | 2065 | |
---|
2001 | | - current_head_index = *rx->head_cpu_ptr; |
---|
2002 | 2066 | if (current_head_index < 0 || current_head_index >= rx->ring_size) |
---|
2003 | 2067 | goto done; |
---|
2004 | 2068 | |
---|
.. | .. |
---|
2007 | 2071 | |
---|
2008 | 2072 | if (rx->last_head != current_head_index) { |
---|
2009 | 2073 | descriptor = &rx->ring_cpu_ptr[rx->last_head]; |
---|
2010 | | - if (descriptor->data0 & RX_DESC_DATA0_OWN_) |
---|
| 2074 | + if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_OWN_) |
---|
2011 | 2075 | goto done; |
---|
2012 | 2076 | |
---|
2013 | | - if (!(descriptor->data0 & RX_DESC_DATA0_FS_)) |
---|
| 2077 | + if (!(le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_FS_)) |
---|
2014 | 2078 | goto done; |
---|
2015 | 2079 | |
---|
2016 | 2080 | first_index = rx->last_head; |
---|
2017 | | - if (descriptor->data0 & RX_DESC_DATA0_LS_) { |
---|
| 2081 | + if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) { |
---|
2018 | 2082 | last_index = rx->last_head; |
---|
2019 | 2083 | } else { |
---|
2020 | 2084 | int index; |
---|
.. | .. |
---|
2022 | 2086 | index = lan743x_rx_next_index(rx, first_index); |
---|
2023 | 2087 | while (index != current_head_index) { |
---|
2024 | 2088 | descriptor = &rx->ring_cpu_ptr[index]; |
---|
2025 | | - if (descriptor->data0 & RX_DESC_DATA0_OWN_) |
---|
| 2089 | + if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_OWN_) |
---|
2026 | 2090 | goto done; |
---|
2027 | 2091 | |
---|
2028 | | - if (descriptor->data0 & RX_DESC_DATA0_LS_) { |
---|
| 2092 | + if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) { |
---|
2029 | 2093 | last_index = index; |
---|
2030 | 2094 | break; |
---|
2031 | 2095 | } |
---|
.. | .. |
---|
2034 | 2098 | } |
---|
2035 | 2099 | if (last_index >= 0) { |
---|
2036 | 2100 | descriptor = &rx->ring_cpu_ptr[last_index]; |
---|
2037 | | - if (descriptor->data0 & RX_DESC_DATA0_EXT_) { |
---|
| 2101 | + if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_EXT_) { |
---|
2038 | 2102 | /* extension is expected to follow */ |
---|
2039 | 2103 | int index = lan743x_rx_next_index(rx, |
---|
2040 | 2104 | last_index); |
---|
2041 | 2105 | if (index != current_head_index) { |
---|
2042 | 2106 | descriptor = &rx->ring_cpu_ptr[index]; |
---|
2043 | | - if (descriptor->data0 & |
---|
| 2107 | + if (le32_to_cpu(descriptor->data0) & |
---|
2044 | 2108 | RX_DESC_DATA0_OWN_) { |
---|
2045 | 2109 | goto done; |
---|
2046 | 2110 | } |
---|
2047 | | - if (descriptor->data0 & |
---|
| 2111 | + if (le32_to_cpu(descriptor->data0) & |
---|
2048 | 2112 | RX_DESC_DATA0_EXT_) { |
---|
2049 | 2113 | extension_index = index; |
---|
2050 | 2114 | } else { |
---|
.. | .. |
---|
2071 | 2135 | struct sk_buff *new_skb = NULL; |
---|
2072 | 2136 | int packet_length; |
---|
2073 | 2137 | |
---|
2074 | | - new_skb = lan743x_rx_allocate_skb(rx); |
---|
| 2138 | + new_skb = lan743x_rx_allocate_skb(rx, |
---|
| 2139 | + GFP_ATOMIC | GFP_DMA); |
---|
2075 | 2140 | if (!new_skb) { |
---|
2076 | 2141 | /* failed to allocate next skb. |
---|
2077 | 2142 | * Memory is very low. |
---|
.. | .. |
---|
2096 | 2161 | } |
---|
2097 | 2162 | buffer_info->skb = NULL; |
---|
2098 | 2163 | packet_length = RX_DESC_DATA0_FRAME_LENGTH_GET_ |
---|
2099 | | - (descriptor->data0); |
---|
| 2164 | + (le32_to_cpu(descriptor->data0)); |
---|
2100 | 2165 | skb_put(skb, packet_length - 4); |
---|
2101 | 2166 | skb->protocol = eth_type_trans(skb, |
---|
2102 | 2167 | rx->adapter->netdev); |
---|
.. | .. |
---|
2134 | 2199 | descriptor = &rx->ring_cpu_ptr[extension_index]; |
---|
2135 | 2200 | buffer_info = &rx->buffer_info[extension_index]; |
---|
2136 | 2201 | |
---|
2137 | | - ts_sec = descriptor->data1; |
---|
2138 | | - ts_nsec = (descriptor->data2 & |
---|
| 2202 | + ts_sec = le32_to_cpu(descriptor->data1); |
---|
| 2203 | + ts_nsec = (le32_to_cpu(descriptor->data2) & |
---|
2139 | 2204 | RX_DESC_DATA2_TS_NS_MASK_); |
---|
2140 | 2205 | lan743x_rx_reuse_ring_element(rx, extension_index); |
---|
2141 | 2206 | real_last_index = extension_index; |
---|
.. | .. |
---|
2170 | 2235 | { |
---|
2171 | 2236 | struct lan743x_rx *rx = container_of(napi, struct lan743x_rx, napi); |
---|
2172 | 2237 | struct lan743x_adapter *adapter = rx->adapter; |
---|
| 2238 | + int result = RX_PROCESS_RESULT_NOTHING_TO_DO; |
---|
2173 | 2239 | u32 rx_tail_flags = 0; |
---|
2174 | 2240 | int count; |
---|
2175 | 2241 | |
---|
.. | .. |
---|
2178 | 2244 | lan743x_csr_write(adapter, DMAC_INT_STS, |
---|
2179 | 2245 | DMAC_INT_BIT_RXFRM_(rx->channel_number)); |
---|
2180 | 2246 | } |
---|
2181 | | - count = 0; |
---|
2182 | | - while (count < weight) { |
---|
2183 | | - int rx_process_result = -1; |
---|
2184 | | - |
---|
2185 | | - rx_process_result = lan743x_rx_process_packet(rx); |
---|
2186 | | - if (rx_process_result == RX_PROCESS_RESULT_PACKET_RECEIVED) { |
---|
2187 | | - count++; |
---|
2188 | | - } else if (rx_process_result == |
---|
2189 | | - RX_PROCESS_RESULT_NOTHING_TO_DO) { |
---|
| 2247 | + for (count = 0; count < weight; count++) { |
---|
| 2248 | + result = lan743x_rx_process_packet(rx); |
---|
| 2249 | + if (result == RX_PROCESS_RESULT_NOTHING_TO_DO) |
---|
2190 | 2250 | break; |
---|
2191 | | - } else if (rx_process_result == |
---|
2192 | | - RX_PROCESS_RESULT_PACKET_DROPPED) { |
---|
2193 | | - continue; |
---|
2194 | | - } |
---|
2195 | 2251 | } |
---|
2196 | 2252 | rx->frame_count += count; |
---|
2197 | | - if (count == weight) |
---|
2198 | | - goto done; |
---|
| 2253 | + if (count == weight || result == RX_PROCESS_RESULT_PACKET_RECEIVED) |
---|
| 2254 | + return weight; |
---|
2199 | 2255 | |
---|
2200 | 2256 | if (!napi_complete_done(napi, count)) |
---|
2201 | | - goto done; |
---|
| 2257 | + return count; |
---|
2202 | 2258 | |
---|
| 2259 | + /* re-arm interrupts, must write to rx tail on some chip variants */ |
---|
2203 | 2260 | if (rx->vector_flags & LAN743X_VECTOR_FLAG_VECTOR_ENABLE_AUTO_SET) |
---|
2204 | 2261 | rx_tail_flags |= RX_TAIL_SET_TOP_INT_VEC_EN_; |
---|
2205 | 2262 | if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_SET) { |
---|
.. | .. |
---|
2209 | 2266 | INT_BIT_DMA_RX_(rx->channel_number)); |
---|
2210 | 2267 | } |
---|
2211 | 2268 | |
---|
2212 | | - /* update RX_TAIL */ |
---|
2213 | | - lan743x_csr_write(adapter, RX_TAIL(rx->channel_number), |
---|
2214 | | - rx_tail_flags | rx->last_tail); |
---|
2215 | | -done: |
---|
| 2269 | + if (rx_tail_flags) |
---|
| 2270 | + lan743x_csr_write(adapter, RX_TAIL(rx->channel_number), |
---|
| 2271 | + rx_tail_flags | rx->last_tail); |
---|
| 2272 | + |
---|
2216 | 2273 | return count; |
---|
2217 | 2274 | } |
---|
2218 | 2275 | |
---|
.. | .. |
---|
2226 | 2283 | } |
---|
2227 | 2284 | |
---|
2228 | 2285 | if (rx->head_cpu_ptr) { |
---|
2229 | | - pci_free_consistent(rx->adapter->pdev, |
---|
2230 | | - sizeof(*rx->head_cpu_ptr), |
---|
2231 | | - rx->head_cpu_ptr, |
---|
2232 | | - rx->head_dma_ptr); |
---|
| 2286 | + dma_free_coherent(&rx->adapter->pdev->dev, |
---|
| 2287 | + sizeof(*rx->head_cpu_ptr), rx->head_cpu_ptr, |
---|
| 2288 | + rx->head_dma_ptr); |
---|
2233 | 2289 | rx->head_cpu_ptr = NULL; |
---|
2234 | 2290 | rx->head_dma_ptr = 0; |
---|
2235 | 2291 | } |
---|
.. | .. |
---|
2238 | 2294 | rx->buffer_info = NULL; |
---|
2239 | 2295 | |
---|
2240 | 2296 | if (rx->ring_cpu_ptr) { |
---|
2241 | | - pci_free_consistent(rx->adapter->pdev, |
---|
2242 | | - rx->ring_allocation_size, |
---|
2243 | | - rx->ring_cpu_ptr, |
---|
2244 | | - rx->ring_dma_ptr); |
---|
| 2297 | + dma_free_coherent(&rx->adapter->pdev->dev, |
---|
| 2298 | + rx->ring_allocation_size, rx->ring_cpu_ptr, |
---|
| 2299 | + rx->ring_dma_ptr); |
---|
2245 | 2300 | rx->ring_allocation_size = 0; |
---|
2246 | 2301 | rx->ring_cpu_ptr = NULL; |
---|
2247 | 2302 | rx->ring_dma_ptr = 0; |
---|
.. | .. |
---|
2282 | 2337 | sizeof(struct lan743x_rx_descriptor), |
---|
2283 | 2338 | PAGE_SIZE); |
---|
2284 | 2339 | dma_ptr = 0; |
---|
2285 | | - cpu_ptr = pci_zalloc_consistent(rx->adapter->pdev, |
---|
2286 | | - ring_allocation_size, &dma_ptr); |
---|
| 2340 | + cpu_ptr = dma_alloc_coherent(&rx->adapter->pdev->dev, |
---|
| 2341 | + ring_allocation_size, &dma_ptr, GFP_KERNEL); |
---|
2287 | 2342 | if (!cpu_ptr) { |
---|
2288 | 2343 | ret = -ENOMEM; |
---|
2289 | 2344 | goto cleanup; |
---|
.. | .. |
---|
2300 | 2355 | } |
---|
2301 | 2356 | rx->buffer_info = (struct lan743x_rx_buffer_info *)cpu_ptr; |
---|
2302 | 2357 | dma_ptr = 0; |
---|
2303 | | - cpu_ptr = pci_zalloc_consistent(rx->adapter->pdev, |
---|
2304 | | - sizeof(*rx->head_cpu_ptr), &dma_ptr); |
---|
| 2358 | + cpu_ptr = dma_alloc_coherent(&rx->adapter->pdev->dev, |
---|
| 2359 | + sizeof(*rx->head_cpu_ptr), &dma_ptr, |
---|
| 2360 | + GFP_KERNEL); |
---|
2305 | 2361 | if (!cpu_ptr) { |
---|
2306 | 2362 | ret = -ENOMEM; |
---|
2307 | 2363 | goto cleanup; |
---|
.. | .. |
---|
2316 | 2372 | |
---|
2317 | 2373 | rx->last_head = 0; |
---|
2318 | 2374 | for (index = 0; index < rx->ring_size; index++) { |
---|
2319 | | - struct sk_buff *new_skb = lan743x_rx_allocate_skb(rx); |
---|
| 2375 | + struct sk_buff *new_skb = lan743x_rx_allocate_skb(rx, |
---|
| 2376 | + GFP_KERNEL); |
---|
2320 | 2377 | |
---|
2321 | 2378 | ret = lan743x_rx_init_ring_element(rx, index, new_skb); |
---|
2322 | 2379 | if (ret) |
---|
.. | .. |
---|
2367 | 2424 | |
---|
2368 | 2425 | netif_napi_add(adapter->netdev, |
---|
2369 | 2426 | &rx->napi, lan743x_rx_napi_poll, |
---|
2370 | | - rx->ring_size - 1); |
---|
| 2427 | + NAPI_POLL_WEIGHT); |
---|
2371 | 2428 | |
---|
2372 | 2429 | lan743x_csr_write(adapter, DMAC_CMD, |
---|
2373 | 2430 | DMAC_CMD_RX_SWR_(rx->channel_number)); |
---|
.. | .. |
---|
2774 | 2831 | { |
---|
2775 | 2832 | struct lan743x_adapter *adapter = NULL; |
---|
2776 | 2833 | struct net_device *netdev = NULL; |
---|
| 2834 | + const void *mac_addr; |
---|
2777 | 2835 | int ret = -ENODEV; |
---|
2778 | 2836 | |
---|
2779 | 2837 | netdev = devm_alloc_etherdev(&pdev->dev, |
---|
.. | .. |
---|
2789 | 2847 | NETIF_MSG_LINK | NETIF_MSG_IFUP | |
---|
2790 | 2848 | NETIF_MSG_IFDOWN | NETIF_MSG_TX_QUEUED; |
---|
2791 | 2849 | netdev->max_mtu = LAN743X_MAX_FRAME_SIZE; |
---|
| 2850 | + |
---|
| 2851 | + mac_addr = of_get_mac_address(pdev->dev.of_node); |
---|
| 2852 | + if (!IS_ERR(mac_addr)) |
---|
| 2853 | + ether_addr_copy(adapter->mac_address, mac_addr); |
---|
2792 | 2854 | |
---|
2793 | 2855 | ret = lan743x_pci_init(adapter, pdev); |
---|
2794 | 2856 | if (ret) |
---|
.. | .. |
---|
2990 | 3052 | struct pci_dev *pdev = to_pci_dev(dev); |
---|
2991 | 3053 | struct net_device *netdev = pci_get_drvdata(pdev); |
---|
2992 | 3054 | struct lan743x_adapter *adapter = netdev_priv(netdev); |
---|
2993 | | - int ret; |
---|
2994 | 3055 | |
---|
2995 | 3056 | lan743x_pcidev_shutdown(pdev); |
---|
2996 | 3057 | |
---|
.. | .. |
---|
3003 | 3064 | lan743x_pm_set_wol(adapter); |
---|
3004 | 3065 | |
---|
3005 | 3066 | /* Host sets PME_En, put D3hot */ |
---|
3006 | | - ret = pci_prepare_to_sleep(pdev); |
---|
3007 | | - |
---|
3008 | | - return 0; |
---|
| 3067 | + return pci_prepare_to_sleep(pdev);; |
---|
3009 | 3068 | } |
---|
3010 | 3069 | |
---|
3011 | 3070 | static int lan743x_pm_resume(struct device *dev) |
---|
.. | .. |
---|
3050 | 3109 | { 0, } |
---|
3051 | 3110 | }; |
---|
3052 | 3111 | |
---|
| 3112 | +MODULE_DEVICE_TABLE(pci, lan743x_pcidev_tbl); |
---|
| 3113 | + |
---|
3053 | 3114 | static struct pci_driver lan743x_pcidev_driver = { |
---|
3054 | 3115 | .name = DRIVER_NAME, |
---|
3055 | 3116 | .id_table = lan743x_pcidev_tbl, |
---|