hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/net/ethernet/microchip/lan743x_main.c
....@@ -8,7 +8,10 @@
88 #include <linux/crc32.h>
99 #include <linux/microchipphy.h>
1010 #include <linux/net_tstamp.h>
11
+#include <linux/of_mdio.h>
12
+#include <linux/of_net.h>
1113 #include <linux/phy.h>
14
+#include <linux/phy_fixed.h>
1215 #include <linux/rtnetlink.h>
1316 #include <linux/iopoll.h>
1417 #include <linux/crc16.h>
....@@ -78,6 +81,18 @@
7881
7982 return readx_poll_timeout(LAN743X_CSR_READ_OP, HW_CFG, data,
8083 !(data & HW_CFG_LRST_), 100000, 10000000);
84
+}
85
+
86
+static int lan743x_csr_wait_for_bit_atomic(struct lan743x_adapter *adapter,
87
+ int offset, u32 bit_mask,
88
+ int target_value, int udelay_min,
89
+ int udelay_max, int count)
90
+{
91
+ u32 data;
92
+
93
+ return readx_poll_timeout_atomic(LAN743X_CSR_READ_OP, offset, data,
94
+ target_value == !!(data & bit_mask),
95
+ udelay_max, udelay_min * count);
8196 }
8297
8398 static int lan743x_csr_wait_for_bit(struct lan743x_adapter *adapter,
....@@ -675,8 +690,8 @@
675690 u32 dp_sel;
676691 int i;
677692
678
- if (lan743x_csr_wait_for_bit(adapter, DP_SEL, DP_SEL_DPRDY_,
679
- 1, 40, 100, 100))
693
+ if (lan743x_csr_wait_for_bit_atomic(adapter, DP_SEL, DP_SEL_DPRDY_,
694
+ 1, 40, 100, 100))
680695 return -EIO;
681696 dp_sel = lan743x_csr_read(adapter, DP_SEL);
682697 dp_sel &= ~DP_SEL_MASK_;
....@@ -687,8 +702,9 @@
687702 lan743x_csr_write(adapter, DP_ADDR, addr + i);
688703 lan743x_csr_write(adapter, DP_DATA_0, buf[i]);
689704 lan743x_csr_write(adapter, DP_CMD, DP_CMD_WRITE_);
690
- if (lan743x_csr_wait_for_bit(adapter, DP_SEL, DP_SEL_DPRDY_,
691
- 1, 40, 100, 100))
705
+ if (lan743x_csr_wait_for_bit_atomic(adapter, DP_SEL,
706
+ DP_SEL_DPRDY_,
707
+ 1, 40, 100, 100))
692708 return -EIO;
693709 }
694710
....@@ -793,32 +809,35 @@
793809
794810 netdev = adapter->netdev;
795811
796
- /* setup auto duplex, and speed detection */
812
+ /* disable auto duplex, and speed detection. Phylib does that */
797813 data = lan743x_csr_read(adapter, MAC_CR);
798
- data |= MAC_CR_ADD_ | MAC_CR_ASD_;
814
+ data &= ~(MAC_CR_ADD_ | MAC_CR_ASD_);
799815 data |= MAC_CR_CNTR_RST_;
800816 lan743x_csr_write(adapter, MAC_CR, data);
801817
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;
818
+ if (!is_valid_ether_addr(adapter->mac_address)) {
819
+ mac_addr_hi = lan743x_csr_read(adapter, MAC_RX_ADDRH);
820
+ mac_addr_lo = lan743x_csr_read(adapter, MAC_RX_ADDRL);
821
+ adapter->mac_address[0] = mac_addr_lo & 0xFF;
822
+ adapter->mac_address[1] = (mac_addr_lo >> 8) & 0xFF;
823
+ adapter->mac_address[2] = (mac_addr_lo >> 16) & 0xFF;
824
+ adapter->mac_address[3] = (mac_addr_lo >> 24) & 0xFF;
825
+ adapter->mac_address[4] = mac_addr_hi & 0xFF;
826
+ adapter->mac_address[5] = (mac_addr_hi >> 8) & 0xFF;
810827
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;
828
+ if (((mac_addr_hi & 0x0000FFFF) == 0x0000FFFF) &&
829
+ mac_addr_lo == 0xFFFFFFFF) {
830
+ mac_address_valid = false;
831
+ } else if (!is_valid_ether_addr(adapter->mac_address)) {
832
+ mac_address_valid = false;
833
+ }
834
+
835
+ if (!mac_address_valid)
836
+ eth_random_addr(adapter->mac_address);
816837 }
817
-
818
- if (!mac_address_valid)
819
- eth_random_addr(adapter->mac_address);
820838 lan743x_mac_set_address(adapter, adapter->mac_address);
821839 ether_addr_copy(netdev->dev_addr, adapter->mac_address);
840
+
822841 return 0;
823842 }
824843
....@@ -916,8 +935,7 @@
916935 }
917936
918937 static void lan743x_phy_update_flowcontrol(struct lan743x_adapter *adapter,
919
- u8 duplex, u16 local_adv,
920
- u16 remote_adv)
938
+ u16 local_adv, u16 remote_adv)
921939 {
922940 struct lan743x_phy *phy = &adapter->phy;
923941 u8 cap;
....@@ -941,25 +959,54 @@
941959 {
942960 struct lan743x_adapter *adapter = netdev_priv(netdev);
943961 struct phy_device *phydev = netdev->phydev;
962
+ u32 data;
944963
945964 phy_print_status(phydev);
946965 if (phydev->state == PHY_RUNNING) {
947
- struct ethtool_link_ksettings ksettings;
948966 int remote_advertisement = 0;
949967 int local_advertisement = 0;
950968
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);
969
+ data = lan743x_csr_read(adapter, MAC_CR);
957970
958
- lan743x_phy_update_flowcontrol(adapter,
959
- ksettings.base.duplex,
960
- local_advertisement,
971
+ /* set interface mode */
972
+ if (phy_interface_mode_is_rgmii(adapter->phy_mode))
973
+ /* RGMII */
974
+ data &= ~MAC_CR_MII_EN_;
975
+ else
976
+ /* GMII */
977
+ data |= MAC_CR_MII_EN_;
978
+
979
+ /* set duplex mode */
980
+ if (phydev->duplex)
981
+ data |= MAC_CR_DPX_;
982
+ else
983
+ data &= ~MAC_CR_DPX_;
984
+
985
+ /* set bus speed */
986
+ switch (phydev->speed) {
987
+ case SPEED_10:
988
+ data &= ~MAC_CR_CFG_H_;
989
+ data &= ~MAC_CR_CFG_L_;
990
+ break;
991
+ case SPEED_100:
992
+ data &= ~MAC_CR_CFG_H_;
993
+ data |= MAC_CR_CFG_L_;
994
+ break;
995
+ case SPEED_1000:
996
+ data |= MAC_CR_CFG_H_;
997
+ data &= ~MAC_CR_CFG_L_;
998
+ break;
999
+ }
1000
+ lan743x_csr_write(adapter, MAC_CR, data);
1001
+
1002
+ local_advertisement =
1003
+ linkmode_adv_to_mii_adv_t(phydev->advertising);
1004
+ remote_advertisement =
1005
+ linkmode_adv_to_mii_adv_t(phydev->lp_advertising);
1006
+
1007
+ lan743x_phy_update_flowcontrol(adapter, local_advertisement,
9611008 remote_advertisement);
962
- lan743x_ptp_update_latency(adapter, ksettings.base.speed);
1009
+ lan743x_ptp_update_latency(adapter, phydev->speed);
9631010 }
9641011 }
9651012
....@@ -975,30 +1022,53 @@
9751022 static int lan743x_phy_open(struct lan743x_adapter *adapter)
9761023 {
9771024 struct lan743x_phy *phy = &adapter->phy;
978
- struct phy_device *phydev;
1025
+ struct phy_device *phydev = NULL;
1026
+ struct device_node *phynode;
9791027 struct net_device *netdev;
9801028 int ret = -EIO;
981
- u32 mii_adv;
9821029
9831030 netdev = adapter->netdev;
984
- phydev = phy_find_first(adapter->mdiobus);
985
- if (!phydev)
986
- goto return_error;
1031
+ phynode = of_node_get(adapter->pdev->dev.of_node);
9871032
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;
1033
+ if (phynode) {
1034
+ /* try devicetree phy, or fixed link */
1035
+ of_get_phy_mode(phynode, &adapter->phy_mode);
1036
+
1037
+ if (of_phy_is_fixed_link(phynode)) {
1038
+ ret = of_phy_register_fixed_link(phynode);
1039
+ if (ret) {
1040
+ netdev_err(netdev,
1041
+ "cannot register fixed PHY\n");
1042
+ of_node_put(phynode);
1043
+ goto return_error;
1044
+ }
1045
+ }
1046
+ phydev = of_phy_connect(netdev, phynode,
1047
+ lan743x_phy_link_status_change, 0,
1048
+ adapter->phy_mode);
1049
+ of_node_put(phynode);
1050
+ }
1051
+
1052
+ if (!phydev) {
1053
+ /* try internal phy */
1054
+ phydev = phy_find_first(adapter->mdiobus);
1055
+ if (!phydev)
1056
+ goto return_error;
1057
+
1058
+ adapter->phy_mode = PHY_INTERFACE_MODE_GMII;
1059
+ ret = phy_connect_direct(netdev, phydev,
1060
+ lan743x_phy_link_status_change,
1061
+ adapter->phy_mode);
1062
+ if (ret)
1063
+ goto return_error;
1064
+ }
9931065
9941066 /* MAC doesn't support 1000T Half */
995
- phydev->supported &= ~SUPPORTED_1000baseT_Half;
1067
+ phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
9961068
9971069 /* support both flow controls */
1070
+ phy_support_asym_pause(phydev);
9981071 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);
10021072 phy->fc_autoneg = phydev->autoneg;
10031073
10041074 phy_start(phydev);
....@@ -1217,7 +1287,7 @@
12171287 if (!(buffer_info->flags & TX_BUFFER_INFO_FLAG_ACTIVE))
12181288 goto done;
12191289
1220
- descriptor_type = (descriptor->data0) &
1290
+ descriptor_type = le32_to_cpu(descriptor->data0) &
12211291 TX_DESC_DATA0_DTYPE_MASK_;
12221292 if (descriptor_type == TX_DESC_DATA0_DTYPE_DATA_)
12231293 goto clean_up_data_descriptor;
....@@ -1277,7 +1347,7 @@
12771347
12781348 static void lan743x_tx_release_completed_descriptors(struct lan743x_tx *tx)
12791349 {
1280
- while ((*tx->head_cpu_ptr) != (tx->last_head)) {
1350
+ while (le32_to_cpu(*tx->head_cpu_ptr) != (tx->last_head)) {
12811351 lan743x_tx_release_desc(tx, tx->last_head, false);
12821352 tx->last_head = lan743x_tx_next_index(tx, tx->last_head);
12831353 }
....@@ -1363,10 +1433,10 @@
13631433 if (dma_mapping_error(dev, dma_ptr))
13641434 return -ENOMEM;
13651435
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_;
1436
+ tx_descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(dma_ptr));
1437
+ tx_descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(dma_ptr));
1438
+ tx_descriptor->data3 = cpu_to_le32((frame_length << 16) &
1439
+ TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_);
13701440
13711441 buffer_info->skb = NULL;
13721442 buffer_info->dma_ptr = dma_ptr;
....@@ -1407,7 +1477,7 @@
14071477 tx->frame_data0 |= TX_DESC_DATA0_IOC_;
14081478 }
14091479 tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail];
1410
- tx_descriptor->data0 = tx->frame_data0;
1480
+ tx_descriptor->data0 = cpu_to_le32(tx->frame_data0);
14111481
14121482 /* move to next descriptor */
14131483 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail);
....@@ -1432,7 +1502,7 @@
14321502 }
14331503
14341504 static int lan743x_tx_frame_add_fragment(struct lan743x_tx *tx,
1435
- const struct skb_frag_struct *fragment,
1505
+ const skb_frag_t *fragment,
14361506 unsigned int frame_length)
14371507 {
14381508 /* called only from within lan743x_tx_xmit_frame
....@@ -1451,7 +1521,7 @@
14511521
14521522 /* wrap up previous descriptor */
14531523 tx_descriptor = &tx->ring_cpu_ptr[tx->frame_tail];
1454
- tx_descriptor->data0 = tx->frame_data0;
1524
+ tx_descriptor->data0 = cpu_to_le32(tx->frame_data0);
14551525
14561526 /* move to next descriptor */
14571527 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail);
....@@ -1477,10 +1547,10 @@
14771547 return -ENOMEM;
14781548 }
14791549
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_;
1550
+ tx_descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(dma_ptr));
1551
+ tx_descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(dma_ptr));
1552
+ tx_descriptor->data3 = cpu_to_le32((frame_length << 16) &
1553
+ TX_DESC_DATA3_FRAME_LENGTH_MSS_MASK_);
14841554
14851555 buffer_info->skb = NULL;
14861556 buffer_info->dma_ptr = dma_ptr;
....@@ -1524,7 +1594,7 @@
15241594 if (ignore_sync)
15251595 buffer_info->flags |= TX_BUFFER_INFO_FLAG_IGNORE_SYNC;
15261596
1527
- tx_descriptor->data0 = tx->frame_data0;
1597
+ tx_descriptor->data0 = cpu_to_le32(tx->frame_data0);
15281598 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail);
15291599 tx->last_tail = tx->frame_tail;
15301600
....@@ -1605,9 +1675,8 @@
16051675 goto finish;
16061676
16071677 for (j = 0; j < nr_frags; j++) {
1608
- const struct skb_frag_struct *frag;
1678
+ const skb_frag_t *frag = &(skb_shinfo(skb)->frags[j]);
16091679
1610
- frag = &(skb_shinfo(skb)->frags[j]);
16111680 if (lan743x_tx_frame_add_fragment(tx, frag, frame_length)) {
16121681 /* upon error no need to call
16131682 * lan743x_tx_frame_end
....@@ -1676,10 +1745,9 @@
16761745 static void lan743x_tx_ring_cleanup(struct lan743x_tx *tx)
16771746 {
16781747 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);
1748
+ dma_free_coherent(&tx->adapter->pdev->dev,
1749
+ sizeof(*tx->head_cpu_ptr), tx->head_cpu_ptr,
1750
+ tx->head_dma_ptr);
16831751 tx->head_cpu_ptr = NULL;
16841752 tx->head_dma_ptr = 0;
16851753 }
....@@ -1687,10 +1755,9 @@
16871755 tx->buffer_info = NULL;
16881756
16891757 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);
1758
+ dma_free_coherent(&tx->adapter->pdev->dev,
1759
+ tx->ring_allocation_size, tx->ring_cpu_ptr,
1760
+ tx->ring_dma_ptr);
16941761 tx->ring_allocation_size = 0;
16951762 tx->ring_cpu_ptr = NULL;
16961763 tx->ring_dma_ptr = 0;
....@@ -1724,8 +1791,8 @@
17241791 sizeof(struct lan743x_tx_descriptor),
17251792 PAGE_SIZE);
17261793 dma_ptr = 0;
1727
- cpu_ptr = pci_zalloc_consistent(tx->adapter->pdev,
1728
- ring_allocation_size, &dma_ptr);
1794
+ cpu_ptr = dma_alloc_coherent(&tx->adapter->pdev->dev,
1795
+ ring_allocation_size, &dma_ptr, GFP_KERNEL);
17291796 if (!cpu_ptr) {
17301797 ret = -ENOMEM;
17311798 goto cleanup;
....@@ -1742,8 +1809,9 @@
17421809 }
17431810 tx->buffer_info = (struct lan743x_tx_buffer_info *)cpu_ptr;
17441811 dma_ptr = 0;
1745
- cpu_ptr = pci_zalloc_consistent(tx->adapter->pdev,
1746
- sizeof(*tx->head_cpu_ptr), &dma_ptr);
1812
+ cpu_ptr = dma_alloc_coherent(&tx->adapter->pdev->dev,
1813
+ sizeof(*tx->head_cpu_ptr), &dma_ptr,
1814
+ GFP_KERNEL);
17471815 if (!cpu_ptr) {
17481816 ret = -ENOMEM;
17491817 goto cleanup;
....@@ -1902,13 +1970,21 @@
19021970 return ((++index) % rx->ring_size);
19031971 }
19041972
1905
-static struct sk_buff *lan743x_rx_allocate_skb(struct lan743x_rx *rx)
1973
+static struct sk_buff *lan743x_rx_allocate_skb(struct lan743x_rx *rx, gfp_t gfp)
19061974 {
19071975 int length = 0;
19081976
19091977 length = (LAN743X_MAX_FRAME_SIZE + ETH_HLEN + 4 + RX_HEAD_PADDING);
19101978 return __netdev_alloc_skb(rx->adapter->netdev,
1911
- length, GFP_ATOMIC | GFP_DMA);
1979
+ length, gfp);
1980
+}
1981
+
1982
+static void lan743x_rx_update_tail(struct lan743x_rx *rx, int index)
1983
+{
1984
+ /* update the tail once per 8 descriptors */
1985
+ if ((index & 7) == 7)
1986
+ lan743x_csr_write(rx->adapter, RX_TAIL(rx->channel_number),
1987
+ index);
19121988 }
19131989
19141990 static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index,
....@@ -1935,12 +2011,13 @@
19352011 }
19362012
19372013 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);
2014
+ descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(buffer_info->dma_ptr));
2015
+ descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(buffer_info->dma_ptr));
19402016 descriptor->data3 = 0;
1941
- descriptor->data0 = (RX_DESC_DATA0_OWN_ |
1942
- (length & RX_DESC_DATA0_BUF_LENGTH_MASK_));
2017
+ descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ |
2018
+ (length & RX_DESC_DATA0_BUF_LENGTH_MASK_)));
19432019 skb_reserve(buffer_info->skb, RX_HEAD_PADDING);
2020
+ lan743x_rx_update_tail(rx, index);
19442021
19452022 return 0;
19462023 }
....@@ -1953,12 +2030,13 @@
19532030 descriptor = &rx->ring_cpu_ptr[index];
19542031 buffer_info = &rx->buffer_info[index];
19552032
1956
- descriptor->data1 = DMA_ADDR_LOW32(buffer_info->dma_ptr);
1957
- descriptor->data2 = DMA_ADDR_HIGH32(buffer_info->dma_ptr);
2033
+ descriptor->data1 = cpu_to_le32(DMA_ADDR_LOW32(buffer_info->dma_ptr));
2034
+ descriptor->data2 = cpu_to_le32(DMA_ADDR_HIGH32(buffer_info->dma_ptr));
19582035 descriptor->data3 = 0;
1959
- descriptor->data0 = (RX_DESC_DATA0_OWN_ |
2036
+ descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ |
19602037 ((buffer_info->buffer_length) &
1961
- RX_DESC_DATA0_BUF_LENGTH_MASK_));
2038
+ RX_DESC_DATA0_BUF_LENGTH_MASK_)));
2039
+ lan743x_rx_update_tail(rx, index);
19622040 }
19632041
19642042 static void lan743x_rx_release_ring_element(struct lan743x_rx *rx, int index)
....@@ -1991,14 +2069,13 @@
19912069 {
19922070 struct skb_shared_hwtstamps *hwtstamps = NULL;
19932071 int result = RX_PROCESS_RESULT_NOTHING_TO_DO;
2072
+ int current_head_index = le32_to_cpu(*rx->head_cpu_ptr);
19942073 struct lan743x_rx_buffer_info *buffer_info;
19952074 struct lan743x_rx_descriptor *descriptor;
1996
- int current_head_index = -1;
19972075 int extension_index = -1;
19982076 int first_index = -1;
19992077 int last_index = -1;
20002078
2001
- current_head_index = *rx->head_cpu_ptr;
20022079 if (current_head_index < 0 || current_head_index >= rx->ring_size)
20032080 goto done;
20042081
....@@ -2007,14 +2084,14 @@
20072084
20082085 if (rx->last_head != current_head_index) {
20092086 descriptor = &rx->ring_cpu_ptr[rx->last_head];
2010
- if (descriptor->data0 & RX_DESC_DATA0_OWN_)
2087
+ if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_OWN_)
20112088 goto done;
20122089
2013
- if (!(descriptor->data0 & RX_DESC_DATA0_FS_))
2090
+ if (!(le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_FS_))
20142091 goto done;
20152092
20162093 first_index = rx->last_head;
2017
- if (descriptor->data0 & RX_DESC_DATA0_LS_) {
2094
+ if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) {
20182095 last_index = rx->last_head;
20192096 } else {
20202097 int index;
....@@ -2022,10 +2099,10 @@
20222099 index = lan743x_rx_next_index(rx, first_index);
20232100 while (index != current_head_index) {
20242101 descriptor = &rx->ring_cpu_ptr[index];
2025
- if (descriptor->data0 & RX_DESC_DATA0_OWN_)
2102
+ if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_OWN_)
20262103 goto done;
20272104
2028
- if (descriptor->data0 & RX_DESC_DATA0_LS_) {
2105
+ if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) {
20292106 last_index = index;
20302107 break;
20312108 }
....@@ -2034,17 +2111,17 @@
20342111 }
20352112 if (last_index >= 0) {
20362113 descriptor = &rx->ring_cpu_ptr[last_index];
2037
- if (descriptor->data0 & RX_DESC_DATA0_EXT_) {
2114
+ if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_EXT_) {
20382115 /* extension is expected to follow */
20392116 int index = lan743x_rx_next_index(rx,
20402117 last_index);
20412118 if (index != current_head_index) {
20422119 descriptor = &rx->ring_cpu_ptr[index];
2043
- if (descriptor->data0 &
2120
+ if (le32_to_cpu(descriptor->data0) &
20442121 RX_DESC_DATA0_OWN_) {
20452122 goto done;
20462123 }
2047
- if (descriptor->data0 &
2124
+ if (le32_to_cpu(descriptor->data0) &
20482125 RX_DESC_DATA0_EXT_) {
20492126 extension_index = index;
20502127 } else {
....@@ -2071,7 +2148,8 @@
20712148 struct sk_buff *new_skb = NULL;
20722149 int packet_length;
20732150
2074
- new_skb = lan743x_rx_allocate_skb(rx);
2151
+ new_skb = lan743x_rx_allocate_skb(rx,
2152
+ GFP_ATOMIC | GFP_DMA);
20752153 if (!new_skb) {
20762154 /* failed to allocate next skb.
20772155 * Memory is very low.
....@@ -2096,7 +2174,7 @@
20962174 }
20972175 buffer_info->skb = NULL;
20982176 packet_length = RX_DESC_DATA0_FRAME_LENGTH_GET_
2099
- (descriptor->data0);
2177
+ (le32_to_cpu(descriptor->data0));
21002178 skb_put(skb, packet_length - 4);
21012179 skb->protocol = eth_type_trans(skb,
21022180 rx->adapter->netdev);
....@@ -2134,8 +2212,8 @@
21342212 descriptor = &rx->ring_cpu_ptr[extension_index];
21352213 buffer_info = &rx->buffer_info[extension_index];
21362214
2137
- ts_sec = descriptor->data1;
2138
- ts_nsec = (descriptor->data2 &
2215
+ ts_sec = le32_to_cpu(descriptor->data1);
2216
+ ts_nsec = (le32_to_cpu(descriptor->data2) &
21392217 RX_DESC_DATA2_TS_NS_MASK_);
21402218 lan743x_rx_reuse_ring_element(rx, extension_index);
21412219 real_last_index = extension_index;
....@@ -2170,6 +2248,7 @@
21702248 {
21712249 struct lan743x_rx *rx = container_of(napi, struct lan743x_rx, napi);
21722250 struct lan743x_adapter *adapter = rx->adapter;
2251
+ int result = RX_PROCESS_RESULT_NOTHING_TO_DO;
21732252 u32 rx_tail_flags = 0;
21742253 int count;
21752254
....@@ -2178,28 +2257,19 @@
21782257 lan743x_csr_write(adapter, DMAC_INT_STS,
21792258 DMAC_INT_BIT_RXFRM_(rx->channel_number));
21802259 }
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) {
2260
+ for (count = 0; count < weight; count++) {
2261
+ result = lan743x_rx_process_packet(rx);
2262
+ if (result == RX_PROCESS_RESULT_NOTHING_TO_DO)
21902263 break;
2191
- } else if (rx_process_result ==
2192
- RX_PROCESS_RESULT_PACKET_DROPPED) {
2193
- continue;
2194
- }
21952264 }
21962265 rx->frame_count += count;
2197
- if (count == weight)
2198
- goto done;
2266
+ if (count == weight || result == RX_PROCESS_RESULT_PACKET_RECEIVED)
2267
+ return weight;
21992268
22002269 if (!napi_complete_done(napi, count))
2201
- goto done;
2270
+ return count;
22022271
2272
+ /* re-arm interrupts, must write to rx tail on some chip variants */
22032273 if (rx->vector_flags & LAN743X_VECTOR_FLAG_VECTOR_ENABLE_AUTO_SET)
22042274 rx_tail_flags |= RX_TAIL_SET_TOP_INT_VEC_EN_;
22052275 if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_SET) {
....@@ -2209,10 +2279,10 @@
22092279 INT_BIT_DMA_RX_(rx->channel_number));
22102280 }
22112281
2212
- /* update RX_TAIL */
2213
- lan743x_csr_write(adapter, RX_TAIL(rx->channel_number),
2214
- rx_tail_flags | rx->last_tail);
2215
-done:
2282
+ if (rx_tail_flags)
2283
+ lan743x_csr_write(adapter, RX_TAIL(rx->channel_number),
2284
+ rx_tail_flags | rx->last_tail);
2285
+
22162286 return count;
22172287 }
22182288
....@@ -2226,10 +2296,9 @@
22262296 }
22272297
22282298 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);
2299
+ dma_free_coherent(&rx->adapter->pdev->dev,
2300
+ sizeof(*rx->head_cpu_ptr), rx->head_cpu_ptr,
2301
+ rx->head_dma_ptr);
22332302 rx->head_cpu_ptr = NULL;
22342303 rx->head_dma_ptr = 0;
22352304 }
....@@ -2238,10 +2307,9 @@
22382307 rx->buffer_info = NULL;
22392308
22402309 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);
2310
+ dma_free_coherent(&rx->adapter->pdev->dev,
2311
+ rx->ring_allocation_size, rx->ring_cpu_ptr,
2312
+ rx->ring_dma_ptr);
22452313 rx->ring_allocation_size = 0;
22462314 rx->ring_cpu_ptr = NULL;
22472315 rx->ring_dma_ptr = 0;
....@@ -2282,8 +2350,8 @@
22822350 sizeof(struct lan743x_rx_descriptor),
22832351 PAGE_SIZE);
22842352 dma_ptr = 0;
2285
- cpu_ptr = pci_zalloc_consistent(rx->adapter->pdev,
2286
- ring_allocation_size, &dma_ptr);
2353
+ cpu_ptr = dma_alloc_coherent(&rx->adapter->pdev->dev,
2354
+ ring_allocation_size, &dma_ptr, GFP_KERNEL);
22872355 if (!cpu_ptr) {
22882356 ret = -ENOMEM;
22892357 goto cleanup;
....@@ -2300,8 +2368,9 @@
23002368 }
23012369 rx->buffer_info = (struct lan743x_rx_buffer_info *)cpu_ptr;
23022370 dma_ptr = 0;
2303
- cpu_ptr = pci_zalloc_consistent(rx->adapter->pdev,
2304
- sizeof(*rx->head_cpu_ptr), &dma_ptr);
2371
+ cpu_ptr = dma_alloc_coherent(&rx->adapter->pdev->dev,
2372
+ sizeof(*rx->head_cpu_ptr), &dma_ptr,
2373
+ GFP_KERNEL);
23052374 if (!cpu_ptr) {
23062375 ret = -ENOMEM;
23072376 goto cleanup;
....@@ -2316,7 +2385,8 @@
23162385
23172386 rx->last_head = 0;
23182387 for (index = 0; index < rx->ring_size; index++) {
2319
- struct sk_buff *new_skb = lan743x_rx_allocate_skb(rx);
2388
+ struct sk_buff *new_skb = lan743x_rx_allocate_skb(rx,
2389
+ GFP_KERNEL);
23202390
23212391 ret = lan743x_rx_init_ring_element(rx, index, new_skb);
23222392 if (ret)
....@@ -2367,7 +2437,7 @@
23672437
23682438 netif_napi_add(adapter->netdev,
23692439 &rx->napi, lan743x_rx_napi_poll,
2370
- rx->ring_size - 1);
2440
+ NAPI_POLL_WEIGHT);
23712441
23722442 lan743x_csr_write(adapter, DMAC_CMD,
23732443 DMAC_CMD_RX_SWR_(rx->channel_number));
....@@ -2774,6 +2844,7 @@
27742844 {
27752845 struct lan743x_adapter *adapter = NULL;
27762846 struct net_device *netdev = NULL;
2847
+ const void *mac_addr;
27772848 int ret = -ENODEV;
27782849
27792850 netdev = devm_alloc_etherdev(&pdev->dev,
....@@ -2789,6 +2860,10 @@
27892860 NETIF_MSG_LINK | NETIF_MSG_IFUP |
27902861 NETIF_MSG_IFDOWN | NETIF_MSG_TX_QUEUED;
27912862 netdev->max_mtu = LAN743X_MAX_FRAME_SIZE;
2863
+
2864
+ mac_addr = of_get_mac_address(pdev->dev.of_node);
2865
+ if (!IS_ERR(mac_addr))
2866
+ ether_addr_copy(adapter->mac_address, mac_addr);
27922867
27932868 ret = lan743x_pci_init(adapter, pdev);
27942869 if (ret)
....@@ -2990,7 +3065,6 @@
29903065 struct pci_dev *pdev = to_pci_dev(dev);
29913066 struct net_device *netdev = pci_get_drvdata(pdev);
29923067 struct lan743x_adapter *adapter = netdev_priv(netdev);
2993
- int ret;
29943068
29953069 lan743x_pcidev_shutdown(pdev);
29963070
....@@ -3003,9 +3077,7 @@
30033077 lan743x_pm_set_wol(adapter);
30043078
30053079 /* Host sets PME_En, put D3hot */
3006
- ret = pci_prepare_to_sleep(pdev);
3007
-
3008
- return 0;
3080
+ return pci_prepare_to_sleep(pdev);;
30093081 }
30103082
30113083 static int lan743x_pm_resume(struct device *dev)
....@@ -3050,6 +3122,8 @@
30503122 { 0, }
30513123 };
30523124
3125
+MODULE_DEVICE_TABLE(pci, lan743x_pcidev_tbl);
3126
+
30533127 static struct pci_driver lan743x_pcidev_driver = {
30543128 .name = DRIVER_NAME,
30553129 .id_table = lan743x_pcidev_tbl,