18691632fSRavi Kumar /* SPDX-License-Identifier: BSD-3-Clause 28691632fSRavi Kumar * Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved. 38691632fSRavi Kumar * Copyright(c) 2018 Synopsys, Inc. All rights reserved. 48691632fSRavi Kumar */ 58691632fSRavi Kumar 69e890103SRavi Kumar #include "axgbe_rxtx.h" 78691632fSRavi Kumar #include "axgbe_ethdev.h" 8572890efSRavi Kumar #include "axgbe_common.h" 9572890efSRavi Kumar #include "axgbe_phy.h" 10df4867cdSChandu Babu N #include "axgbe_regs.h" 11e0444948SSelwin Sebastian #include "rte_time.h" 128691632fSRavi Kumar 13b0db927bSChandubabu Namburu #include "eal_filesystem.h" 14b0db927bSChandubabu Namburu 15*4feb9aa0SJesna K E #include <rte_vect.h> 16*4feb9aa0SJesna K E 17a27ff9caSSelwin Sebastian #ifdef RTE_ARCH_X86 18a27ff9caSSelwin Sebastian #include <cpuid.h> 19a27ff9caSSelwin Sebastian #else 20a27ff9caSSelwin Sebastian #define __cpuid(n, a, b, c, d) 21a27ff9caSSelwin Sebastian #endif 22a27ff9caSSelwin Sebastian 238691632fSRavi Kumar static int eth_axgbe_dev_init(struct rte_eth_dev *eth_dev); 247c4158a5SRavi Kumar static int axgbe_dev_configure(struct rte_eth_dev *dev); 257c4158a5SRavi Kumar static int axgbe_dev_start(struct rte_eth_dev *dev); 2662024eb8SIvan Ilchenko static int axgbe_dev_stop(struct rte_eth_dev *dev); 27456ff159SRavi Kumar static void axgbe_dev_interrupt_handler(void *param); 28b142387bSThomas Monjalon static int axgbe_dev_close(struct rte_eth_dev *dev); 29bf403cfeSSelwin Sebastian static int axgbe_dev_reset(struct rte_eth_dev *dev); 309039c812SAndrew Rybchenko static int axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev); 319039c812SAndrew Rybchenko static int axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev); 32ca041cd4SIvan Ilchenko static int axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev); 33ca041cd4SIvan Ilchenko static int axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev); 3449a5e622SChandu Babu N static int axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, 3549a5e622SChandu Babu N struct rte_ether_addr *mac_addr); 3649a5e622SChandu Babu N static int axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, 3749a5e622SChandu Babu N struct rte_ether_addr *mac_addr, 3849a5e622SChandu Babu N uint32_t index, 3949a5e622SChandu Babu N uint32_t vmdq); 4049a5e622SChandu Babu N static void axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index); 4149a5e622SChandu Babu N static int axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev, 4249a5e622SChandu Babu N struct rte_ether_addr *mc_addr_set, 4349a5e622SChandu Babu N uint32_t nb_mc_addr); 44e01d9b2eSChandu Babu N static int axgbe_dev_uc_hash_table_set(struct rte_eth_dev *dev, 45e01d9b2eSChandu Babu N struct rte_ether_addr *mac_addr, 46e01d9b2eSChandu Babu N uint8_t add); 47e01d9b2eSChandu Babu N static int axgbe_dev_uc_all_hash_table_set(struct rte_eth_dev *dev, 48e01d9b2eSChandu Babu N uint8_t add); 4944d45ffeSRavi Kumar static int axgbe_dev_link_update(struct rte_eth_dev *dev, 5044d45ffeSRavi Kumar int wait_to_complete); 51df4867cdSChandu Babu N static int axgbe_dev_get_regs(struct rte_eth_dev *dev, 52df4867cdSChandu Babu N struct rte_dev_reg_info *regs); 533e730511SRavi Kumar static int axgbe_dev_stats_get(struct rte_eth_dev *dev, 543e730511SRavi Kumar struct rte_eth_stats *stats); 559970a9adSIgor Romanov static int axgbe_dev_stats_reset(struct rte_eth_dev *dev); 569d1ef6b2SChandu Babu N static int axgbe_dev_xstats_get(struct rte_eth_dev *dev, 579d1ef6b2SChandu Babu N struct rte_eth_xstat *stats, 589d1ef6b2SChandu Babu N unsigned int n); 599d1ef6b2SChandu Babu N static int 609d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(struct rte_eth_dev *dev, 619d1ef6b2SChandu Babu N struct rte_eth_xstat_name *xstats_names, 629d1ef6b2SChandu Babu N unsigned int size); 639d1ef6b2SChandu Babu N static int 649d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, 659d1ef6b2SChandu Babu N const uint64_t *ids, 669d1ef6b2SChandu Babu N uint64_t *values, 679d1ef6b2SChandu Babu N unsigned int n); 689d1ef6b2SChandu Babu N static int 699d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, 709d1ef6b2SChandu Babu N const uint64_t *ids, 718c9f976fSAndrew Rybchenko struct rte_eth_xstat_name *xstats_names, 729d1ef6b2SChandu Babu N unsigned int size); 739d1ef6b2SChandu Babu N static int axgbe_dev_xstats_reset(struct rte_eth_dev *dev); 7476d7664dSChandu Babu N static int axgbe_dev_rss_reta_update(struct rte_eth_dev *dev, 7576d7664dSChandu Babu N struct rte_eth_rss_reta_entry64 *reta_conf, 7676d7664dSChandu Babu N uint16_t reta_size); 7776d7664dSChandu Babu N static int axgbe_dev_rss_reta_query(struct rte_eth_dev *dev, 7876d7664dSChandu Babu N struct rte_eth_rss_reta_entry64 *reta_conf, 7976d7664dSChandu Babu N uint16_t reta_size); 8076d7664dSChandu Babu N static int axgbe_dev_rss_hash_update(struct rte_eth_dev *dev, 8176d7664dSChandu Babu N struct rte_eth_rss_conf *rss_conf); 8276d7664dSChandu Babu N static int axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev, 8376d7664dSChandu Babu N struct rte_eth_rss_conf *rss_conf); 84bdad90d1SIvan Ilchenko static int axgbe_dev_info_get(struct rte_eth_dev *dev, 859e890103SRavi Kumar struct rte_eth_dev_info *dev_info); 86cf97f33eSAmaranath Somalapuram static int axgbe_flow_ctrl_get(struct rte_eth_dev *dev, 87cf97f33eSAmaranath Somalapuram struct rte_eth_fc_conf *fc_conf); 88cf97f33eSAmaranath Somalapuram static int axgbe_flow_ctrl_set(struct rte_eth_dev *dev, 89cf97f33eSAmaranath Somalapuram struct rte_eth_fc_conf *fc_conf); 90e0543d4eSAmaranath Somalapuram static int axgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, 91e0543d4eSAmaranath Somalapuram struct rte_eth_pfc_conf *pfc_conf); 927aed95c9SAmaranath Somalapuram static void axgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 937aed95c9SAmaranath Somalapuram struct rte_eth_rxq_info *qinfo); 947aed95c9SAmaranath Somalapuram static void axgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 957aed95c9SAmaranath Somalapuram struct rte_eth_txq_info *qinfo); 96410cf087SAmaranath Somalapuram const uint32_t *axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev); 97b58d8781SGirish Nandibasappa static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu); 988691632fSRavi Kumar 99e0444948SSelwin Sebastian static int 100e0444948SSelwin Sebastian axgbe_timesync_enable(struct rte_eth_dev *dev); 101e0444948SSelwin Sebastian static int 102e0444948SSelwin Sebastian axgbe_timesync_disable(struct rte_eth_dev *dev); 103e0444948SSelwin Sebastian static int 104e0444948SSelwin Sebastian axgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev, 105e0444948SSelwin Sebastian struct timespec *timestamp, uint32_t flags); 106e0444948SSelwin Sebastian static int 107e0444948SSelwin Sebastian axgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev, 108e0444948SSelwin Sebastian struct timespec *timestamp); 109e0444948SSelwin Sebastian static int 110e0444948SSelwin Sebastian axgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta); 111e0444948SSelwin Sebastian static int 112e0444948SSelwin Sebastian axgbe_timesync_read_time(struct rte_eth_dev *dev, 113e0444948SSelwin Sebastian struct timespec *timestamp); 114e0444948SSelwin Sebastian static int 115e0444948SSelwin Sebastian axgbe_timesync_write_time(struct rte_eth_dev *dev, 116e0444948SSelwin Sebastian const struct timespec *timestamp); 117e0444948SSelwin Sebastian static void 118e0444948SSelwin Sebastian axgbe_set_tstamp_time(struct axgbe_port *pdata, unsigned int sec, 119e0444948SSelwin Sebastian unsigned int nsec); 120e0444948SSelwin Sebastian static void 121e0444948SSelwin Sebastian axgbe_update_tstamp_addend(struct axgbe_port *pdata, 122e0444948SSelwin Sebastian unsigned int addend); 12386578516SGirish Nandibasappa static int 12486578516SGirish Nandibasappa axgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on); 12586578516SGirish Nandibasappa static int axgbe_vlan_tpid_set(struct rte_eth_dev *dev, 12686578516SGirish Nandibasappa enum rte_vlan_type vlan_type, uint16_t tpid); 12786578516SGirish Nandibasappa static int axgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask); 128e0444948SSelwin Sebastian 1299d1ef6b2SChandu Babu N struct axgbe_xstats { 1309d1ef6b2SChandu Babu N char name[RTE_ETH_XSTATS_NAME_SIZE]; 1319d1ef6b2SChandu Babu N int offset; 1329d1ef6b2SChandu Babu N }; 1339d1ef6b2SChandu Babu N 1349d1ef6b2SChandu Babu N #define AXGMAC_MMC_STAT(_string, _var) \ 1359d1ef6b2SChandu Babu N { _string, \ 1369d1ef6b2SChandu Babu N offsetof(struct axgbe_mmc_stats, _var), \ 1379d1ef6b2SChandu Babu N } 1389d1ef6b2SChandu Babu N 1399d1ef6b2SChandu Babu N static const struct axgbe_xstats axgbe_xstats_strings[] = { 1409d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_bytes", txoctetcount_gb), 1419d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_packets", txframecount_gb), 1429d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb), 1439d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb), 1449d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb), 1459d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g), 1469d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb), 1479d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb), 1489d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb), 1499d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb), 1509d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb), 1519d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb), 1529d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror), 1539d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_pause_frames", txpauseframes), 1549d1ef6b2SChandu Babu N 1559d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb), 1569d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_packets", rxframecount_gb), 1579d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g), 1589d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g), 1599d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g), 1609d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb), 1619d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb), 1629d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb), 1639d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb), 1649d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb), 1659d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb), 1669d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb), 1679d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g), 1689d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g), 1699d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_crc_errors", rxcrcerror), 1709d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror), 1719d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror), 1729d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_length_errors", rxlengtherror), 1739d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype), 1749d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow), 1759d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror), 1769d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_pause_frames", rxpauseframes), 1779d1ef6b2SChandu Babu N }; 1789d1ef6b2SChandu Babu N 1799d1ef6b2SChandu Babu N #define AXGBE_XSTATS_COUNT ARRAY_SIZE(axgbe_xstats_strings) 1809d1ef6b2SChandu Babu N 1818691632fSRavi Kumar /* The set of PCI devices this driver supports */ 1828691632fSRavi Kumar #define AMD_PCI_VENDOR_ID 0x1022 183a27ff9caSSelwin Sebastian 184a27ff9caSSelwin Sebastian #define Fam17h 0x17 185a27ff9caSSelwin Sebastian #define Fam19h 0x19 186a27ff9caSSelwin Sebastian 187a27ff9caSSelwin Sebastian #define CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 188a27ff9caSSelwin Sebastian #define CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 189a27ff9caSSelwin Sebastian #define CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 190a27ff9caSSelwin Sebastian 1918691632fSRavi Kumar #define AMD_PCI_AXGBE_DEVICE_V2A 0x1458 1928691632fSRavi Kumar #define AMD_PCI_AXGBE_DEVICE_V2B 0x1459 1938691632fSRavi Kumar 1948691632fSRavi Kumar static const struct rte_pci_id pci_id_axgbe_map[] = { 1958691632fSRavi Kumar {RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_AXGBE_DEVICE_V2A)}, 1968691632fSRavi Kumar {RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_AXGBE_DEVICE_V2B)}, 1978691632fSRavi Kumar { .vendor_id = 0, }, 1988691632fSRavi Kumar }; 1998691632fSRavi Kumar 200572890efSRavi Kumar static struct axgbe_version_data axgbe_v2a = { 2014ac7516bSRavi Kumar .init_function_ptrs_phy_impl = axgbe_init_function_ptrs_phy_v2, 202572890efSRavi Kumar .xpcs_access = AXGBE_XPCS_ACCESS_V2, 203572890efSRavi Kumar .mmc_64bit = 1, 204572890efSRavi Kumar .tx_max_fifo_size = 229376, 205572890efSRavi Kumar .rx_max_fifo_size = 229376, 206572890efSRavi Kumar .tx_tstamp_workaround = 1, 207572890efSRavi Kumar .ecc_support = 1, 208572890efSRavi Kumar .i2c_support = 1, 20900072056SRavi Kumar .an_cdr_workaround = 1, 210572890efSRavi Kumar }; 211572890efSRavi Kumar 212572890efSRavi Kumar static struct axgbe_version_data axgbe_v2b = { 2134ac7516bSRavi Kumar .init_function_ptrs_phy_impl = axgbe_init_function_ptrs_phy_v2, 214572890efSRavi Kumar .xpcs_access = AXGBE_XPCS_ACCESS_V2, 215572890efSRavi Kumar .mmc_64bit = 1, 216572890efSRavi Kumar .tx_max_fifo_size = 65536, 217572890efSRavi Kumar .rx_max_fifo_size = 65536, 218572890efSRavi Kumar .tx_tstamp_workaround = 1, 219572890efSRavi Kumar .ecc_support = 1, 220572890efSRavi Kumar .i2c_support = 1, 22100072056SRavi Kumar .an_cdr_workaround = 1, 222572890efSRavi Kumar }; 223572890efSRavi Kumar 2249e890103SRavi Kumar static const struct rte_eth_desc_lim rx_desc_lim = { 2259e890103SRavi Kumar .nb_max = AXGBE_MAX_RING_DESC, 2269e890103SRavi Kumar .nb_min = AXGBE_MIN_RING_DESC, 2279e890103SRavi Kumar .nb_align = 8, 2289e890103SRavi Kumar }; 2299e890103SRavi Kumar 2309e890103SRavi Kumar static const struct rte_eth_desc_lim tx_desc_lim = { 2319e890103SRavi Kumar .nb_max = AXGBE_MAX_RING_DESC, 2329e890103SRavi Kumar .nb_min = AXGBE_MIN_RING_DESC, 2339e890103SRavi Kumar .nb_align = 8, 2349e890103SRavi Kumar }; 2359e890103SRavi Kumar 2369e890103SRavi Kumar static const struct eth_dev_ops axgbe_eth_dev_ops = { 2377c4158a5SRavi Kumar .dev_configure = axgbe_dev_configure, 2387c4158a5SRavi Kumar .dev_start = axgbe_dev_start, 2397c4158a5SRavi Kumar .dev_stop = axgbe_dev_stop, 2409e890103SRavi Kumar .dev_close = axgbe_dev_close, 241bf403cfeSSelwin Sebastian .dev_reset = axgbe_dev_reset, 242fa3e0440SRavi Kumar .promiscuous_enable = axgbe_dev_promiscuous_enable, 243fa3e0440SRavi Kumar .promiscuous_disable = axgbe_dev_promiscuous_disable, 244fa3e0440SRavi Kumar .allmulticast_enable = axgbe_dev_allmulticast_enable, 245fa3e0440SRavi Kumar .allmulticast_disable = axgbe_dev_allmulticast_disable, 24649a5e622SChandu Babu N .mac_addr_set = axgbe_dev_mac_addr_set, 24749a5e622SChandu Babu N .mac_addr_add = axgbe_dev_mac_addr_add, 24849a5e622SChandu Babu N .mac_addr_remove = axgbe_dev_mac_addr_remove, 24949a5e622SChandu Babu N .set_mc_addr_list = axgbe_dev_set_mc_addr_list, 250e01d9b2eSChandu Babu N .uc_hash_table_set = axgbe_dev_uc_hash_table_set, 251e01d9b2eSChandu Babu N .uc_all_hash_table_set = axgbe_dev_uc_all_hash_table_set, 25244d45ffeSRavi Kumar .link_update = axgbe_dev_link_update, 253df4867cdSChandu Babu N .get_reg = axgbe_dev_get_regs, 2543e730511SRavi Kumar .stats_get = axgbe_dev_stats_get, 2553e730511SRavi Kumar .stats_reset = axgbe_dev_stats_reset, 2569d1ef6b2SChandu Babu N .xstats_get = axgbe_dev_xstats_get, 2579d1ef6b2SChandu Babu N .xstats_reset = axgbe_dev_xstats_reset, 2589d1ef6b2SChandu Babu N .xstats_get_names = axgbe_dev_xstats_get_names, 2599d1ef6b2SChandu Babu N .xstats_get_names_by_id = axgbe_dev_xstats_get_names_by_id, 2609d1ef6b2SChandu Babu N .xstats_get_by_id = axgbe_dev_xstats_get_by_id, 26176d7664dSChandu Babu N .reta_update = axgbe_dev_rss_reta_update, 26276d7664dSChandu Babu N .reta_query = axgbe_dev_rss_reta_query, 26376d7664dSChandu Babu N .rss_hash_update = axgbe_dev_rss_hash_update, 26476d7664dSChandu Babu N .rss_hash_conf_get = axgbe_dev_rss_hash_conf_get, 2659e890103SRavi Kumar .dev_infos_get = axgbe_dev_info_get, 2669e890103SRavi Kumar .rx_queue_setup = axgbe_dev_rx_queue_setup, 2679e890103SRavi Kumar .rx_queue_release = axgbe_dev_rx_queue_release, 2689e890103SRavi Kumar .tx_queue_setup = axgbe_dev_tx_queue_setup, 2699e890103SRavi Kumar .tx_queue_release = axgbe_dev_tx_queue_release, 270cf97f33eSAmaranath Somalapuram .flow_ctrl_get = axgbe_flow_ctrl_get, 271cf97f33eSAmaranath Somalapuram .flow_ctrl_set = axgbe_flow_ctrl_set, 272e0543d4eSAmaranath Somalapuram .priority_flow_ctrl_set = axgbe_priority_flow_ctrl_set, 2737aed95c9SAmaranath Somalapuram .rxq_info_get = axgbe_rxq_info_get, 2747aed95c9SAmaranath Somalapuram .txq_info_get = axgbe_txq_info_get, 275410cf087SAmaranath Somalapuram .dev_supported_ptypes_get = axgbe_dev_supported_ptypes_get, 276b58d8781SGirish Nandibasappa .mtu_set = axgb_mtu_set, 27786578516SGirish Nandibasappa .vlan_filter_set = axgbe_vlan_filter_set, 27886578516SGirish Nandibasappa .vlan_tpid_set = axgbe_vlan_tpid_set, 27986578516SGirish Nandibasappa .vlan_offload_set = axgbe_vlan_offload_set, 280e0444948SSelwin Sebastian .timesync_enable = axgbe_timesync_enable, 281e0444948SSelwin Sebastian .timesync_disable = axgbe_timesync_disable, 282e0444948SSelwin Sebastian .timesync_read_rx_timestamp = axgbe_timesync_read_rx_timestamp, 283e0444948SSelwin Sebastian .timesync_read_tx_timestamp = axgbe_timesync_read_tx_timestamp, 284e0444948SSelwin Sebastian .timesync_adjust_time = axgbe_timesync_adjust_time, 285e0444948SSelwin Sebastian .timesync_read_time = axgbe_timesync_read_time, 286e0444948SSelwin Sebastian .timesync_write_time = axgbe_timesync_write_time, 287ff70acdfSSelwin Sebastian .fw_version_get = axgbe_dev_fw_version_get, 2889e890103SRavi Kumar }; 2899e890103SRavi Kumar 2907c4158a5SRavi Kumar static int axgbe_phy_reset(struct axgbe_port *pdata) 2917c4158a5SRavi Kumar { 2927c4158a5SRavi Kumar pdata->phy_link = -1; 2937c4158a5SRavi Kumar pdata->phy_speed = SPEED_UNKNOWN; 2947c4158a5SRavi Kumar return pdata->phy_if.phy_reset(pdata); 2957c4158a5SRavi Kumar } 2967c4158a5SRavi Kumar 297456ff159SRavi Kumar /* 298456ff159SRavi Kumar * Interrupt handler triggered by NIC for handling 299456ff159SRavi Kumar * specific interrupt. 300456ff159SRavi Kumar * 301456ff159SRavi Kumar * @param handle 302456ff159SRavi Kumar * Pointer to interrupt handle. 303456ff159SRavi Kumar * @param param 3047be78d02SJosh Soref * The address of parameter (struct rte_eth_dev *) registered before. 305456ff159SRavi Kumar * 306456ff159SRavi Kumar * @return 307456ff159SRavi Kumar * void 308456ff159SRavi Kumar */ 309456ff159SRavi Kumar static void 310456ff159SRavi Kumar axgbe_dev_interrupt_handler(void *param) 311456ff159SRavi Kumar { 312456ff159SRavi Kumar struct rte_eth_dev *dev = (struct rte_eth_dev *)param; 313456ff159SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 3148590b93dSRavi Kumar unsigned int dma_isr, dma_ch_isr; 315456ff159SRavi Kumar 316456ff159SRavi Kumar pdata->phy_if.an_isr(pdata); 3178590b93dSRavi Kumar /*DMA related interrupts*/ 3188590b93dSRavi Kumar dma_isr = AXGMAC_IOREAD(pdata, DMA_ISR); 3194216cdc0SChandu Babu N PMD_DRV_LOG(DEBUG, "DMA_ISR=%#010x\n", dma_isr); 3208590b93dSRavi Kumar if (dma_isr) { 3218590b93dSRavi Kumar if (dma_isr & 1) { 3228590b93dSRavi Kumar dma_ch_isr = 3238590b93dSRavi Kumar AXGMAC_DMA_IOREAD((struct axgbe_rx_queue *) 3248590b93dSRavi Kumar pdata->rx_queues[0], 3258590b93dSRavi Kumar DMA_CH_SR); 3264216cdc0SChandu Babu N PMD_DRV_LOG(DEBUG, "DMA_CH0_ISR=%#010x\n", dma_ch_isr); 3278590b93dSRavi Kumar AXGMAC_DMA_IOWRITE((struct axgbe_rx_queue *) 3288590b93dSRavi Kumar pdata->rx_queues[0], 3298590b93dSRavi Kumar DMA_CH_SR, dma_ch_isr); 3308590b93dSRavi Kumar } 3318590b93dSRavi Kumar } 3326bee9d5fSNithin Dabilpuram /* Unmask interrupts since disabled after generation */ 333d61138d4SHarman Kalra rte_intr_ack(pdata->pci_dev->intr_handle); 334456ff159SRavi Kumar } 335456ff159SRavi Kumar 3367c4158a5SRavi Kumar /* 3377c4158a5SRavi Kumar * Configure device link speed and setup link. 3387c4158a5SRavi Kumar * It returns 0 on success. 3397c4158a5SRavi Kumar */ 3407c4158a5SRavi Kumar static int 3417c4158a5SRavi Kumar axgbe_dev_configure(struct rte_eth_dev *dev) 3427c4158a5SRavi Kumar { 3437c4158a5SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 3447c4158a5SRavi Kumar /* Checksum offload to hardware */ 3457c4158a5SRavi Kumar pdata->rx_csum_enable = dev->data->dev_conf.rxmode.offloads & 346295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_CHECKSUM; 3477c4158a5SRavi Kumar return 0; 3487c4158a5SRavi Kumar } 3497c4158a5SRavi Kumar 3507c4158a5SRavi Kumar static int 3517c4158a5SRavi Kumar axgbe_dev_rx_mq_config(struct rte_eth_dev *dev) 3527c4158a5SRavi Kumar { 3530bc212a8SStephen Hemminger struct axgbe_port *pdata = dev->data->dev_private; 3547c4158a5SRavi Kumar 355295968d1SFerruh Yigit if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) 3567c4158a5SRavi Kumar pdata->rss_enable = 1; 357295968d1SFerruh Yigit else if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_NONE) 3587c4158a5SRavi Kumar pdata->rss_enable = 0; 3597c4158a5SRavi Kumar else 3607c4158a5SRavi Kumar return -1; 3617c4158a5SRavi Kumar return 0; 3627c4158a5SRavi Kumar } 3637c4158a5SRavi Kumar 3647c4158a5SRavi Kumar static int 3657c4158a5SRavi Kumar axgbe_dev_start(struct rte_eth_dev *dev) 3667c4158a5SRavi Kumar { 3670bc212a8SStephen Hemminger struct axgbe_port *pdata = dev->data->dev_private; 3680236016cSJie Hai uint16_t i; 3697c4158a5SRavi Kumar int ret; 370965b3127SSelwin Sebastian 371965b3127SSelwin Sebastian dev->dev_ops = &axgbe_eth_dev_ops; 3727c4158a5SRavi Kumar 3730bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 3740bc212a8SStephen Hemminger 3757c4158a5SRavi Kumar /* Multiqueue RSS */ 3767c4158a5SRavi Kumar ret = axgbe_dev_rx_mq_config(dev); 3777c4158a5SRavi Kumar if (ret) { 3787c4158a5SRavi Kumar PMD_DRV_LOG(ERR, "Unable to config RX MQ\n"); 3797c4158a5SRavi Kumar return ret; 3807c4158a5SRavi Kumar } 3817c4158a5SRavi Kumar ret = axgbe_phy_reset(pdata); 3827c4158a5SRavi Kumar if (ret) { 3837c4158a5SRavi Kumar PMD_DRV_LOG(ERR, "phy reset failed\n"); 3847c4158a5SRavi Kumar return ret; 3857c4158a5SRavi Kumar } 3867c4158a5SRavi Kumar ret = pdata->hw_if.init(pdata); 3877c4158a5SRavi Kumar if (ret) { 3887c4158a5SRavi Kumar PMD_DRV_LOG(ERR, "dev_init failed\n"); 3897c4158a5SRavi Kumar return ret; 3907c4158a5SRavi Kumar } 3917c4158a5SRavi Kumar 3927c4158a5SRavi Kumar /* enable uio/vfio intr/eventfd mapping */ 393d61138d4SHarman Kalra rte_intr_enable(pdata->pci_dev->intr_handle); 3947c4158a5SRavi Kumar 3957c4158a5SRavi Kumar /* phy start*/ 3967c4158a5SRavi Kumar pdata->phy_if.phy_start(pdata); 3978590b93dSRavi Kumar axgbe_dev_enable_tx(dev); 3988590b93dSRavi Kumar axgbe_dev_enable_rx(dev); 3997c4158a5SRavi Kumar 4004693ae4aSJoyce Kong rte_bit_relaxed_clear32(AXGBE_STOPPED, &pdata->dev_state); 4014693ae4aSJoyce Kong rte_bit_relaxed_clear32(AXGBE_DOWN, &pdata->dev_state); 4021bb4a528SFerruh Yigit 4039963b513SJesna K E axgbe_set_rx_function(dev); 4049963b513SJesna K E axgbe_set_tx_function(dev); 4050236016cSJie Hai 4060236016cSJie Hai for (i = 0; i < dev->data->nb_rx_queues; i++) 4070236016cSJie Hai dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; 4080236016cSJie Hai for (i = 0; i < dev->data->nb_tx_queues; i++) 4090236016cSJie Hai dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; 4100236016cSJie Hai 4117c4158a5SRavi Kumar return 0; 4127c4158a5SRavi Kumar } 4137c4158a5SRavi Kumar 4147c4158a5SRavi Kumar /* Stop device: disable rx and tx functions to allow for reconfiguring. */ 41562024eb8SIvan Ilchenko static int 4167c4158a5SRavi Kumar axgbe_dev_stop(struct rte_eth_dev *dev) 4177c4158a5SRavi Kumar { 4187c4158a5SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 4197c4158a5SRavi Kumar 4200bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4210bc212a8SStephen Hemminger 422d61138d4SHarman Kalra rte_intr_disable(pdata->pci_dev->intr_handle); 4237c4158a5SRavi Kumar 4244693ae4aSJoyce Kong if (rte_bit_relaxed_get32(AXGBE_STOPPED, &pdata->dev_state)) 42562024eb8SIvan Ilchenko return 0; 4267c4158a5SRavi Kumar 4274693ae4aSJoyce Kong rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state); 4288590b93dSRavi Kumar axgbe_dev_disable_tx(dev); 4298590b93dSRavi Kumar axgbe_dev_disable_rx(dev); 4307c4158a5SRavi Kumar 4317c4158a5SRavi Kumar pdata->phy_if.phy_stop(pdata); 4327c4158a5SRavi Kumar pdata->hw_if.exit(pdata); 4337c4158a5SRavi Kumar memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link)); 4344693ae4aSJoyce Kong rte_bit_relaxed_set32(AXGBE_DOWN, &pdata->dev_state); 43562024eb8SIvan Ilchenko 43662024eb8SIvan Ilchenko return 0; 4377c4158a5SRavi Kumar } 4387c4158a5SRavi Kumar 4399039c812SAndrew Rybchenko static int 440fa3e0440SRavi Kumar axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev) 441fa3e0440SRavi Kumar { 442fa3e0440SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 443fa3e0440SRavi Kumar 4440bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4450bc212a8SStephen Hemminger 446fa3e0440SRavi Kumar AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 1); 4479039c812SAndrew Rybchenko 4489039c812SAndrew Rybchenko return 0; 449fa3e0440SRavi Kumar } 450fa3e0440SRavi Kumar 4519039c812SAndrew Rybchenko static int 452fa3e0440SRavi Kumar axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev) 453fa3e0440SRavi Kumar { 454fa3e0440SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 455fa3e0440SRavi Kumar 4560bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4570bc212a8SStephen Hemminger 458fa3e0440SRavi Kumar AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 0); 4599039c812SAndrew Rybchenko 4609039c812SAndrew Rybchenko return 0; 461fa3e0440SRavi Kumar } 462fa3e0440SRavi Kumar 463ca041cd4SIvan Ilchenko static int 464fa3e0440SRavi Kumar axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev) 465fa3e0440SRavi Kumar { 466fa3e0440SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 467fa3e0440SRavi Kumar 4680bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4690bc212a8SStephen Hemminger 470fa3e0440SRavi Kumar if (AXGMAC_IOREAD_BITS(pdata, MAC_PFR, PM)) 471ca041cd4SIvan Ilchenko return 0; 472fa3e0440SRavi Kumar AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, 1); 473ca041cd4SIvan Ilchenko 474ca041cd4SIvan Ilchenko return 0; 475fa3e0440SRavi Kumar } 476fa3e0440SRavi Kumar 477ca041cd4SIvan Ilchenko static int 478fa3e0440SRavi Kumar axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev) 479fa3e0440SRavi Kumar { 480fa3e0440SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 481fa3e0440SRavi Kumar 4820bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4830bc212a8SStephen Hemminger 484fa3e0440SRavi Kumar if (!AXGMAC_IOREAD_BITS(pdata, MAC_PFR, PM)) 485ca041cd4SIvan Ilchenko return 0; 486fa3e0440SRavi Kumar AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, 0); 487ca041cd4SIvan Ilchenko 488ca041cd4SIvan Ilchenko return 0; 489fa3e0440SRavi Kumar } 490fa3e0440SRavi Kumar 49149a5e622SChandu Babu N static int 49249a5e622SChandu Babu N axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) 49349a5e622SChandu Babu N { 49449a5e622SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 49549a5e622SChandu Babu N 49649a5e622SChandu Babu N /* Set Default MAC Addr */ 49749a5e622SChandu Babu N axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, 0); 49849a5e622SChandu Babu N 49949a5e622SChandu Babu N return 0; 50049a5e622SChandu Babu N } 50149a5e622SChandu Babu N 50249a5e622SChandu Babu N static int 50349a5e622SChandu Babu N axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr, 50449a5e622SChandu Babu N uint32_t index, uint32_t pool __rte_unused) 50549a5e622SChandu Babu N { 50649a5e622SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 50749a5e622SChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 50849a5e622SChandu Babu N 50949a5e622SChandu Babu N if (index > hw_feat->addn_mac) { 51049a5e622SChandu Babu N PMD_DRV_LOG(ERR, "Invalid Index %d\n", index); 51149a5e622SChandu Babu N return -EINVAL; 51249a5e622SChandu Babu N } 51349a5e622SChandu Babu N axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, index); 51449a5e622SChandu Babu N return 0; 51549a5e622SChandu Babu N } 51649a5e622SChandu Babu N 51776d7664dSChandu Babu N static int 51876d7664dSChandu Babu N axgbe_dev_rss_reta_update(struct rte_eth_dev *dev, 51976d7664dSChandu Babu N struct rte_eth_rss_reta_entry64 *reta_conf, 52076d7664dSChandu Babu N uint16_t reta_size) 52176d7664dSChandu Babu N { 52276d7664dSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 52376d7664dSChandu Babu N unsigned int i, idx, shift; 52476d7664dSChandu Babu N int ret; 52576d7664dSChandu Babu N 52676d7664dSChandu Babu N if (!pdata->rss_enable) { 52776d7664dSChandu Babu N PMD_DRV_LOG(ERR, "RSS not enabled\n"); 52876d7664dSChandu Babu N return -ENOTSUP; 52976d7664dSChandu Babu N } 53076d7664dSChandu Babu N 53176d7664dSChandu Babu N if (reta_size == 0 || reta_size > AXGBE_RSS_MAX_TABLE_SIZE) { 53276d7664dSChandu Babu N PMD_DRV_LOG(ERR, "reta_size %d is not supported\n", reta_size); 53376d7664dSChandu Babu N return -EINVAL; 53476d7664dSChandu Babu N } 53576d7664dSChandu Babu N 53676d7664dSChandu Babu N for (i = 0; i < reta_size; i++) { 537295968d1SFerruh Yigit idx = i / RTE_ETH_RETA_GROUP_SIZE; 538295968d1SFerruh Yigit shift = i % RTE_ETH_RETA_GROUP_SIZE; 53976d7664dSChandu Babu N if ((reta_conf[idx].mask & (1ULL << shift)) == 0) 54076d7664dSChandu Babu N continue; 54176d7664dSChandu Babu N pdata->rss_table[i] = reta_conf[idx].reta[shift]; 54276d7664dSChandu Babu N } 54376d7664dSChandu Babu N 54476d7664dSChandu Babu N /* Program the lookup table */ 54576d7664dSChandu Babu N ret = axgbe_write_rss_lookup_table(pdata); 54676d7664dSChandu Babu N return ret; 54776d7664dSChandu Babu N } 54876d7664dSChandu Babu N 54976d7664dSChandu Babu N static int 55076d7664dSChandu Babu N axgbe_dev_rss_reta_query(struct rte_eth_dev *dev, 55176d7664dSChandu Babu N struct rte_eth_rss_reta_entry64 *reta_conf, 55276d7664dSChandu Babu N uint16_t reta_size) 55376d7664dSChandu Babu N { 55476d7664dSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 55576d7664dSChandu Babu N unsigned int i, idx, shift; 55676d7664dSChandu Babu N 55776d7664dSChandu Babu N if (!pdata->rss_enable) { 55876d7664dSChandu Babu N PMD_DRV_LOG(ERR, "RSS not enabled\n"); 55976d7664dSChandu Babu N return -ENOTSUP; 56076d7664dSChandu Babu N } 56176d7664dSChandu Babu N 56276d7664dSChandu Babu N if (reta_size == 0 || reta_size > AXGBE_RSS_MAX_TABLE_SIZE) { 56376d7664dSChandu Babu N PMD_DRV_LOG(ERR, "reta_size %d is not supported\n", reta_size); 56476d7664dSChandu Babu N return -EINVAL; 56576d7664dSChandu Babu N } 56676d7664dSChandu Babu N 56776d7664dSChandu Babu N for (i = 0; i < reta_size; i++) { 568295968d1SFerruh Yigit idx = i / RTE_ETH_RETA_GROUP_SIZE; 569295968d1SFerruh Yigit shift = i % RTE_ETH_RETA_GROUP_SIZE; 57076d7664dSChandu Babu N if ((reta_conf[idx].mask & (1ULL << shift)) == 0) 57176d7664dSChandu Babu N continue; 57276d7664dSChandu Babu N reta_conf[idx].reta[shift] = pdata->rss_table[i]; 57376d7664dSChandu Babu N } 57476d7664dSChandu Babu N return 0; 57576d7664dSChandu Babu N } 57676d7664dSChandu Babu N 57776d7664dSChandu Babu N static int 57876d7664dSChandu Babu N axgbe_dev_rss_hash_update(struct rte_eth_dev *dev, 57976d7664dSChandu Babu N struct rte_eth_rss_conf *rss_conf) 58076d7664dSChandu Babu N { 58176d7664dSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 58276d7664dSChandu Babu N int ret; 58376d7664dSChandu Babu N 58476d7664dSChandu Babu N if (!pdata->rss_enable) { 58576d7664dSChandu Babu N PMD_DRV_LOG(ERR, "RSS not enabled\n"); 58676d7664dSChandu Babu N return -ENOTSUP; 58776d7664dSChandu Babu N } 58876d7664dSChandu Babu N 58976d7664dSChandu Babu N if (rss_conf == NULL) { 59076d7664dSChandu Babu N PMD_DRV_LOG(ERR, "rss_conf value isn't valid\n"); 59176d7664dSChandu Babu N return -EINVAL; 59276d7664dSChandu Babu N } 59376d7664dSChandu Babu N 59476d7664dSChandu Babu N if (rss_conf->rss_key != NULL && 59576d7664dSChandu Babu N rss_conf->rss_key_len == AXGBE_RSS_HASH_KEY_SIZE) { 59676d7664dSChandu Babu N rte_memcpy(pdata->rss_key, rss_conf->rss_key, 59776d7664dSChandu Babu N AXGBE_RSS_HASH_KEY_SIZE); 59876d7664dSChandu Babu N /* Program the hash key */ 59976d7664dSChandu Babu N ret = axgbe_write_rss_hash_key(pdata); 60076d7664dSChandu Babu N if (ret != 0) 60176d7664dSChandu Babu N return ret; 60276d7664dSChandu Babu N } 60376d7664dSChandu Babu N 60476d7664dSChandu Babu N pdata->rss_hf = rss_conf->rss_hf & AXGBE_RSS_OFFLOAD; 60576d7664dSChandu Babu N 606295968d1SFerruh Yigit if (pdata->rss_hf & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6)) 60776d7664dSChandu Babu N AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1); 60876d7664dSChandu Babu N if (pdata->rss_hf & 609295968d1SFerruh Yigit (RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_NONFRAG_IPV6_TCP)) 61076d7664dSChandu Babu N AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1); 61176d7664dSChandu Babu N if (pdata->rss_hf & 612295968d1SFerruh Yigit (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV6_UDP)) 61376d7664dSChandu Babu N AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1); 61476d7664dSChandu Babu N 61576d7664dSChandu Babu N /* Set the RSS options */ 61676d7664dSChandu Babu N AXGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options); 61776d7664dSChandu Babu N 61876d7664dSChandu Babu N return 0; 61976d7664dSChandu Babu N } 62076d7664dSChandu Babu N 62176d7664dSChandu Babu N static int 62276d7664dSChandu Babu N axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev, 62376d7664dSChandu Babu N struct rte_eth_rss_conf *rss_conf) 62476d7664dSChandu Babu N { 62576d7664dSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 62676d7664dSChandu Babu N 62776d7664dSChandu Babu N if (!pdata->rss_enable) { 62876d7664dSChandu Babu N PMD_DRV_LOG(ERR, "RSS not enabled\n"); 62976d7664dSChandu Babu N return -ENOTSUP; 63076d7664dSChandu Babu N } 63176d7664dSChandu Babu N 63276d7664dSChandu Babu N if (rss_conf == NULL) { 63376d7664dSChandu Babu N PMD_DRV_LOG(ERR, "rss_conf value isn't valid\n"); 63476d7664dSChandu Babu N return -EINVAL; 63576d7664dSChandu Babu N } 63676d7664dSChandu Babu N 63776d7664dSChandu Babu N if (rss_conf->rss_key != NULL && 63876d7664dSChandu Babu N rss_conf->rss_key_len >= AXGBE_RSS_HASH_KEY_SIZE) { 63976d7664dSChandu Babu N rte_memcpy(rss_conf->rss_key, pdata->rss_key, 64076d7664dSChandu Babu N AXGBE_RSS_HASH_KEY_SIZE); 64176d7664dSChandu Babu N } 64276d7664dSChandu Babu N rss_conf->rss_key_len = AXGBE_RSS_HASH_KEY_SIZE; 64376d7664dSChandu Babu N rss_conf->rss_hf = pdata->rss_hf; 64476d7664dSChandu Babu N return 0; 64576d7664dSChandu Babu N } 64676d7664dSChandu Babu N 647bf403cfeSSelwin Sebastian static int 648bf403cfeSSelwin Sebastian axgbe_dev_reset(struct rte_eth_dev *dev) 649bf403cfeSSelwin Sebastian { 650bf403cfeSSelwin Sebastian int ret = 0; 651bf403cfeSSelwin Sebastian 652bf403cfeSSelwin Sebastian ret = axgbe_dev_close(dev); 653bf403cfeSSelwin Sebastian if (ret) 654bf403cfeSSelwin Sebastian return ret; 655bf403cfeSSelwin Sebastian 656bf403cfeSSelwin Sebastian ret = eth_axgbe_dev_init(dev); 657bf403cfeSSelwin Sebastian 658bf403cfeSSelwin Sebastian return ret; 659bf403cfeSSelwin Sebastian } 660bf403cfeSSelwin Sebastian 66149a5e622SChandu Babu N static void 66249a5e622SChandu Babu N axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) 66349a5e622SChandu Babu N { 66449a5e622SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 66549a5e622SChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 66649a5e622SChandu Babu N 66749a5e622SChandu Babu N if (index > hw_feat->addn_mac) { 66849a5e622SChandu Babu N PMD_DRV_LOG(ERR, "Invalid Index %d\n", index); 66949a5e622SChandu Babu N return; 67049a5e622SChandu Babu N } 67149a5e622SChandu Babu N axgbe_set_mac_addn_addr(pdata, NULL, index); 67249a5e622SChandu Babu N } 67349a5e622SChandu Babu N 67449a5e622SChandu Babu N static int 67549a5e622SChandu Babu N axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev, 67649a5e622SChandu Babu N struct rte_ether_addr *mc_addr_set, 67749a5e622SChandu Babu N uint32_t nb_mc_addr) 67849a5e622SChandu Babu N { 67949a5e622SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 68049a5e622SChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 68149a5e622SChandu Babu N uint32_t index = 1; /* 0 is always default mac */ 68249a5e622SChandu Babu N uint32_t i; 68349a5e622SChandu Babu N 68449a5e622SChandu Babu N if (nb_mc_addr > hw_feat->addn_mac) { 68549a5e622SChandu Babu N PMD_DRV_LOG(ERR, "Invalid Index %d\n", nb_mc_addr); 68649a5e622SChandu Babu N return -EINVAL; 68749a5e622SChandu Babu N } 68849a5e622SChandu Babu N 68949a5e622SChandu Babu N /* clear unicast addresses */ 69049a5e622SChandu Babu N for (i = 1; i < hw_feat->addn_mac; i++) { 69149a5e622SChandu Babu N if (rte_is_zero_ether_addr(&dev->data->mac_addrs[i])) 69249a5e622SChandu Babu N continue; 69349a5e622SChandu Babu N memset(&dev->data->mac_addrs[i], 0, 69449a5e622SChandu Babu N sizeof(struct rte_ether_addr)); 69549a5e622SChandu Babu N } 69649a5e622SChandu Babu N 69749a5e622SChandu Babu N while (nb_mc_addr--) 69849a5e622SChandu Babu N axgbe_set_mac_addn_addr(pdata, (u8 *)mc_addr_set++, index++); 69949a5e622SChandu Babu N 70049a5e622SChandu Babu N return 0; 70149a5e622SChandu Babu N } 70249a5e622SChandu Babu N 703e01d9b2eSChandu Babu N static int 704e01d9b2eSChandu Babu N axgbe_dev_uc_hash_table_set(struct rte_eth_dev *dev, 705e01d9b2eSChandu Babu N struct rte_ether_addr *mac_addr, uint8_t add) 706e01d9b2eSChandu Babu N { 707e01d9b2eSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 708e01d9b2eSChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 709e01d9b2eSChandu Babu N 710e01d9b2eSChandu Babu N if (!hw_feat->hash_table_size) { 711e01d9b2eSChandu Babu N PMD_DRV_LOG(ERR, "MAC Hash Table not supported\n"); 712e01d9b2eSChandu Babu N return -ENOTSUP; 713e01d9b2eSChandu Babu N } 714e01d9b2eSChandu Babu N 715e01d9b2eSChandu Babu N axgbe_set_mac_hash_table(pdata, (u8 *)mac_addr, add); 716e01d9b2eSChandu Babu N 717e01d9b2eSChandu Babu N if (pdata->uc_hash_mac_addr > 0) { 718e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1); 719e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1); 720e01d9b2eSChandu Babu N } else { 721e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 0); 722e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0); 723e01d9b2eSChandu Babu N } 724e01d9b2eSChandu Babu N return 0; 725e01d9b2eSChandu Babu N } 726e01d9b2eSChandu Babu N 727e01d9b2eSChandu Babu N static int 728e01d9b2eSChandu Babu N axgbe_dev_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t add) 729e01d9b2eSChandu Babu N { 730e01d9b2eSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 731e01d9b2eSChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 732e01d9b2eSChandu Babu N uint32_t index; 733e01d9b2eSChandu Babu N 734e01d9b2eSChandu Babu N if (!hw_feat->hash_table_size) { 735e01d9b2eSChandu Babu N PMD_DRV_LOG(ERR, "MAC Hash Table not supported\n"); 736e01d9b2eSChandu Babu N return -ENOTSUP; 737e01d9b2eSChandu Babu N } 738e01d9b2eSChandu Babu N 739e01d9b2eSChandu Babu N for (index = 0; index < pdata->hash_table_count; index++) { 740e01d9b2eSChandu Babu N if (add) 741e01d9b2eSChandu Babu N pdata->uc_hash_table[index] = ~0; 742e01d9b2eSChandu Babu N else 743e01d9b2eSChandu Babu N pdata->uc_hash_table[index] = 0; 744e01d9b2eSChandu Babu N 745e01d9b2eSChandu Babu N PMD_DRV_LOG(DEBUG, "%s MAC hash table at Index %#x\n", 746e01d9b2eSChandu Babu N add ? "set" : "clear", index); 747e01d9b2eSChandu Babu N 748e01d9b2eSChandu Babu N AXGMAC_IOWRITE(pdata, MAC_HTR(index), 749e01d9b2eSChandu Babu N pdata->uc_hash_table[index]); 750e01d9b2eSChandu Babu N } 751e01d9b2eSChandu Babu N 752e01d9b2eSChandu Babu N if (add) { 753e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1); 754e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1); 755e01d9b2eSChandu Babu N } else { 756e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 0); 757e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0); 758e01d9b2eSChandu Babu N } 759e01d9b2eSChandu Babu N return 0; 760e01d9b2eSChandu Babu N } 761e01d9b2eSChandu Babu N 76244d45ffeSRavi Kumar /* return 0 means link status changed, -1 means not changed */ 76344d45ffeSRavi Kumar static int 76444d45ffeSRavi Kumar axgbe_dev_link_update(struct rte_eth_dev *dev, 76544d45ffeSRavi Kumar int wait_to_complete __rte_unused) 76644d45ffeSRavi Kumar { 76744d45ffeSRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 76844d45ffeSRavi Kumar struct rte_eth_link link; 76944d45ffeSRavi Kumar int ret = 0; 77044d45ffeSRavi Kumar 77144d45ffeSRavi Kumar PMD_INIT_FUNC_TRACE(); 77244d45ffeSRavi Kumar rte_delay_ms(800); 77344d45ffeSRavi Kumar 77444d45ffeSRavi Kumar pdata->phy_if.phy_status(pdata); 77544d45ffeSRavi Kumar 77644d45ffeSRavi Kumar memset(&link, 0, sizeof(struct rte_eth_link)); 77744d45ffeSRavi Kumar link.link_duplex = pdata->phy.duplex; 77844d45ffeSRavi Kumar link.link_status = pdata->phy_link; 77944d45ffeSRavi Kumar link.link_speed = pdata->phy_speed; 78044d45ffeSRavi Kumar link.link_autoneg = !(dev->data->dev_conf.link_speeds & 781295968d1SFerruh Yigit RTE_ETH_LINK_SPEED_FIXED); 78244d45ffeSRavi Kumar ret = rte_eth_linkstatus_set(dev, &link); 78344d45ffeSRavi Kumar if (ret == -1) 78444d45ffeSRavi Kumar PMD_DRV_LOG(ERR, "No change in link status\n"); 78544d45ffeSRavi Kumar 78644d45ffeSRavi Kumar return ret; 78744d45ffeSRavi Kumar } 78844d45ffeSRavi Kumar 789df4867cdSChandu Babu N static int 790df4867cdSChandu Babu N axgbe_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs) 791df4867cdSChandu Babu N { 792df4867cdSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 793df4867cdSChandu Babu N 794df4867cdSChandu Babu N if (regs->data == NULL) { 795df4867cdSChandu Babu N regs->length = axgbe_regs_get_count(pdata); 796df4867cdSChandu Babu N regs->width = sizeof(uint32_t); 797df4867cdSChandu Babu N return 0; 798df4867cdSChandu Babu N } 799df4867cdSChandu Babu N 800df4867cdSChandu Babu N /* Only full register dump is supported */ 801df4867cdSChandu Babu N if (regs->length && 802df4867cdSChandu Babu N regs->length != (uint32_t)axgbe_regs_get_count(pdata)) 803df4867cdSChandu Babu N return -ENOTSUP; 804df4867cdSChandu Babu N 805df4867cdSChandu Babu N regs->version = pdata->pci_dev->id.vendor_id << 16 | 806df4867cdSChandu Babu N pdata->pci_dev->id.device_id; 807df4867cdSChandu Babu N axgbe_regs_dump(pdata, regs->data); 808df4867cdSChandu Babu N return 0; 809df4867cdSChandu Babu N } 8109d1ef6b2SChandu Babu N static void axgbe_read_mmc_stats(struct axgbe_port *pdata) 8119d1ef6b2SChandu Babu N { 8129d1ef6b2SChandu Babu N struct axgbe_mmc_stats *stats = &pdata->mmc_stats; 8139d1ef6b2SChandu Babu N 8149d1ef6b2SChandu Babu N /* Freeze counters */ 8159d1ef6b2SChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1); 8169d1ef6b2SChandu Babu N 8179d1ef6b2SChandu Babu N /* Tx counters */ 8189d1ef6b2SChandu Babu N stats->txoctetcount_gb += 8199d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO); 8209d1ef6b2SChandu Babu N stats->txoctetcount_gb += 8219d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_HI) << 32); 8229d1ef6b2SChandu Babu N 8239d1ef6b2SChandu Babu N stats->txframecount_gb += 8249d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO); 8259d1ef6b2SChandu Babu N stats->txframecount_gb += 8269d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_HI) << 32); 8279d1ef6b2SChandu Babu N 8289d1ef6b2SChandu Babu N stats->txbroadcastframes_g += 8299d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO); 8309d1ef6b2SChandu Babu N stats->txbroadcastframes_g += 8319d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_HI) << 32); 8329d1ef6b2SChandu Babu N 8339d1ef6b2SChandu Babu N stats->txmulticastframes_g += 8349d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO); 8359d1ef6b2SChandu Babu N stats->txmulticastframes_g += 8369d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_HI) << 32); 8379d1ef6b2SChandu Babu N 8389d1ef6b2SChandu Babu N stats->tx64octets_gb += 8399d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO); 8409d1ef6b2SChandu Babu N stats->tx64octets_gb += 8419d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_HI) << 32); 8429d1ef6b2SChandu Babu N 8439d1ef6b2SChandu Babu N stats->tx65to127octets_gb += 8449d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO); 8459d1ef6b2SChandu Babu N stats->tx65to127octets_gb += 8469d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_HI) << 32); 8479d1ef6b2SChandu Babu N 8489d1ef6b2SChandu Babu N stats->tx128to255octets_gb += 8499d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO); 8509d1ef6b2SChandu Babu N stats->tx128to255octets_gb += 8519d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_HI) << 32); 8529d1ef6b2SChandu Babu N 8539d1ef6b2SChandu Babu N stats->tx256to511octets_gb += 8549d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO); 8559d1ef6b2SChandu Babu N stats->tx256to511octets_gb += 8569d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_HI) << 32); 8579d1ef6b2SChandu Babu N 8589d1ef6b2SChandu Babu N stats->tx512to1023octets_gb += 8599d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO); 8609d1ef6b2SChandu Babu N stats->tx512to1023octets_gb += 8619d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_HI) << 32); 8629d1ef6b2SChandu Babu N 8639d1ef6b2SChandu Babu N stats->tx1024tomaxoctets_gb += 8649d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO); 8659d1ef6b2SChandu Babu N stats->tx1024tomaxoctets_gb += 8669d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_HI) << 32); 8679d1ef6b2SChandu Babu N 8689d1ef6b2SChandu Babu N stats->txunicastframes_gb += 8699d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO); 8709d1ef6b2SChandu Babu N stats->txunicastframes_gb += 8719d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_HI) << 32); 8729d1ef6b2SChandu Babu N 8739d1ef6b2SChandu Babu N stats->txmulticastframes_gb += 8749d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO); 8759d1ef6b2SChandu Babu N stats->txmulticastframes_gb += 8769d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_HI) << 32); 8779d1ef6b2SChandu Babu N 8789d1ef6b2SChandu Babu N stats->txbroadcastframes_g += 8799d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO); 8809d1ef6b2SChandu Babu N stats->txbroadcastframes_g += 8819d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_HI) << 32); 8829d1ef6b2SChandu Babu N 8839d1ef6b2SChandu Babu N stats->txunderflowerror += 8849d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO); 8859d1ef6b2SChandu Babu N stats->txunderflowerror += 8869d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_HI) << 32); 8879d1ef6b2SChandu Babu N 8889d1ef6b2SChandu Babu N stats->txoctetcount_g += 8899d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO); 8909d1ef6b2SChandu Babu N stats->txoctetcount_g += 8919d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_HI) << 32); 8929d1ef6b2SChandu Babu N 8939d1ef6b2SChandu Babu N stats->txframecount_g += 8949d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO); 8959d1ef6b2SChandu Babu N stats->txframecount_g += 8969d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_HI) << 32); 8979d1ef6b2SChandu Babu N 8989d1ef6b2SChandu Babu N stats->txpauseframes += 8999d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO); 9009d1ef6b2SChandu Babu N stats->txpauseframes += 9019d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_HI) << 32); 9029d1ef6b2SChandu Babu N 9039d1ef6b2SChandu Babu N stats->txvlanframes_g += 9049d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO); 9059d1ef6b2SChandu Babu N stats->txvlanframes_g += 9069d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_HI) << 32); 9079d1ef6b2SChandu Babu N 9089d1ef6b2SChandu Babu N /* Rx counters */ 9099d1ef6b2SChandu Babu N stats->rxframecount_gb += 9109d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO); 9119d1ef6b2SChandu Babu N stats->rxframecount_gb += 9129d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_HI) << 32); 9139d1ef6b2SChandu Babu N 9149d1ef6b2SChandu Babu N stats->rxoctetcount_gb += 9159d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO); 9169d1ef6b2SChandu Babu N stats->rxoctetcount_gb += 9179d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_HI) << 32); 9189d1ef6b2SChandu Babu N 9199d1ef6b2SChandu Babu N stats->rxoctetcount_g += 9209d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO); 9219d1ef6b2SChandu Babu N stats->rxoctetcount_g += 9229d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_HI) << 32); 9239d1ef6b2SChandu Babu N 9249d1ef6b2SChandu Babu N stats->rxbroadcastframes_g += 9259d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO); 9269d1ef6b2SChandu Babu N stats->rxbroadcastframes_g += 9279d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_HI) << 32); 9289d1ef6b2SChandu Babu N 9299d1ef6b2SChandu Babu N stats->rxmulticastframes_g += 9309d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO); 9319d1ef6b2SChandu Babu N stats->rxmulticastframes_g += 9329d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_HI) << 32); 9339d1ef6b2SChandu Babu N 9349d1ef6b2SChandu Babu N stats->rxcrcerror += 9359d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO); 9369d1ef6b2SChandu Babu N stats->rxcrcerror += 9379d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXCRCERROR_HI) << 32); 9389d1ef6b2SChandu Babu N 9399d1ef6b2SChandu Babu N stats->rxrunterror += 9409d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXRUNTERROR); 9419d1ef6b2SChandu Babu N 9429d1ef6b2SChandu Babu N stats->rxjabbererror += 9439d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXJABBERERROR); 9449d1ef6b2SChandu Babu N 9459d1ef6b2SChandu Babu N stats->rxundersize_g += 9469d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G); 9479d1ef6b2SChandu Babu N 9489d1ef6b2SChandu Babu N stats->rxoversize_g += 9499d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G); 9509d1ef6b2SChandu Babu N 9519d1ef6b2SChandu Babu N stats->rx64octets_gb += 9529d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO); 9539d1ef6b2SChandu Babu N stats->rx64octets_gb += 9549d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_HI) << 32); 9559d1ef6b2SChandu Babu N 9569d1ef6b2SChandu Babu N stats->rx65to127octets_gb += 9579d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO); 9589d1ef6b2SChandu Babu N stats->rx65to127octets_gb += 9599d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_HI) << 32); 9609d1ef6b2SChandu Babu N 9619d1ef6b2SChandu Babu N stats->rx128to255octets_gb += 9629d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO); 9639d1ef6b2SChandu Babu N stats->rx128to255octets_gb += 9649d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_HI) << 32); 9659d1ef6b2SChandu Babu N 9669d1ef6b2SChandu Babu N stats->rx256to511octets_gb += 9679d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO); 9689d1ef6b2SChandu Babu N stats->rx256to511octets_gb += 9699d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_HI) << 32); 9709d1ef6b2SChandu Babu N 9719d1ef6b2SChandu Babu N stats->rx512to1023octets_gb += 9729d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO); 9739d1ef6b2SChandu Babu N stats->rx512to1023octets_gb += 9749d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_HI) << 32); 9759d1ef6b2SChandu Babu N 9769d1ef6b2SChandu Babu N stats->rx1024tomaxoctets_gb += 9779d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO); 9789d1ef6b2SChandu Babu N stats->rx1024tomaxoctets_gb += 9799d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_HI) << 32); 9809d1ef6b2SChandu Babu N 9819d1ef6b2SChandu Babu N stats->rxunicastframes_g += 9829d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO); 9839d1ef6b2SChandu Babu N stats->rxunicastframes_g += 9849d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_HI) << 32); 9859d1ef6b2SChandu Babu N 9869d1ef6b2SChandu Babu N stats->rxlengtherror += 9879d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO); 9889d1ef6b2SChandu Babu N stats->rxlengtherror += 9899d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_HI) << 32); 9909d1ef6b2SChandu Babu N 9919d1ef6b2SChandu Babu N stats->rxoutofrangetype += 9929d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO); 9939d1ef6b2SChandu Babu N stats->rxoutofrangetype += 9949d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_HI) << 32); 9959d1ef6b2SChandu Babu N 9969d1ef6b2SChandu Babu N stats->rxpauseframes += 9979d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO); 9989d1ef6b2SChandu Babu N stats->rxpauseframes += 9999d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_HI) << 32); 10009d1ef6b2SChandu Babu N 10019d1ef6b2SChandu Babu N stats->rxfifooverflow += 10029d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO); 10039d1ef6b2SChandu Babu N stats->rxfifooverflow += 10049d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_HI) << 32); 10059d1ef6b2SChandu Babu N 10069d1ef6b2SChandu Babu N stats->rxvlanframes_gb += 10079d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO); 10089d1ef6b2SChandu Babu N stats->rxvlanframes_gb += 10099d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_HI) << 32); 10109d1ef6b2SChandu Babu N 10119d1ef6b2SChandu Babu N stats->rxwatchdogerror += 10129d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR); 10139d1ef6b2SChandu Babu N 10149d1ef6b2SChandu Babu N /* Un-freeze counters */ 10159d1ef6b2SChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0); 10169d1ef6b2SChandu Babu N } 10179d1ef6b2SChandu Babu N 10189d1ef6b2SChandu Babu N static int 10199d1ef6b2SChandu Babu N axgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats, 10209d1ef6b2SChandu Babu N unsigned int n) 10219d1ef6b2SChandu Babu N { 10229d1ef6b2SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 10239d1ef6b2SChandu Babu N unsigned int i; 10249d1ef6b2SChandu Babu N 102593041fd5SChengwen Feng if (n < AXGBE_XSTATS_COUNT) 102693041fd5SChengwen Feng return AXGBE_XSTATS_COUNT; 10279d1ef6b2SChandu Babu N 10289d1ef6b2SChandu Babu N axgbe_read_mmc_stats(pdata); 10299d1ef6b2SChandu Babu N 103093041fd5SChengwen Feng for (i = 0; i < AXGBE_XSTATS_COUNT; i++) { 10319d1ef6b2SChandu Babu N stats[i].id = i; 10329d1ef6b2SChandu Babu N stats[i].value = *(u64 *)((uint8_t *)&pdata->mmc_stats + 10339d1ef6b2SChandu Babu N axgbe_xstats_strings[i].offset); 10349d1ef6b2SChandu Babu N } 10359d1ef6b2SChandu Babu N 103693041fd5SChengwen Feng return AXGBE_XSTATS_COUNT; 10379d1ef6b2SChandu Babu N } 10389d1ef6b2SChandu Babu N 10399d1ef6b2SChandu Babu N static int 10409d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev, 10419d1ef6b2SChandu Babu N struct rte_eth_xstat_name *xstats_names, 10429d1ef6b2SChandu Babu N unsigned int n) 10439d1ef6b2SChandu Babu N { 10449d1ef6b2SChandu Babu N unsigned int i; 10459d1ef6b2SChandu Babu N 10469d1ef6b2SChandu Babu N if (n >= AXGBE_XSTATS_COUNT && xstats_names) { 10479d1ef6b2SChandu Babu N for (i = 0; i < AXGBE_XSTATS_COUNT; ++i) { 10489d1ef6b2SChandu Babu N snprintf(xstats_names[i].name, 10499d1ef6b2SChandu Babu N RTE_ETH_XSTATS_NAME_SIZE, "%s", 10509d1ef6b2SChandu Babu N axgbe_xstats_strings[i].name); 10519d1ef6b2SChandu Babu N } 10529d1ef6b2SChandu Babu N } 10539d1ef6b2SChandu Babu N 10549d1ef6b2SChandu Babu N return AXGBE_XSTATS_COUNT; 10559d1ef6b2SChandu Babu N } 10569d1ef6b2SChandu Babu N 10579d1ef6b2SChandu Babu N static int 10589d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, 10599d1ef6b2SChandu Babu N uint64_t *values, unsigned int n) 10609d1ef6b2SChandu Babu N { 10619d1ef6b2SChandu Babu N unsigned int i; 10629d1ef6b2SChandu Babu N uint64_t values_copy[AXGBE_XSTATS_COUNT]; 10639d1ef6b2SChandu Babu N 10649d1ef6b2SChandu Babu N if (!ids) { 10659d1ef6b2SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 10669d1ef6b2SChandu Babu N 10679d1ef6b2SChandu Babu N if (n < AXGBE_XSTATS_COUNT) 10689d1ef6b2SChandu Babu N return AXGBE_XSTATS_COUNT; 10699d1ef6b2SChandu Babu N 10709d1ef6b2SChandu Babu N axgbe_read_mmc_stats(pdata); 10719d1ef6b2SChandu Babu N 10729d1ef6b2SChandu Babu N for (i = 0; i < AXGBE_XSTATS_COUNT; i++) { 10739d1ef6b2SChandu Babu N values[i] = *(u64 *)((uint8_t *)&pdata->mmc_stats + 10749d1ef6b2SChandu Babu N axgbe_xstats_strings[i].offset); 10759d1ef6b2SChandu Babu N } 10769d1ef6b2SChandu Babu N 10779d1ef6b2SChandu Babu N return i; 10789d1ef6b2SChandu Babu N } 10799d1ef6b2SChandu Babu N 10809d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(dev, NULL, values_copy, AXGBE_XSTATS_COUNT); 10819d1ef6b2SChandu Babu N 10829d1ef6b2SChandu Babu N for (i = 0; i < n; i++) { 10839d1ef6b2SChandu Babu N if (ids[i] >= AXGBE_XSTATS_COUNT) { 10849d1ef6b2SChandu Babu N PMD_DRV_LOG(ERR, "id value isn't valid\n"); 10859d1ef6b2SChandu Babu N return -1; 10869d1ef6b2SChandu Babu N } 10879d1ef6b2SChandu Babu N values[i] = values_copy[ids[i]]; 10889d1ef6b2SChandu Babu N } 10899d1ef6b2SChandu Babu N return n; 10909d1ef6b2SChandu Babu N } 10919d1ef6b2SChandu Babu N 10929d1ef6b2SChandu Babu N static int 10939d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, 10949d1ef6b2SChandu Babu N const uint64_t *ids, 10958c9f976fSAndrew Rybchenko struct rte_eth_xstat_name *xstats_names, 10969d1ef6b2SChandu Babu N unsigned int size) 10979d1ef6b2SChandu Babu N { 10989d1ef6b2SChandu Babu N struct rte_eth_xstat_name xstats_names_copy[AXGBE_XSTATS_COUNT]; 10999d1ef6b2SChandu Babu N unsigned int i; 11009d1ef6b2SChandu Babu N 11019d1ef6b2SChandu Babu N if (!ids) 11029d1ef6b2SChandu Babu N return axgbe_dev_xstats_get_names(dev, xstats_names, size); 11039d1ef6b2SChandu Babu N 11049d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(dev, xstats_names_copy, size); 11059d1ef6b2SChandu Babu N 11069d1ef6b2SChandu Babu N for (i = 0; i < size; i++) { 11079d1ef6b2SChandu Babu N if (ids[i] >= AXGBE_XSTATS_COUNT) { 11089d1ef6b2SChandu Babu N PMD_DRV_LOG(ERR, "id value isn't valid\n"); 11099d1ef6b2SChandu Babu N return -1; 11109d1ef6b2SChandu Babu N } 11119d1ef6b2SChandu Babu N strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name); 11129d1ef6b2SChandu Babu N } 11139d1ef6b2SChandu Babu N return size; 11149d1ef6b2SChandu Babu N } 11159d1ef6b2SChandu Babu N 11169d1ef6b2SChandu Babu N static int 11179d1ef6b2SChandu Babu N axgbe_dev_xstats_reset(struct rte_eth_dev *dev) 11189d1ef6b2SChandu Babu N { 11199d1ef6b2SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 11209d1ef6b2SChandu Babu N struct axgbe_mmc_stats *stats = &pdata->mmc_stats; 11219d1ef6b2SChandu Babu N 11229d1ef6b2SChandu Babu N /* MMC registers are configured for reset on read */ 11239d1ef6b2SChandu Babu N axgbe_read_mmc_stats(pdata); 11249d1ef6b2SChandu Babu N 11259d1ef6b2SChandu Babu N /* Reset stats */ 11269d1ef6b2SChandu Babu N memset(stats, 0, sizeof(*stats)); 11279d1ef6b2SChandu Babu N 11289d1ef6b2SChandu Babu N return 0; 11299d1ef6b2SChandu Babu N } 11309d1ef6b2SChandu Babu N 11313e730511SRavi Kumar static int 11323e730511SRavi Kumar axgbe_dev_stats_get(struct rte_eth_dev *dev, 11333e730511SRavi Kumar struct rte_eth_stats *stats) 11343e730511SRavi Kumar { 11353e730511SRavi Kumar struct axgbe_rx_queue *rxq; 11363e730511SRavi Kumar struct axgbe_tx_queue *txq; 11379d1ef6b2SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 11389d1ef6b2SChandu Babu N struct axgbe_mmc_stats *mmc_stats = &pdata->mmc_stats; 11393e730511SRavi Kumar unsigned int i; 11403e730511SRavi Kumar 11419d1ef6b2SChandu Babu N axgbe_read_mmc_stats(pdata); 11429d1ef6b2SChandu Babu N 11439d1ef6b2SChandu Babu N stats->imissed = mmc_stats->rxfifooverflow; 11449d1ef6b2SChandu Babu N 11453e730511SRavi Kumar for (i = 0; i < dev->data->nb_rx_queues; i++) { 11463e730511SRavi Kumar rxq = dev->data->rx_queues[i]; 1147bf403cfeSSelwin Sebastian if (rxq) { 11483e730511SRavi Kumar stats->q_ipackets[i] = rxq->pkts; 11493e730511SRavi Kumar stats->ipackets += rxq->pkts; 11503e730511SRavi Kumar stats->q_ibytes[i] = rxq->bytes; 11513e730511SRavi Kumar stats->ibytes += rxq->bytes; 11529d1ef6b2SChandu Babu N stats->rx_nombuf += rxq->rx_mbuf_alloc_failed; 1153bf403cfeSSelwin Sebastian stats->q_errors[i] = rxq->errors 1154bf403cfeSSelwin Sebastian + rxq->rx_mbuf_alloc_failed; 11559d1ef6b2SChandu Babu N stats->ierrors += rxq->errors; 1156bf403cfeSSelwin Sebastian } else { 1157bf403cfeSSelwin Sebastian PMD_DRV_LOG(DEBUG, "Rx queue not setup for port %d\n", 1158bf403cfeSSelwin Sebastian dev->data->port_id); 1159bf403cfeSSelwin Sebastian } 11603e730511SRavi Kumar } 11619d1ef6b2SChandu Babu N 11623e730511SRavi Kumar for (i = 0; i < dev->data->nb_tx_queues; i++) { 11633e730511SRavi Kumar txq = dev->data->tx_queues[i]; 1164bf403cfeSSelwin Sebastian if (txq) { 11653e730511SRavi Kumar stats->q_opackets[i] = txq->pkts; 11663e730511SRavi Kumar stats->opackets += txq->pkts; 11673e730511SRavi Kumar stats->q_obytes[i] = txq->bytes; 11683e730511SRavi Kumar stats->obytes += txq->bytes; 11699d1ef6b2SChandu Babu N stats->oerrors += txq->errors; 1170bf403cfeSSelwin Sebastian } else { 1171bf403cfeSSelwin Sebastian PMD_DRV_LOG(DEBUG, "Tx queue not setup for port %d\n", 1172bf403cfeSSelwin Sebastian dev->data->port_id); 1173bf403cfeSSelwin Sebastian } 11743e730511SRavi Kumar } 11753e730511SRavi Kumar 11763e730511SRavi Kumar return 0; 11773e730511SRavi Kumar } 11783e730511SRavi Kumar 11799970a9adSIgor Romanov static int 11803e730511SRavi Kumar axgbe_dev_stats_reset(struct rte_eth_dev *dev) 11813e730511SRavi Kumar { 11823e730511SRavi Kumar struct axgbe_rx_queue *rxq; 11833e730511SRavi Kumar struct axgbe_tx_queue *txq; 11843e730511SRavi Kumar unsigned int i; 11853e730511SRavi Kumar 11863e730511SRavi Kumar for (i = 0; i < dev->data->nb_rx_queues; i++) { 11873e730511SRavi Kumar rxq = dev->data->rx_queues[i]; 1188bf403cfeSSelwin Sebastian if (rxq) { 11893e730511SRavi Kumar rxq->pkts = 0; 11903e730511SRavi Kumar rxq->bytes = 0; 11913e730511SRavi Kumar rxq->errors = 0; 11929d1ef6b2SChandu Babu N rxq->rx_mbuf_alloc_failed = 0; 1193bf403cfeSSelwin Sebastian } else { 1194bf403cfeSSelwin Sebastian PMD_DRV_LOG(DEBUG, "Rx queue not setup for port %d\n", 1195bf403cfeSSelwin Sebastian dev->data->port_id); 1196bf403cfeSSelwin Sebastian } 11973e730511SRavi Kumar } 11983e730511SRavi Kumar for (i = 0; i < dev->data->nb_tx_queues; i++) { 11993e730511SRavi Kumar txq = dev->data->tx_queues[i]; 1200bf403cfeSSelwin Sebastian if (txq) { 12013e730511SRavi Kumar txq->pkts = 0; 12023e730511SRavi Kumar txq->bytes = 0; 12033e730511SRavi Kumar txq->errors = 0; 1204bf403cfeSSelwin Sebastian } else { 1205bf403cfeSSelwin Sebastian PMD_DRV_LOG(DEBUG, "Tx queue not setup for port %d\n", 1206bf403cfeSSelwin Sebastian dev->data->port_id); 1207bf403cfeSSelwin Sebastian } 12083e730511SRavi Kumar } 12099970a9adSIgor Romanov 12109970a9adSIgor Romanov return 0; 12113e730511SRavi Kumar } 12123e730511SRavi Kumar 1213bdad90d1SIvan Ilchenko static int 1214cd8c7c7cSFerruh Yigit axgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) 12159e890103SRavi Kumar { 12169e890103SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 12179e890103SRavi Kumar 12189e890103SRavi Kumar dev_info->max_rx_queues = pdata->rx_ring_count; 12199e890103SRavi Kumar dev_info->max_tx_queues = pdata->tx_ring_count; 12209e890103SRavi Kumar dev_info->min_rx_bufsize = AXGBE_RX_MIN_BUF_SIZE; 12219e890103SRavi Kumar dev_info->max_rx_pktlen = AXGBE_RX_MAX_BUF_SIZE; 122249a5e622SChandu Babu N dev_info->max_mac_addrs = pdata->hw_feat.addn_mac + 1; 1223e01d9b2eSChandu Babu N dev_info->max_hash_mac_addrs = pdata->hw_feat.hash_table_size; 1224295968d1SFerruh Yigit dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G; 12259e890103SRavi Kumar 12269e890103SRavi Kumar dev_info->rx_offload_capa = 1227295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_VLAN_STRIP | 1228295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_VLAN_FILTER | 1229295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_VLAN_EXTEND | 1230295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | 1231295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_UDP_CKSUM | 1232295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_TCP_CKSUM | 1233295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_SCATTER | 1234295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_KEEP_CRC; 12359e890103SRavi Kumar 12369e890103SRavi Kumar dev_info->tx_offload_capa = 1237295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_VLAN_INSERT | 1238295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_QINQ_INSERT | 1239295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | 124093bffd8fSBhagyada Modali RTE_ETH_TX_OFFLOAD_MULTI_SEGS | 1241295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_UDP_CKSUM | 1242295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_TCP_CKSUM; 12439e890103SRavi Kumar 12449e890103SRavi Kumar if (pdata->hw_feat.rss) { 12459e890103SRavi Kumar dev_info->flow_type_rss_offloads = AXGBE_RSS_OFFLOAD; 12469e890103SRavi Kumar dev_info->reta_size = pdata->hw_feat.hash_table_size; 12479e890103SRavi Kumar dev_info->hash_key_size = AXGBE_RSS_HASH_KEY_SIZE; 12489e890103SRavi Kumar } 12499e890103SRavi Kumar 12509e890103SRavi Kumar dev_info->rx_desc_lim = rx_desc_lim; 12519e890103SRavi Kumar dev_info->tx_desc_lim = tx_desc_lim; 12529e890103SRavi Kumar 12539e890103SRavi Kumar dev_info->default_rxconf = (struct rte_eth_rxconf) { 12549e890103SRavi Kumar .rx_free_thresh = AXGBE_RX_FREE_THRESH, 12559e890103SRavi Kumar }; 12569e890103SRavi Kumar 12579e890103SRavi Kumar dev_info->default_txconf = (struct rte_eth_txconf) { 12589e890103SRavi Kumar .tx_free_thresh = AXGBE_TX_FREE_THRESH, 12599e890103SRavi Kumar }; 1260bdad90d1SIvan Ilchenko 1261bdad90d1SIvan Ilchenko return 0; 12629e890103SRavi Kumar } 12639e890103SRavi Kumar 1264cf97f33eSAmaranath Somalapuram static int 1265cf97f33eSAmaranath Somalapuram axgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) 1266cf97f33eSAmaranath Somalapuram { 1267cf97f33eSAmaranath Somalapuram struct axgbe_port *pdata = dev->data->dev_private; 1268cf97f33eSAmaranath Somalapuram struct xgbe_fc_info fc = pdata->fc; 1269cf97f33eSAmaranath Somalapuram unsigned int reg, reg_val = 0; 1270cf97f33eSAmaranath Somalapuram 1271cf97f33eSAmaranath Somalapuram reg = MAC_Q0TFCR; 1272cf97f33eSAmaranath Somalapuram reg_val = AXGMAC_IOREAD(pdata, reg); 1273cf97f33eSAmaranath Somalapuram fc.low_water[0] = AXGMAC_MTL_IOREAD_BITS(pdata, 0, MTL_Q_RQFCR, RFA); 1274cf97f33eSAmaranath Somalapuram fc.high_water[0] = AXGMAC_MTL_IOREAD_BITS(pdata, 0, MTL_Q_RQFCR, RFD); 1275cf97f33eSAmaranath Somalapuram fc.pause_time[0] = AXGMAC_GET_BITS(reg_val, MAC_Q0TFCR, PT); 1276cf97f33eSAmaranath Somalapuram fc.autoneg = pdata->pause_autoneg; 1277cf97f33eSAmaranath Somalapuram 1278cf97f33eSAmaranath Somalapuram if (pdata->rx_pause && pdata->tx_pause) 1279295968d1SFerruh Yigit fc.mode = RTE_ETH_FC_FULL; 1280cf97f33eSAmaranath Somalapuram else if (pdata->rx_pause) 1281295968d1SFerruh Yigit fc.mode = RTE_ETH_FC_RX_PAUSE; 1282cf97f33eSAmaranath Somalapuram else if (pdata->tx_pause) 1283295968d1SFerruh Yigit fc.mode = RTE_ETH_FC_TX_PAUSE; 1284cf97f33eSAmaranath Somalapuram else 1285295968d1SFerruh Yigit fc.mode = RTE_ETH_FC_NONE; 1286cf97f33eSAmaranath Somalapuram 1287cf97f33eSAmaranath Somalapuram fc_conf->high_water = (1024 + (fc.low_water[0] << 9)) / 1024; 1288cf97f33eSAmaranath Somalapuram fc_conf->low_water = (1024 + (fc.high_water[0] << 9)) / 1024; 1289cf97f33eSAmaranath Somalapuram fc_conf->pause_time = fc.pause_time[0]; 1290cf97f33eSAmaranath Somalapuram fc_conf->send_xon = fc.send_xon; 1291cf97f33eSAmaranath Somalapuram fc_conf->mode = fc.mode; 1292cf97f33eSAmaranath Somalapuram 1293cf97f33eSAmaranath Somalapuram return 0; 1294cf97f33eSAmaranath Somalapuram } 1295cf97f33eSAmaranath Somalapuram 1296cf97f33eSAmaranath Somalapuram static int 1297cf97f33eSAmaranath Somalapuram axgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) 1298cf97f33eSAmaranath Somalapuram { 1299cf97f33eSAmaranath Somalapuram struct axgbe_port *pdata = dev->data->dev_private; 1300cf97f33eSAmaranath Somalapuram struct xgbe_fc_info fc = pdata->fc; 1301cf97f33eSAmaranath Somalapuram unsigned int reg, reg_val = 0; 1302cf97f33eSAmaranath Somalapuram reg = MAC_Q0TFCR; 1303cf97f33eSAmaranath Somalapuram 1304cf97f33eSAmaranath Somalapuram pdata->pause_autoneg = fc_conf->autoneg; 1305cf97f33eSAmaranath Somalapuram pdata->phy.pause_autoneg = pdata->pause_autoneg; 1306cf97f33eSAmaranath Somalapuram fc.send_xon = fc_conf->send_xon; 1307cf97f33eSAmaranath Somalapuram AXGMAC_MTL_IOWRITE_BITS(pdata, 0, MTL_Q_RQFCR, RFA, 1308cf97f33eSAmaranath Somalapuram AXGMAC_FLOW_CONTROL_VALUE(1024 * fc_conf->high_water)); 1309cf97f33eSAmaranath Somalapuram AXGMAC_MTL_IOWRITE_BITS(pdata, 0, MTL_Q_RQFCR, RFD, 1310cf97f33eSAmaranath Somalapuram AXGMAC_FLOW_CONTROL_VALUE(1024 * fc_conf->low_water)); 1311cf97f33eSAmaranath Somalapuram AXGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, fc_conf->pause_time); 1312cf97f33eSAmaranath Somalapuram AXGMAC_IOWRITE(pdata, reg, reg_val); 1313cf97f33eSAmaranath Somalapuram fc.mode = fc_conf->mode; 1314cf97f33eSAmaranath Somalapuram 1315295968d1SFerruh Yigit if (fc.mode == RTE_ETH_FC_FULL) { 1316cf97f33eSAmaranath Somalapuram pdata->tx_pause = 1; 1317cf97f33eSAmaranath Somalapuram pdata->rx_pause = 1; 1318295968d1SFerruh Yigit } else if (fc.mode == RTE_ETH_FC_RX_PAUSE) { 1319cf97f33eSAmaranath Somalapuram pdata->tx_pause = 0; 1320cf97f33eSAmaranath Somalapuram pdata->rx_pause = 1; 1321295968d1SFerruh Yigit } else if (fc.mode == RTE_ETH_FC_TX_PAUSE) { 1322cf97f33eSAmaranath Somalapuram pdata->tx_pause = 1; 1323cf97f33eSAmaranath Somalapuram pdata->rx_pause = 0; 1324cf97f33eSAmaranath Somalapuram } else { 1325cf97f33eSAmaranath Somalapuram pdata->tx_pause = 0; 1326cf97f33eSAmaranath Somalapuram pdata->rx_pause = 0; 1327cf97f33eSAmaranath Somalapuram } 1328cf97f33eSAmaranath Somalapuram 1329cf97f33eSAmaranath Somalapuram if (pdata->tx_pause != (unsigned int)pdata->phy.tx_pause) 1330cf97f33eSAmaranath Somalapuram pdata->hw_if.config_tx_flow_control(pdata); 1331cf97f33eSAmaranath Somalapuram 1332cf97f33eSAmaranath Somalapuram if (pdata->rx_pause != (unsigned int)pdata->phy.rx_pause) 1333cf97f33eSAmaranath Somalapuram pdata->hw_if.config_rx_flow_control(pdata); 1334cf97f33eSAmaranath Somalapuram 1335cf97f33eSAmaranath Somalapuram pdata->hw_if.config_flow_control(pdata); 1336cf97f33eSAmaranath Somalapuram pdata->phy.tx_pause = pdata->tx_pause; 1337cf97f33eSAmaranath Somalapuram pdata->phy.rx_pause = pdata->rx_pause; 1338cf97f33eSAmaranath Somalapuram 1339cf97f33eSAmaranath Somalapuram return 0; 1340cf97f33eSAmaranath Somalapuram } 1341cf97f33eSAmaranath Somalapuram 1342e0543d4eSAmaranath Somalapuram static int 1343e0543d4eSAmaranath Somalapuram axgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, 1344e0543d4eSAmaranath Somalapuram struct rte_eth_pfc_conf *pfc_conf) 1345e0543d4eSAmaranath Somalapuram { 1346e0543d4eSAmaranath Somalapuram struct axgbe_port *pdata = dev->data->dev_private; 1347e0543d4eSAmaranath Somalapuram struct xgbe_fc_info fc = pdata->fc; 1348e0543d4eSAmaranath Somalapuram uint8_t tc_num; 1349e0543d4eSAmaranath Somalapuram 1350e0543d4eSAmaranath Somalapuram tc_num = pdata->pfc_map[pfc_conf->priority]; 1351e0543d4eSAmaranath Somalapuram 1352e0543d4eSAmaranath Somalapuram if (pfc_conf->priority >= pdata->hw_feat.tc_cnt) { 1353e0543d4eSAmaranath Somalapuram PMD_INIT_LOG(ERR, "Max supported traffic class: %d\n", 1354e0543d4eSAmaranath Somalapuram pdata->hw_feat.tc_cnt); 1355e0543d4eSAmaranath Somalapuram return -EINVAL; 1356e0543d4eSAmaranath Somalapuram } 1357e0543d4eSAmaranath Somalapuram 1358e0543d4eSAmaranath Somalapuram pdata->pause_autoneg = pfc_conf->fc.autoneg; 1359e0543d4eSAmaranath Somalapuram pdata->phy.pause_autoneg = pdata->pause_autoneg; 1360e0543d4eSAmaranath Somalapuram fc.send_xon = pfc_conf->fc.send_xon; 1361e0543d4eSAmaranath Somalapuram AXGMAC_MTL_IOWRITE_BITS(pdata, tc_num, MTL_Q_RQFCR, RFA, 1362e0543d4eSAmaranath Somalapuram AXGMAC_FLOW_CONTROL_VALUE(1024 * pfc_conf->fc.high_water)); 1363e0543d4eSAmaranath Somalapuram AXGMAC_MTL_IOWRITE_BITS(pdata, tc_num, MTL_Q_RQFCR, RFD, 1364e0543d4eSAmaranath Somalapuram AXGMAC_FLOW_CONTROL_VALUE(1024 * pfc_conf->fc.low_water)); 1365e0543d4eSAmaranath Somalapuram 1366e0543d4eSAmaranath Somalapuram switch (tc_num) { 1367e0543d4eSAmaranath Somalapuram case 0: 1368e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R, 1369e0543d4eSAmaranath Somalapuram PSTC0, pfc_conf->fc.pause_time); 1370e0543d4eSAmaranath Somalapuram break; 1371e0543d4eSAmaranath Somalapuram case 1: 1372e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R, 1373e0543d4eSAmaranath Somalapuram PSTC1, pfc_conf->fc.pause_time); 1374e0543d4eSAmaranath Somalapuram break; 1375e0543d4eSAmaranath Somalapuram case 2: 1376e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R, 1377e0543d4eSAmaranath Somalapuram PSTC2, pfc_conf->fc.pause_time); 1378e0543d4eSAmaranath Somalapuram break; 1379e0543d4eSAmaranath Somalapuram case 3: 1380e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R, 1381e0543d4eSAmaranath Somalapuram PSTC3, pfc_conf->fc.pause_time); 1382e0543d4eSAmaranath Somalapuram break; 1383e0543d4eSAmaranath Somalapuram case 4: 1384e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R, 1385e0543d4eSAmaranath Somalapuram PSTC4, pfc_conf->fc.pause_time); 1386e0543d4eSAmaranath Somalapuram break; 1387e0543d4eSAmaranath Somalapuram case 5: 1388e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R, 1389e0543d4eSAmaranath Somalapuram PSTC5, pfc_conf->fc.pause_time); 1390e0543d4eSAmaranath Somalapuram break; 1391e0543d4eSAmaranath Somalapuram case 7: 1392e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R, 1393e0543d4eSAmaranath Somalapuram PSTC6, pfc_conf->fc.pause_time); 1394e0543d4eSAmaranath Somalapuram break; 1395e0543d4eSAmaranath Somalapuram case 6: 1396e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R, 1397e0543d4eSAmaranath Somalapuram PSTC7, pfc_conf->fc.pause_time); 1398e0543d4eSAmaranath Somalapuram break; 1399e0543d4eSAmaranath Somalapuram } 1400e0543d4eSAmaranath Somalapuram 1401e0543d4eSAmaranath Somalapuram fc.mode = pfc_conf->fc.mode; 1402e0543d4eSAmaranath Somalapuram 1403295968d1SFerruh Yigit if (fc.mode == RTE_ETH_FC_FULL) { 1404e0543d4eSAmaranath Somalapuram pdata->tx_pause = 1; 1405e0543d4eSAmaranath Somalapuram pdata->rx_pause = 1; 1406e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 1); 1407295968d1SFerruh Yigit } else if (fc.mode == RTE_ETH_FC_RX_PAUSE) { 1408e0543d4eSAmaranath Somalapuram pdata->tx_pause = 0; 1409e0543d4eSAmaranath Somalapuram pdata->rx_pause = 1; 1410e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 1); 1411295968d1SFerruh Yigit } else if (fc.mode == RTE_ETH_FC_TX_PAUSE) { 1412e0543d4eSAmaranath Somalapuram pdata->tx_pause = 1; 1413e0543d4eSAmaranath Somalapuram pdata->rx_pause = 0; 1414e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0); 1415e0543d4eSAmaranath Somalapuram } else { 1416e0543d4eSAmaranath Somalapuram pdata->tx_pause = 0; 1417e0543d4eSAmaranath Somalapuram pdata->rx_pause = 0; 1418e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0); 1419e0543d4eSAmaranath Somalapuram } 1420e0543d4eSAmaranath Somalapuram 1421e0543d4eSAmaranath Somalapuram if (pdata->tx_pause != (unsigned int)pdata->phy.tx_pause) 1422e0543d4eSAmaranath Somalapuram pdata->hw_if.config_tx_flow_control(pdata); 1423e0543d4eSAmaranath Somalapuram 1424e0543d4eSAmaranath Somalapuram if (pdata->rx_pause != (unsigned int)pdata->phy.rx_pause) 1425e0543d4eSAmaranath Somalapuram pdata->hw_if.config_rx_flow_control(pdata); 1426e0543d4eSAmaranath Somalapuram pdata->hw_if.config_flow_control(pdata); 1427e0543d4eSAmaranath Somalapuram pdata->phy.tx_pause = pdata->tx_pause; 1428e0543d4eSAmaranath Somalapuram pdata->phy.rx_pause = pdata->rx_pause; 1429e0543d4eSAmaranath Somalapuram 1430e0543d4eSAmaranath Somalapuram return 0; 1431e0543d4eSAmaranath Somalapuram } 1432e0543d4eSAmaranath Somalapuram 14337aed95c9SAmaranath Somalapuram void 14347aed95c9SAmaranath Somalapuram axgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 14357aed95c9SAmaranath Somalapuram struct rte_eth_rxq_info *qinfo) 14367aed95c9SAmaranath Somalapuram { 14377aed95c9SAmaranath Somalapuram struct axgbe_rx_queue *rxq; 14387aed95c9SAmaranath Somalapuram 14397aed95c9SAmaranath Somalapuram rxq = dev->data->rx_queues[queue_id]; 14407aed95c9SAmaranath Somalapuram qinfo->mp = rxq->mb_pool; 14417aed95c9SAmaranath Somalapuram qinfo->scattered_rx = dev->data->scattered_rx; 14427aed95c9SAmaranath Somalapuram qinfo->nb_desc = rxq->nb_desc; 14437aed95c9SAmaranath Somalapuram qinfo->conf.rx_free_thresh = rxq->free_thresh; 14447aed95c9SAmaranath Somalapuram } 14457aed95c9SAmaranath Somalapuram 14467aed95c9SAmaranath Somalapuram void 14477aed95c9SAmaranath Somalapuram axgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 14487aed95c9SAmaranath Somalapuram struct rte_eth_txq_info *qinfo) 14497aed95c9SAmaranath Somalapuram { 14507aed95c9SAmaranath Somalapuram struct axgbe_tx_queue *txq; 14517aed95c9SAmaranath Somalapuram 14527aed95c9SAmaranath Somalapuram txq = dev->data->tx_queues[queue_id]; 14537aed95c9SAmaranath Somalapuram qinfo->nb_desc = txq->nb_desc; 14547aed95c9SAmaranath Somalapuram qinfo->conf.tx_free_thresh = txq->free_thresh; 14557aed95c9SAmaranath Somalapuram } 1456410cf087SAmaranath Somalapuram const uint32_t * 1457410cf087SAmaranath Somalapuram axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev) 1458410cf087SAmaranath Somalapuram { 1459410cf087SAmaranath Somalapuram static const uint32_t ptypes[] = { 1460410cf087SAmaranath Somalapuram RTE_PTYPE_L2_ETHER, 1461410cf087SAmaranath Somalapuram RTE_PTYPE_L2_ETHER_TIMESYNC, 1462410cf087SAmaranath Somalapuram RTE_PTYPE_L2_ETHER_LLDP, 1463410cf087SAmaranath Somalapuram RTE_PTYPE_L2_ETHER_ARP, 1464410cf087SAmaranath Somalapuram RTE_PTYPE_L3_IPV4_EXT_UNKNOWN, 1465410cf087SAmaranath Somalapuram RTE_PTYPE_L3_IPV6_EXT_UNKNOWN, 1466410cf087SAmaranath Somalapuram RTE_PTYPE_L4_FRAG, 1467410cf087SAmaranath Somalapuram RTE_PTYPE_L4_ICMP, 1468410cf087SAmaranath Somalapuram RTE_PTYPE_L4_NONFRAG, 1469410cf087SAmaranath Somalapuram RTE_PTYPE_L4_SCTP, 1470410cf087SAmaranath Somalapuram RTE_PTYPE_L4_TCP, 1471410cf087SAmaranath Somalapuram RTE_PTYPE_L4_UDP, 1472410cf087SAmaranath Somalapuram RTE_PTYPE_TUNNEL_GRENAT, 1473410cf087SAmaranath Somalapuram RTE_PTYPE_TUNNEL_IP, 1474410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L2_ETHER, 1475410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L2_ETHER_VLAN, 1476410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN, 1477410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN, 1478410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_FRAG, 1479410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_ICMP, 1480410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_NONFRAG, 1481410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_SCTP, 1482410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_TCP, 1483410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_UDP, 1484410cf087SAmaranath Somalapuram RTE_PTYPE_UNKNOWN 1485410cf087SAmaranath Somalapuram }; 1486410cf087SAmaranath Somalapuram 1487410cf087SAmaranath Somalapuram if (dev->rx_pkt_burst == axgbe_recv_pkts) 1488410cf087SAmaranath Somalapuram return ptypes; 1489410cf087SAmaranath Somalapuram return NULL; 1490410cf087SAmaranath Somalapuram } 1491e0444948SSelwin Sebastian 1492b58d8781SGirish Nandibasappa static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) 1493b58d8781SGirish Nandibasappa { 1494b58d8781SGirish Nandibasappa struct axgbe_port *pdata = dev->data->dev_private; 1495f7e04f57SFerruh Yigit unsigned int val; 1496f7e04f57SFerruh Yigit 1497b58d8781SGirish Nandibasappa /* mtu setting is forbidden if port is start */ 1498b58d8781SGirish Nandibasappa if (dev->data->dev_started) { 1499b58d8781SGirish Nandibasappa PMD_DRV_LOG(ERR, "port %d must be stopped before configuration", 1500b58d8781SGirish Nandibasappa dev->data->port_id); 1501b58d8781SGirish Nandibasappa return -EBUSY; 1502b58d8781SGirish Nandibasappa } 1503f7e04f57SFerruh Yigit val = mtu > RTE_ETHER_MTU ? 1 : 0; 1504b58d8781SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val); 1505f7e04f57SFerruh Yigit 1506b58d8781SGirish Nandibasappa return 0; 1507b58d8781SGirish Nandibasappa } 1508e0444948SSelwin Sebastian 1509e0444948SSelwin Sebastian static void 1510e0444948SSelwin Sebastian axgbe_update_tstamp_time(struct axgbe_port *pdata, 1511e0444948SSelwin Sebastian unsigned int sec, unsigned int nsec, int addsub) 1512e0444948SSelwin Sebastian { 1513e0444948SSelwin Sebastian unsigned int count = 100; 1514e0444948SSelwin Sebastian uint32_t sub_val = 0; 1515e0444948SSelwin Sebastian uint32_t sub_val_sec = 0xFFFFFFFF; 1516e0444948SSelwin Sebastian uint32_t sub_val_nsec = 0x3B9ACA00; 1517e0444948SSelwin Sebastian 1518e0444948SSelwin Sebastian if (addsub) { 1519e0444948SSelwin Sebastian if (sec) 1520e0444948SSelwin Sebastian sub_val = sub_val_sec - (sec - 1); 1521e0444948SSelwin Sebastian else 1522e0444948SSelwin Sebastian sub_val = sec; 1523e0444948SSelwin Sebastian 1524e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STSUR, sub_val); 1525e0444948SSelwin Sebastian sub_val = sub_val_nsec - nsec; 1526e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STNUR, sub_val); 1527e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_STNUR, ADDSUB, 1); 1528e0444948SSelwin Sebastian } else { 1529e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STSUR, sec); 1530e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_STNUR, ADDSUB, 0); 1531e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STNUR, nsec); 1532e0444948SSelwin Sebastian } 1533e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSUPDT, 1); 1534e0444948SSelwin Sebastian /* Wait for time update to complete */ 1535e0444948SSelwin Sebastian while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSUPDT)) 1536e0444948SSelwin Sebastian rte_delay_ms(1); 1537e0444948SSelwin Sebastian } 1538e0444948SSelwin Sebastian 1539e0444948SSelwin Sebastian static inline uint64_t 1540e0444948SSelwin Sebastian div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder) 1541e0444948SSelwin Sebastian { 1542e0444948SSelwin Sebastian *remainder = dividend % divisor; 1543e0444948SSelwin Sebastian return dividend / divisor; 1544e0444948SSelwin Sebastian } 1545e0444948SSelwin Sebastian 1546e0444948SSelwin Sebastian static inline uint64_t 1547e0444948SSelwin Sebastian div_u64(uint64_t dividend, uint32_t divisor) 1548e0444948SSelwin Sebastian { 1549e0444948SSelwin Sebastian uint32_t remainder; 1550e0444948SSelwin Sebastian return div_u64_rem(dividend, divisor, &remainder); 1551e0444948SSelwin Sebastian } 1552e0444948SSelwin Sebastian 1553e0444948SSelwin Sebastian static int 1554e0444948SSelwin Sebastian axgbe_adjfreq(struct axgbe_port *pdata, int64_t delta) 1555e0444948SSelwin Sebastian { 1556e0444948SSelwin Sebastian uint64_t adjust; 1557e0444948SSelwin Sebastian uint32_t addend, diff; 1558e0444948SSelwin Sebastian unsigned int neg_adjust = 0; 1559e0444948SSelwin Sebastian 1560e0444948SSelwin Sebastian if (delta < 0) { 1561e0444948SSelwin Sebastian neg_adjust = 1; 1562e0444948SSelwin Sebastian delta = -delta; 1563e0444948SSelwin Sebastian } 1564e0444948SSelwin Sebastian adjust = (uint64_t)pdata->tstamp_addend; 1565e0444948SSelwin Sebastian adjust *= delta; 1566e0444948SSelwin Sebastian diff = (uint32_t)div_u64(adjust, 1000000000UL); 1567e0444948SSelwin Sebastian addend = (neg_adjust) ? pdata->tstamp_addend - diff : 1568e0444948SSelwin Sebastian pdata->tstamp_addend + diff; 1569e0444948SSelwin Sebastian pdata->tstamp_addend = addend; 1570e0444948SSelwin Sebastian axgbe_update_tstamp_addend(pdata, addend); 1571e0444948SSelwin Sebastian return 0; 1572e0444948SSelwin Sebastian } 1573e0444948SSelwin Sebastian 1574e0444948SSelwin Sebastian static int 1575e0444948SSelwin Sebastian axgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta) 1576e0444948SSelwin Sebastian { 1577e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1578e0444948SSelwin Sebastian struct timespec timestamp_delta; 1579e0444948SSelwin Sebastian 1580e0444948SSelwin Sebastian axgbe_adjfreq(pdata, delta); 1581e0444948SSelwin Sebastian pdata->systime_tc.nsec += delta; 1582e0444948SSelwin Sebastian 1583e0444948SSelwin Sebastian if (delta < 0) { 1584e0444948SSelwin Sebastian delta = -delta; 1585e0444948SSelwin Sebastian timestamp_delta = rte_ns_to_timespec(delta); 1586e0444948SSelwin Sebastian axgbe_update_tstamp_time(pdata, timestamp_delta.tv_sec, 1587e0444948SSelwin Sebastian timestamp_delta.tv_nsec, 1); 1588e0444948SSelwin Sebastian } else { 1589e0444948SSelwin Sebastian timestamp_delta = rte_ns_to_timespec(delta); 1590e0444948SSelwin Sebastian axgbe_update_tstamp_time(pdata, timestamp_delta.tv_sec, 1591e0444948SSelwin Sebastian timestamp_delta.tv_nsec, 0); 1592e0444948SSelwin Sebastian } 1593e0444948SSelwin Sebastian return 0; 1594e0444948SSelwin Sebastian } 1595e0444948SSelwin Sebastian 1596e0444948SSelwin Sebastian static int 1597e0444948SSelwin Sebastian axgbe_timesync_read_time(struct rte_eth_dev *dev, 1598e0444948SSelwin Sebastian struct timespec *timestamp) 1599e0444948SSelwin Sebastian { 1600e0444948SSelwin Sebastian uint64_t nsec; 1601e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1602e0444948SSelwin Sebastian 1603e0444948SSelwin Sebastian nsec = AXGMAC_IOREAD(pdata, MAC_STSR); 1604e0444948SSelwin Sebastian nsec *= NSEC_PER_SEC; 1605e0444948SSelwin Sebastian nsec += AXGMAC_IOREAD(pdata, MAC_STNR); 1606e0444948SSelwin Sebastian *timestamp = rte_ns_to_timespec(nsec); 1607e0444948SSelwin Sebastian return 0; 1608e0444948SSelwin Sebastian } 1609e0444948SSelwin Sebastian static int 1610e0444948SSelwin Sebastian axgbe_timesync_write_time(struct rte_eth_dev *dev, 1611e0444948SSelwin Sebastian const struct timespec *timestamp) 1612e0444948SSelwin Sebastian { 1613e0444948SSelwin Sebastian unsigned int count = 100; 1614e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1615e0444948SSelwin Sebastian 1616e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STSUR, timestamp->tv_sec); 1617e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STNUR, timestamp->tv_nsec); 1618e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSUPDT, 1); 1619e0444948SSelwin Sebastian /* Wait for time update to complete */ 1620e0444948SSelwin Sebastian while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSUPDT)) 1621e0444948SSelwin Sebastian rte_delay_ms(1); 1622e0444948SSelwin Sebastian if (!count) 1623e0444948SSelwin Sebastian PMD_DRV_LOG(ERR, "Timed out update timestamp\n"); 1624e0444948SSelwin Sebastian return 0; 1625e0444948SSelwin Sebastian } 1626e0444948SSelwin Sebastian 1627e0444948SSelwin Sebastian static void 1628e0444948SSelwin Sebastian axgbe_update_tstamp_addend(struct axgbe_port *pdata, 1629e0444948SSelwin Sebastian uint32_t addend) 1630e0444948SSelwin Sebastian { 1631e0444948SSelwin Sebastian unsigned int count = 100; 1632e0444948SSelwin Sebastian 1633e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_TSAR, addend); 1634e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1); 1635e0444948SSelwin Sebastian 1636e0444948SSelwin Sebastian /* Wait for addend update to complete */ 1637e0444948SSelwin Sebastian while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG)) 1638e0444948SSelwin Sebastian rte_delay_ms(1); 1639e0444948SSelwin Sebastian if (!count) 1640e0444948SSelwin Sebastian PMD_DRV_LOG(ERR, "Timed out updating timestamp addend register\n"); 1641e0444948SSelwin Sebastian } 1642e0444948SSelwin Sebastian 1643e0444948SSelwin Sebastian static void 1644e0444948SSelwin Sebastian axgbe_set_tstamp_time(struct axgbe_port *pdata, unsigned int sec, 1645e0444948SSelwin Sebastian unsigned int nsec) 1646e0444948SSelwin Sebastian { 1647e0444948SSelwin Sebastian unsigned int count = 100; 1648e0444948SSelwin Sebastian 1649e0444948SSelwin Sebastian /*System Time Sec Update*/ 1650e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STSUR, sec); 1651e0444948SSelwin Sebastian /*System Time nanoSec Update*/ 1652e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STNUR, nsec); 1653e0444948SSelwin Sebastian /*Initialize Timestamp*/ 1654e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1); 1655e0444948SSelwin Sebastian 1656e0444948SSelwin Sebastian /* Wait for time update to complete */ 1657e0444948SSelwin Sebastian while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT)) 1658e0444948SSelwin Sebastian rte_delay_ms(1); 1659e0444948SSelwin Sebastian if (!count) 1660e0444948SSelwin Sebastian PMD_DRV_LOG(ERR, "Timed out initializing timestamp\n"); 1661e0444948SSelwin Sebastian } 1662e0444948SSelwin Sebastian 1663e0444948SSelwin Sebastian static int 1664e0444948SSelwin Sebastian axgbe_timesync_enable(struct rte_eth_dev *dev) 1665e0444948SSelwin Sebastian { 1666e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1667e0444948SSelwin Sebastian unsigned int mac_tscr = 0; 1668e0444948SSelwin Sebastian uint64_t dividend; 1669e0444948SSelwin Sebastian struct timespec timestamp; 1670e0444948SSelwin Sebastian uint64_t nsec; 1671e0444948SSelwin Sebastian 1672e0444948SSelwin Sebastian /* Set one nano-second accuracy */ 1673e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1); 1674e0444948SSelwin Sebastian 1675e0444948SSelwin Sebastian /* Set fine timestamp update */ 1676e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1); 1677e0444948SSelwin Sebastian 1678e0444948SSelwin Sebastian /* Overwrite earlier timestamps */ 1679e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1); 1680e0444948SSelwin Sebastian 1681e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr); 1682e0444948SSelwin Sebastian 1683e0444948SSelwin Sebastian /* Enabling processing of ptp over eth pkt */ 1684e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); 1685e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); 1686e0444948SSelwin Sebastian /* Enable timestamp for all pkts*/ 1687e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 1); 1688e0444948SSelwin Sebastian 1689e0444948SSelwin Sebastian /* enabling timestamp */ 1690e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); 1691e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr); 1692e0444948SSelwin Sebastian 1693e0444948SSelwin Sebastian /* Exit if timestamping is not enabled */ 1694e0444948SSelwin Sebastian if (!AXGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA)) { 1695e0444948SSelwin Sebastian PMD_DRV_LOG(ERR, "Exiting as timestamp is not enabled\n"); 1696e0444948SSelwin Sebastian return 0; 1697e0444948SSelwin Sebastian } 1698e0444948SSelwin Sebastian 1699e0444948SSelwin Sebastian /* Sub-second Increment Value*/ 1700e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, AXGBE_TSTAMP_SSINC); 1701e0444948SSelwin Sebastian /* Sub-nanosecond Increment Value */ 1702e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, AXGBE_TSTAMP_SNSINC); 1703e0444948SSelwin Sebastian 1704e0444948SSelwin Sebastian pdata->ptpclk_rate = AXGBE_V2_PTP_CLOCK_FREQ; 1705e0444948SSelwin Sebastian dividend = 50000000; 1706e0444948SSelwin Sebastian dividend <<= 32; 1707e0444948SSelwin Sebastian pdata->tstamp_addend = div_u64(dividend, pdata->ptpclk_rate); 1708e0444948SSelwin Sebastian 1709e0444948SSelwin Sebastian axgbe_update_tstamp_addend(pdata, pdata->tstamp_addend); 1710e0444948SSelwin Sebastian axgbe_set_tstamp_time(pdata, 0, 0); 1711e0444948SSelwin Sebastian 1712e0444948SSelwin Sebastian /* Initialize the timecounter */ 1713e0444948SSelwin Sebastian memset(&pdata->systime_tc, 0, sizeof(struct rte_timecounter)); 1714e0444948SSelwin Sebastian 1715e0444948SSelwin Sebastian pdata->systime_tc.cc_mask = AXGBE_CYCLECOUNTER_MASK; 1716e0444948SSelwin Sebastian pdata->systime_tc.cc_shift = 0; 1717e0444948SSelwin Sebastian pdata->systime_tc.nsec_mask = 0; 1718e0444948SSelwin Sebastian 1719e0444948SSelwin Sebastian PMD_DRV_LOG(DEBUG, "Initializing system time counter with realtime\n"); 1720e0444948SSelwin Sebastian 1721e0444948SSelwin Sebastian /* Updating the counter once with clock real time */ 1722e0444948SSelwin Sebastian clock_gettime(CLOCK_REALTIME, ×tamp); 1723e0444948SSelwin Sebastian nsec = rte_timespec_to_ns(×tamp); 1724e0444948SSelwin Sebastian nsec = rte_timecounter_update(&pdata->systime_tc, nsec); 1725e0444948SSelwin Sebastian axgbe_set_tstamp_time(pdata, timestamp.tv_sec, timestamp.tv_nsec); 1726e0444948SSelwin Sebastian return 0; 1727e0444948SSelwin Sebastian } 1728e0444948SSelwin Sebastian 1729e0444948SSelwin Sebastian static int 1730e0444948SSelwin Sebastian axgbe_timesync_disable(struct rte_eth_dev *dev) 1731e0444948SSelwin Sebastian { 1732e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1733e0444948SSelwin Sebastian unsigned int mac_tscr = 0; 1734e0444948SSelwin Sebastian 1735e0444948SSelwin Sebastian /*disable timestamp for all pkts*/ 1736e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 0); 1737e0444948SSelwin Sebastian /*disable the addened register*/ 1738e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 0); 1739e0444948SSelwin Sebastian /* disable timestamp update */ 1740e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 0); 1741e0444948SSelwin Sebastian /*disable time stamp*/ 1742e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 0); 1743e0444948SSelwin Sebastian return 0; 1744e0444948SSelwin Sebastian } 1745e0444948SSelwin Sebastian 1746e0444948SSelwin Sebastian static int 1747e0444948SSelwin Sebastian axgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev, 1748e0444948SSelwin Sebastian struct timespec *timestamp, uint32_t flags) 1749e0444948SSelwin Sebastian { 1750e0444948SSelwin Sebastian uint64_t nsec = 0; 1751e0444948SSelwin Sebastian volatile union axgbe_rx_desc *desc; 1752e0444948SSelwin Sebastian uint16_t idx, pmt; 1753e0444948SSelwin Sebastian struct axgbe_rx_queue *rxq = *dev->data->rx_queues; 1754e0444948SSelwin Sebastian 1755e0444948SSelwin Sebastian idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur); 1756e0444948SSelwin Sebastian desc = &rxq->desc[idx]; 1757e0444948SSelwin Sebastian 1758e0444948SSelwin Sebastian while (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN)) 1759e0444948SSelwin Sebastian rte_delay_ms(1); 1760e0444948SSelwin Sebastian if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, CTXT)) { 1761e0444948SSelwin Sebastian if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_CONTEXT_DESC3, TSA) && 1762e0444948SSelwin Sebastian !AXGMAC_GET_BITS_LE(desc->write.desc3, 1763e0444948SSelwin Sebastian RX_CONTEXT_DESC3, TSD)) { 1764e0444948SSelwin Sebastian pmt = AXGMAC_GET_BITS_LE(desc->write.desc3, 1765e0444948SSelwin Sebastian RX_CONTEXT_DESC3, PMT); 1766e0444948SSelwin Sebastian nsec = rte_le_to_cpu_32(desc->write.desc1); 1767e0444948SSelwin Sebastian nsec *= NSEC_PER_SEC; 1768e0444948SSelwin Sebastian nsec += rte_le_to_cpu_32(desc->write.desc0); 1769e0444948SSelwin Sebastian if (nsec != 0xffffffffffffffffULL) { 1770e0444948SSelwin Sebastian if (pmt == 0x01) 1771e0444948SSelwin Sebastian *timestamp = rte_ns_to_timespec(nsec); 1772e0444948SSelwin Sebastian PMD_DRV_LOG(DEBUG, 1773e0444948SSelwin Sebastian "flags = 0x%x nsec = %"PRIu64"\n", 1774e0444948SSelwin Sebastian flags, nsec); 1775e0444948SSelwin Sebastian } 1776e0444948SSelwin Sebastian } 1777e0444948SSelwin Sebastian } 1778e0444948SSelwin Sebastian 1779e0444948SSelwin Sebastian return 0; 1780e0444948SSelwin Sebastian } 1781e0444948SSelwin Sebastian 1782e0444948SSelwin Sebastian static int 1783e0444948SSelwin Sebastian axgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev, 1784e0444948SSelwin Sebastian struct timespec *timestamp) 1785e0444948SSelwin Sebastian { 1786e0444948SSelwin Sebastian uint64_t nsec; 1787e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1788e0444948SSelwin Sebastian unsigned int tx_snr, tx_ssr; 1789e0444948SSelwin Sebastian 1790e0444948SSelwin Sebastian rte_delay_us(5); 1791e0444948SSelwin Sebastian if (pdata->vdata->tx_tstamp_workaround) { 1792e0444948SSelwin Sebastian tx_snr = AXGMAC_IOREAD(pdata, MAC_TXSNR); 1793e0444948SSelwin Sebastian tx_ssr = AXGMAC_IOREAD(pdata, MAC_TXSSR); 1794e0444948SSelwin Sebastian 1795e0444948SSelwin Sebastian } else { 1796e0444948SSelwin Sebastian tx_ssr = AXGMAC_IOREAD(pdata, MAC_TXSSR); 1797e0444948SSelwin Sebastian tx_snr = AXGMAC_IOREAD(pdata, MAC_TXSNR); 1798e0444948SSelwin Sebastian } 1799e0444948SSelwin Sebastian if (AXGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS)) { 1800e0444948SSelwin Sebastian PMD_DRV_LOG(DEBUG, "Waiting for TXTSSTSMIS\n"); 1801e0444948SSelwin Sebastian return 0; 1802e0444948SSelwin Sebastian } 1803e0444948SSelwin Sebastian nsec = tx_ssr; 1804e0444948SSelwin Sebastian nsec *= NSEC_PER_SEC; 1805e0444948SSelwin Sebastian nsec += tx_snr; 1806e0444948SSelwin Sebastian PMD_DRV_LOG(DEBUG, "nsec = %"PRIu64" tx_ssr = %d tx_snr = %d\n", 1807e0444948SSelwin Sebastian nsec, tx_ssr, tx_snr); 1808e0444948SSelwin Sebastian *timestamp = rte_ns_to_timespec(nsec); 1809e0444948SSelwin Sebastian return 0; 1810e0444948SSelwin Sebastian } 1811e0444948SSelwin Sebastian 181286578516SGirish Nandibasappa static int 181386578516SGirish Nandibasappa axgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on) 181486578516SGirish Nandibasappa { 181586578516SGirish Nandibasappa struct axgbe_port *pdata = dev->data->dev_private; 181686578516SGirish Nandibasappa unsigned long vid_bit, vid_idx; 181786578516SGirish Nandibasappa 181886578516SGirish Nandibasappa vid_bit = VLAN_TABLE_BIT(vid); 181986578516SGirish Nandibasappa vid_idx = VLAN_TABLE_IDX(vid); 182086578516SGirish Nandibasappa 182186578516SGirish Nandibasappa if (on) { 182286578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Set VLAN vid=%d for device = %s\n", 182386578516SGirish Nandibasappa vid, pdata->eth_dev->device->name); 182486578516SGirish Nandibasappa pdata->active_vlans[vid_idx] |= vid_bit; 182586578516SGirish Nandibasappa } else { 182686578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Reset VLAN vid=%d for device = %s\n", 182786578516SGirish Nandibasappa vid, pdata->eth_dev->device->name); 182886578516SGirish Nandibasappa pdata->active_vlans[vid_idx] &= ~vid_bit; 182986578516SGirish Nandibasappa } 183086578516SGirish Nandibasappa pdata->hw_if.update_vlan_hash_table(pdata); 183186578516SGirish Nandibasappa return 0; 183286578516SGirish Nandibasappa } 183386578516SGirish Nandibasappa 183486578516SGirish Nandibasappa static int 183586578516SGirish Nandibasappa axgbe_vlan_tpid_set(struct rte_eth_dev *dev, 183686578516SGirish Nandibasappa enum rte_vlan_type vlan_type, 183786578516SGirish Nandibasappa uint16_t tpid) 183886578516SGirish Nandibasappa { 183986578516SGirish Nandibasappa struct axgbe_port *pdata = dev->data->dev_private; 184086578516SGirish Nandibasappa uint32_t reg = 0; 184186578516SGirish Nandibasappa uint32_t qinq = 0; 184286578516SGirish Nandibasappa 184386578516SGirish Nandibasappa qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP); 184486578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "EDVLP: qinq = 0x%x\n", qinq); 184586578516SGirish Nandibasappa 184686578516SGirish Nandibasappa switch (vlan_type) { 1847295968d1SFerruh Yigit case RTE_ETH_VLAN_TYPE_INNER: 1848295968d1SFerruh Yigit PMD_DRV_LOG(DEBUG, "RTE_ETH_VLAN_TYPE_INNER\n"); 184986578516SGirish Nandibasappa if (qinq) { 185086578516SGirish Nandibasappa if (tpid != 0x8100 && tpid != 0x88a8) 185186578516SGirish Nandibasappa PMD_DRV_LOG(ERR, 185286578516SGirish Nandibasappa "tag supported 0x8100/0x88A8\n"); 185386578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "qinq with inner tag\n"); 185486578516SGirish Nandibasappa 185586578516SGirish Nandibasappa /*Enable Inner VLAN Tag */ 185686578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERIVLT, 1); 185786578516SGirish Nandibasappa reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, ERIVLT); 185886578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "bit ERIVLT = 0x%x\n", reg); 185986578516SGirish Nandibasappa 186086578516SGirish Nandibasappa } else { 186186578516SGirish Nandibasappa PMD_DRV_LOG(ERR, 186286578516SGirish Nandibasappa "Inner type not supported in single tag\n"); 186386578516SGirish Nandibasappa } 186486578516SGirish Nandibasappa break; 1865295968d1SFerruh Yigit case RTE_ETH_VLAN_TYPE_OUTER: 1866295968d1SFerruh Yigit PMD_DRV_LOG(DEBUG, "RTE_ETH_VLAN_TYPE_OUTER\n"); 186786578516SGirish Nandibasappa if (qinq) { 186886578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "double tagging is enabled\n"); 186986578516SGirish Nandibasappa /*Enable outer VLAN tag*/ 187086578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERIVLT, 0); 187186578516SGirish Nandibasappa reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, ERIVLT); 187286578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "bit ERIVLT = 0x%x\n", reg); 187386578516SGirish Nandibasappa 187486578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 1); 187586578516SGirish Nandibasappa reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANIR, CSVL); 187686578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "bit CSVL = 0x%x\n", reg); 187786578516SGirish Nandibasappa } else { 187886578516SGirish Nandibasappa if (tpid != 0x8100 && tpid != 0x88a8) 187986578516SGirish Nandibasappa PMD_DRV_LOG(ERR, 188086578516SGirish Nandibasappa "tag supported 0x8100/0x88A8\n"); 188186578516SGirish Nandibasappa } 188286578516SGirish Nandibasappa break; 1883295968d1SFerruh Yigit case RTE_ETH_VLAN_TYPE_MAX: 1884295968d1SFerruh Yigit PMD_DRV_LOG(ERR, "RTE_ETH_VLAN_TYPE_MAX\n"); 188586578516SGirish Nandibasappa break; 1886295968d1SFerruh Yigit case RTE_ETH_VLAN_TYPE_UNKNOWN: 1887295968d1SFerruh Yigit PMD_DRV_LOG(ERR, "RTE_ETH_VLAN_TYPE_UNKNOWN\n"); 188886578516SGirish Nandibasappa break; 188986578516SGirish Nandibasappa } 189086578516SGirish Nandibasappa return 0; 189186578516SGirish Nandibasappa } 189286578516SGirish Nandibasappa 189386578516SGirish Nandibasappa static void axgbe_vlan_extend_enable(struct axgbe_port *pdata) 189486578516SGirish Nandibasappa { 189586578516SGirish Nandibasappa int qinq = 0; 189686578516SGirish Nandibasappa 189786578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EDVLP, 1); 189886578516SGirish Nandibasappa qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP); 189986578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "vlan double tag enabled EDVLP:qinq=0x%x\n", qinq); 190086578516SGirish Nandibasappa } 190186578516SGirish Nandibasappa 190286578516SGirish Nandibasappa static void axgbe_vlan_extend_disable(struct axgbe_port *pdata) 190386578516SGirish Nandibasappa { 190486578516SGirish Nandibasappa int qinq = 0; 190586578516SGirish Nandibasappa 190686578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EDVLP, 0); 190786578516SGirish Nandibasappa qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP); 190886578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "vlan double tag disable EDVLP:qinq=0x%x\n", qinq); 190986578516SGirish Nandibasappa } 191086578516SGirish Nandibasappa 191186578516SGirish Nandibasappa static int 191286578516SGirish Nandibasappa axgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask) 191386578516SGirish Nandibasappa { 191486578516SGirish Nandibasappa struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode; 191586578516SGirish Nandibasappa struct axgbe_port *pdata = dev->data->dev_private; 191686578516SGirish Nandibasappa 191786578516SGirish Nandibasappa /* Indicate that VLAN Tx CTAGs come from context descriptors */ 191886578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0); 191986578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1); 192086578516SGirish Nandibasappa 1921295968d1SFerruh Yigit if (mask & RTE_ETH_VLAN_STRIP_MASK) { 1922295968d1SFerruh Yigit if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) { 192386578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Strip ON for device = %s\n", 192486578516SGirish Nandibasappa pdata->eth_dev->device->name); 192586578516SGirish Nandibasappa pdata->hw_if.enable_rx_vlan_stripping(pdata); 192686578516SGirish Nandibasappa } else { 192786578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Strip OFF for device = %s\n", 192886578516SGirish Nandibasappa pdata->eth_dev->device->name); 192986578516SGirish Nandibasappa pdata->hw_if.disable_rx_vlan_stripping(pdata); 193086578516SGirish Nandibasappa } 193186578516SGirish Nandibasappa } 1932295968d1SFerruh Yigit if (mask & RTE_ETH_VLAN_FILTER_MASK) { 1933295968d1SFerruh Yigit if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) { 193486578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Filter ON for device = %s\n", 193586578516SGirish Nandibasappa pdata->eth_dev->device->name); 193686578516SGirish Nandibasappa pdata->hw_if.enable_rx_vlan_filtering(pdata); 193786578516SGirish Nandibasappa } else { 193886578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Filter OFF for device = %s\n", 193986578516SGirish Nandibasappa pdata->eth_dev->device->name); 194086578516SGirish Nandibasappa pdata->hw_if.disable_rx_vlan_filtering(pdata); 194186578516SGirish Nandibasappa } 194286578516SGirish Nandibasappa } 1943295968d1SFerruh Yigit if (mask & RTE_ETH_VLAN_EXTEND_MASK) { 1944295968d1SFerruh Yigit if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) { 194586578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "enabling vlan extended mode\n"); 194686578516SGirish Nandibasappa axgbe_vlan_extend_enable(pdata); 194786578516SGirish Nandibasappa /* Set global registers with default ethertype*/ 1948295968d1SFerruh Yigit axgbe_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER, 194986578516SGirish Nandibasappa RTE_ETHER_TYPE_VLAN); 1950295968d1SFerruh Yigit axgbe_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER, 195186578516SGirish Nandibasappa RTE_ETHER_TYPE_VLAN); 195286578516SGirish Nandibasappa } else { 195386578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "disabling vlan extended mode\n"); 195486578516SGirish Nandibasappa axgbe_vlan_extend_disable(pdata); 195586578516SGirish Nandibasappa } 195686578516SGirish Nandibasappa } 195786578516SGirish Nandibasappa return 0; 195886578516SGirish Nandibasappa } 195986578516SGirish Nandibasappa 1960572890efSRavi Kumar static void axgbe_get_all_hw_features(struct axgbe_port *pdata) 1961572890efSRavi Kumar { 196286578516SGirish Nandibasappa unsigned int mac_hfr0, mac_hfr1, mac_hfr2, mac_hfr3; 1963572890efSRavi Kumar struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 1964572890efSRavi Kumar 1965572890efSRavi Kumar mac_hfr0 = AXGMAC_IOREAD(pdata, MAC_HWF0R); 1966572890efSRavi Kumar mac_hfr1 = AXGMAC_IOREAD(pdata, MAC_HWF1R); 1967572890efSRavi Kumar mac_hfr2 = AXGMAC_IOREAD(pdata, MAC_HWF2R); 196886578516SGirish Nandibasappa mac_hfr3 = AXGMAC_IOREAD(pdata, MAC_HWF3R); 1969572890efSRavi Kumar 1970572890efSRavi Kumar memset(hw_feat, 0, sizeof(*hw_feat)); 1971572890efSRavi Kumar 1972572890efSRavi Kumar hw_feat->version = AXGMAC_IOREAD(pdata, MAC_VR); 1973572890efSRavi Kumar 1974572890efSRavi Kumar /* Hardware feature register 0 */ 1975572890efSRavi Kumar hw_feat->gmii = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, GMIISEL); 1976572890efSRavi Kumar hw_feat->vlhash = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, VLHASH); 1977572890efSRavi Kumar hw_feat->sma = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SMASEL); 1978572890efSRavi Kumar hw_feat->rwk = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RWKSEL); 1979572890efSRavi Kumar hw_feat->mgk = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MGKSEL); 1980572890efSRavi Kumar hw_feat->mmc = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MMCSEL); 1981572890efSRavi Kumar hw_feat->aoe = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, ARPOFFSEL); 1982572890efSRavi Kumar hw_feat->ts = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSEL); 1983572890efSRavi Kumar hw_feat->eee = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, EEESEL); 1984572890efSRavi Kumar hw_feat->tx_coe = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TXCOESEL); 1985572890efSRavi Kumar hw_feat->rx_coe = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RXCOESEL); 1986572890efSRavi Kumar hw_feat->addn_mac = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, 1987572890efSRavi Kumar ADDMACADRSEL); 1988572890efSRavi Kumar hw_feat->ts_src = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSTSSEL); 1989572890efSRavi Kumar hw_feat->sa_vlan_ins = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SAVLANINS); 1990572890efSRavi Kumar 1991572890efSRavi Kumar /* Hardware feature register 1 */ 1992572890efSRavi Kumar hw_feat->rx_fifo_size = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, 1993572890efSRavi Kumar RXFIFOSIZE); 1994572890efSRavi Kumar hw_feat->tx_fifo_size = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, 1995572890efSRavi Kumar TXFIFOSIZE); 1996572890efSRavi Kumar hw_feat->adv_ts_hi = AXGMAC_GET_BITS(mac_hfr1, 1997572890efSRavi Kumar MAC_HWF1R, ADVTHWORD); 1998572890efSRavi Kumar hw_feat->dma_width = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, ADDR64); 1999572890efSRavi Kumar hw_feat->dcb = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DCBEN); 2000572890efSRavi Kumar hw_feat->sph = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, SPHEN); 2001572890efSRavi Kumar hw_feat->tso = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, TSOEN); 2002572890efSRavi Kumar hw_feat->dma_debug = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DBGMEMA); 2003572890efSRavi Kumar hw_feat->rss = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, RSSEN); 2004572890efSRavi Kumar hw_feat->tc_cnt = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, NUMTC); 2005572890efSRavi Kumar hw_feat->hash_table_size = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, 2006572890efSRavi Kumar HASHTBLSZ); 2007572890efSRavi Kumar hw_feat->l3l4_filter_num = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, 2008572890efSRavi Kumar L3L4FNUM); 2009572890efSRavi Kumar 2010572890efSRavi Kumar /* Hardware feature register 2 */ 2011572890efSRavi Kumar hw_feat->rx_q_cnt = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXQCNT); 2012572890efSRavi Kumar hw_feat->tx_q_cnt = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXQCNT); 2013572890efSRavi Kumar hw_feat->rx_ch_cnt = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXCHCNT); 2014572890efSRavi Kumar hw_feat->tx_ch_cnt = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXCHCNT); 2015572890efSRavi Kumar hw_feat->pps_out_num = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, PPSOUTNUM); 2016572890efSRavi Kumar hw_feat->aux_snap_num = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, 2017572890efSRavi Kumar AUXSNAPNUM); 2018572890efSRavi Kumar 201986578516SGirish Nandibasappa /* Hardware feature register 3 */ 202086578516SGirish Nandibasappa hw_feat->tx_q_vlan_tag_ins = AXGMAC_GET_BITS(mac_hfr3, 202186578516SGirish Nandibasappa MAC_HWF3R, CBTISEL); 202286578516SGirish Nandibasappa hw_feat->no_of_vlan_extn = AXGMAC_GET_BITS(mac_hfr3, 202386578516SGirish Nandibasappa MAC_HWF3R, NRVF); 202486578516SGirish Nandibasappa 2025572890efSRavi Kumar /* Translate the Hash Table size into actual number */ 2026572890efSRavi Kumar switch (hw_feat->hash_table_size) { 2027572890efSRavi Kumar case 0: 2028572890efSRavi Kumar break; 2029572890efSRavi Kumar case 1: 2030572890efSRavi Kumar hw_feat->hash_table_size = 64; 2031572890efSRavi Kumar break; 2032572890efSRavi Kumar case 2: 2033572890efSRavi Kumar hw_feat->hash_table_size = 128; 2034572890efSRavi Kumar break; 2035572890efSRavi Kumar case 3: 2036572890efSRavi Kumar hw_feat->hash_table_size = 256; 2037572890efSRavi Kumar break; 2038572890efSRavi Kumar } 2039572890efSRavi Kumar 2040572890efSRavi Kumar /* Translate the address width setting into actual number */ 2041572890efSRavi Kumar switch (hw_feat->dma_width) { 2042572890efSRavi Kumar case 0: 2043572890efSRavi Kumar hw_feat->dma_width = 32; 2044572890efSRavi Kumar break; 2045572890efSRavi Kumar case 1: 2046572890efSRavi Kumar hw_feat->dma_width = 40; 2047572890efSRavi Kumar break; 2048572890efSRavi Kumar case 2: 2049572890efSRavi Kumar hw_feat->dma_width = 48; 2050572890efSRavi Kumar break; 2051572890efSRavi Kumar default: 2052572890efSRavi Kumar hw_feat->dma_width = 32; 2053572890efSRavi Kumar } 2054572890efSRavi Kumar 2055572890efSRavi Kumar /* The Queue, Channel and TC counts are zero based so increment them 2056572890efSRavi Kumar * to get the actual number 2057572890efSRavi Kumar */ 2058572890efSRavi Kumar hw_feat->rx_q_cnt++; 2059572890efSRavi Kumar hw_feat->tx_q_cnt++; 2060572890efSRavi Kumar hw_feat->rx_ch_cnt++; 2061572890efSRavi Kumar hw_feat->tx_ch_cnt++; 2062572890efSRavi Kumar hw_feat->tc_cnt++; 2063572890efSRavi Kumar 2064572890efSRavi Kumar /* Translate the fifo sizes into actual numbers */ 2065572890efSRavi Kumar hw_feat->rx_fifo_size = 1 << (hw_feat->rx_fifo_size + 7); 2066572890efSRavi Kumar hw_feat->tx_fifo_size = 1 << (hw_feat->tx_fifo_size + 7); 2067572890efSRavi Kumar } 2068572890efSRavi Kumar 2069572890efSRavi Kumar static void axgbe_init_all_fptrs(struct axgbe_port *pdata) 2070572890efSRavi Kumar { 2071572890efSRavi Kumar axgbe_init_function_ptrs_dev(&pdata->hw_if); 20724ac7516bSRavi Kumar axgbe_init_function_ptrs_phy(&pdata->phy_if); 20734ac7516bSRavi Kumar axgbe_init_function_ptrs_i2c(&pdata->i2c_if); 20744ac7516bSRavi Kumar pdata->vdata->init_function_ptrs_phy_impl(&pdata->phy_if); 2075572890efSRavi Kumar } 2076572890efSRavi Kumar 2077572890efSRavi Kumar static void axgbe_set_counts(struct axgbe_port *pdata) 2078572890efSRavi Kumar { 2079572890efSRavi Kumar /* Set all the function pointers */ 2080572890efSRavi Kumar axgbe_init_all_fptrs(pdata); 2081572890efSRavi Kumar 2082572890efSRavi Kumar /* Populate the hardware features */ 2083572890efSRavi Kumar axgbe_get_all_hw_features(pdata); 2084572890efSRavi Kumar 2085572890efSRavi Kumar /* Set default max values if not provided */ 2086572890efSRavi Kumar if (!pdata->tx_max_channel_count) 2087572890efSRavi Kumar pdata->tx_max_channel_count = pdata->hw_feat.tx_ch_cnt; 2088572890efSRavi Kumar if (!pdata->rx_max_channel_count) 2089572890efSRavi Kumar pdata->rx_max_channel_count = pdata->hw_feat.rx_ch_cnt; 2090572890efSRavi Kumar 2091572890efSRavi Kumar if (!pdata->tx_max_q_count) 2092572890efSRavi Kumar pdata->tx_max_q_count = pdata->hw_feat.tx_q_cnt; 2093572890efSRavi Kumar if (!pdata->rx_max_q_count) 2094572890efSRavi Kumar pdata->rx_max_q_count = pdata->hw_feat.rx_q_cnt; 2095572890efSRavi Kumar 2096572890efSRavi Kumar /* Calculate the number of Tx and Rx rings to be created 2097572890efSRavi Kumar * -Tx (DMA) Channels map 1-to-1 to Tx Queues so set 2098572890efSRavi Kumar * the number of Tx queues to the number of Tx channels 2099572890efSRavi Kumar * enabled 2100572890efSRavi Kumar * -Rx (DMA) Channels do not map 1-to-1 so use the actual 2101572890efSRavi Kumar * number of Rx queues or maximum allowed 2102572890efSRavi Kumar */ 2103572890efSRavi Kumar pdata->tx_ring_count = RTE_MIN(pdata->hw_feat.tx_ch_cnt, 2104572890efSRavi Kumar pdata->tx_max_channel_count); 2105572890efSRavi Kumar pdata->tx_ring_count = RTE_MIN(pdata->tx_ring_count, 2106572890efSRavi Kumar pdata->tx_max_q_count); 2107572890efSRavi Kumar 2108572890efSRavi Kumar pdata->tx_q_count = pdata->tx_ring_count; 2109572890efSRavi Kumar 2110572890efSRavi Kumar pdata->rx_ring_count = RTE_MIN(pdata->hw_feat.rx_ch_cnt, 2111572890efSRavi Kumar pdata->rx_max_channel_count); 2112572890efSRavi Kumar 2113572890efSRavi Kumar pdata->rx_q_count = RTE_MIN(pdata->hw_feat.rx_q_cnt, 2114572890efSRavi Kumar pdata->rx_max_q_count); 2115572890efSRavi Kumar } 2116572890efSRavi Kumar 2117572890efSRavi Kumar static void axgbe_default_config(struct axgbe_port *pdata) 2118572890efSRavi Kumar { 2119572890efSRavi Kumar pdata->pblx8 = DMA_PBL_X8_ENABLE; 2120572890efSRavi Kumar pdata->tx_sf_mode = MTL_TSF_ENABLE; 2121572890efSRavi Kumar pdata->tx_threshold = MTL_TX_THRESHOLD_64; 2122572890efSRavi Kumar pdata->tx_pbl = DMA_PBL_32; 2123572890efSRavi Kumar pdata->tx_osp_mode = DMA_OSP_ENABLE; 2124572890efSRavi Kumar pdata->rx_sf_mode = MTL_RSF_ENABLE; 2125572890efSRavi Kumar pdata->rx_threshold = MTL_RX_THRESHOLD_64; 2126572890efSRavi Kumar pdata->rx_pbl = DMA_PBL_32; 2127572890efSRavi Kumar pdata->pause_autoneg = 1; 2128572890efSRavi Kumar pdata->tx_pause = 0; 2129572890efSRavi Kumar pdata->rx_pause = 0; 2130572890efSRavi Kumar pdata->phy_speed = SPEED_UNKNOWN; 2131572890efSRavi Kumar pdata->power_down = 0; 2132572890efSRavi Kumar } 2133572890efSRavi Kumar 21349963b513SJesna K E /* Used in dev_start by primary process and then 21359963b513SJesna K E * in dev_init by secondary process when attaching to an existing ethdev. 21369963b513SJesna K E */ 21379963b513SJesna K E void 21389963b513SJesna K E axgbe_set_tx_function(struct rte_eth_dev *dev) 21399963b513SJesna K E { 21409963b513SJesna K E struct axgbe_port *pdata = dev->data->dev_private; 21419963b513SJesna K E 2142*4feb9aa0SJesna K E dev->tx_pkt_burst = &axgbe_xmit_pkts; 2143*4feb9aa0SJesna K E 21449963b513SJesna K E if (pdata->multi_segs_tx) 21459963b513SJesna K E dev->tx_pkt_burst = &axgbe_xmit_pkts_seg; 21469963b513SJesna K E #ifdef RTE_ARCH_X86 21479963b513SJesna K E struct axgbe_tx_queue *txq = dev->data->tx_queues[0]; 21489963b513SJesna K E if (!txq->vector_disable && 21499963b513SJesna K E rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) 21509963b513SJesna K E dev->tx_pkt_burst = &axgbe_xmit_pkts_vec; 21519963b513SJesna K E #endif 21529963b513SJesna K E } 21539963b513SJesna K E 21549963b513SJesna K E void 21559963b513SJesna K E axgbe_set_rx_function(struct rte_eth_dev *dev) 21569963b513SJesna K E { 21579963b513SJesna K E struct rte_eth_dev_data *dev_data = dev->data; 21589963b513SJesna K E uint16_t max_pkt_len; 21599963b513SJesna K E struct axgbe_port *pdata; 21609963b513SJesna K E 21619963b513SJesna K E pdata = dev->data->dev_private; 21629963b513SJesna K E max_pkt_len = dev_data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN; 21639963b513SJesna K E if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) || 21649963b513SJesna K E max_pkt_len > pdata->rx_buf_size) 21659963b513SJesna K E dev_data->scattered_rx = 1; 21669963b513SJesna K E /* Scatter Rx handling */ 21679963b513SJesna K E if (dev_data->scattered_rx) 21689963b513SJesna K E dev->rx_pkt_burst = ð_axgbe_recv_scattered_pkts; 21699963b513SJesna K E else 21709963b513SJesna K E dev->rx_pkt_burst = &axgbe_recv_pkts; 21719963b513SJesna K E } 21729963b513SJesna K E 21738691632fSRavi Kumar /* 21748691632fSRavi Kumar * It returns 0 on success. 21758691632fSRavi Kumar */ 21768691632fSRavi Kumar static int 21778691632fSRavi Kumar eth_axgbe_dev_init(struct rte_eth_dev *eth_dev) 21788691632fSRavi Kumar { 21798691632fSRavi Kumar PMD_INIT_FUNC_TRACE(); 21808691632fSRavi Kumar struct axgbe_port *pdata; 21818691632fSRavi Kumar struct rte_pci_device *pci_dev; 2182572890efSRavi Kumar uint32_t reg, mac_lo, mac_hi; 218349a5e622SChandu Babu N uint32_t len; 2184572890efSRavi Kumar int ret; 21858691632fSRavi Kumar 2186a27ff9caSSelwin Sebastian unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; 2187a27ff9caSSelwin Sebastian unsigned char cpu_family = 0, cpu_model = 0; 2188a27ff9caSSelwin Sebastian 21899e890103SRavi Kumar eth_dev->dev_ops = &axgbe_eth_dev_ops; 21909e890103SRavi Kumar 2191cbfc6111SFerruh Yigit eth_dev->rx_descriptor_status = axgbe_dev_rx_descriptor_status; 2192cbfc6111SFerruh Yigit eth_dev->tx_descriptor_status = axgbe_dev_tx_descriptor_status; 2193cbfc6111SFerruh Yigit 21949963b513SJesna K E eth_dev->tx_pkt_burst = &axgbe_xmit_pkts; 21959963b513SJesna K E eth_dev->rx_pkt_burst = &axgbe_recv_pkts; 21969963b513SJesna K E 21978691632fSRavi Kumar /* 21988691632fSRavi Kumar * For secondary processes, we don't initialise any further as primary 21998691632fSRavi Kumar * has already done this work. 22008691632fSRavi Kumar */ 22019963b513SJesna K E if (rte_eal_process_type() != RTE_PROC_PRIMARY) { 22029963b513SJesna K E axgbe_set_tx_function(eth_dev); 22039963b513SJesna K E axgbe_set_rx_function(eth_dev); 22048691632fSRavi Kumar return 0; 22059963b513SJesna K E } 22068691632fSRavi Kumar 2207f30e69b4SFerruh Yigit eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; 2208f30e69b4SFerruh Yigit 22090bc212a8SStephen Hemminger pdata = eth_dev->data->dev_private; 2210572890efSRavi Kumar /* initial state */ 22114693ae4aSJoyce Kong rte_bit_relaxed_set32(AXGBE_DOWN, &pdata->dev_state); 22124693ae4aSJoyce Kong rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state); 22138691632fSRavi Kumar pdata->eth_dev = eth_dev; 22148691632fSRavi Kumar 22158691632fSRavi Kumar pci_dev = RTE_DEV_TO_PCI(eth_dev->device); 22168691632fSRavi Kumar pdata->pci_dev = pci_dev; 22178691632fSRavi Kumar 2218572890efSRavi Kumar pdata->xgmac_regs = 22197784d0d3SRavi Kumar (void *)pci_dev->mem_resource[AXGBE_AXGMAC_BAR].addr; 22207784d0d3SRavi Kumar pdata->xprop_regs = (void *)((uint8_t *)pdata->xgmac_regs 22217784d0d3SRavi Kumar + AXGBE_MAC_PROP_OFFSET); 22227784d0d3SRavi Kumar pdata->xi2c_regs = (void *)((uint8_t *)pdata->xgmac_regs 22237784d0d3SRavi Kumar + AXGBE_I2C_CTRL_OFFSET); 22247784d0d3SRavi Kumar pdata->xpcs_regs = (void *)pci_dev->mem_resource[AXGBE_XPCS_BAR].addr; 2225572890efSRavi Kumar 2226572890efSRavi Kumar /* version specific driver data*/ 2227572890efSRavi Kumar if (pci_dev->id.device_id == AMD_PCI_AXGBE_DEVICE_V2A) 2228572890efSRavi Kumar pdata->vdata = &axgbe_v2a; 2229572890efSRavi Kumar else 2230572890efSRavi Kumar pdata->vdata = &axgbe_v2b; 2231572890efSRavi Kumar 2232f7706f88SSelwin Sebastian /* 2233a27ff9caSSelwin Sebastian * Use CPUID to get Family and model ID to identify the CPU 2234f7706f88SSelwin Sebastian */ 2235a27ff9caSSelwin Sebastian __cpuid(0x0, eax, ebx, ecx, edx); 2236a27ff9caSSelwin Sebastian 2237a27ff9caSSelwin Sebastian if (ebx == CPUID_VENDOR_AuthenticAMD_ebx && 2238a27ff9caSSelwin Sebastian edx == CPUID_VENDOR_AuthenticAMD_edx && 2239a27ff9caSSelwin Sebastian ecx == CPUID_VENDOR_AuthenticAMD_ecx) { 2240a27ff9caSSelwin Sebastian int unknown_cpu = 0; 2241a27ff9caSSelwin Sebastian eax = 0, ebx = 0, ecx = 0, edx = 0; 2242a27ff9caSSelwin Sebastian 2243a27ff9caSSelwin Sebastian __cpuid(0x1, eax, ebx, ecx, edx); 2244a27ff9caSSelwin Sebastian 2245a27ff9caSSelwin Sebastian cpu_family = ((GET_BITS(eax, 8, 4)) + (GET_BITS(eax, 20, 8))); 2246a27ff9caSSelwin Sebastian cpu_model = ((GET_BITS(eax, 4, 4)) | (((GET_BITS(eax, 16, 4)) << 4) & 0xF0)); 2247a27ff9caSSelwin Sebastian 2248a27ff9caSSelwin Sebastian switch (cpu_family) { 2249a27ff9caSSelwin Sebastian case Fam17h: 2250a27ff9caSSelwin Sebastian /* V1000/R1000 */ 2251a27ff9caSSelwin Sebastian if (cpu_model >= 0x10 && cpu_model <= 0x1F) { 2252f7706f88SSelwin Sebastian pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF; 2253f7706f88SSelwin Sebastian pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT; 2254a27ff9caSSelwin Sebastian /* EPYC 3000 */ 2255a27ff9caSSelwin Sebastian } else if (cpu_model >= 0x01 && cpu_model <= 0x0F) { 2256f7706f88SSelwin Sebastian pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF; 2257f7706f88SSelwin Sebastian pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; 2258a27ff9caSSelwin Sebastian } else { 2259a27ff9caSSelwin Sebastian unknown_cpu = 1; 2260a27ff9caSSelwin Sebastian } 2261a27ff9caSSelwin Sebastian break; 2262a27ff9caSSelwin Sebastian case Fam19h: 2263a27ff9caSSelwin Sebastian /* V3000 (Yellow Carp) */ 2264a27ff9caSSelwin Sebastian if (cpu_model >= 0x44 && cpu_model <= 0x47) { 2265a27ff9caSSelwin Sebastian pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF; 2266a27ff9caSSelwin Sebastian pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT; 2267a27ff9caSSelwin Sebastian 2268a27ff9caSSelwin Sebastian /* Yellow Carp devices do not need cdr workaround */ 2269a27ff9caSSelwin Sebastian pdata->vdata->an_cdr_workaround = 0; 2270a27ff9caSSelwin Sebastian } else { 2271a27ff9caSSelwin Sebastian unknown_cpu = 1; 2272a27ff9caSSelwin Sebastian } 2273f7706f88SSelwin Sebastian break; 2274f7706f88SSelwin Sebastian default: 2275a27ff9caSSelwin Sebastian unknown_cpu = 1; 2276a27ff9caSSelwin Sebastian break; 2277a27ff9caSSelwin Sebastian } 2278a27ff9caSSelwin Sebastian if (unknown_cpu) { 2279a27ff9caSSelwin Sebastian PMD_DRV_LOG(ERR, "Unknown CPU family, no supported axgbe device found\n"); 2280f7706f88SSelwin Sebastian return -ENODEV; 2281f7706f88SSelwin Sebastian } 2282a27ff9caSSelwin Sebastian } 2283f7706f88SSelwin Sebastian 2284572890efSRavi Kumar /* Configure the PCS indirect addressing support */ 2285991e0b1dSSelwin Sebastian reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg); 2286572890efSRavi Kumar pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET); 2287572890efSRavi Kumar pdata->xpcs_window <<= 6; 2288572890efSRavi Kumar pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE); 2289572890efSRavi Kumar pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7); 2290572890efSRavi Kumar pdata->xpcs_window_mask = pdata->xpcs_window_size - 1; 2291991e0b1dSSelwin Sebastian 2292572890efSRavi Kumar PMD_INIT_LOG(DEBUG, 2293572890efSRavi Kumar "xpcs window :%x, size :%x, mask :%x ", pdata->xpcs_window, 2294572890efSRavi Kumar pdata->xpcs_window_size, pdata->xpcs_window_mask); 2295572890efSRavi Kumar XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff); 2296572890efSRavi Kumar 2297572890efSRavi Kumar /* Retrieve the MAC address */ 2298572890efSRavi Kumar mac_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO); 2299572890efSRavi Kumar mac_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI); 2300572890efSRavi Kumar pdata->mac_addr.addr_bytes[0] = mac_lo & 0xff; 2301572890efSRavi Kumar pdata->mac_addr.addr_bytes[1] = (mac_lo >> 8) & 0xff; 2302572890efSRavi Kumar pdata->mac_addr.addr_bytes[2] = (mac_lo >> 16) & 0xff; 2303572890efSRavi Kumar pdata->mac_addr.addr_bytes[3] = (mac_lo >> 24) & 0xff; 2304572890efSRavi Kumar pdata->mac_addr.addr_bytes[4] = mac_hi & 0xff; 2305572890efSRavi Kumar pdata->mac_addr.addr_bytes[5] = (mac_hi >> 8) & 0xff; 2306572890efSRavi Kumar 230749a5e622SChandu Babu N len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_MAC_ADDRS; 230849a5e622SChandu Babu N eth_dev->data->mac_addrs = rte_zmalloc("axgbe_mac_addr", len, 0); 230949a5e622SChandu Babu N 2310572890efSRavi Kumar if (!eth_dev->data->mac_addrs) { 2311572890efSRavi Kumar PMD_INIT_LOG(ERR, 231249a5e622SChandu Babu N "Failed to alloc %u bytes needed to " 231349a5e622SChandu Babu N "store MAC addresses", len); 2314572890efSRavi Kumar return -ENOMEM; 2315572890efSRavi Kumar } 2316572890efSRavi Kumar 2317e01d9b2eSChandu Babu N /* Allocate memory for storing hash filter MAC addresses */ 2318e01d9b2eSChandu Babu N len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_HASH_MAC_ADDRS; 2319e01d9b2eSChandu Babu N eth_dev->data->hash_mac_addrs = rte_zmalloc("axgbe_hash_mac_addr", 2320e01d9b2eSChandu Babu N len, 0); 2321e01d9b2eSChandu Babu N 2322e01d9b2eSChandu Babu N if (eth_dev->data->hash_mac_addrs == NULL) { 2323e01d9b2eSChandu Babu N PMD_INIT_LOG(ERR, 2324e01d9b2eSChandu Babu N "Failed to allocate %d bytes needed to " 2325e01d9b2eSChandu Babu N "store MAC addresses", len); 2326e01d9b2eSChandu Babu N return -ENOMEM; 2327e01d9b2eSChandu Babu N } 2328e01d9b2eSChandu Babu N 2329538da7a1SOlivier Matz if (!rte_is_valid_assigned_ether_addr(&pdata->mac_addr)) 2330538da7a1SOlivier Matz rte_eth_random_addr(pdata->mac_addr.addr_bytes); 2331572890efSRavi Kumar 2332572890efSRavi Kumar /* Copy the permanent MAC address */ 2333538da7a1SOlivier Matz rte_ether_addr_copy(&pdata->mac_addr, ð_dev->data->mac_addrs[0]); 2334572890efSRavi Kumar 2335572890efSRavi Kumar /* Clock settings */ 2336572890efSRavi Kumar pdata->sysclk_rate = AXGBE_V2_DMA_CLOCK_FREQ; 2337572890efSRavi Kumar pdata->ptpclk_rate = AXGBE_V2_PTP_CLOCK_FREQ; 2338572890efSRavi Kumar 2339572890efSRavi Kumar /* Set the DMA coherency values */ 2340572890efSRavi Kumar pdata->coherent = 1; 2341572890efSRavi Kumar pdata->axdomain = AXGBE_DMA_OS_AXDOMAIN; 2342572890efSRavi Kumar pdata->arcache = AXGBE_DMA_OS_ARCACHE; 2343572890efSRavi Kumar pdata->awcache = AXGBE_DMA_OS_AWCACHE; 2344572890efSRavi Kumar 2345572890efSRavi Kumar /* Set the maximum channels and queues */ 2346572890efSRavi Kumar reg = XP_IOREAD(pdata, XP_PROP_1); 2347572890efSRavi Kumar pdata->tx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_DMA); 2348572890efSRavi Kumar pdata->rx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_DMA); 2349572890efSRavi Kumar pdata->tx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_QUEUES); 2350572890efSRavi Kumar pdata->rx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_QUEUES); 2351572890efSRavi Kumar 2352572890efSRavi Kumar /* Set the hardware channel and queue counts */ 2353572890efSRavi Kumar axgbe_set_counts(pdata); 2354572890efSRavi Kumar 2355572890efSRavi Kumar /* Set the maximum fifo amounts */ 2356572890efSRavi Kumar reg = XP_IOREAD(pdata, XP_PROP_2); 2357572890efSRavi Kumar pdata->tx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, TX_FIFO_SIZE); 2358572890efSRavi Kumar pdata->tx_max_fifo_size *= 16384; 2359572890efSRavi Kumar pdata->tx_max_fifo_size = RTE_MIN(pdata->tx_max_fifo_size, 2360572890efSRavi Kumar pdata->vdata->tx_max_fifo_size); 2361572890efSRavi Kumar pdata->rx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, RX_FIFO_SIZE); 2362572890efSRavi Kumar pdata->rx_max_fifo_size *= 16384; 2363572890efSRavi Kumar pdata->rx_max_fifo_size = RTE_MIN(pdata->rx_max_fifo_size, 2364572890efSRavi Kumar pdata->vdata->rx_max_fifo_size); 2365572890efSRavi Kumar /* Issue software reset to DMA */ 2366572890efSRavi Kumar ret = pdata->hw_if.exit(pdata); 2367572890efSRavi Kumar if (ret) 2368572890efSRavi Kumar PMD_DRV_LOG(ERR, "hw_if->exit EBUSY error\n"); 2369572890efSRavi Kumar 2370572890efSRavi Kumar /* Set default configuration data */ 2371572890efSRavi Kumar axgbe_default_config(pdata); 2372572890efSRavi Kumar 2373572890efSRavi Kumar /* Set default max values if not provided */ 2374572890efSRavi Kumar if (!pdata->tx_max_fifo_size) 2375572890efSRavi Kumar pdata->tx_max_fifo_size = pdata->hw_feat.tx_fifo_size; 2376572890efSRavi Kumar if (!pdata->rx_max_fifo_size) 2377572890efSRavi Kumar pdata->rx_max_fifo_size = pdata->hw_feat.rx_fifo_size; 2378572890efSRavi Kumar 23799e890103SRavi Kumar pdata->tx_desc_count = AXGBE_MAX_RING_DESC; 23809e890103SRavi Kumar pdata->rx_desc_count = AXGBE_MAX_RING_DESC; 2381572890efSRavi Kumar pthread_mutex_init(&pdata->xpcs_mutex, NULL); 2382572890efSRavi Kumar pthread_mutex_init(&pdata->i2c_mutex, NULL); 2383572890efSRavi Kumar pthread_mutex_init(&pdata->an_mutex, NULL); 2384572890efSRavi Kumar pthread_mutex_init(&pdata->phy_mutex, NULL); 2385572890efSRavi Kumar 23864ac7516bSRavi Kumar ret = pdata->phy_if.phy_init(pdata); 23874ac7516bSRavi Kumar if (ret) { 23884ac7516bSRavi Kumar rte_free(eth_dev->data->mac_addrs); 2389e7f2fa88SDavid Marchand eth_dev->data->mac_addrs = NULL; 23904ac7516bSRavi Kumar return ret; 23914ac7516bSRavi Kumar } 23924ac7516bSRavi Kumar 2393d61138d4SHarman Kalra rte_intr_callback_register(pci_dev->intr_handle, 2394456ff159SRavi Kumar axgbe_dev_interrupt_handler, 2395456ff159SRavi Kumar (void *)eth_dev); 23968691632fSRavi Kumar PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x", 23978691632fSRavi Kumar eth_dev->data->port_id, pci_dev->id.vendor_id, 23988691632fSRavi Kumar pci_dev->id.device_id); 23998691632fSRavi Kumar 24008691632fSRavi Kumar return 0; 24018691632fSRavi Kumar } 24028691632fSRavi Kumar 24038691632fSRavi Kumar static int 2404479e6a42SThomas Monjalon axgbe_dev_close(struct rte_eth_dev *eth_dev) 24058691632fSRavi Kumar { 2406456ff159SRavi Kumar struct rte_pci_device *pci_dev; 2407456ff159SRavi Kumar 24088691632fSRavi Kumar PMD_INIT_FUNC_TRACE(); 24098691632fSRavi Kumar 2410572890efSRavi Kumar if (rte_eal_process_type() != RTE_PROC_PRIMARY) 2411572890efSRavi Kumar return 0; 2412572890efSRavi Kumar 2413456ff159SRavi Kumar pci_dev = RTE_DEV_TO_PCI(eth_dev->device); 24149e890103SRavi Kumar axgbe_dev_clear_queues(eth_dev); 2415572890efSRavi Kumar 2416456ff159SRavi Kumar /* disable uio intr before callback unregister */ 2417d61138d4SHarman Kalra rte_intr_disable(pci_dev->intr_handle); 2418d61138d4SHarman Kalra rte_intr_callback_unregister(pci_dev->intr_handle, 2419456ff159SRavi Kumar axgbe_dev_interrupt_handler, 2420456ff159SRavi Kumar (void *)eth_dev); 2421456ff159SRavi Kumar 24228691632fSRavi Kumar return 0; 24238691632fSRavi Kumar } 24248691632fSRavi Kumar 24258691632fSRavi Kumar static int eth_axgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, 24268691632fSRavi Kumar struct rte_pci_device *pci_dev) 24278691632fSRavi Kumar { 24288691632fSRavi Kumar return rte_eth_dev_pci_generic_probe(pci_dev, 24298691632fSRavi Kumar sizeof(struct axgbe_port), eth_axgbe_dev_init); 24308691632fSRavi Kumar } 24318691632fSRavi Kumar 24328691632fSRavi Kumar static int eth_axgbe_pci_remove(struct rte_pci_device *pci_dev) 24338691632fSRavi Kumar { 2434479e6a42SThomas Monjalon return rte_eth_dev_pci_generic_remove(pci_dev, axgbe_dev_close); 24358691632fSRavi Kumar } 24368691632fSRavi Kumar 24378691632fSRavi Kumar static struct rte_pci_driver rte_axgbe_pmd = { 24388691632fSRavi Kumar .id_table = pci_id_axgbe_map, 24398691632fSRavi Kumar .drv_flags = RTE_PCI_DRV_NEED_MAPPING, 24408691632fSRavi Kumar .probe = eth_axgbe_pci_probe, 24418691632fSRavi Kumar .remove = eth_axgbe_pci_remove, 24428691632fSRavi Kumar }; 24438691632fSRavi Kumar 24448691632fSRavi Kumar RTE_PMD_REGISTER_PCI(net_axgbe, rte_axgbe_pmd); 24458691632fSRavi Kumar RTE_PMD_REGISTER_PCI_TABLE(net_axgbe, pci_id_axgbe_map); 24468691632fSRavi Kumar RTE_PMD_REGISTER_KMOD_DEP(net_axgbe, "* igb_uio | uio_pci_generic | vfio-pci"); 2447eeded204SDavid Marchand RTE_LOG_REGISTER_SUFFIX(axgbe_logtype_init, init, NOTICE); 2448eeded204SDavid Marchand RTE_LOG_REGISTER_SUFFIX(axgbe_logtype_driver, driver, NOTICE); 2449