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*a27ff9caSSelwin Sebastian #ifdef RTE_ARCH_X86 16*a27ff9caSSelwin Sebastian #include <cpuid.h> 17*a27ff9caSSelwin Sebastian #else 18*a27ff9caSSelwin Sebastian #define __cpuid(n, a, b, c, d) 19*a27ff9caSSelwin Sebastian #endif 20*a27ff9caSSelwin Sebastian 218691632fSRavi Kumar static int eth_axgbe_dev_init(struct rte_eth_dev *eth_dev); 227c4158a5SRavi Kumar static int axgbe_dev_configure(struct rte_eth_dev *dev); 237c4158a5SRavi Kumar static int axgbe_dev_start(struct rte_eth_dev *dev); 2462024eb8SIvan Ilchenko static int axgbe_dev_stop(struct rte_eth_dev *dev); 25456ff159SRavi Kumar static void axgbe_dev_interrupt_handler(void *param); 26b142387bSThomas Monjalon static int axgbe_dev_close(struct rte_eth_dev *dev); 27bf403cfeSSelwin Sebastian static int axgbe_dev_reset(struct rte_eth_dev *dev); 289039c812SAndrew Rybchenko static int axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev); 299039c812SAndrew Rybchenko static int axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev); 30ca041cd4SIvan Ilchenko static int axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev); 31ca041cd4SIvan Ilchenko static int axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev); 3249a5e622SChandu Babu N static int axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, 3349a5e622SChandu Babu N struct rte_ether_addr *mac_addr); 3449a5e622SChandu Babu N static int axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, 3549a5e622SChandu Babu N struct rte_ether_addr *mac_addr, 3649a5e622SChandu Babu N uint32_t index, 3749a5e622SChandu Babu N uint32_t vmdq); 3849a5e622SChandu Babu N static void axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index); 3949a5e622SChandu Babu N static int axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev, 4049a5e622SChandu Babu N struct rte_ether_addr *mc_addr_set, 4149a5e622SChandu Babu N uint32_t nb_mc_addr); 42e01d9b2eSChandu Babu N static int axgbe_dev_uc_hash_table_set(struct rte_eth_dev *dev, 43e01d9b2eSChandu Babu N struct rte_ether_addr *mac_addr, 44e01d9b2eSChandu Babu N uint8_t add); 45e01d9b2eSChandu Babu N static int axgbe_dev_uc_all_hash_table_set(struct rte_eth_dev *dev, 46e01d9b2eSChandu Babu N uint8_t add); 4744d45ffeSRavi Kumar static int axgbe_dev_link_update(struct rte_eth_dev *dev, 4844d45ffeSRavi Kumar int wait_to_complete); 49df4867cdSChandu Babu N static int axgbe_dev_get_regs(struct rte_eth_dev *dev, 50df4867cdSChandu Babu N struct rte_dev_reg_info *regs); 513e730511SRavi Kumar static int axgbe_dev_stats_get(struct rte_eth_dev *dev, 523e730511SRavi Kumar struct rte_eth_stats *stats); 539970a9adSIgor Romanov static int axgbe_dev_stats_reset(struct rte_eth_dev *dev); 549d1ef6b2SChandu Babu N static int axgbe_dev_xstats_get(struct rte_eth_dev *dev, 559d1ef6b2SChandu Babu N struct rte_eth_xstat *stats, 569d1ef6b2SChandu Babu N unsigned int n); 579d1ef6b2SChandu Babu N static int 589d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(struct rte_eth_dev *dev, 599d1ef6b2SChandu Babu N struct rte_eth_xstat_name *xstats_names, 609d1ef6b2SChandu Babu N unsigned int size); 619d1ef6b2SChandu Babu N static int 629d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, 639d1ef6b2SChandu Babu N const uint64_t *ids, 649d1ef6b2SChandu Babu N uint64_t *values, 659d1ef6b2SChandu Babu N unsigned int n); 669d1ef6b2SChandu Babu N static int 679d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, 689d1ef6b2SChandu Babu N const uint64_t *ids, 698c9f976fSAndrew Rybchenko struct rte_eth_xstat_name *xstats_names, 709d1ef6b2SChandu Babu N unsigned int size); 719d1ef6b2SChandu Babu N static int axgbe_dev_xstats_reset(struct rte_eth_dev *dev); 7276d7664dSChandu Babu N static int axgbe_dev_rss_reta_update(struct rte_eth_dev *dev, 7376d7664dSChandu Babu N struct rte_eth_rss_reta_entry64 *reta_conf, 7476d7664dSChandu Babu N uint16_t reta_size); 7576d7664dSChandu Babu N static int axgbe_dev_rss_reta_query(struct rte_eth_dev *dev, 7676d7664dSChandu Babu N struct rte_eth_rss_reta_entry64 *reta_conf, 7776d7664dSChandu Babu N uint16_t reta_size); 7876d7664dSChandu Babu N static int axgbe_dev_rss_hash_update(struct rte_eth_dev *dev, 7976d7664dSChandu Babu N struct rte_eth_rss_conf *rss_conf); 8076d7664dSChandu Babu N static int axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev, 8176d7664dSChandu Babu N struct rte_eth_rss_conf *rss_conf); 82bdad90d1SIvan Ilchenko static int axgbe_dev_info_get(struct rte_eth_dev *dev, 839e890103SRavi Kumar struct rte_eth_dev_info *dev_info); 84cf97f33eSAmaranath Somalapuram static int axgbe_flow_ctrl_get(struct rte_eth_dev *dev, 85cf97f33eSAmaranath Somalapuram struct rte_eth_fc_conf *fc_conf); 86cf97f33eSAmaranath Somalapuram static int axgbe_flow_ctrl_set(struct rte_eth_dev *dev, 87cf97f33eSAmaranath Somalapuram struct rte_eth_fc_conf *fc_conf); 88e0543d4eSAmaranath Somalapuram static int axgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, 89e0543d4eSAmaranath Somalapuram struct rte_eth_pfc_conf *pfc_conf); 907aed95c9SAmaranath Somalapuram static void axgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 917aed95c9SAmaranath Somalapuram struct rte_eth_rxq_info *qinfo); 927aed95c9SAmaranath Somalapuram static void axgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 937aed95c9SAmaranath Somalapuram struct rte_eth_txq_info *qinfo); 94410cf087SAmaranath Somalapuram const uint32_t *axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev); 95b58d8781SGirish Nandibasappa static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu); 968691632fSRavi Kumar 97e0444948SSelwin Sebastian static int 98e0444948SSelwin Sebastian axgbe_timesync_enable(struct rte_eth_dev *dev); 99e0444948SSelwin Sebastian static int 100e0444948SSelwin Sebastian axgbe_timesync_disable(struct rte_eth_dev *dev); 101e0444948SSelwin Sebastian static int 102e0444948SSelwin Sebastian axgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev, 103e0444948SSelwin Sebastian struct timespec *timestamp, uint32_t flags); 104e0444948SSelwin Sebastian static int 105e0444948SSelwin Sebastian axgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev, 106e0444948SSelwin Sebastian struct timespec *timestamp); 107e0444948SSelwin Sebastian static int 108e0444948SSelwin Sebastian axgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta); 109e0444948SSelwin Sebastian static int 110e0444948SSelwin Sebastian axgbe_timesync_read_time(struct rte_eth_dev *dev, 111e0444948SSelwin Sebastian struct timespec *timestamp); 112e0444948SSelwin Sebastian static int 113e0444948SSelwin Sebastian axgbe_timesync_write_time(struct rte_eth_dev *dev, 114e0444948SSelwin Sebastian const struct timespec *timestamp); 115e0444948SSelwin Sebastian static void 116e0444948SSelwin Sebastian axgbe_set_tstamp_time(struct axgbe_port *pdata, unsigned int sec, 117e0444948SSelwin Sebastian unsigned int nsec); 118e0444948SSelwin Sebastian static void 119e0444948SSelwin Sebastian axgbe_update_tstamp_addend(struct axgbe_port *pdata, 120e0444948SSelwin Sebastian unsigned int addend); 12186578516SGirish Nandibasappa static int 12286578516SGirish Nandibasappa axgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on); 12386578516SGirish Nandibasappa static int axgbe_vlan_tpid_set(struct rte_eth_dev *dev, 12486578516SGirish Nandibasappa enum rte_vlan_type vlan_type, uint16_t tpid); 12586578516SGirish Nandibasappa static int axgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask); 126e0444948SSelwin Sebastian 1279d1ef6b2SChandu Babu N struct axgbe_xstats { 1289d1ef6b2SChandu Babu N char name[RTE_ETH_XSTATS_NAME_SIZE]; 1299d1ef6b2SChandu Babu N int offset; 1309d1ef6b2SChandu Babu N }; 1319d1ef6b2SChandu Babu N 1329d1ef6b2SChandu Babu N #define AXGMAC_MMC_STAT(_string, _var) \ 1339d1ef6b2SChandu Babu N { _string, \ 1349d1ef6b2SChandu Babu N offsetof(struct axgbe_mmc_stats, _var), \ 1359d1ef6b2SChandu Babu N } 1369d1ef6b2SChandu Babu N 1379d1ef6b2SChandu Babu N static const struct axgbe_xstats axgbe_xstats_strings[] = { 1389d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_bytes", txoctetcount_gb), 1399d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_packets", txframecount_gb), 1409d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb), 1419d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb), 1429d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb), 1439d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g), 1449d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb), 1459d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb), 1469d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb), 1479d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb), 1489d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb), 1499d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb), 1509d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror), 1519d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("tx_pause_frames", txpauseframes), 1529d1ef6b2SChandu Babu N 1539d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb), 1549d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_packets", rxframecount_gb), 1559d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g), 1569d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g), 1579d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g), 1589d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb), 1599d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb), 1609d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb), 1619d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb), 1629d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb), 1639d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb), 1649d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb), 1659d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g), 1669d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g), 1679d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_crc_errors", rxcrcerror), 1689d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror), 1699d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror), 1709d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_length_errors", rxlengtherror), 1719d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype), 1729d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow), 1739d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror), 1749d1ef6b2SChandu Babu N AXGMAC_MMC_STAT("rx_pause_frames", rxpauseframes), 1759d1ef6b2SChandu Babu N }; 1769d1ef6b2SChandu Babu N 1779d1ef6b2SChandu Babu N #define AXGBE_XSTATS_COUNT ARRAY_SIZE(axgbe_xstats_strings) 1789d1ef6b2SChandu Babu N 1798691632fSRavi Kumar /* The set of PCI devices this driver supports */ 1808691632fSRavi Kumar #define AMD_PCI_VENDOR_ID 0x1022 181*a27ff9caSSelwin Sebastian 182*a27ff9caSSelwin Sebastian #define Fam17h 0x17 183*a27ff9caSSelwin Sebastian #define Fam19h 0x19 184*a27ff9caSSelwin Sebastian 185*a27ff9caSSelwin Sebastian #define CPUID_VENDOR_AuthenticAMD_ebx 0x68747541 186*a27ff9caSSelwin Sebastian #define CPUID_VENDOR_AuthenticAMD_ecx 0x444d4163 187*a27ff9caSSelwin Sebastian #define CPUID_VENDOR_AuthenticAMD_edx 0x69746e65 188*a27ff9caSSelwin Sebastian 1898691632fSRavi Kumar #define AMD_PCI_AXGBE_DEVICE_V2A 0x1458 1908691632fSRavi Kumar #define AMD_PCI_AXGBE_DEVICE_V2B 0x1459 1918691632fSRavi Kumar 1928691632fSRavi Kumar static const struct rte_pci_id pci_id_axgbe_map[] = { 1938691632fSRavi Kumar {RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_AXGBE_DEVICE_V2A)}, 1948691632fSRavi Kumar {RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_AXGBE_DEVICE_V2B)}, 1958691632fSRavi Kumar { .vendor_id = 0, }, 1968691632fSRavi Kumar }; 1978691632fSRavi Kumar 198572890efSRavi Kumar static struct axgbe_version_data axgbe_v2a = { 1994ac7516bSRavi Kumar .init_function_ptrs_phy_impl = axgbe_init_function_ptrs_phy_v2, 200572890efSRavi Kumar .xpcs_access = AXGBE_XPCS_ACCESS_V2, 201572890efSRavi Kumar .mmc_64bit = 1, 202572890efSRavi Kumar .tx_max_fifo_size = 229376, 203572890efSRavi Kumar .rx_max_fifo_size = 229376, 204572890efSRavi Kumar .tx_tstamp_workaround = 1, 205572890efSRavi Kumar .ecc_support = 1, 206572890efSRavi Kumar .i2c_support = 1, 20700072056SRavi Kumar .an_cdr_workaround = 1, 208572890efSRavi Kumar }; 209572890efSRavi Kumar 210572890efSRavi Kumar static struct axgbe_version_data axgbe_v2b = { 2114ac7516bSRavi Kumar .init_function_ptrs_phy_impl = axgbe_init_function_ptrs_phy_v2, 212572890efSRavi Kumar .xpcs_access = AXGBE_XPCS_ACCESS_V2, 213572890efSRavi Kumar .mmc_64bit = 1, 214572890efSRavi Kumar .tx_max_fifo_size = 65536, 215572890efSRavi Kumar .rx_max_fifo_size = 65536, 216572890efSRavi Kumar .tx_tstamp_workaround = 1, 217572890efSRavi Kumar .ecc_support = 1, 218572890efSRavi Kumar .i2c_support = 1, 21900072056SRavi Kumar .an_cdr_workaround = 1, 220572890efSRavi Kumar }; 221572890efSRavi Kumar 2229e890103SRavi Kumar static const struct rte_eth_desc_lim rx_desc_lim = { 2239e890103SRavi Kumar .nb_max = AXGBE_MAX_RING_DESC, 2249e890103SRavi Kumar .nb_min = AXGBE_MIN_RING_DESC, 2259e890103SRavi Kumar .nb_align = 8, 2269e890103SRavi Kumar }; 2279e890103SRavi Kumar 2289e890103SRavi Kumar static const struct rte_eth_desc_lim tx_desc_lim = { 2299e890103SRavi Kumar .nb_max = AXGBE_MAX_RING_DESC, 2309e890103SRavi Kumar .nb_min = AXGBE_MIN_RING_DESC, 2319e890103SRavi Kumar .nb_align = 8, 2329e890103SRavi Kumar }; 2339e890103SRavi Kumar 2349e890103SRavi Kumar static const struct eth_dev_ops axgbe_eth_dev_ops = { 2357c4158a5SRavi Kumar .dev_configure = axgbe_dev_configure, 2367c4158a5SRavi Kumar .dev_start = axgbe_dev_start, 2377c4158a5SRavi Kumar .dev_stop = axgbe_dev_stop, 2389e890103SRavi Kumar .dev_close = axgbe_dev_close, 239bf403cfeSSelwin Sebastian .dev_reset = axgbe_dev_reset, 240fa3e0440SRavi Kumar .promiscuous_enable = axgbe_dev_promiscuous_enable, 241fa3e0440SRavi Kumar .promiscuous_disable = axgbe_dev_promiscuous_disable, 242fa3e0440SRavi Kumar .allmulticast_enable = axgbe_dev_allmulticast_enable, 243fa3e0440SRavi Kumar .allmulticast_disable = axgbe_dev_allmulticast_disable, 24449a5e622SChandu Babu N .mac_addr_set = axgbe_dev_mac_addr_set, 24549a5e622SChandu Babu N .mac_addr_add = axgbe_dev_mac_addr_add, 24649a5e622SChandu Babu N .mac_addr_remove = axgbe_dev_mac_addr_remove, 24749a5e622SChandu Babu N .set_mc_addr_list = axgbe_dev_set_mc_addr_list, 248e01d9b2eSChandu Babu N .uc_hash_table_set = axgbe_dev_uc_hash_table_set, 249e01d9b2eSChandu Babu N .uc_all_hash_table_set = axgbe_dev_uc_all_hash_table_set, 25044d45ffeSRavi Kumar .link_update = axgbe_dev_link_update, 251df4867cdSChandu Babu N .get_reg = axgbe_dev_get_regs, 2523e730511SRavi Kumar .stats_get = axgbe_dev_stats_get, 2533e730511SRavi Kumar .stats_reset = axgbe_dev_stats_reset, 2549d1ef6b2SChandu Babu N .xstats_get = axgbe_dev_xstats_get, 2559d1ef6b2SChandu Babu N .xstats_reset = axgbe_dev_xstats_reset, 2569d1ef6b2SChandu Babu N .xstats_get_names = axgbe_dev_xstats_get_names, 2579d1ef6b2SChandu Babu N .xstats_get_names_by_id = axgbe_dev_xstats_get_names_by_id, 2589d1ef6b2SChandu Babu N .xstats_get_by_id = axgbe_dev_xstats_get_by_id, 25976d7664dSChandu Babu N .reta_update = axgbe_dev_rss_reta_update, 26076d7664dSChandu Babu N .reta_query = axgbe_dev_rss_reta_query, 26176d7664dSChandu Babu N .rss_hash_update = axgbe_dev_rss_hash_update, 26276d7664dSChandu Babu N .rss_hash_conf_get = axgbe_dev_rss_hash_conf_get, 2639e890103SRavi Kumar .dev_infos_get = axgbe_dev_info_get, 2649e890103SRavi Kumar .rx_queue_setup = axgbe_dev_rx_queue_setup, 2659e890103SRavi Kumar .rx_queue_release = axgbe_dev_rx_queue_release, 2669e890103SRavi Kumar .tx_queue_setup = axgbe_dev_tx_queue_setup, 2679e890103SRavi Kumar .tx_queue_release = axgbe_dev_tx_queue_release, 268cf97f33eSAmaranath Somalapuram .flow_ctrl_get = axgbe_flow_ctrl_get, 269cf97f33eSAmaranath Somalapuram .flow_ctrl_set = axgbe_flow_ctrl_set, 270e0543d4eSAmaranath Somalapuram .priority_flow_ctrl_set = axgbe_priority_flow_ctrl_set, 2717aed95c9SAmaranath Somalapuram .rxq_info_get = axgbe_rxq_info_get, 2727aed95c9SAmaranath Somalapuram .txq_info_get = axgbe_txq_info_get, 273410cf087SAmaranath Somalapuram .dev_supported_ptypes_get = axgbe_dev_supported_ptypes_get, 274b58d8781SGirish Nandibasappa .mtu_set = axgb_mtu_set, 27586578516SGirish Nandibasappa .vlan_filter_set = axgbe_vlan_filter_set, 27686578516SGirish Nandibasappa .vlan_tpid_set = axgbe_vlan_tpid_set, 27786578516SGirish Nandibasappa .vlan_offload_set = axgbe_vlan_offload_set, 278e0444948SSelwin Sebastian .timesync_enable = axgbe_timesync_enable, 279e0444948SSelwin Sebastian .timesync_disable = axgbe_timesync_disable, 280e0444948SSelwin Sebastian .timesync_read_rx_timestamp = axgbe_timesync_read_rx_timestamp, 281e0444948SSelwin Sebastian .timesync_read_tx_timestamp = axgbe_timesync_read_tx_timestamp, 282e0444948SSelwin Sebastian .timesync_adjust_time = axgbe_timesync_adjust_time, 283e0444948SSelwin Sebastian .timesync_read_time = axgbe_timesync_read_time, 284e0444948SSelwin Sebastian .timesync_write_time = axgbe_timesync_write_time, 285ff70acdfSSelwin Sebastian .fw_version_get = axgbe_dev_fw_version_get, 2869e890103SRavi Kumar }; 2879e890103SRavi Kumar 2887c4158a5SRavi Kumar static int axgbe_phy_reset(struct axgbe_port *pdata) 2897c4158a5SRavi Kumar { 2907c4158a5SRavi Kumar pdata->phy_link = -1; 2917c4158a5SRavi Kumar pdata->phy_speed = SPEED_UNKNOWN; 2927c4158a5SRavi Kumar return pdata->phy_if.phy_reset(pdata); 2937c4158a5SRavi Kumar } 2947c4158a5SRavi Kumar 295456ff159SRavi Kumar /* 296456ff159SRavi Kumar * Interrupt handler triggered by NIC for handling 297456ff159SRavi Kumar * specific interrupt. 298456ff159SRavi Kumar * 299456ff159SRavi Kumar * @param handle 300456ff159SRavi Kumar * Pointer to interrupt handle. 301456ff159SRavi Kumar * @param param 3027be78d02SJosh Soref * The address of parameter (struct rte_eth_dev *) registered before. 303456ff159SRavi Kumar * 304456ff159SRavi Kumar * @return 305456ff159SRavi Kumar * void 306456ff159SRavi Kumar */ 307456ff159SRavi Kumar static void 308456ff159SRavi Kumar axgbe_dev_interrupt_handler(void *param) 309456ff159SRavi Kumar { 310456ff159SRavi Kumar struct rte_eth_dev *dev = (struct rte_eth_dev *)param; 311456ff159SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 3128590b93dSRavi Kumar unsigned int dma_isr, dma_ch_isr; 313456ff159SRavi Kumar 314456ff159SRavi Kumar pdata->phy_if.an_isr(pdata); 3158590b93dSRavi Kumar /*DMA related interrupts*/ 3168590b93dSRavi Kumar dma_isr = AXGMAC_IOREAD(pdata, DMA_ISR); 3174216cdc0SChandu Babu N PMD_DRV_LOG(DEBUG, "DMA_ISR=%#010x\n", dma_isr); 3188590b93dSRavi Kumar if (dma_isr) { 3198590b93dSRavi Kumar if (dma_isr & 1) { 3208590b93dSRavi Kumar dma_ch_isr = 3218590b93dSRavi Kumar AXGMAC_DMA_IOREAD((struct axgbe_rx_queue *) 3228590b93dSRavi Kumar pdata->rx_queues[0], 3238590b93dSRavi Kumar DMA_CH_SR); 3244216cdc0SChandu Babu N PMD_DRV_LOG(DEBUG, "DMA_CH0_ISR=%#010x\n", dma_ch_isr); 3258590b93dSRavi Kumar AXGMAC_DMA_IOWRITE((struct axgbe_rx_queue *) 3268590b93dSRavi Kumar pdata->rx_queues[0], 3278590b93dSRavi Kumar DMA_CH_SR, dma_ch_isr); 3288590b93dSRavi Kumar } 3298590b93dSRavi Kumar } 3306bee9d5fSNithin Dabilpuram /* Unmask interrupts since disabled after generation */ 331d61138d4SHarman Kalra rte_intr_ack(pdata->pci_dev->intr_handle); 332456ff159SRavi Kumar } 333456ff159SRavi Kumar 3347c4158a5SRavi Kumar /* 3357c4158a5SRavi Kumar * Configure device link speed and setup link. 3367c4158a5SRavi Kumar * It returns 0 on success. 3377c4158a5SRavi Kumar */ 3387c4158a5SRavi Kumar static int 3397c4158a5SRavi Kumar axgbe_dev_configure(struct rte_eth_dev *dev) 3407c4158a5SRavi Kumar { 3417c4158a5SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 3427c4158a5SRavi Kumar /* Checksum offload to hardware */ 3437c4158a5SRavi Kumar pdata->rx_csum_enable = dev->data->dev_conf.rxmode.offloads & 344295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_CHECKSUM; 3457c4158a5SRavi Kumar return 0; 3467c4158a5SRavi Kumar } 3477c4158a5SRavi Kumar 3487c4158a5SRavi Kumar static int 3497c4158a5SRavi Kumar axgbe_dev_rx_mq_config(struct rte_eth_dev *dev) 3507c4158a5SRavi Kumar { 3510bc212a8SStephen Hemminger struct axgbe_port *pdata = dev->data->dev_private; 3527c4158a5SRavi Kumar 353295968d1SFerruh Yigit if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS) 3547c4158a5SRavi Kumar pdata->rss_enable = 1; 355295968d1SFerruh Yigit else if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_NONE) 3567c4158a5SRavi Kumar pdata->rss_enable = 0; 3577c4158a5SRavi Kumar else 3587c4158a5SRavi Kumar return -1; 3597c4158a5SRavi Kumar return 0; 3607c4158a5SRavi Kumar } 3617c4158a5SRavi Kumar 3627c4158a5SRavi Kumar static int 3637c4158a5SRavi Kumar axgbe_dev_start(struct rte_eth_dev *dev) 3647c4158a5SRavi Kumar { 3650bc212a8SStephen Hemminger struct axgbe_port *pdata = dev->data->dev_private; 3667c4158a5SRavi Kumar int ret; 367965b3127SSelwin Sebastian 368965b3127SSelwin Sebastian dev->dev_ops = &axgbe_eth_dev_ops; 3697c4158a5SRavi Kumar 3700bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 3710bc212a8SStephen Hemminger 3727c4158a5SRavi Kumar /* Multiqueue RSS */ 3737c4158a5SRavi Kumar ret = axgbe_dev_rx_mq_config(dev); 3747c4158a5SRavi Kumar if (ret) { 3757c4158a5SRavi Kumar PMD_DRV_LOG(ERR, "Unable to config RX MQ\n"); 3767c4158a5SRavi Kumar return ret; 3777c4158a5SRavi Kumar } 3787c4158a5SRavi Kumar ret = axgbe_phy_reset(pdata); 3797c4158a5SRavi Kumar if (ret) { 3807c4158a5SRavi Kumar PMD_DRV_LOG(ERR, "phy reset failed\n"); 3817c4158a5SRavi Kumar return ret; 3827c4158a5SRavi Kumar } 3837c4158a5SRavi Kumar ret = pdata->hw_if.init(pdata); 3847c4158a5SRavi Kumar if (ret) { 3857c4158a5SRavi Kumar PMD_DRV_LOG(ERR, "dev_init failed\n"); 3867c4158a5SRavi Kumar return ret; 3877c4158a5SRavi Kumar } 3887c4158a5SRavi Kumar 3897c4158a5SRavi Kumar /* enable uio/vfio intr/eventfd mapping */ 390d61138d4SHarman Kalra rte_intr_enable(pdata->pci_dev->intr_handle); 3917c4158a5SRavi Kumar 3927c4158a5SRavi Kumar /* phy start*/ 3937c4158a5SRavi Kumar pdata->phy_if.phy_start(pdata); 3948590b93dSRavi Kumar axgbe_dev_enable_tx(dev); 3958590b93dSRavi Kumar axgbe_dev_enable_rx(dev); 3967c4158a5SRavi Kumar 3974693ae4aSJoyce Kong rte_bit_relaxed_clear32(AXGBE_STOPPED, &pdata->dev_state); 3984693ae4aSJoyce Kong rte_bit_relaxed_clear32(AXGBE_DOWN, &pdata->dev_state); 3991bb4a528SFerruh Yigit 4009963b513SJesna K E axgbe_set_rx_function(dev); 4019963b513SJesna K E axgbe_set_tx_function(dev); 4027c4158a5SRavi Kumar return 0; 4037c4158a5SRavi Kumar } 4047c4158a5SRavi Kumar 4057c4158a5SRavi Kumar /* Stop device: disable rx and tx functions to allow for reconfiguring. */ 40662024eb8SIvan Ilchenko static int 4077c4158a5SRavi Kumar axgbe_dev_stop(struct rte_eth_dev *dev) 4087c4158a5SRavi Kumar { 4097c4158a5SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 4107c4158a5SRavi Kumar 4110bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4120bc212a8SStephen Hemminger 413d61138d4SHarman Kalra rte_intr_disable(pdata->pci_dev->intr_handle); 4147c4158a5SRavi Kumar 4154693ae4aSJoyce Kong if (rte_bit_relaxed_get32(AXGBE_STOPPED, &pdata->dev_state)) 41662024eb8SIvan Ilchenko return 0; 4177c4158a5SRavi Kumar 4184693ae4aSJoyce Kong rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state); 4198590b93dSRavi Kumar axgbe_dev_disable_tx(dev); 4208590b93dSRavi Kumar axgbe_dev_disable_rx(dev); 4217c4158a5SRavi Kumar 4227c4158a5SRavi Kumar pdata->phy_if.phy_stop(pdata); 4237c4158a5SRavi Kumar pdata->hw_if.exit(pdata); 4247c4158a5SRavi Kumar memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link)); 4254693ae4aSJoyce Kong rte_bit_relaxed_set32(AXGBE_DOWN, &pdata->dev_state); 42662024eb8SIvan Ilchenko 42762024eb8SIvan Ilchenko return 0; 4287c4158a5SRavi Kumar } 4297c4158a5SRavi Kumar 4309039c812SAndrew Rybchenko static int 431fa3e0440SRavi Kumar axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev) 432fa3e0440SRavi Kumar { 433fa3e0440SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 434fa3e0440SRavi Kumar 4350bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4360bc212a8SStephen Hemminger 437fa3e0440SRavi Kumar AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 1); 4389039c812SAndrew Rybchenko 4399039c812SAndrew Rybchenko return 0; 440fa3e0440SRavi Kumar } 441fa3e0440SRavi Kumar 4429039c812SAndrew Rybchenko static int 443fa3e0440SRavi Kumar axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev) 444fa3e0440SRavi Kumar { 445fa3e0440SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 446fa3e0440SRavi Kumar 4470bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4480bc212a8SStephen Hemminger 449fa3e0440SRavi Kumar AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 0); 4509039c812SAndrew Rybchenko 4519039c812SAndrew Rybchenko return 0; 452fa3e0440SRavi Kumar } 453fa3e0440SRavi Kumar 454ca041cd4SIvan Ilchenko static int 455fa3e0440SRavi Kumar axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev) 456fa3e0440SRavi Kumar { 457fa3e0440SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 458fa3e0440SRavi Kumar 4590bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4600bc212a8SStephen Hemminger 461fa3e0440SRavi Kumar if (AXGMAC_IOREAD_BITS(pdata, MAC_PFR, PM)) 462ca041cd4SIvan Ilchenko return 0; 463fa3e0440SRavi Kumar AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, 1); 464ca041cd4SIvan Ilchenko 465ca041cd4SIvan Ilchenko return 0; 466fa3e0440SRavi Kumar } 467fa3e0440SRavi Kumar 468ca041cd4SIvan Ilchenko static int 469fa3e0440SRavi Kumar axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev) 470fa3e0440SRavi Kumar { 471fa3e0440SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 472fa3e0440SRavi Kumar 4730bc212a8SStephen Hemminger PMD_INIT_FUNC_TRACE(); 4740bc212a8SStephen Hemminger 475fa3e0440SRavi Kumar if (!AXGMAC_IOREAD_BITS(pdata, MAC_PFR, PM)) 476ca041cd4SIvan Ilchenko return 0; 477fa3e0440SRavi Kumar AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, 0); 478ca041cd4SIvan Ilchenko 479ca041cd4SIvan Ilchenko return 0; 480fa3e0440SRavi Kumar } 481fa3e0440SRavi Kumar 48249a5e622SChandu Babu N static int 48349a5e622SChandu Babu N axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) 48449a5e622SChandu Babu N { 48549a5e622SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 48649a5e622SChandu Babu N 48749a5e622SChandu Babu N /* Set Default MAC Addr */ 48849a5e622SChandu Babu N axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, 0); 48949a5e622SChandu Babu N 49049a5e622SChandu Babu N return 0; 49149a5e622SChandu Babu N } 49249a5e622SChandu Babu N 49349a5e622SChandu Babu N static int 49449a5e622SChandu Babu N axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr, 49549a5e622SChandu Babu N uint32_t index, uint32_t pool __rte_unused) 49649a5e622SChandu Babu N { 49749a5e622SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 49849a5e622SChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 49949a5e622SChandu Babu N 50049a5e622SChandu Babu N if (index > hw_feat->addn_mac) { 50149a5e622SChandu Babu N PMD_DRV_LOG(ERR, "Invalid Index %d\n", index); 50249a5e622SChandu Babu N return -EINVAL; 50349a5e622SChandu Babu N } 50449a5e622SChandu Babu N axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, index); 50549a5e622SChandu Babu N return 0; 50649a5e622SChandu Babu N } 50749a5e622SChandu Babu N 50876d7664dSChandu Babu N static int 50976d7664dSChandu Babu N axgbe_dev_rss_reta_update(struct rte_eth_dev *dev, 51076d7664dSChandu Babu N struct rte_eth_rss_reta_entry64 *reta_conf, 51176d7664dSChandu Babu N uint16_t reta_size) 51276d7664dSChandu Babu N { 51376d7664dSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 51476d7664dSChandu Babu N unsigned int i, idx, shift; 51576d7664dSChandu Babu N int ret; 51676d7664dSChandu Babu N 51776d7664dSChandu Babu N if (!pdata->rss_enable) { 51876d7664dSChandu Babu N PMD_DRV_LOG(ERR, "RSS not enabled\n"); 51976d7664dSChandu Babu N return -ENOTSUP; 52076d7664dSChandu Babu N } 52176d7664dSChandu Babu N 52276d7664dSChandu Babu N if (reta_size == 0 || reta_size > AXGBE_RSS_MAX_TABLE_SIZE) { 52376d7664dSChandu Babu N PMD_DRV_LOG(ERR, "reta_size %d is not supported\n", reta_size); 52476d7664dSChandu Babu N return -EINVAL; 52576d7664dSChandu Babu N } 52676d7664dSChandu Babu N 52776d7664dSChandu Babu N for (i = 0; i < reta_size; i++) { 528295968d1SFerruh Yigit idx = i / RTE_ETH_RETA_GROUP_SIZE; 529295968d1SFerruh Yigit shift = i % RTE_ETH_RETA_GROUP_SIZE; 53076d7664dSChandu Babu N if ((reta_conf[idx].mask & (1ULL << shift)) == 0) 53176d7664dSChandu Babu N continue; 53276d7664dSChandu Babu N pdata->rss_table[i] = reta_conf[idx].reta[shift]; 53376d7664dSChandu Babu N } 53476d7664dSChandu Babu N 53576d7664dSChandu Babu N /* Program the lookup table */ 53676d7664dSChandu Babu N ret = axgbe_write_rss_lookup_table(pdata); 53776d7664dSChandu Babu N return ret; 53876d7664dSChandu Babu N } 53976d7664dSChandu Babu N 54076d7664dSChandu Babu N static int 54176d7664dSChandu Babu N axgbe_dev_rss_reta_query(struct rte_eth_dev *dev, 54276d7664dSChandu Babu N struct rte_eth_rss_reta_entry64 *reta_conf, 54376d7664dSChandu Babu N uint16_t reta_size) 54476d7664dSChandu Babu N { 54576d7664dSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 54676d7664dSChandu Babu N unsigned int i, idx, shift; 54776d7664dSChandu Babu N 54876d7664dSChandu Babu N if (!pdata->rss_enable) { 54976d7664dSChandu Babu N PMD_DRV_LOG(ERR, "RSS not enabled\n"); 55076d7664dSChandu Babu N return -ENOTSUP; 55176d7664dSChandu Babu N } 55276d7664dSChandu Babu N 55376d7664dSChandu Babu N if (reta_size == 0 || reta_size > AXGBE_RSS_MAX_TABLE_SIZE) { 55476d7664dSChandu Babu N PMD_DRV_LOG(ERR, "reta_size %d is not supported\n", reta_size); 55576d7664dSChandu Babu N return -EINVAL; 55676d7664dSChandu Babu N } 55776d7664dSChandu Babu N 55876d7664dSChandu Babu N for (i = 0; i < reta_size; i++) { 559295968d1SFerruh Yigit idx = i / RTE_ETH_RETA_GROUP_SIZE; 560295968d1SFerruh Yigit shift = i % RTE_ETH_RETA_GROUP_SIZE; 56176d7664dSChandu Babu N if ((reta_conf[idx].mask & (1ULL << shift)) == 0) 56276d7664dSChandu Babu N continue; 56376d7664dSChandu Babu N reta_conf[idx].reta[shift] = pdata->rss_table[i]; 56476d7664dSChandu Babu N } 56576d7664dSChandu Babu N return 0; 56676d7664dSChandu Babu N } 56776d7664dSChandu Babu N 56876d7664dSChandu Babu N static int 56976d7664dSChandu Babu N axgbe_dev_rss_hash_update(struct rte_eth_dev *dev, 57076d7664dSChandu Babu N struct rte_eth_rss_conf *rss_conf) 57176d7664dSChandu Babu N { 57276d7664dSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 57376d7664dSChandu Babu N int ret; 57476d7664dSChandu Babu N 57576d7664dSChandu Babu N if (!pdata->rss_enable) { 57676d7664dSChandu Babu N PMD_DRV_LOG(ERR, "RSS not enabled\n"); 57776d7664dSChandu Babu N return -ENOTSUP; 57876d7664dSChandu Babu N } 57976d7664dSChandu Babu N 58076d7664dSChandu Babu N if (rss_conf == NULL) { 58176d7664dSChandu Babu N PMD_DRV_LOG(ERR, "rss_conf value isn't valid\n"); 58276d7664dSChandu Babu N return -EINVAL; 58376d7664dSChandu Babu N } 58476d7664dSChandu Babu N 58576d7664dSChandu Babu N if (rss_conf->rss_key != NULL && 58676d7664dSChandu Babu N rss_conf->rss_key_len == AXGBE_RSS_HASH_KEY_SIZE) { 58776d7664dSChandu Babu N rte_memcpy(pdata->rss_key, rss_conf->rss_key, 58876d7664dSChandu Babu N AXGBE_RSS_HASH_KEY_SIZE); 58976d7664dSChandu Babu N /* Program the hash key */ 59076d7664dSChandu Babu N ret = axgbe_write_rss_hash_key(pdata); 59176d7664dSChandu Babu N if (ret != 0) 59276d7664dSChandu Babu N return ret; 59376d7664dSChandu Babu N } 59476d7664dSChandu Babu N 59576d7664dSChandu Babu N pdata->rss_hf = rss_conf->rss_hf & AXGBE_RSS_OFFLOAD; 59676d7664dSChandu Babu N 597295968d1SFerruh Yigit if (pdata->rss_hf & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6)) 59876d7664dSChandu Babu N AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1); 59976d7664dSChandu Babu N if (pdata->rss_hf & 600295968d1SFerruh Yigit (RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_NONFRAG_IPV6_TCP)) 60176d7664dSChandu Babu N AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1); 60276d7664dSChandu Babu N if (pdata->rss_hf & 603295968d1SFerruh Yigit (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV6_UDP)) 60476d7664dSChandu Babu N AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1); 60576d7664dSChandu Babu N 60676d7664dSChandu Babu N /* Set the RSS options */ 60776d7664dSChandu Babu N AXGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options); 60876d7664dSChandu Babu N 60976d7664dSChandu Babu N return 0; 61076d7664dSChandu Babu N } 61176d7664dSChandu Babu N 61276d7664dSChandu Babu N static int 61376d7664dSChandu Babu N axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev, 61476d7664dSChandu Babu N struct rte_eth_rss_conf *rss_conf) 61576d7664dSChandu Babu N { 61676d7664dSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 61776d7664dSChandu Babu N 61876d7664dSChandu Babu N if (!pdata->rss_enable) { 61976d7664dSChandu Babu N PMD_DRV_LOG(ERR, "RSS not enabled\n"); 62076d7664dSChandu Babu N return -ENOTSUP; 62176d7664dSChandu Babu N } 62276d7664dSChandu Babu N 62376d7664dSChandu Babu N if (rss_conf == NULL) { 62476d7664dSChandu Babu N PMD_DRV_LOG(ERR, "rss_conf value isn't valid\n"); 62576d7664dSChandu Babu N return -EINVAL; 62676d7664dSChandu Babu N } 62776d7664dSChandu Babu N 62876d7664dSChandu Babu N if (rss_conf->rss_key != NULL && 62976d7664dSChandu Babu N rss_conf->rss_key_len >= AXGBE_RSS_HASH_KEY_SIZE) { 63076d7664dSChandu Babu N rte_memcpy(rss_conf->rss_key, pdata->rss_key, 63176d7664dSChandu Babu N AXGBE_RSS_HASH_KEY_SIZE); 63276d7664dSChandu Babu N } 63376d7664dSChandu Babu N rss_conf->rss_key_len = AXGBE_RSS_HASH_KEY_SIZE; 63476d7664dSChandu Babu N rss_conf->rss_hf = pdata->rss_hf; 63576d7664dSChandu Babu N return 0; 63676d7664dSChandu Babu N } 63776d7664dSChandu Babu N 638bf403cfeSSelwin Sebastian static int 639bf403cfeSSelwin Sebastian axgbe_dev_reset(struct rte_eth_dev *dev) 640bf403cfeSSelwin Sebastian { 641bf403cfeSSelwin Sebastian int ret = 0; 642bf403cfeSSelwin Sebastian 643bf403cfeSSelwin Sebastian ret = axgbe_dev_close(dev); 644bf403cfeSSelwin Sebastian if (ret) 645bf403cfeSSelwin Sebastian return ret; 646bf403cfeSSelwin Sebastian 647bf403cfeSSelwin Sebastian ret = eth_axgbe_dev_init(dev); 648bf403cfeSSelwin Sebastian 649bf403cfeSSelwin Sebastian return ret; 650bf403cfeSSelwin Sebastian } 651bf403cfeSSelwin Sebastian 65249a5e622SChandu Babu N static void 65349a5e622SChandu Babu N axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) 65449a5e622SChandu Babu N { 65549a5e622SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 65649a5e622SChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 65749a5e622SChandu Babu N 65849a5e622SChandu Babu N if (index > hw_feat->addn_mac) { 65949a5e622SChandu Babu N PMD_DRV_LOG(ERR, "Invalid Index %d\n", index); 66049a5e622SChandu Babu N return; 66149a5e622SChandu Babu N } 66249a5e622SChandu Babu N axgbe_set_mac_addn_addr(pdata, NULL, index); 66349a5e622SChandu Babu N } 66449a5e622SChandu Babu N 66549a5e622SChandu Babu N static int 66649a5e622SChandu Babu N axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev, 66749a5e622SChandu Babu N struct rte_ether_addr *mc_addr_set, 66849a5e622SChandu Babu N uint32_t nb_mc_addr) 66949a5e622SChandu Babu N { 67049a5e622SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 67149a5e622SChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 67249a5e622SChandu Babu N uint32_t index = 1; /* 0 is always default mac */ 67349a5e622SChandu Babu N uint32_t i; 67449a5e622SChandu Babu N 67549a5e622SChandu Babu N if (nb_mc_addr > hw_feat->addn_mac) { 67649a5e622SChandu Babu N PMD_DRV_LOG(ERR, "Invalid Index %d\n", nb_mc_addr); 67749a5e622SChandu Babu N return -EINVAL; 67849a5e622SChandu Babu N } 67949a5e622SChandu Babu N 68049a5e622SChandu Babu N /* clear unicast addresses */ 68149a5e622SChandu Babu N for (i = 1; i < hw_feat->addn_mac; i++) { 68249a5e622SChandu Babu N if (rte_is_zero_ether_addr(&dev->data->mac_addrs[i])) 68349a5e622SChandu Babu N continue; 68449a5e622SChandu Babu N memset(&dev->data->mac_addrs[i], 0, 68549a5e622SChandu Babu N sizeof(struct rte_ether_addr)); 68649a5e622SChandu Babu N } 68749a5e622SChandu Babu N 68849a5e622SChandu Babu N while (nb_mc_addr--) 68949a5e622SChandu Babu N axgbe_set_mac_addn_addr(pdata, (u8 *)mc_addr_set++, index++); 69049a5e622SChandu Babu N 69149a5e622SChandu Babu N return 0; 69249a5e622SChandu Babu N } 69349a5e622SChandu Babu N 694e01d9b2eSChandu Babu N static int 695e01d9b2eSChandu Babu N axgbe_dev_uc_hash_table_set(struct rte_eth_dev *dev, 696e01d9b2eSChandu Babu N struct rte_ether_addr *mac_addr, uint8_t add) 697e01d9b2eSChandu Babu N { 698e01d9b2eSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 699e01d9b2eSChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 700e01d9b2eSChandu Babu N 701e01d9b2eSChandu Babu N if (!hw_feat->hash_table_size) { 702e01d9b2eSChandu Babu N PMD_DRV_LOG(ERR, "MAC Hash Table not supported\n"); 703e01d9b2eSChandu Babu N return -ENOTSUP; 704e01d9b2eSChandu Babu N } 705e01d9b2eSChandu Babu N 706e01d9b2eSChandu Babu N axgbe_set_mac_hash_table(pdata, (u8 *)mac_addr, add); 707e01d9b2eSChandu Babu N 708e01d9b2eSChandu Babu N if (pdata->uc_hash_mac_addr > 0) { 709e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1); 710e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1); 711e01d9b2eSChandu Babu N } else { 712e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 0); 713e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0); 714e01d9b2eSChandu Babu N } 715e01d9b2eSChandu Babu N return 0; 716e01d9b2eSChandu Babu N } 717e01d9b2eSChandu Babu N 718e01d9b2eSChandu Babu N static int 719e01d9b2eSChandu Babu N axgbe_dev_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t add) 720e01d9b2eSChandu Babu N { 721e01d9b2eSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 722e01d9b2eSChandu Babu N struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 723e01d9b2eSChandu Babu N uint32_t index; 724e01d9b2eSChandu Babu N 725e01d9b2eSChandu Babu N if (!hw_feat->hash_table_size) { 726e01d9b2eSChandu Babu N PMD_DRV_LOG(ERR, "MAC Hash Table not supported\n"); 727e01d9b2eSChandu Babu N return -ENOTSUP; 728e01d9b2eSChandu Babu N } 729e01d9b2eSChandu Babu N 730e01d9b2eSChandu Babu N for (index = 0; index < pdata->hash_table_count; index++) { 731e01d9b2eSChandu Babu N if (add) 732e01d9b2eSChandu Babu N pdata->uc_hash_table[index] = ~0; 733e01d9b2eSChandu Babu N else 734e01d9b2eSChandu Babu N pdata->uc_hash_table[index] = 0; 735e01d9b2eSChandu Babu N 736e01d9b2eSChandu Babu N PMD_DRV_LOG(DEBUG, "%s MAC hash table at Index %#x\n", 737e01d9b2eSChandu Babu N add ? "set" : "clear", index); 738e01d9b2eSChandu Babu N 739e01d9b2eSChandu Babu N AXGMAC_IOWRITE(pdata, MAC_HTR(index), 740e01d9b2eSChandu Babu N pdata->uc_hash_table[index]); 741e01d9b2eSChandu Babu N } 742e01d9b2eSChandu Babu N 743e01d9b2eSChandu Babu N if (add) { 744e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1); 745e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1); 746e01d9b2eSChandu Babu N } else { 747e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 0); 748e01d9b2eSChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0); 749e01d9b2eSChandu Babu N } 750e01d9b2eSChandu Babu N return 0; 751e01d9b2eSChandu Babu N } 752e01d9b2eSChandu Babu N 75344d45ffeSRavi Kumar /* return 0 means link status changed, -1 means not changed */ 75444d45ffeSRavi Kumar static int 75544d45ffeSRavi Kumar axgbe_dev_link_update(struct rte_eth_dev *dev, 75644d45ffeSRavi Kumar int wait_to_complete __rte_unused) 75744d45ffeSRavi Kumar { 75844d45ffeSRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 75944d45ffeSRavi Kumar struct rte_eth_link link; 76044d45ffeSRavi Kumar int ret = 0; 76144d45ffeSRavi Kumar 76244d45ffeSRavi Kumar PMD_INIT_FUNC_TRACE(); 76344d45ffeSRavi Kumar rte_delay_ms(800); 76444d45ffeSRavi Kumar 76544d45ffeSRavi Kumar pdata->phy_if.phy_status(pdata); 76644d45ffeSRavi Kumar 76744d45ffeSRavi Kumar memset(&link, 0, sizeof(struct rte_eth_link)); 76844d45ffeSRavi Kumar link.link_duplex = pdata->phy.duplex; 76944d45ffeSRavi Kumar link.link_status = pdata->phy_link; 77044d45ffeSRavi Kumar link.link_speed = pdata->phy_speed; 77144d45ffeSRavi Kumar link.link_autoneg = !(dev->data->dev_conf.link_speeds & 772295968d1SFerruh Yigit RTE_ETH_LINK_SPEED_FIXED); 77344d45ffeSRavi Kumar ret = rte_eth_linkstatus_set(dev, &link); 77444d45ffeSRavi Kumar if (ret == -1) 77544d45ffeSRavi Kumar PMD_DRV_LOG(ERR, "No change in link status\n"); 77644d45ffeSRavi Kumar 77744d45ffeSRavi Kumar return ret; 77844d45ffeSRavi Kumar } 77944d45ffeSRavi Kumar 780df4867cdSChandu Babu N static int 781df4867cdSChandu Babu N axgbe_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs) 782df4867cdSChandu Babu N { 783df4867cdSChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 784df4867cdSChandu Babu N 785df4867cdSChandu Babu N if (regs->data == NULL) { 786df4867cdSChandu Babu N regs->length = axgbe_regs_get_count(pdata); 787df4867cdSChandu Babu N regs->width = sizeof(uint32_t); 788df4867cdSChandu Babu N return 0; 789df4867cdSChandu Babu N } 790df4867cdSChandu Babu N 791df4867cdSChandu Babu N /* Only full register dump is supported */ 792df4867cdSChandu Babu N if (regs->length && 793df4867cdSChandu Babu N regs->length != (uint32_t)axgbe_regs_get_count(pdata)) 794df4867cdSChandu Babu N return -ENOTSUP; 795df4867cdSChandu Babu N 796df4867cdSChandu Babu N regs->version = pdata->pci_dev->id.vendor_id << 16 | 797df4867cdSChandu Babu N pdata->pci_dev->id.device_id; 798df4867cdSChandu Babu N axgbe_regs_dump(pdata, regs->data); 799df4867cdSChandu Babu N return 0; 800df4867cdSChandu Babu N } 8019d1ef6b2SChandu Babu N static void axgbe_read_mmc_stats(struct axgbe_port *pdata) 8029d1ef6b2SChandu Babu N { 8039d1ef6b2SChandu Babu N struct axgbe_mmc_stats *stats = &pdata->mmc_stats; 8049d1ef6b2SChandu Babu N 8059d1ef6b2SChandu Babu N /* Freeze counters */ 8069d1ef6b2SChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1); 8079d1ef6b2SChandu Babu N 8089d1ef6b2SChandu Babu N /* Tx counters */ 8099d1ef6b2SChandu Babu N stats->txoctetcount_gb += 8109d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO); 8119d1ef6b2SChandu Babu N stats->txoctetcount_gb += 8129d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_HI) << 32); 8139d1ef6b2SChandu Babu N 8149d1ef6b2SChandu Babu N stats->txframecount_gb += 8159d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO); 8169d1ef6b2SChandu Babu N stats->txframecount_gb += 8179d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_HI) << 32); 8189d1ef6b2SChandu Babu N 8199d1ef6b2SChandu Babu N stats->txbroadcastframes_g += 8209d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO); 8219d1ef6b2SChandu Babu N stats->txbroadcastframes_g += 8229d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_HI) << 32); 8239d1ef6b2SChandu Babu N 8249d1ef6b2SChandu Babu N stats->txmulticastframes_g += 8259d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO); 8269d1ef6b2SChandu Babu N stats->txmulticastframes_g += 8279d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_HI) << 32); 8289d1ef6b2SChandu Babu N 8299d1ef6b2SChandu Babu N stats->tx64octets_gb += 8309d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO); 8319d1ef6b2SChandu Babu N stats->tx64octets_gb += 8329d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_HI) << 32); 8339d1ef6b2SChandu Babu N 8349d1ef6b2SChandu Babu N stats->tx65to127octets_gb += 8359d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO); 8369d1ef6b2SChandu Babu N stats->tx65to127octets_gb += 8379d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_HI) << 32); 8389d1ef6b2SChandu Babu N 8399d1ef6b2SChandu Babu N stats->tx128to255octets_gb += 8409d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO); 8419d1ef6b2SChandu Babu N stats->tx128to255octets_gb += 8429d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_HI) << 32); 8439d1ef6b2SChandu Babu N 8449d1ef6b2SChandu Babu N stats->tx256to511octets_gb += 8459d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO); 8469d1ef6b2SChandu Babu N stats->tx256to511octets_gb += 8479d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_HI) << 32); 8489d1ef6b2SChandu Babu N 8499d1ef6b2SChandu Babu N stats->tx512to1023octets_gb += 8509d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO); 8519d1ef6b2SChandu Babu N stats->tx512to1023octets_gb += 8529d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_HI) << 32); 8539d1ef6b2SChandu Babu N 8549d1ef6b2SChandu Babu N stats->tx1024tomaxoctets_gb += 8559d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO); 8569d1ef6b2SChandu Babu N stats->tx1024tomaxoctets_gb += 8579d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_HI) << 32); 8589d1ef6b2SChandu Babu N 8599d1ef6b2SChandu Babu N stats->txunicastframes_gb += 8609d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO); 8619d1ef6b2SChandu Babu N stats->txunicastframes_gb += 8629d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_HI) << 32); 8639d1ef6b2SChandu Babu N 8649d1ef6b2SChandu Babu N stats->txmulticastframes_gb += 8659d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO); 8669d1ef6b2SChandu Babu N stats->txmulticastframes_gb += 8679d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_HI) << 32); 8689d1ef6b2SChandu Babu N 8699d1ef6b2SChandu Babu N stats->txbroadcastframes_g += 8709d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO); 8719d1ef6b2SChandu Babu N stats->txbroadcastframes_g += 8729d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_HI) << 32); 8739d1ef6b2SChandu Babu N 8749d1ef6b2SChandu Babu N stats->txunderflowerror += 8759d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO); 8769d1ef6b2SChandu Babu N stats->txunderflowerror += 8779d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_HI) << 32); 8789d1ef6b2SChandu Babu N 8799d1ef6b2SChandu Babu N stats->txoctetcount_g += 8809d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO); 8819d1ef6b2SChandu Babu N stats->txoctetcount_g += 8829d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_HI) << 32); 8839d1ef6b2SChandu Babu N 8849d1ef6b2SChandu Babu N stats->txframecount_g += 8859d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO); 8869d1ef6b2SChandu Babu N stats->txframecount_g += 8879d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_HI) << 32); 8889d1ef6b2SChandu Babu N 8899d1ef6b2SChandu Babu N stats->txpauseframes += 8909d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO); 8919d1ef6b2SChandu Babu N stats->txpauseframes += 8929d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_HI) << 32); 8939d1ef6b2SChandu Babu N 8949d1ef6b2SChandu Babu N stats->txvlanframes_g += 8959d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO); 8969d1ef6b2SChandu Babu N stats->txvlanframes_g += 8979d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_HI) << 32); 8989d1ef6b2SChandu Babu N 8999d1ef6b2SChandu Babu N /* Rx counters */ 9009d1ef6b2SChandu Babu N stats->rxframecount_gb += 9019d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO); 9029d1ef6b2SChandu Babu N stats->rxframecount_gb += 9039d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_HI) << 32); 9049d1ef6b2SChandu Babu N 9059d1ef6b2SChandu Babu N stats->rxoctetcount_gb += 9069d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO); 9079d1ef6b2SChandu Babu N stats->rxoctetcount_gb += 9089d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_HI) << 32); 9099d1ef6b2SChandu Babu N 9109d1ef6b2SChandu Babu N stats->rxoctetcount_g += 9119d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO); 9129d1ef6b2SChandu Babu N stats->rxoctetcount_g += 9139d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_HI) << 32); 9149d1ef6b2SChandu Babu N 9159d1ef6b2SChandu Babu N stats->rxbroadcastframes_g += 9169d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO); 9179d1ef6b2SChandu Babu N stats->rxbroadcastframes_g += 9189d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_HI) << 32); 9199d1ef6b2SChandu Babu N 9209d1ef6b2SChandu Babu N stats->rxmulticastframes_g += 9219d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO); 9229d1ef6b2SChandu Babu N stats->rxmulticastframes_g += 9239d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_HI) << 32); 9249d1ef6b2SChandu Babu N 9259d1ef6b2SChandu Babu N stats->rxcrcerror += 9269d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO); 9279d1ef6b2SChandu Babu N stats->rxcrcerror += 9289d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXCRCERROR_HI) << 32); 9299d1ef6b2SChandu Babu N 9309d1ef6b2SChandu Babu N stats->rxrunterror += 9319d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXRUNTERROR); 9329d1ef6b2SChandu Babu N 9339d1ef6b2SChandu Babu N stats->rxjabbererror += 9349d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXJABBERERROR); 9359d1ef6b2SChandu Babu N 9369d1ef6b2SChandu Babu N stats->rxundersize_g += 9379d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G); 9389d1ef6b2SChandu Babu N 9399d1ef6b2SChandu Babu N stats->rxoversize_g += 9409d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G); 9419d1ef6b2SChandu Babu N 9429d1ef6b2SChandu Babu N stats->rx64octets_gb += 9439d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO); 9449d1ef6b2SChandu Babu N stats->rx64octets_gb += 9459d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_HI) << 32); 9469d1ef6b2SChandu Babu N 9479d1ef6b2SChandu Babu N stats->rx65to127octets_gb += 9489d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO); 9499d1ef6b2SChandu Babu N stats->rx65to127octets_gb += 9509d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_HI) << 32); 9519d1ef6b2SChandu Babu N 9529d1ef6b2SChandu Babu N stats->rx128to255octets_gb += 9539d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO); 9549d1ef6b2SChandu Babu N stats->rx128to255octets_gb += 9559d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_HI) << 32); 9569d1ef6b2SChandu Babu N 9579d1ef6b2SChandu Babu N stats->rx256to511octets_gb += 9589d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO); 9599d1ef6b2SChandu Babu N stats->rx256to511octets_gb += 9609d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_HI) << 32); 9619d1ef6b2SChandu Babu N 9629d1ef6b2SChandu Babu N stats->rx512to1023octets_gb += 9639d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO); 9649d1ef6b2SChandu Babu N stats->rx512to1023octets_gb += 9659d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_HI) << 32); 9669d1ef6b2SChandu Babu N 9679d1ef6b2SChandu Babu N stats->rx1024tomaxoctets_gb += 9689d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO); 9699d1ef6b2SChandu Babu N stats->rx1024tomaxoctets_gb += 9709d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_HI) << 32); 9719d1ef6b2SChandu Babu N 9729d1ef6b2SChandu Babu N stats->rxunicastframes_g += 9739d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO); 9749d1ef6b2SChandu Babu N stats->rxunicastframes_g += 9759d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_HI) << 32); 9769d1ef6b2SChandu Babu N 9779d1ef6b2SChandu Babu N stats->rxlengtherror += 9789d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO); 9799d1ef6b2SChandu Babu N stats->rxlengtherror += 9809d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_HI) << 32); 9819d1ef6b2SChandu Babu N 9829d1ef6b2SChandu Babu N stats->rxoutofrangetype += 9839d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO); 9849d1ef6b2SChandu Babu N stats->rxoutofrangetype += 9859d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_HI) << 32); 9869d1ef6b2SChandu Babu N 9879d1ef6b2SChandu Babu N stats->rxpauseframes += 9889d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO); 9899d1ef6b2SChandu Babu N stats->rxpauseframes += 9909d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_HI) << 32); 9919d1ef6b2SChandu Babu N 9929d1ef6b2SChandu Babu N stats->rxfifooverflow += 9939d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO); 9949d1ef6b2SChandu Babu N stats->rxfifooverflow += 9959d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_HI) << 32); 9969d1ef6b2SChandu Babu N 9979d1ef6b2SChandu Babu N stats->rxvlanframes_gb += 9989d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO); 9999d1ef6b2SChandu Babu N stats->rxvlanframes_gb += 10009d1ef6b2SChandu Babu N ((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_HI) << 32); 10019d1ef6b2SChandu Babu N 10029d1ef6b2SChandu Babu N stats->rxwatchdogerror += 10039d1ef6b2SChandu Babu N AXGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR); 10049d1ef6b2SChandu Babu N 10059d1ef6b2SChandu Babu N /* Un-freeze counters */ 10069d1ef6b2SChandu Babu N AXGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0); 10079d1ef6b2SChandu Babu N } 10089d1ef6b2SChandu Babu N 10099d1ef6b2SChandu Babu N static int 10109d1ef6b2SChandu Babu N axgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats, 10119d1ef6b2SChandu Babu N unsigned int n) 10129d1ef6b2SChandu Babu N { 10139d1ef6b2SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 10149d1ef6b2SChandu Babu N unsigned int i; 10159d1ef6b2SChandu Babu N 101693041fd5SChengwen Feng if (n < AXGBE_XSTATS_COUNT) 101793041fd5SChengwen Feng return AXGBE_XSTATS_COUNT; 10189d1ef6b2SChandu Babu N 10199d1ef6b2SChandu Babu N axgbe_read_mmc_stats(pdata); 10209d1ef6b2SChandu Babu N 102193041fd5SChengwen Feng for (i = 0; i < AXGBE_XSTATS_COUNT; i++) { 10229d1ef6b2SChandu Babu N stats[i].id = i; 10239d1ef6b2SChandu Babu N stats[i].value = *(u64 *)((uint8_t *)&pdata->mmc_stats + 10249d1ef6b2SChandu Babu N axgbe_xstats_strings[i].offset); 10259d1ef6b2SChandu Babu N } 10269d1ef6b2SChandu Babu N 102793041fd5SChengwen Feng return AXGBE_XSTATS_COUNT; 10289d1ef6b2SChandu Babu N } 10299d1ef6b2SChandu Babu N 10309d1ef6b2SChandu Babu N static int 10319d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev, 10329d1ef6b2SChandu Babu N struct rte_eth_xstat_name *xstats_names, 10339d1ef6b2SChandu Babu N unsigned int n) 10349d1ef6b2SChandu Babu N { 10359d1ef6b2SChandu Babu N unsigned int i; 10369d1ef6b2SChandu Babu N 10379d1ef6b2SChandu Babu N if (n >= AXGBE_XSTATS_COUNT && xstats_names) { 10389d1ef6b2SChandu Babu N for (i = 0; i < AXGBE_XSTATS_COUNT; ++i) { 10399d1ef6b2SChandu Babu N snprintf(xstats_names[i].name, 10409d1ef6b2SChandu Babu N RTE_ETH_XSTATS_NAME_SIZE, "%s", 10419d1ef6b2SChandu Babu N axgbe_xstats_strings[i].name); 10429d1ef6b2SChandu Babu N } 10439d1ef6b2SChandu Babu N } 10449d1ef6b2SChandu Babu N 10459d1ef6b2SChandu Babu N return AXGBE_XSTATS_COUNT; 10469d1ef6b2SChandu Babu N } 10479d1ef6b2SChandu Babu N 10489d1ef6b2SChandu Babu N static int 10499d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids, 10509d1ef6b2SChandu Babu N uint64_t *values, unsigned int n) 10519d1ef6b2SChandu Babu N { 10529d1ef6b2SChandu Babu N unsigned int i; 10539d1ef6b2SChandu Babu N uint64_t values_copy[AXGBE_XSTATS_COUNT]; 10549d1ef6b2SChandu Babu N 10559d1ef6b2SChandu Babu N if (!ids) { 10569d1ef6b2SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 10579d1ef6b2SChandu Babu N 10589d1ef6b2SChandu Babu N if (n < AXGBE_XSTATS_COUNT) 10599d1ef6b2SChandu Babu N return AXGBE_XSTATS_COUNT; 10609d1ef6b2SChandu Babu N 10619d1ef6b2SChandu Babu N axgbe_read_mmc_stats(pdata); 10629d1ef6b2SChandu Babu N 10639d1ef6b2SChandu Babu N for (i = 0; i < AXGBE_XSTATS_COUNT; i++) { 10649d1ef6b2SChandu Babu N values[i] = *(u64 *)((uint8_t *)&pdata->mmc_stats + 10659d1ef6b2SChandu Babu N axgbe_xstats_strings[i].offset); 10669d1ef6b2SChandu Babu N } 10679d1ef6b2SChandu Babu N 10689d1ef6b2SChandu Babu N return i; 10699d1ef6b2SChandu Babu N } 10709d1ef6b2SChandu Babu N 10719d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(dev, NULL, values_copy, AXGBE_XSTATS_COUNT); 10729d1ef6b2SChandu Babu N 10739d1ef6b2SChandu Babu N for (i = 0; i < n; i++) { 10749d1ef6b2SChandu Babu N if (ids[i] >= AXGBE_XSTATS_COUNT) { 10759d1ef6b2SChandu Babu N PMD_DRV_LOG(ERR, "id value isn't valid\n"); 10769d1ef6b2SChandu Babu N return -1; 10779d1ef6b2SChandu Babu N } 10789d1ef6b2SChandu Babu N values[i] = values_copy[ids[i]]; 10799d1ef6b2SChandu Babu N } 10809d1ef6b2SChandu Babu N return n; 10819d1ef6b2SChandu Babu N } 10829d1ef6b2SChandu Babu N 10839d1ef6b2SChandu Babu N static int 10849d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev, 10859d1ef6b2SChandu Babu N const uint64_t *ids, 10868c9f976fSAndrew Rybchenko struct rte_eth_xstat_name *xstats_names, 10879d1ef6b2SChandu Babu N unsigned int size) 10889d1ef6b2SChandu Babu N { 10899d1ef6b2SChandu Babu N struct rte_eth_xstat_name xstats_names_copy[AXGBE_XSTATS_COUNT]; 10909d1ef6b2SChandu Babu N unsigned int i; 10919d1ef6b2SChandu Babu N 10929d1ef6b2SChandu Babu N if (!ids) 10939d1ef6b2SChandu Babu N return axgbe_dev_xstats_get_names(dev, xstats_names, size); 10949d1ef6b2SChandu Babu N 10959d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(dev, xstats_names_copy, size); 10969d1ef6b2SChandu Babu N 10979d1ef6b2SChandu Babu N for (i = 0; i < size; i++) { 10989d1ef6b2SChandu Babu N if (ids[i] >= AXGBE_XSTATS_COUNT) { 10999d1ef6b2SChandu Babu N PMD_DRV_LOG(ERR, "id value isn't valid\n"); 11009d1ef6b2SChandu Babu N return -1; 11019d1ef6b2SChandu Babu N } 11029d1ef6b2SChandu Babu N strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name); 11039d1ef6b2SChandu Babu N } 11049d1ef6b2SChandu Babu N return size; 11059d1ef6b2SChandu Babu N } 11069d1ef6b2SChandu Babu N 11079d1ef6b2SChandu Babu N static int 11089d1ef6b2SChandu Babu N axgbe_dev_xstats_reset(struct rte_eth_dev *dev) 11099d1ef6b2SChandu Babu N { 11109d1ef6b2SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 11119d1ef6b2SChandu Babu N struct axgbe_mmc_stats *stats = &pdata->mmc_stats; 11129d1ef6b2SChandu Babu N 11139d1ef6b2SChandu Babu N /* MMC registers are configured for reset on read */ 11149d1ef6b2SChandu Babu N axgbe_read_mmc_stats(pdata); 11159d1ef6b2SChandu Babu N 11169d1ef6b2SChandu Babu N /* Reset stats */ 11179d1ef6b2SChandu Babu N memset(stats, 0, sizeof(*stats)); 11189d1ef6b2SChandu Babu N 11199d1ef6b2SChandu Babu N return 0; 11209d1ef6b2SChandu Babu N } 11219d1ef6b2SChandu Babu N 11223e730511SRavi Kumar static int 11233e730511SRavi Kumar axgbe_dev_stats_get(struct rte_eth_dev *dev, 11243e730511SRavi Kumar struct rte_eth_stats *stats) 11253e730511SRavi Kumar { 11263e730511SRavi Kumar struct axgbe_rx_queue *rxq; 11273e730511SRavi Kumar struct axgbe_tx_queue *txq; 11289d1ef6b2SChandu Babu N struct axgbe_port *pdata = dev->data->dev_private; 11299d1ef6b2SChandu Babu N struct axgbe_mmc_stats *mmc_stats = &pdata->mmc_stats; 11303e730511SRavi Kumar unsigned int i; 11313e730511SRavi Kumar 11329d1ef6b2SChandu Babu N axgbe_read_mmc_stats(pdata); 11339d1ef6b2SChandu Babu N 11349d1ef6b2SChandu Babu N stats->imissed = mmc_stats->rxfifooverflow; 11359d1ef6b2SChandu Babu N 11363e730511SRavi Kumar for (i = 0; i < dev->data->nb_rx_queues; i++) { 11373e730511SRavi Kumar rxq = dev->data->rx_queues[i]; 1138bf403cfeSSelwin Sebastian if (rxq) { 11393e730511SRavi Kumar stats->q_ipackets[i] = rxq->pkts; 11403e730511SRavi Kumar stats->ipackets += rxq->pkts; 11413e730511SRavi Kumar stats->q_ibytes[i] = rxq->bytes; 11423e730511SRavi Kumar stats->ibytes += rxq->bytes; 11439d1ef6b2SChandu Babu N stats->rx_nombuf += rxq->rx_mbuf_alloc_failed; 1144bf403cfeSSelwin Sebastian stats->q_errors[i] = rxq->errors 1145bf403cfeSSelwin Sebastian + rxq->rx_mbuf_alloc_failed; 11469d1ef6b2SChandu Babu N stats->ierrors += rxq->errors; 1147bf403cfeSSelwin Sebastian } else { 1148bf403cfeSSelwin Sebastian PMD_DRV_LOG(DEBUG, "Rx queue not setup for port %d\n", 1149bf403cfeSSelwin Sebastian dev->data->port_id); 1150bf403cfeSSelwin Sebastian } 11513e730511SRavi Kumar } 11529d1ef6b2SChandu Babu N 11533e730511SRavi Kumar for (i = 0; i < dev->data->nb_tx_queues; i++) { 11543e730511SRavi Kumar txq = dev->data->tx_queues[i]; 1155bf403cfeSSelwin Sebastian if (txq) { 11563e730511SRavi Kumar stats->q_opackets[i] = txq->pkts; 11573e730511SRavi Kumar stats->opackets += txq->pkts; 11583e730511SRavi Kumar stats->q_obytes[i] = txq->bytes; 11593e730511SRavi Kumar stats->obytes += txq->bytes; 11609d1ef6b2SChandu Babu N stats->oerrors += txq->errors; 1161bf403cfeSSelwin Sebastian } else { 1162bf403cfeSSelwin Sebastian PMD_DRV_LOG(DEBUG, "Tx queue not setup for port %d\n", 1163bf403cfeSSelwin Sebastian dev->data->port_id); 1164bf403cfeSSelwin Sebastian } 11653e730511SRavi Kumar } 11663e730511SRavi Kumar 11673e730511SRavi Kumar return 0; 11683e730511SRavi Kumar } 11693e730511SRavi Kumar 11709970a9adSIgor Romanov static int 11713e730511SRavi Kumar axgbe_dev_stats_reset(struct rte_eth_dev *dev) 11723e730511SRavi Kumar { 11733e730511SRavi Kumar struct axgbe_rx_queue *rxq; 11743e730511SRavi Kumar struct axgbe_tx_queue *txq; 11753e730511SRavi Kumar unsigned int i; 11763e730511SRavi Kumar 11773e730511SRavi Kumar for (i = 0; i < dev->data->nb_rx_queues; i++) { 11783e730511SRavi Kumar rxq = dev->data->rx_queues[i]; 1179bf403cfeSSelwin Sebastian if (rxq) { 11803e730511SRavi Kumar rxq->pkts = 0; 11813e730511SRavi Kumar rxq->bytes = 0; 11823e730511SRavi Kumar rxq->errors = 0; 11839d1ef6b2SChandu Babu N rxq->rx_mbuf_alloc_failed = 0; 1184bf403cfeSSelwin Sebastian } else { 1185bf403cfeSSelwin Sebastian PMD_DRV_LOG(DEBUG, "Rx queue not setup for port %d\n", 1186bf403cfeSSelwin Sebastian dev->data->port_id); 1187bf403cfeSSelwin Sebastian } 11883e730511SRavi Kumar } 11893e730511SRavi Kumar for (i = 0; i < dev->data->nb_tx_queues; i++) { 11903e730511SRavi Kumar txq = dev->data->tx_queues[i]; 1191bf403cfeSSelwin Sebastian if (txq) { 11923e730511SRavi Kumar txq->pkts = 0; 11933e730511SRavi Kumar txq->bytes = 0; 11943e730511SRavi Kumar txq->errors = 0; 1195bf403cfeSSelwin Sebastian } else { 1196bf403cfeSSelwin Sebastian PMD_DRV_LOG(DEBUG, "Tx queue not setup for port %d\n", 1197bf403cfeSSelwin Sebastian dev->data->port_id); 1198bf403cfeSSelwin Sebastian } 11993e730511SRavi Kumar } 12009970a9adSIgor Romanov 12019970a9adSIgor Romanov return 0; 12023e730511SRavi Kumar } 12033e730511SRavi Kumar 1204bdad90d1SIvan Ilchenko static int 1205cd8c7c7cSFerruh Yigit axgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) 12069e890103SRavi Kumar { 12079e890103SRavi Kumar struct axgbe_port *pdata = dev->data->dev_private; 12089e890103SRavi Kumar 12099e890103SRavi Kumar dev_info->max_rx_queues = pdata->rx_ring_count; 12109e890103SRavi Kumar dev_info->max_tx_queues = pdata->tx_ring_count; 12119e890103SRavi Kumar dev_info->min_rx_bufsize = AXGBE_RX_MIN_BUF_SIZE; 12129e890103SRavi Kumar dev_info->max_rx_pktlen = AXGBE_RX_MAX_BUF_SIZE; 121349a5e622SChandu Babu N dev_info->max_mac_addrs = pdata->hw_feat.addn_mac + 1; 1214e01d9b2eSChandu Babu N dev_info->max_hash_mac_addrs = pdata->hw_feat.hash_table_size; 1215295968d1SFerruh Yigit dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G; 12169e890103SRavi Kumar 12179e890103SRavi Kumar dev_info->rx_offload_capa = 1218295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_VLAN_STRIP | 1219295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_VLAN_FILTER | 1220295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_VLAN_EXTEND | 1221295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | 1222295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_UDP_CKSUM | 1223295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_TCP_CKSUM | 1224295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_SCATTER | 1225295968d1SFerruh Yigit RTE_ETH_RX_OFFLOAD_KEEP_CRC; 12269e890103SRavi Kumar 12279e890103SRavi Kumar dev_info->tx_offload_capa = 1228295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_VLAN_INSERT | 1229295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_QINQ_INSERT | 1230295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | 123193bffd8fSBhagyada Modali RTE_ETH_TX_OFFLOAD_MULTI_SEGS | 1232295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_UDP_CKSUM | 1233295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_TCP_CKSUM; 12349e890103SRavi Kumar 12359e890103SRavi Kumar if (pdata->hw_feat.rss) { 12369e890103SRavi Kumar dev_info->flow_type_rss_offloads = AXGBE_RSS_OFFLOAD; 12379e890103SRavi Kumar dev_info->reta_size = pdata->hw_feat.hash_table_size; 12389e890103SRavi Kumar dev_info->hash_key_size = AXGBE_RSS_HASH_KEY_SIZE; 12399e890103SRavi Kumar } 12409e890103SRavi Kumar 12419e890103SRavi Kumar dev_info->rx_desc_lim = rx_desc_lim; 12429e890103SRavi Kumar dev_info->tx_desc_lim = tx_desc_lim; 12439e890103SRavi Kumar 12449e890103SRavi Kumar dev_info->default_rxconf = (struct rte_eth_rxconf) { 12459e890103SRavi Kumar .rx_free_thresh = AXGBE_RX_FREE_THRESH, 12469e890103SRavi Kumar }; 12479e890103SRavi Kumar 12489e890103SRavi Kumar dev_info->default_txconf = (struct rte_eth_txconf) { 12499e890103SRavi Kumar .tx_free_thresh = AXGBE_TX_FREE_THRESH, 12509e890103SRavi Kumar }; 1251bdad90d1SIvan Ilchenko 1252bdad90d1SIvan Ilchenko return 0; 12539e890103SRavi Kumar } 12549e890103SRavi Kumar 1255cf97f33eSAmaranath Somalapuram static int 1256cf97f33eSAmaranath Somalapuram axgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) 1257cf97f33eSAmaranath Somalapuram { 1258cf97f33eSAmaranath Somalapuram struct axgbe_port *pdata = dev->data->dev_private; 1259cf97f33eSAmaranath Somalapuram struct xgbe_fc_info fc = pdata->fc; 1260cf97f33eSAmaranath Somalapuram unsigned int reg, reg_val = 0; 1261cf97f33eSAmaranath Somalapuram 1262cf97f33eSAmaranath Somalapuram reg = MAC_Q0TFCR; 1263cf97f33eSAmaranath Somalapuram reg_val = AXGMAC_IOREAD(pdata, reg); 1264cf97f33eSAmaranath Somalapuram fc.low_water[0] = AXGMAC_MTL_IOREAD_BITS(pdata, 0, MTL_Q_RQFCR, RFA); 1265cf97f33eSAmaranath Somalapuram fc.high_water[0] = AXGMAC_MTL_IOREAD_BITS(pdata, 0, MTL_Q_RQFCR, RFD); 1266cf97f33eSAmaranath Somalapuram fc.pause_time[0] = AXGMAC_GET_BITS(reg_val, MAC_Q0TFCR, PT); 1267cf97f33eSAmaranath Somalapuram fc.autoneg = pdata->pause_autoneg; 1268cf97f33eSAmaranath Somalapuram 1269cf97f33eSAmaranath Somalapuram if (pdata->rx_pause && pdata->tx_pause) 1270295968d1SFerruh Yigit fc.mode = RTE_ETH_FC_FULL; 1271cf97f33eSAmaranath Somalapuram else if (pdata->rx_pause) 1272295968d1SFerruh Yigit fc.mode = RTE_ETH_FC_RX_PAUSE; 1273cf97f33eSAmaranath Somalapuram else if (pdata->tx_pause) 1274295968d1SFerruh Yigit fc.mode = RTE_ETH_FC_TX_PAUSE; 1275cf97f33eSAmaranath Somalapuram else 1276295968d1SFerruh Yigit fc.mode = RTE_ETH_FC_NONE; 1277cf97f33eSAmaranath Somalapuram 1278cf97f33eSAmaranath Somalapuram fc_conf->high_water = (1024 + (fc.low_water[0] << 9)) / 1024; 1279cf97f33eSAmaranath Somalapuram fc_conf->low_water = (1024 + (fc.high_water[0] << 9)) / 1024; 1280cf97f33eSAmaranath Somalapuram fc_conf->pause_time = fc.pause_time[0]; 1281cf97f33eSAmaranath Somalapuram fc_conf->send_xon = fc.send_xon; 1282cf97f33eSAmaranath Somalapuram fc_conf->mode = fc.mode; 1283cf97f33eSAmaranath Somalapuram 1284cf97f33eSAmaranath Somalapuram return 0; 1285cf97f33eSAmaranath Somalapuram } 1286cf97f33eSAmaranath Somalapuram 1287cf97f33eSAmaranath Somalapuram static int 1288cf97f33eSAmaranath Somalapuram axgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf) 1289cf97f33eSAmaranath Somalapuram { 1290cf97f33eSAmaranath Somalapuram struct axgbe_port *pdata = dev->data->dev_private; 1291cf97f33eSAmaranath Somalapuram struct xgbe_fc_info fc = pdata->fc; 1292cf97f33eSAmaranath Somalapuram unsigned int reg, reg_val = 0; 1293cf97f33eSAmaranath Somalapuram reg = MAC_Q0TFCR; 1294cf97f33eSAmaranath Somalapuram 1295cf97f33eSAmaranath Somalapuram pdata->pause_autoneg = fc_conf->autoneg; 1296cf97f33eSAmaranath Somalapuram pdata->phy.pause_autoneg = pdata->pause_autoneg; 1297cf97f33eSAmaranath Somalapuram fc.send_xon = fc_conf->send_xon; 1298cf97f33eSAmaranath Somalapuram AXGMAC_MTL_IOWRITE_BITS(pdata, 0, MTL_Q_RQFCR, RFA, 1299cf97f33eSAmaranath Somalapuram AXGMAC_FLOW_CONTROL_VALUE(1024 * fc_conf->high_water)); 1300cf97f33eSAmaranath Somalapuram AXGMAC_MTL_IOWRITE_BITS(pdata, 0, MTL_Q_RQFCR, RFD, 1301cf97f33eSAmaranath Somalapuram AXGMAC_FLOW_CONTROL_VALUE(1024 * fc_conf->low_water)); 1302cf97f33eSAmaranath Somalapuram AXGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, fc_conf->pause_time); 1303cf97f33eSAmaranath Somalapuram AXGMAC_IOWRITE(pdata, reg, reg_val); 1304cf97f33eSAmaranath Somalapuram fc.mode = fc_conf->mode; 1305cf97f33eSAmaranath Somalapuram 1306295968d1SFerruh Yigit if (fc.mode == RTE_ETH_FC_FULL) { 1307cf97f33eSAmaranath Somalapuram pdata->tx_pause = 1; 1308cf97f33eSAmaranath Somalapuram pdata->rx_pause = 1; 1309295968d1SFerruh Yigit } else if (fc.mode == RTE_ETH_FC_RX_PAUSE) { 1310cf97f33eSAmaranath Somalapuram pdata->tx_pause = 0; 1311cf97f33eSAmaranath Somalapuram pdata->rx_pause = 1; 1312295968d1SFerruh Yigit } else if (fc.mode == RTE_ETH_FC_TX_PAUSE) { 1313cf97f33eSAmaranath Somalapuram pdata->tx_pause = 1; 1314cf97f33eSAmaranath Somalapuram pdata->rx_pause = 0; 1315cf97f33eSAmaranath Somalapuram } else { 1316cf97f33eSAmaranath Somalapuram pdata->tx_pause = 0; 1317cf97f33eSAmaranath Somalapuram pdata->rx_pause = 0; 1318cf97f33eSAmaranath Somalapuram } 1319cf97f33eSAmaranath Somalapuram 1320cf97f33eSAmaranath Somalapuram if (pdata->tx_pause != (unsigned int)pdata->phy.tx_pause) 1321cf97f33eSAmaranath Somalapuram pdata->hw_if.config_tx_flow_control(pdata); 1322cf97f33eSAmaranath Somalapuram 1323cf97f33eSAmaranath Somalapuram if (pdata->rx_pause != (unsigned int)pdata->phy.rx_pause) 1324cf97f33eSAmaranath Somalapuram pdata->hw_if.config_rx_flow_control(pdata); 1325cf97f33eSAmaranath Somalapuram 1326cf97f33eSAmaranath Somalapuram pdata->hw_if.config_flow_control(pdata); 1327cf97f33eSAmaranath Somalapuram pdata->phy.tx_pause = pdata->tx_pause; 1328cf97f33eSAmaranath Somalapuram pdata->phy.rx_pause = pdata->rx_pause; 1329cf97f33eSAmaranath Somalapuram 1330cf97f33eSAmaranath Somalapuram return 0; 1331cf97f33eSAmaranath Somalapuram } 1332cf97f33eSAmaranath Somalapuram 1333e0543d4eSAmaranath Somalapuram static int 1334e0543d4eSAmaranath Somalapuram axgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, 1335e0543d4eSAmaranath Somalapuram struct rte_eth_pfc_conf *pfc_conf) 1336e0543d4eSAmaranath Somalapuram { 1337e0543d4eSAmaranath Somalapuram struct axgbe_port *pdata = dev->data->dev_private; 1338e0543d4eSAmaranath Somalapuram struct xgbe_fc_info fc = pdata->fc; 1339e0543d4eSAmaranath Somalapuram uint8_t tc_num; 1340e0543d4eSAmaranath Somalapuram 1341e0543d4eSAmaranath Somalapuram tc_num = pdata->pfc_map[pfc_conf->priority]; 1342e0543d4eSAmaranath Somalapuram 1343e0543d4eSAmaranath Somalapuram if (pfc_conf->priority >= pdata->hw_feat.tc_cnt) { 1344e0543d4eSAmaranath Somalapuram PMD_INIT_LOG(ERR, "Max supported traffic class: %d\n", 1345e0543d4eSAmaranath Somalapuram pdata->hw_feat.tc_cnt); 1346e0543d4eSAmaranath Somalapuram return -EINVAL; 1347e0543d4eSAmaranath Somalapuram } 1348e0543d4eSAmaranath Somalapuram 1349e0543d4eSAmaranath Somalapuram pdata->pause_autoneg = pfc_conf->fc.autoneg; 1350e0543d4eSAmaranath Somalapuram pdata->phy.pause_autoneg = pdata->pause_autoneg; 1351e0543d4eSAmaranath Somalapuram fc.send_xon = pfc_conf->fc.send_xon; 1352e0543d4eSAmaranath Somalapuram AXGMAC_MTL_IOWRITE_BITS(pdata, tc_num, MTL_Q_RQFCR, RFA, 1353e0543d4eSAmaranath Somalapuram AXGMAC_FLOW_CONTROL_VALUE(1024 * pfc_conf->fc.high_water)); 1354e0543d4eSAmaranath Somalapuram AXGMAC_MTL_IOWRITE_BITS(pdata, tc_num, MTL_Q_RQFCR, RFD, 1355e0543d4eSAmaranath Somalapuram AXGMAC_FLOW_CONTROL_VALUE(1024 * pfc_conf->fc.low_water)); 1356e0543d4eSAmaranath Somalapuram 1357e0543d4eSAmaranath Somalapuram switch (tc_num) { 1358e0543d4eSAmaranath Somalapuram case 0: 1359e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R, 1360e0543d4eSAmaranath Somalapuram PSTC0, pfc_conf->fc.pause_time); 1361e0543d4eSAmaranath Somalapuram break; 1362e0543d4eSAmaranath Somalapuram case 1: 1363e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R, 1364e0543d4eSAmaranath Somalapuram PSTC1, pfc_conf->fc.pause_time); 1365e0543d4eSAmaranath Somalapuram break; 1366e0543d4eSAmaranath Somalapuram case 2: 1367e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R, 1368e0543d4eSAmaranath Somalapuram PSTC2, pfc_conf->fc.pause_time); 1369e0543d4eSAmaranath Somalapuram break; 1370e0543d4eSAmaranath Somalapuram case 3: 1371e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R, 1372e0543d4eSAmaranath Somalapuram PSTC3, pfc_conf->fc.pause_time); 1373e0543d4eSAmaranath Somalapuram break; 1374e0543d4eSAmaranath Somalapuram case 4: 1375e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R, 1376e0543d4eSAmaranath Somalapuram PSTC4, pfc_conf->fc.pause_time); 1377e0543d4eSAmaranath Somalapuram break; 1378e0543d4eSAmaranath Somalapuram case 5: 1379e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R, 1380e0543d4eSAmaranath Somalapuram PSTC5, pfc_conf->fc.pause_time); 1381e0543d4eSAmaranath Somalapuram break; 1382e0543d4eSAmaranath Somalapuram case 7: 1383e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R, 1384e0543d4eSAmaranath Somalapuram PSTC6, pfc_conf->fc.pause_time); 1385e0543d4eSAmaranath Somalapuram break; 1386e0543d4eSAmaranath Somalapuram case 6: 1387e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R, 1388e0543d4eSAmaranath Somalapuram PSTC7, pfc_conf->fc.pause_time); 1389e0543d4eSAmaranath Somalapuram break; 1390e0543d4eSAmaranath Somalapuram } 1391e0543d4eSAmaranath Somalapuram 1392e0543d4eSAmaranath Somalapuram fc.mode = pfc_conf->fc.mode; 1393e0543d4eSAmaranath Somalapuram 1394295968d1SFerruh Yigit if (fc.mode == RTE_ETH_FC_FULL) { 1395e0543d4eSAmaranath Somalapuram pdata->tx_pause = 1; 1396e0543d4eSAmaranath Somalapuram pdata->rx_pause = 1; 1397e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 1); 1398295968d1SFerruh Yigit } else if (fc.mode == RTE_ETH_FC_RX_PAUSE) { 1399e0543d4eSAmaranath Somalapuram pdata->tx_pause = 0; 1400e0543d4eSAmaranath Somalapuram pdata->rx_pause = 1; 1401e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 1); 1402295968d1SFerruh Yigit } else if (fc.mode == RTE_ETH_FC_TX_PAUSE) { 1403e0543d4eSAmaranath Somalapuram pdata->tx_pause = 1; 1404e0543d4eSAmaranath Somalapuram pdata->rx_pause = 0; 1405e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0); 1406e0543d4eSAmaranath Somalapuram } else { 1407e0543d4eSAmaranath Somalapuram pdata->tx_pause = 0; 1408e0543d4eSAmaranath Somalapuram pdata->rx_pause = 0; 1409e0543d4eSAmaranath Somalapuram AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0); 1410e0543d4eSAmaranath Somalapuram } 1411e0543d4eSAmaranath Somalapuram 1412e0543d4eSAmaranath Somalapuram if (pdata->tx_pause != (unsigned int)pdata->phy.tx_pause) 1413e0543d4eSAmaranath Somalapuram pdata->hw_if.config_tx_flow_control(pdata); 1414e0543d4eSAmaranath Somalapuram 1415e0543d4eSAmaranath Somalapuram if (pdata->rx_pause != (unsigned int)pdata->phy.rx_pause) 1416e0543d4eSAmaranath Somalapuram pdata->hw_if.config_rx_flow_control(pdata); 1417e0543d4eSAmaranath Somalapuram pdata->hw_if.config_flow_control(pdata); 1418e0543d4eSAmaranath Somalapuram pdata->phy.tx_pause = pdata->tx_pause; 1419e0543d4eSAmaranath Somalapuram pdata->phy.rx_pause = pdata->rx_pause; 1420e0543d4eSAmaranath Somalapuram 1421e0543d4eSAmaranath Somalapuram return 0; 1422e0543d4eSAmaranath Somalapuram } 1423e0543d4eSAmaranath Somalapuram 14247aed95c9SAmaranath Somalapuram void 14257aed95c9SAmaranath Somalapuram axgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 14267aed95c9SAmaranath Somalapuram struct rte_eth_rxq_info *qinfo) 14277aed95c9SAmaranath Somalapuram { 14287aed95c9SAmaranath Somalapuram struct axgbe_rx_queue *rxq; 14297aed95c9SAmaranath Somalapuram 14307aed95c9SAmaranath Somalapuram rxq = dev->data->rx_queues[queue_id]; 14317aed95c9SAmaranath Somalapuram qinfo->mp = rxq->mb_pool; 14327aed95c9SAmaranath Somalapuram qinfo->scattered_rx = dev->data->scattered_rx; 14337aed95c9SAmaranath Somalapuram qinfo->nb_desc = rxq->nb_desc; 14347aed95c9SAmaranath Somalapuram qinfo->conf.rx_free_thresh = rxq->free_thresh; 14357aed95c9SAmaranath Somalapuram } 14367aed95c9SAmaranath Somalapuram 14377aed95c9SAmaranath Somalapuram void 14387aed95c9SAmaranath Somalapuram axgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id, 14397aed95c9SAmaranath Somalapuram struct rte_eth_txq_info *qinfo) 14407aed95c9SAmaranath Somalapuram { 14417aed95c9SAmaranath Somalapuram struct axgbe_tx_queue *txq; 14427aed95c9SAmaranath Somalapuram 14437aed95c9SAmaranath Somalapuram txq = dev->data->tx_queues[queue_id]; 14447aed95c9SAmaranath Somalapuram qinfo->nb_desc = txq->nb_desc; 14457aed95c9SAmaranath Somalapuram qinfo->conf.tx_free_thresh = txq->free_thresh; 14467aed95c9SAmaranath Somalapuram } 1447410cf087SAmaranath Somalapuram const uint32_t * 1448410cf087SAmaranath Somalapuram axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev) 1449410cf087SAmaranath Somalapuram { 1450410cf087SAmaranath Somalapuram static const uint32_t ptypes[] = { 1451410cf087SAmaranath Somalapuram RTE_PTYPE_L2_ETHER, 1452410cf087SAmaranath Somalapuram RTE_PTYPE_L2_ETHER_TIMESYNC, 1453410cf087SAmaranath Somalapuram RTE_PTYPE_L2_ETHER_LLDP, 1454410cf087SAmaranath Somalapuram RTE_PTYPE_L2_ETHER_ARP, 1455410cf087SAmaranath Somalapuram RTE_PTYPE_L3_IPV4_EXT_UNKNOWN, 1456410cf087SAmaranath Somalapuram RTE_PTYPE_L3_IPV6_EXT_UNKNOWN, 1457410cf087SAmaranath Somalapuram RTE_PTYPE_L4_FRAG, 1458410cf087SAmaranath Somalapuram RTE_PTYPE_L4_ICMP, 1459410cf087SAmaranath Somalapuram RTE_PTYPE_L4_NONFRAG, 1460410cf087SAmaranath Somalapuram RTE_PTYPE_L4_SCTP, 1461410cf087SAmaranath Somalapuram RTE_PTYPE_L4_TCP, 1462410cf087SAmaranath Somalapuram RTE_PTYPE_L4_UDP, 1463410cf087SAmaranath Somalapuram RTE_PTYPE_TUNNEL_GRENAT, 1464410cf087SAmaranath Somalapuram RTE_PTYPE_TUNNEL_IP, 1465410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L2_ETHER, 1466410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L2_ETHER_VLAN, 1467410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN, 1468410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN, 1469410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_FRAG, 1470410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_ICMP, 1471410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_NONFRAG, 1472410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_SCTP, 1473410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_TCP, 1474410cf087SAmaranath Somalapuram RTE_PTYPE_INNER_L4_UDP, 1475410cf087SAmaranath Somalapuram RTE_PTYPE_UNKNOWN 1476410cf087SAmaranath Somalapuram }; 1477410cf087SAmaranath Somalapuram 1478410cf087SAmaranath Somalapuram if (dev->rx_pkt_burst == axgbe_recv_pkts) 1479410cf087SAmaranath Somalapuram return ptypes; 1480410cf087SAmaranath Somalapuram return NULL; 1481410cf087SAmaranath Somalapuram } 1482e0444948SSelwin Sebastian 1483b58d8781SGirish Nandibasappa static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) 1484b58d8781SGirish Nandibasappa { 1485b58d8781SGirish Nandibasappa struct axgbe_port *pdata = dev->data->dev_private; 1486f7e04f57SFerruh Yigit unsigned int val; 1487f7e04f57SFerruh Yigit 1488b58d8781SGirish Nandibasappa /* mtu setting is forbidden if port is start */ 1489b58d8781SGirish Nandibasappa if (dev->data->dev_started) { 1490b58d8781SGirish Nandibasappa PMD_DRV_LOG(ERR, "port %d must be stopped before configuration", 1491b58d8781SGirish Nandibasappa dev->data->port_id); 1492b58d8781SGirish Nandibasappa return -EBUSY; 1493b58d8781SGirish Nandibasappa } 1494f7e04f57SFerruh Yigit val = mtu > RTE_ETHER_MTU ? 1 : 0; 1495b58d8781SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val); 1496f7e04f57SFerruh Yigit 1497b58d8781SGirish Nandibasappa return 0; 1498b58d8781SGirish Nandibasappa } 1499e0444948SSelwin Sebastian 1500e0444948SSelwin Sebastian static void 1501e0444948SSelwin Sebastian axgbe_update_tstamp_time(struct axgbe_port *pdata, 1502e0444948SSelwin Sebastian unsigned int sec, unsigned int nsec, int addsub) 1503e0444948SSelwin Sebastian { 1504e0444948SSelwin Sebastian unsigned int count = 100; 1505e0444948SSelwin Sebastian uint32_t sub_val = 0; 1506e0444948SSelwin Sebastian uint32_t sub_val_sec = 0xFFFFFFFF; 1507e0444948SSelwin Sebastian uint32_t sub_val_nsec = 0x3B9ACA00; 1508e0444948SSelwin Sebastian 1509e0444948SSelwin Sebastian if (addsub) { 1510e0444948SSelwin Sebastian if (sec) 1511e0444948SSelwin Sebastian sub_val = sub_val_sec - (sec - 1); 1512e0444948SSelwin Sebastian else 1513e0444948SSelwin Sebastian sub_val = sec; 1514e0444948SSelwin Sebastian 1515e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STSUR, sub_val); 1516e0444948SSelwin Sebastian sub_val = sub_val_nsec - nsec; 1517e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STNUR, sub_val); 1518e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_STNUR, ADDSUB, 1); 1519e0444948SSelwin Sebastian } else { 1520e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STSUR, sec); 1521e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_STNUR, ADDSUB, 0); 1522e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STNUR, nsec); 1523e0444948SSelwin Sebastian } 1524e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSUPDT, 1); 1525e0444948SSelwin Sebastian /* Wait for time update to complete */ 1526e0444948SSelwin Sebastian while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSUPDT)) 1527e0444948SSelwin Sebastian rte_delay_ms(1); 1528e0444948SSelwin Sebastian } 1529e0444948SSelwin Sebastian 1530e0444948SSelwin Sebastian static inline uint64_t 1531e0444948SSelwin Sebastian div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder) 1532e0444948SSelwin Sebastian { 1533e0444948SSelwin Sebastian *remainder = dividend % divisor; 1534e0444948SSelwin Sebastian return dividend / divisor; 1535e0444948SSelwin Sebastian } 1536e0444948SSelwin Sebastian 1537e0444948SSelwin Sebastian static inline uint64_t 1538e0444948SSelwin Sebastian div_u64(uint64_t dividend, uint32_t divisor) 1539e0444948SSelwin Sebastian { 1540e0444948SSelwin Sebastian uint32_t remainder; 1541e0444948SSelwin Sebastian return div_u64_rem(dividend, divisor, &remainder); 1542e0444948SSelwin Sebastian } 1543e0444948SSelwin Sebastian 1544e0444948SSelwin Sebastian static int 1545e0444948SSelwin Sebastian axgbe_adjfreq(struct axgbe_port *pdata, int64_t delta) 1546e0444948SSelwin Sebastian { 1547e0444948SSelwin Sebastian uint64_t adjust; 1548e0444948SSelwin Sebastian uint32_t addend, diff; 1549e0444948SSelwin Sebastian unsigned int neg_adjust = 0; 1550e0444948SSelwin Sebastian 1551e0444948SSelwin Sebastian if (delta < 0) { 1552e0444948SSelwin Sebastian neg_adjust = 1; 1553e0444948SSelwin Sebastian delta = -delta; 1554e0444948SSelwin Sebastian } 1555e0444948SSelwin Sebastian adjust = (uint64_t)pdata->tstamp_addend; 1556e0444948SSelwin Sebastian adjust *= delta; 1557e0444948SSelwin Sebastian diff = (uint32_t)div_u64(adjust, 1000000000UL); 1558e0444948SSelwin Sebastian addend = (neg_adjust) ? pdata->tstamp_addend - diff : 1559e0444948SSelwin Sebastian pdata->tstamp_addend + diff; 1560e0444948SSelwin Sebastian pdata->tstamp_addend = addend; 1561e0444948SSelwin Sebastian axgbe_update_tstamp_addend(pdata, addend); 1562e0444948SSelwin Sebastian return 0; 1563e0444948SSelwin Sebastian } 1564e0444948SSelwin Sebastian 1565e0444948SSelwin Sebastian static int 1566e0444948SSelwin Sebastian axgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta) 1567e0444948SSelwin Sebastian { 1568e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1569e0444948SSelwin Sebastian struct timespec timestamp_delta; 1570e0444948SSelwin Sebastian 1571e0444948SSelwin Sebastian axgbe_adjfreq(pdata, delta); 1572e0444948SSelwin Sebastian pdata->systime_tc.nsec += delta; 1573e0444948SSelwin Sebastian 1574e0444948SSelwin Sebastian if (delta < 0) { 1575e0444948SSelwin Sebastian delta = -delta; 1576e0444948SSelwin Sebastian timestamp_delta = rte_ns_to_timespec(delta); 1577e0444948SSelwin Sebastian axgbe_update_tstamp_time(pdata, timestamp_delta.tv_sec, 1578e0444948SSelwin Sebastian timestamp_delta.tv_nsec, 1); 1579e0444948SSelwin Sebastian } else { 1580e0444948SSelwin Sebastian timestamp_delta = rte_ns_to_timespec(delta); 1581e0444948SSelwin Sebastian axgbe_update_tstamp_time(pdata, timestamp_delta.tv_sec, 1582e0444948SSelwin Sebastian timestamp_delta.tv_nsec, 0); 1583e0444948SSelwin Sebastian } 1584e0444948SSelwin Sebastian return 0; 1585e0444948SSelwin Sebastian } 1586e0444948SSelwin Sebastian 1587e0444948SSelwin Sebastian static int 1588e0444948SSelwin Sebastian axgbe_timesync_read_time(struct rte_eth_dev *dev, 1589e0444948SSelwin Sebastian struct timespec *timestamp) 1590e0444948SSelwin Sebastian { 1591e0444948SSelwin Sebastian uint64_t nsec; 1592e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1593e0444948SSelwin Sebastian 1594e0444948SSelwin Sebastian nsec = AXGMAC_IOREAD(pdata, MAC_STSR); 1595e0444948SSelwin Sebastian nsec *= NSEC_PER_SEC; 1596e0444948SSelwin Sebastian nsec += AXGMAC_IOREAD(pdata, MAC_STNR); 1597e0444948SSelwin Sebastian *timestamp = rte_ns_to_timespec(nsec); 1598e0444948SSelwin Sebastian return 0; 1599e0444948SSelwin Sebastian } 1600e0444948SSelwin Sebastian static int 1601e0444948SSelwin Sebastian axgbe_timesync_write_time(struct rte_eth_dev *dev, 1602e0444948SSelwin Sebastian const struct timespec *timestamp) 1603e0444948SSelwin Sebastian { 1604e0444948SSelwin Sebastian unsigned int count = 100; 1605e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1606e0444948SSelwin Sebastian 1607e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STSUR, timestamp->tv_sec); 1608e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STNUR, timestamp->tv_nsec); 1609e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSUPDT, 1); 1610e0444948SSelwin Sebastian /* Wait for time update to complete */ 1611e0444948SSelwin Sebastian while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSUPDT)) 1612e0444948SSelwin Sebastian rte_delay_ms(1); 1613e0444948SSelwin Sebastian if (!count) 1614e0444948SSelwin Sebastian PMD_DRV_LOG(ERR, "Timed out update timestamp\n"); 1615e0444948SSelwin Sebastian return 0; 1616e0444948SSelwin Sebastian } 1617e0444948SSelwin Sebastian 1618e0444948SSelwin Sebastian static void 1619e0444948SSelwin Sebastian axgbe_update_tstamp_addend(struct axgbe_port *pdata, 1620e0444948SSelwin Sebastian uint32_t addend) 1621e0444948SSelwin Sebastian { 1622e0444948SSelwin Sebastian unsigned int count = 100; 1623e0444948SSelwin Sebastian 1624e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_TSAR, addend); 1625e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1); 1626e0444948SSelwin Sebastian 1627e0444948SSelwin Sebastian /* Wait for addend update to complete */ 1628e0444948SSelwin Sebastian while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG)) 1629e0444948SSelwin Sebastian rte_delay_ms(1); 1630e0444948SSelwin Sebastian if (!count) 1631e0444948SSelwin Sebastian PMD_DRV_LOG(ERR, "Timed out updating timestamp addend register\n"); 1632e0444948SSelwin Sebastian } 1633e0444948SSelwin Sebastian 1634e0444948SSelwin Sebastian static void 1635e0444948SSelwin Sebastian axgbe_set_tstamp_time(struct axgbe_port *pdata, unsigned int sec, 1636e0444948SSelwin Sebastian unsigned int nsec) 1637e0444948SSelwin Sebastian { 1638e0444948SSelwin Sebastian unsigned int count = 100; 1639e0444948SSelwin Sebastian 1640e0444948SSelwin Sebastian /*System Time Sec Update*/ 1641e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STSUR, sec); 1642e0444948SSelwin Sebastian /*System Time nanoSec Update*/ 1643e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_STNUR, nsec); 1644e0444948SSelwin Sebastian /*Initialize Timestamp*/ 1645e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1); 1646e0444948SSelwin Sebastian 1647e0444948SSelwin Sebastian /* Wait for time update to complete */ 1648e0444948SSelwin Sebastian while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT)) 1649e0444948SSelwin Sebastian rte_delay_ms(1); 1650e0444948SSelwin Sebastian if (!count) 1651e0444948SSelwin Sebastian PMD_DRV_LOG(ERR, "Timed out initializing timestamp\n"); 1652e0444948SSelwin Sebastian } 1653e0444948SSelwin Sebastian 1654e0444948SSelwin Sebastian static int 1655e0444948SSelwin Sebastian axgbe_timesync_enable(struct rte_eth_dev *dev) 1656e0444948SSelwin Sebastian { 1657e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1658e0444948SSelwin Sebastian unsigned int mac_tscr = 0; 1659e0444948SSelwin Sebastian uint64_t dividend; 1660e0444948SSelwin Sebastian struct timespec timestamp; 1661e0444948SSelwin Sebastian uint64_t nsec; 1662e0444948SSelwin Sebastian 1663e0444948SSelwin Sebastian /* Set one nano-second accuracy */ 1664e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1); 1665e0444948SSelwin Sebastian 1666e0444948SSelwin Sebastian /* Set fine timestamp update */ 1667e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1); 1668e0444948SSelwin Sebastian 1669e0444948SSelwin Sebastian /* Overwrite earlier timestamps */ 1670e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1); 1671e0444948SSelwin Sebastian 1672e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr); 1673e0444948SSelwin Sebastian 1674e0444948SSelwin Sebastian /* Enabling processing of ptp over eth pkt */ 1675e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1); 1676e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1); 1677e0444948SSelwin Sebastian /* Enable timestamp for all pkts*/ 1678e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 1); 1679e0444948SSelwin Sebastian 1680e0444948SSelwin Sebastian /* enabling timestamp */ 1681e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1); 1682e0444948SSelwin Sebastian AXGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr); 1683e0444948SSelwin Sebastian 1684e0444948SSelwin Sebastian /* Exit if timestamping is not enabled */ 1685e0444948SSelwin Sebastian if (!AXGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA)) { 1686e0444948SSelwin Sebastian PMD_DRV_LOG(ERR, "Exiting as timestamp is not enabled\n"); 1687e0444948SSelwin Sebastian return 0; 1688e0444948SSelwin Sebastian } 1689e0444948SSelwin Sebastian 1690e0444948SSelwin Sebastian /* Sub-second Increment Value*/ 1691e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, AXGBE_TSTAMP_SSINC); 1692e0444948SSelwin Sebastian /* Sub-nanosecond Increment Value */ 1693e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, AXGBE_TSTAMP_SNSINC); 1694e0444948SSelwin Sebastian 1695e0444948SSelwin Sebastian pdata->ptpclk_rate = AXGBE_V2_PTP_CLOCK_FREQ; 1696e0444948SSelwin Sebastian dividend = 50000000; 1697e0444948SSelwin Sebastian dividend <<= 32; 1698e0444948SSelwin Sebastian pdata->tstamp_addend = div_u64(dividend, pdata->ptpclk_rate); 1699e0444948SSelwin Sebastian 1700e0444948SSelwin Sebastian axgbe_update_tstamp_addend(pdata, pdata->tstamp_addend); 1701e0444948SSelwin Sebastian axgbe_set_tstamp_time(pdata, 0, 0); 1702e0444948SSelwin Sebastian 1703e0444948SSelwin Sebastian /* Initialize the timecounter */ 1704e0444948SSelwin Sebastian memset(&pdata->systime_tc, 0, sizeof(struct rte_timecounter)); 1705e0444948SSelwin Sebastian 1706e0444948SSelwin Sebastian pdata->systime_tc.cc_mask = AXGBE_CYCLECOUNTER_MASK; 1707e0444948SSelwin Sebastian pdata->systime_tc.cc_shift = 0; 1708e0444948SSelwin Sebastian pdata->systime_tc.nsec_mask = 0; 1709e0444948SSelwin Sebastian 1710e0444948SSelwin Sebastian PMD_DRV_LOG(DEBUG, "Initializing system time counter with realtime\n"); 1711e0444948SSelwin Sebastian 1712e0444948SSelwin Sebastian /* Updating the counter once with clock real time */ 1713e0444948SSelwin Sebastian clock_gettime(CLOCK_REALTIME, ×tamp); 1714e0444948SSelwin Sebastian nsec = rte_timespec_to_ns(×tamp); 1715e0444948SSelwin Sebastian nsec = rte_timecounter_update(&pdata->systime_tc, nsec); 1716e0444948SSelwin Sebastian axgbe_set_tstamp_time(pdata, timestamp.tv_sec, timestamp.tv_nsec); 1717e0444948SSelwin Sebastian return 0; 1718e0444948SSelwin Sebastian } 1719e0444948SSelwin Sebastian 1720e0444948SSelwin Sebastian static int 1721e0444948SSelwin Sebastian axgbe_timesync_disable(struct rte_eth_dev *dev) 1722e0444948SSelwin Sebastian { 1723e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1724e0444948SSelwin Sebastian unsigned int mac_tscr = 0; 1725e0444948SSelwin Sebastian 1726e0444948SSelwin Sebastian /*disable timestamp for all pkts*/ 1727e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 0); 1728e0444948SSelwin Sebastian /*disable the addened register*/ 1729e0444948SSelwin Sebastian AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 0); 1730e0444948SSelwin Sebastian /* disable timestamp update */ 1731e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 0); 1732e0444948SSelwin Sebastian /*disable time stamp*/ 1733e0444948SSelwin Sebastian AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 0); 1734e0444948SSelwin Sebastian return 0; 1735e0444948SSelwin Sebastian } 1736e0444948SSelwin Sebastian 1737e0444948SSelwin Sebastian static int 1738e0444948SSelwin Sebastian axgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev, 1739e0444948SSelwin Sebastian struct timespec *timestamp, uint32_t flags) 1740e0444948SSelwin Sebastian { 1741e0444948SSelwin Sebastian uint64_t nsec = 0; 1742e0444948SSelwin Sebastian volatile union axgbe_rx_desc *desc; 1743e0444948SSelwin Sebastian uint16_t idx, pmt; 1744e0444948SSelwin Sebastian struct axgbe_rx_queue *rxq = *dev->data->rx_queues; 1745e0444948SSelwin Sebastian 1746e0444948SSelwin Sebastian idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur); 1747e0444948SSelwin Sebastian desc = &rxq->desc[idx]; 1748e0444948SSelwin Sebastian 1749e0444948SSelwin Sebastian while (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN)) 1750e0444948SSelwin Sebastian rte_delay_ms(1); 1751e0444948SSelwin Sebastian if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, CTXT)) { 1752e0444948SSelwin Sebastian if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_CONTEXT_DESC3, TSA) && 1753e0444948SSelwin Sebastian !AXGMAC_GET_BITS_LE(desc->write.desc3, 1754e0444948SSelwin Sebastian RX_CONTEXT_DESC3, TSD)) { 1755e0444948SSelwin Sebastian pmt = AXGMAC_GET_BITS_LE(desc->write.desc3, 1756e0444948SSelwin Sebastian RX_CONTEXT_DESC3, PMT); 1757e0444948SSelwin Sebastian nsec = rte_le_to_cpu_32(desc->write.desc1); 1758e0444948SSelwin Sebastian nsec *= NSEC_PER_SEC; 1759e0444948SSelwin Sebastian nsec += rte_le_to_cpu_32(desc->write.desc0); 1760e0444948SSelwin Sebastian if (nsec != 0xffffffffffffffffULL) { 1761e0444948SSelwin Sebastian if (pmt == 0x01) 1762e0444948SSelwin Sebastian *timestamp = rte_ns_to_timespec(nsec); 1763e0444948SSelwin Sebastian PMD_DRV_LOG(DEBUG, 1764e0444948SSelwin Sebastian "flags = 0x%x nsec = %"PRIu64"\n", 1765e0444948SSelwin Sebastian flags, nsec); 1766e0444948SSelwin Sebastian } 1767e0444948SSelwin Sebastian } 1768e0444948SSelwin Sebastian } 1769e0444948SSelwin Sebastian 1770e0444948SSelwin Sebastian return 0; 1771e0444948SSelwin Sebastian } 1772e0444948SSelwin Sebastian 1773e0444948SSelwin Sebastian static int 1774e0444948SSelwin Sebastian axgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev, 1775e0444948SSelwin Sebastian struct timespec *timestamp) 1776e0444948SSelwin Sebastian { 1777e0444948SSelwin Sebastian uint64_t nsec; 1778e0444948SSelwin Sebastian struct axgbe_port *pdata = dev->data->dev_private; 1779e0444948SSelwin Sebastian unsigned int tx_snr, tx_ssr; 1780e0444948SSelwin Sebastian 1781e0444948SSelwin Sebastian rte_delay_us(5); 1782e0444948SSelwin Sebastian if (pdata->vdata->tx_tstamp_workaround) { 1783e0444948SSelwin Sebastian tx_snr = AXGMAC_IOREAD(pdata, MAC_TXSNR); 1784e0444948SSelwin Sebastian tx_ssr = AXGMAC_IOREAD(pdata, MAC_TXSSR); 1785e0444948SSelwin Sebastian 1786e0444948SSelwin Sebastian } else { 1787e0444948SSelwin Sebastian tx_ssr = AXGMAC_IOREAD(pdata, MAC_TXSSR); 1788e0444948SSelwin Sebastian tx_snr = AXGMAC_IOREAD(pdata, MAC_TXSNR); 1789e0444948SSelwin Sebastian } 1790e0444948SSelwin Sebastian if (AXGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS)) { 1791e0444948SSelwin Sebastian PMD_DRV_LOG(DEBUG, "Waiting for TXTSSTSMIS\n"); 1792e0444948SSelwin Sebastian return 0; 1793e0444948SSelwin Sebastian } 1794e0444948SSelwin Sebastian nsec = tx_ssr; 1795e0444948SSelwin Sebastian nsec *= NSEC_PER_SEC; 1796e0444948SSelwin Sebastian nsec += tx_snr; 1797e0444948SSelwin Sebastian PMD_DRV_LOG(DEBUG, "nsec = %"PRIu64" tx_ssr = %d tx_snr = %d\n", 1798e0444948SSelwin Sebastian nsec, tx_ssr, tx_snr); 1799e0444948SSelwin Sebastian *timestamp = rte_ns_to_timespec(nsec); 1800e0444948SSelwin Sebastian return 0; 1801e0444948SSelwin Sebastian } 1802e0444948SSelwin Sebastian 180386578516SGirish Nandibasappa static int 180486578516SGirish Nandibasappa axgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on) 180586578516SGirish Nandibasappa { 180686578516SGirish Nandibasappa struct axgbe_port *pdata = dev->data->dev_private; 180786578516SGirish Nandibasappa unsigned long vid_bit, vid_idx; 180886578516SGirish Nandibasappa 180986578516SGirish Nandibasappa vid_bit = VLAN_TABLE_BIT(vid); 181086578516SGirish Nandibasappa vid_idx = VLAN_TABLE_IDX(vid); 181186578516SGirish Nandibasappa 181286578516SGirish Nandibasappa if (on) { 181386578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Set VLAN vid=%d for device = %s\n", 181486578516SGirish Nandibasappa vid, pdata->eth_dev->device->name); 181586578516SGirish Nandibasappa pdata->active_vlans[vid_idx] |= vid_bit; 181686578516SGirish Nandibasappa } else { 181786578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Reset VLAN vid=%d for device = %s\n", 181886578516SGirish Nandibasappa vid, pdata->eth_dev->device->name); 181986578516SGirish Nandibasappa pdata->active_vlans[vid_idx] &= ~vid_bit; 182086578516SGirish Nandibasappa } 182186578516SGirish Nandibasappa pdata->hw_if.update_vlan_hash_table(pdata); 182286578516SGirish Nandibasappa return 0; 182386578516SGirish Nandibasappa } 182486578516SGirish Nandibasappa 182586578516SGirish Nandibasappa static int 182686578516SGirish Nandibasappa axgbe_vlan_tpid_set(struct rte_eth_dev *dev, 182786578516SGirish Nandibasappa enum rte_vlan_type vlan_type, 182886578516SGirish Nandibasappa uint16_t tpid) 182986578516SGirish Nandibasappa { 183086578516SGirish Nandibasappa struct axgbe_port *pdata = dev->data->dev_private; 183186578516SGirish Nandibasappa uint32_t reg = 0; 183286578516SGirish Nandibasappa uint32_t qinq = 0; 183386578516SGirish Nandibasappa 183486578516SGirish Nandibasappa qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP); 183586578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "EDVLP: qinq = 0x%x\n", qinq); 183686578516SGirish Nandibasappa 183786578516SGirish Nandibasappa switch (vlan_type) { 1838295968d1SFerruh Yigit case RTE_ETH_VLAN_TYPE_INNER: 1839295968d1SFerruh Yigit PMD_DRV_LOG(DEBUG, "RTE_ETH_VLAN_TYPE_INNER\n"); 184086578516SGirish Nandibasappa if (qinq) { 184186578516SGirish Nandibasappa if (tpid != 0x8100 && tpid != 0x88a8) 184286578516SGirish Nandibasappa PMD_DRV_LOG(ERR, 184386578516SGirish Nandibasappa "tag supported 0x8100/0x88A8\n"); 184486578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "qinq with inner tag\n"); 184586578516SGirish Nandibasappa 184686578516SGirish Nandibasappa /*Enable Inner VLAN Tag */ 184786578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERIVLT, 1); 184886578516SGirish Nandibasappa reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, ERIVLT); 184986578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "bit ERIVLT = 0x%x\n", reg); 185086578516SGirish Nandibasappa 185186578516SGirish Nandibasappa } else { 185286578516SGirish Nandibasappa PMD_DRV_LOG(ERR, 185386578516SGirish Nandibasappa "Inner type not supported in single tag\n"); 185486578516SGirish Nandibasappa } 185586578516SGirish Nandibasappa break; 1856295968d1SFerruh Yigit case RTE_ETH_VLAN_TYPE_OUTER: 1857295968d1SFerruh Yigit PMD_DRV_LOG(DEBUG, "RTE_ETH_VLAN_TYPE_OUTER\n"); 185886578516SGirish Nandibasappa if (qinq) { 185986578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "double tagging is enabled\n"); 186086578516SGirish Nandibasappa /*Enable outer VLAN tag*/ 186186578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERIVLT, 0); 186286578516SGirish Nandibasappa reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, ERIVLT); 186386578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "bit ERIVLT = 0x%x\n", reg); 186486578516SGirish Nandibasappa 186586578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 1); 186686578516SGirish Nandibasappa reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANIR, CSVL); 186786578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "bit CSVL = 0x%x\n", reg); 186886578516SGirish Nandibasappa } else { 186986578516SGirish Nandibasappa if (tpid != 0x8100 && tpid != 0x88a8) 187086578516SGirish Nandibasappa PMD_DRV_LOG(ERR, 187186578516SGirish Nandibasappa "tag supported 0x8100/0x88A8\n"); 187286578516SGirish Nandibasappa } 187386578516SGirish Nandibasappa break; 1874295968d1SFerruh Yigit case RTE_ETH_VLAN_TYPE_MAX: 1875295968d1SFerruh Yigit PMD_DRV_LOG(ERR, "RTE_ETH_VLAN_TYPE_MAX\n"); 187686578516SGirish Nandibasappa break; 1877295968d1SFerruh Yigit case RTE_ETH_VLAN_TYPE_UNKNOWN: 1878295968d1SFerruh Yigit PMD_DRV_LOG(ERR, "RTE_ETH_VLAN_TYPE_UNKNOWN\n"); 187986578516SGirish Nandibasappa break; 188086578516SGirish Nandibasappa } 188186578516SGirish Nandibasappa return 0; 188286578516SGirish Nandibasappa } 188386578516SGirish Nandibasappa 188486578516SGirish Nandibasappa static void axgbe_vlan_extend_enable(struct axgbe_port *pdata) 188586578516SGirish Nandibasappa { 188686578516SGirish Nandibasappa int qinq = 0; 188786578516SGirish Nandibasappa 188886578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EDVLP, 1); 188986578516SGirish Nandibasappa qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP); 189086578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "vlan double tag enabled EDVLP:qinq=0x%x\n", qinq); 189186578516SGirish Nandibasappa } 189286578516SGirish Nandibasappa 189386578516SGirish Nandibasappa static void axgbe_vlan_extend_disable(struct axgbe_port *pdata) 189486578516SGirish Nandibasappa { 189586578516SGirish Nandibasappa int qinq = 0; 189686578516SGirish Nandibasappa 189786578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EDVLP, 0); 189886578516SGirish Nandibasappa qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP); 189986578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "vlan double tag disable EDVLP:qinq=0x%x\n", qinq); 190086578516SGirish Nandibasappa } 190186578516SGirish Nandibasappa 190286578516SGirish Nandibasappa static int 190386578516SGirish Nandibasappa axgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask) 190486578516SGirish Nandibasappa { 190586578516SGirish Nandibasappa struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode; 190686578516SGirish Nandibasappa struct axgbe_port *pdata = dev->data->dev_private; 190786578516SGirish Nandibasappa 190886578516SGirish Nandibasappa /* Indicate that VLAN Tx CTAGs come from context descriptors */ 190986578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0); 191086578516SGirish Nandibasappa AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1); 191186578516SGirish Nandibasappa 1912295968d1SFerruh Yigit if (mask & RTE_ETH_VLAN_STRIP_MASK) { 1913295968d1SFerruh Yigit if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) { 191486578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Strip ON for device = %s\n", 191586578516SGirish Nandibasappa pdata->eth_dev->device->name); 191686578516SGirish Nandibasappa pdata->hw_if.enable_rx_vlan_stripping(pdata); 191786578516SGirish Nandibasappa } else { 191886578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Strip OFF for device = %s\n", 191986578516SGirish Nandibasappa pdata->eth_dev->device->name); 192086578516SGirish Nandibasappa pdata->hw_if.disable_rx_vlan_stripping(pdata); 192186578516SGirish Nandibasappa } 192286578516SGirish Nandibasappa } 1923295968d1SFerruh Yigit if (mask & RTE_ETH_VLAN_FILTER_MASK) { 1924295968d1SFerruh Yigit if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) { 192586578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Filter ON for device = %s\n", 192686578516SGirish Nandibasappa pdata->eth_dev->device->name); 192786578516SGirish Nandibasappa pdata->hw_if.enable_rx_vlan_filtering(pdata); 192886578516SGirish Nandibasappa } else { 192986578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "Filter OFF for device = %s\n", 193086578516SGirish Nandibasappa pdata->eth_dev->device->name); 193186578516SGirish Nandibasappa pdata->hw_if.disable_rx_vlan_filtering(pdata); 193286578516SGirish Nandibasappa } 193386578516SGirish Nandibasappa } 1934295968d1SFerruh Yigit if (mask & RTE_ETH_VLAN_EXTEND_MASK) { 1935295968d1SFerruh Yigit if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) { 193686578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "enabling vlan extended mode\n"); 193786578516SGirish Nandibasappa axgbe_vlan_extend_enable(pdata); 193886578516SGirish Nandibasappa /* Set global registers with default ethertype*/ 1939295968d1SFerruh Yigit axgbe_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER, 194086578516SGirish Nandibasappa RTE_ETHER_TYPE_VLAN); 1941295968d1SFerruh Yigit axgbe_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER, 194286578516SGirish Nandibasappa RTE_ETHER_TYPE_VLAN); 194386578516SGirish Nandibasappa } else { 194486578516SGirish Nandibasappa PMD_DRV_LOG(DEBUG, "disabling vlan extended mode\n"); 194586578516SGirish Nandibasappa axgbe_vlan_extend_disable(pdata); 194686578516SGirish Nandibasappa } 194786578516SGirish Nandibasappa } 194886578516SGirish Nandibasappa return 0; 194986578516SGirish Nandibasappa } 195086578516SGirish Nandibasappa 1951572890efSRavi Kumar static void axgbe_get_all_hw_features(struct axgbe_port *pdata) 1952572890efSRavi Kumar { 195386578516SGirish Nandibasappa unsigned int mac_hfr0, mac_hfr1, mac_hfr2, mac_hfr3; 1954572890efSRavi Kumar struct axgbe_hw_features *hw_feat = &pdata->hw_feat; 1955572890efSRavi Kumar 1956572890efSRavi Kumar mac_hfr0 = AXGMAC_IOREAD(pdata, MAC_HWF0R); 1957572890efSRavi Kumar mac_hfr1 = AXGMAC_IOREAD(pdata, MAC_HWF1R); 1958572890efSRavi Kumar mac_hfr2 = AXGMAC_IOREAD(pdata, MAC_HWF2R); 195986578516SGirish Nandibasappa mac_hfr3 = AXGMAC_IOREAD(pdata, MAC_HWF3R); 1960572890efSRavi Kumar 1961572890efSRavi Kumar memset(hw_feat, 0, sizeof(*hw_feat)); 1962572890efSRavi Kumar 1963572890efSRavi Kumar hw_feat->version = AXGMAC_IOREAD(pdata, MAC_VR); 1964572890efSRavi Kumar 1965572890efSRavi Kumar /* Hardware feature register 0 */ 1966572890efSRavi Kumar hw_feat->gmii = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, GMIISEL); 1967572890efSRavi Kumar hw_feat->vlhash = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, VLHASH); 1968572890efSRavi Kumar hw_feat->sma = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SMASEL); 1969572890efSRavi Kumar hw_feat->rwk = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RWKSEL); 1970572890efSRavi Kumar hw_feat->mgk = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MGKSEL); 1971572890efSRavi Kumar hw_feat->mmc = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MMCSEL); 1972572890efSRavi Kumar hw_feat->aoe = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, ARPOFFSEL); 1973572890efSRavi Kumar hw_feat->ts = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSEL); 1974572890efSRavi Kumar hw_feat->eee = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, EEESEL); 1975572890efSRavi Kumar hw_feat->tx_coe = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TXCOESEL); 1976572890efSRavi Kumar hw_feat->rx_coe = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RXCOESEL); 1977572890efSRavi Kumar hw_feat->addn_mac = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, 1978572890efSRavi Kumar ADDMACADRSEL); 1979572890efSRavi Kumar hw_feat->ts_src = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSTSSEL); 1980572890efSRavi Kumar hw_feat->sa_vlan_ins = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SAVLANINS); 1981572890efSRavi Kumar 1982572890efSRavi Kumar /* Hardware feature register 1 */ 1983572890efSRavi Kumar hw_feat->rx_fifo_size = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, 1984572890efSRavi Kumar RXFIFOSIZE); 1985572890efSRavi Kumar hw_feat->tx_fifo_size = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, 1986572890efSRavi Kumar TXFIFOSIZE); 1987572890efSRavi Kumar hw_feat->adv_ts_hi = AXGMAC_GET_BITS(mac_hfr1, 1988572890efSRavi Kumar MAC_HWF1R, ADVTHWORD); 1989572890efSRavi Kumar hw_feat->dma_width = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, ADDR64); 1990572890efSRavi Kumar hw_feat->dcb = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DCBEN); 1991572890efSRavi Kumar hw_feat->sph = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, SPHEN); 1992572890efSRavi Kumar hw_feat->tso = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, TSOEN); 1993572890efSRavi Kumar hw_feat->dma_debug = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DBGMEMA); 1994572890efSRavi Kumar hw_feat->rss = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, RSSEN); 1995572890efSRavi Kumar hw_feat->tc_cnt = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, NUMTC); 1996572890efSRavi Kumar hw_feat->hash_table_size = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, 1997572890efSRavi Kumar HASHTBLSZ); 1998572890efSRavi Kumar hw_feat->l3l4_filter_num = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, 1999572890efSRavi Kumar L3L4FNUM); 2000572890efSRavi Kumar 2001572890efSRavi Kumar /* Hardware feature register 2 */ 2002572890efSRavi Kumar hw_feat->rx_q_cnt = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXQCNT); 2003572890efSRavi Kumar hw_feat->tx_q_cnt = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXQCNT); 2004572890efSRavi Kumar hw_feat->rx_ch_cnt = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXCHCNT); 2005572890efSRavi Kumar hw_feat->tx_ch_cnt = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXCHCNT); 2006572890efSRavi Kumar hw_feat->pps_out_num = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, PPSOUTNUM); 2007572890efSRavi Kumar hw_feat->aux_snap_num = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, 2008572890efSRavi Kumar AUXSNAPNUM); 2009572890efSRavi Kumar 201086578516SGirish Nandibasappa /* Hardware feature register 3 */ 201186578516SGirish Nandibasappa hw_feat->tx_q_vlan_tag_ins = AXGMAC_GET_BITS(mac_hfr3, 201286578516SGirish Nandibasappa MAC_HWF3R, CBTISEL); 201386578516SGirish Nandibasappa hw_feat->no_of_vlan_extn = AXGMAC_GET_BITS(mac_hfr3, 201486578516SGirish Nandibasappa MAC_HWF3R, NRVF); 201586578516SGirish Nandibasappa 2016572890efSRavi Kumar /* Translate the Hash Table size into actual number */ 2017572890efSRavi Kumar switch (hw_feat->hash_table_size) { 2018572890efSRavi Kumar case 0: 2019572890efSRavi Kumar break; 2020572890efSRavi Kumar case 1: 2021572890efSRavi Kumar hw_feat->hash_table_size = 64; 2022572890efSRavi Kumar break; 2023572890efSRavi Kumar case 2: 2024572890efSRavi Kumar hw_feat->hash_table_size = 128; 2025572890efSRavi Kumar break; 2026572890efSRavi Kumar case 3: 2027572890efSRavi Kumar hw_feat->hash_table_size = 256; 2028572890efSRavi Kumar break; 2029572890efSRavi Kumar } 2030572890efSRavi Kumar 2031572890efSRavi Kumar /* Translate the address width setting into actual number */ 2032572890efSRavi Kumar switch (hw_feat->dma_width) { 2033572890efSRavi Kumar case 0: 2034572890efSRavi Kumar hw_feat->dma_width = 32; 2035572890efSRavi Kumar break; 2036572890efSRavi Kumar case 1: 2037572890efSRavi Kumar hw_feat->dma_width = 40; 2038572890efSRavi Kumar break; 2039572890efSRavi Kumar case 2: 2040572890efSRavi Kumar hw_feat->dma_width = 48; 2041572890efSRavi Kumar break; 2042572890efSRavi Kumar default: 2043572890efSRavi Kumar hw_feat->dma_width = 32; 2044572890efSRavi Kumar } 2045572890efSRavi Kumar 2046572890efSRavi Kumar /* The Queue, Channel and TC counts are zero based so increment them 2047572890efSRavi Kumar * to get the actual number 2048572890efSRavi Kumar */ 2049572890efSRavi Kumar hw_feat->rx_q_cnt++; 2050572890efSRavi Kumar hw_feat->tx_q_cnt++; 2051572890efSRavi Kumar hw_feat->rx_ch_cnt++; 2052572890efSRavi Kumar hw_feat->tx_ch_cnt++; 2053572890efSRavi Kumar hw_feat->tc_cnt++; 2054572890efSRavi Kumar 2055572890efSRavi Kumar /* Translate the fifo sizes into actual numbers */ 2056572890efSRavi Kumar hw_feat->rx_fifo_size = 1 << (hw_feat->rx_fifo_size + 7); 2057572890efSRavi Kumar hw_feat->tx_fifo_size = 1 << (hw_feat->tx_fifo_size + 7); 2058572890efSRavi Kumar } 2059572890efSRavi Kumar 2060572890efSRavi Kumar static void axgbe_init_all_fptrs(struct axgbe_port *pdata) 2061572890efSRavi Kumar { 2062572890efSRavi Kumar axgbe_init_function_ptrs_dev(&pdata->hw_if); 20634ac7516bSRavi Kumar axgbe_init_function_ptrs_phy(&pdata->phy_if); 20644ac7516bSRavi Kumar axgbe_init_function_ptrs_i2c(&pdata->i2c_if); 20654ac7516bSRavi Kumar pdata->vdata->init_function_ptrs_phy_impl(&pdata->phy_if); 2066572890efSRavi Kumar } 2067572890efSRavi Kumar 2068572890efSRavi Kumar static void axgbe_set_counts(struct axgbe_port *pdata) 2069572890efSRavi Kumar { 2070572890efSRavi Kumar /* Set all the function pointers */ 2071572890efSRavi Kumar axgbe_init_all_fptrs(pdata); 2072572890efSRavi Kumar 2073572890efSRavi Kumar /* Populate the hardware features */ 2074572890efSRavi Kumar axgbe_get_all_hw_features(pdata); 2075572890efSRavi Kumar 2076572890efSRavi Kumar /* Set default max values if not provided */ 2077572890efSRavi Kumar if (!pdata->tx_max_channel_count) 2078572890efSRavi Kumar pdata->tx_max_channel_count = pdata->hw_feat.tx_ch_cnt; 2079572890efSRavi Kumar if (!pdata->rx_max_channel_count) 2080572890efSRavi Kumar pdata->rx_max_channel_count = pdata->hw_feat.rx_ch_cnt; 2081572890efSRavi Kumar 2082572890efSRavi Kumar if (!pdata->tx_max_q_count) 2083572890efSRavi Kumar pdata->tx_max_q_count = pdata->hw_feat.tx_q_cnt; 2084572890efSRavi Kumar if (!pdata->rx_max_q_count) 2085572890efSRavi Kumar pdata->rx_max_q_count = pdata->hw_feat.rx_q_cnt; 2086572890efSRavi Kumar 2087572890efSRavi Kumar /* Calculate the number of Tx and Rx rings to be created 2088572890efSRavi Kumar * -Tx (DMA) Channels map 1-to-1 to Tx Queues so set 2089572890efSRavi Kumar * the number of Tx queues to the number of Tx channels 2090572890efSRavi Kumar * enabled 2091572890efSRavi Kumar * -Rx (DMA) Channels do not map 1-to-1 so use the actual 2092572890efSRavi Kumar * number of Rx queues or maximum allowed 2093572890efSRavi Kumar */ 2094572890efSRavi Kumar pdata->tx_ring_count = RTE_MIN(pdata->hw_feat.tx_ch_cnt, 2095572890efSRavi Kumar pdata->tx_max_channel_count); 2096572890efSRavi Kumar pdata->tx_ring_count = RTE_MIN(pdata->tx_ring_count, 2097572890efSRavi Kumar pdata->tx_max_q_count); 2098572890efSRavi Kumar 2099572890efSRavi Kumar pdata->tx_q_count = pdata->tx_ring_count; 2100572890efSRavi Kumar 2101572890efSRavi Kumar pdata->rx_ring_count = RTE_MIN(pdata->hw_feat.rx_ch_cnt, 2102572890efSRavi Kumar pdata->rx_max_channel_count); 2103572890efSRavi Kumar 2104572890efSRavi Kumar pdata->rx_q_count = RTE_MIN(pdata->hw_feat.rx_q_cnt, 2105572890efSRavi Kumar pdata->rx_max_q_count); 2106572890efSRavi Kumar } 2107572890efSRavi Kumar 2108572890efSRavi Kumar static void axgbe_default_config(struct axgbe_port *pdata) 2109572890efSRavi Kumar { 2110572890efSRavi Kumar pdata->pblx8 = DMA_PBL_X8_ENABLE; 2111572890efSRavi Kumar pdata->tx_sf_mode = MTL_TSF_ENABLE; 2112572890efSRavi Kumar pdata->tx_threshold = MTL_TX_THRESHOLD_64; 2113572890efSRavi Kumar pdata->tx_pbl = DMA_PBL_32; 2114572890efSRavi Kumar pdata->tx_osp_mode = DMA_OSP_ENABLE; 2115572890efSRavi Kumar pdata->rx_sf_mode = MTL_RSF_ENABLE; 2116572890efSRavi Kumar pdata->rx_threshold = MTL_RX_THRESHOLD_64; 2117572890efSRavi Kumar pdata->rx_pbl = DMA_PBL_32; 2118572890efSRavi Kumar pdata->pause_autoneg = 1; 2119572890efSRavi Kumar pdata->tx_pause = 0; 2120572890efSRavi Kumar pdata->rx_pause = 0; 2121572890efSRavi Kumar pdata->phy_speed = SPEED_UNKNOWN; 2122572890efSRavi Kumar pdata->power_down = 0; 2123572890efSRavi Kumar } 2124572890efSRavi Kumar 21259963b513SJesna K E /* Used in dev_start by primary process and then 21269963b513SJesna K E * in dev_init by secondary process when attaching to an existing ethdev. 21279963b513SJesna K E */ 21289963b513SJesna K E void 21299963b513SJesna K E axgbe_set_tx_function(struct rte_eth_dev *dev) 21309963b513SJesna K E { 21319963b513SJesna K E struct axgbe_port *pdata = dev->data->dev_private; 21329963b513SJesna K E 21339963b513SJesna K E if (pdata->multi_segs_tx) 21349963b513SJesna K E dev->tx_pkt_burst = &axgbe_xmit_pkts_seg; 21359963b513SJesna K E #ifdef RTE_ARCH_X86 21369963b513SJesna K E struct axgbe_tx_queue *txq = dev->data->tx_queues[0]; 21379963b513SJesna K E if (!txq->vector_disable && 21389963b513SJesna K E rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) 21399963b513SJesna K E dev->tx_pkt_burst = &axgbe_xmit_pkts_vec; 21409963b513SJesna K E #else 21419963b513SJesna K E dev->tx_pkt_burst = &axgbe_xmit_pkts; 21429963b513SJesna K E #endif 21439963b513SJesna K E } 21449963b513SJesna K E 21459963b513SJesna K E void 21469963b513SJesna K E axgbe_set_rx_function(struct rte_eth_dev *dev) 21479963b513SJesna K E { 21489963b513SJesna K E struct rte_eth_dev_data *dev_data = dev->data; 21499963b513SJesna K E uint16_t max_pkt_len; 21509963b513SJesna K E struct axgbe_port *pdata; 21519963b513SJesna K E 21529963b513SJesna K E pdata = dev->data->dev_private; 21539963b513SJesna K E max_pkt_len = dev_data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN; 21549963b513SJesna K E if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) || 21559963b513SJesna K E max_pkt_len > pdata->rx_buf_size) 21569963b513SJesna K E dev_data->scattered_rx = 1; 21579963b513SJesna K E /* Scatter Rx handling */ 21589963b513SJesna K E if (dev_data->scattered_rx) 21599963b513SJesna K E dev->rx_pkt_burst = ð_axgbe_recv_scattered_pkts; 21609963b513SJesna K E else 21619963b513SJesna K E dev->rx_pkt_burst = &axgbe_recv_pkts; 21629963b513SJesna K E } 21639963b513SJesna K E 21648691632fSRavi Kumar /* 21658691632fSRavi Kumar * It returns 0 on success. 21668691632fSRavi Kumar */ 21678691632fSRavi Kumar static int 21688691632fSRavi Kumar eth_axgbe_dev_init(struct rte_eth_dev *eth_dev) 21698691632fSRavi Kumar { 21708691632fSRavi Kumar PMD_INIT_FUNC_TRACE(); 21718691632fSRavi Kumar struct axgbe_port *pdata; 21728691632fSRavi Kumar struct rte_pci_device *pci_dev; 2173572890efSRavi Kumar uint32_t reg, mac_lo, mac_hi; 217449a5e622SChandu Babu N uint32_t len; 2175572890efSRavi Kumar int ret; 21768691632fSRavi Kumar 2177*a27ff9caSSelwin Sebastian unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; 2178*a27ff9caSSelwin Sebastian unsigned char cpu_family = 0, cpu_model = 0; 2179*a27ff9caSSelwin Sebastian 21809e890103SRavi Kumar eth_dev->dev_ops = &axgbe_eth_dev_ops; 21819e890103SRavi Kumar 2182cbfc6111SFerruh Yigit eth_dev->rx_descriptor_status = axgbe_dev_rx_descriptor_status; 2183cbfc6111SFerruh Yigit eth_dev->tx_descriptor_status = axgbe_dev_tx_descriptor_status; 2184cbfc6111SFerruh Yigit 21859963b513SJesna K E eth_dev->tx_pkt_burst = &axgbe_xmit_pkts; 21869963b513SJesna K E eth_dev->rx_pkt_burst = &axgbe_recv_pkts; 21879963b513SJesna K E 21888691632fSRavi Kumar /* 21898691632fSRavi Kumar * For secondary processes, we don't initialise any further as primary 21908691632fSRavi Kumar * has already done this work. 21918691632fSRavi Kumar */ 21929963b513SJesna K E if (rte_eal_process_type() != RTE_PROC_PRIMARY) { 21939963b513SJesna K E axgbe_set_tx_function(eth_dev); 21949963b513SJesna K E axgbe_set_rx_function(eth_dev); 21958691632fSRavi Kumar return 0; 21969963b513SJesna K E } 21978691632fSRavi Kumar 2198f30e69b4SFerruh Yigit eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; 2199f30e69b4SFerruh Yigit 22000bc212a8SStephen Hemminger pdata = eth_dev->data->dev_private; 2201572890efSRavi Kumar /* initial state */ 22024693ae4aSJoyce Kong rte_bit_relaxed_set32(AXGBE_DOWN, &pdata->dev_state); 22034693ae4aSJoyce Kong rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state); 22048691632fSRavi Kumar pdata->eth_dev = eth_dev; 22058691632fSRavi Kumar 22068691632fSRavi Kumar pci_dev = RTE_DEV_TO_PCI(eth_dev->device); 22078691632fSRavi Kumar pdata->pci_dev = pci_dev; 22088691632fSRavi Kumar 2209572890efSRavi Kumar pdata->xgmac_regs = 22107784d0d3SRavi Kumar (void *)pci_dev->mem_resource[AXGBE_AXGMAC_BAR].addr; 22117784d0d3SRavi Kumar pdata->xprop_regs = (void *)((uint8_t *)pdata->xgmac_regs 22127784d0d3SRavi Kumar + AXGBE_MAC_PROP_OFFSET); 22137784d0d3SRavi Kumar pdata->xi2c_regs = (void *)((uint8_t *)pdata->xgmac_regs 22147784d0d3SRavi Kumar + AXGBE_I2C_CTRL_OFFSET); 22157784d0d3SRavi Kumar pdata->xpcs_regs = (void *)pci_dev->mem_resource[AXGBE_XPCS_BAR].addr; 2216572890efSRavi Kumar 2217572890efSRavi Kumar /* version specific driver data*/ 2218572890efSRavi Kumar if (pci_dev->id.device_id == AMD_PCI_AXGBE_DEVICE_V2A) 2219572890efSRavi Kumar pdata->vdata = &axgbe_v2a; 2220572890efSRavi Kumar else 2221572890efSRavi Kumar pdata->vdata = &axgbe_v2b; 2222572890efSRavi Kumar 2223f7706f88SSelwin Sebastian /* 2224*a27ff9caSSelwin Sebastian * Use CPUID to get Family and model ID to identify the CPU 2225f7706f88SSelwin Sebastian */ 2226*a27ff9caSSelwin Sebastian __cpuid(0x0, eax, ebx, ecx, edx); 2227*a27ff9caSSelwin Sebastian 2228*a27ff9caSSelwin Sebastian if (ebx == CPUID_VENDOR_AuthenticAMD_ebx && 2229*a27ff9caSSelwin Sebastian edx == CPUID_VENDOR_AuthenticAMD_edx && 2230*a27ff9caSSelwin Sebastian ecx == CPUID_VENDOR_AuthenticAMD_ecx) { 2231*a27ff9caSSelwin Sebastian int unknown_cpu = 0; 2232*a27ff9caSSelwin Sebastian eax = 0, ebx = 0, ecx = 0, edx = 0; 2233*a27ff9caSSelwin Sebastian 2234*a27ff9caSSelwin Sebastian __cpuid(0x1, eax, ebx, ecx, edx); 2235*a27ff9caSSelwin Sebastian 2236*a27ff9caSSelwin Sebastian cpu_family = ((GET_BITS(eax, 8, 4)) + (GET_BITS(eax, 20, 8))); 2237*a27ff9caSSelwin Sebastian cpu_model = ((GET_BITS(eax, 4, 4)) | (((GET_BITS(eax, 16, 4)) << 4) & 0xF0)); 2238*a27ff9caSSelwin Sebastian 2239*a27ff9caSSelwin Sebastian switch (cpu_family) { 2240*a27ff9caSSelwin Sebastian case Fam17h: 2241*a27ff9caSSelwin Sebastian /* V1000/R1000 */ 2242*a27ff9caSSelwin Sebastian if (cpu_model >= 0x10 && cpu_model <= 0x1F) { 2243f7706f88SSelwin Sebastian pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF; 2244f7706f88SSelwin Sebastian pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT; 2245*a27ff9caSSelwin Sebastian /* EPYC 3000 */ 2246*a27ff9caSSelwin Sebastian } else if (cpu_model >= 0x01 && cpu_model <= 0x0F) { 2247f7706f88SSelwin Sebastian pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF; 2248f7706f88SSelwin Sebastian pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT; 2249*a27ff9caSSelwin Sebastian } else { 2250*a27ff9caSSelwin Sebastian unknown_cpu = 1; 2251*a27ff9caSSelwin Sebastian } 2252*a27ff9caSSelwin Sebastian break; 2253*a27ff9caSSelwin Sebastian case Fam19h: 2254*a27ff9caSSelwin Sebastian /* V3000 (Yellow Carp) */ 2255*a27ff9caSSelwin Sebastian if (cpu_model >= 0x44 && cpu_model <= 0x47) { 2256*a27ff9caSSelwin Sebastian pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF; 2257*a27ff9caSSelwin Sebastian pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT; 2258*a27ff9caSSelwin Sebastian 2259*a27ff9caSSelwin Sebastian /* Yellow Carp devices do not need cdr workaround */ 2260*a27ff9caSSelwin Sebastian pdata->vdata->an_cdr_workaround = 0; 2261*a27ff9caSSelwin Sebastian } else { 2262*a27ff9caSSelwin Sebastian unknown_cpu = 1; 2263*a27ff9caSSelwin Sebastian } 2264f7706f88SSelwin Sebastian break; 2265f7706f88SSelwin Sebastian default: 2266*a27ff9caSSelwin Sebastian unknown_cpu = 1; 2267*a27ff9caSSelwin Sebastian break; 2268*a27ff9caSSelwin Sebastian } 2269*a27ff9caSSelwin Sebastian if (unknown_cpu) { 2270*a27ff9caSSelwin Sebastian PMD_DRV_LOG(ERR, "Unknown CPU family, no supported axgbe device found\n"); 2271f7706f88SSelwin Sebastian return -ENODEV; 2272f7706f88SSelwin Sebastian } 2273*a27ff9caSSelwin Sebastian } 2274f7706f88SSelwin Sebastian 2275572890efSRavi Kumar /* Configure the PCS indirect addressing support */ 2276991e0b1dSSelwin Sebastian reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg); 2277572890efSRavi Kumar pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET); 2278572890efSRavi Kumar pdata->xpcs_window <<= 6; 2279572890efSRavi Kumar pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE); 2280572890efSRavi Kumar pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7); 2281572890efSRavi Kumar pdata->xpcs_window_mask = pdata->xpcs_window_size - 1; 2282991e0b1dSSelwin Sebastian 2283572890efSRavi Kumar PMD_INIT_LOG(DEBUG, 2284572890efSRavi Kumar "xpcs window :%x, size :%x, mask :%x ", pdata->xpcs_window, 2285572890efSRavi Kumar pdata->xpcs_window_size, pdata->xpcs_window_mask); 2286572890efSRavi Kumar XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff); 2287572890efSRavi Kumar 2288572890efSRavi Kumar /* Retrieve the MAC address */ 2289572890efSRavi Kumar mac_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO); 2290572890efSRavi Kumar mac_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI); 2291572890efSRavi Kumar pdata->mac_addr.addr_bytes[0] = mac_lo & 0xff; 2292572890efSRavi Kumar pdata->mac_addr.addr_bytes[1] = (mac_lo >> 8) & 0xff; 2293572890efSRavi Kumar pdata->mac_addr.addr_bytes[2] = (mac_lo >> 16) & 0xff; 2294572890efSRavi Kumar pdata->mac_addr.addr_bytes[3] = (mac_lo >> 24) & 0xff; 2295572890efSRavi Kumar pdata->mac_addr.addr_bytes[4] = mac_hi & 0xff; 2296572890efSRavi Kumar pdata->mac_addr.addr_bytes[5] = (mac_hi >> 8) & 0xff; 2297572890efSRavi Kumar 229849a5e622SChandu Babu N len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_MAC_ADDRS; 229949a5e622SChandu Babu N eth_dev->data->mac_addrs = rte_zmalloc("axgbe_mac_addr", len, 0); 230049a5e622SChandu Babu N 2301572890efSRavi Kumar if (!eth_dev->data->mac_addrs) { 2302572890efSRavi Kumar PMD_INIT_LOG(ERR, 230349a5e622SChandu Babu N "Failed to alloc %u bytes needed to " 230449a5e622SChandu Babu N "store MAC addresses", len); 2305572890efSRavi Kumar return -ENOMEM; 2306572890efSRavi Kumar } 2307572890efSRavi Kumar 2308e01d9b2eSChandu Babu N /* Allocate memory for storing hash filter MAC addresses */ 2309e01d9b2eSChandu Babu N len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_HASH_MAC_ADDRS; 2310e01d9b2eSChandu Babu N eth_dev->data->hash_mac_addrs = rte_zmalloc("axgbe_hash_mac_addr", 2311e01d9b2eSChandu Babu N len, 0); 2312e01d9b2eSChandu Babu N 2313e01d9b2eSChandu Babu N if (eth_dev->data->hash_mac_addrs == NULL) { 2314e01d9b2eSChandu Babu N PMD_INIT_LOG(ERR, 2315e01d9b2eSChandu Babu N "Failed to allocate %d bytes needed to " 2316e01d9b2eSChandu Babu N "store MAC addresses", len); 2317e01d9b2eSChandu Babu N return -ENOMEM; 2318e01d9b2eSChandu Babu N } 2319e01d9b2eSChandu Babu N 2320538da7a1SOlivier Matz if (!rte_is_valid_assigned_ether_addr(&pdata->mac_addr)) 2321538da7a1SOlivier Matz rte_eth_random_addr(pdata->mac_addr.addr_bytes); 2322572890efSRavi Kumar 2323572890efSRavi Kumar /* Copy the permanent MAC address */ 2324538da7a1SOlivier Matz rte_ether_addr_copy(&pdata->mac_addr, ð_dev->data->mac_addrs[0]); 2325572890efSRavi Kumar 2326572890efSRavi Kumar /* Clock settings */ 2327572890efSRavi Kumar pdata->sysclk_rate = AXGBE_V2_DMA_CLOCK_FREQ; 2328572890efSRavi Kumar pdata->ptpclk_rate = AXGBE_V2_PTP_CLOCK_FREQ; 2329572890efSRavi Kumar 2330572890efSRavi Kumar /* Set the DMA coherency values */ 2331572890efSRavi Kumar pdata->coherent = 1; 2332572890efSRavi Kumar pdata->axdomain = AXGBE_DMA_OS_AXDOMAIN; 2333572890efSRavi Kumar pdata->arcache = AXGBE_DMA_OS_ARCACHE; 2334572890efSRavi Kumar pdata->awcache = AXGBE_DMA_OS_AWCACHE; 2335572890efSRavi Kumar 2336572890efSRavi Kumar /* Set the maximum channels and queues */ 2337572890efSRavi Kumar reg = XP_IOREAD(pdata, XP_PROP_1); 2338572890efSRavi Kumar pdata->tx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_DMA); 2339572890efSRavi Kumar pdata->rx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_DMA); 2340572890efSRavi Kumar pdata->tx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_QUEUES); 2341572890efSRavi Kumar pdata->rx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_QUEUES); 2342572890efSRavi Kumar 2343572890efSRavi Kumar /* Set the hardware channel and queue counts */ 2344572890efSRavi Kumar axgbe_set_counts(pdata); 2345572890efSRavi Kumar 2346572890efSRavi Kumar /* Set the maximum fifo amounts */ 2347572890efSRavi Kumar reg = XP_IOREAD(pdata, XP_PROP_2); 2348572890efSRavi Kumar pdata->tx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, TX_FIFO_SIZE); 2349572890efSRavi Kumar pdata->tx_max_fifo_size *= 16384; 2350572890efSRavi Kumar pdata->tx_max_fifo_size = RTE_MIN(pdata->tx_max_fifo_size, 2351572890efSRavi Kumar pdata->vdata->tx_max_fifo_size); 2352572890efSRavi Kumar pdata->rx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, RX_FIFO_SIZE); 2353572890efSRavi Kumar pdata->rx_max_fifo_size *= 16384; 2354572890efSRavi Kumar pdata->rx_max_fifo_size = RTE_MIN(pdata->rx_max_fifo_size, 2355572890efSRavi Kumar pdata->vdata->rx_max_fifo_size); 2356572890efSRavi Kumar /* Issue software reset to DMA */ 2357572890efSRavi Kumar ret = pdata->hw_if.exit(pdata); 2358572890efSRavi Kumar if (ret) 2359572890efSRavi Kumar PMD_DRV_LOG(ERR, "hw_if->exit EBUSY error\n"); 2360572890efSRavi Kumar 2361572890efSRavi Kumar /* Set default configuration data */ 2362572890efSRavi Kumar axgbe_default_config(pdata); 2363572890efSRavi Kumar 2364572890efSRavi Kumar /* Set default max values if not provided */ 2365572890efSRavi Kumar if (!pdata->tx_max_fifo_size) 2366572890efSRavi Kumar pdata->tx_max_fifo_size = pdata->hw_feat.tx_fifo_size; 2367572890efSRavi Kumar if (!pdata->rx_max_fifo_size) 2368572890efSRavi Kumar pdata->rx_max_fifo_size = pdata->hw_feat.rx_fifo_size; 2369572890efSRavi Kumar 23709e890103SRavi Kumar pdata->tx_desc_count = AXGBE_MAX_RING_DESC; 23719e890103SRavi Kumar pdata->rx_desc_count = AXGBE_MAX_RING_DESC; 2372572890efSRavi Kumar pthread_mutex_init(&pdata->xpcs_mutex, NULL); 2373572890efSRavi Kumar pthread_mutex_init(&pdata->i2c_mutex, NULL); 2374572890efSRavi Kumar pthread_mutex_init(&pdata->an_mutex, NULL); 2375572890efSRavi Kumar pthread_mutex_init(&pdata->phy_mutex, NULL); 2376572890efSRavi Kumar 23774ac7516bSRavi Kumar ret = pdata->phy_if.phy_init(pdata); 23784ac7516bSRavi Kumar if (ret) { 23794ac7516bSRavi Kumar rte_free(eth_dev->data->mac_addrs); 2380e7f2fa88SDavid Marchand eth_dev->data->mac_addrs = NULL; 23814ac7516bSRavi Kumar return ret; 23824ac7516bSRavi Kumar } 23834ac7516bSRavi Kumar 2384d61138d4SHarman Kalra rte_intr_callback_register(pci_dev->intr_handle, 2385456ff159SRavi Kumar axgbe_dev_interrupt_handler, 2386456ff159SRavi Kumar (void *)eth_dev); 23878691632fSRavi Kumar PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x", 23888691632fSRavi Kumar eth_dev->data->port_id, pci_dev->id.vendor_id, 23898691632fSRavi Kumar pci_dev->id.device_id); 23908691632fSRavi Kumar 23918691632fSRavi Kumar return 0; 23928691632fSRavi Kumar } 23938691632fSRavi Kumar 23948691632fSRavi Kumar static int 2395479e6a42SThomas Monjalon axgbe_dev_close(struct rte_eth_dev *eth_dev) 23968691632fSRavi Kumar { 2397456ff159SRavi Kumar struct rte_pci_device *pci_dev; 2398456ff159SRavi Kumar 23998691632fSRavi Kumar PMD_INIT_FUNC_TRACE(); 24008691632fSRavi Kumar 2401572890efSRavi Kumar if (rte_eal_process_type() != RTE_PROC_PRIMARY) 2402572890efSRavi Kumar return 0; 2403572890efSRavi Kumar 2404456ff159SRavi Kumar pci_dev = RTE_DEV_TO_PCI(eth_dev->device); 24059e890103SRavi Kumar axgbe_dev_clear_queues(eth_dev); 2406572890efSRavi Kumar 2407456ff159SRavi Kumar /* disable uio intr before callback unregister */ 2408d61138d4SHarman Kalra rte_intr_disable(pci_dev->intr_handle); 2409d61138d4SHarman Kalra rte_intr_callback_unregister(pci_dev->intr_handle, 2410456ff159SRavi Kumar axgbe_dev_interrupt_handler, 2411456ff159SRavi Kumar (void *)eth_dev); 2412456ff159SRavi Kumar 24138691632fSRavi Kumar return 0; 24148691632fSRavi Kumar } 24158691632fSRavi Kumar 24168691632fSRavi Kumar static int eth_axgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, 24178691632fSRavi Kumar struct rte_pci_device *pci_dev) 24188691632fSRavi Kumar { 24198691632fSRavi Kumar return rte_eth_dev_pci_generic_probe(pci_dev, 24208691632fSRavi Kumar sizeof(struct axgbe_port), eth_axgbe_dev_init); 24218691632fSRavi Kumar } 24228691632fSRavi Kumar 24238691632fSRavi Kumar static int eth_axgbe_pci_remove(struct rte_pci_device *pci_dev) 24248691632fSRavi Kumar { 2425479e6a42SThomas Monjalon return rte_eth_dev_pci_generic_remove(pci_dev, axgbe_dev_close); 24268691632fSRavi Kumar } 24278691632fSRavi Kumar 24288691632fSRavi Kumar static struct rte_pci_driver rte_axgbe_pmd = { 24298691632fSRavi Kumar .id_table = pci_id_axgbe_map, 24308691632fSRavi Kumar .drv_flags = RTE_PCI_DRV_NEED_MAPPING, 24318691632fSRavi Kumar .probe = eth_axgbe_pci_probe, 24328691632fSRavi Kumar .remove = eth_axgbe_pci_remove, 24338691632fSRavi Kumar }; 24348691632fSRavi Kumar 24358691632fSRavi Kumar RTE_PMD_REGISTER_PCI(net_axgbe, rte_axgbe_pmd); 24368691632fSRavi Kumar RTE_PMD_REGISTER_PCI_TABLE(net_axgbe, pci_id_axgbe_map); 24378691632fSRavi Kumar RTE_PMD_REGISTER_KMOD_DEP(net_axgbe, "* igb_uio | uio_pci_generic | vfio-pci"); 2438eeded204SDavid Marchand RTE_LOG_REGISTER_SUFFIX(axgbe_logtype_init, init, NOTICE); 2439eeded204SDavid Marchand RTE_LOG_REGISTER_SUFFIX(axgbe_logtype_driver, driver, NOTICE); 2440