xref: /dpdk/drivers/net/axgbe/axgbe_ethdev.c (revision 186f8e8c336158942d9dceae03db89266dddaa97)
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 
154feb9aa0SJesna K E #include <rte_vect.h>
164feb9aa0SJesna K E 
17a27ff9caSSelwin Sebastian #ifdef RTE_ARCH_X86
18a27ff9caSSelwin Sebastian #include <cpuid.h>
19a27ff9caSSelwin Sebastian #else
20a27ff9caSSelwin Sebastian #define __cpuid(n, a, b, c, d)
21a27ff9caSSelwin Sebastian #endif
22a27ff9caSSelwin Sebastian 
238691632fSRavi Kumar static int eth_axgbe_dev_init(struct rte_eth_dev *eth_dev);
247c4158a5SRavi Kumar static int  axgbe_dev_configure(struct rte_eth_dev *dev);
257c4158a5SRavi Kumar static int  axgbe_dev_start(struct rte_eth_dev *dev);
2662024eb8SIvan Ilchenko static int  axgbe_dev_stop(struct rte_eth_dev *dev);
27456ff159SRavi Kumar static void axgbe_dev_interrupt_handler(void *param);
28b142387bSThomas Monjalon static int axgbe_dev_close(struct rte_eth_dev *dev);
29bf403cfeSSelwin Sebastian static int axgbe_dev_reset(struct rte_eth_dev *dev);
309039c812SAndrew Rybchenko static int axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
319039c812SAndrew Rybchenko static int axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
32ca041cd4SIvan Ilchenko static int axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
33ca041cd4SIvan Ilchenko static int axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
3449a5e622SChandu Babu N static int axgbe_dev_mac_addr_set(struct rte_eth_dev *dev,
3549a5e622SChandu Babu N 				  struct rte_ether_addr *mac_addr);
3649a5e622SChandu Babu N static int axgbe_dev_mac_addr_add(struct rte_eth_dev *dev,
3749a5e622SChandu Babu N 				  struct rte_ether_addr *mac_addr,
3849a5e622SChandu Babu N 				  uint32_t index,
3949a5e622SChandu Babu N 				  uint32_t vmdq);
4049a5e622SChandu Babu N static void axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
4149a5e622SChandu Babu N static int axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
4249a5e622SChandu Babu N 				      struct rte_ether_addr *mc_addr_set,
4349a5e622SChandu Babu N 				      uint32_t nb_mc_addr);
44e01d9b2eSChandu Babu N static int axgbe_dev_uc_hash_table_set(struct rte_eth_dev *dev,
45e01d9b2eSChandu Babu N 				       struct rte_ether_addr *mac_addr,
46e01d9b2eSChandu Babu N 				       uint8_t add);
47e01d9b2eSChandu Babu N static int axgbe_dev_uc_all_hash_table_set(struct rte_eth_dev *dev,
48e01d9b2eSChandu Babu N 					   uint8_t add);
4944d45ffeSRavi Kumar static int axgbe_dev_link_update(struct rte_eth_dev *dev,
5044d45ffeSRavi Kumar 				 int wait_to_complete);
51df4867cdSChandu Babu N static int axgbe_dev_get_regs(struct rte_eth_dev *dev,
52df4867cdSChandu Babu N 			      struct rte_dev_reg_info *regs);
533e730511SRavi Kumar static int axgbe_dev_stats_get(struct rte_eth_dev *dev,
543e730511SRavi Kumar 				struct rte_eth_stats *stats);
559970a9adSIgor Romanov static int axgbe_dev_stats_reset(struct rte_eth_dev *dev);
569d1ef6b2SChandu Babu N static int axgbe_dev_xstats_get(struct rte_eth_dev *dev,
579d1ef6b2SChandu Babu N 				struct rte_eth_xstat *stats,
589d1ef6b2SChandu Babu N 				unsigned int n);
599d1ef6b2SChandu Babu N static int
609d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(struct rte_eth_dev *dev,
619d1ef6b2SChandu Babu N 			   struct rte_eth_xstat_name *xstats_names,
629d1ef6b2SChandu Babu N 			   unsigned int size);
639d1ef6b2SChandu Babu N static int
649d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev,
659d1ef6b2SChandu Babu N 			   const uint64_t *ids,
669d1ef6b2SChandu Babu N 			   uint64_t *values,
679d1ef6b2SChandu Babu N 			   unsigned int n);
689d1ef6b2SChandu Babu N static int
699d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
709d1ef6b2SChandu Babu N 				 const uint64_t *ids,
718c9f976fSAndrew Rybchenko 				 struct rte_eth_xstat_name *xstats_names,
729d1ef6b2SChandu Babu N 				 unsigned int size);
739d1ef6b2SChandu Babu N static int axgbe_dev_xstats_reset(struct rte_eth_dev *dev);
7476d7664dSChandu Babu N static int axgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
7576d7664dSChandu Babu N 			  struct rte_eth_rss_reta_entry64 *reta_conf,
7676d7664dSChandu Babu N 			  uint16_t reta_size);
7776d7664dSChandu Babu N static int axgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
7876d7664dSChandu Babu N 			 struct rte_eth_rss_reta_entry64 *reta_conf,
7976d7664dSChandu Babu N 			 uint16_t reta_size);
8076d7664dSChandu Babu N static int axgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
8176d7664dSChandu Babu N 				     struct rte_eth_rss_conf *rss_conf);
8276d7664dSChandu Babu N static int axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
8376d7664dSChandu Babu N 				       struct rte_eth_rss_conf *rss_conf);
84bdad90d1SIvan Ilchenko static int  axgbe_dev_info_get(struct rte_eth_dev *dev,
859e890103SRavi Kumar 			       struct rte_eth_dev_info *dev_info);
86cf97f33eSAmaranath Somalapuram static int axgbe_flow_ctrl_get(struct rte_eth_dev *dev,
87cf97f33eSAmaranath Somalapuram 				struct rte_eth_fc_conf *fc_conf);
88cf97f33eSAmaranath Somalapuram static int axgbe_flow_ctrl_set(struct rte_eth_dev *dev,
89cf97f33eSAmaranath Somalapuram 				struct rte_eth_fc_conf *fc_conf);
90e0543d4eSAmaranath Somalapuram static int axgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
91e0543d4eSAmaranath Somalapuram 				struct rte_eth_pfc_conf *pfc_conf);
927aed95c9SAmaranath Somalapuram static void axgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
937aed95c9SAmaranath Somalapuram 	struct rte_eth_rxq_info *qinfo);
947aed95c9SAmaranath Somalapuram static void axgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
957aed95c9SAmaranath Somalapuram 	struct rte_eth_txq_info *qinfo);
96ba6a168aSSivaramakrishnan Venkat const uint32_t *axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev,
97ba6a168aSSivaramakrishnan Venkat 					       size_t *no_of_elements);
98b58d8781SGirish Nandibasappa static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
998691632fSRavi Kumar 
100e0444948SSelwin Sebastian static int
101e0444948SSelwin Sebastian axgbe_timesync_enable(struct rte_eth_dev *dev);
102e0444948SSelwin Sebastian static int
103e0444948SSelwin Sebastian axgbe_timesync_disable(struct rte_eth_dev *dev);
104e0444948SSelwin Sebastian static int
105e0444948SSelwin Sebastian axgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
106e0444948SSelwin Sebastian 			struct timespec *timestamp, uint32_t flags);
107e0444948SSelwin Sebastian static int
108e0444948SSelwin Sebastian axgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
109e0444948SSelwin Sebastian 			struct timespec *timestamp);
110e0444948SSelwin Sebastian static int
111e0444948SSelwin Sebastian axgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
112e0444948SSelwin Sebastian static int
113e0444948SSelwin Sebastian axgbe_timesync_read_time(struct rte_eth_dev *dev,
114e0444948SSelwin Sebastian 			struct timespec *timestamp);
115e0444948SSelwin Sebastian static int
116e0444948SSelwin Sebastian axgbe_timesync_write_time(struct rte_eth_dev *dev,
117e0444948SSelwin Sebastian 			const struct timespec *timestamp);
118e0444948SSelwin Sebastian static void
119e0444948SSelwin Sebastian axgbe_set_tstamp_time(struct axgbe_port *pdata, unsigned int sec,
120e0444948SSelwin Sebastian 			unsigned int nsec);
121e0444948SSelwin Sebastian static void
122e0444948SSelwin Sebastian axgbe_update_tstamp_addend(struct axgbe_port *pdata,
123e0444948SSelwin Sebastian 			unsigned int addend);
12486578516SGirish Nandibasappa static int
12586578516SGirish Nandibasappa 	axgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on);
12686578516SGirish Nandibasappa static int axgbe_vlan_tpid_set(struct rte_eth_dev *dev,
12786578516SGirish Nandibasappa 				enum rte_vlan_type vlan_type, uint16_t tpid);
12886578516SGirish Nandibasappa static int axgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask);
129e0444948SSelwin Sebastian 
1309d1ef6b2SChandu Babu N struct axgbe_xstats {
1319d1ef6b2SChandu Babu N 	char name[RTE_ETH_XSTATS_NAME_SIZE];
1329d1ef6b2SChandu Babu N 	int offset;
1339d1ef6b2SChandu Babu N };
1349d1ef6b2SChandu Babu N 
1359d1ef6b2SChandu Babu N #define AXGMAC_MMC_STAT(_string, _var)                           \
1369d1ef6b2SChandu Babu N 	{ _string,                                              \
1379d1ef6b2SChandu Babu N 	  offsetof(struct axgbe_mmc_stats, _var),       \
1389d1ef6b2SChandu Babu N 	}
1399d1ef6b2SChandu Babu N 
1409d1ef6b2SChandu Babu N static const struct axgbe_xstats axgbe_xstats_strings[] = {
1419d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_bytes", txoctetcount_gb),
1429d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_packets", txframecount_gb),
1439d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb),
1449d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
1459d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb),
1469d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g),
1479d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
1489d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
1499d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
1509d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
1519d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
1529d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
1539d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
1549d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
1559d1ef6b2SChandu Babu N 
1569d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
1579d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_packets", rxframecount_gb),
1589d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
1599d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
1609d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
1619d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
1629d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
1639d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
1649d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
1659d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
1669d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
1679d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
1689d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
1699d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
1709d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
1719d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
1729d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
1739d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
1749d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
1759d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
1769d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
1779d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
1789d1ef6b2SChandu Babu N };
1799d1ef6b2SChandu Babu N 
1809d1ef6b2SChandu Babu N #define AXGBE_XSTATS_COUNT        ARRAY_SIZE(axgbe_xstats_strings)
1819d1ef6b2SChandu Babu N 
1828691632fSRavi Kumar /* The set of PCI devices this driver supports */
1838691632fSRavi Kumar #define AMD_PCI_VENDOR_ID       0x1022
184a27ff9caSSelwin Sebastian 
185a27ff9caSSelwin Sebastian #define	Fam17h	0x17
186a27ff9caSSelwin Sebastian #define	Fam19h	0x19
187a27ff9caSSelwin Sebastian 
188a27ff9caSSelwin Sebastian #define	CPUID_VENDOR_AuthenticAMD_ebx	0x68747541
189a27ff9caSSelwin Sebastian #define	CPUID_VENDOR_AuthenticAMD_ecx	0x444d4163
190a27ff9caSSelwin Sebastian #define	CPUID_VENDOR_AuthenticAMD_edx	0x69746e65
191a27ff9caSSelwin Sebastian 
1928691632fSRavi Kumar #define AMD_PCI_AXGBE_DEVICE_V2A 0x1458
1938691632fSRavi Kumar #define AMD_PCI_AXGBE_DEVICE_V2B 0x1459
1948691632fSRavi Kumar 
1958691632fSRavi Kumar static const struct rte_pci_id pci_id_axgbe_map[] = {
1968691632fSRavi Kumar 	{RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_AXGBE_DEVICE_V2A)},
1978691632fSRavi Kumar 	{RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_AXGBE_DEVICE_V2B)},
1988691632fSRavi Kumar 	{ .vendor_id = 0, },
1998691632fSRavi Kumar };
2008691632fSRavi Kumar 
201572890efSRavi Kumar static struct axgbe_version_data axgbe_v2a = {
2024ac7516bSRavi Kumar 	.init_function_ptrs_phy_impl    = axgbe_init_function_ptrs_phy_v2,
203572890efSRavi Kumar 	.xpcs_access			= AXGBE_XPCS_ACCESS_V2,
204572890efSRavi Kumar 	.mmc_64bit			= 1,
205572890efSRavi Kumar 	.tx_max_fifo_size		= 229376,
206572890efSRavi Kumar 	.rx_max_fifo_size		= 229376,
207572890efSRavi Kumar 	.tx_tstamp_workaround		= 1,
208572890efSRavi Kumar 	.ecc_support			= 1,
209572890efSRavi Kumar 	.i2c_support			= 1,
21000072056SRavi Kumar 	.an_cdr_workaround		= 1,
211e82b0fe0SVenkat Kumar Ande 	.enable_rrc			= 1,
212572890efSRavi Kumar };
213572890efSRavi Kumar 
214572890efSRavi Kumar static struct axgbe_version_data axgbe_v2b = {
2154ac7516bSRavi Kumar 	.init_function_ptrs_phy_impl    = axgbe_init_function_ptrs_phy_v2,
216572890efSRavi Kumar 	.xpcs_access			= AXGBE_XPCS_ACCESS_V2,
217572890efSRavi Kumar 	.mmc_64bit			= 1,
218572890efSRavi Kumar 	.tx_max_fifo_size		= 65536,
219572890efSRavi Kumar 	.rx_max_fifo_size		= 65536,
220572890efSRavi Kumar 	.tx_tstamp_workaround		= 1,
221572890efSRavi Kumar 	.ecc_support			= 1,
222572890efSRavi Kumar 	.i2c_support			= 1,
22300072056SRavi Kumar 	.an_cdr_workaround		= 1,
224e82b0fe0SVenkat Kumar Ande 	.enable_rrc			= 1,
225572890efSRavi Kumar };
226572890efSRavi Kumar 
2279e890103SRavi Kumar static const struct rte_eth_desc_lim rx_desc_lim = {
2289e890103SRavi Kumar 	.nb_max = AXGBE_MAX_RING_DESC,
2299e890103SRavi Kumar 	.nb_min = AXGBE_MIN_RING_DESC,
2309e890103SRavi Kumar 	.nb_align = 8,
2319e890103SRavi Kumar };
2329e890103SRavi Kumar 
2339e890103SRavi Kumar static const struct rte_eth_desc_lim tx_desc_lim = {
2349e890103SRavi Kumar 	.nb_max = AXGBE_MAX_RING_DESC,
2359e890103SRavi Kumar 	.nb_min = AXGBE_MIN_RING_DESC,
2369e890103SRavi Kumar 	.nb_align = 8,
2379e890103SRavi Kumar };
2389e890103SRavi Kumar 
2399e890103SRavi Kumar static const struct eth_dev_ops axgbe_eth_dev_ops = {
2407c4158a5SRavi Kumar 	.dev_configure        = axgbe_dev_configure,
2417c4158a5SRavi Kumar 	.dev_start            = axgbe_dev_start,
2427c4158a5SRavi Kumar 	.dev_stop             = axgbe_dev_stop,
2439e890103SRavi Kumar 	.dev_close            = axgbe_dev_close,
244bf403cfeSSelwin Sebastian 	.dev_reset            = axgbe_dev_reset,
245fa3e0440SRavi Kumar 	.promiscuous_enable   = axgbe_dev_promiscuous_enable,
246fa3e0440SRavi Kumar 	.promiscuous_disable  = axgbe_dev_promiscuous_disable,
247fa3e0440SRavi Kumar 	.allmulticast_enable  = axgbe_dev_allmulticast_enable,
248fa3e0440SRavi Kumar 	.allmulticast_disable = axgbe_dev_allmulticast_disable,
24949a5e622SChandu Babu N 	.mac_addr_set         = axgbe_dev_mac_addr_set,
25049a5e622SChandu Babu N 	.mac_addr_add         = axgbe_dev_mac_addr_add,
25149a5e622SChandu Babu N 	.mac_addr_remove      = axgbe_dev_mac_addr_remove,
25249a5e622SChandu Babu N 	.set_mc_addr_list     = axgbe_dev_set_mc_addr_list,
253e01d9b2eSChandu Babu N 	.uc_hash_table_set    = axgbe_dev_uc_hash_table_set,
254e01d9b2eSChandu Babu N 	.uc_all_hash_table_set = axgbe_dev_uc_all_hash_table_set,
25544d45ffeSRavi Kumar 	.link_update          = axgbe_dev_link_update,
256df4867cdSChandu Babu N 	.get_reg	      = axgbe_dev_get_regs,
2573e730511SRavi Kumar 	.stats_get            = axgbe_dev_stats_get,
2583e730511SRavi Kumar 	.stats_reset          = axgbe_dev_stats_reset,
2599d1ef6b2SChandu Babu N 	.xstats_get	      = axgbe_dev_xstats_get,
2609d1ef6b2SChandu Babu N 	.xstats_reset	      = axgbe_dev_xstats_reset,
2619d1ef6b2SChandu Babu N 	.xstats_get_names     = axgbe_dev_xstats_get_names,
2629d1ef6b2SChandu Babu N 	.xstats_get_names_by_id = axgbe_dev_xstats_get_names_by_id,
2639d1ef6b2SChandu Babu N 	.xstats_get_by_id     = axgbe_dev_xstats_get_by_id,
26476d7664dSChandu Babu N 	.reta_update          = axgbe_dev_rss_reta_update,
26576d7664dSChandu Babu N 	.reta_query           = axgbe_dev_rss_reta_query,
26676d7664dSChandu Babu N 	.rss_hash_update      = axgbe_dev_rss_hash_update,
26776d7664dSChandu Babu N 	.rss_hash_conf_get    = axgbe_dev_rss_hash_conf_get,
2689e890103SRavi Kumar 	.dev_infos_get        = axgbe_dev_info_get,
2699e890103SRavi Kumar 	.rx_queue_setup       = axgbe_dev_rx_queue_setup,
2709e890103SRavi Kumar 	.rx_queue_release     = axgbe_dev_rx_queue_release,
2719e890103SRavi Kumar 	.tx_queue_setup       = axgbe_dev_tx_queue_setup,
2729e890103SRavi Kumar 	.tx_queue_release     = axgbe_dev_tx_queue_release,
273cf97f33eSAmaranath Somalapuram 	.flow_ctrl_get        = axgbe_flow_ctrl_get,
274cf97f33eSAmaranath Somalapuram 	.flow_ctrl_set        = axgbe_flow_ctrl_set,
275e0543d4eSAmaranath Somalapuram 	.priority_flow_ctrl_set = axgbe_priority_flow_ctrl_set,
2767aed95c9SAmaranath Somalapuram 	.rxq_info_get                 = axgbe_rxq_info_get,
2777aed95c9SAmaranath Somalapuram 	.txq_info_get                 = axgbe_txq_info_get,
278410cf087SAmaranath Somalapuram 	.dev_supported_ptypes_get     = axgbe_dev_supported_ptypes_get,
279b58d8781SGirish Nandibasappa 	.mtu_set		= axgb_mtu_set,
28086578516SGirish Nandibasappa 	.vlan_filter_set      = axgbe_vlan_filter_set,
28186578516SGirish Nandibasappa 	.vlan_tpid_set        = axgbe_vlan_tpid_set,
28286578516SGirish Nandibasappa 	.vlan_offload_set     = axgbe_vlan_offload_set,
283e0444948SSelwin Sebastian 	.timesync_enable              = axgbe_timesync_enable,
284e0444948SSelwin Sebastian 	.timesync_disable             = axgbe_timesync_disable,
285e0444948SSelwin Sebastian 	.timesync_read_rx_timestamp   = axgbe_timesync_read_rx_timestamp,
286e0444948SSelwin Sebastian 	.timesync_read_tx_timestamp   = axgbe_timesync_read_tx_timestamp,
287e0444948SSelwin Sebastian 	.timesync_adjust_time         = axgbe_timesync_adjust_time,
288e0444948SSelwin Sebastian 	.timesync_read_time           = axgbe_timesync_read_time,
289e0444948SSelwin Sebastian 	.timesync_write_time          = axgbe_timesync_write_time,
290ff70acdfSSelwin Sebastian 	.fw_version_get			= axgbe_dev_fw_version_get,
2919e890103SRavi Kumar };
2929e890103SRavi Kumar 
2937c4158a5SRavi Kumar static int axgbe_phy_reset(struct axgbe_port *pdata)
2947c4158a5SRavi Kumar {
2957c4158a5SRavi Kumar 	pdata->phy_link = -1;
2967c4158a5SRavi Kumar 	pdata->phy_speed = SPEED_UNKNOWN;
2977c4158a5SRavi Kumar 	return pdata->phy_if.phy_reset(pdata);
2987c4158a5SRavi Kumar }
2997c4158a5SRavi Kumar 
300456ff159SRavi Kumar /*
301456ff159SRavi Kumar  * Interrupt handler triggered by NIC  for handling
302456ff159SRavi Kumar  * specific interrupt.
303456ff159SRavi Kumar  *
304456ff159SRavi Kumar  * @param handle
305456ff159SRavi Kumar  *  Pointer to interrupt handle.
306456ff159SRavi Kumar  * @param param
3077be78d02SJosh Soref  *  The address of parameter (struct rte_eth_dev *) registered before.
308456ff159SRavi Kumar  *
309456ff159SRavi Kumar  * @return
310456ff159SRavi Kumar  *  void
311456ff159SRavi Kumar  */
312456ff159SRavi Kumar static void
313456ff159SRavi Kumar axgbe_dev_interrupt_handler(void *param)
314456ff159SRavi Kumar {
315456ff159SRavi Kumar 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
316456ff159SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
3178590b93dSRavi Kumar 	unsigned int dma_isr, dma_ch_isr;
318456ff159SRavi Kumar 
319456ff159SRavi Kumar 	pdata->phy_if.an_isr(pdata);
3208590b93dSRavi Kumar 	/*DMA related interrupts*/
3218590b93dSRavi Kumar 	dma_isr = AXGMAC_IOREAD(pdata, DMA_ISR);
322e99981afSDavid Marchand 	PMD_DRV_LOG_LINE(DEBUG, "DMA_ISR=%#010x", dma_isr);
3238590b93dSRavi Kumar 	if (dma_isr) {
3248590b93dSRavi Kumar 		if (dma_isr & 1) {
3258590b93dSRavi Kumar 			dma_ch_isr =
3268590b93dSRavi Kumar 				AXGMAC_DMA_IOREAD((struct axgbe_rx_queue *)
3278590b93dSRavi Kumar 						  pdata->rx_queues[0],
3288590b93dSRavi Kumar 						  DMA_CH_SR);
329e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "DMA_CH0_ISR=%#010x", dma_ch_isr);
3308590b93dSRavi Kumar 			AXGMAC_DMA_IOWRITE((struct axgbe_rx_queue *)
3318590b93dSRavi Kumar 					   pdata->rx_queues[0],
3328590b93dSRavi Kumar 					   DMA_CH_SR, dma_ch_isr);
3338590b93dSRavi Kumar 		}
3348590b93dSRavi Kumar 	}
3356bee9d5fSNithin Dabilpuram 	/* Unmask interrupts since disabled after generation */
336d61138d4SHarman Kalra 	rte_intr_ack(pdata->pci_dev->intr_handle);
337456ff159SRavi Kumar }
338456ff159SRavi Kumar 
3397c4158a5SRavi Kumar /*
3407c4158a5SRavi Kumar  * Configure device link speed and setup link.
3417c4158a5SRavi Kumar  * It returns 0 on success.
3427c4158a5SRavi Kumar  */
3437c4158a5SRavi Kumar static int
3447c4158a5SRavi Kumar axgbe_dev_configure(struct rte_eth_dev *dev)
3457c4158a5SRavi Kumar {
3467c4158a5SRavi Kumar 	struct axgbe_port *pdata =  dev->data->dev_private;
3477c4158a5SRavi Kumar 	/* Checksum offload to hardware */
3487c4158a5SRavi Kumar 	pdata->rx_csum_enable = dev->data->dev_conf.rxmode.offloads &
349295968d1SFerruh Yigit 				RTE_ETH_RX_OFFLOAD_CHECKSUM;
3507c4158a5SRavi Kumar 	return 0;
3517c4158a5SRavi Kumar }
3527c4158a5SRavi Kumar 
3537c4158a5SRavi Kumar static int
3547c4158a5SRavi Kumar axgbe_dev_rx_mq_config(struct rte_eth_dev *dev)
3557c4158a5SRavi Kumar {
3560bc212a8SStephen Hemminger 	struct axgbe_port *pdata = dev->data->dev_private;
3577c4158a5SRavi Kumar 
358295968d1SFerruh Yigit 	if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS)
3597c4158a5SRavi Kumar 		pdata->rss_enable = 1;
360295968d1SFerruh Yigit 	else if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_NONE)
3617c4158a5SRavi Kumar 		pdata->rss_enable = 0;
3627c4158a5SRavi Kumar 	else
3637c4158a5SRavi Kumar 		return  -1;
3647c4158a5SRavi Kumar 	return 0;
3657c4158a5SRavi Kumar }
3667c4158a5SRavi Kumar 
3677c4158a5SRavi Kumar static int
3687c4158a5SRavi Kumar axgbe_dev_start(struct rte_eth_dev *dev)
3697c4158a5SRavi Kumar {
3700bc212a8SStephen Hemminger 	struct axgbe_port *pdata = dev->data->dev_private;
3710236016cSJie Hai 	uint16_t i;
3727c4158a5SRavi Kumar 	int ret;
373965b3127SSelwin Sebastian 
374965b3127SSelwin Sebastian 	dev->dev_ops = &axgbe_eth_dev_ops;
3757c4158a5SRavi Kumar 
3760bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
3770bc212a8SStephen Hemminger 
3787c4158a5SRavi Kumar 	/* Multiqueue RSS */
3797c4158a5SRavi Kumar 	ret = axgbe_dev_rx_mq_config(dev);
3807c4158a5SRavi Kumar 	if (ret) {
381e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Unable to config RX MQ");
3827c4158a5SRavi Kumar 		return ret;
3837c4158a5SRavi Kumar 	}
3847c4158a5SRavi Kumar 	ret = axgbe_phy_reset(pdata);
3857c4158a5SRavi Kumar 	if (ret) {
386e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "phy reset failed");
3877c4158a5SRavi Kumar 		return ret;
3887c4158a5SRavi Kumar 	}
3897c4158a5SRavi Kumar 	ret = pdata->hw_if.init(pdata);
3907c4158a5SRavi Kumar 	if (ret) {
391e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "dev_init failed");
3927c4158a5SRavi Kumar 		return ret;
3937c4158a5SRavi Kumar 	}
3947c4158a5SRavi Kumar 
3957c4158a5SRavi Kumar 	/* enable uio/vfio intr/eventfd mapping */
396d61138d4SHarman Kalra 	rte_intr_enable(pdata->pci_dev->intr_handle);
3977c4158a5SRavi Kumar 
3987c4158a5SRavi Kumar 	/* phy start*/
3997c4158a5SRavi Kumar 	pdata->phy_if.phy_start(pdata);
4008590b93dSRavi Kumar 	axgbe_dev_enable_tx(dev);
4018590b93dSRavi Kumar 	axgbe_dev_enable_rx(dev);
4027c4158a5SRavi Kumar 
4034693ae4aSJoyce Kong 	rte_bit_relaxed_clear32(AXGBE_STOPPED, &pdata->dev_state);
4044693ae4aSJoyce Kong 	rte_bit_relaxed_clear32(AXGBE_DOWN, &pdata->dev_state);
4051bb4a528SFerruh Yigit 
4069963b513SJesna K E 	axgbe_set_rx_function(dev);
4079963b513SJesna K E 	axgbe_set_tx_function(dev);
4080236016cSJie Hai 
4090236016cSJie Hai 	for (i = 0; i < dev->data->nb_rx_queues; i++)
4100236016cSJie Hai 		dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
4110236016cSJie Hai 	for (i = 0; i < dev->data->nb_tx_queues; i++)
4120236016cSJie Hai 		dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
4130236016cSJie Hai 
4147c4158a5SRavi Kumar 	return 0;
4157c4158a5SRavi Kumar }
4167c4158a5SRavi Kumar 
4177c4158a5SRavi Kumar /* Stop device: disable rx and tx functions to allow for reconfiguring. */
41862024eb8SIvan Ilchenko static int
4197c4158a5SRavi Kumar axgbe_dev_stop(struct rte_eth_dev *dev)
4207c4158a5SRavi Kumar {
4217c4158a5SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
4227c4158a5SRavi Kumar 
4230bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
4240bc212a8SStephen Hemminger 
425d61138d4SHarman Kalra 	rte_intr_disable(pdata->pci_dev->intr_handle);
4267c4158a5SRavi Kumar 
4274693ae4aSJoyce Kong 	if (rte_bit_relaxed_get32(AXGBE_STOPPED, &pdata->dev_state))
42862024eb8SIvan Ilchenko 		return 0;
4297c4158a5SRavi Kumar 
4304693ae4aSJoyce Kong 	rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state);
4318590b93dSRavi Kumar 	axgbe_dev_disable_tx(dev);
4328590b93dSRavi Kumar 	axgbe_dev_disable_rx(dev);
4337c4158a5SRavi Kumar 
4347c4158a5SRavi Kumar 	pdata->phy_if.phy_stop(pdata);
4357c4158a5SRavi Kumar 	pdata->hw_if.exit(pdata);
4367c4158a5SRavi Kumar 	memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link));
4374693ae4aSJoyce Kong 	rte_bit_relaxed_set32(AXGBE_DOWN, &pdata->dev_state);
43862024eb8SIvan Ilchenko 
43962024eb8SIvan Ilchenko 	return 0;
4407c4158a5SRavi Kumar }
4417c4158a5SRavi Kumar 
4429039c812SAndrew Rybchenko static int
443fa3e0440SRavi Kumar axgbe_dev_promiscuous_enable(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, 1);
4509039c812SAndrew Rybchenko 
4519039c812SAndrew Rybchenko 	return 0;
452fa3e0440SRavi Kumar }
453fa3e0440SRavi Kumar 
4549039c812SAndrew Rybchenko static int
455fa3e0440SRavi Kumar axgbe_dev_promiscuous_disable(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 	AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 0);
4629039c812SAndrew Rybchenko 
4639039c812SAndrew Rybchenko 	return 0;
464fa3e0440SRavi Kumar }
465fa3e0440SRavi Kumar 
466ca041cd4SIvan Ilchenko static int
467fa3e0440SRavi Kumar axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
468fa3e0440SRavi Kumar {
469fa3e0440SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
470fa3e0440SRavi Kumar 
4710bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
4720bc212a8SStephen Hemminger 
473fa3e0440SRavi Kumar 	if (AXGMAC_IOREAD_BITS(pdata, MAC_PFR, PM))
474ca041cd4SIvan Ilchenko 		return 0;
475fa3e0440SRavi Kumar 	AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, 1);
476ca041cd4SIvan Ilchenko 
477ca041cd4SIvan Ilchenko 	return 0;
478fa3e0440SRavi Kumar }
479fa3e0440SRavi Kumar 
480ca041cd4SIvan Ilchenko static int
481fa3e0440SRavi Kumar axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
482fa3e0440SRavi Kumar {
483fa3e0440SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
484fa3e0440SRavi Kumar 
4850bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
4860bc212a8SStephen Hemminger 
487fa3e0440SRavi Kumar 	if (!AXGMAC_IOREAD_BITS(pdata, MAC_PFR, PM))
488ca041cd4SIvan Ilchenko 		return 0;
489fa3e0440SRavi Kumar 	AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, 0);
490ca041cd4SIvan Ilchenko 
491ca041cd4SIvan Ilchenko 	return 0;
492fa3e0440SRavi Kumar }
493fa3e0440SRavi Kumar 
49449a5e622SChandu Babu N static int
49549a5e622SChandu Babu N axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
49649a5e622SChandu Babu N {
49749a5e622SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
49849a5e622SChandu Babu N 
49949a5e622SChandu Babu N 	/* Set Default MAC Addr */
50049a5e622SChandu Babu N 	axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, 0);
50149a5e622SChandu Babu N 
50249a5e622SChandu Babu N 	return 0;
50349a5e622SChandu Babu N }
50449a5e622SChandu Babu N 
50549a5e622SChandu Babu N static int
50649a5e622SChandu Babu N axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
50749a5e622SChandu Babu N 			      uint32_t index, uint32_t pool __rte_unused)
50849a5e622SChandu Babu N {
50949a5e622SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
51049a5e622SChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
51149a5e622SChandu Babu N 
51249a5e622SChandu Babu N 	if (index > hw_feat->addn_mac) {
513e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Invalid Index %d", index);
51449a5e622SChandu Babu N 		return -EINVAL;
51549a5e622SChandu Babu N 	}
51649a5e622SChandu Babu N 	axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, index);
51749a5e622SChandu Babu N 	return 0;
51849a5e622SChandu Babu N }
51949a5e622SChandu Babu N 
52076d7664dSChandu Babu N static int
52176d7664dSChandu Babu N axgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
52276d7664dSChandu Babu N 			  struct rte_eth_rss_reta_entry64 *reta_conf,
52376d7664dSChandu Babu N 			  uint16_t reta_size)
52476d7664dSChandu Babu N {
52576d7664dSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
52676d7664dSChandu Babu N 	unsigned int i, idx, shift;
52776d7664dSChandu Babu N 	int ret;
52876d7664dSChandu Babu N 
52976d7664dSChandu Babu N 	if (!pdata->rss_enable) {
530e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "RSS not enabled");
53176d7664dSChandu Babu N 		return -ENOTSUP;
53276d7664dSChandu Babu N 	}
53376d7664dSChandu Babu N 
53476d7664dSChandu Babu N 	if (reta_size == 0 || reta_size > AXGBE_RSS_MAX_TABLE_SIZE) {
535e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "reta_size %d is not supported", reta_size);
53676d7664dSChandu Babu N 		return -EINVAL;
53776d7664dSChandu Babu N 	}
53876d7664dSChandu Babu N 
53976d7664dSChandu Babu N 	for (i = 0; i < reta_size; i++) {
540295968d1SFerruh Yigit 		idx = i / RTE_ETH_RETA_GROUP_SIZE;
541295968d1SFerruh Yigit 		shift = i % RTE_ETH_RETA_GROUP_SIZE;
54276d7664dSChandu Babu N 		if ((reta_conf[idx].mask & (1ULL << shift)) == 0)
54376d7664dSChandu Babu N 			continue;
54476d7664dSChandu Babu N 		pdata->rss_table[i] = reta_conf[idx].reta[shift];
54576d7664dSChandu Babu N 	}
54676d7664dSChandu Babu N 
54776d7664dSChandu Babu N 	/* Program the lookup table */
54876d7664dSChandu Babu N 	ret = axgbe_write_rss_lookup_table(pdata);
54976d7664dSChandu Babu N 	return ret;
55076d7664dSChandu Babu N }
55176d7664dSChandu Babu N 
55276d7664dSChandu Babu N static int
55376d7664dSChandu Babu N axgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
55476d7664dSChandu Babu N 			 struct rte_eth_rss_reta_entry64 *reta_conf,
55576d7664dSChandu Babu N 			 uint16_t reta_size)
55676d7664dSChandu Babu N {
55776d7664dSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
55876d7664dSChandu Babu N 	unsigned int i, idx, shift;
55976d7664dSChandu Babu N 
56076d7664dSChandu Babu N 	if (!pdata->rss_enable) {
561e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "RSS not enabled");
56276d7664dSChandu Babu N 		return -ENOTSUP;
56376d7664dSChandu Babu N 	}
56476d7664dSChandu Babu N 
56576d7664dSChandu Babu N 	if (reta_size == 0 || reta_size > AXGBE_RSS_MAX_TABLE_SIZE) {
566e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "reta_size %d is not supported", reta_size);
56776d7664dSChandu Babu N 		return -EINVAL;
56876d7664dSChandu Babu N 	}
56976d7664dSChandu Babu N 
57076d7664dSChandu Babu N 	for (i = 0; i < reta_size; i++) {
571295968d1SFerruh Yigit 		idx = i / RTE_ETH_RETA_GROUP_SIZE;
572295968d1SFerruh Yigit 		shift = i % RTE_ETH_RETA_GROUP_SIZE;
57376d7664dSChandu Babu N 		if ((reta_conf[idx].mask & (1ULL << shift)) == 0)
57476d7664dSChandu Babu N 			continue;
57576d7664dSChandu Babu N 		reta_conf[idx].reta[shift] = pdata->rss_table[i];
57676d7664dSChandu Babu N 	}
57776d7664dSChandu Babu N 	return 0;
57876d7664dSChandu Babu N }
57976d7664dSChandu Babu N 
58076d7664dSChandu Babu N static int
58176d7664dSChandu Babu N axgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
58276d7664dSChandu Babu N 			  struct rte_eth_rss_conf *rss_conf)
58376d7664dSChandu Babu N {
58476d7664dSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
58576d7664dSChandu Babu N 	int ret;
58676d7664dSChandu Babu N 
58776d7664dSChandu Babu N 	if (!pdata->rss_enable) {
588e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "RSS not enabled");
58976d7664dSChandu Babu N 		return -ENOTSUP;
59076d7664dSChandu Babu N 	}
59176d7664dSChandu Babu N 
59276d7664dSChandu Babu N 	if (rss_conf == NULL) {
593e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "rss_conf value isn't valid");
59476d7664dSChandu Babu N 		return -EINVAL;
59576d7664dSChandu Babu N 	}
59676d7664dSChandu Babu N 
59776d7664dSChandu Babu N 	if (rss_conf->rss_key != NULL &&
59876d7664dSChandu Babu N 	    rss_conf->rss_key_len == AXGBE_RSS_HASH_KEY_SIZE) {
59976d7664dSChandu Babu N 		rte_memcpy(pdata->rss_key, rss_conf->rss_key,
60076d7664dSChandu Babu N 		       AXGBE_RSS_HASH_KEY_SIZE);
60176d7664dSChandu Babu N 		/* Program the hash key */
60276d7664dSChandu Babu N 		ret = axgbe_write_rss_hash_key(pdata);
60376d7664dSChandu Babu N 		if (ret != 0)
60476d7664dSChandu Babu N 			return ret;
60576d7664dSChandu Babu N 	}
60676d7664dSChandu Babu N 
60776d7664dSChandu Babu N 	pdata->rss_hf = rss_conf->rss_hf & AXGBE_RSS_OFFLOAD;
60876d7664dSChandu Babu N 
609295968d1SFerruh Yigit 	if (pdata->rss_hf & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6))
61076d7664dSChandu Babu N 		AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1);
61176d7664dSChandu Babu N 	if (pdata->rss_hf &
612295968d1SFerruh Yigit 	    (RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_NONFRAG_IPV6_TCP))
61376d7664dSChandu Babu N 		AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1);
61476d7664dSChandu Babu N 	if (pdata->rss_hf &
615295968d1SFerruh Yigit 	    (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV6_UDP))
61676d7664dSChandu Babu N 		AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1);
61776d7664dSChandu Babu N 
61876d7664dSChandu Babu N 	/* Set the RSS options */
61976d7664dSChandu Babu N 	AXGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options);
62076d7664dSChandu Babu N 
62176d7664dSChandu Babu N 	return 0;
62276d7664dSChandu Babu N }
62376d7664dSChandu Babu N 
62476d7664dSChandu Babu N static int
62576d7664dSChandu Babu N axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
62676d7664dSChandu Babu N 			    struct rte_eth_rss_conf *rss_conf)
62776d7664dSChandu Babu N {
62876d7664dSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
62976d7664dSChandu Babu N 
63076d7664dSChandu Babu N 	if (!pdata->rss_enable) {
631e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "RSS not enabled");
63276d7664dSChandu Babu N 		return -ENOTSUP;
63376d7664dSChandu Babu N 	}
63476d7664dSChandu Babu N 
63576d7664dSChandu Babu N 	if (rss_conf == NULL) {
636e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "rss_conf value isn't valid");
63776d7664dSChandu Babu N 		return -EINVAL;
63876d7664dSChandu Babu N 	}
63976d7664dSChandu Babu N 
64076d7664dSChandu Babu N 	if (rss_conf->rss_key != NULL &&
64176d7664dSChandu Babu N 	    rss_conf->rss_key_len >= AXGBE_RSS_HASH_KEY_SIZE) {
64276d7664dSChandu Babu N 		rte_memcpy(rss_conf->rss_key, pdata->rss_key,
64376d7664dSChandu Babu N 		       AXGBE_RSS_HASH_KEY_SIZE);
64476d7664dSChandu Babu N 	}
64576d7664dSChandu Babu N 	rss_conf->rss_key_len = AXGBE_RSS_HASH_KEY_SIZE;
64676d7664dSChandu Babu N 	rss_conf->rss_hf = pdata->rss_hf;
64776d7664dSChandu Babu N 	return 0;
64876d7664dSChandu Babu N }
64976d7664dSChandu Babu N 
650bf403cfeSSelwin Sebastian static int
651bf403cfeSSelwin Sebastian axgbe_dev_reset(struct rte_eth_dev *dev)
652bf403cfeSSelwin Sebastian {
653bf403cfeSSelwin Sebastian 	int ret = 0;
654bf403cfeSSelwin Sebastian 
655bf403cfeSSelwin Sebastian 	ret = axgbe_dev_close(dev);
656bf403cfeSSelwin Sebastian 	if (ret)
657bf403cfeSSelwin Sebastian 		return ret;
658bf403cfeSSelwin Sebastian 
659bf403cfeSSelwin Sebastian 	ret = eth_axgbe_dev_init(dev);
660bf403cfeSSelwin Sebastian 
661bf403cfeSSelwin Sebastian 	return ret;
662bf403cfeSSelwin Sebastian }
663bf403cfeSSelwin Sebastian 
66449a5e622SChandu Babu N static void
66549a5e622SChandu Babu N axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
66649a5e622SChandu Babu N {
66749a5e622SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
66849a5e622SChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
66949a5e622SChandu Babu N 
67049a5e622SChandu Babu N 	if (index > hw_feat->addn_mac) {
671e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Invalid Index %d", index);
67249a5e622SChandu Babu N 		return;
67349a5e622SChandu Babu N 	}
67449a5e622SChandu Babu N 	axgbe_set_mac_addn_addr(pdata, NULL, index);
67549a5e622SChandu Babu N }
67649a5e622SChandu Babu N 
67749a5e622SChandu Babu N static int
67849a5e622SChandu Babu N axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
67949a5e622SChandu Babu N 				      struct rte_ether_addr *mc_addr_set,
68049a5e622SChandu Babu N 				      uint32_t nb_mc_addr)
68149a5e622SChandu Babu N {
68249a5e622SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
68349a5e622SChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
68449a5e622SChandu Babu N 	uint32_t index = 1; /* 0 is always default mac */
68549a5e622SChandu Babu N 	uint32_t i;
68649a5e622SChandu Babu N 
68749a5e622SChandu Babu N 	if (nb_mc_addr > hw_feat->addn_mac) {
688e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Invalid Index %d", nb_mc_addr);
68949a5e622SChandu Babu N 		return -EINVAL;
69049a5e622SChandu Babu N 	}
69149a5e622SChandu Babu N 
69249a5e622SChandu Babu N 	/* clear unicast addresses */
69349a5e622SChandu Babu N 	for (i = 1; i < hw_feat->addn_mac; i++) {
69449a5e622SChandu Babu N 		if (rte_is_zero_ether_addr(&dev->data->mac_addrs[i]))
69549a5e622SChandu Babu N 			continue;
69649a5e622SChandu Babu N 		memset(&dev->data->mac_addrs[i], 0,
69749a5e622SChandu Babu N 		       sizeof(struct rte_ether_addr));
69849a5e622SChandu Babu N 	}
69949a5e622SChandu Babu N 
70049a5e622SChandu Babu N 	while (nb_mc_addr--)
70149a5e622SChandu Babu N 		axgbe_set_mac_addn_addr(pdata, (u8 *)mc_addr_set++, index++);
70249a5e622SChandu Babu N 
70349a5e622SChandu Babu N 	return 0;
70449a5e622SChandu Babu N }
70549a5e622SChandu Babu N 
706e01d9b2eSChandu Babu N static int
707e01d9b2eSChandu Babu N axgbe_dev_uc_hash_table_set(struct rte_eth_dev *dev,
708e01d9b2eSChandu Babu N 			    struct rte_ether_addr *mac_addr, uint8_t add)
709e01d9b2eSChandu Babu N {
710e01d9b2eSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
711e01d9b2eSChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
712e01d9b2eSChandu Babu N 
713e01d9b2eSChandu Babu N 	if (!hw_feat->hash_table_size) {
714e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "MAC Hash Table not supported");
715e01d9b2eSChandu Babu N 		return -ENOTSUP;
716e01d9b2eSChandu Babu N 	}
717e01d9b2eSChandu Babu N 
718e01d9b2eSChandu Babu N 	axgbe_set_mac_hash_table(pdata, (u8 *)mac_addr, add);
719e01d9b2eSChandu Babu N 
720e01d9b2eSChandu Babu N 	if (pdata->uc_hash_mac_addr > 0) {
721e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
722e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
723e01d9b2eSChandu Babu N 	} else {
724e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 0);
725e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0);
726e01d9b2eSChandu Babu N 	}
727e01d9b2eSChandu Babu N 	return 0;
728e01d9b2eSChandu Babu N }
729e01d9b2eSChandu Babu N 
730e01d9b2eSChandu Babu N static int
731e01d9b2eSChandu Babu N axgbe_dev_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t add)
732e01d9b2eSChandu Babu N {
733e01d9b2eSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
734e01d9b2eSChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
735e01d9b2eSChandu Babu N 	uint32_t index;
736e01d9b2eSChandu Babu N 
737e01d9b2eSChandu Babu N 	if (!hw_feat->hash_table_size) {
738e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "MAC Hash Table not supported");
739e01d9b2eSChandu Babu N 		return -ENOTSUP;
740e01d9b2eSChandu Babu N 	}
741e01d9b2eSChandu Babu N 
742e01d9b2eSChandu Babu N 	for (index = 0; index < pdata->hash_table_count; index++) {
743e01d9b2eSChandu Babu N 		if (add)
744e01d9b2eSChandu Babu N 			pdata->uc_hash_table[index] = ~0;
745e01d9b2eSChandu Babu N 		else
746e01d9b2eSChandu Babu N 			pdata->uc_hash_table[index] = 0;
747e01d9b2eSChandu Babu N 
748e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(DEBUG, "%s MAC hash table at Index %#x",
749e01d9b2eSChandu Babu N 			    add ? "set" : "clear", index);
750e01d9b2eSChandu Babu N 
751e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE(pdata, MAC_HTR(index),
752e01d9b2eSChandu Babu N 			       pdata->uc_hash_table[index]);
753e01d9b2eSChandu Babu N 	}
754e01d9b2eSChandu Babu N 
755e01d9b2eSChandu Babu N 	if (add) {
756e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
757e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
758e01d9b2eSChandu Babu N 	} else {
759e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 0);
760e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0);
761e01d9b2eSChandu Babu N 	}
762e01d9b2eSChandu Babu N 	return 0;
763e01d9b2eSChandu Babu N }
764e01d9b2eSChandu Babu N 
76544d45ffeSRavi Kumar /* return 0 means link status changed, -1 means not changed */
76644d45ffeSRavi Kumar static int
76744d45ffeSRavi Kumar axgbe_dev_link_update(struct rte_eth_dev *dev,
76844d45ffeSRavi Kumar 		      int wait_to_complete __rte_unused)
76944d45ffeSRavi Kumar {
77044d45ffeSRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
77144d45ffeSRavi Kumar 	struct rte_eth_link link;
77244d45ffeSRavi Kumar 	int ret = 0;
77344d45ffeSRavi Kumar 
77444d45ffeSRavi Kumar 	PMD_INIT_FUNC_TRACE();
77544d45ffeSRavi Kumar 	rte_delay_ms(800);
77644d45ffeSRavi Kumar 
77744d45ffeSRavi Kumar 	pdata->phy_if.phy_status(pdata);
77844d45ffeSRavi Kumar 
77944d45ffeSRavi Kumar 	memset(&link, 0, sizeof(struct rte_eth_link));
78044d45ffeSRavi Kumar 	link.link_duplex = pdata->phy.duplex;
78144d45ffeSRavi Kumar 	link.link_status = pdata->phy_link;
78244d45ffeSRavi Kumar 	link.link_speed = pdata->phy_speed;
78344d45ffeSRavi Kumar 	link.link_autoneg = !(dev->data->dev_conf.link_speeds &
784295968d1SFerruh Yigit 			      RTE_ETH_LINK_SPEED_FIXED);
78544d45ffeSRavi Kumar 	ret = rte_eth_linkstatus_set(dev, &link);
786e64f909dSVenkat Kumar Ande 	if (ret == 0)
787e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Link status changed");
78844d45ffeSRavi Kumar 
78944d45ffeSRavi Kumar 	return ret;
79044d45ffeSRavi Kumar }
79144d45ffeSRavi Kumar 
792df4867cdSChandu Babu N static int
793df4867cdSChandu Babu N axgbe_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs)
794df4867cdSChandu Babu N {
795df4867cdSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
796df4867cdSChandu Babu N 
797df4867cdSChandu Babu N 	if (regs->data == NULL) {
798df4867cdSChandu Babu N 		regs->length = axgbe_regs_get_count(pdata);
799df4867cdSChandu Babu N 		regs->width = sizeof(uint32_t);
800df4867cdSChandu Babu N 		return 0;
801df4867cdSChandu Babu N 	}
802df4867cdSChandu Babu N 
803df4867cdSChandu Babu N 	/* Only full register dump is supported */
804df4867cdSChandu Babu N 	if (regs->length &&
805df4867cdSChandu Babu N 	    regs->length != (uint32_t)axgbe_regs_get_count(pdata))
806df4867cdSChandu Babu N 		return -ENOTSUP;
807df4867cdSChandu Babu N 
808df4867cdSChandu Babu N 	regs->version = pdata->pci_dev->id.vendor_id << 16 |
809df4867cdSChandu Babu N 			pdata->pci_dev->id.device_id;
810df4867cdSChandu Babu N 	axgbe_regs_dump(pdata, regs->data);
811df4867cdSChandu Babu N 	return 0;
812df4867cdSChandu Babu N }
8139d1ef6b2SChandu Babu N static void axgbe_read_mmc_stats(struct axgbe_port *pdata)
8149d1ef6b2SChandu Babu N {
8159d1ef6b2SChandu Babu N 	struct axgbe_mmc_stats *stats = &pdata->mmc_stats;
8169d1ef6b2SChandu Babu N 
8179d1ef6b2SChandu Babu N 	/* Freeze counters */
8189d1ef6b2SChandu Babu N 	AXGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
8199d1ef6b2SChandu Babu N 
8209d1ef6b2SChandu Babu N 	/* Tx counters */
8219d1ef6b2SChandu Babu N 	stats->txoctetcount_gb +=
8229d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
8239d1ef6b2SChandu Babu N 	stats->txoctetcount_gb +=
8249d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_HI) << 32);
8259d1ef6b2SChandu Babu N 
8269d1ef6b2SChandu Babu N 	stats->txframecount_gb +=
8279d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
8289d1ef6b2SChandu Babu N 	stats->txframecount_gb +=
8299d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_HI) << 32);
8309d1ef6b2SChandu Babu N 
8319d1ef6b2SChandu Babu N 	stats->txbroadcastframes_g +=
8329d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
8339d1ef6b2SChandu Babu N 	stats->txbroadcastframes_g +=
8349d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_HI) << 32);
8359d1ef6b2SChandu Babu N 
8369d1ef6b2SChandu Babu N 	stats->txmulticastframes_g +=
8379d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
8389d1ef6b2SChandu Babu N 	stats->txmulticastframes_g +=
8399d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_HI) << 32);
8409d1ef6b2SChandu Babu N 
8419d1ef6b2SChandu Babu N 	stats->tx64octets_gb +=
8429d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
8439d1ef6b2SChandu Babu N 	stats->tx64octets_gb +=
8449d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_HI) << 32);
8459d1ef6b2SChandu Babu N 
8469d1ef6b2SChandu Babu N 	stats->tx65to127octets_gb +=
8479d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
8489d1ef6b2SChandu Babu N 	stats->tx65to127octets_gb +=
8499d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_HI) << 32);
8509d1ef6b2SChandu Babu N 
8519d1ef6b2SChandu Babu N 	stats->tx128to255octets_gb +=
8529d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
8539d1ef6b2SChandu Babu N 	stats->tx128to255octets_gb +=
8549d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_HI) << 32);
8559d1ef6b2SChandu Babu N 
8569d1ef6b2SChandu Babu N 	stats->tx256to511octets_gb +=
8579d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
8589d1ef6b2SChandu Babu N 	stats->tx256to511octets_gb +=
8599d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_HI) << 32);
8609d1ef6b2SChandu Babu N 
8619d1ef6b2SChandu Babu N 	stats->tx512to1023octets_gb +=
8629d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
8639d1ef6b2SChandu Babu N 	stats->tx512to1023octets_gb +=
8649d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_HI) << 32);
8659d1ef6b2SChandu Babu N 
8669d1ef6b2SChandu Babu N 	stats->tx1024tomaxoctets_gb +=
8679d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
8689d1ef6b2SChandu Babu N 	stats->tx1024tomaxoctets_gb +=
8699d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_HI) << 32);
8709d1ef6b2SChandu Babu N 
8719d1ef6b2SChandu Babu N 	stats->txunicastframes_gb +=
8729d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
8739d1ef6b2SChandu Babu N 	stats->txunicastframes_gb +=
8749d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_HI) << 32);
8759d1ef6b2SChandu Babu N 
8769d1ef6b2SChandu Babu N 	stats->txmulticastframes_gb +=
8779d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
8789d1ef6b2SChandu Babu N 	stats->txmulticastframes_gb +=
8799d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_HI) << 32);
8809d1ef6b2SChandu Babu N 
8819d1ef6b2SChandu Babu N 	stats->txbroadcastframes_g +=
8829d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
8839d1ef6b2SChandu Babu N 	stats->txbroadcastframes_g +=
8849d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_HI) << 32);
8859d1ef6b2SChandu Babu N 
8869d1ef6b2SChandu Babu N 	stats->txunderflowerror +=
8879d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
8889d1ef6b2SChandu Babu N 	stats->txunderflowerror +=
8899d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_HI) << 32);
8909d1ef6b2SChandu Babu N 
8919d1ef6b2SChandu Babu N 	stats->txoctetcount_g +=
8929d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
8939d1ef6b2SChandu Babu N 	stats->txoctetcount_g +=
8949d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_HI) << 32);
8959d1ef6b2SChandu Babu N 
8969d1ef6b2SChandu Babu N 	stats->txframecount_g +=
8979d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
8989d1ef6b2SChandu Babu N 	stats->txframecount_g +=
8999d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_HI) << 32);
9009d1ef6b2SChandu Babu N 
9019d1ef6b2SChandu Babu N 	stats->txpauseframes +=
9029d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
9039d1ef6b2SChandu Babu N 	stats->txpauseframes +=
9049d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_HI) << 32);
9059d1ef6b2SChandu Babu N 
9069d1ef6b2SChandu Babu N 	stats->txvlanframes_g +=
9079d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
9089d1ef6b2SChandu Babu N 	stats->txvlanframes_g +=
9099d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_HI) << 32);
9109d1ef6b2SChandu Babu N 
9119d1ef6b2SChandu Babu N 	/* Rx counters */
9129d1ef6b2SChandu Babu N 	stats->rxframecount_gb +=
9139d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
9149d1ef6b2SChandu Babu N 	stats->rxframecount_gb +=
9159d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_HI) << 32);
9169d1ef6b2SChandu Babu N 
9179d1ef6b2SChandu Babu N 	stats->rxoctetcount_gb +=
9189d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
9199d1ef6b2SChandu Babu N 	stats->rxoctetcount_gb +=
9209d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_HI) << 32);
9219d1ef6b2SChandu Babu N 
9229d1ef6b2SChandu Babu N 	stats->rxoctetcount_g +=
9239d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
9249d1ef6b2SChandu Babu N 	stats->rxoctetcount_g +=
9259d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_HI) << 32);
9269d1ef6b2SChandu Babu N 
9279d1ef6b2SChandu Babu N 	stats->rxbroadcastframes_g +=
9289d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
9299d1ef6b2SChandu Babu N 	stats->rxbroadcastframes_g +=
9309d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_HI) << 32);
9319d1ef6b2SChandu Babu N 
9329d1ef6b2SChandu Babu N 	stats->rxmulticastframes_g +=
9339d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
9349d1ef6b2SChandu Babu N 	stats->rxmulticastframes_g +=
9359d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_HI) << 32);
9369d1ef6b2SChandu Babu N 
9379d1ef6b2SChandu Babu N 	stats->rxcrcerror +=
9389d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
9399d1ef6b2SChandu Babu N 	stats->rxcrcerror +=
9409d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXCRCERROR_HI) << 32);
9419d1ef6b2SChandu Babu N 
9429d1ef6b2SChandu Babu N 	stats->rxrunterror +=
9439d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
9449d1ef6b2SChandu Babu N 
9459d1ef6b2SChandu Babu N 	stats->rxjabbererror +=
9469d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
9479d1ef6b2SChandu Babu N 
9489d1ef6b2SChandu Babu N 	stats->rxundersize_g +=
9499d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
9509d1ef6b2SChandu Babu N 
9519d1ef6b2SChandu Babu N 	stats->rxoversize_g +=
9529d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
9539d1ef6b2SChandu Babu N 
9549d1ef6b2SChandu Babu N 	stats->rx64octets_gb +=
9559d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
9569d1ef6b2SChandu Babu N 	stats->rx64octets_gb +=
9579d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_HI) << 32);
9589d1ef6b2SChandu Babu N 
9599d1ef6b2SChandu Babu N 	stats->rx65to127octets_gb +=
9609d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
9619d1ef6b2SChandu Babu N 	stats->rx65to127octets_gb +=
9629d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_HI) << 32);
9639d1ef6b2SChandu Babu N 
9649d1ef6b2SChandu Babu N 	stats->rx128to255octets_gb +=
9659d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
9669d1ef6b2SChandu Babu N 	stats->rx128to255octets_gb +=
9679d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_HI) << 32);
9689d1ef6b2SChandu Babu N 
9699d1ef6b2SChandu Babu N 	stats->rx256to511octets_gb +=
9709d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
9719d1ef6b2SChandu Babu N 	stats->rx256to511octets_gb +=
9729d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_HI) << 32);
9739d1ef6b2SChandu Babu N 
9749d1ef6b2SChandu Babu N 	stats->rx512to1023octets_gb +=
9759d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
9769d1ef6b2SChandu Babu N 	stats->rx512to1023octets_gb +=
9779d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_HI) << 32);
9789d1ef6b2SChandu Babu N 
9799d1ef6b2SChandu Babu N 	stats->rx1024tomaxoctets_gb +=
9809d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
9819d1ef6b2SChandu Babu N 	stats->rx1024tomaxoctets_gb +=
9829d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_HI) << 32);
9839d1ef6b2SChandu Babu N 
9849d1ef6b2SChandu Babu N 	stats->rxunicastframes_g +=
9859d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
9869d1ef6b2SChandu Babu N 	stats->rxunicastframes_g +=
9879d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_HI) << 32);
9889d1ef6b2SChandu Babu N 
9899d1ef6b2SChandu Babu N 	stats->rxlengtherror +=
9909d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
9919d1ef6b2SChandu Babu N 	stats->rxlengtherror +=
9929d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_HI) << 32);
9939d1ef6b2SChandu Babu N 
9949d1ef6b2SChandu Babu N 	stats->rxoutofrangetype +=
9959d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
9969d1ef6b2SChandu Babu N 	stats->rxoutofrangetype +=
9979d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_HI) << 32);
9989d1ef6b2SChandu Babu N 
9999d1ef6b2SChandu Babu N 	stats->rxpauseframes +=
10009d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
10019d1ef6b2SChandu Babu N 	stats->rxpauseframes +=
10029d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_HI) << 32);
10039d1ef6b2SChandu Babu N 
10049d1ef6b2SChandu Babu N 	stats->rxfifooverflow +=
10059d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
10069d1ef6b2SChandu Babu N 	stats->rxfifooverflow +=
10079d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_HI) << 32);
10089d1ef6b2SChandu Babu N 
10099d1ef6b2SChandu Babu N 	stats->rxvlanframes_gb +=
10109d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
10119d1ef6b2SChandu Babu N 	stats->rxvlanframes_gb +=
10129d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_HI) << 32);
10139d1ef6b2SChandu Babu N 
10149d1ef6b2SChandu Babu N 	stats->rxwatchdogerror +=
10159d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
10169d1ef6b2SChandu Babu N 
10179d1ef6b2SChandu Babu N 	/* Un-freeze counters */
10189d1ef6b2SChandu Babu N 	AXGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
10199d1ef6b2SChandu Babu N }
10209d1ef6b2SChandu Babu N 
10219d1ef6b2SChandu Babu N static int
10229d1ef6b2SChandu Babu N axgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
10239d1ef6b2SChandu Babu N 		     unsigned int n)
10249d1ef6b2SChandu Babu N {
10259d1ef6b2SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
10269d1ef6b2SChandu Babu N 	unsigned int i;
10279d1ef6b2SChandu Babu N 
102893041fd5SChengwen Feng 	if (n < AXGBE_XSTATS_COUNT)
102993041fd5SChengwen Feng 		return AXGBE_XSTATS_COUNT;
10309d1ef6b2SChandu Babu N 
10319d1ef6b2SChandu Babu N 	axgbe_read_mmc_stats(pdata);
10329d1ef6b2SChandu Babu N 
103393041fd5SChengwen Feng 	for (i = 0; i < AXGBE_XSTATS_COUNT; i++) {
10349d1ef6b2SChandu Babu N 		stats[i].id = i;
10359d1ef6b2SChandu Babu N 		stats[i].value = *(u64 *)((uint8_t *)&pdata->mmc_stats +
10369d1ef6b2SChandu Babu N 				axgbe_xstats_strings[i].offset);
10379d1ef6b2SChandu Babu N 	}
10389d1ef6b2SChandu Babu N 
103993041fd5SChengwen Feng 	return AXGBE_XSTATS_COUNT;
10409d1ef6b2SChandu Babu N }
10419d1ef6b2SChandu Babu N 
10429d1ef6b2SChandu Babu N static int
10439d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
10449d1ef6b2SChandu Babu N 			   struct rte_eth_xstat_name *xstats_names,
10459d1ef6b2SChandu Babu N 			   unsigned int n)
10469d1ef6b2SChandu Babu N {
10479d1ef6b2SChandu Babu N 	unsigned int i;
10489d1ef6b2SChandu Babu N 
10499d1ef6b2SChandu Babu N 	if (n >= AXGBE_XSTATS_COUNT && xstats_names) {
10509d1ef6b2SChandu Babu N 		for (i = 0; i < AXGBE_XSTATS_COUNT; ++i) {
10519d1ef6b2SChandu Babu N 			snprintf(xstats_names[i].name,
10529d1ef6b2SChandu Babu N 				 RTE_ETH_XSTATS_NAME_SIZE, "%s",
10539d1ef6b2SChandu Babu N 				 axgbe_xstats_strings[i].name);
10549d1ef6b2SChandu Babu N 		}
10559d1ef6b2SChandu Babu N 	}
10569d1ef6b2SChandu Babu N 
10579d1ef6b2SChandu Babu N 	return AXGBE_XSTATS_COUNT;
10589d1ef6b2SChandu Babu N }
10599d1ef6b2SChandu Babu N 
10609d1ef6b2SChandu Babu N static int
10619d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
10629d1ef6b2SChandu Babu N 			   uint64_t *values, unsigned int n)
10639d1ef6b2SChandu Babu N {
10649d1ef6b2SChandu Babu N 	unsigned int i;
10659d1ef6b2SChandu Babu N 	uint64_t values_copy[AXGBE_XSTATS_COUNT];
10669d1ef6b2SChandu Babu N 
10679d1ef6b2SChandu Babu N 	if (!ids) {
10689d1ef6b2SChandu Babu N 		struct axgbe_port *pdata = dev->data->dev_private;
10699d1ef6b2SChandu Babu N 
10709d1ef6b2SChandu Babu N 		if (n < AXGBE_XSTATS_COUNT)
10719d1ef6b2SChandu Babu N 			return AXGBE_XSTATS_COUNT;
10729d1ef6b2SChandu Babu N 
10739d1ef6b2SChandu Babu N 		axgbe_read_mmc_stats(pdata);
10749d1ef6b2SChandu Babu N 
10759d1ef6b2SChandu Babu N 		for (i = 0; i < AXGBE_XSTATS_COUNT; i++) {
10769d1ef6b2SChandu Babu N 			values[i] = *(u64 *)((uint8_t *)&pdata->mmc_stats +
10779d1ef6b2SChandu Babu N 					axgbe_xstats_strings[i].offset);
10789d1ef6b2SChandu Babu N 		}
10799d1ef6b2SChandu Babu N 
10809d1ef6b2SChandu Babu N 		return i;
10819d1ef6b2SChandu Babu N 	}
10829d1ef6b2SChandu Babu N 
10839d1ef6b2SChandu Babu N 	axgbe_dev_xstats_get_by_id(dev, NULL, values_copy, AXGBE_XSTATS_COUNT);
10849d1ef6b2SChandu Babu N 
10859d1ef6b2SChandu Babu N 	for (i = 0; i < n; i++) {
10869d1ef6b2SChandu Babu N 		if (ids[i] >= AXGBE_XSTATS_COUNT) {
1087e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(ERR, "id value isn't valid");
10889d1ef6b2SChandu Babu N 			return -1;
10899d1ef6b2SChandu Babu N 		}
10909d1ef6b2SChandu Babu N 		values[i] = values_copy[ids[i]];
10919d1ef6b2SChandu Babu N 	}
10929d1ef6b2SChandu Babu N 	return n;
10939d1ef6b2SChandu Babu N }
10949d1ef6b2SChandu Babu N 
10959d1ef6b2SChandu Babu N static int
10969d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
10979d1ef6b2SChandu Babu N 				 const uint64_t *ids,
10988c9f976fSAndrew Rybchenko 				 struct rte_eth_xstat_name *xstats_names,
10999d1ef6b2SChandu Babu N 				 unsigned int size)
11009d1ef6b2SChandu Babu N {
11019d1ef6b2SChandu Babu N 	struct rte_eth_xstat_name xstats_names_copy[AXGBE_XSTATS_COUNT];
11029d1ef6b2SChandu Babu N 	unsigned int i;
11039d1ef6b2SChandu Babu N 
11049d1ef6b2SChandu Babu N 	if (!ids)
11059d1ef6b2SChandu Babu N 		return axgbe_dev_xstats_get_names(dev, xstats_names, size);
11069d1ef6b2SChandu Babu N 
11079d1ef6b2SChandu Babu N 	axgbe_dev_xstats_get_names(dev, xstats_names_copy, size);
11089d1ef6b2SChandu Babu N 
11099d1ef6b2SChandu Babu N 	for (i = 0; i < size; i++) {
11109d1ef6b2SChandu Babu N 		if (ids[i] >= AXGBE_XSTATS_COUNT) {
1111e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(ERR, "id value isn't valid");
11129d1ef6b2SChandu Babu N 			return -1;
11139d1ef6b2SChandu Babu N 		}
11149d1ef6b2SChandu Babu N 		strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
11159d1ef6b2SChandu Babu N 	}
11169d1ef6b2SChandu Babu N 	return size;
11179d1ef6b2SChandu Babu N }
11189d1ef6b2SChandu Babu N 
11199d1ef6b2SChandu Babu N static int
11209d1ef6b2SChandu Babu N axgbe_dev_xstats_reset(struct rte_eth_dev *dev)
11219d1ef6b2SChandu Babu N {
11229d1ef6b2SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
11239d1ef6b2SChandu Babu N 	struct axgbe_mmc_stats *stats = &pdata->mmc_stats;
11249d1ef6b2SChandu Babu N 
11259d1ef6b2SChandu Babu N 	/* MMC registers are configured for reset on read */
11269d1ef6b2SChandu Babu N 	axgbe_read_mmc_stats(pdata);
11279d1ef6b2SChandu Babu N 
11289d1ef6b2SChandu Babu N 	/* Reset stats */
11299d1ef6b2SChandu Babu N 	memset(stats, 0, sizeof(*stats));
11309d1ef6b2SChandu Babu N 
11319d1ef6b2SChandu Babu N 	return 0;
11329d1ef6b2SChandu Babu N }
11339d1ef6b2SChandu Babu N 
11343e730511SRavi Kumar static int
11353e730511SRavi Kumar axgbe_dev_stats_get(struct rte_eth_dev *dev,
11363e730511SRavi Kumar 		    struct rte_eth_stats *stats)
11373e730511SRavi Kumar {
11383e730511SRavi Kumar 	struct axgbe_rx_queue *rxq;
11393e730511SRavi Kumar 	struct axgbe_tx_queue *txq;
11409d1ef6b2SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
11419d1ef6b2SChandu Babu N 	struct axgbe_mmc_stats *mmc_stats = &pdata->mmc_stats;
11423e730511SRavi Kumar 	unsigned int i;
11433e730511SRavi Kumar 
11449d1ef6b2SChandu Babu N 	axgbe_read_mmc_stats(pdata);
11459d1ef6b2SChandu Babu N 
11469d1ef6b2SChandu Babu N 	stats->imissed = mmc_stats->rxfifooverflow;
11479d1ef6b2SChandu Babu N 
11483e730511SRavi Kumar 	for (i = 0; i < dev->data->nb_rx_queues; i++) {
11493e730511SRavi Kumar 		rxq = dev->data->rx_queues[i];
1150bf403cfeSSelwin Sebastian 		if (rxq) {
11513e730511SRavi Kumar 			stats->q_ipackets[i] = rxq->pkts;
11523e730511SRavi Kumar 			stats->ipackets += rxq->pkts;
11533e730511SRavi Kumar 			stats->q_ibytes[i] = rxq->bytes;
11543e730511SRavi Kumar 			stats->ibytes += rxq->bytes;
11559d1ef6b2SChandu Babu N 			stats->rx_nombuf += rxq->rx_mbuf_alloc_failed;
1156bf403cfeSSelwin Sebastian 			stats->q_errors[i] = rxq->errors
1157bf403cfeSSelwin Sebastian 				+ rxq->rx_mbuf_alloc_failed;
11589d1ef6b2SChandu Babu N 			stats->ierrors += rxq->errors;
1159bf403cfeSSelwin Sebastian 		} else {
1160e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "Rx queue not setup for port %d",
1161bf403cfeSSelwin Sebastian 					dev->data->port_id);
1162bf403cfeSSelwin Sebastian 		}
11633e730511SRavi Kumar 	}
11649d1ef6b2SChandu Babu N 
11653e730511SRavi Kumar 	for (i = 0; i < dev->data->nb_tx_queues; i++) {
11663e730511SRavi Kumar 		txq = dev->data->tx_queues[i];
1167bf403cfeSSelwin Sebastian 		if (txq) {
11683e730511SRavi Kumar 			stats->q_opackets[i] = txq->pkts;
11693e730511SRavi Kumar 			stats->opackets += txq->pkts;
11703e730511SRavi Kumar 			stats->q_obytes[i] = txq->bytes;
11713e730511SRavi Kumar 			stats->obytes += txq->bytes;
11729d1ef6b2SChandu Babu N 			stats->oerrors += txq->errors;
1173bf403cfeSSelwin Sebastian 		} else {
1174e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "Tx queue not setup for port %d",
1175bf403cfeSSelwin Sebastian 					dev->data->port_id);
1176bf403cfeSSelwin Sebastian 		}
11773e730511SRavi Kumar 	}
11783e730511SRavi Kumar 
11793e730511SRavi Kumar 	return 0;
11803e730511SRavi Kumar }
11813e730511SRavi Kumar 
11829970a9adSIgor Romanov static int
11833e730511SRavi Kumar axgbe_dev_stats_reset(struct rte_eth_dev *dev)
11843e730511SRavi Kumar {
11853e730511SRavi Kumar 	struct axgbe_rx_queue *rxq;
11863e730511SRavi Kumar 	struct axgbe_tx_queue *txq;
11873e730511SRavi Kumar 	unsigned int i;
11883e730511SRavi Kumar 
11893e730511SRavi Kumar 	for (i = 0; i < dev->data->nb_rx_queues; i++) {
11903e730511SRavi Kumar 		rxq = dev->data->rx_queues[i];
1191bf403cfeSSelwin Sebastian 		if (rxq) {
11923e730511SRavi Kumar 			rxq->pkts = 0;
11933e730511SRavi Kumar 			rxq->bytes = 0;
11943e730511SRavi Kumar 			rxq->errors = 0;
11959d1ef6b2SChandu Babu N 			rxq->rx_mbuf_alloc_failed = 0;
1196bf403cfeSSelwin Sebastian 		} else {
1197e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "Rx queue not setup for port %d",
1198bf403cfeSSelwin Sebastian 					dev->data->port_id);
1199bf403cfeSSelwin Sebastian 		}
12003e730511SRavi Kumar 	}
12013e730511SRavi Kumar 	for (i = 0; i < dev->data->nb_tx_queues; i++) {
12023e730511SRavi Kumar 		txq = dev->data->tx_queues[i];
1203bf403cfeSSelwin Sebastian 		if (txq) {
12043e730511SRavi Kumar 			txq->pkts = 0;
12053e730511SRavi Kumar 			txq->bytes = 0;
12063e730511SRavi Kumar 			txq->errors = 0;
1207bf403cfeSSelwin Sebastian 		} else {
1208e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "Tx queue not setup for port %d",
1209bf403cfeSSelwin Sebastian 					dev->data->port_id);
1210bf403cfeSSelwin Sebastian 		}
12113e730511SRavi Kumar 	}
12129970a9adSIgor Romanov 
12139970a9adSIgor Romanov 	return 0;
12143e730511SRavi Kumar }
12153e730511SRavi Kumar 
1216bdad90d1SIvan Ilchenko static int
1217cd8c7c7cSFerruh Yigit axgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
12189e890103SRavi Kumar {
12199e890103SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
12209e890103SRavi Kumar 
12219e890103SRavi Kumar 	dev_info->max_rx_queues = pdata->rx_ring_count;
12229e890103SRavi Kumar 	dev_info->max_tx_queues = pdata->tx_ring_count;
12239e890103SRavi Kumar 	dev_info->min_rx_bufsize = AXGBE_RX_MIN_BUF_SIZE;
12249e890103SRavi Kumar 	dev_info->max_rx_pktlen = AXGBE_RX_MAX_BUF_SIZE;
122549a5e622SChandu Babu N 	dev_info->max_mac_addrs = pdata->hw_feat.addn_mac + 1;
1226e01d9b2eSChandu Babu N 	dev_info->max_hash_mac_addrs = pdata->hw_feat.hash_table_size;
1227295968d1SFerruh Yigit 	dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G;
12289e890103SRavi Kumar 
12299e890103SRavi Kumar 	dev_info->rx_offload_capa =
1230295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1231295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1232295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
1233295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1234295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_UDP_CKSUM  |
1235295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_TCP_CKSUM  |
1236295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_SCATTER	  |
1237295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_KEEP_CRC;
12389e890103SRavi Kumar 
12399e890103SRavi Kumar 	dev_info->tx_offload_capa =
1240295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1241295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
1242295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_IPV4_CKSUM  |
124393bffd8fSBhagyada Modali 		RTE_ETH_TX_OFFLOAD_MULTI_SEGS  |
1244*186f8e8cSJesna K E 		RTE_ETH_TX_OFFLOAD_TCP_TSO     |
1245295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_UDP_CKSUM   |
1246295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
12479e890103SRavi Kumar 
12489e890103SRavi Kumar 	if (pdata->hw_feat.rss) {
12499e890103SRavi Kumar 		dev_info->flow_type_rss_offloads = AXGBE_RSS_OFFLOAD;
12509e890103SRavi Kumar 		dev_info->reta_size = pdata->hw_feat.hash_table_size;
12519e890103SRavi Kumar 		dev_info->hash_key_size =  AXGBE_RSS_HASH_KEY_SIZE;
12529e890103SRavi Kumar 	}
12539e890103SRavi Kumar 
12549e890103SRavi Kumar 	dev_info->rx_desc_lim = rx_desc_lim;
12559e890103SRavi Kumar 	dev_info->tx_desc_lim = tx_desc_lim;
12569e890103SRavi Kumar 
12579e890103SRavi Kumar 	dev_info->default_rxconf = (struct rte_eth_rxconf) {
12589e890103SRavi Kumar 		.rx_free_thresh = AXGBE_RX_FREE_THRESH,
12599e890103SRavi Kumar 	};
12609e890103SRavi Kumar 
12619e890103SRavi Kumar 	dev_info->default_txconf = (struct rte_eth_txconf) {
12629e890103SRavi Kumar 		.tx_free_thresh = AXGBE_TX_FREE_THRESH,
12639e890103SRavi Kumar 	};
1264bdad90d1SIvan Ilchenko 
1265bdad90d1SIvan Ilchenko 	return 0;
12669e890103SRavi Kumar }
12679e890103SRavi Kumar 
1268cf97f33eSAmaranath Somalapuram static int
1269cf97f33eSAmaranath Somalapuram axgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1270cf97f33eSAmaranath Somalapuram {
1271cf97f33eSAmaranath Somalapuram 	struct axgbe_port *pdata = dev->data->dev_private;
1272cf97f33eSAmaranath Somalapuram 	struct xgbe_fc_info fc = pdata->fc;
1273cf97f33eSAmaranath Somalapuram 	unsigned int reg, reg_val = 0;
1274cf97f33eSAmaranath Somalapuram 
1275cf97f33eSAmaranath Somalapuram 	reg = MAC_Q0TFCR;
1276cf97f33eSAmaranath Somalapuram 	reg_val = AXGMAC_IOREAD(pdata, reg);
1277cf97f33eSAmaranath Somalapuram 	fc.low_water[0] =  AXGMAC_MTL_IOREAD_BITS(pdata, 0, MTL_Q_RQFCR, RFA);
1278cf97f33eSAmaranath Somalapuram 	fc.high_water[0] =  AXGMAC_MTL_IOREAD_BITS(pdata, 0, MTL_Q_RQFCR, RFD);
1279cf97f33eSAmaranath Somalapuram 	fc.pause_time[0] = AXGMAC_GET_BITS(reg_val, MAC_Q0TFCR, PT);
1280cf97f33eSAmaranath Somalapuram 	fc.autoneg = pdata->pause_autoneg;
1281cf97f33eSAmaranath Somalapuram 
1282cf97f33eSAmaranath Somalapuram 	if (pdata->rx_pause && pdata->tx_pause)
1283295968d1SFerruh Yigit 		fc.mode = RTE_ETH_FC_FULL;
1284cf97f33eSAmaranath Somalapuram 	else if (pdata->rx_pause)
1285295968d1SFerruh Yigit 		fc.mode = RTE_ETH_FC_RX_PAUSE;
1286cf97f33eSAmaranath Somalapuram 	else if (pdata->tx_pause)
1287295968d1SFerruh Yigit 		fc.mode = RTE_ETH_FC_TX_PAUSE;
1288cf97f33eSAmaranath Somalapuram 	else
1289295968d1SFerruh Yigit 		fc.mode = RTE_ETH_FC_NONE;
1290cf97f33eSAmaranath Somalapuram 
1291cf97f33eSAmaranath Somalapuram 	fc_conf->high_water =  (1024 + (fc.low_water[0] << 9)) / 1024;
1292cf97f33eSAmaranath Somalapuram 	fc_conf->low_water =  (1024 + (fc.high_water[0] << 9)) / 1024;
1293cf97f33eSAmaranath Somalapuram 	fc_conf->pause_time = fc.pause_time[0];
1294cf97f33eSAmaranath Somalapuram 	fc_conf->send_xon = fc.send_xon;
1295cf97f33eSAmaranath Somalapuram 	fc_conf->mode = fc.mode;
1296cf97f33eSAmaranath Somalapuram 
1297cf97f33eSAmaranath Somalapuram 	return 0;
1298cf97f33eSAmaranath Somalapuram }
1299cf97f33eSAmaranath Somalapuram 
1300cf97f33eSAmaranath Somalapuram static int
1301cf97f33eSAmaranath Somalapuram axgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1302cf97f33eSAmaranath Somalapuram {
1303cf97f33eSAmaranath Somalapuram 	struct axgbe_port *pdata = dev->data->dev_private;
1304cf97f33eSAmaranath Somalapuram 	struct xgbe_fc_info fc = pdata->fc;
1305cf97f33eSAmaranath Somalapuram 	unsigned int reg, reg_val = 0;
1306cf97f33eSAmaranath Somalapuram 	reg = MAC_Q0TFCR;
1307cf97f33eSAmaranath Somalapuram 
1308cf97f33eSAmaranath Somalapuram 	pdata->pause_autoneg = fc_conf->autoneg;
1309cf97f33eSAmaranath Somalapuram 	pdata->phy.pause_autoneg = pdata->pause_autoneg;
1310cf97f33eSAmaranath Somalapuram 	fc.send_xon = fc_conf->send_xon;
1311cf97f33eSAmaranath Somalapuram 	AXGMAC_MTL_IOWRITE_BITS(pdata, 0, MTL_Q_RQFCR, RFA,
1312cf97f33eSAmaranath Somalapuram 			AXGMAC_FLOW_CONTROL_VALUE(1024 * fc_conf->high_water));
1313cf97f33eSAmaranath Somalapuram 	AXGMAC_MTL_IOWRITE_BITS(pdata, 0, MTL_Q_RQFCR, RFD,
1314cf97f33eSAmaranath Somalapuram 			AXGMAC_FLOW_CONTROL_VALUE(1024 * fc_conf->low_water));
1315cf97f33eSAmaranath Somalapuram 	AXGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, fc_conf->pause_time);
1316cf97f33eSAmaranath Somalapuram 	AXGMAC_IOWRITE(pdata, reg, reg_val);
1317cf97f33eSAmaranath Somalapuram 	fc.mode = fc_conf->mode;
1318cf97f33eSAmaranath Somalapuram 
1319295968d1SFerruh Yigit 	if (fc.mode == RTE_ETH_FC_FULL) {
1320cf97f33eSAmaranath Somalapuram 		pdata->tx_pause = 1;
1321cf97f33eSAmaranath Somalapuram 		pdata->rx_pause = 1;
1322295968d1SFerruh Yigit 	} else if (fc.mode == RTE_ETH_FC_RX_PAUSE) {
1323cf97f33eSAmaranath Somalapuram 		pdata->tx_pause = 0;
1324cf97f33eSAmaranath Somalapuram 		pdata->rx_pause = 1;
1325295968d1SFerruh Yigit 	} else if (fc.mode == RTE_ETH_FC_TX_PAUSE) {
1326cf97f33eSAmaranath Somalapuram 		pdata->tx_pause = 1;
1327cf97f33eSAmaranath Somalapuram 		pdata->rx_pause = 0;
1328cf97f33eSAmaranath Somalapuram 	} else {
1329cf97f33eSAmaranath Somalapuram 		pdata->tx_pause = 0;
1330cf97f33eSAmaranath Somalapuram 		pdata->rx_pause = 0;
1331cf97f33eSAmaranath Somalapuram 	}
1332cf97f33eSAmaranath Somalapuram 
1333cf97f33eSAmaranath Somalapuram 	if (pdata->tx_pause != (unsigned int)pdata->phy.tx_pause)
1334cf97f33eSAmaranath Somalapuram 		pdata->hw_if.config_tx_flow_control(pdata);
1335cf97f33eSAmaranath Somalapuram 
1336cf97f33eSAmaranath Somalapuram 	if (pdata->rx_pause != (unsigned int)pdata->phy.rx_pause)
1337cf97f33eSAmaranath Somalapuram 		pdata->hw_if.config_rx_flow_control(pdata);
1338cf97f33eSAmaranath Somalapuram 
1339cf97f33eSAmaranath Somalapuram 	pdata->hw_if.config_flow_control(pdata);
1340cf97f33eSAmaranath Somalapuram 	pdata->phy.tx_pause = pdata->tx_pause;
1341cf97f33eSAmaranath Somalapuram 	pdata->phy.rx_pause = pdata->rx_pause;
1342cf97f33eSAmaranath Somalapuram 
1343cf97f33eSAmaranath Somalapuram 	return 0;
1344cf97f33eSAmaranath Somalapuram }
1345cf97f33eSAmaranath Somalapuram 
1346e0543d4eSAmaranath Somalapuram static int
1347e0543d4eSAmaranath Somalapuram axgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
1348e0543d4eSAmaranath Somalapuram 		struct rte_eth_pfc_conf *pfc_conf)
1349e0543d4eSAmaranath Somalapuram {
1350e0543d4eSAmaranath Somalapuram 	struct axgbe_port *pdata = dev->data->dev_private;
1351e0543d4eSAmaranath Somalapuram 	struct xgbe_fc_info fc = pdata->fc;
1352e0543d4eSAmaranath Somalapuram 	uint8_t tc_num;
1353e0543d4eSAmaranath Somalapuram 
1354e0543d4eSAmaranath Somalapuram 	tc_num = pdata->pfc_map[pfc_conf->priority];
1355e0543d4eSAmaranath Somalapuram 
1356e0543d4eSAmaranath Somalapuram 	if (pfc_conf->priority >= pdata->hw_feat.tc_cnt) {
1357f665790aSDavid Marchand 		PMD_INIT_LOG(ERR, "Max supported  traffic class: %d",
1358e0543d4eSAmaranath Somalapuram 				pdata->hw_feat.tc_cnt);
1359e0543d4eSAmaranath Somalapuram 	return -EINVAL;
1360e0543d4eSAmaranath Somalapuram 	}
1361e0543d4eSAmaranath Somalapuram 
1362e0543d4eSAmaranath Somalapuram 	pdata->pause_autoneg = pfc_conf->fc.autoneg;
1363e0543d4eSAmaranath Somalapuram 	pdata->phy.pause_autoneg = pdata->pause_autoneg;
1364e0543d4eSAmaranath Somalapuram 	fc.send_xon = pfc_conf->fc.send_xon;
1365e0543d4eSAmaranath Somalapuram 	AXGMAC_MTL_IOWRITE_BITS(pdata, tc_num, MTL_Q_RQFCR, RFA,
1366e0543d4eSAmaranath Somalapuram 		AXGMAC_FLOW_CONTROL_VALUE(1024 * pfc_conf->fc.high_water));
1367e0543d4eSAmaranath Somalapuram 	AXGMAC_MTL_IOWRITE_BITS(pdata, tc_num, MTL_Q_RQFCR, RFD,
1368e0543d4eSAmaranath Somalapuram 		AXGMAC_FLOW_CONTROL_VALUE(1024 * pfc_conf->fc.low_water));
1369e0543d4eSAmaranath Somalapuram 
1370e0543d4eSAmaranath Somalapuram 	switch (tc_num) {
1371e0543d4eSAmaranath Somalapuram 	case 0:
1372e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R,
1373e0543d4eSAmaranath Somalapuram 				PSTC0, pfc_conf->fc.pause_time);
1374e0543d4eSAmaranath Somalapuram 		break;
1375e0543d4eSAmaranath Somalapuram 	case 1:
1376e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R,
1377e0543d4eSAmaranath Somalapuram 				PSTC1, pfc_conf->fc.pause_time);
1378e0543d4eSAmaranath Somalapuram 		break;
1379e0543d4eSAmaranath Somalapuram 	case 2:
1380e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R,
1381e0543d4eSAmaranath Somalapuram 				PSTC2, pfc_conf->fc.pause_time);
1382e0543d4eSAmaranath Somalapuram 		break;
1383e0543d4eSAmaranath Somalapuram 	case 3:
1384e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R,
1385e0543d4eSAmaranath Somalapuram 				PSTC3, pfc_conf->fc.pause_time);
1386e0543d4eSAmaranath Somalapuram 		break;
1387e0543d4eSAmaranath Somalapuram 	case 4:
1388e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R,
1389e0543d4eSAmaranath Somalapuram 				PSTC4, pfc_conf->fc.pause_time);
1390e0543d4eSAmaranath Somalapuram 		break;
1391e0543d4eSAmaranath Somalapuram 	case 5:
1392e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R,
1393e0543d4eSAmaranath Somalapuram 				PSTC5, pfc_conf->fc.pause_time);
1394e0543d4eSAmaranath Somalapuram 		break;
1395e0543d4eSAmaranath Somalapuram 	case 7:
1396e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R,
1397e0543d4eSAmaranath Somalapuram 				PSTC6, pfc_conf->fc.pause_time);
1398e0543d4eSAmaranath Somalapuram 		break;
1399e0543d4eSAmaranath Somalapuram 	case 6:
1400e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R,
1401e0543d4eSAmaranath Somalapuram 				PSTC7, pfc_conf->fc.pause_time);
1402e0543d4eSAmaranath Somalapuram 		break;
1403e0543d4eSAmaranath Somalapuram 	}
1404e0543d4eSAmaranath Somalapuram 
1405e0543d4eSAmaranath Somalapuram 	fc.mode = pfc_conf->fc.mode;
1406e0543d4eSAmaranath Somalapuram 
1407295968d1SFerruh Yigit 	if (fc.mode == RTE_ETH_FC_FULL) {
1408e0543d4eSAmaranath Somalapuram 		pdata->tx_pause = 1;
1409e0543d4eSAmaranath Somalapuram 		pdata->rx_pause = 1;
1410e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 1);
1411295968d1SFerruh Yigit 	} else if (fc.mode == RTE_ETH_FC_RX_PAUSE) {
1412e0543d4eSAmaranath Somalapuram 		pdata->tx_pause = 0;
1413e0543d4eSAmaranath Somalapuram 		pdata->rx_pause = 1;
1414e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 1);
1415295968d1SFerruh Yigit 	} else if (fc.mode == RTE_ETH_FC_TX_PAUSE) {
1416e0543d4eSAmaranath Somalapuram 		pdata->tx_pause = 1;
1417e0543d4eSAmaranath Somalapuram 		pdata->rx_pause = 0;
1418e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0);
1419e0543d4eSAmaranath Somalapuram 	} else {
1420e0543d4eSAmaranath Somalapuram 		pdata->tx_pause = 0;
1421e0543d4eSAmaranath Somalapuram 		pdata->rx_pause = 0;
1422e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0);
1423e0543d4eSAmaranath Somalapuram 	}
1424e0543d4eSAmaranath Somalapuram 
1425e0543d4eSAmaranath Somalapuram 	if (pdata->tx_pause != (unsigned int)pdata->phy.tx_pause)
1426e0543d4eSAmaranath Somalapuram 		pdata->hw_if.config_tx_flow_control(pdata);
1427e0543d4eSAmaranath Somalapuram 
1428e0543d4eSAmaranath Somalapuram 	if (pdata->rx_pause != (unsigned int)pdata->phy.rx_pause)
1429e0543d4eSAmaranath Somalapuram 		pdata->hw_if.config_rx_flow_control(pdata);
1430e0543d4eSAmaranath Somalapuram 	pdata->hw_if.config_flow_control(pdata);
1431e0543d4eSAmaranath Somalapuram 	pdata->phy.tx_pause = pdata->tx_pause;
1432e0543d4eSAmaranath Somalapuram 	pdata->phy.rx_pause = pdata->rx_pause;
1433e0543d4eSAmaranath Somalapuram 
1434e0543d4eSAmaranath Somalapuram 	return 0;
1435e0543d4eSAmaranath Somalapuram }
1436e0543d4eSAmaranath Somalapuram 
14377aed95c9SAmaranath Somalapuram void
14387aed95c9SAmaranath Somalapuram axgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
14397aed95c9SAmaranath Somalapuram 	struct rte_eth_rxq_info *qinfo)
14407aed95c9SAmaranath Somalapuram {
14417aed95c9SAmaranath Somalapuram 	struct   axgbe_rx_queue *rxq;
14427aed95c9SAmaranath Somalapuram 
14437aed95c9SAmaranath Somalapuram 	rxq = dev->data->rx_queues[queue_id];
14447aed95c9SAmaranath Somalapuram 	qinfo->mp = rxq->mb_pool;
14457aed95c9SAmaranath Somalapuram 	qinfo->scattered_rx = dev->data->scattered_rx;
14467aed95c9SAmaranath Somalapuram 	qinfo->nb_desc = rxq->nb_desc;
14477aed95c9SAmaranath Somalapuram 	qinfo->conf.rx_free_thresh = rxq->free_thresh;
14487aed95c9SAmaranath Somalapuram }
14497aed95c9SAmaranath Somalapuram 
14507aed95c9SAmaranath Somalapuram void
14517aed95c9SAmaranath Somalapuram axgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
14527aed95c9SAmaranath Somalapuram 	struct rte_eth_txq_info *qinfo)
14537aed95c9SAmaranath Somalapuram {
14547aed95c9SAmaranath Somalapuram 	struct  axgbe_tx_queue *txq;
14557aed95c9SAmaranath Somalapuram 
14567aed95c9SAmaranath Somalapuram 	txq = dev->data->tx_queues[queue_id];
14577aed95c9SAmaranath Somalapuram 	qinfo->nb_desc = txq->nb_desc;
14587aed95c9SAmaranath Somalapuram 	qinfo->conf.tx_free_thresh = txq->free_thresh;
14597aed95c9SAmaranath Somalapuram }
1460410cf087SAmaranath Somalapuram const uint32_t *
1461ba6a168aSSivaramakrishnan Venkat axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
1462410cf087SAmaranath Somalapuram {
1463410cf087SAmaranath Somalapuram 	static const uint32_t ptypes[] = {
1464410cf087SAmaranath Somalapuram 		RTE_PTYPE_L2_ETHER,
1465410cf087SAmaranath Somalapuram 		RTE_PTYPE_L2_ETHER_TIMESYNC,
1466410cf087SAmaranath Somalapuram 		RTE_PTYPE_L2_ETHER_LLDP,
1467410cf087SAmaranath Somalapuram 		RTE_PTYPE_L2_ETHER_ARP,
1468410cf087SAmaranath Somalapuram 		RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1469410cf087SAmaranath Somalapuram 		RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
1470410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_FRAG,
1471410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_ICMP,
1472410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_NONFRAG,
1473410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_SCTP,
1474410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_TCP,
1475410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_UDP,
1476410cf087SAmaranath Somalapuram 		RTE_PTYPE_TUNNEL_GRENAT,
1477410cf087SAmaranath Somalapuram 		RTE_PTYPE_TUNNEL_IP,
1478410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L2_ETHER,
1479410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L2_ETHER_VLAN,
1480410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
1481410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
1482410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_FRAG,
1483410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_ICMP,
1484410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_NONFRAG,
1485410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_SCTP,
1486410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_TCP,
1487410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_UDP,
1488410cf087SAmaranath Somalapuram 	};
1489410cf087SAmaranath Somalapuram 
1490ba6a168aSSivaramakrishnan Venkat 	if (dev->rx_pkt_burst == axgbe_recv_pkts) {
1491ba6a168aSSivaramakrishnan Venkat 		*no_of_elements = RTE_DIM(ptypes);
1492410cf087SAmaranath Somalapuram 		return ptypes;
1493ba6a168aSSivaramakrishnan Venkat 	}
1494410cf087SAmaranath Somalapuram 	return NULL;
1495410cf087SAmaranath Somalapuram }
1496e0444948SSelwin Sebastian 
1497b58d8781SGirish Nandibasappa static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1498b58d8781SGirish Nandibasappa {
1499b58d8781SGirish Nandibasappa 	struct axgbe_port *pdata = dev->data->dev_private;
1500f7e04f57SFerruh Yigit 	unsigned int val;
1501f7e04f57SFerruh Yigit 
1502b58d8781SGirish Nandibasappa 	/* mtu setting is forbidden if port is start */
1503b58d8781SGirish Nandibasappa 	if (dev->data->dev_started) {
1504e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "port %d must be stopped before configuration",
1505b58d8781SGirish Nandibasappa 				dev->data->port_id);
1506b58d8781SGirish Nandibasappa 		return -EBUSY;
1507b58d8781SGirish Nandibasappa 	}
1508f7e04f57SFerruh Yigit 	val = mtu > RTE_ETHER_MTU ? 1 : 0;
1509b58d8781SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1510f7e04f57SFerruh Yigit 
1511b58d8781SGirish Nandibasappa 	return 0;
1512b58d8781SGirish Nandibasappa }
1513e0444948SSelwin Sebastian 
1514e0444948SSelwin Sebastian static void
1515e0444948SSelwin Sebastian axgbe_update_tstamp_time(struct axgbe_port *pdata,
1516e0444948SSelwin Sebastian 		unsigned int sec, unsigned int nsec, int addsub)
1517e0444948SSelwin Sebastian {
1518e0444948SSelwin Sebastian 	unsigned int count = 100;
1519e0444948SSelwin Sebastian 	uint32_t sub_val = 0;
1520e0444948SSelwin Sebastian 	uint32_t sub_val_sec = 0xFFFFFFFF;
1521e0444948SSelwin Sebastian 	uint32_t sub_val_nsec = 0x3B9ACA00;
1522e0444948SSelwin Sebastian 
1523e0444948SSelwin Sebastian 	if (addsub) {
1524e0444948SSelwin Sebastian 		if (sec)
1525e0444948SSelwin Sebastian 			sub_val = sub_val_sec - (sec - 1);
1526e0444948SSelwin Sebastian 		else
1527e0444948SSelwin Sebastian 			sub_val = sec;
1528e0444948SSelwin Sebastian 
1529e0444948SSelwin Sebastian 		AXGMAC_IOWRITE(pdata, MAC_STSUR, sub_val);
1530e0444948SSelwin Sebastian 		sub_val = sub_val_nsec - nsec;
1531e0444948SSelwin Sebastian 		AXGMAC_IOWRITE(pdata, MAC_STNUR, sub_val);
1532e0444948SSelwin Sebastian 		AXGMAC_IOWRITE_BITS(pdata, MAC_STNUR, ADDSUB, 1);
1533e0444948SSelwin Sebastian 	} else {
1534e0444948SSelwin Sebastian 		AXGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1535e0444948SSelwin Sebastian 		AXGMAC_IOWRITE_BITS(pdata, MAC_STNUR, ADDSUB, 0);
1536e0444948SSelwin Sebastian 		AXGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1537e0444948SSelwin Sebastian 	}
1538e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSUPDT, 1);
1539e0444948SSelwin Sebastian 	/* Wait for time update to complete */
1540e0444948SSelwin Sebastian 	while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSUPDT))
1541e0444948SSelwin Sebastian 		rte_delay_ms(1);
1542e0444948SSelwin Sebastian }
1543e0444948SSelwin Sebastian 
1544e0444948SSelwin Sebastian static inline uint64_t
1545e0444948SSelwin Sebastian div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
1546e0444948SSelwin Sebastian {
1547e0444948SSelwin Sebastian 	*remainder = dividend % divisor;
1548e0444948SSelwin Sebastian 	return dividend / divisor;
1549e0444948SSelwin Sebastian }
1550e0444948SSelwin Sebastian 
1551e0444948SSelwin Sebastian static inline uint64_t
1552e0444948SSelwin Sebastian div_u64(uint64_t dividend, uint32_t divisor)
1553e0444948SSelwin Sebastian {
1554e0444948SSelwin Sebastian 	uint32_t remainder;
1555e0444948SSelwin Sebastian 	return div_u64_rem(dividend, divisor, &remainder);
1556e0444948SSelwin Sebastian }
1557e0444948SSelwin Sebastian 
1558e0444948SSelwin Sebastian static int
1559e0444948SSelwin Sebastian axgbe_adjfreq(struct axgbe_port *pdata, int64_t delta)
1560e0444948SSelwin Sebastian {
1561e0444948SSelwin Sebastian 	uint64_t adjust;
1562e0444948SSelwin Sebastian 	uint32_t addend, diff;
1563e0444948SSelwin Sebastian 	unsigned int neg_adjust = 0;
1564e0444948SSelwin Sebastian 
1565e0444948SSelwin Sebastian 	if (delta < 0) {
1566e0444948SSelwin Sebastian 		neg_adjust = 1;
1567e0444948SSelwin Sebastian 		delta = -delta;
1568e0444948SSelwin Sebastian 	}
1569e0444948SSelwin Sebastian 	adjust = (uint64_t)pdata->tstamp_addend;
1570e0444948SSelwin Sebastian 	adjust *= delta;
1571e0444948SSelwin Sebastian 	diff = (uint32_t)div_u64(adjust, 1000000000UL);
1572e0444948SSelwin Sebastian 	addend = (neg_adjust) ? pdata->tstamp_addend - diff :
1573e0444948SSelwin Sebastian 				pdata->tstamp_addend + diff;
1574e0444948SSelwin Sebastian 	pdata->tstamp_addend = addend;
1575e0444948SSelwin Sebastian 	axgbe_update_tstamp_addend(pdata, addend);
1576e0444948SSelwin Sebastian 	return 0;
1577e0444948SSelwin Sebastian }
1578e0444948SSelwin Sebastian 
1579e0444948SSelwin Sebastian static int
1580e0444948SSelwin Sebastian axgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
1581e0444948SSelwin Sebastian {
1582e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1583e0444948SSelwin Sebastian 	struct timespec timestamp_delta;
1584e0444948SSelwin Sebastian 
1585e0444948SSelwin Sebastian 	axgbe_adjfreq(pdata, delta);
1586e0444948SSelwin Sebastian 	pdata->systime_tc.nsec += delta;
1587e0444948SSelwin Sebastian 
1588e0444948SSelwin Sebastian 	if (delta < 0) {
1589e0444948SSelwin Sebastian 		delta = -delta;
1590e0444948SSelwin Sebastian 		timestamp_delta = rte_ns_to_timespec(delta);
1591e0444948SSelwin Sebastian 		axgbe_update_tstamp_time(pdata, timestamp_delta.tv_sec,
1592e0444948SSelwin Sebastian 				timestamp_delta.tv_nsec, 1);
1593e0444948SSelwin Sebastian 	} else {
1594e0444948SSelwin Sebastian 		timestamp_delta = rte_ns_to_timespec(delta);
1595e0444948SSelwin Sebastian 		axgbe_update_tstamp_time(pdata, timestamp_delta.tv_sec,
1596e0444948SSelwin Sebastian 				timestamp_delta.tv_nsec, 0);
1597e0444948SSelwin Sebastian 	}
1598e0444948SSelwin Sebastian 	return 0;
1599e0444948SSelwin Sebastian }
1600e0444948SSelwin Sebastian 
1601e0444948SSelwin Sebastian static int
1602e0444948SSelwin Sebastian axgbe_timesync_read_time(struct rte_eth_dev *dev,
1603e0444948SSelwin Sebastian 		struct timespec *timestamp)
1604e0444948SSelwin Sebastian {
1605e0444948SSelwin Sebastian 	uint64_t nsec;
1606e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1607e0444948SSelwin Sebastian 
1608e0444948SSelwin Sebastian 	nsec = AXGMAC_IOREAD(pdata, MAC_STSR);
1609e0444948SSelwin Sebastian 	nsec *= NSEC_PER_SEC;
1610e0444948SSelwin Sebastian 	nsec += AXGMAC_IOREAD(pdata, MAC_STNR);
1611e0444948SSelwin Sebastian 	*timestamp = rte_ns_to_timespec(nsec);
1612e0444948SSelwin Sebastian 	return 0;
1613e0444948SSelwin Sebastian }
1614e0444948SSelwin Sebastian static int
1615e0444948SSelwin Sebastian axgbe_timesync_write_time(struct rte_eth_dev *dev,
1616e0444948SSelwin Sebastian 				    const struct timespec *timestamp)
1617e0444948SSelwin Sebastian {
1618e0444948SSelwin Sebastian 	unsigned int count = 100;
1619e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1620e0444948SSelwin Sebastian 
1621e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_STSUR, timestamp->tv_sec);
1622e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_STNUR, timestamp->tv_nsec);
1623e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSUPDT, 1);
1624e0444948SSelwin Sebastian 	/* Wait for time update to complete */
1625e0444948SSelwin Sebastian 	while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSUPDT))
1626e0444948SSelwin Sebastian 		rte_delay_ms(1);
1627e0444948SSelwin Sebastian 	if (!count)
1628e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Timed out update timestamp");
1629e0444948SSelwin Sebastian 	return 0;
1630e0444948SSelwin Sebastian }
1631e0444948SSelwin Sebastian 
1632e0444948SSelwin Sebastian static void
1633e0444948SSelwin Sebastian axgbe_update_tstamp_addend(struct axgbe_port *pdata,
1634e0444948SSelwin Sebastian 		uint32_t addend)
1635e0444948SSelwin Sebastian {
1636e0444948SSelwin Sebastian 	unsigned int count = 100;
1637e0444948SSelwin Sebastian 
1638e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1639e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1640e0444948SSelwin Sebastian 
1641e0444948SSelwin Sebastian 	/* Wait for addend update to complete */
1642e0444948SSelwin Sebastian 	while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1643e0444948SSelwin Sebastian 		rte_delay_ms(1);
1644e0444948SSelwin Sebastian 	if (!count)
1645e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Timed out updating timestamp addend register");
1646e0444948SSelwin Sebastian }
1647e0444948SSelwin Sebastian 
1648e0444948SSelwin Sebastian static void
1649e0444948SSelwin Sebastian axgbe_set_tstamp_time(struct axgbe_port *pdata, unsigned int sec,
1650e0444948SSelwin Sebastian 		unsigned int nsec)
1651e0444948SSelwin Sebastian {
1652e0444948SSelwin Sebastian 	unsigned int count = 100;
1653e0444948SSelwin Sebastian 
1654e0444948SSelwin Sebastian 	/*System Time Sec Update*/
1655e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1656e0444948SSelwin Sebastian 	/*System Time nanoSec Update*/
1657e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1658e0444948SSelwin Sebastian 	/*Initialize Timestamp*/
1659e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1660e0444948SSelwin Sebastian 
1661e0444948SSelwin Sebastian 	/* Wait for time update to complete */
1662e0444948SSelwin Sebastian 	while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1663e0444948SSelwin Sebastian 		rte_delay_ms(1);
1664e0444948SSelwin Sebastian 	if (!count)
1665e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Timed out initializing timestamp");
1666e0444948SSelwin Sebastian }
1667e0444948SSelwin Sebastian 
1668e0444948SSelwin Sebastian static int
1669e0444948SSelwin Sebastian axgbe_timesync_enable(struct rte_eth_dev *dev)
1670e0444948SSelwin Sebastian {
1671e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1672e0444948SSelwin Sebastian 	unsigned int mac_tscr = 0;
1673e0444948SSelwin Sebastian 	uint64_t dividend;
1674e0444948SSelwin Sebastian 	struct timespec timestamp;
1675e0444948SSelwin Sebastian 	uint64_t nsec;
1676e0444948SSelwin Sebastian 
1677e0444948SSelwin Sebastian 	/* Set one nano-second accuracy */
1678e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1679e0444948SSelwin Sebastian 
1680e0444948SSelwin Sebastian 	/* Set fine timestamp update */
1681e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1682e0444948SSelwin Sebastian 
1683e0444948SSelwin Sebastian 	/* Overwrite earlier timestamps */
1684e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1685e0444948SSelwin Sebastian 
1686e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1687e0444948SSelwin Sebastian 
1688e0444948SSelwin Sebastian 	/* Enabling processing of ptp over eth pkt */
1689e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1);
1690e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1);
1691e0444948SSelwin Sebastian 	/* Enable timestamp for all pkts*/
1692e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 1);
1693e0444948SSelwin Sebastian 
1694e0444948SSelwin Sebastian 	/* enabling timestamp */
1695e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1);
1696e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1697e0444948SSelwin Sebastian 
1698e0444948SSelwin Sebastian 	/* Exit if timestamping is not enabled */
1699e0444948SSelwin Sebastian 	if (!AXGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA)) {
1700e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "Exiting as timestamp is not enabled");
1701e0444948SSelwin Sebastian 		return 0;
1702e0444948SSelwin Sebastian 	}
1703e0444948SSelwin Sebastian 
1704e0444948SSelwin Sebastian 	/* Sub-second Increment Value*/
1705e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, AXGBE_TSTAMP_SSINC);
1706e0444948SSelwin Sebastian 	/* Sub-nanosecond Increment Value */
1707e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, AXGBE_TSTAMP_SNSINC);
1708e0444948SSelwin Sebastian 
1709e0444948SSelwin Sebastian 	pdata->ptpclk_rate = AXGBE_V2_PTP_CLOCK_FREQ;
1710e0444948SSelwin Sebastian 	dividend = 50000000;
1711e0444948SSelwin Sebastian 	dividend <<= 32;
1712e0444948SSelwin Sebastian 	pdata->tstamp_addend = div_u64(dividend, pdata->ptpclk_rate);
1713e0444948SSelwin Sebastian 
1714e0444948SSelwin Sebastian 	axgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1715e0444948SSelwin Sebastian 	axgbe_set_tstamp_time(pdata, 0, 0);
1716e0444948SSelwin Sebastian 
1717e0444948SSelwin Sebastian 	/* Initialize the timecounter */
1718e0444948SSelwin Sebastian 	memset(&pdata->systime_tc, 0, sizeof(struct rte_timecounter));
1719e0444948SSelwin Sebastian 
1720e0444948SSelwin Sebastian 	pdata->systime_tc.cc_mask = AXGBE_CYCLECOUNTER_MASK;
1721e0444948SSelwin Sebastian 	pdata->systime_tc.cc_shift = 0;
1722e0444948SSelwin Sebastian 	pdata->systime_tc.nsec_mask = 0;
1723e0444948SSelwin Sebastian 
1724e99981afSDavid Marchand 	PMD_DRV_LOG_LINE(DEBUG, "Initializing system time counter with realtime");
1725e0444948SSelwin Sebastian 
1726e0444948SSelwin Sebastian 	/* Updating the counter once with clock real time */
1727e0444948SSelwin Sebastian 	clock_gettime(CLOCK_REALTIME, &timestamp);
1728e0444948SSelwin Sebastian 	nsec = rte_timespec_to_ns(&timestamp);
1729e0444948SSelwin Sebastian 	nsec = rte_timecounter_update(&pdata->systime_tc, nsec);
1730e0444948SSelwin Sebastian 	axgbe_set_tstamp_time(pdata, timestamp.tv_sec, timestamp.tv_nsec);
1731e0444948SSelwin Sebastian 	return 0;
1732e0444948SSelwin Sebastian }
1733e0444948SSelwin Sebastian 
1734e0444948SSelwin Sebastian static int
1735e0444948SSelwin Sebastian axgbe_timesync_disable(struct rte_eth_dev *dev)
1736e0444948SSelwin Sebastian {
1737e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1738e0444948SSelwin Sebastian 	unsigned int mac_tscr = 0;
1739e0444948SSelwin Sebastian 
1740e0444948SSelwin Sebastian 	/*disable timestamp for all pkts*/
1741e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 0);
1742e0444948SSelwin Sebastian 	/*disable the addened register*/
1743e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 0);
1744e0444948SSelwin Sebastian 	/* disable timestamp update */
1745e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 0);
1746e0444948SSelwin Sebastian 	/*disable time stamp*/
1747e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 0);
1748e0444948SSelwin Sebastian 	return 0;
1749e0444948SSelwin Sebastian }
1750e0444948SSelwin Sebastian 
1751e0444948SSelwin Sebastian static int
1752e0444948SSelwin Sebastian axgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
1753e0444948SSelwin Sebastian 				struct timespec *timestamp, uint32_t flags)
1754e0444948SSelwin Sebastian {
1755e0444948SSelwin Sebastian 	uint64_t nsec = 0;
1756e0444948SSelwin Sebastian 	volatile union axgbe_rx_desc *desc;
1757e0444948SSelwin Sebastian 	uint16_t idx, pmt;
1758e0444948SSelwin Sebastian 	struct axgbe_rx_queue *rxq = *dev->data->rx_queues;
1759e0444948SSelwin Sebastian 
1760e0444948SSelwin Sebastian 	idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur);
1761e0444948SSelwin Sebastian 	desc = &rxq->desc[idx];
1762e0444948SSelwin Sebastian 
1763e0444948SSelwin Sebastian 	while (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN))
1764e0444948SSelwin Sebastian 		rte_delay_ms(1);
1765e0444948SSelwin Sebastian 	if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, CTXT)) {
1766e0444948SSelwin Sebastian 		if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_CONTEXT_DESC3, TSA) &&
1767e0444948SSelwin Sebastian 				!AXGMAC_GET_BITS_LE(desc->write.desc3,
1768e0444948SSelwin Sebastian 					RX_CONTEXT_DESC3, TSD)) {
1769e0444948SSelwin Sebastian 			pmt = AXGMAC_GET_BITS_LE(desc->write.desc3,
1770e0444948SSelwin Sebastian 					RX_CONTEXT_DESC3, PMT);
1771e0444948SSelwin Sebastian 			nsec = rte_le_to_cpu_32(desc->write.desc1);
1772e0444948SSelwin Sebastian 			nsec *= NSEC_PER_SEC;
1773e0444948SSelwin Sebastian 			nsec += rte_le_to_cpu_32(desc->write.desc0);
1774e0444948SSelwin Sebastian 			if (nsec != 0xffffffffffffffffULL) {
1775e0444948SSelwin Sebastian 				if (pmt == 0x01)
1776e0444948SSelwin Sebastian 					*timestamp = rte_ns_to_timespec(nsec);
1777e99981afSDavid Marchand 				PMD_DRV_LOG_LINE(DEBUG,
1778e99981afSDavid Marchand 					"flags = 0x%x nsec = %"PRIu64,
1779e0444948SSelwin Sebastian 					flags, nsec);
1780e0444948SSelwin Sebastian 			}
1781e0444948SSelwin Sebastian 		}
1782e0444948SSelwin Sebastian 	}
1783e0444948SSelwin Sebastian 
1784e0444948SSelwin Sebastian 	return 0;
1785e0444948SSelwin Sebastian }
1786e0444948SSelwin Sebastian 
1787e0444948SSelwin Sebastian static int
1788e0444948SSelwin Sebastian axgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
1789e0444948SSelwin Sebastian 				struct timespec *timestamp)
1790e0444948SSelwin Sebastian {
1791e0444948SSelwin Sebastian 	uint64_t nsec;
1792e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1793e0444948SSelwin Sebastian 	unsigned int tx_snr, tx_ssr;
1794e0444948SSelwin Sebastian 
1795e0444948SSelwin Sebastian 	rte_delay_us(5);
1796e0444948SSelwin Sebastian 	if (pdata->vdata->tx_tstamp_workaround) {
1797e0444948SSelwin Sebastian 		tx_snr = AXGMAC_IOREAD(pdata, MAC_TXSNR);
1798e0444948SSelwin Sebastian 		tx_ssr = AXGMAC_IOREAD(pdata, MAC_TXSSR);
1799e0444948SSelwin Sebastian 
1800e0444948SSelwin Sebastian 	} else {
1801e0444948SSelwin Sebastian 		tx_ssr = AXGMAC_IOREAD(pdata, MAC_TXSSR);
1802e0444948SSelwin Sebastian 		tx_snr = AXGMAC_IOREAD(pdata, MAC_TXSNR);
1803e0444948SSelwin Sebastian 	}
1804e0444948SSelwin Sebastian 	if (AXGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS)) {
1805e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(DEBUG, "Waiting for TXTSSTSMIS");
1806e0444948SSelwin Sebastian 		return 0;
1807e0444948SSelwin Sebastian 	}
1808e0444948SSelwin Sebastian 	nsec = tx_ssr;
1809e0444948SSelwin Sebastian 	nsec *= NSEC_PER_SEC;
1810e0444948SSelwin Sebastian 	nsec += tx_snr;
1811e99981afSDavid Marchand 	PMD_DRV_LOG_LINE(DEBUG, "nsec = %"PRIu64" tx_ssr = %d tx_snr = %d",
1812e0444948SSelwin Sebastian 			nsec, tx_ssr, tx_snr);
1813e0444948SSelwin Sebastian 	*timestamp = rte_ns_to_timespec(nsec);
1814e0444948SSelwin Sebastian 	return 0;
1815e0444948SSelwin Sebastian }
1816e0444948SSelwin Sebastian 
181786578516SGirish Nandibasappa static int
181886578516SGirish Nandibasappa axgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on)
181986578516SGirish Nandibasappa {
182086578516SGirish Nandibasappa 	struct axgbe_port *pdata = dev->data->dev_private;
182186578516SGirish Nandibasappa 	unsigned long vid_bit, vid_idx;
182286578516SGirish Nandibasappa 
182386578516SGirish Nandibasappa 	vid_bit = VLAN_TABLE_BIT(vid);
182486578516SGirish Nandibasappa 	vid_idx = VLAN_TABLE_IDX(vid);
182586578516SGirish Nandibasappa 
182686578516SGirish Nandibasappa 	if (on) {
1827e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(DEBUG, "Set VLAN vid=%d for device = %s",
182886578516SGirish Nandibasappa 			    vid, pdata->eth_dev->device->name);
182986578516SGirish Nandibasappa 		pdata->active_vlans[vid_idx] |= vid_bit;
183086578516SGirish Nandibasappa 	} else {
1831e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(DEBUG, "Reset VLAN vid=%d for device = %s",
183286578516SGirish Nandibasappa 			    vid, pdata->eth_dev->device->name);
183386578516SGirish Nandibasappa 		pdata->active_vlans[vid_idx] &= ~vid_bit;
183486578516SGirish Nandibasappa 	}
183586578516SGirish Nandibasappa 	pdata->hw_if.update_vlan_hash_table(pdata);
183686578516SGirish Nandibasappa 	return 0;
183786578516SGirish Nandibasappa }
183886578516SGirish Nandibasappa 
183986578516SGirish Nandibasappa static int
184086578516SGirish Nandibasappa axgbe_vlan_tpid_set(struct rte_eth_dev *dev,
184186578516SGirish Nandibasappa 		    enum rte_vlan_type vlan_type,
184286578516SGirish Nandibasappa 		    uint16_t tpid)
184386578516SGirish Nandibasappa {
184486578516SGirish Nandibasappa 	struct axgbe_port *pdata = dev->data->dev_private;
184586578516SGirish Nandibasappa 	uint32_t reg = 0;
184686578516SGirish Nandibasappa 	uint32_t qinq = 0;
184786578516SGirish Nandibasappa 
184886578516SGirish Nandibasappa 	qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP);
1849e99981afSDavid Marchand 	PMD_DRV_LOG_LINE(DEBUG, "EDVLP: qinq = 0x%x", qinq);
185086578516SGirish Nandibasappa 
185186578516SGirish Nandibasappa 	switch (vlan_type) {
1852295968d1SFerruh Yigit 	case RTE_ETH_VLAN_TYPE_INNER:
1853e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(DEBUG, "RTE_ETH_VLAN_TYPE_INNER");
185486578516SGirish Nandibasappa 		if (qinq) {
185586578516SGirish Nandibasappa 			if (tpid != 0x8100 && tpid != 0x88a8)
1856e99981afSDavid Marchand 				PMD_DRV_LOG_LINE(ERR,
1857e99981afSDavid Marchand 					    "tag supported 0x8100/0x88A8");
1858e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "qinq with inner tag");
185986578516SGirish Nandibasappa 
186086578516SGirish Nandibasappa 			/*Enable Inner VLAN Tag */
186186578516SGirish Nandibasappa 			AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERIVLT, 1);
186286578516SGirish Nandibasappa 			reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, ERIVLT);
1863e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "bit ERIVLT = 0x%x", reg);
186486578516SGirish Nandibasappa 
186586578516SGirish Nandibasappa 		} else {
1866e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(ERR,
1867e99981afSDavid Marchand 				    "Inner type not supported in single tag");
186886578516SGirish Nandibasappa 		}
186986578516SGirish Nandibasappa 		break;
1870295968d1SFerruh Yigit 	case RTE_ETH_VLAN_TYPE_OUTER:
1871e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(DEBUG, "RTE_ETH_VLAN_TYPE_OUTER");
187286578516SGirish Nandibasappa 		if (qinq) {
1873e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "double tagging is enabled");
187486578516SGirish Nandibasappa 			/*Enable outer VLAN tag*/
187586578516SGirish Nandibasappa 			AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERIVLT, 0);
187686578516SGirish Nandibasappa 			reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, ERIVLT);
1877e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "bit ERIVLT = 0x%x", reg);
187886578516SGirish Nandibasappa 
187986578516SGirish Nandibasappa 			AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 1);
188086578516SGirish Nandibasappa 			reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANIR, CSVL);
1881e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "bit CSVL = 0x%x", reg);
188286578516SGirish Nandibasappa 		} else {
188386578516SGirish Nandibasappa 			if (tpid != 0x8100 && tpid != 0x88a8)
1884e99981afSDavid Marchand 				PMD_DRV_LOG_LINE(ERR,
1885e99981afSDavid Marchand 					    "tag supported 0x8100/0x88A8");
188686578516SGirish Nandibasappa 		}
188786578516SGirish Nandibasappa 		break;
1888295968d1SFerruh Yigit 	case RTE_ETH_VLAN_TYPE_MAX:
1889e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "RTE_ETH_VLAN_TYPE_MAX");
189086578516SGirish Nandibasappa 		break;
1891295968d1SFerruh Yigit 	case RTE_ETH_VLAN_TYPE_UNKNOWN:
1892e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "RTE_ETH_VLAN_TYPE_UNKNOWN");
189386578516SGirish Nandibasappa 		break;
189486578516SGirish Nandibasappa 	}
189586578516SGirish Nandibasappa 	return 0;
189686578516SGirish Nandibasappa }
189786578516SGirish Nandibasappa 
189886578516SGirish Nandibasappa static void axgbe_vlan_extend_enable(struct axgbe_port *pdata)
189986578516SGirish Nandibasappa {
190086578516SGirish Nandibasappa 	int qinq = 0;
190186578516SGirish Nandibasappa 
190286578516SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EDVLP, 1);
190386578516SGirish Nandibasappa 	qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP);
1904e99981afSDavid Marchand 	PMD_DRV_LOG_LINE(DEBUG, "vlan double tag enabled EDVLP:qinq=0x%x", qinq);
190586578516SGirish Nandibasappa }
190686578516SGirish Nandibasappa 
190786578516SGirish Nandibasappa static void axgbe_vlan_extend_disable(struct axgbe_port *pdata)
190886578516SGirish Nandibasappa {
190986578516SGirish Nandibasappa 	int qinq = 0;
191086578516SGirish Nandibasappa 
191186578516SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EDVLP, 0);
191286578516SGirish Nandibasappa 	qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP);
1913e99981afSDavid Marchand 	PMD_DRV_LOG_LINE(DEBUG, "vlan double tag disable EDVLP:qinq=0x%x", qinq);
191486578516SGirish Nandibasappa }
191586578516SGirish Nandibasappa 
191686578516SGirish Nandibasappa static int
191786578516SGirish Nandibasappa axgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
191886578516SGirish Nandibasappa {
191986578516SGirish Nandibasappa 	struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
192086578516SGirish Nandibasappa 	struct axgbe_port *pdata = dev->data->dev_private;
192186578516SGirish Nandibasappa 
192286578516SGirish Nandibasappa 	/* Indicate that VLAN Tx CTAGs come from context descriptors */
192386578516SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
192486578516SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
192586578516SGirish Nandibasappa 
1926295968d1SFerruh Yigit 	if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1927295968d1SFerruh Yigit 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
1928e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "Strip ON for device = %s",
192986578516SGirish Nandibasappa 				    pdata->eth_dev->device->name);
193086578516SGirish Nandibasappa 			pdata->hw_if.enable_rx_vlan_stripping(pdata);
193186578516SGirish Nandibasappa 		} else {
1932e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "Strip OFF for device = %s",
193386578516SGirish Nandibasappa 				    pdata->eth_dev->device->name);
193486578516SGirish Nandibasappa 			pdata->hw_if.disable_rx_vlan_stripping(pdata);
193586578516SGirish Nandibasappa 		}
193686578516SGirish Nandibasappa 	}
1937295968d1SFerruh Yigit 	if (mask & RTE_ETH_VLAN_FILTER_MASK) {
1938295968d1SFerruh Yigit 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
1939e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "Filter ON for device = %s",
194086578516SGirish Nandibasappa 				    pdata->eth_dev->device->name);
194186578516SGirish Nandibasappa 			pdata->hw_if.enable_rx_vlan_filtering(pdata);
194286578516SGirish Nandibasappa 		} else {
1943e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "Filter OFF for device = %s",
194486578516SGirish Nandibasappa 				    pdata->eth_dev->device->name);
194586578516SGirish Nandibasappa 			pdata->hw_if.disable_rx_vlan_filtering(pdata);
194686578516SGirish Nandibasappa 		}
194786578516SGirish Nandibasappa 	}
1948295968d1SFerruh Yigit 	if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
1949295968d1SFerruh Yigit 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
1950e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "enabling vlan extended mode");
195186578516SGirish Nandibasappa 			axgbe_vlan_extend_enable(pdata);
195286578516SGirish Nandibasappa 			/* Set global registers with default ethertype*/
1953295968d1SFerruh Yigit 			axgbe_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
195486578516SGirish Nandibasappa 					    RTE_ETHER_TYPE_VLAN);
1955295968d1SFerruh Yigit 			axgbe_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
195686578516SGirish Nandibasappa 					    RTE_ETHER_TYPE_VLAN);
195786578516SGirish Nandibasappa 		} else {
1958e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(DEBUG, "disabling vlan extended mode");
195986578516SGirish Nandibasappa 			axgbe_vlan_extend_disable(pdata);
196086578516SGirish Nandibasappa 		}
196186578516SGirish Nandibasappa 	}
196286578516SGirish Nandibasappa 	return 0;
196386578516SGirish Nandibasappa }
196486578516SGirish Nandibasappa 
1965572890efSRavi Kumar static void axgbe_get_all_hw_features(struct axgbe_port *pdata)
1966572890efSRavi Kumar {
196786578516SGirish Nandibasappa 	unsigned int mac_hfr0, mac_hfr1, mac_hfr2, mac_hfr3;
1968572890efSRavi Kumar 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
1969572890efSRavi Kumar 
1970572890efSRavi Kumar 	mac_hfr0 = AXGMAC_IOREAD(pdata, MAC_HWF0R);
1971572890efSRavi Kumar 	mac_hfr1 = AXGMAC_IOREAD(pdata, MAC_HWF1R);
1972572890efSRavi Kumar 	mac_hfr2 = AXGMAC_IOREAD(pdata, MAC_HWF2R);
197386578516SGirish Nandibasappa 	mac_hfr3 = AXGMAC_IOREAD(pdata, MAC_HWF3R);
1974572890efSRavi Kumar 
1975572890efSRavi Kumar 	memset(hw_feat, 0, sizeof(*hw_feat));
1976572890efSRavi Kumar 
1977572890efSRavi Kumar 	hw_feat->version = AXGMAC_IOREAD(pdata, MAC_VR);
1978572890efSRavi Kumar 
1979572890efSRavi Kumar 	/* Hardware feature register 0 */
1980572890efSRavi Kumar 	hw_feat->gmii        = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, GMIISEL);
1981572890efSRavi Kumar 	hw_feat->vlhash      = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, VLHASH);
1982572890efSRavi Kumar 	hw_feat->sma         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SMASEL);
1983572890efSRavi Kumar 	hw_feat->rwk         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RWKSEL);
1984572890efSRavi Kumar 	hw_feat->mgk         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MGKSEL);
1985572890efSRavi Kumar 	hw_feat->mmc         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MMCSEL);
1986572890efSRavi Kumar 	hw_feat->aoe         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, ARPOFFSEL);
1987572890efSRavi Kumar 	hw_feat->ts          = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSEL);
1988572890efSRavi Kumar 	hw_feat->eee         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, EEESEL);
1989572890efSRavi Kumar 	hw_feat->tx_coe      = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TXCOESEL);
1990572890efSRavi Kumar 	hw_feat->rx_coe      = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RXCOESEL);
1991572890efSRavi Kumar 	hw_feat->addn_mac    = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R,
1992572890efSRavi Kumar 					      ADDMACADRSEL);
1993572890efSRavi Kumar 	hw_feat->ts_src      = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSTSSEL);
1994572890efSRavi Kumar 	hw_feat->sa_vlan_ins = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SAVLANINS);
1995572890efSRavi Kumar 
1996572890efSRavi Kumar 	/* Hardware feature register 1 */
1997572890efSRavi Kumar 	hw_feat->rx_fifo_size  = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R,
1998572890efSRavi Kumar 						RXFIFOSIZE);
1999572890efSRavi Kumar 	hw_feat->tx_fifo_size  = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R,
2000572890efSRavi Kumar 						TXFIFOSIZE);
2001572890efSRavi Kumar 	hw_feat->adv_ts_hi     = AXGMAC_GET_BITS(mac_hfr1,
2002572890efSRavi Kumar 						 MAC_HWF1R, ADVTHWORD);
2003572890efSRavi Kumar 	hw_feat->dma_width     = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, ADDR64);
2004572890efSRavi Kumar 	hw_feat->dcb           = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DCBEN);
2005572890efSRavi Kumar 	hw_feat->sph           = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, SPHEN);
2006572890efSRavi Kumar 	hw_feat->tso           = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, TSOEN);
2007572890efSRavi Kumar 	hw_feat->dma_debug     = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DBGMEMA);
2008572890efSRavi Kumar 	hw_feat->rss           = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, RSSEN);
2009572890efSRavi Kumar 	hw_feat->tc_cnt	       = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, NUMTC);
2010572890efSRavi Kumar 	hw_feat->hash_table_size = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R,
2011572890efSRavi Kumar 						  HASHTBLSZ);
2012572890efSRavi Kumar 	hw_feat->l3l4_filter_num = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R,
2013572890efSRavi Kumar 						  L3L4FNUM);
2014572890efSRavi Kumar 
2015572890efSRavi Kumar 	/* Hardware feature register 2 */
2016572890efSRavi Kumar 	hw_feat->rx_q_cnt     = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXQCNT);
2017572890efSRavi Kumar 	hw_feat->tx_q_cnt     = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXQCNT);
2018572890efSRavi Kumar 	hw_feat->rx_ch_cnt    = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXCHCNT);
2019572890efSRavi Kumar 	hw_feat->tx_ch_cnt    = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXCHCNT);
2020572890efSRavi Kumar 	hw_feat->pps_out_num  = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, PPSOUTNUM);
2021572890efSRavi Kumar 	hw_feat->aux_snap_num = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R,
2022572890efSRavi Kumar 						AUXSNAPNUM);
2023572890efSRavi Kumar 
202486578516SGirish Nandibasappa 	/* Hardware feature register 3 */
202586578516SGirish Nandibasappa 	hw_feat->tx_q_vlan_tag_ins  = AXGMAC_GET_BITS(mac_hfr3,
202686578516SGirish Nandibasappa 						      MAC_HWF3R, CBTISEL);
202786578516SGirish Nandibasappa 	hw_feat->no_of_vlan_extn    = AXGMAC_GET_BITS(mac_hfr3,
202886578516SGirish Nandibasappa 						      MAC_HWF3R, NRVF);
202986578516SGirish Nandibasappa 
2030572890efSRavi Kumar 	/* Translate the Hash Table size into actual number */
2031572890efSRavi Kumar 	switch (hw_feat->hash_table_size) {
2032572890efSRavi Kumar 	case 0:
2033572890efSRavi Kumar 		break;
2034572890efSRavi Kumar 	case 1:
2035572890efSRavi Kumar 		hw_feat->hash_table_size = 64;
2036572890efSRavi Kumar 		break;
2037572890efSRavi Kumar 	case 2:
2038572890efSRavi Kumar 		hw_feat->hash_table_size = 128;
2039572890efSRavi Kumar 		break;
2040572890efSRavi Kumar 	case 3:
2041572890efSRavi Kumar 		hw_feat->hash_table_size = 256;
2042572890efSRavi Kumar 		break;
2043572890efSRavi Kumar 	}
2044572890efSRavi Kumar 
2045572890efSRavi Kumar 	/* Translate the address width setting into actual number */
2046572890efSRavi Kumar 	switch (hw_feat->dma_width) {
2047572890efSRavi Kumar 	case 0:
2048572890efSRavi Kumar 		hw_feat->dma_width = 32;
2049572890efSRavi Kumar 		break;
2050572890efSRavi Kumar 	case 1:
2051572890efSRavi Kumar 		hw_feat->dma_width = 40;
2052572890efSRavi Kumar 		break;
2053572890efSRavi Kumar 	case 2:
2054572890efSRavi Kumar 		hw_feat->dma_width = 48;
2055572890efSRavi Kumar 		break;
2056572890efSRavi Kumar 	default:
2057572890efSRavi Kumar 		hw_feat->dma_width = 32;
2058572890efSRavi Kumar 	}
2059572890efSRavi Kumar 
2060572890efSRavi Kumar 	/* The Queue, Channel and TC counts are zero based so increment them
2061572890efSRavi Kumar 	 * to get the actual number
2062572890efSRavi Kumar 	 */
2063572890efSRavi Kumar 	hw_feat->rx_q_cnt++;
2064572890efSRavi Kumar 	hw_feat->tx_q_cnt++;
2065572890efSRavi Kumar 	hw_feat->rx_ch_cnt++;
2066572890efSRavi Kumar 	hw_feat->tx_ch_cnt++;
2067572890efSRavi Kumar 	hw_feat->tc_cnt++;
2068572890efSRavi Kumar 
2069572890efSRavi Kumar 	/* Translate the fifo sizes into actual numbers */
2070572890efSRavi Kumar 	hw_feat->rx_fifo_size = 1 << (hw_feat->rx_fifo_size + 7);
2071572890efSRavi Kumar 	hw_feat->tx_fifo_size = 1 << (hw_feat->tx_fifo_size + 7);
2072572890efSRavi Kumar }
2073572890efSRavi Kumar 
2074572890efSRavi Kumar static void axgbe_init_all_fptrs(struct axgbe_port *pdata)
2075572890efSRavi Kumar {
2076572890efSRavi Kumar 	axgbe_init_function_ptrs_dev(&pdata->hw_if);
20774ac7516bSRavi Kumar 	axgbe_init_function_ptrs_phy(&pdata->phy_if);
20784ac7516bSRavi Kumar 	axgbe_init_function_ptrs_i2c(&pdata->i2c_if);
20794ac7516bSRavi Kumar 	pdata->vdata->init_function_ptrs_phy_impl(&pdata->phy_if);
2080572890efSRavi Kumar }
2081572890efSRavi Kumar 
2082572890efSRavi Kumar static void axgbe_set_counts(struct axgbe_port *pdata)
2083572890efSRavi Kumar {
2084572890efSRavi Kumar 	/* Set all the function pointers */
2085572890efSRavi Kumar 	axgbe_init_all_fptrs(pdata);
2086572890efSRavi Kumar 
2087572890efSRavi Kumar 	/* Populate the hardware features */
2088572890efSRavi Kumar 	axgbe_get_all_hw_features(pdata);
2089572890efSRavi Kumar 
2090572890efSRavi Kumar 	/* Set default max values if not provided */
2091572890efSRavi Kumar 	if (!pdata->tx_max_channel_count)
2092572890efSRavi Kumar 		pdata->tx_max_channel_count = pdata->hw_feat.tx_ch_cnt;
2093572890efSRavi Kumar 	if (!pdata->rx_max_channel_count)
2094572890efSRavi Kumar 		pdata->rx_max_channel_count = pdata->hw_feat.rx_ch_cnt;
2095572890efSRavi Kumar 
2096572890efSRavi Kumar 	if (!pdata->tx_max_q_count)
2097572890efSRavi Kumar 		pdata->tx_max_q_count = pdata->hw_feat.tx_q_cnt;
2098572890efSRavi Kumar 	if (!pdata->rx_max_q_count)
2099572890efSRavi Kumar 		pdata->rx_max_q_count = pdata->hw_feat.rx_q_cnt;
2100572890efSRavi Kumar 
2101572890efSRavi Kumar 	/* Calculate the number of Tx and Rx rings to be created
2102572890efSRavi Kumar 	 *  -Tx (DMA) Channels map 1-to-1 to Tx Queues so set
2103572890efSRavi Kumar 	 *   the number of Tx queues to the number of Tx channels
2104572890efSRavi Kumar 	 *   enabled
2105572890efSRavi Kumar 	 *  -Rx (DMA) Channels do not map 1-to-1 so use the actual
2106572890efSRavi Kumar 	 *   number of Rx queues or maximum allowed
2107572890efSRavi Kumar 	 */
2108572890efSRavi Kumar 	pdata->tx_ring_count = RTE_MIN(pdata->hw_feat.tx_ch_cnt,
2109572890efSRavi Kumar 				     pdata->tx_max_channel_count);
2110572890efSRavi Kumar 	pdata->tx_ring_count = RTE_MIN(pdata->tx_ring_count,
2111572890efSRavi Kumar 				     pdata->tx_max_q_count);
2112572890efSRavi Kumar 
2113572890efSRavi Kumar 	pdata->tx_q_count = pdata->tx_ring_count;
2114572890efSRavi Kumar 
2115572890efSRavi Kumar 	pdata->rx_ring_count = RTE_MIN(pdata->hw_feat.rx_ch_cnt,
2116572890efSRavi Kumar 				     pdata->rx_max_channel_count);
2117572890efSRavi Kumar 
2118572890efSRavi Kumar 	pdata->rx_q_count = RTE_MIN(pdata->hw_feat.rx_q_cnt,
2119572890efSRavi Kumar 				  pdata->rx_max_q_count);
2120572890efSRavi Kumar }
2121572890efSRavi Kumar 
2122572890efSRavi Kumar static void axgbe_default_config(struct axgbe_port *pdata)
2123572890efSRavi Kumar {
2124572890efSRavi Kumar 	pdata->pblx8 = DMA_PBL_X8_ENABLE;
2125572890efSRavi Kumar 	pdata->tx_sf_mode = MTL_TSF_ENABLE;
2126572890efSRavi Kumar 	pdata->tx_threshold = MTL_TX_THRESHOLD_64;
2127572890efSRavi Kumar 	pdata->tx_pbl = DMA_PBL_32;
2128572890efSRavi Kumar 	pdata->tx_osp_mode = DMA_OSP_ENABLE;
2129572890efSRavi Kumar 	pdata->rx_sf_mode = MTL_RSF_ENABLE;
2130572890efSRavi Kumar 	pdata->rx_threshold = MTL_RX_THRESHOLD_64;
2131572890efSRavi Kumar 	pdata->rx_pbl = DMA_PBL_32;
2132572890efSRavi Kumar 	pdata->pause_autoneg = 1;
2133572890efSRavi Kumar 	pdata->tx_pause = 0;
2134572890efSRavi Kumar 	pdata->rx_pause = 0;
2135572890efSRavi Kumar 	pdata->phy_speed = SPEED_UNKNOWN;
2136572890efSRavi Kumar 	pdata->power_down = 0;
2137572890efSRavi Kumar }
2138572890efSRavi Kumar 
21399963b513SJesna K E /* Used in dev_start by primary process and then
21409963b513SJesna K E  * in dev_init by secondary process when attaching to an existing ethdev.
21419963b513SJesna K E  */
21429963b513SJesna K E void
21439963b513SJesna K E axgbe_set_tx_function(struct rte_eth_dev *dev)
21449963b513SJesna K E {
21459963b513SJesna K E 	struct axgbe_port *pdata = dev->data->dev_private;
21469963b513SJesna K E 
21474feb9aa0SJesna K E 	dev->tx_pkt_burst = &axgbe_xmit_pkts;
21484feb9aa0SJesna K E 
21499963b513SJesna K E 	if (pdata->multi_segs_tx)
21509963b513SJesna K E 		dev->tx_pkt_burst = &axgbe_xmit_pkts_seg;
21519963b513SJesna K E #ifdef RTE_ARCH_X86
21529963b513SJesna K E 	struct axgbe_tx_queue *txq = dev->data->tx_queues[0];
21539963b513SJesna K E 	if (!txq->vector_disable &&
21549963b513SJesna K E 			rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128)
21559963b513SJesna K E 		dev->tx_pkt_burst = &axgbe_xmit_pkts_vec;
21569963b513SJesna K E #endif
21579963b513SJesna K E }
21589963b513SJesna K E 
21599963b513SJesna K E void
21609963b513SJesna K E axgbe_set_rx_function(struct rte_eth_dev *dev)
21619963b513SJesna K E {
21629963b513SJesna K E 	struct rte_eth_dev_data *dev_data = dev->data;
21639963b513SJesna K E 	uint16_t max_pkt_len;
21649963b513SJesna K E 	struct axgbe_port *pdata;
21659963b513SJesna K E 
21669963b513SJesna K E 	pdata = dev->data->dev_private;
21679963b513SJesna K E 	max_pkt_len = dev_data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
21689963b513SJesna K E 	if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
21699963b513SJesna K E 			max_pkt_len > pdata->rx_buf_size)
21709963b513SJesna K E 		dev_data->scattered_rx = 1;
21719963b513SJesna K E 	/*  Scatter Rx handling */
21729963b513SJesna K E 	if (dev_data->scattered_rx)
21739963b513SJesna K E 		dev->rx_pkt_burst = &eth_axgbe_recv_scattered_pkts;
21749963b513SJesna K E 	else
21759963b513SJesna K E 		dev->rx_pkt_burst = &axgbe_recv_pkts;
21769963b513SJesna K E }
21779963b513SJesna K E 
21788691632fSRavi Kumar /*
21798691632fSRavi Kumar  * It returns 0 on success.
21808691632fSRavi Kumar  */
21818691632fSRavi Kumar static int
21828691632fSRavi Kumar eth_axgbe_dev_init(struct rte_eth_dev *eth_dev)
21838691632fSRavi Kumar {
21848691632fSRavi Kumar 	PMD_INIT_FUNC_TRACE();
21858691632fSRavi Kumar 	struct axgbe_port *pdata;
21868691632fSRavi Kumar 	struct rte_pci_device *pci_dev;
2187572890efSRavi Kumar 	uint32_t reg, mac_lo, mac_hi;
218849a5e622SChandu Babu N 	uint32_t len;
2189572890efSRavi Kumar 	int ret;
21908691632fSRavi Kumar 
2191a27ff9caSSelwin Sebastian 	unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
2192a27ff9caSSelwin Sebastian 	unsigned char cpu_family = 0, cpu_model = 0;
2193a27ff9caSSelwin Sebastian 
21949e890103SRavi Kumar 	eth_dev->dev_ops = &axgbe_eth_dev_ops;
21959e890103SRavi Kumar 
2196cbfc6111SFerruh Yigit 	eth_dev->rx_descriptor_status = axgbe_dev_rx_descriptor_status;
2197cbfc6111SFerruh Yigit 	eth_dev->tx_descriptor_status = axgbe_dev_tx_descriptor_status;
2198cbfc6111SFerruh Yigit 
21999963b513SJesna K E 	eth_dev->tx_pkt_burst = &axgbe_xmit_pkts;
22009963b513SJesna K E 	eth_dev->rx_pkt_burst = &axgbe_recv_pkts;
22019963b513SJesna K E 
22028691632fSRavi Kumar 	/*
22038691632fSRavi Kumar 	 * For secondary processes, we don't initialise any further as primary
22048691632fSRavi Kumar 	 * has already done this work.
22058691632fSRavi Kumar 	 */
22069963b513SJesna K E 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
22079963b513SJesna K E 		axgbe_set_tx_function(eth_dev);
22089963b513SJesna K E 		axgbe_set_rx_function(eth_dev);
22098691632fSRavi Kumar 		return 0;
22109963b513SJesna K E 	}
22118691632fSRavi Kumar 
2212f30e69b4SFerruh Yigit 	eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2213f30e69b4SFerruh Yigit 
22140bc212a8SStephen Hemminger 	pdata = eth_dev->data->dev_private;
2215572890efSRavi Kumar 	/* initial state */
22164693ae4aSJoyce Kong 	rte_bit_relaxed_set32(AXGBE_DOWN, &pdata->dev_state);
22174693ae4aSJoyce Kong 	rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state);
22188691632fSRavi Kumar 	pdata->eth_dev = eth_dev;
22198691632fSRavi Kumar 
22208691632fSRavi Kumar 	pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
22218691632fSRavi Kumar 	pdata->pci_dev = pci_dev;
22228691632fSRavi Kumar 
2223572890efSRavi Kumar 	pdata->xgmac_regs =
22247784d0d3SRavi Kumar 		(void *)pci_dev->mem_resource[AXGBE_AXGMAC_BAR].addr;
22257784d0d3SRavi Kumar 	pdata->xprop_regs = (void *)((uint8_t *)pdata->xgmac_regs
22267784d0d3SRavi Kumar 				     + AXGBE_MAC_PROP_OFFSET);
22277784d0d3SRavi Kumar 	pdata->xi2c_regs = (void *)((uint8_t *)pdata->xgmac_regs
22287784d0d3SRavi Kumar 				    + AXGBE_I2C_CTRL_OFFSET);
22297784d0d3SRavi Kumar 	pdata->xpcs_regs = (void *)pci_dev->mem_resource[AXGBE_XPCS_BAR].addr;
2230572890efSRavi Kumar 
2231572890efSRavi Kumar 	/* version specific driver data*/
2232572890efSRavi Kumar 	if (pci_dev->id.device_id == AMD_PCI_AXGBE_DEVICE_V2A)
2233572890efSRavi Kumar 		pdata->vdata = &axgbe_v2a;
2234572890efSRavi Kumar 	else
2235572890efSRavi Kumar 		pdata->vdata = &axgbe_v2b;
2236572890efSRavi Kumar 
2237f7706f88SSelwin Sebastian 	/*
2238a27ff9caSSelwin Sebastian 	 * Use CPUID to get Family and model ID to identify the CPU
2239f7706f88SSelwin Sebastian 	 */
2240a27ff9caSSelwin Sebastian 	__cpuid(0x0, eax, ebx, ecx, edx);
2241a27ff9caSSelwin Sebastian 
2242a27ff9caSSelwin Sebastian 	if (ebx == CPUID_VENDOR_AuthenticAMD_ebx &&
2243a27ff9caSSelwin Sebastian 		edx == CPUID_VENDOR_AuthenticAMD_edx &&
2244a27ff9caSSelwin Sebastian 		ecx == CPUID_VENDOR_AuthenticAMD_ecx) {
2245a27ff9caSSelwin Sebastian 		int unknown_cpu = 0;
2246a27ff9caSSelwin Sebastian 		eax = 0, ebx = 0, ecx = 0, edx = 0;
2247a27ff9caSSelwin Sebastian 
2248a27ff9caSSelwin Sebastian 		__cpuid(0x1, eax, ebx, ecx, edx);
2249a27ff9caSSelwin Sebastian 
2250a27ff9caSSelwin Sebastian 		cpu_family = ((GET_BITS(eax, 8, 4)) + (GET_BITS(eax, 20, 8)));
2251a27ff9caSSelwin Sebastian 		cpu_model = ((GET_BITS(eax, 4, 4)) | (((GET_BITS(eax, 16, 4)) << 4) & 0xF0));
2252a27ff9caSSelwin Sebastian 
2253a27ff9caSSelwin Sebastian 		switch (cpu_family) {
2254a27ff9caSSelwin Sebastian 		case Fam17h:
2255a27ff9caSSelwin Sebastian 		/* V1000/R1000 */
2256a27ff9caSSelwin Sebastian 		if (cpu_model >= 0x10 && cpu_model <= 0x1F) {
2257f7706f88SSelwin Sebastian 			pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF;
2258f7706f88SSelwin Sebastian 			pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT;
2259a27ff9caSSelwin Sebastian 		/* EPYC 3000 */
2260a27ff9caSSelwin Sebastian 		} else if (cpu_model >= 0x01 && cpu_model <= 0x0F) {
2261f7706f88SSelwin Sebastian 			pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF;
2262f7706f88SSelwin Sebastian 			pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT;
2263a27ff9caSSelwin Sebastian 		} else {
2264a27ff9caSSelwin Sebastian 			unknown_cpu = 1;
2265a27ff9caSSelwin Sebastian 		}
2266a27ff9caSSelwin Sebastian 		break;
2267a27ff9caSSelwin Sebastian 		case Fam19h:
2268a27ff9caSSelwin Sebastian 		/* V3000 (Yellow Carp) */
2269a27ff9caSSelwin Sebastian 		if (cpu_model >= 0x44 && cpu_model <= 0x47) {
2270a27ff9caSSelwin Sebastian 			pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF;
2271a27ff9caSSelwin Sebastian 			pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT;
2272a27ff9caSSelwin Sebastian 
2273a27ff9caSSelwin Sebastian 			/* Yellow Carp devices do not need cdr workaround */
2274a27ff9caSSelwin Sebastian 			pdata->vdata->an_cdr_workaround = 0;
2275e82b0fe0SVenkat Kumar Ande 
2276e82b0fe0SVenkat Kumar Ande 			/* Yellow Carp devices do not need rrc */
2277e82b0fe0SVenkat Kumar Ande 			pdata->vdata->enable_rrc = 0;
2278a27ff9caSSelwin Sebastian 		} else {
2279a27ff9caSSelwin Sebastian 			unknown_cpu = 1;
2280a27ff9caSSelwin Sebastian 		}
2281f7706f88SSelwin Sebastian 		break;
2282f7706f88SSelwin Sebastian 		default:
2283a27ff9caSSelwin Sebastian 			unknown_cpu = 1;
2284a27ff9caSSelwin Sebastian 			break;
2285a27ff9caSSelwin Sebastian 		}
2286a27ff9caSSelwin Sebastian 		if (unknown_cpu) {
2287e99981afSDavid Marchand 			PMD_DRV_LOG_LINE(ERR, "Unknown CPU family, no supported axgbe device found");
2288f7706f88SSelwin Sebastian 			return -ENODEV;
2289f7706f88SSelwin Sebastian 		}
2290a27ff9caSSelwin Sebastian 	}
2291f7706f88SSelwin Sebastian 
2292572890efSRavi Kumar 	/* Configure the PCS indirect addressing support */
2293991e0b1dSSelwin Sebastian 	reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg);
2294572890efSRavi Kumar 	pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET);
2295572890efSRavi Kumar 	pdata->xpcs_window <<= 6;
2296572890efSRavi Kumar 	pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE);
2297572890efSRavi Kumar 	pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7);
2298572890efSRavi Kumar 	pdata->xpcs_window_mask = pdata->xpcs_window_size - 1;
2299991e0b1dSSelwin Sebastian 
2300572890efSRavi Kumar 	PMD_INIT_LOG(DEBUG,
2301572890efSRavi Kumar 		     "xpcs window :%x, size :%x, mask :%x ", pdata->xpcs_window,
2302572890efSRavi Kumar 		     pdata->xpcs_window_size, pdata->xpcs_window_mask);
2303572890efSRavi Kumar 	XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff);
2304572890efSRavi Kumar 
2305572890efSRavi Kumar 	/* Retrieve the MAC address */
2306572890efSRavi Kumar 	mac_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO);
2307572890efSRavi Kumar 	mac_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI);
2308572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[0] = mac_lo & 0xff;
2309572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[1] = (mac_lo >> 8) & 0xff;
2310572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[2] = (mac_lo >> 16) & 0xff;
2311572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[3] = (mac_lo >> 24) & 0xff;
2312572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[4] = mac_hi & 0xff;
2313572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[5] = (mac_hi >> 8)  &  0xff;
2314572890efSRavi Kumar 
231549a5e622SChandu Babu N 	len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_MAC_ADDRS;
231649a5e622SChandu Babu N 	eth_dev->data->mac_addrs = rte_zmalloc("axgbe_mac_addr", len, 0);
231749a5e622SChandu Babu N 
2318572890efSRavi Kumar 	if (!eth_dev->data->mac_addrs) {
2319572890efSRavi Kumar 		PMD_INIT_LOG(ERR,
232049a5e622SChandu Babu N 			     "Failed to alloc %u bytes needed to "
232149a5e622SChandu Babu N 			     "store MAC addresses", len);
2322572890efSRavi Kumar 		return -ENOMEM;
2323572890efSRavi Kumar 	}
2324572890efSRavi Kumar 
2325e01d9b2eSChandu Babu N 	/* Allocate memory for storing hash filter MAC addresses */
2326e01d9b2eSChandu Babu N 	len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_HASH_MAC_ADDRS;
2327e01d9b2eSChandu Babu N 	eth_dev->data->hash_mac_addrs = rte_zmalloc("axgbe_hash_mac_addr",
2328e01d9b2eSChandu Babu N 						    len, 0);
2329e01d9b2eSChandu Babu N 
2330e01d9b2eSChandu Babu N 	if (eth_dev->data->hash_mac_addrs == NULL) {
2331e01d9b2eSChandu Babu N 		PMD_INIT_LOG(ERR,
2332e01d9b2eSChandu Babu N 			     "Failed to allocate %d bytes needed to "
2333e01d9b2eSChandu Babu N 			     "store MAC addresses", len);
2334e01d9b2eSChandu Babu N 		return -ENOMEM;
2335e01d9b2eSChandu Babu N 	}
2336e01d9b2eSChandu Babu N 
2337538da7a1SOlivier Matz 	if (!rte_is_valid_assigned_ether_addr(&pdata->mac_addr))
2338538da7a1SOlivier Matz 		rte_eth_random_addr(pdata->mac_addr.addr_bytes);
2339572890efSRavi Kumar 
2340572890efSRavi Kumar 	/* Copy the permanent MAC address */
2341538da7a1SOlivier Matz 	rte_ether_addr_copy(&pdata->mac_addr, &eth_dev->data->mac_addrs[0]);
2342572890efSRavi Kumar 
2343572890efSRavi Kumar 	/* Clock settings */
2344572890efSRavi Kumar 	pdata->sysclk_rate = AXGBE_V2_DMA_CLOCK_FREQ;
2345572890efSRavi Kumar 	pdata->ptpclk_rate = AXGBE_V2_PTP_CLOCK_FREQ;
2346572890efSRavi Kumar 
2347572890efSRavi Kumar 	/* Set the DMA coherency values */
2348572890efSRavi Kumar 	pdata->coherent = 1;
2349572890efSRavi Kumar 	pdata->axdomain = AXGBE_DMA_OS_AXDOMAIN;
2350572890efSRavi Kumar 	pdata->arcache = AXGBE_DMA_OS_ARCACHE;
2351572890efSRavi Kumar 	pdata->awcache = AXGBE_DMA_OS_AWCACHE;
2352572890efSRavi Kumar 
2353a3ec01b4SVenkat Kumar Ande 	/* Read the port property registers */
2354a3ec01b4SVenkat Kumar Ande 	pdata->pp0 = XP_IOREAD(pdata, XP_PROP_0);
2355a3ec01b4SVenkat Kumar Ande 	pdata->pp1 = XP_IOREAD(pdata, XP_PROP_1);
2356a3ec01b4SVenkat Kumar Ande 	pdata->pp2 = XP_IOREAD(pdata, XP_PROP_2);
2357a3ec01b4SVenkat Kumar Ande 	pdata->pp3 = XP_IOREAD(pdata, XP_PROP_3);
2358a3ec01b4SVenkat Kumar Ande 	pdata->pp4 = XP_IOREAD(pdata, XP_PROP_4);
2359a3ec01b4SVenkat Kumar Ande 
2360572890efSRavi Kumar 	/* Set the maximum channels and queues */
2361a3ec01b4SVenkat Kumar Ande 	pdata->tx_max_channel_count = XP_GET_BITS(pdata->pp1, XP_PROP_1, MAX_TX_DMA);
2362a3ec01b4SVenkat Kumar Ande 	pdata->rx_max_channel_count = XP_GET_BITS(pdata->pp1, XP_PROP_1, MAX_RX_DMA);
2363a3ec01b4SVenkat Kumar Ande 	pdata->tx_max_q_count = XP_GET_BITS(pdata->pp1, XP_PROP_1, MAX_TX_QUEUES);
2364a3ec01b4SVenkat Kumar Ande 	pdata->rx_max_q_count = XP_GET_BITS(pdata->pp1, XP_PROP_1, MAX_RX_QUEUES);
2365572890efSRavi Kumar 
2366572890efSRavi Kumar 	/* Set the hardware channel and queue counts */
2367572890efSRavi Kumar 	axgbe_set_counts(pdata);
2368572890efSRavi Kumar 
2369572890efSRavi Kumar 	/* Set the maximum fifo amounts */
2370a3ec01b4SVenkat Kumar Ande 	pdata->tx_max_fifo_size = XP_GET_BITS(pdata->pp2, XP_PROP_2, TX_FIFO_SIZE);
2371572890efSRavi Kumar 	pdata->tx_max_fifo_size *= 16384;
2372572890efSRavi Kumar 	pdata->tx_max_fifo_size = RTE_MIN(pdata->tx_max_fifo_size,
2373572890efSRavi Kumar 					  pdata->vdata->tx_max_fifo_size);
2374a3ec01b4SVenkat Kumar Ande 	pdata->rx_max_fifo_size = XP_GET_BITS(pdata->pp2, XP_PROP_2, RX_FIFO_SIZE);
2375572890efSRavi Kumar 	pdata->rx_max_fifo_size *= 16384;
2376572890efSRavi Kumar 	pdata->rx_max_fifo_size = RTE_MIN(pdata->rx_max_fifo_size,
2377572890efSRavi Kumar 					  pdata->vdata->rx_max_fifo_size);
2378572890efSRavi Kumar 	/* Issue software reset to DMA */
2379572890efSRavi Kumar 	ret = pdata->hw_if.exit(pdata);
2380572890efSRavi Kumar 	if (ret)
2381e99981afSDavid Marchand 		PMD_DRV_LOG_LINE(ERR, "hw_if->exit EBUSY error");
2382572890efSRavi Kumar 
2383572890efSRavi Kumar 	/* Set default configuration data */
2384572890efSRavi Kumar 	axgbe_default_config(pdata);
2385572890efSRavi Kumar 
2386572890efSRavi Kumar 	/* Set default max values if not provided */
2387572890efSRavi Kumar 	if (!pdata->tx_max_fifo_size)
2388572890efSRavi Kumar 		pdata->tx_max_fifo_size = pdata->hw_feat.tx_fifo_size;
2389572890efSRavi Kumar 	if (!pdata->rx_max_fifo_size)
2390572890efSRavi Kumar 		pdata->rx_max_fifo_size = pdata->hw_feat.rx_fifo_size;
2391572890efSRavi Kumar 
23929e890103SRavi Kumar 	pdata->tx_desc_count = AXGBE_MAX_RING_DESC;
23939e890103SRavi Kumar 	pdata->rx_desc_count = AXGBE_MAX_RING_DESC;
2394572890efSRavi Kumar 	pthread_mutex_init(&pdata->xpcs_mutex, NULL);
2395572890efSRavi Kumar 	pthread_mutex_init(&pdata->i2c_mutex, NULL);
2396572890efSRavi Kumar 	pthread_mutex_init(&pdata->an_mutex, NULL);
2397572890efSRavi Kumar 	pthread_mutex_init(&pdata->phy_mutex, NULL);
2398572890efSRavi Kumar 
23994ac7516bSRavi Kumar 	ret = pdata->phy_if.phy_init(pdata);
24004ac7516bSRavi Kumar 	if (ret) {
24014ac7516bSRavi Kumar 		rte_free(eth_dev->data->mac_addrs);
2402e7f2fa88SDavid Marchand 		eth_dev->data->mac_addrs = NULL;
24034ac7516bSRavi Kumar 		return ret;
24044ac7516bSRavi Kumar 	}
24054ac7516bSRavi Kumar 
2406d61138d4SHarman Kalra 	rte_intr_callback_register(pci_dev->intr_handle,
2407456ff159SRavi Kumar 				   axgbe_dev_interrupt_handler,
2408456ff159SRavi Kumar 				   (void *)eth_dev);
24098691632fSRavi Kumar 	PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
24108691632fSRavi Kumar 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
24118691632fSRavi Kumar 		     pci_dev->id.device_id);
24128691632fSRavi Kumar 
24138691632fSRavi Kumar 	return 0;
24148691632fSRavi Kumar }
24158691632fSRavi Kumar 
24168691632fSRavi Kumar static int
2417479e6a42SThomas Monjalon axgbe_dev_close(struct rte_eth_dev *eth_dev)
24188691632fSRavi Kumar {
2419456ff159SRavi Kumar 	struct rte_pci_device *pci_dev;
24207b7288b0SVenkat Kumar Ande 	struct axgbe_port *pdata;
2421456ff159SRavi Kumar 
24228691632fSRavi Kumar 	PMD_INIT_FUNC_TRACE();
24238691632fSRavi Kumar 
2424572890efSRavi Kumar 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2425572890efSRavi Kumar 		return 0;
2426572890efSRavi Kumar 
24277b7288b0SVenkat Kumar Ande 	pdata = eth_dev->data->dev_private;
2428456ff159SRavi Kumar 	pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
24299e890103SRavi Kumar 	axgbe_dev_clear_queues(eth_dev);
2430572890efSRavi Kumar 
2431456ff159SRavi Kumar 	/* disable uio intr before callback unregister */
2432d61138d4SHarman Kalra 	rte_intr_disable(pci_dev->intr_handle);
2433d61138d4SHarman Kalra 	rte_intr_callback_unregister(pci_dev->intr_handle,
2434456ff159SRavi Kumar 				     axgbe_dev_interrupt_handler,
2435456ff159SRavi Kumar 				     (void *)eth_dev);
2436456ff159SRavi Kumar 
24377b7288b0SVenkat Kumar Ande 	/* Disable all interrupts in the hardware */
24387b7288b0SVenkat Kumar Ande 	XP_IOWRITE(pdata, XP_INT_EN, 0x0);
24397b7288b0SVenkat Kumar Ande 
24408691632fSRavi Kumar 	return 0;
24418691632fSRavi Kumar }
24428691632fSRavi Kumar 
24438691632fSRavi Kumar static int eth_axgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
24448691632fSRavi Kumar 	struct rte_pci_device *pci_dev)
24458691632fSRavi Kumar {
24468691632fSRavi Kumar 	return rte_eth_dev_pci_generic_probe(pci_dev,
24478691632fSRavi Kumar 		sizeof(struct axgbe_port), eth_axgbe_dev_init);
24488691632fSRavi Kumar }
24498691632fSRavi Kumar 
24508691632fSRavi Kumar static int eth_axgbe_pci_remove(struct rte_pci_device *pci_dev)
24518691632fSRavi Kumar {
2452479e6a42SThomas Monjalon 	return rte_eth_dev_pci_generic_remove(pci_dev, axgbe_dev_close);
24538691632fSRavi Kumar }
24548691632fSRavi Kumar 
24558691632fSRavi Kumar static struct rte_pci_driver rte_axgbe_pmd = {
24568691632fSRavi Kumar 	.id_table = pci_id_axgbe_map,
24578691632fSRavi Kumar 	.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
24588691632fSRavi Kumar 	.probe = eth_axgbe_pci_probe,
24598691632fSRavi Kumar 	.remove = eth_axgbe_pci_remove,
24608691632fSRavi Kumar };
24618691632fSRavi Kumar 
24628691632fSRavi Kumar RTE_PMD_REGISTER_PCI(net_axgbe, rte_axgbe_pmd);
24638691632fSRavi Kumar RTE_PMD_REGISTER_PCI_TABLE(net_axgbe, pci_id_axgbe_map);
24648691632fSRavi Kumar RTE_PMD_REGISTER_KMOD_DEP(net_axgbe, "* igb_uio | uio_pci_generic | vfio-pci");
2465eeded204SDavid Marchand RTE_LOG_REGISTER_SUFFIX(axgbe_logtype_init, init, NOTICE);
2466eeded204SDavid Marchand RTE_LOG_REGISTER_SUFFIX(axgbe_logtype_driver, driver, NOTICE);
2467