hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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>
....@@ -793,32 +796,35 @@
793796
794797 netdev = adapter->netdev;
795798
796
- /* setup auto duplex, and speed detection */
799
+ /* disable auto duplex, and speed detection. Phylib does that */
797800 data = lan743x_csr_read(adapter, MAC_CR);
798
- data |= MAC_CR_ADD_ | MAC_CR_ASD_;
801
+ data &= ~(MAC_CR_ADD_ | MAC_CR_ASD_);
799802 data |= MAC_CR_CNTR_RST_;
800803 lan743x_csr_write(adapter, MAC_CR, data);
801804
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;
810814
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);
816824 }
817
-
818
- if (!mac_address_valid)
819
- eth_random_addr(adapter->mac_address);
820825 lan743x_mac_set_address(adapter, adapter->mac_address);
821826 ether_addr_copy(netdev->dev_addr, adapter->mac_address);
827
+
822828 return 0;
823829 }
824830
....@@ -916,8 +922,7 @@
916922 }
917923
918924 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)
921926 {
922927 struct lan743x_phy *phy = &adapter->phy;
923928 u8 cap;
....@@ -941,25 +946,54 @@
941946 {
942947 struct lan743x_adapter *adapter = netdev_priv(netdev);
943948 struct phy_device *phydev = netdev->phydev;
949
+ u32 data;
944950
945951 phy_print_status(phydev);
946952 if (phydev->state == PHY_RUNNING) {
947
- struct ethtool_link_ksettings ksettings;
948953 int remote_advertisement = 0;
949954 int local_advertisement = 0;
950955
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);
957957
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,
961995 remote_advertisement);
962
- lan743x_ptp_update_latency(adapter, ksettings.base.speed);
996
+ lan743x_ptp_update_latency(adapter, phydev->speed);
963997 }
964998 }
965999
....@@ -975,30 +1009,53 @@
9751009 static int lan743x_phy_open(struct lan743x_adapter *adapter)
9761010 {
9771011 struct lan743x_phy *phy = &adapter->phy;
978
- struct phy_device *phydev;
1012
+ struct phy_device *phydev = NULL;
1013
+ struct device_node *phynode;
9791014 struct net_device *netdev;
9801015 int ret = -EIO;
981
- u32 mii_adv;
9821016
9831017 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);
9871019
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
+ }
9931052
9941053 /* MAC doesn't support 1000T Half */
995
- phydev->supported &= ~SUPPORTED_1000baseT_Half;
1054
+ phy_remove_link_mode(phydev, ETHTOOL_LINK_MODE_1000baseT_Half_BIT);
9961055
9971056 /* support both flow controls */
1057
+ phy_support_asym_pause(phydev);
9981058 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);
10021059 phy->fc_autoneg = phydev->autoneg;
10031060
10041061 phy_start(phydev);
....@@ -1217,7 +1274,7 @@
12171274 if (!(buffer_info->flags & TX_BUFFER_INFO_FLAG_ACTIVE))
12181275 goto done;
12191276
1220
- descriptor_type = (descriptor->data0) &
1277
+ descriptor_type = le32_to_cpu(descriptor->data0) &
12211278 TX_DESC_DATA0_DTYPE_MASK_;
12221279 if (descriptor_type == TX_DESC_DATA0_DTYPE_DATA_)
12231280 goto clean_up_data_descriptor;
....@@ -1277,7 +1334,7 @@
12771334
12781335 static void lan743x_tx_release_completed_descriptors(struct lan743x_tx *tx)
12791336 {
1280
- while ((*tx->head_cpu_ptr) != (tx->last_head)) {
1337
+ while (le32_to_cpu(*tx->head_cpu_ptr) != (tx->last_head)) {
12811338 lan743x_tx_release_desc(tx, tx->last_head, false);
12821339 tx->last_head = lan743x_tx_next_index(tx, tx->last_head);
12831340 }
....@@ -1363,10 +1420,10 @@
13631420 if (dma_mapping_error(dev, dma_ptr))
13641421 return -ENOMEM;
13651422
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_);
13701427
13711428 buffer_info->skb = NULL;
13721429 buffer_info->dma_ptr = dma_ptr;
....@@ -1407,7 +1464,7 @@
14071464 tx->frame_data0 |= TX_DESC_DATA0_IOC_;
14081465 }
14091466 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);
14111468
14121469 /* move to next descriptor */
14131470 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail);
....@@ -1432,7 +1489,7 @@
14321489 }
14331490
14341491 static int lan743x_tx_frame_add_fragment(struct lan743x_tx *tx,
1435
- const struct skb_frag_struct *fragment,
1492
+ const skb_frag_t *fragment,
14361493 unsigned int frame_length)
14371494 {
14381495 /* called only from within lan743x_tx_xmit_frame
....@@ -1451,7 +1508,7 @@
14511508
14521509 /* wrap up previous descriptor */
14531510 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);
14551512
14561513 /* move to next descriptor */
14571514 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail);
....@@ -1477,10 +1534,10 @@
14771534 return -ENOMEM;
14781535 }
14791536
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_);
14841541
14851542 buffer_info->skb = NULL;
14861543 buffer_info->dma_ptr = dma_ptr;
....@@ -1524,7 +1581,7 @@
15241581 if (ignore_sync)
15251582 buffer_info->flags |= TX_BUFFER_INFO_FLAG_IGNORE_SYNC;
15261583
1527
- tx_descriptor->data0 = tx->frame_data0;
1584
+ tx_descriptor->data0 = cpu_to_le32(tx->frame_data0);
15281585 tx->frame_tail = lan743x_tx_next_index(tx, tx->frame_tail);
15291586 tx->last_tail = tx->frame_tail;
15301587
....@@ -1605,9 +1662,8 @@
16051662 goto finish;
16061663
16071664 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]);
16091666
1610
- frag = &(skb_shinfo(skb)->frags[j]);
16111667 if (lan743x_tx_frame_add_fragment(tx, frag, frame_length)) {
16121668 /* upon error no need to call
16131669 * lan743x_tx_frame_end
....@@ -1676,10 +1732,9 @@
16761732 static void lan743x_tx_ring_cleanup(struct lan743x_tx *tx)
16771733 {
16781734 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);
16831738 tx->head_cpu_ptr = NULL;
16841739 tx->head_dma_ptr = 0;
16851740 }
....@@ -1687,10 +1742,9 @@
16871742 tx->buffer_info = NULL;
16881743
16891744 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);
16941748 tx->ring_allocation_size = 0;
16951749 tx->ring_cpu_ptr = NULL;
16961750 tx->ring_dma_ptr = 0;
....@@ -1724,8 +1778,8 @@
17241778 sizeof(struct lan743x_tx_descriptor),
17251779 PAGE_SIZE);
17261780 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);
17291783 if (!cpu_ptr) {
17301784 ret = -ENOMEM;
17311785 goto cleanup;
....@@ -1742,8 +1796,9 @@
17421796 }
17431797 tx->buffer_info = (struct lan743x_tx_buffer_info *)cpu_ptr;
17441798 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);
17471802 if (!cpu_ptr) {
17481803 ret = -ENOMEM;
17491804 goto cleanup;
....@@ -1902,13 +1957,21 @@
19021957 return ((++index) % rx->ring_size);
19031958 }
19041959
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)
19061961 {
19071962 int length = 0;
19081963
19091964 length = (LAN743X_MAX_FRAME_SIZE + ETH_HLEN + 4 + RX_HEAD_PADDING);
19101965 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);
19121975 }
19131976
19141977 static int lan743x_rx_init_ring_element(struct lan743x_rx *rx, int index,
....@@ -1935,12 +1998,13 @@
19351998 }
19361999
19372000 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));
19402003 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_)));
19432006 skb_reserve(buffer_info->skb, RX_HEAD_PADDING);
2007
+ lan743x_rx_update_tail(rx, index);
19442008
19452009 return 0;
19462010 }
....@@ -1953,12 +2017,13 @@
19532017 descriptor = &rx->ring_cpu_ptr[index];
19542018 buffer_info = &rx->buffer_info[index];
19552019
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));
19582022 descriptor->data3 = 0;
1959
- descriptor->data0 = (RX_DESC_DATA0_OWN_ |
2023
+ descriptor->data0 = cpu_to_le32((RX_DESC_DATA0_OWN_ |
19602024 ((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);
19622027 }
19632028
19642029 static void lan743x_rx_release_ring_element(struct lan743x_rx *rx, int index)
....@@ -1991,14 +2056,13 @@
19912056 {
19922057 struct skb_shared_hwtstamps *hwtstamps = NULL;
19932058 int result = RX_PROCESS_RESULT_NOTHING_TO_DO;
2059
+ int current_head_index = le32_to_cpu(*rx->head_cpu_ptr);
19942060 struct lan743x_rx_buffer_info *buffer_info;
19952061 struct lan743x_rx_descriptor *descriptor;
1996
- int current_head_index = -1;
19972062 int extension_index = -1;
19982063 int first_index = -1;
19992064 int last_index = -1;
20002065
2001
- current_head_index = *rx->head_cpu_ptr;
20022066 if (current_head_index < 0 || current_head_index >= rx->ring_size)
20032067 goto done;
20042068
....@@ -2007,14 +2071,14 @@
20072071
20082072 if (rx->last_head != current_head_index) {
20092073 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_)
20112075 goto done;
20122076
2013
- if (!(descriptor->data0 & RX_DESC_DATA0_FS_))
2077
+ if (!(le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_FS_))
20142078 goto done;
20152079
20162080 first_index = rx->last_head;
2017
- if (descriptor->data0 & RX_DESC_DATA0_LS_) {
2081
+ if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) {
20182082 last_index = rx->last_head;
20192083 } else {
20202084 int index;
....@@ -2022,10 +2086,10 @@
20222086 index = lan743x_rx_next_index(rx, first_index);
20232087 while (index != current_head_index) {
20242088 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_)
20262090 goto done;
20272091
2028
- if (descriptor->data0 & RX_DESC_DATA0_LS_) {
2092
+ if (le32_to_cpu(descriptor->data0) & RX_DESC_DATA0_LS_) {
20292093 last_index = index;
20302094 break;
20312095 }
....@@ -2034,17 +2098,17 @@
20342098 }
20352099 if (last_index >= 0) {
20362100 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_) {
20382102 /* extension is expected to follow */
20392103 int index = lan743x_rx_next_index(rx,
20402104 last_index);
20412105 if (index != current_head_index) {
20422106 descriptor = &rx->ring_cpu_ptr[index];
2043
- if (descriptor->data0 &
2107
+ if (le32_to_cpu(descriptor->data0) &
20442108 RX_DESC_DATA0_OWN_) {
20452109 goto done;
20462110 }
2047
- if (descriptor->data0 &
2111
+ if (le32_to_cpu(descriptor->data0) &
20482112 RX_DESC_DATA0_EXT_) {
20492113 extension_index = index;
20502114 } else {
....@@ -2071,7 +2135,8 @@
20712135 struct sk_buff *new_skb = NULL;
20722136 int packet_length;
20732137
2074
- new_skb = lan743x_rx_allocate_skb(rx);
2138
+ new_skb = lan743x_rx_allocate_skb(rx,
2139
+ GFP_ATOMIC | GFP_DMA);
20752140 if (!new_skb) {
20762141 /* failed to allocate next skb.
20772142 * Memory is very low.
....@@ -2096,7 +2161,7 @@
20962161 }
20972162 buffer_info->skb = NULL;
20982163 packet_length = RX_DESC_DATA0_FRAME_LENGTH_GET_
2099
- (descriptor->data0);
2164
+ (le32_to_cpu(descriptor->data0));
21002165 skb_put(skb, packet_length - 4);
21012166 skb->protocol = eth_type_trans(skb,
21022167 rx->adapter->netdev);
....@@ -2134,8 +2199,8 @@
21342199 descriptor = &rx->ring_cpu_ptr[extension_index];
21352200 buffer_info = &rx->buffer_info[extension_index];
21362201
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) &
21392204 RX_DESC_DATA2_TS_NS_MASK_);
21402205 lan743x_rx_reuse_ring_element(rx, extension_index);
21412206 real_last_index = extension_index;
....@@ -2170,6 +2235,7 @@
21702235 {
21712236 struct lan743x_rx *rx = container_of(napi, struct lan743x_rx, napi);
21722237 struct lan743x_adapter *adapter = rx->adapter;
2238
+ int result = RX_PROCESS_RESULT_NOTHING_TO_DO;
21732239 u32 rx_tail_flags = 0;
21742240 int count;
21752241
....@@ -2178,28 +2244,19 @@
21782244 lan743x_csr_write(adapter, DMAC_INT_STS,
21792245 DMAC_INT_BIT_RXFRM_(rx->channel_number));
21802246 }
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)
21902250 break;
2191
- } else if (rx_process_result ==
2192
- RX_PROCESS_RESULT_PACKET_DROPPED) {
2193
- continue;
2194
- }
21952251 }
21962252 rx->frame_count += count;
2197
- if (count == weight)
2198
- goto done;
2253
+ if (count == weight || result == RX_PROCESS_RESULT_PACKET_RECEIVED)
2254
+ return weight;
21992255
22002256 if (!napi_complete_done(napi, count))
2201
- goto done;
2257
+ return count;
22022258
2259
+ /* re-arm interrupts, must write to rx tail on some chip variants */
22032260 if (rx->vector_flags & LAN743X_VECTOR_FLAG_VECTOR_ENABLE_AUTO_SET)
22042261 rx_tail_flags |= RX_TAIL_SET_TOP_INT_VEC_EN_;
22052262 if (rx->vector_flags & LAN743X_VECTOR_FLAG_SOURCE_ENABLE_AUTO_SET) {
....@@ -2209,10 +2266,10 @@
22092266 INT_BIT_DMA_RX_(rx->channel_number));
22102267 }
22112268
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
+
22162273 return count;
22172274 }
22182275
....@@ -2226,10 +2283,9 @@
22262283 }
22272284
22282285 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);
22332289 rx->head_cpu_ptr = NULL;
22342290 rx->head_dma_ptr = 0;
22352291 }
....@@ -2238,10 +2294,9 @@
22382294 rx->buffer_info = NULL;
22392295
22402296 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);
22452300 rx->ring_allocation_size = 0;
22462301 rx->ring_cpu_ptr = NULL;
22472302 rx->ring_dma_ptr = 0;
....@@ -2282,8 +2337,8 @@
22822337 sizeof(struct lan743x_rx_descriptor),
22832338 PAGE_SIZE);
22842339 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);
22872342 if (!cpu_ptr) {
22882343 ret = -ENOMEM;
22892344 goto cleanup;
....@@ -2300,8 +2355,9 @@
23002355 }
23012356 rx->buffer_info = (struct lan743x_rx_buffer_info *)cpu_ptr;
23022357 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);
23052361 if (!cpu_ptr) {
23062362 ret = -ENOMEM;
23072363 goto cleanup;
....@@ -2316,7 +2372,8 @@
23162372
23172373 rx->last_head = 0;
23182374 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);
23202377
23212378 ret = lan743x_rx_init_ring_element(rx, index, new_skb);
23222379 if (ret)
....@@ -2367,7 +2424,7 @@
23672424
23682425 netif_napi_add(adapter->netdev,
23692426 &rx->napi, lan743x_rx_napi_poll,
2370
- rx->ring_size - 1);
2427
+ NAPI_POLL_WEIGHT);
23712428
23722429 lan743x_csr_write(adapter, DMAC_CMD,
23732430 DMAC_CMD_RX_SWR_(rx->channel_number));
....@@ -2774,6 +2831,7 @@
27742831 {
27752832 struct lan743x_adapter *adapter = NULL;
27762833 struct net_device *netdev = NULL;
2834
+ const void *mac_addr;
27772835 int ret = -ENODEV;
27782836
27792837 netdev = devm_alloc_etherdev(&pdev->dev,
....@@ -2789,6 +2847,10 @@
27892847 NETIF_MSG_LINK | NETIF_MSG_IFUP |
27902848 NETIF_MSG_IFDOWN | NETIF_MSG_TX_QUEUED;
27912849 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);
27922854
27932855 ret = lan743x_pci_init(adapter, pdev);
27942856 if (ret)
....@@ -2990,7 +3052,6 @@
29903052 struct pci_dev *pdev = to_pci_dev(dev);
29913053 struct net_device *netdev = pci_get_drvdata(pdev);
29923054 struct lan743x_adapter *adapter = netdev_priv(netdev);
2993
- int ret;
29943055
29953056 lan743x_pcidev_shutdown(pdev);
29963057
....@@ -3003,9 +3064,7 @@
30033064 lan743x_pm_set_wol(adapter);
30043065
30053066 /* Host sets PME_En, put D3hot */
3006
- ret = pci_prepare_to_sleep(pdev);
3007
-
3008
- return 0;
3067
+ return pci_prepare_to_sleep(pdev);;
30093068 }
30103069
30113070 static int lan743x_pm_resume(struct device *dev)
....@@ -3050,6 +3109,8 @@
30503109 { 0, }
30513110 };
30523111
3112
+MODULE_DEVICE_TABLE(pci, lan743x_pcidev_tbl);
3113
+
30533114 static struct pci_driver lan743x_pcidev_driver = {
30543115 .name = DRIVER_NAME,
30553116 .id_table = lan743x_pcidev_tbl,