xref: /dpdk/drivers/net/axgbe/axgbe_ethdev.c (revision 93041fd5149a4f8cc795ea8ebb229415e2994e51)
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 
158691632fSRavi Kumar static int eth_axgbe_dev_init(struct rte_eth_dev *eth_dev);
167c4158a5SRavi Kumar static int  axgbe_dev_configure(struct rte_eth_dev *dev);
177c4158a5SRavi Kumar static int  axgbe_dev_start(struct rte_eth_dev *dev);
1862024eb8SIvan Ilchenko static int  axgbe_dev_stop(struct rte_eth_dev *dev);
19456ff159SRavi Kumar static void axgbe_dev_interrupt_handler(void *param);
20b142387bSThomas Monjalon static int axgbe_dev_close(struct rte_eth_dev *dev);
21bf403cfeSSelwin Sebastian static int axgbe_dev_reset(struct rte_eth_dev *dev);
229039c812SAndrew Rybchenko static int axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
239039c812SAndrew Rybchenko static int axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
24ca041cd4SIvan Ilchenko static int axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
25ca041cd4SIvan Ilchenko static int axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
2649a5e622SChandu Babu N static int axgbe_dev_mac_addr_set(struct rte_eth_dev *dev,
2749a5e622SChandu Babu N 				  struct rte_ether_addr *mac_addr);
2849a5e622SChandu Babu N static int axgbe_dev_mac_addr_add(struct rte_eth_dev *dev,
2949a5e622SChandu Babu N 				  struct rte_ether_addr *mac_addr,
3049a5e622SChandu Babu N 				  uint32_t index,
3149a5e622SChandu Babu N 				  uint32_t vmdq);
3249a5e622SChandu Babu N static void axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
3349a5e622SChandu Babu N static int axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
3449a5e622SChandu Babu N 				      struct rte_ether_addr *mc_addr_set,
3549a5e622SChandu Babu N 				      uint32_t nb_mc_addr);
36e01d9b2eSChandu Babu N static int axgbe_dev_uc_hash_table_set(struct rte_eth_dev *dev,
37e01d9b2eSChandu Babu N 				       struct rte_ether_addr *mac_addr,
38e01d9b2eSChandu Babu N 				       uint8_t add);
39e01d9b2eSChandu Babu N static int axgbe_dev_uc_all_hash_table_set(struct rte_eth_dev *dev,
40e01d9b2eSChandu Babu N 					   uint8_t add);
4144d45ffeSRavi Kumar static int axgbe_dev_link_update(struct rte_eth_dev *dev,
4244d45ffeSRavi Kumar 				 int wait_to_complete);
43df4867cdSChandu Babu N static int axgbe_dev_get_regs(struct rte_eth_dev *dev,
44df4867cdSChandu Babu N 			      struct rte_dev_reg_info *regs);
453e730511SRavi Kumar static int axgbe_dev_stats_get(struct rte_eth_dev *dev,
463e730511SRavi Kumar 				struct rte_eth_stats *stats);
479970a9adSIgor Romanov static int axgbe_dev_stats_reset(struct rte_eth_dev *dev);
489d1ef6b2SChandu Babu N static int axgbe_dev_xstats_get(struct rte_eth_dev *dev,
499d1ef6b2SChandu Babu N 				struct rte_eth_xstat *stats,
509d1ef6b2SChandu Babu N 				unsigned int n);
519d1ef6b2SChandu Babu N static int
529d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(struct rte_eth_dev *dev,
539d1ef6b2SChandu Babu N 			   struct rte_eth_xstat_name *xstats_names,
549d1ef6b2SChandu Babu N 			   unsigned int size);
559d1ef6b2SChandu Babu N static int
569d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev,
579d1ef6b2SChandu Babu N 			   const uint64_t *ids,
589d1ef6b2SChandu Babu N 			   uint64_t *values,
599d1ef6b2SChandu Babu N 			   unsigned int n);
609d1ef6b2SChandu Babu N static int
619d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
629d1ef6b2SChandu Babu N 				 const uint64_t *ids,
638c9f976fSAndrew Rybchenko 				 struct rte_eth_xstat_name *xstats_names,
649d1ef6b2SChandu Babu N 				 unsigned int size);
659d1ef6b2SChandu Babu N static int axgbe_dev_xstats_reset(struct rte_eth_dev *dev);
6676d7664dSChandu Babu N static int axgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
6776d7664dSChandu Babu N 			  struct rte_eth_rss_reta_entry64 *reta_conf,
6876d7664dSChandu Babu N 			  uint16_t reta_size);
6976d7664dSChandu Babu N static int axgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
7076d7664dSChandu Babu N 			 struct rte_eth_rss_reta_entry64 *reta_conf,
7176d7664dSChandu Babu N 			 uint16_t reta_size);
7276d7664dSChandu Babu N static int axgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
7376d7664dSChandu Babu N 				     struct rte_eth_rss_conf *rss_conf);
7476d7664dSChandu Babu N static int axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7576d7664dSChandu Babu N 				       struct rte_eth_rss_conf *rss_conf);
76bdad90d1SIvan Ilchenko static int  axgbe_dev_info_get(struct rte_eth_dev *dev,
779e890103SRavi Kumar 			       struct rte_eth_dev_info *dev_info);
78cf97f33eSAmaranath Somalapuram static int axgbe_flow_ctrl_get(struct rte_eth_dev *dev,
79cf97f33eSAmaranath Somalapuram 				struct rte_eth_fc_conf *fc_conf);
80cf97f33eSAmaranath Somalapuram static int axgbe_flow_ctrl_set(struct rte_eth_dev *dev,
81cf97f33eSAmaranath Somalapuram 				struct rte_eth_fc_conf *fc_conf);
82e0543d4eSAmaranath Somalapuram static int axgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
83e0543d4eSAmaranath Somalapuram 				struct rte_eth_pfc_conf *pfc_conf);
847aed95c9SAmaranath Somalapuram static void axgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
857aed95c9SAmaranath Somalapuram 	struct rte_eth_rxq_info *qinfo);
867aed95c9SAmaranath Somalapuram static void axgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
877aed95c9SAmaranath Somalapuram 	struct rte_eth_txq_info *qinfo);
88410cf087SAmaranath Somalapuram const uint32_t *axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev);
89b58d8781SGirish Nandibasappa static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
908691632fSRavi Kumar 
91e0444948SSelwin Sebastian static int
92e0444948SSelwin Sebastian axgbe_timesync_enable(struct rte_eth_dev *dev);
93e0444948SSelwin Sebastian static int
94e0444948SSelwin Sebastian axgbe_timesync_disable(struct rte_eth_dev *dev);
95e0444948SSelwin Sebastian static int
96e0444948SSelwin Sebastian axgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
97e0444948SSelwin Sebastian 			struct timespec *timestamp, uint32_t flags);
98e0444948SSelwin Sebastian static int
99e0444948SSelwin Sebastian axgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
100e0444948SSelwin Sebastian 			struct timespec *timestamp);
101e0444948SSelwin Sebastian static int
102e0444948SSelwin Sebastian axgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
103e0444948SSelwin Sebastian static int
104e0444948SSelwin Sebastian axgbe_timesync_read_time(struct rte_eth_dev *dev,
105e0444948SSelwin Sebastian 			struct timespec *timestamp);
106e0444948SSelwin Sebastian static int
107e0444948SSelwin Sebastian axgbe_timesync_write_time(struct rte_eth_dev *dev,
108e0444948SSelwin Sebastian 			const struct timespec *timestamp);
109e0444948SSelwin Sebastian static void
110e0444948SSelwin Sebastian axgbe_set_tstamp_time(struct axgbe_port *pdata, unsigned int sec,
111e0444948SSelwin Sebastian 			unsigned int nsec);
112e0444948SSelwin Sebastian static void
113e0444948SSelwin Sebastian axgbe_update_tstamp_addend(struct axgbe_port *pdata,
114e0444948SSelwin Sebastian 			unsigned int addend);
11586578516SGirish Nandibasappa static int
11686578516SGirish Nandibasappa 	axgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on);
11786578516SGirish Nandibasappa static int axgbe_vlan_tpid_set(struct rte_eth_dev *dev,
11886578516SGirish Nandibasappa 				enum rte_vlan_type vlan_type, uint16_t tpid);
11986578516SGirish Nandibasappa static int axgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask);
120e0444948SSelwin Sebastian 
1219d1ef6b2SChandu Babu N struct axgbe_xstats {
1229d1ef6b2SChandu Babu N 	char name[RTE_ETH_XSTATS_NAME_SIZE];
1239d1ef6b2SChandu Babu N 	int offset;
1249d1ef6b2SChandu Babu N };
1259d1ef6b2SChandu Babu N 
1269d1ef6b2SChandu Babu N #define AXGMAC_MMC_STAT(_string, _var)                           \
1279d1ef6b2SChandu Babu N 	{ _string,                                              \
1289d1ef6b2SChandu Babu N 	  offsetof(struct axgbe_mmc_stats, _var),       \
1299d1ef6b2SChandu Babu N 	}
1309d1ef6b2SChandu Babu N 
1319d1ef6b2SChandu Babu N static const struct axgbe_xstats axgbe_xstats_strings[] = {
1329d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_bytes", txoctetcount_gb),
1339d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_packets", txframecount_gb),
1349d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb),
1359d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
1369d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb),
1379d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g),
1389d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
1399d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
1409d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
1419d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
1429d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
1439d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
1449d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
1459d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
1469d1ef6b2SChandu Babu N 
1479d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
1489d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_packets", rxframecount_gb),
1499d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
1509d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
1519d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
1529d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
1539d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
1549d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
1559d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
1569d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
1579d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
1589d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
1599d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
1609d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
1619d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
1629d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
1639d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
1649d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
1659d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
1669d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
1679d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
1689d1ef6b2SChandu Babu N 	AXGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
1699d1ef6b2SChandu Babu N };
1709d1ef6b2SChandu Babu N 
1719d1ef6b2SChandu Babu N #define AXGBE_XSTATS_COUNT        ARRAY_SIZE(axgbe_xstats_strings)
1729d1ef6b2SChandu Babu N 
1738691632fSRavi Kumar /* The set of PCI devices this driver supports */
1748691632fSRavi Kumar #define AMD_PCI_VENDOR_ID       0x1022
175991e0b1dSSelwin Sebastian #define AMD_PCI_RV_ROOT_COMPLEX_ID	0x15d0
176f7706f88SSelwin Sebastian #define AMD_PCI_YC_ROOT_COMPLEX_ID	0x14b5
177f7706f88SSelwin Sebastian #define AMD_PCI_SNOWY_ROOT_COMPLEX_ID	0x1450
1788691632fSRavi Kumar #define AMD_PCI_AXGBE_DEVICE_V2A 0x1458
1798691632fSRavi Kumar #define AMD_PCI_AXGBE_DEVICE_V2B 0x1459
1808691632fSRavi Kumar 
1818691632fSRavi Kumar static const struct rte_pci_id pci_id_axgbe_map[] = {
1828691632fSRavi Kumar 	{RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_AXGBE_DEVICE_V2A)},
1838691632fSRavi Kumar 	{RTE_PCI_DEVICE(AMD_PCI_VENDOR_ID, AMD_PCI_AXGBE_DEVICE_V2B)},
1848691632fSRavi Kumar 	{ .vendor_id = 0, },
1858691632fSRavi Kumar };
1868691632fSRavi Kumar 
187572890efSRavi Kumar static struct axgbe_version_data axgbe_v2a = {
1884ac7516bSRavi Kumar 	.init_function_ptrs_phy_impl    = axgbe_init_function_ptrs_phy_v2,
189572890efSRavi Kumar 	.xpcs_access			= AXGBE_XPCS_ACCESS_V2,
190572890efSRavi Kumar 	.mmc_64bit			= 1,
191572890efSRavi Kumar 	.tx_max_fifo_size		= 229376,
192572890efSRavi Kumar 	.rx_max_fifo_size		= 229376,
193572890efSRavi Kumar 	.tx_tstamp_workaround		= 1,
194572890efSRavi Kumar 	.ecc_support			= 1,
195572890efSRavi Kumar 	.i2c_support			= 1,
19600072056SRavi Kumar 	.an_cdr_workaround		= 1,
197572890efSRavi Kumar };
198572890efSRavi Kumar 
199572890efSRavi Kumar static struct axgbe_version_data axgbe_v2b = {
2004ac7516bSRavi Kumar 	.init_function_ptrs_phy_impl    = axgbe_init_function_ptrs_phy_v2,
201572890efSRavi Kumar 	.xpcs_access			= AXGBE_XPCS_ACCESS_V2,
202572890efSRavi Kumar 	.mmc_64bit			= 1,
203572890efSRavi Kumar 	.tx_max_fifo_size		= 65536,
204572890efSRavi Kumar 	.rx_max_fifo_size		= 65536,
205572890efSRavi Kumar 	.tx_tstamp_workaround		= 1,
206572890efSRavi Kumar 	.ecc_support			= 1,
207572890efSRavi Kumar 	.i2c_support			= 1,
20800072056SRavi Kumar 	.an_cdr_workaround		= 1,
209572890efSRavi Kumar };
210572890efSRavi Kumar 
2119e890103SRavi Kumar static const struct rte_eth_desc_lim rx_desc_lim = {
2129e890103SRavi Kumar 	.nb_max = AXGBE_MAX_RING_DESC,
2139e890103SRavi Kumar 	.nb_min = AXGBE_MIN_RING_DESC,
2149e890103SRavi Kumar 	.nb_align = 8,
2159e890103SRavi Kumar };
2169e890103SRavi Kumar 
2179e890103SRavi Kumar static const struct rte_eth_desc_lim tx_desc_lim = {
2189e890103SRavi Kumar 	.nb_max = AXGBE_MAX_RING_DESC,
2199e890103SRavi Kumar 	.nb_min = AXGBE_MIN_RING_DESC,
2209e890103SRavi Kumar 	.nb_align = 8,
2219e890103SRavi Kumar };
2229e890103SRavi Kumar 
2239e890103SRavi Kumar static const struct eth_dev_ops axgbe_eth_dev_ops = {
2247c4158a5SRavi Kumar 	.dev_configure        = axgbe_dev_configure,
2257c4158a5SRavi Kumar 	.dev_start            = axgbe_dev_start,
2267c4158a5SRavi Kumar 	.dev_stop             = axgbe_dev_stop,
2279e890103SRavi Kumar 	.dev_close            = axgbe_dev_close,
228bf403cfeSSelwin Sebastian 	.dev_reset            = axgbe_dev_reset,
229fa3e0440SRavi Kumar 	.promiscuous_enable   = axgbe_dev_promiscuous_enable,
230fa3e0440SRavi Kumar 	.promiscuous_disable  = axgbe_dev_promiscuous_disable,
231fa3e0440SRavi Kumar 	.allmulticast_enable  = axgbe_dev_allmulticast_enable,
232fa3e0440SRavi Kumar 	.allmulticast_disable = axgbe_dev_allmulticast_disable,
23349a5e622SChandu Babu N 	.mac_addr_set         = axgbe_dev_mac_addr_set,
23449a5e622SChandu Babu N 	.mac_addr_add         = axgbe_dev_mac_addr_add,
23549a5e622SChandu Babu N 	.mac_addr_remove      = axgbe_dev_mac_addr_remove,
23649a5e622SChandu Babu N 	.set_mc_addr_list     = axgbe_dev_set_mc_addr_list,
237e01d9b2eSChandu Babu N 	.uc_hash_table_set    = axgbe_dev_uc_hash_table_set,
238e01d9b2eSChandu Babu N 	.uc_all_hash_table_set = axgbe_dev_uc_all_hash_table_set,
23944d45ffeSRavi Kumar 	.link_update          = axgbe_dev_link_update,
240df4867cdSChandu Babu N 	.get_reg	      = axgbe_dev_get_regs,
2413e730511SRavi Kumar 	.stats_get            = axgbe_dev_stats_get,
2423e730511SRavi Kumar 	.stats_reset          = axgbe_dev_stats_reset,
2439d1ef6b2SChandu Babu N 	.xstats_get	      = axgbe_dev_xstats_get,
2449d1ef6b2SChandu Babu N 	.xstats_reset	      = axgbe_dev_xstats_reset,
2459d1ef6b2SChandu Babu N 	.xstats_get_names     = axgbe_dev_xstats_get_names,
2469d1ef6b2SChandu Babu N 	.xstats_get_names_by_id = axgbe_dev_xstats_get_names_by_id,
2479d1ef6b2SChandu Babu N 	.xstats_get_by_id     = axgbe_dev_xstats_get_by_id,
24876d7664dSChandu Babu N 	.reta_update          = axgbe_dev_rss_reta_update,
24976d7664dSChandu Babu N 	.reta_query           = axgbe_dev_rss_reta_query,
25076d7664dSChandu Babu N 	.rss_hash_update      = axgbe_dev_rss_hash_update,
25176d7664dSChandu Babu N 	.rss_hash_conf_get    = axgbe_dev_rss_hash_conf_get,
2529e890103SRavi Kumar 	.dev_infos_get        = axgbe_dev_info_get,
2539e890103SRavi Kumar 	.rx_queue_setup       = axgbe_dev_rx_queue_setup,
2549e890103SRavi Kumar 	.rx_queue_release     = axgbe_dev_rx_queue_release,
2559e890103SRavi Kumar 	.tx_queue_setup       = axgbe_dev_tx_queue_setup,
2569e890103SRavi Kumar 	.tx_queue_release     = axgbe_dev_tx_queue_release,
257cf97f33eSAmaranath Somalapuram 	.flow_ctrl_get        = axgbe_flow_ctrl_get,
258cf97f33eSAmaranath Somalapuram 	.flow_ctrl_set        = axgbe_flow_ctrl_set,
259e0543d4eSAmaranath Somalapuram 	.priority_flow_ctrl_set = axgbe_priority_flow_ctrl_set,
2607aed95c9SAmaranath Somalapuram 	.rxq_info_get                 = axgbe_rxq_info_get,
2617aed95c9SAmaranath Somalapuram 	.txq_info_get                 = axgbe_txq_info_get,
262410cf087SAmaranath Somalapuram 	.dev_supported_ptypes_get     = axgbe_dev_supported_ptypes_get,
263b58d8781SGirish Nandibasappa 	.mtu_set		= axgb_mtu_set,
26486578516SGirish Nandibasappa 	.vlan_filter_set      = axgbe_vlan_filter_set,
26586578516SGirish Nandibasappa 	.vlan_tpid_set        = axgbe_vlan_tpid_set,
26686578516SGirish Nandibasappa 	.vlan_offload_set     = axgbe_vlan_offload_set,
267e0444948SSelwin Sebastian 	.timesync_enable              = axgbe_timesync_enable,
268e0444948SSelwin Sebastian 	.timesync_disable             = axgbe_timesync_disable,
269e0444948SSelwin Sebastian 	.timesync_read_rx_timestamp   = axgbe_timesync_read_rx_timestamp,
270e0444948SSelwin Sebastian 	.timesync_read_tx_timestamp   = axgbe_timesync_read_tx_timestamp,
271e0444948SSelwin Sebastian 	.timesync_adjust_time         = axgbe_timesync_adjust_time,
272e0444948SSelwin Sebastian 	.timesync_read_time           = axgbe_timesync_read_time,
273e0444948SSelwin Sebastian 	.timesync_write_time          = axgbe_timesync_write_time,
274ff70acdfSSelwin Sebastian 	.fw_version_get			= axgbe_dev_fw_version_get,
2759e890103SRavi Kumar };
2769e890103SRavi Kumar 
2777c4158a5SRavi Kumar static int axgbe_phy_reset(struct axgbe_port *pdata)
2787c4158a5SRavi Kumar {
2797c4158a5SRavi Kumar 	pdata->phy_link = -1;
2807c4158a5SRavi Kumar 	pdata->phy_speed = SPEED_UNKNOWN;
2817c4158a5SRavi Kumar 	return pdata->phy_if.phy_reset(pdata);
2827c4158a5SRavi Kumar }
2837c4158a5SRavi Kumar 
284456ff159SRavi Kumar /*
285456ff159SRavi Kumar  * Interrupt handler triggered by NIC  for handling
286456ff159SRavi Kumar  * specific interrupt.
287456ff159SRavi Kumar  *
288456ff159SRavi Kumar  * @param handle
289456ff159SRavi Kumar  *  Pointer to interrupt handle.
290456ff159SRavi Kumar  * @param param
2917be78d02SJosh Soref  *  The address of parameter (struct rte_eth_dev *) registered before.
292456ff159SRavi Kumar  *
293456ff159SRavi Kumar  * @return
294456ff159SRavi Kumar  *  void
295456ff159SRavi Kumar  */
296456ff159SRavi Kumar static void
297456ff159SRavi Kumar axgbe_dev_interrupt_handler(void *param)
298456ff159SRavi Kumar {
299456ff159SRavi Kumar 	struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
300456ff159SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
3018590b93dSRavi Kumar 	unsigned int dma_isr, dma_ch_isr;
302456ff159SRavi Kumar 
303456ff159SRavi Kumar 	pdata->phy_if.an_isr(pdata);
3048590b93dSRavi Kumar 	/*DMA related interrupts*/
3058590b93dSRavi Kumar 	dma_isr = AXGMAC_IOREAD(pdata, DMA_ISR);
3064216cdc0SChandu Babu N 	PMD_DRV_LOG(DEBUG, "DMA_ISR=%#010x\n", dma_isr);
3078590b93dSRavi Kumar 	if (dma_isr) {
3088590b93dSRavi Kumar 		if (dma_isr & 1) {
3098590b93dSRavi Kumar 			dma_ch_isr =
3108590b93dSRavi Kumar 				AXGMAC_DMA_IOREAD((struct axgbe_rx_queue *)
3118590b93dSRavi Kumar 						  pdata->rx_queues[0],
3128590b93dSRavi Kumar 						  DMA_CH_SR);
3134216cdc0SChandu Babu N 			PMD_DRV_LOG(DEBUG, "DMA_CH0_ISR=%#010x\n", dma_ch_isr);
3148590b93dSRavi Kumar 			AXGMAC_DMA_IOWRITE((struct axgbe_rx_queue *)
3158590b93dSRavi Kumar 					   pdata->rx_queues[0],
3168590b93dSRavi Kumar 					   DMA_CH_SR, dma_ch_isr);
3178590b93dSRavi Kumar 		}
3188590b93dSRavi Kumar 	}
3196bee9d5fSNithin Dabilpuram 	/* Unmask interrupts since disabled after generation */
320d61138d4SHarman Kalra 	rte_intr_ack(pdata->pci_dev->intr_handle);
321456ff159SRavi Kumar }
322456ff159SRavi Kumar 
3237c4158a5SRavi Kumar /*
3247c4158a5SRavi Kumar  * Configure device link speed and setup link.
3257c4158a5SRavi Kumar  * It returns 0 on success.
3267c4158a5SRavi Kumar  */
3277c4158a5SRavi Kumar static int
3287c4158a5SRavi Kumar axgbe_dev_configure(struct rte_eth_dev *dev)
3297c4158a5SRavi Kumar {
3307c4158a5SRavi Kumar 	struct axgbe_port *pdata =  dev->data->dev_private;
3317c4158a5SRavi Kumar 	/* Checksum offload to hardware */
3327c4158a5SRavi Kumar 	pdata->rx_csum_enable = dev->data->dev_conf.rxmode.offloads &
333295968d1SFerruh Yigit 				RTE_ETH_RX_OFFLOAD_CHECKSUM;
3347c4158a5SRavi Kumar 	return 0;
3357c4158a5SRavi Kumar }
3367c4158a5SRavi Kumar 
3377c4158a5SRavi Kumar static int
3387c4158a5SRavi Kumar axgbe_dev_rx_mq_config(struct rte_eth_dev *dev)
3397c4158a5SRavi Kumar {
3400bc212a8SStephen Hemminger 	struct axgbe_port *pdata = dev->data->dev_private;
3417c4158a5SRavi Kumar 
342295968d1SFerruh Yigit 	if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_RSS)
3437c4158a5SRavi Kumar 		pdata->rss_enable = 1;
344295968d1SFerruh Yigit 	else if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_NONE)
3457c4158a5SRavi Kumar 		pdata->rss_enable = 0;
3467c4158a5SRavi Kumar 	else
3477c4158a5SRavi Kumar 		return  -1;
3487c4158a5SRavi Kumar 	return 0;
3497c4158a5SRavi Kumar }
3507c4158a5SRavi Kumar 
3517c4158a5SRavi Kumar static int
3527c4158a5SRavi Kumar axgbe_dev_start(struct rte_eth_dev *dev)
3537c4158a5SRavi Kumar {
3540bc212a8SStephen Hemminger 	struct axgbe_port *pdata = dev->data->dev_private;
3557c4158a5SRavi Kumar 	int ret;
356965b3127SSelwin Sebastian 	struct rte_eth_dev_data *dev_data = dev->data;
3571bb4a528SFerruh Yigit 	uint16_t max_pkt_len;
358965b3127SSelwin Sebastian 
359965b3127SSelwin Sebastian 	dev->dev_ops = &axgbe_eth_dev_ops;
3607c4158a5SRavi Kumar 
3610bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
3620bc212a8SStephen Hemminger 
3637c4158a5SRavi Kumar 	/* Multiqueue RSS */
3647c4158a5SRavi Kumar 	ret = axgbe_dev_rx_mq_config(dev);
3657c4158a5SRavi Kumar 	if (ret) {
3667c4158a5SRavi Kumar 		PMD_DRV_LOG(ERR, "Unable to config RX MQ\n");
3677c4158a5SRavi Kumar 		return ret;
3687c4158a5SRavi Kumar 	}
3697c4158a5SRavi Kumar 	ret = axgbe_phy_reset(pdata);
3707c4158a5SRavi Kumar 	if (ret) {
3717c4158a5SRavi Kumar 		PMD_DRV_LOG(ERR, "phy reset failed\n");
3727c4158a5SRavi Kumar 		return ret;
3737c4158a5SRavi Kumar 	}
3747c4158a5SRavi Kumar 	ret = pdata->hw_if.init(pdata);
3757c4158a5SRavi Kumar 	if (ret) {
3767c4158a5SRavi Kumar 		PMD_DRV_LOG(ERR, "dev_init failed\n");
3777c4158a5SRavi Kumar 		return ret;
3787c4158a5SRavi Kumar 	}
3797c4158a5SRavi Kumar 
3807c4158a5SRavi Kumar 	/* enable uio/vfio intr/eventfd mapping */
381d61138d4SHarman Kalra 	rte_intr_enable(pdata->pci_dev->intr_handle);
3827c4158a5SRavi Kumar 
3837c4158a5SRavi Kumar 	/* phy start*/
3847c4158a5SRavi Kumar 	pdata->phy_if.phy_start(pdata);
3858590b93dSRavi Kumar 	axgbe_dev_enable_tx(dev);
3868590b93dSRavi Kumar 	axgbe_dev_enable_rx(dev);
3877c4158a5SRavi Kumar 
3884693ae4aSJoyce Kong 	rte_bit_relaxed_clear32(AXGBE_STOPPED, &pdata->dev_state);
3894693ae4aSJoyce Kong 	rte_bit_relaxed_clear32(AXGBE_DOWN, &pdata->dev_state);
3901bb4a528SFerruh Yigit 
3911bb4a528SFerruh Yigit 	max_pkt_len = dev_data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
392295968d1SFerruh Yigit 	if ((dev_data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
393965b3127SSelwin Sebastian 				max_pkt_len > pdata->rx_buf_size)
394965b3127SSelwin Sebastian 		dev_data->scattered_rx = 1;
395965b3127SSelwin Sebastian 
396965b3127SSelwin Sebastian 	/*  Scatter Rx handling */
397965b3127SSelwin Sebastian 	if (dev_data->scattered_rx)
398965b3127SSelwin Sebastian 		dev->rx_pkt_burst = &eth_axgbe_recv_scattered_pkts;
399965b3127SSelwin Sebastian 	else
400965b3127SSelwin Sebastian 		dev->rx_pkt_burst = &axgbe_recv_pkts;
401965b3127SSelwin Sebastian 
4027c4158a5SRavi Kumar 	return 0;
4037c4158a5SRavi Kumar }
4047c4158a5SRavi Kumar 
4057c4158a5SRavi Kumar /* Stop device: disable rx and tx functions to allow for reconfiguring. */
40662024eb8SIvan Ilchenko static int
4077c4158a5SRavi Kumar axgbe_dev_stop(struct rte_eth_dev *dev)
4087c4158a5SRavi Kumar {
4097c4158a5SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
4107c4158a5SRavi Kumar 
4110bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
4120bc212a8SStephen Hemminger 
413d61138d4SHarman Kalra 	rte_intr_disable(pdata->pci_dev->intr_handle);
4147c4158a5SRavi Kumar 
4154693ae4aSJoyce Kong 	if (rte_bit_relaxed_get32(AXGBE_STOPPED, &pdata->dev_state))
41662024eb8SIvan Ilchenko 		return 0;
4177c4158a5SRavi Kumar 
4184693ae4aSJoyce Kong 	rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state);
4198590b93dSRavi Kumar 	axgbe_dev_disable_tx(dev);
4208590b93dSRavi Kumar 	axgbe_dev_disable_rx(dev);
4217c4158a5SRavi Kumar 
4227c4158a5SRavi Kumar 	pdata->phy_if.phy_stop(pdata);
4237c4158a5SRavi Kumar 	pdata->hw_if.exit(pdata);
4247c4158a5SRavi Kumar 	memset(&dev->data->dev_link, 0, sizeof(struct rte_eth_link));
4254693ae4aSJoyce Kong 	rte_bit_relaxed_set32(AXGBE_DOWN, &pdata->dev_state);
42662024eb8SIvan Ilchenko 
42762024eb8SIvan Ilchenko 	return 0;
4287c4158a5SRavi Kumar }
4297c4158a5SRavi Kumar 
4309039c812SAndrew Rybchenko static int
431fa3e0440SRavi Kumar axgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
432fa3e0440SRavi Kumar {
433fa3e0440SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
434fa3e0440SRavi Kumar 
4350bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
4360bc212a8SStephen Hemminger 
437fa3e0440SRavi Kumar 	AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 1);
4389039c812SAndrew Rybchenko 
4399039c812SAndrew Rybchenko 	return 0;
440fa3e0440SRavi Kumar }
441fa3e0440SRavi Kumar 
4429039c812SAndrew Rybchenko static int
443fa3e0440SRavi Kumar axgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
444fa3e0440SRavi Kumar {
445fa3e0440SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
446fa3e0440SRavi Kumar 
4470bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
4480bc212a8SStephen Hemminger 
449fa3e0440SRavi Kumar 	AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PR, 0);
4509039c812SAndrew Rybchenko 
4519039c812SAndrew Rybchenko 	return 0;
452fa3e0440SRavi Kumar }
453fa3e0440SRavi Kumar 
454ca041cd4SIvan Ilchenko static int
455fa3e0440SRavi Kumar axgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
456fa3e0440SRavi Kumar {
457fa3e0440SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
458fa3e0440SRavi Kumar 
4590bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
4600bc212a8SStephen Hemminger 
461fa3e0440SRavi Kumar 	if (AXGMAC_IOREAD_BITS(pdata, MAC_PFR, PM))
462ca041cd4SIvan Ilchenko 		return 0;
463fa3e0440SRavi Kumar 	AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, 1);
464ca041cd4SIvan Ilchenko 
465ca041cd4SIvan Ilchenko 	return 0;
466fa3e0440SRavi Kumar }
467fa3e0440SRavi Kumar 
468ca041cd4SIvan Ilchenko static int
469fa3e0440SRavi Kumar axgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
470fa3e0440SRavi Kumar {
471fa3e0440SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
472fa3e0440SRavi Kumar 
4730bc212a8SStephen Hemminger 	PMD_INIT_FUNC_TRACE();
4740bc212a8SStephen Hemminger 
475fa3e0440SRavi Kumar 	if (!AXGMAC_IOREAD_BITS(pdata, MAC_PFR, PM))
476ca041cd4SIvan Ilchenko 		return 0;
477fa3e0440SRavi Kumar 	AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, PM, 0);
478ca041cd4SIvan Ilchenko 
479ca041cd4SIvan Ilchenko 	return 0;
480fa3e0440SRavi Kumar }
481fa3e0440SRavi Kumar 
48249a5e622SChandu Babu N static int
48349a5e622SChandu Babu N axgbe_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
48449a5e622SChandu Babu N {
48549a5e622SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
48649a5e622SChandu Babu N 
48749a5e622SChandu Babu N 	/* Set Default MAC Addr */
48849a5e622SChandu Babu N 	axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, 0);
48949a5e622SChandu Babu N 
49049a5e622SChandu Babu N 	return 0;
49149a5e622SChandu Babu N }
49249a5e622SChandu Babu N 
49349a5e622SChandu Babu N static int
49449a5e622SChandu Babu N axgbe_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
49549a5e622SChandu Babu N 			      uint32_t index, uint32_t pool __rte_unused)
49649a5e622SChandu Babu N {
49749a5e622SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
49849a5e622SChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
49949a5e622SChandu Babu N 
50049a5e622SChandu Babu N 	if (index > hw_feat->addn_mac) {
50149a5e622SChandu Babu N 		PMD_DRV_LOG(ERR, "Invalid Index %d\n", index);
50249a5e622SChandu Babu N 		return -EINVAL;
50349a5e622SChandu Babu N 	}
50449a5e622SChandu Babu N 	axgbe_set_mac_addn_addr(pdata, (u8 *)mac_addr, index);
50549a5e622SChandu Babu N 	return 0;
50649a5e622SChandu Babu N }
50749a5e622SChandu Babu N 
50876d7664dSChandu Babu N static int
50976d7664dSChandu Babu N axgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
51076d7664dSChandu Babu N 			  struct rte_eth_rss_reta_entry64 *reta_conf,
51176d7664dSChandu Babu N 			  uint16_t reta_size)
51276d7664dSChandu Babu N {
51376d7664dSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
51476d7664dSChandu Babu N 	unsigned int i, idx, shift;
51576d7664dSChandu Babu N 	int ret;
51676d7664dSChandu Babu N 
51776d7664dSChandu Babu N 	if (!pdata->rss_enable) {
51876d7664dSChandu Babu N 		PMD_DRV_LOG(ERR, "RSS not enabled\n");
51976d7664dSChandu Babu N 		return -ENOTSUP;
52076d7664dSChandu Babu N 	}
52176d7664dSChandu Babu N 
52276d7664dSChandu Babu N 	if (reta_size == 0 || reta_size > AXGBE_RSS_MAX_TABLE_SIZE) {
52376d7664dSChandu Babu N 		PMD_DRV_LOG(ERR, "reta_size %d is not supported\n", reta_size);
52476d7664dSChandu Babu N 		return -EINVAL;
52576d7664dSChandu Babu N 	}
52676d7664dSChandu Babu N 
52776d7664dSChandu Babu N 	for (i = 0; i < reta_size; i++) {
528295968d1SFerruh Yigit 		idx = i / RTE_ETH_RETA_GROUP_SIZE;
529295968d1SFerruh Yigit 		shift = i % RTE_ETH_RETA_GROUP_SIZE;
53076d7664dSChandu Babu N 		if ((reta_conf[idx].mask & (1ULL << shift)) == 0)
53176d7664dSChandu Babu N 			continue;
53276d7664dSChandu Babu N 		pdata->rss_table[i] = reta_conf[idx].reta[shift];
53376d7664dSChandu Babu N 	}
53476d7664dSChandu Babu N 
53576d7664dSChandu Babu N 	/* Program the lookup table */
53676d7664dSChandu Babu N 	ret = axgbe_write_rss_lookup_table(pdata);
53776d7664dSChandu Babu N 	return ret;
53876d7664dSChandu Babu N }
53976d7664dSChandu Babu N 
54076d7664dSChandu Babu N static int
54176d7664dSChandu Babu N axgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
54276d7664dSChandu Babu N 			 struct rte_eth_rss_reta_entry64 *reta_conf,
54376d7664dSChandu Babu N 			 uint16_t reta_size)
54476d7664dSChandu Babu N {
54576d7664dSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
54676d7664dSChandu Babu N 	unsigned int i, idx, shift;
54776d7664dSChandu Babu N 
54876d7664dSChandu Babu N 	if (!pdata->rss_enable) {
54976d7664dSChandu Babu N 		PMD_DRV_LOG(ERR, "RSS not enabled\n");
55076d7664dSChandu Babu N 		return -ENOTSUP;
55176d7664dSChandu Babu N 	}
55276d7664dSChandu Babu N 
55376d7664dSChandu Babu N 	if (reta_size == 0 || reta_size > AXGBE_RSS_MAX_TABLE_SIZE) {
55476d7664dSChandu Babu N 		PMD_DRV_LOG(ERR, "reta_size %d is not supported\n", reta_size);
55576d7664dSChandu Babu N 		return -EINVAL;
55676d7664dSChandu Babu N 	}
55776d7664dSChandu Babu N 
55876d7664dSChandu Babu N 	for (i = 0; i < reta_size; i++) {
559295968d1SFerruh Yigit 		idx = i / RTE_ETH_RETA_GROUP_SIZE;
560295968d1SFerruh Yigit 		shift = i % RTE_ETH_RETA_GROUP_SIZE;
56176d7664dSChandu Babu N 		if ((reta_conf[idx].mask & (1ULL << shift)) == 0)
56276d7664dSChandu Babu N 			continue;
56376d7664dSChandu Babu N 		reta_conf[idx].reta[shift] = pdata->rss_table[i];
56476d7664dSChandu Babu N 	}
56576d7664dSChandu Babu N 	return 0;
56676d7664dSChandu Babu N }
56776d7664dSChandu Babu N 
56876d7664dSChandu Babu N static int
56976d7664dSChandu Babu N axgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
57076d7664dSChandu Babu N 			  struct rte_eth_rss_conf *rss_conf)
57176d7664dSChandu Babu N {
57276d7664dSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
57376d7664dSChandu Babu N 	int ret;
57476d7664dSChandu Babu N 
57576d7664dSChandu Babu N 	if (!pdata->rss_enable) {
57676d7664dSChandu Babu N 		PMD_DRV_LOG(ERR, "RSS not enabled\n");
57776d7664dSChandu Babu N 		return -ENOTSUP;
57876d7664dSChandu Babu N 	}
57976d7664dSChandu Babu N 
58076d7664dSChandu Babu N 	if (rss_conf == NULL) {
58176d7664dSChandu Babu N 		PMD_DRV_LOG(ERR, "rss_conf value isn't valid\n");
58276d7664dSChandu Babu N 		return -EINVAL;
58376d7664dSChandu Babu N 	}
58476d7664dSChandu Babu N 
58576d7664dSChandu Babu N 	if (rss_conf->rss_key != NULL &&
58676d7664dSChandu Babu N 	    rss_conf->rss_key_len == AXGBE_RSS_HASH_KEY_SIZE) {
58776d7664dSChandu Babu N 		rte_memcpy(pdata->rss_key, rss_conf->rss_key,
58876d7664dSChandu Babu N 		       AXGBE_RSS_HASH_KEY_SIZE);
58976d7664dSChandu Babu N 		/* Program the hash key */
59076d7664dSChandu Babu N 		ret = axgbe_write_rss_hash_key(pdata);
59176d7664dSChandu Babu N 		if (ret != 0)
59276d7664dSChandu Babu N 			return ret;
59376d7664dSChandu Babu N 	}
59476d7664dSChandu Babu N 
59576d7664dSChandu Babu N 	pdata->rss_hf = rss_conf->rss_hf & AXGBE_RSS_OFFLOAD;
59676d7664dSChandu Babu N 
597295968d1SFerruh Yigit 	if (pdata->rss_hf & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6))
59876d7664dSChandu Babu N 		AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, IP2TE, 1);
59976d7664dSChandu Babu N 	if (pdata->rss_hf &
600295968d1SFerruh Yigit 	    (RTE_ETH_RSS_NONFRAG_IPV4_TCP | RTE_ETH_RSS_NONFRAG_IPV6_TCP))
60176d7664dSChandu Babu N 		AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, TCP4TE, 1);
60276d7664dSChandu Babu N 	if (pdata->rss_hf &
603295968d1SFerruh Yigit 	    (RTE_ETH_RSS_NONFRAG_IPV4_UDP | RTE_ETH_RSS_NONFRAG_IPV6_UDP))
60476d7664dSChandu Babu N 		AXGMAC_SET_BITS(pdata->rss_options, MAC_RSSCR, UDP4TE, 1);
60576d7664dSChandu Babu N 
60676d7664dSChandu Babu N 	/* Set the RSS options */
60776d7664dSChandu Babu N 	AXGMAC_IOWRITE(pdata, MAC_RSSCR, pdata->rss_options);
60876d7664dSChandu Babu N 
60976d7664dSChandu Babu N 	return 0;
61076d7664dSChandu Babu N }
61176d7664dSChandu Babu N 
61276d7664dSChandu Babu N static int
61376d7664dSChandu Babu N axgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
61476d7664dSChandu Babu N 			    struct rte_eth_rss_conf *rss_conf)
61576d7664dSChandu Babu N {
61676d7664dSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
61776d7664dSChandu Babu N 
61876d7664dSChandu Babu N 	if (!pdata->rss_enable) {
61976d7664dSChandu Babu N 		PMD_DRV_LOG(ERR, "RSS not enabled\n");
62076d7664dSChandu Babu N 		return -ENOTSUP;
62176d7664dSChandu Babu N 	}
62276d7664dSChandu Babu N 
62376d7664dSChandu Babu N 	if (rss_conf == NULL) {
62476d7664dSChandu Babu N 		PMD_DRV_LOG(ERR, "rss_conf value isn't valid\n");
62576d7664dSChandu Babu N 		return -EINVAL;
62676d7664dSChandu Babu N 	}
62776d7664dSChandu Babu N 
62876d7664dSChandu Babu N 	if (rss_conf->rss_key != NULL &&
62976d7664dSChandu Babu N 	    rss_conf->rss_key_len >= AXGBE_RSS_HASH_KEY_SIZE) {
63076d7664dSChandu Babu N 		rte_memcpy(rss_conf->rss_key, pdata->rss_key,
63176d7664dSChandu Babu N 		       AXGBE_RSS_HASH_KEY_SIZE);
63276d7664dSChandu Babu N 	}
63376d7664dSChandu Babu N 	rss_conf->rss_key_len = AXGBE_RSS_HASH_KEY_SIZE;
63476d7664dSChandu Babu N 	rss_conf->rss_hf = pdata->rss_hf;
63576d7664dSChandu Babu N 	return 0;
63676d7664dSChandu Babu N }
63776d7664dSChandu Babu N 
638bf403cfeSSelwin Sebastian static int
639bf403cfeSSelwin Sebastian axgbe_dev_reset(struct rte_eth_dev *dev)
640bf403cfeSSelwin Sebastian {
641bf403cfeSSelwin Sebastian 	int ret = 0;
642bf403cfeSSelwin Sebastian 
643bf403cfeSSelwin Sebastian 	ret = axgbe_dev_close(dev);
644bf403cfeSSelwin Sebastian 	if (ret)
645bf403cfeSSelwin Sebastian 		return ret;
646bf403cfeSSelwin Sebastian 
647bf403cfeSSelwin Sebastian 	ret = eth_axgbe_dev_init(dev);
648bf403cfeSSelwin Sebastian 
649bf403cfeSSelwin Sebastian 	return ret;
650bf403cfeSSelwin Sebastian }
651bf403cfeSSelwin Sebastian 
65249a5e622SChandu Babu N static void
65349a5e622SChandu Babu N axgbe_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
65449a5e622SChandu Babu N {
65549a5e622SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
65649a5e622SChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
65749a5e622SChandu Babu N 
65849a5e622SChandu Babu N 	if (index > hw_feat->addn_mac) {
65949a5e622SChandu Babu N 		PMD_DRV_LOG(ERR, "Invalid Index %d\n", index);
66049a5e622SChandu Babu N 		return;
66149a5e622SChandu Babu N 	}
66249a5e622SChandu Babu N 	axgbe_set_mac_addn_addr(pdata, NULL, index);
66349a5e622SChandu Babu N }
66449a5e622SChandu Babu N 
66549a5e622SChandu Babu N static int
66649a5e622SChandu Babu N axgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
66749a5e622SChandu Babu N 				      struct rte_ether_addr *mc_addr_set,
66849a5e622SChandu Babu N 				      uint32_t nb_mc_addr)
66949a5e622SChandu Babu N {
67049a5e622SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
67149a5e622SChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
67249a5e622SChandu Babu N 	uint32_t index = 1; /* 0 is always default mac */
67349a5e622SChandu Babu N 	uint32_t i;
67449a5e622SChandu Babu N 
67549a5e622SChandu Babu N 	if (nb_mc_addr > hw_feat->addn_mac) {
67649a5e622SChandu Babu N 		PMD_DRV_LOG(ERR, "Invalid Index %d\n", nb_mc_addr);
67749a5e622SChandu Babu N 		return -EINVAL;
67849a5e622SChandu Babu N 	}
67949a5e622SChandu Babu N 
68049a5e622SChandu Babu N 	/* clear unicast addresses */
68149a5e622SChandu Babu N 	for (i = 1; i < hw_feat->addn_mac; i++) {
68249a5e622SChandu Babu N 		if (rte_is_zero_ether_addr(&dev->data->mac_addrs[i]))
68349a5e622SChandu Babu N 			continue;
68449a5e622SChandu Babu N 		memset(&dev->data->mac_addrs[i], 0,
68549a5e622SChandu Babu N 		       sizeof(struct rte_ether_addr));
68649a5e622SChandu Babu N 	}
68749a5e622SChandu Babu N 
68849a5e622SChandu Babu N 	while (nb_mc_addr--)
68949a5e622SChandu Babu N 		axgbe_set_mac_addn_addr(pdata, (u8 *)mc_addr_set++, index++);
69049a5e622SChandu Babu N 
69149a5e622SChandu Babu N 	return 0;
69249a5e622SChandu Babu N }
69349a5e622SChandu Babu N 
694e01d9b2eSChandu Babu N static int
695e01d9b2eSChandu Babu N axgbe_dev_uc_hash_table_set(struct rte_eth_dev *dev,
696e01d9b2eSChandu Babu N 			    struct rte_ether_addr *mac_addr, uint8_t add)
697e01d9b2eSChandu Babu N {
698e01d9b2eSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
699e01d9b2eSChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
700e01d9b2eSChandu Babu N 
701e01d9b2eSChandu Babu N 	if (!hw_feat->hash_table_size) {
702e01d9b2eSChandu Babu N 		PMD_DRV_LOG(ERR, "MAC Hash Table not supported\n");
703e01d9b2eSChandu Babu N 		return -ENOTSUP;
704e01d9b2eSChandu Babu N 	}
705e01d9b2eSChandu Babu N 
706e01d9b2eSChandu Babu N 	axgbe_set_mac_hash_table(pdata, (u8 *)mac_addr, add);
707e01d9b2eSChandu Babu N 
708e01d9b2eSChandu Babu N 	if (pdata->uc_hash_mac_addr > 0) {
709e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
710e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
711e01d9b2eSChandu Babu N 	} else {
712e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 0);
713e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0);
714e01d9b2eSChandu Babu N 	}
715e01d9b2eSChandu Babu N 	return 0;
716e01d9b2eSChandu Babu N }
717e01d9b2eSChandu Babu N 
718e01d9b2eSChandu Babu N static int
719e01d9b2eSChandu Babu N axgbe_dev_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t add)
720e01d9b2eSChandu Babu N {
721e01d9b2eSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
722e01d9b2eSChandu Babu N 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
723e01d9b2eSChandu Babu N 	uint32_t index;
724e01d9b2eSChandu Babu N 
725e01d9b2eSChandu Babu N 	if (!hw_feat->hash_table_size) {
726e01d9b2eSChandu Babu N 		PMD_DRV_LOG(ERR, "MAC Hash Table not supported\n");
727e01d9b2eSChandu Babu N 		return -ENOTSUP;
728e01d9b2eSChandu Babu N 	}
729e01d9b2eSChandu Babu N 
730e01d9b2eSChandu Babu N 	for (index = 0; index < pdata->hash_table_count; index++) {
731e01d9b2eSChandu Babu N 		if (add)
732e01d9b2eSChandu Babu N 			pdata->uc_hash_table[index] = ~0;
733e01d9b2eSChandu Babu N 		else
734e01d9b2eSChandu Babu N 			pdata->uc_hash_table[index] = 0;
735e01d9b2eSChandu Babu N 
736e01d9b2eSChandu Babu N 		PMD_DRV_LOG(DEBUG, "%s MAC hash table at Index %#x\n",
737e01d9b2eSChandu Babu N 			    add ? "set" : "clear", index);
738e01d9b2eSChandu Babu N 
739e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE(pdata, MAC_HTR(index),
740e01d9b2eSChandu Babu N 			       pdata->uc_hash_table[index]);
741e01d9b2eSChandu Babu N 	}
742e01d9b2eSChandu Babu N 
743e01d9b2eSChandu Babu N 	if (add) {
744e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 1);
745e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 1);
746e01d9b2eSChandu Babu N 	} else {
747e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HPF, 0);
748e01d9b2eSChandu Babu N 		AXGMAC_IOWRITE_BITS(pdata, MAC_PFR, HUC, 0);
749e01d9b2eSChandu Babu N 	}
750e01d9b2eSChandu Babu N 	return 0;
751e01d9b2eSChandu Babu N }
752e01d9b2eSChandu Babu N 
75344d45ffeSRavi Kumar /* return 0 means link status changed, -1 means not changed */
75444d45ffeSRavi Kumar static int
75544d45ffeSRavi Kumar axgbe_dev_link_update(struct rte_eth_dev *dev,
75644d45ffeSRavi Kumar 		      int wait_to_complete __rte_unused)
75744d45ffeSRavi Kumar {
75844d45ffeSRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
75944d45ffeSRavi Kumar 	struct rte_eth_link link;
76044d45ffeSRavi Kumar 	int ret = 0;
76144d45ffeSRavi Kumar 
76244d45ffeSRavi Kumar 	PMD_INIT_FUNC_TRACE();
76344d45ffeSRavi Kumar 	rte_delay_ms(800);
76444d45ffeSRavi Kumar 
76544d45ffeSRavi Kumar 	pdata->phy_if.phy_status(pdata);
76644d45ffeSRavi Kumar 
76744d45ffeSRavi Kumar 	memset(&link, 0, sizeof(struct rte_eth_link));
76844d45ffeSRavi Kumar 	link.link_duplex = pdata->phy.duplex;
76944d45ffeSRavi Kumar 	link.link_status = pdata->phy_link;
77044d45ffeSRavi Kumar 	link.link_speed = pdata->phy_speed;
77144d45ffeSRavi Kumar 	link.link_autoneg = !(dev->data->dev_conf.link_speeds &
772295968d1SFerruh Yigit 			      RTE_ETH_LINK_SPEED_FIXED);
77344d45ffeSRavi Kumar 	ret = rte_eth_linkstatus_set(dev, &link);
77444d45ffeSRavi Kumar 	if (ret == -1)
77544d45ffeSRavi Kumar 		PMD_DRV_LOG(ERR, "No change in link status\n");
77644d45ffeSRavi Kumar 
77744d45ffeSRavi Kumar 	return ret;
77844d45ffeSRavi Kumar }
77944d45ffeSRavi Kumar 
780df4867cdSChandu Babu N static int
781df4867cdSChandu Babu N axgbe_dev_get_regs(struct rte_eth_dev *dev, struct rte_dev_reg_info *regs)
782df4867cdSChandu Babu N {
783df4867cdSChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
784df4867cdSChandu Babu N 
785df4867cdSChandu Babu N 	if (regs->data == NULL) {
786df4867cdSChandu Babu N 		regs->length = axgbe_regs_get_count(pdata);
787df4867cdSChandu Babu N 		regs->width = sizeof(uint32_t);
788df4867cdSChandu Babu N 		return 0;
789df4867cdSChandu Babu N 	}
790df4867cdSChandu Babu N 
791df4867cdSChandu Babu N 	/* Only full register dump is supported */
792df4867cdSChandu Babu N 	if (regs->length &&
793df4867cdSChandu Babu N 	    regs->length != (uint32_t)axgbe_regs_get_count(pdata))
794df4867cdSChandu Babu N 		return -ENOTSUP;
795df4867cdSChandu Babu N 
796df4867cdSChandu Babu N 	regs->version = pdata->pci_dev->id.vendor_id << 16 |
797df4867cdSChandu Babu N 			pdata->pci_dev->id.device_id;
798df4867cdSChandu Babu N 	axgbe_regs_dump(pdata, regs->data);
799df4867cdSChandu Babu N 	return 0;
800df4867cdSChandu Babu N }
8019d1ef6b2SChandu Babu N static void axgbe_read_mmc_stats(struct axgbe_port *pdata)
8029d1ef6b2SChandu Babu N {
8039d1ef6b2SChandu Babu N 	struct axgbe_mmc_stats *stats = &pdata->mmc_stats;
8049d1ef6b2SChandu Babu N 
8059d1ef6b2SChandu Babu N 	/* Freeze counters */
8069d1ef6b2SChandu Babu N 	AXGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 1);
8079d1ef6b2SChandu Babu N 
8089d1ef6b2SChandu Babu N 	/* Tx counters */
8099d1ef6b2SChandu Babu N 	stats->txoctetcount_gb +=
8109d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_LO);
8119d1ef6b2SChandu Babu N 	stats->txoctetcount_gb +=
8129d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_GB_HI) << 32);
8139d1ef6b2SChandu Babu N 
8149d1ef6b2SChandu Babu N 	stats->txframecount_gb +=
8159d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_LO);
8169d1ef6b2SChandu Babu N 	stats->txframecount_gb +=
8179d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_GB_HI) << 32);
8189d1ef6b2SChandu Babu N 
8199d1ef6b2SChandu Babu N 	stats->txbroadcastframes_g +=
8209d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_LO);
8219d1ef6b2SChandu Babu N 	stats->txbroadcastframes_g +=
8229d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_G_HI) << 32);
8239d1ef6b2SChandu Babu N 
8249d1ef6b2SChandu Babu N 	stats->txmulticastframes_g +=
8259d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_LO);
8269d1ef6b2SChandu Babu N 	stats->txmulticastframes_g +=
8279d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_G_HI) << 32);
8289d1ef6b2SChandu Babu N 
8299d1ef6b2SChandu Babu N 	stats->tx64octets_gb +=
8309d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_LO);
8319d1ef6b2SChandu Babu N 	stats->tx64octets_gb +=
8329d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX64OCTETS_GB_HI) << 32);
8339d1ef6b2SChandu Babu N 
8349d1ef6b2SChandu Babu N 	stats->tx65to127octets_gb +=
8359d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_LO);
8369d1ef6b2SChandu Babu N 	stats->tx65to127octets_gb +=
8379d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX65TO127OCTETS_GB_HI) << 32);
8389d1ef6b2SChandu Babu N 
8399d1ef6b2SChandu Babu N 	stats->tx128to255octets_gb +=
8409d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_LO);
8419d1ef6b2SChandu Babu N 	stats->tx128to255octets_gb +=
8429d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX128TO255OCTETS_GB_HI) << 32);
8439d1ef6b2SChandu Babu N 
8449d1ef6b2SChandu Babu N 	stats->tx256to511octets_gb +=
8459d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_LO);
8469d1ef6b2SChandu Babu N 	stats->tx256to511octets_gb +=
8479d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX256TO511OCTETS_GB_HI) << 32);
8489d1ef6b2SChandu Babu N 
8499d1ef6b2SChandu Babu N 	stats->tx512to1023octets_gb +=
8509d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_LO);
8519d1ef6b2SChandu Babu N 	stats->tx512to1023octets_gb +=
8529d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX512TO1023OCTETS_GB_HI) << 32);
8539d1ef6b2SChandu Babu N 
8549d1ef6b2SChandu Babu N 	stats->tx1024tomaxoctets_gb +=
8559d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_LO);
8569d1ef6b2SChandu Babu N 	stats->tx1024tomaxoctets_gb +=
8579d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TX1024TOMAXOCTETS_GB_HI) << 32);
8589d1ef6b2SChandu Babu N 
8599d1ef6b2SChandu Babu N 	stats->txunicastframes_gb +=
8609d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_LO);
8619d1ef6b2SChandu Babu N 	stats->txunicastframes_gb +=
8629d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXUNICASTFRAMES_GB_HI) << 32);
8639d1ef6b2SChandu Babu N 
8649d1ef6b2SChandu Babu N 	stats->txmulticastframes_gb +=
8659d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_LO);
8669d1ef6b2SChandu Babu N 	stats->txmulticastframes_gb +=
8679d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXMULTICASTFRAMES_GB_HI) << 32);
8689d1ef6b2SChandu Babu N 
8699d1ef6b2SChandu Babu N 	stats->txbroadcastframes_g +=
8709d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_LO);
8719d1ef6b2SChandu Babu N 	stats->txbroadcastframes_g +=
8729d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXBROADCASTFRAMES_GB_HI) << 32);
8739d1ef6b2SChandu Babu N 
8749d1ef6b2SChandu Babu N 	stats->txunderflowerror +=
8759d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_LO);
8769d1ef6b2SChandu Babu N 	stats->txunderflowerror +=
8779d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXUNDERFLOWERROR_HI) << 32);
8789d1ef6b2SChandu Babu N 
8799d1ef6b2SChandu Babu N 	stats->txoctetcount_g +=
8809d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_LO);
8819d1ef6b2SChandu Babu N 	stats->txoctetcount_g +=
8829d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXOCTETCOUNT_G_HI) << 32);
8839d1ef6b2SChandu Babu N 
8849d1ef6b2SChandu Babu N 	stats->txframecount_g +=
8859d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_LO);
8869d1ef6b2SChandu Babu N 	stats->txframecount_g +=
8879d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXFRAMECOUNT_G_HI) << 32);
8889d1ef6b2SChandu Babu N 
8899d1ef6b2SChandu Babu N 	stats->txpauseframes +=
8909d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_LO);
8919d1ef6b2SChandu Babu N 	stats->txpauseframes +=
8929d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXPAUSEFRAMES_HI) << 32);
8939d1ef6b2SChandu Babu N 
8949d1ef6b2SChandu Babu N 	stats->txvlanframes_g +=
8959d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_LO);
8969d1ef6b2SChandu Babu N 	stats->txvlanframes_g +=
8979d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_TXVLANFRAMES_G_HI) << 32);
8989d1ef6b2SChandu Babu N 
8999d1ef6b2SChandu Babu N 	/* Rx counters */
9009d1ef6b2SChandu Babu N 	stats->rxframecount_gb +=
9019d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_LO);
9029d1ef6b2SChandu Babu N 	stats->rxframecount_gb +=
9039d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXFRAMECOUNT_GB_HI) << 32);
9049d1ef6b2SChandu Babu N 
9059d1ef6b2SChandu Babu N 	stats->rxoctetcount_gb +=
9069d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_LO);
9079d1ef6b2SChandu Babu N 	stats->rxoctetcount_gb +=
9089d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_GB_HI) << 32);
9099d1ef6b2SChandu Babu N 
9109d1ef6b2SChandu Babu N 	stats->rxoctetcount_g +=
9119d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_LO);
9129d1ef6b2SChandu Babu N 	stats->rxoctetcount_g +=
9139d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOCTETCOUNT_G_HI) << 32);
9149d1ef6b2SChandu Babu N 
9159d1ef6b2SChandu Babu N 	stats->rxbroadcastframes_g +=
9169d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_LO);
9179d1ef6b2SChandu Babu N 	stats->rxbroadcastframes_g +=
9189d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXBROADCASTFRAMES_G_HI) << 32);
9199d1ef6b2SChandu Babu N 
9209d1ef6b2SChandu Babu N 	stats->rxmulticastframes_g +=
9219d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_LO);
9229d1ef6b2SChandu Babu N 	stats->rxmulticastframes_g +=
9239d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXMULTICASTFRAMES_G_HI) << 32);
9249d1ef6b2SChandu Babu N 
9259d1ef6b2SChandu Babu N 	stats->rxcrcerror +=
9269d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXCRCERROR_LO);
9279d1ef6b2SChandu Babu N 	stats->rxcrcerror +=
9289d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXCRCERROR_HI) << 32);
9299d1ef6b2SChandu Babu N 
9309d1ef6b2SChandu Babu N 	stats->rxrunterror +=
9319d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXRUNTERROR);
9329d1ef6b2SChandu Babu N 
9339d1ef6b2SChandu Babu N 	stats->rxjabbererror +=
9349d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXJABBERERROR);
9359d1ef6b2SChandu Babu N 
9369d1ef6b2SChandu Babu N 	stats->rxundersize_g +=
9379d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXUNDERSIZE_G);
9389d1ef6b2SChandu Babu N 
9399d1ef6b2SChandu Babu N 	stats->rxoversize_g +=
9409d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXOVERSIZE_G);
9419d1ef6b2SChandu Babu N 
9429d1ef6b2SChandu Babu N 	stats->rx64octets_gb +=
9439d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_LO);
9449d1ef6b2SChandu Babu N 	stats->rx64octets_gb +=
9459d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX64OCTETS_GB_HI) << 32);
9469d1ef6b2SChandu Babu N 
9479d1ef6b2SChandu Babu N 	stats->rx65to127octets_gb +=
9489d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_LO);
9499d1ef6b2SChandu Babu N 	stats->rx65to127octets_gb +=
9509d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX65TO127OCTETS_GB_HI) << 32);
9519d1ef6b2SChandu Babu N 
9529d1ef6b2SChandu Babu N 	stats->rx128to255octets_gb +=
9539d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_LO);
9549d1ef6b2SChandu Babu N 	stats->rx128to255octets_gb +=
9559d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX128TO255OCTETS_GB_HI) << 32);
9569d1ef6b2SChandu Babu N 
9579d1ef6b2SChandu Babu N 	stats->rx256to511octets_gb +=
9589d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_LO);
9599d1ef6b2SChandu Babu N 	stats->rx256to511octets_gb +=
9609d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX256TO511OCTETS_GB_HI) << 32);
9619d1ef6b2SChandu Babu N 
9629d1ef6b2SChandu Babu N 	stats->rx512to1023octets_gb +=
9639d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_LO);
9649d1ef6b2SChandu Babu N 	stats->rx512to1023octets_gb +=
9659d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX512TO1023OCTETS_GB_HI) << 32);
9669d1ef6b2SChandu Babu N 
9679d1ef6b2SChandu Babu N 	stats->rx1024tomaxoctets_gb +=
9689d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_LO);
9699d1ef6b2SChandu Babu N 	stats->rx1024tomaxoctets_gb +=
9709d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RX1024TOMAXOCTETS_GB_HI) << 32);
9719d1ef6b2SChandu Babu N 
9729d1ef6b2SChandu Babu N 	stats->rxunicastframes_g +=
9739d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_LO);
9749d1ef6b2SChandu Babu N 	stats->rxunicastframes_g +=
9759d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXUNICASTFRAMES_G_HI) << 32);
9769d1ef6b2SChandu Babu N 
9779d1ef6b2SChandu Babu N 	stats->rxlengtherror +=
9789d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_LO);
9799d1ef6b2SChandu Babu N 	stats->rxlengtherror +=
9809d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXLENGTHERROR_HI) << 32);
9819d1ef6b2SChandu Babu N 
9829d1ef6b2SChandu Babu N 	stats->rxoutofrangetype +=
9839d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_LO);
9849d1ef6b2SChandu Babu N 	stats->rxoutofrangetype +=
9859d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXOUTOFRANGETYPE_HI) << 32);
9869d1ef6b2SChandu Babu N 
9879d1ef6b2SChandu Babu N 	stats->rxpauseframes +=
9889d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_LO);
9899d1ef6b2SChandu Babu N 	stats->rxpauseframes +=
9909d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXPAUSEFRAMES_HI) << 32);
9919d1ef6b2SChandu Babu N 
9929d1ef6b2SChandu Babu N 	stats->rxfifooverflow +=
9939d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_LO);
9949d1ef6b2SChandu Babu N 	stats->rxfifooverflow +=
9959d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXFIFOOVERFLOW_HI) << 32);
9969d1ef6b2SChandu Babu N 
9979d1ef6b2SChandu Babu N 	stats->rxvlanframes_gb +=
9989d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_LO);
9999d1ef6b2SChandu Babu N 	stats->rxvlanframes_gb +=
10009d1ef6b2SChandu Babu N 	((uint64_t)AXGMAC_IOREAD(pdata, MMC_RXVLANFRAMES_GB_HI) << 32);
10019d1ef6b2SChandu Babu N 
10029d1ef6b2SChandu Babu N 	stats->rxwatchdogerror +=
10039d1ef6b2SChandu Babu N 		AXGMAC_IOREAD(pdata, MMC_RXWATCHDOGERROR);
10049d1ef6b2SChandu Babu N 
10059d1ef6b2SChandu Babu N 	/* Un-freeze counters */
10069d1ef6b2SChandu Babu N 	AXGMAC_IOWRITE_BITS(pdata, MMC_CR, MCF, 0);
10079d1ef6b2SChandu Babu N }
10089d1ef6b2SChandu Babu N 
10099d1ef6b2SChandu Babu N static int
10109d1ef6b2SChandu Babu N axgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
10119d1ef6b2SChandu Babu N 		     unsigned int n)
10129d1ef6b2SChandu Babu N {
10139d1ef6b2SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
10149d1ef6b2SChandu Babu N 	unsigned int i;
10159d1ef6b2SChandu Babu N 
1016*93041fd5SChengwen Feng 	if (n < AXGBE_XSTATS_COUNT)
1017*93041fd5SChengwen Feng 		return AXGBE_XSTATS_COUNT;
10189d1ef6b2SChandu Babu N 
10199d1ef6b2SChandu Babu N 	axgbe_read_mmc_stats(pdata);
10209d1ef6b2SChandu Babu N 
1021*93041fd5SChengwen Feng 	for (i = 0; i < AXGBE_XSTATS_COUNT; i++) {
10229d1ef6b2SChandu Babu N 		stats[i].id = i;
10239d1ef6b2SChandu Babu N 		stats[i].value = *(u64 *)((uint8_t *)&pdata->mmc_stats +
10249d1ef6b2SChandu Babu N 				axgbe_xstats_strings[i].offset);
10259d1ef6b2SChandu Babu N 	}
10269d1ef6b2SChandu Babu N 
1027*93041fd5SChengwen Feng 	return AXGBE_XSTATS_COUNT;
10289d1ef6b2SChandu Babu N }
10299d1ef6b2SChandu Babu N 
10309d1ef6b2SChandu Babu N static int
10319d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
10329d1ef6b2SChandu Babu N 			   struct rte_eth_xstat_name *xstats_names,
10339d1ef6b2SChandu Babu N 			   unsigned int n)
10349d1ef6b2SChandu Babu N {
10359d1ef6b2SChandu Babu N 	unsigned int i;
10369d1ef6b2SChandu Babu N 
10379d1ef6b2SChandu Babu N 	if (n >= AXGBE_XSTATS_COUNT && xstats_names) {
10389d1ef6b2SChandu Babu N 		for (i = 0; i < AXGBE_XSTATS_COUNT; ++i) {
10399d1ef6b2SChandu Babu N 			snprintf(xstats_names[i].name,
10409d1ef6b2SChandu Babu N 				 RTE_ETH_XSTATS_NAME_SIZE, "%s",
10419d1ef6b2SChandu Babu N 				 axgbe_xstats_strings[i].name);
10429d1ef6b2SChandu Babu N 		}
10439d1ef6b2SChandu Babu N 	}
10449d1ef6b2SChandu Babu N 
10459d1ef6b2SChandu Babu N 	return AXGBE_XSTATS_COUNT;
10469d1ef6b2SChandu Babu N }
10479d1ef6b2SChandu Babu N 
10489d1ef6b2SChandu Babu N static int
10499d1ef6b2SChandu Babu N axgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
10509d1ef6b2SChandu Babu N 			   uint64_t *values, unsigned int n)
10519d1ef6b2SChandu Babu N {
10529d1ef6b2SChandu Babu N 	unsigned int i;
10539d1ef6b2SChandu Babu N 	uint64_t values_copy[AXGBE_XSTATS_COUNT];
10549d1ef6b2SChandu Babu N 
10559d1ef6b2SChandu Babu N 	if (!ids) {
10569d1ef6b2SChandu Babu N 		struct axgbe_port *pdata = dev->data->dev_private;
10579d1ef6b2SChandu Babu N 
10589d1ef6b2SChandu Babu N 		if (n < AXGBE_XSTATS_COUNT)
10599d1ef6b2SChandu Babu N 			return AXGBE_XSTATS_COUNT;
10609d1ef6b2SChandu Babu N 
10619d1ef6b2SChandu Babu N 		axgbe_read_mmc_stats(pdata);
10629d1ef6b2SChandu Babu N 
10639d1ef6b2SChandu Babu N 		for (i = 0; i < AXGBE_XSTATS_COUNT; i++) {
10649d1ef6b2SChandu Babu N 			values[i] = *(u64 *)((uint8_t *)&pdata->mmc_stats +
10659d1ef6b2SChandu Babu N 					axgbe_xstats_strings[i].offset);
10669d1ef6b2SChandu Babu N 		}
10679d1ef6b2SChandu Babu N 
10689d1ef6b2SChandu Babu N 		return i;
10699d1ef6b2SChandu Babu N 	}
10709d1ef6b2SChandu Babu N 
10719d1ef6b2SChandu Babu N 	axgbe_dev_xstats_get_by_id(dev, NULL, values_copy, AXGBE_XSTATS_COUNT);
10729d1ef6b2SChandu Babu N 
10739d1ef6b2SChandu Babu N 	for (i = 0; i < n; i++) {
10749d1ef6b2SChandu Babu N 		if (ids[i] >= AXGBE_XSTATS_COUNT) {
10759d1ef6b2SChandu Babu N 			PMD_DRV_LOG(ERR, "id value isn't valid\n");
10769d1ef6b2SChandu Babu N 			return -1;
10779d1ef6b2SChandu Babu N 		}
10789d1ef6b2SChandu Babu N 		values[i] = values_copy[ids[i]];
10799d1ef6b2SChandu Babu N 	}
10809d1ef6b2SChandu Babu N 	return n;
10819d1ef6b2SChandu Babu N }
10829d1ef6b2SChandu Babu N 
10839d1ef6b2SChandu Babu N static int
10849d1ef6b2SChandu Babu N axgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
10859d1ef6b2SChandu Babu N 				 const uint64_t *ids,
10868c9f976fSAndrew Rybchenko 				 struct rte_eth_xstat_name *xstats_names,
10879d1ef6b2SChandu Babu N 				 unsigned int size)
10889d1ef6b2SChandu Babu N {
10899d1ef6b2SChandu Babu N 	struct rte_eth_xstat_name xstats_names_copy[AXGBE_XSTATS_COUNT];
10909d1ef6b2SChandu Babu N 	unsigned int i;
10919d1ef6b2SChandu Babu N 
10929d1ef6b2SChandu Babu N 	if (!ids)
10939d1ef6b2SChandu Babu N 		return axgbe_dev_xstats_get_names(dev, xstats_names, size);
10949d1ef6b2SChandu Babu N 
10959d1ef6b2SChandu Babu N 	axgbe_dev_xstats_get_names(dev, xstats_names_copy, size);
10969d1ef6b2SChandu Babu N 
10979d1ef6b2SChandu Babu N 	for (i = 0; i < size; i++) {
10989d1ef6b2SChandu Babu N 		if (ids[i] >= AXGBE_XSTATS_COUNT) {
10999d1ef6b2SChandu Babu N 			PMD_DRV_LOG(ERR, "id value isn't valid\n");
11009d1ef6b2SChandu Babu N 			return -1;
11019d1ef6b2SChandu Babu N 		}
11029d1ef6b2SChandu Babu N 		strcpy(xstats_names[i].name, xstats_names_copy[ids[i]].name);
11039d1ef6b2SChandu Babu N 	}
11049d1ef6b2SChandu Babu N 	return size;
11059d1ef6b2SChandu Babu N }
11069d1ef6b2SChandu Babu N 
11079d1ef6b2SChandu Babu N static int
11089d1ef6b2SChandu Babu N axgbe_dev_xstats_reset(struct rte_eth_dev *dev)
11099d1ef6b2SChandu Babu N {
11109d1ef6b2SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
11119d1ef6b2SChandu Babu N 	struct axgbe_mmc_stats *stats = &pdata->mmc_stats;
11129d1ef6b2SChandu Babu N 
11139d1ef6b2SChandu Babu N 	/* MMC registers are configured for reset on read */
11149d1ef6b2SChandu Babu N 	axgbe_read_mmc_stats(pdata);
11159d1ef6b2SChandu Babu N 
11169d1ef6b2SChandu Babu N 	/* Reset stats */
11179d1ef6b2SChandu Babu N 	memset(stats, 0, sizeof(*stats));
11189d1ef6b2SChandu Babu N 
11199d1ef6b2SChandu Babu N 	return 0;
11209d1ef6b2SChandu Babu N }
11219d1ef6b2SChandu Babu N 
11223e730511SRavi Kumar static int
11233e730511SRavi Kumar axgbe_dev_stats_get(struct rte_eth_dev *dev,
11243e730511SRavi Kumar 		    struct rte_eth_stats *stats)
11253e730511SRavi Kumar {
11263e730511SRavi Kumar 	struct axgbe_rx_queue *rxq;
11273e730511SRavi Kumar 	struct axgbe_tx_queue *txq;
11289d1ef6b2SChandu Babu N 	struct axgbe_port *pdata = dev->data->dev_private;
11299d1ef6b2SChandu Babu N 	struct axgbe_mmc_stats *mmc_stats = &pdata->mmc_stats;
11303e730511SRavi Kumar 	unsigned int i;
11313e730511SRavi Kumar 
11329d1ef6b2SChandu Babu N 	axgbe_read_mmc_stats(pdata);
11339d1ef6b2SChandu Babu N 
11349d1ef6b2SChandu Babu N 	stats->imissed = mmc_stats->rxfifooverflow;
11359d1ef6b2SChandu Babu N 
11363e730511SRavi Kumar 	for (i = 0; i < dev->data->nb_rx_queues; i++) {
11373e730511SRavi Kumar 		rxq = dev->data->rx_queues[i];
1138bf403cfeSSelwin Sebastian 		if (rxq) {
11393e730511SRavi Kumar 			stats->q_ipackets[i] = rxq->pkts;
11403e730511SRavi Kumar 			stats->ipackets += rxq->pkts;
11413e730511SRavi Kumar 			stats->q_ibytes[i] = rxq->bytes;
11423e730511SRavi Kumar 			stats->ibytes += rxq->bytes;
11439d1ef6b2SChandu Babu N 			stats->rx_nombuf += rxq->rx_mbuf_alloc_failed;
1144bf403cfeSSelwin Sebastian 			stats->q_errors[i] = rxq->errors
1145bf403cfeSSelwin Sebastian 				+ rxq->rx_mbuf_alloc_failed;
11469d1ef6b2SChandu Babu N 			stats->ierrors += rxq->errors;
1147bf403cfeSSelwin Sebastian 		} else {
1148bf403cfeSSelwin Sebastian 			PMD_DRV_LOG(DEBUG, "Rx queue not setup for port %d\n",
1149bf403cfeSSelwin Sebastian 					dev->data->port_id);
1150bf403cfeSSelwin Sebastian 		}
11513e730511SRavi Kumar 	}
11529d1ef6b2SChandu Babu N 
11533e730511SRavi Kumar 	for (i = 0; i < dev->data->nb_tx_queues; i++) {
11543e730511SRavi Kumar 		txq = dev->data->tx_queues[i];
1155bf403cfeSSelwin Sebastian 		if (txq) {
11563e730511SRavi Kumar 			stats->q_opackets[i] = txq->pkts;
11573e730511SRavi Kumar 			stats->opackets += txq->pkts;
11583e730511SRavi Kumar 			stats->q_obytes[i] = txq->bytes;
11593e730511SRavi Kumar 			stats->obytes += txq->bytes;
11609d1ef6b2SChandu Babu N 			stats->oerrors += txq->errors;
1161bf403cfeSSelwin Sebastian 		} else {
1162bf403cfeSSelwin Sebastian 			PMD_DRV_LOG(DEBUG, "Tx queue not setup for port %d\n",
1163bf403cfeSSelwin Sebastian 					dev->data->port_id);
1164bf403cfeSSelwin Sebastian 		}
11653e730511SRavi Kumar 	}
11663e730511SRavi Kumar 
11673e730511SRavi Kumar 	return 0;
11683e730511SRavi Kumar }
11693e730511SRavi Kumar 
11709970a9adSIgor Romanov static int
11713e730511SRavi Kumar axgbe_dev_stats_reset(struct rte_eth_dev *dev)
11723e730511SRavi Kumar {
11733e730511SRavi Kumar 	struct axgbe_rx_queue *rxq;
11743e730511SRavi Kumar 	struct axgbe_tx_queue *txq;
11753e730511SRavi Kumar 	unsigned int i;
11763e730511SRavi Kumar 
11773e730511SRavi Kumar 	for (i = 0; i < dev->data->nb_rx_queues; i++) {
11783e730511SRavi Kumar 		rxq = dev->data->rx_queues[i];
1179bf403cfeSSelwin Sebastian 		if (rxq) {
11803e730511SRavi Kumar 			rxq->pkts = 0;
11813e730511SRavi Kumar 			rxq->bytes = 0;
11823e730511SRavi Kumar 			rxq->errors = 0;
11839d1ef6b2SChandu Babu N 			rxq->rx_mbuf_alloc_failed = 0;
1184bf403cfeSSelwin Sebastian 		} else {
1185bf403cfeSSelwin Sebastian 			PMD_DRV_LOG(DEBUG, "Rx queue not setup for port %d\n",
1186bf403cfeSSelwin Sebastian 					dev->data->port_id);
1187bf403cfeSSelwin Sebastian 		}
11883e730511SRavi Kumar 	}
11893e730511SRavi Kumar 	for (i = 0; i < dev->data->nb_tx_queues; i++) {
11903e730511SRavi Kumar 		txq = dev->data->tx_queues[i];
1191bf403cfeSSelwin Sebastian 		if (txq) {
11923e730511SRavi Kumar 			txq->pkts = 0;
11933e730511SRavi Kumar 			txq->bytes = 0;
11943e730511SRavi Kumar 			txq->errors = 0;
1195bf403cfeSSelwin Sebastian 		} else {
1196bf403cfeSSelwin Sebastian 			PMD_DRV_LOG(DEBUG, "Tx queue not setup for port %d\n",
1197bf403cfeSSelwin Sebastian 					dev->data->port_id);
1198bf403cfeSSelwin Sebastian 		}
11993e730511SRavi Kumar 	}
12009970a9adSIgor Romanov 
12019970a9adSIgor Romanov 	return 0;
12023e730511SRavi Kumar }
12033e730511SRavi Kumar 
1204bdad90d1SIvan Ilchenko static int
1205cd8c7c7cSFerruh Yigit axgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
12069e890103SRavi Kumar {
12079e890103SRavi Kumar 	struct axgbe_port *pdata = dev->data->dev_private;
12089e890103SRavi Kumar 
12099e890103SRavi Kumar 	dev_info->max_rx_queues = pdata->rx_ring_count;
12109e890103SRavi Kumar 	dev_info->max_tx_queues = pdata->tx_ring_count;
12119e890103SRavi Kumar 	dev_info->min_rx_bufsize = AXGBE_RX_MIN_BUF_SIZE;
12129e890103SRavi Kumar 	dev_info->max_rx_pktlen = AXGBE_RX_MAX_BUF_SIZE;
121349a5e622SChandu Babu N 	dev_info->max_mac_addrs = pdata->hw_feat.addn_mac + 1;
1214e01d9b2eSChandu Babu N 	dev_info->max_hash_mac_addrs = pdata->hw_feat.hash_table_size;
1215295968d1SFerruh Yigit 	dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G;
12169e890103SRavi Kumar 
12179e890103SRavi Kumar 	dev_info->rx_offload_capa =
1218295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1219295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1220295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
1221295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1222295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_UDP_CKSUM  |
1223295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_TCP_CKSUM  |
1224295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_SCATTER	  |
1225295968d1SFerruh Yigit 		RTE_ETH_RX_OFFLOAD_KEEP_CRC;
12269e890103SRavi Kumar 
12279e890103SRavi Kumar 	dev_info->tx_offload_capa =
1228295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1229295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
1230295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_IPV4_CKSUM  |
1231295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_UDP_CKSUM   |
1232295968d1SFerruh Yigit 		RTE_ETH_TX_OFFLOAD_TCP_CKSUM;
12339e890103SRavi Kumar 
12349e890103SRavi Kumar 	if (pdata->hw_feat.rss) {
12359e890103SRavi Kumar 		dev_info->flow_type_rss_offloads = AXGBE_RSS_OFFLOAD;
12369e890103SRavi Kumar 		dev_info->reta_size = pdata->hw_feat.hash_table_size;
12379e890103SRavi Kumar 		dev_info->hash_key_size =  AXGBE_RSS_HASH_KEY_SIZE;
12389e890103SRavi Kumar 	}
12399e890103SRavi Kumar 
12409e890103SRavi Kumar 	dev_info->rx_desc_lim = rx_desc_lim;
12419e890103SRavi Kumar 	dev_info->tx_desc_lim = tx_desc_lim;
12429e890103SRavi Kumar 
12439e890103SRavi Kumar 	dev_info->default_rxconf = (struct rte_eth_rxconf) {
12449e890103SRavi Kumar 		.rx_free_thresh = AXGBE_RX_FREE_THRESH,
12459e890103SRavi Kumar 	};
12469e890103SRavi Kumar 
12479e890103SRavi Kumar 	dev_info->default_txconf = (struct rte_eth_txconf) {
12489e890103SRavi Kumar 		.tx_free_thresh = AXGBE_TX_FREE_THRESH,
12499e890103SRavi Kumar 	};
1250bdad90d1SIvan Ilchenko 
1251bdad90d1SIvan Ilchenko 	return 0;
12529e890103SRavi Kumar }
12539e890103SRavi Kumar 
1254cf97f33eSAmaranath Somalapuram static int
1255cf97f33eSAmaranath Somalapuram axgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1256cf97f33eSAmaranath Somalapuram {
1257cf97f33eSAmaranath Somalapuram 	struct axgbe_port *pdata = dev->data->dev_private;
1258cf97f33eSAmaranath Somalapuram 	struct xgbe_fc_info fc = pdata->fc;
1259cf97f33eSAmaranath Somalapuram 	unsigned int reg, reg_val = 0;
1260cf97f33eSAmaranath Somalapuram 
1261cf97f33eSAmaranath Somalapuram 	reg = MAC_Q0TFCR;
1262cf97f33eSAmaranath Somalapuram 	reg_val = AXGMAC_IOREAD(pdata, reg);
1263cf97f33eSAmaranath Somalapuram 	fc.low_water[0] =  AXGMAC_MTL_IOREAD_BITS(pdata, 0, MTL_Q_RQFCR, RFA);
1264cf97f33eSAmaranath Somalapuram 	fc.high_water[0] =  AXGMAC_MTL_IOREAD_BITS(pdata, 0, MTL_Q_RQFCR, RFD);
1265cf97f33eSAmaranath Somalapuram 	fc.pause_time[0] = AXGMAC_GET_BITS(reg_val, MAC_Q0TFCR, PT);
1266cf97f33eSAmaranath Somalapuram 	fc.autoneg = pdata->pause_autoneg;
1267cf97f33eSAmaranath Somalapuram 
1268cf97f33eSAmaranath Somalapuram 	if (pdata->rx_pause && pdata->tx_pause)
1269295968d1SFerruh Yigit 		fc.mode = RTE_ETH_FC_FULL;
1270cf97f33eSAmaranath Somalapuram 	else if (pdata->rx_pause)
1271295968d1SFerruh Yigit 		fc.mode = RTE_ETH_FC_RX_PAUSE;
1272cf97f33eSAmaranath Somalapuram 	else if (pdata->tx_pause)
1273295968d1SFerruh Yigit 		fc.mode = RTE_ETH_FC_TX_PAUSE;
1274cf97f33eSAmaranath Somalapuram 	else
1275295968d1SFerruh Yigit 		fc.mode = RTE_ETH_FC_NONE;
1276cf97f33eSAmaranath Somalapuram 
1277cf97f33eSAmaranath Somalapuram 	fc_conf->high_water =  (1024 + (fc.low_water[0] << 9)) / 1024;
1278cf97f33eSAmaranath Somalapuram 	fc_conf->low_water =  (1024 + (fc.high_water[0] << 9)) / 1024;
1279cf97f33eSAmaranath Somalapuram 	fc_conf->pause_time = fc.pause_time[0];
1280cf97f33eSAmaranath Somalapuram 	fc_conf->send_xon = fc.send_xon;
1281cf97f33eSAmaranath Somalapuram 	fc_conf->mode = fc.mode;
1282cf97f33eSAmaranath Somalapuram 
1283cf97f33eSAmaranath Somalapuram 	return 0;
1284cf97f33eSAmaranath Somalapuram }
1285cf97f33eSAmaranath Somalapuram 
1286cf97f33eSAmaranath Somalapuram static int
1287cf97f33eSAmaranath Somalapuram axgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1288cf97f33eSAmaranath Somalapuram {
1289cf97f33eSAmaranath Somalapuram 	struct axgbe_port *pdata = dev->data->dev_private;
1290cf97f33eSAmaranath Somalapuram 	struct xgbe_fc_info fc = pdata->fc;
1291cf97f33eSAmaranath Somalapuram 	unsigned int reg, reg_val = 0;
1292cf97f33eSAmaranath Somalapuram 	reg = MAC_Q0TFCR;
1293cf97f33eSAmaranath Somalapuram 
1294cf97f33eSAmaranath Somalapuram 	pdata->pause_autoneg = fc_conf->autoneg;
1295cf97f33eSAmaranath Somalapuram 	pdata->phy.pause_autoneg = pdata->pause_autoneg;
1296cf97f33eSAmaranath Somalapuram 	fc.send_xon = fc_conf->send_xon;
1297cf97f33eSAmaranath Somalapuram 	AXGMAC_MTL_IOWRITE_BITS(pdata, 0, MTL_Q_RQFCR, RFA,
1298cf97f33eSAmaranath Somalapuram 			AXGMAC_FLOW_CONTROL_VALUE(1024 * fc_conf->high_water));
1299cf97f33eSAmaranath Somalapuram 	AXGMAC_MTL_IOWRITE_BITS(pdata, 0, MTL_Q_RQFCR, RFD,
1300cf97f33eSAmaranath Somalapuram 			AXGMAC_FLOW_CONTROL_VALUE(1024 * fc_conf->low_water));
1301cf97f33eSAmaranath Somalapuram 	AXGMAC_SET_BITS(reg_val, MAC_Q0TFCR, PT, fc_conf->pause_time);
1302cf97f33eSAmaranath Somalapuram 	AXGMAC_IOWRITE(pdata, reg, reg_val);
1303cf97f33eSAmaranath Somalapuram 	fc.mode = fc_conf->mode;
1304cf97f33eSAmaranath Somalapuram 
1305295968d1SFerruh Yigit 	if (fc.mode == RTE_ETH_FC_FULL) {
1306cf97f33eSAmaranath Somalapuram 		pdata->tx_pause = 1;
1307cf97f33eSAmaranath Somalapuram 		pdata->rx_pause = 1;
1308295968d1SFerruh Yigit 	} else if (fc.mode == RTE_ETH_FC_RX_PAUSE) {
1309cf97f33eSAmaranath Somalapuram 		pdata->tx_pause = 0;
1310cf97f33eSAmaranath Somalapuram 		pdata->rx_pause = 1;
1311295968d1SFerruh Yigit 	} else if (fc.mode == RTE_ETH_FC_TX_PAUSE) {
1312cf97f33eSAmaranath Somalapuram 		pdata->tx_pause = 1;
1313cf97f33eSAmaranath Somalapuram 		pdata->rx_pause = 0;
1314cf97f33eSAmaranath Somalapuram 	} else {
1315cf97f33eSAmaranath Somalapuram 		pdata->tx_pause = 0;
1316cf97f33eSAmaranath Somalapuram 		pdata->rx_pause = 0;
1317cf97f33eSAmaranath Somalapuram 	}
1318cf97f33eSAmaranath Somalapuram 
1319cf97f33eSAmaranath Somalapuram 	if (pdata->tx_pause != (unsigned int)pdata->phy.tx_pause)
1320cf97f33eSAmaranath Somalapuram 		pdata->hw_if.config_tx_flow_control(pdata);
1321cf97f33eSAmaranath Somalapuram 
1322cf97f33eSAmaranath Somalapuram 	if (pdata->rx_pause != (unsigned int)pdata->phy.rx_pause)
1323cf97f33eSAmaranath Somalapuram 		pdata->hw_if.config_rx_flow_control(pdata);
1324cf97f33eSAmaranath Somalapuram 
1325cf97f33eSAmaranath Somalapuram 	pdata->hw_if.config_flow_control(pdata);
1326cf97f33eSAmaranath Somalapuram 	pdata->phy.tx_pause = pdata->tx_pause;
1327cf97f33eSAmaranath Somalapuram 	pdata->phy.rx_pause = pdata->rx_pause;
1328cf97f33eSAmaranath Somalapuram 
1329cf97f33eSAmaranath Somalapuram 	return 0;
1330cf97f33eSAmaranath Somalapuram }
1331cf97f33eSAmaranath Somalapuram 
1332e0543d4eSAmaranath Somalapuram static int
1333e0543d4eSAmaranath Somalapuram axgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
1334e0543d4eSAmaranath Somalapuram 		struct rte_eth_pfc_conf *pfc_conf)
1335e0543d4eSAmaranath Somalapuram {
1336e0543d4eSAmaranath Somalapuram 	struct axgbe_port *pdata = dev->data->dev_private;
1337e0543d4eSAmaranath Somalapuram 	struct xgbe_fc_info fc = pdata->fc;
1338e0543d4eSAmaranath Somalapuram 	uint8_t tc_num;
1339e0543d4eSAmaranath Somalapuram 
1340e0543d4eSAmaranath Somalapuram 	tc_num = pdata->pfc_map[pfc_conf->priority];
1341e0543d4eSAmaranath Somalapuram 
1342e0543d4eSAmaranath Somalapuram 	if (pfc_conf->priority >= pdata->hw_feat.tc_cnt) {
1343e0543d4eSAmaranath Somalapuram 		PMD_INIT_LOG(ERR, "Max supported  traffic class: %d\n",
1344e0543d4eSAmaranath Somalapuram 				pdata->hw_feat.tc_cnt);
1345e0543d4eSAmaranath Somalapuram 	return -EINVAL;
1346e0543d4eSAmaranath Somalapuram 	}
1347e0543d4eSAmaranath Somalapuram 
1348e0543d4eSAmaranath Somalapuram 	pdata->pause_autoneg = pfc_conf->fc.autoneg;
1349e0543d4eSAmaranath Somalapuram 	pdata->phy.pause_autoneg = pdata->pause_autoneg;
1350e0543d4eSAmaranath Somalapuram 	fc.send_xon = pfc_conf->fc.send_xon;
1351e0543d4eSAmaranath Somalapuram 	AXGMAC_MTL_IOWRITE_BITS(pdata, tc_num, MTL_Q_RQFCR, RFA,
1352e0543d4eSAmaranath Somalapuram 		AXGMAC_FLOW_CONTROL_VALUE(1024 * pfc_conf->fc.high_water));
1353e0543d4eSAmaranath Somalapuram 	AXGMAC_MTL_IOWRITE_BITS(pdata, tc_num, MTL_Q_RQFCR, RFD,
1354e0543d4eSAmaranath Somalapuram 		AXGMAC_FLOW_CONTROL_VALUE(1024 * pfc_conf->fc.low_water));
1355e0543d4eSAmaranath Somalapuram 
1356e0543d4eSAmaranath Somalapuram 	switch (tc_num) {
1357e0543d4eSAmaranath Somalapuram 	case 0:
1358e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R,
1359e0543d4eSAmaranath Somalapuram 				PSTC0, pfc_conf->fc.pause_time);
1360e0543d4eSAmaranath Somalapuram 		break;
1361e0543d4eSAmaranath Somalapuram 	case 1:
1362e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R,
1363e0543d4eSAmaranath Somalapuram 				PSTC1, pfc_conf->fc.pause_time);
1364e0543d4eSAmaranath Somalapuram 		break;
1365e0543d4eSAmaranath Somalapuram 	case 2:
1366e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R,
1367e0543d4eSAmaranath Somalapuram 				PSTC2, pfc_conf->fc.pause_time);
1368e0543d4eSAmaranath Somalapuram 		break;
1369e0543d4eSAmaranath Somalapuram 	case 3:
1370e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM0R,
1371e0543d4eSAmaranath Somalapuram 				PSTC3, pfc_conf->fc.pause_time);
1372e0543d4eSAmaranath Somalapuram 		break;
1373e0543d4eSAmaranath Somalapuram 	case 4:
1374e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R,
1375e0543d4eSAmaranath Somalapuram 				PSTC4, pfc_conf->fc.pause_time);
1376e0543d4eSAmaranath Somalapuram 		break;
1377e0543d4eSAmaranath Somalapuram 	case 5:
1378e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R,
1379e0543d4eSAmaranath Somalapuram 				PSTC5, pfc_conf->fc.pause_time);
1380e0543d4eSAmaranath Somalapuram 		break;
1381e0543d4eSAmaranath Somalapuram 	case 7:
1382e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R,
1383e0543d4eSAmaranath Somalapuram 				PSTC6, pfc_conf->fc.pause_time);
1384e0543d4eSAmaranath Somalapuram 		break;
1385e0543d4eSAmaranath Somalapuram 	case 6:
1386e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MTL_TCPM1R,
1387e0543d4eSAmaranath Somalapuram 				PSTC7, pfc_conf->fc.pause_time);
1388e0543d4eSAmaranath Somalapuram 		break;
1389e0543d4eSAmaranath Somalapuram 	}
1390e0543d4eSAmaranath Somalapuram 
1391e0543d4eSAmaranath Somalapuram 	fc.mode = pfc_conf->fc.mode;
1392e0543d4eSAmaranath Somalapuram 
1393295968d1SFerruh Yigit 	if (fc.mode == RTE_ETH_FC_FULL) {
1394e0543d4eSAmaranath Somalapuram 		pdata->tx_pause = 1;
1395e0543d4eSAmaranath Somalapuram 		pdata->rx_pause = 1;
1396e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 1);
1397295968d1SFerruh Yigit 	} else if (fc.mode == RTE_ETH_FC_RX_PAUSE) {
1398e0543d4eSAmaranath Somalapuram 		pdata->tx_pause = 0;
1399e0543d4eSAmaranath Somalapuram 		pdata->rx_pause = 1;
1400e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 1);
1401295968d1SFerruh Yigit 	} else if (fc.mode == RTE_ETH_FC_TX_PAUSE) {
1402e0543d4eSAmaranath Somalapuram 		pdata->tx_pause = 1;
1403e0543d4eSAmaranath Somalapuram 		pdata->rx_pause = 0;
1404e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0);
1405e0543d4eSAmaranath Somalapuram 	} else {
1406e0543d4eSAmaranath Somalapuram 		pdata->tx_pause = 0;
1407e0543d4eSAmaranath Somalapuram 		pdata->rx_pause = 0;
1408e0543d4eSAmaranath Somalapuram 		AXGMAC_IOWRITE_BITS(pdata, MAC_RFCR, PFCE, 0);
1409e0543d4eSAmaranath Somalapuram 	}
1410e0543d4eSAmaranath Somalapuram 
1411e0543d4eSAmaranath Somalapuram 	if (pdata->tx_pause != (unsigned int)pdata->phy.tx_pause)
1412e0543d4eSAmaranath Somalapuram 		pdata->hw_if.config_tx_flow_control(pdata);
1413e0543d4eSAmaranath Somalapuram 
1414e0543d4eSAmaranath Somalapuram 	if (pdata->rx_pause != (unsigned int)pdata->phy.rx_pause)
1415e0543d4eSAmaranath Somalapuram 		pdata->hw_if.config_rx_flow_control(pdata);
1416e0543d4eSAmaranath Somalapuram 	pdata->hw_if.config_flow_control(pdata);
1417e0543d4eSAmaranath Somalapuram 	pdata->phy.tx_pause = pdata->tx_pause;
1418e0543d4eSAmaranath Somalapuram 	pdata->phy.rx_pause = pdata->rx_pause;
1419e0543d4eSAmaranath Somalapuram 
1420e0543d4eSAmaranath Somalapuram 	return 0;
1421e0543d4eSAmaranath Somalapuram }
1422e0543d4eSAmaranath Somalapuram 
14237aed95c9SAmaranath Somalapuram void
14247aed95c9SAmaranath Somalapuram axgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
14257aed95c9SAmaranath Somalapuram 	struct rte_eth_rxq_info *qinfo)
14267aed95c9SAmaranath Somalapuram {
14277aed95c9SAmaranath Somalapuram 	struct   axgbe_rx_queue *rxq;
14287aed95c9SAmaranath Somalapuram 
14297aed95c9SAmaranath Somalapuram 	rxq = dev->data->rx_queues[queue_id];
14307aed95c9SAmaranath Somalapuram 	qinfo->mp = rxq->mb_pool;
14317aed95c9SAmaranath Somalapuram 	qinfo->scattered_rx = dev->data->scattered_rx;
14327aed95c9SAmaranath Somalapuram 	qinfo->nb_desc = rxq->nb_desc;
14337aed95c9SAmaranath Somalapuram 	qinfo->conf.rx_free_thresh = rxq->free_thresh;
14347aed95c9SAmaranath Somalapuram }
14357aed95c9SAmaranath Somalapuram 
14367aed95c9SAmaranath Somalapuram void
14377aed95c9SAmaranath Somalapuram axgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
14387aed95c9SAmaranath Somalapuram 	struct rte_eth_txq_info *qinfo)
14397aed95c9SAmaranath Somalapuram {
14407aed95c9SAmaranath Somalapuram 	struct  axgbe_tx_queue *txq;
14417aed95c9SAmaranath Somalapuram 
14427aed95c9SAmaranath Somalapuram 	txq = dev->data->tx_queues[queue_id];
14437aed95c9SAmaranath Somalapuram 	qinfo->nb_desc = txq->nb_desc;
14447aed95c9SAmaranath Somalapuram 	qinfo->conf.tx_free_thresh = txq->free_thresh;
14457aed95c9SAmaranath Somalapuram }
1446410cf087SAmaranath Somalapuram const uint32_t *
1447410cf087SAmaranath Somalapuram axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev)
1448410cf087SAmaranath Somalapuram {
1449410cf087SAmaranath Somalapuram 	static const uint32_t ptypes[] = {
1450410cf087SAmaranath Somalapuram 		RTE_PTYPE_L2_ETHER,
1451410cf087SAmaranath Somalapuram 		RTE_PTYPE_L2_ETHER_TIMESYNC,
1452410cf087SAmaranath Somalapuram 		RTE_PTYPE_L2_ETHER_LLDP,
1453410cf087SAmaranath Somalapuram 		RTE_PTYPE_L2_ETHER_ARP,
1454410cf087SAmaranath Somalapuram 		RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
1455410cf087SAmaranath Somalapuram 		RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
1456410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_FRAG,
1457410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_ICMP,
1458410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_NONFRAG,
1459410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_SCTP,
1460410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_TCP,
1461410cf087SAmaranath Somalapuram 		RTE_PTYPE_L4_UDP,
1462410cf087SAmaranath Somalapuram 		RTE_PTYPE_TUNNEL_GRENAT,
1463410cf087SAmaranath Somalapuram 		RTE_PTYPE_TUNNEL_IP,
1464410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L2_ETHER,
1465410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L2_ETHER_VLAN,
1466410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
1467410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
1468410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_FRAG,
1469410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_ICMP,
1470410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_NONFRAG,
1471410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_SCTP,
1472410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_TCP,
1473410cf087SAmaranath Somalapuram 		RTE_PTYPE_INNER_L4_UDP,
1474410cf087SAmaranath Somalapuram 		RTE_PTYPE_UNKNOWN
1475410cf087SAmaranath Somalapuram 	};
1476410cf087SAmaranath Somalapuram 
1477410cf087SAmaranath Somalapuram 	if (dev->rx_pkt_burst == axgbe_recv_pkts)
1478410cf087SAmaranath Somalapuram 		return ptypes;
1479410cf087SAmaranath Somalapuram 	return NULL;
1480410cf087SAmaranath Somalapuram }
1481e0444948SSelwin Sebastian 
1482b58d8781SGirish Nandibasappa static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1483b58d8781SGirish Nandibasappa {
1484b58d8781SGirish Nandibasappa 	struct axgbe_port *pdata = dev->data->dev_private;
1485f7e04f57SFerruh Yigit 	unsigned int val;
1486f7e04f57SFerruh Yigit 
1487b58d8781SGirish Nandibasappa 	/* mtu setting is forbidden if port is start */
1488b58d8781SGirish Nandibasappa 	if (dev->data->dev_started) {
1489b58d8781SGirish Nandibasappa 		PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
1490b58d8781SGirish Nandibasappa 				dev->data->port_id);
1491b58d8781SGirish Nandibasappa 		return -EBUSY;
1492b58d8781SGirish Nandibasappa 	}
1493f7e04f57SFerruh Yigit 	val = mtu > RTE_ETHER_MTU ? 1 : 0;
1494b58d8781SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
1495f7e04f57SFerruh Yigit 
1496b58d8781SGirish Nandibasappa 	return 0;
1497b58d8781SGirish Nandibasappa }
1498e0444948SSelwin Sebastian 
1499e0444948SSelwin Sebastian static void
1500e0444948SSelwin Sebastian axgbe_update_tstamp_time(struct axgbe_port *pdata,
1501e0444948SSelwin Sebastian 		unsigned int sec, unsigned int nsec, int addsub)
1502e0444948SSelwin Sebastian {
1503e0444948SSelwin Sebastian 	unsigned int count = 100;
1504e0444948SSelwin Sebastian 	uint32_t sub_val = 0;
1505e0444948SSelwin Sebastian 	uint32_t sub_val_sec = 0xFFFFFFFF;
1506e0444948SSelwin Sebastian 	uint32_t sub_val_nsec = 0x3B9ACA00;
1507e0444948SSelwin Sebastian 
1508e0444948SSelwin Sebastian 	if (addsub) {
1509e0444948SSelwin Sebastian 		if (sec)
1510e0444948SSelwin Sebastian 			sub_val = sub_val_sec - (sec - 1);
1511e0444948SSelwin Sebastian 		else
1512e0444948SSelwin Sebastian 			sub_val = sec;
1513e0444948SSelwin Sebastian 
1514e0444948SSelwin Sebastian 		AXGMAC_IOWRITE(pdata, MAC_STSUR, sub_val);
1515e0444948SSelwin Sebastian 		sub_val = sub_val_nsec - nsec;
1516e0444948SSelwin Sebastian 		AXGMAC_IOWRITE(pdata, MAC_STNUR, sub_val);
1517e0444948SSelwin Sebastian 		AXGMAC_IOWRITE_BITS(pdata, MAC_STNUR, ADDSUB, 1);
1518e0444948SSelwin Sebastian 	} else {
1519e0444948SSelwin Sebastian 		AXGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1520e0444948SSelwin Sebastian 		AXGMAC_IOWRITE_BITS(pdata, MAC_STNUR, ADDSUB, 0);
1521e0444948SSelwin Sebastian 		AXGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1522e0444948SSelwin Sebastian 	}
1523e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSUPDT, 1);
1524e0444948SSelwin Sebastian 	/* Wait for time update to complete */
1525e0444948SSelwin Sebastian 	while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSUPDT))
1526e0444948SSelwin Sebastian 		rte_delay_ms(1);
1527e0444948SSelwin Sebastian }
1528e0444948SSelwin Sebastian 
1529e0444948SSelwin Sebastian static inline uint64_t
1530e0444948SSelwin Sebastian div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
1531e0444948SSelwin Sebastian {
1532e0444948SSelwin Sebastian 	*remainder = dividend % divisor;
1533e0444948SSelwin Sebastian 	return dividend / divisor;
1534e0444948SSelwin Sebastian }
1535e0444948SSelwin Sebastian 
1536e0444948SSelwin Sebastian static inline uint64_t
1537e0444948SSelwin Sebastian div_u64(uint64_t dividend, uint32_t divisor)
1538e0444948SSelwin Sebastian {
1539e0444948SSelwin Sebastian 	uint32_t remainder;
1540e0444948SSelwin Sebastian 	return div_u64_rem(dividend, divisor, &remainder);
1541e0444948SSelwin Sebastian }
1542e0444948SSelwin Sebastian 
1543e0444948SSelwin Sebastian static int
1544e0444948SSelwin Sebastian axgbe_adjfreq(struct axgbe_port *pdata, int64_t delta)
1545e0444948SSelwin Sebastian {
1546e0444948SSelwin Sebastian 	uint64_t adjust;
1547e0444948SSelwin Sebastian 	uint32_t addend, diff;
1548e0444948SSelwin Sebastian 	unsigned int neg_adjust = 0;
1549e0444948SSelwin Sebastian 
1550e0444948SSelwin Sebastian 	if (delta < 0) {
1551e0444948SSelwin Sebastian 		neg_adjust = 1;
1552e0444948SSelwin Sebastian 		delta = -delta;
1553e0444948SSelwin Sebastian 	}
1554e0444948SSelwin Sebastian 	adjust = (uint64_t)pdata->tstamp_addend;
1555e0444948SSelwin Sebastian 	adjust *= delta;
1556e0444948SSelwin Sebastian 	diff = (uint32_t)div_u64(adjust, 1000000000UL);
1557e0444948SSelwin Sebastian 	addend = (neg_adjust) ? pdata->tstamp_addend - diff :
1558e0444948SSelwin Sebastian 				pdata->tstamp_addend + diff;
1559e0444948SSelwin Sebastian 	pdata->tstamp_addend = addend;
1560e0444948SSelwin Sebastian 	axgbe_update_tstamp_addend(pdata, addend);
1561e0444948SSelwin Sebastian 	return 0;
1562e0444948SSelwin Sebastian }
1563e0444948SSelwin Sebastian 
1564e0444948SSelwin Sebastian static int
1565e0444948SSelwin Sebastian axgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
1566e0444948SSelwin Sebastian {
1567e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1568e0444948SSelwin Sebastian 	struct timespec timestamp_delta;
1569e0444948SSelwin Sebastian 
1570e0444948SSelwin Sebastian 	axgbe_adjfreq(pdata, delta);
1571e0444948SSelwin Sebastian 	pdata->systime_tc.nsec += delta;
1572e0444948SSelwin Sebastian 
1573e0444948SSelwin Sebastian 	if (delta < 0) {
1574e0444948SSelwin Sebastian 		delta = -delta;
1575e0444948SSelwin Sebastian 		timestamp_delta = rte_ns_to_timespec(delta);
1576e0444948SSelwin Sebastian 		axgbe_update_tstamp_time(pdata, timestamp_delta.tv_sec,
1577e0444948SSelwin Sebastian 				timestamp_delta.tv_nsec, 1);
1578e0444948SSelwin Sebastian 	} else {
1579e0444948SSelwin Sebastian 		timestamp_delta = rte_ns_to_timespec(delta);
1580e0444948SSelwin Sebastian 		axgbe_update_tstamp_time(pdata, timestamp_delta.tv_sec,
1581e0444948SSelwin Sebastian 				timestamp_delta.tv_nsec, 0);
1582e0444948SSelwin Sebastian 	}
1583e0444948SSelwin Sebastian 	return 0;
1584e0444948SSelwin Sebastian }
1585e0444948SSelwin Sebastian 
1586e0444948SSelwin Sebastian static int
1587e0444948SSelwin Sebastian axgbe_timesync_read_time(struct rte_eth_dev *dev,
1588e0444948SSelwin Sebastian 		struct timespec *timestamp)
1589e0444948SSelwin Sebastian {
1590e0444948SSelwin Sebastian 	uint64_t nsec;
1591e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1592e0444948SSelwin Sebastian 
1593e0444948SSelwin Sebastian 	nsec = AXGMAC_IOREAD(pdata, MAC_STSR);
1594e0444948SSelwin Sebastian 	nsec *= NSEC_PER_SEC;
1595e0444948SSelwin Sebastian 	nsec += AXGMAC_IOREAD(pdata, MAC_STNR);
1596e0444948SSelwin Sebastian 	*timestamp = rte_ns_to_timespec(nsec);
1597e0444948SSelwin Sebastian 	return 0;
1598e0444948SSelwin Sebastian }
1599e0444948SSelwin Sebastian static int
1600e0444948SSelwin Sebastian axgbe_timesync_write_time(struct rte_eth_dev *dev,
1601e0444948SSelwin Sebastian 				    const struct timespec *timestamp)
1602e0444948SSelwin Sebastian {
1603e0444948SSelwin Sebastian 	unsigned int count = 100;
1604e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1605e0444948SSelwin Sebastian 
1606e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_STSUR, timestamp->tv_sec);
1607e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_STNUR, timestamp->tv_nsec);
1608e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSUPDT, 1);
1609e0444948SSelwin Sebastian 	/* Wait for time update to complete */
1610e0444948SSelwin Sebastian 	while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSUPDT))
1611e0444948SSelwin Sebastian 		rte_delay_ms(1);
1612e0444948SSelwin Sebastian 	if (!count)
1613e0444948SSelwin Sebastian 		PMD_DRV_LOG(ERR, "Timed out update timestamp\n");
1614e0444948SSelwin Sebastian 	return 0;
1615e0444948SSelwin Sebastian }
1616e0444948SSelwin Sebastian 
1617e0444948SSelwin Sebastian static void
1618e0444948SSelwin Sebastian axgbe_update_tstamp_addend(struct axgbe_port *pdata,
1619e0444948SSelwin Sebastian 		uint32_t addend)
1620e0444948SSelwin Sebastian {
1621e0444948SSelwin Sebastian 	unsigned int count = 100;
1622e0444948SSelwin Sebastian 
1623e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_TSAR, addend);
1624e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 1);
1625e0444948SSelwin Sebastian 
1626e0444948SSelwin Sebastian 	/* Wait for addend update to complete */
1627e0444948SSelwin Sebastian 	while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSADDREG))
1628e0444948SSelwin Sebastian 		rte_delay_ms(1);
1629e0444948SSelwin Sebastian 	if (!count)
1630e0444948SSelwin Sebastian 		PMD_DRV_LOG(ERR, "Timed out updating timestamp addend register\n");
1631e0444948SSelwin Sebastian }
1632e0444948SSelwin Sebastian 
1633e0444948SSelwin Sebastian static void
1634e0444948SSelwin Sebastian axgbe_set_tstamp_time(struct axgbe_port *pdata, unsigned int sec,
1635e0444948SSelwin Sebastian 		unsigned int nsec)
1636e0444948SSelwin Sebastian {
1637e0444948SSelwin Sebastian 	unsigned int count = 100;
1638e0444948SSelwin Sebastian 
1639e0444948SSelwin Sebastian 	/*System Time Sec Update*/
1640e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_STSUR, sec);
1641e0444948SSelwin Sebastian 	/*System Time nanoSec Update*/
1642e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_STNUR, nsec);
1643e0444948SSelwin Sebastian 	/*Initialize Timestamp*/
1644e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSINIT, 1);
1645e0444948SSelwin Sebastian 
1646e0444948SSelwin Sebastian 	/* Wait for time update to complete */
1647e0444948SSelwin Sebastian 	while (--count && AXGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSINIT))
1648e0444948SSelwin Sebastian 		rte_delay_ms(1);
1649e0444948SSelwin Sebastian 	if (!count)
1650e0444948SSelwin Sebastian 		PMD_DRV_LOG(ERR, "Timed out initializing timestamp\n");
1651e0444948SSelwin Sebastian }
1652e0444948SSelwin Sebastian 
1653e0444948SSelwin Sebastian static int
1654e0444948SSelwin Sebastian axgbe_timesync_enable(struct rte_eth_dev *dev)
1655e0444948SSelwin Sebastian {
1656e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1657e0444948SSelwin Sebastian 	unsigned int mac_tscr = 0;
1658e0444948SSelwin Sebastian 	uint64_t dividend;
1659e0444948SSelwin Sebastian 	struct timespec timestamp;
1660e0444948SSelwin Sebastian 	uint64_t nsec;
1661e0444948SSelwin Sebastian 
1662e0444948SSelwin Sebastian 	/* Set one nano-second accuracy */
1663e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCTRLSSR, 1);
1664e0444948SSelwin Sebastian 
1665e0444948SSelwin Sebastian 	/* Set fine timestamp update */
1666e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 1);
1667e0444948SSelwin Sebastian 
1668e0444948SSelwin Sebastian 	/* Overwrite earlier timestamps */
1669e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TXTSSTSM, 1);
1670e0444948SSelwin Sebastian 
1671e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1672e0444948SSelwin Sebastian 
1673e0444948SSelwin Sebastian 	/* Enabling processing of ptp over eth pkt */
1674e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPENA, 1);
1675e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1);
1676e0444948SSelwin Sebastian 	/* Enable timestamp for all pkts*/
1677e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 1);
1678e0444948SSelwin Sebastian 
1679e0444948SSelwin Sebastian 	/* enabling timestamp */
1680e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 1);
1681e0444948SSelwin Sebastian 	AXGMAC_IOWRITE(pdata, MAC_TSCR, mac_tscr);
1682e0444948SSelwin Sebastian 
1683e0444948SSelwin Sebastian 	/* Exit if timestamping is not enabled */
1684e0444948SSelwin Sebastian 	if (!AXGMAC_GET_BITS(mac_tscr, MAC_TSCR, TSENA)) {
1685e0444948SSelwin Sebastian 		PMD_DRV_LOG(ERR, "Exiting as timestamp is not enabled\n");
1686e0444948SSelwin Sebastian 		return 0;
1687e0444948SSelwin Sebastian 	}
1688e0444948SSelwin Sebastian 
1689e0444948SSelwin Sebastian 	/* Sub-second Increment Value*/
1690e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SSINC, AXGBE_TSTAMP_SSINC);
1691e0444948SSelwin Sebastian 	/* Sub-nanosecond Increment Value */
1692e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_SSIR, SNSINC, AXGBE_TSTAMP_SNSINC);
1693e0444948SSelwin Sebastian 
1694e0444948SSelwin Sebastian 	pdata->ptpclk_rate = AXGBE_V2_PTP_CLOCK_FREQ;
1695e0444948SSelwin Sebastian 	dividend = 50000000;
1696e0444948SSelwin Sebastian 	dividend <<= 32;
1697e0444948SSelwin Sebastian 	pdata->tstamp_addend = div_u64(dividend, pdata->ptpclk_rate);
1698e0444948SSelwin Sebastian 
1699e0444948SSelwin Sebastian 	axgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
1700e0444948SSelwin Sebastian 	axgbe_set_tstamp_time(pdata, 0, 0);
1701e0444948SSelwin Sebastian 
1702e0444948SSelwin Sebastian 	/* Initialize the timecounter */
1703e0444948SSelwin Sebastian 	memset(&pdata->systime_tc, 0, sizeof(struct rte_timecounter));
1704e0444948SSelwin Sebastian 
1705e0444948SSelwin Sebastian 	pdata->systime_tc.cc_mask = AXGBE_CYCLECOUNTER_MASK;
1706e0444948SSelwin Sebastian 	pdata->systime_tc.cc_shift = 0;
1707e0444948SSelwin Sebastian 	pdata->systime_tc.nsec_mask = 0;
1708e0444948SSelwin Sebastian 
1709e0444948SSelwin Sebastian 	PMD_DRV_LOG(DEBUG, "Initializing system time counter with realtime\n");
1710e0444948SSelwin Sebastian 
1711e0444948SSelwin Sebastian 	/* Updating the counter once with clock real time */
1712e0444948SSelwin Sebastian 	clock_gettime(CLOCK_REALTIME, &timestamp);
1713e0444948SSelwin Sebastian 	nsec = rte_timespec_to_ns(&timestamp);
1714e0444948SSelwin Sebastian 	nsec = rte_timecounter_update(&pdata->systime_tc, nsec);
1715e0444948SSelwin Sebastian 	axgbe_set_tstamp_time(pdata, timestamp.tv_sec, timestamp.tv_nsec);
1716e0444948SSelwin Sebastian 	return 0;
1717e0444948SSelwin Sebastian }
1718e0444948SSelwin Sebastian 
1719e0444948SSelwin Sebastian static int
1720e0444948SSelwin Sebastian axgbe_timesync_disable(struct rte_eth_dev *dev)
1721e0444948SSelwin Sebastian {
1722e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1723e0444948SSelwin Sebastian 	unsigned int mac_tscr = 0;
1724e0444948SSelwin Sebastian 
1725e0444948SSelwin Sebastian 	/*disable timestamp for all pkts*/
1726e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENALL, 0);
1727e0444948SSelwin Sebastian 	/*disable the addened register*/
1728e0444948SSelwin Sebastian 	AXGMAC_IOWRITE_BITS(pdata, MAC_TSCR, TSADDREG, 0);
1729e0444948SSelwin Sebastian 	/* disable timestamp update */
1730e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSCFUPDT, 0);
1731e0444948SSelwin Sebastian 	/*disable time stamp*/
1732e0444948SSelwin Sebastian 	AXGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSENA, 0);
1733e0444948SSelwin Sebastian 	return 0;
1734e0444948SSelwin Sebastian }
1735e0444948SSelwin Sebastian 
1736e0444948SSelwin Sebastian static int
1737e0444948SSelwin Sebastian axgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
1738e0444948SSelwin Sebastian 				struct timespec *timestamp, uint32_t flags)
1739e0444948SSelwin Sebastian {
1740e0444948SSelwin Sebastian 	uint64_t nsec = 0;
1741e0444948SSelwin Sebastian 	volatile union axgbe_rx_desc *desc;
1742e0444948SSelwin Sebastian 	uint16_t idx, pmt;
1743e0444948SSelwin Sebastian 	struct axgbe_rx_queue *rxq = *dev->data->rx_queues;
1744e0444948SSelwin Sebastian 
1745e0444948SSelwin Sebastian 	idx = AXGBE_GET_DESC_IDX(rxq, rxq->cur);
1746e0444948SSelwin Sebastian 	desc = &rxq->desc[idx];
1747e0444948SSelwin Sebastian 
1748e0444948SSelwin Sebastian 	while (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, OWN))
1749e0444948SSelwin Sebastian 		rte_delay_ms(1);
1750e0444948SSelwin Sebastian 	if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_NORMAL_DESC3, CTXT)) {
1751e0444948SSelwin Sebastian 		if (AXGMAC_GET_BITS_LE(desc->write.desc3, RX_CONTEXT_DESC3, TSA) &&
1752e0444948SSelwin Sebastian 				!AXGMAC_GET_BITS_LE(desc->write.desc3,
1753e0444948SSelwin Sebastian 					RX_CONTEXT_DESC3, TSD)) {
1754e0444948SSelwin Sebastian 			pmt = AXGMAC_GET_BITS_LE(desc->write.desc3,
1755e0444948SSelwin Sebastian 					RX_CONTEXT_DESC3, PMT);
1756e0444948SSelwin Sebastian 			nsec = rte_le_to_cpu_32(desc->write.desc1);
1757e0444948SSelwin Sebastian 			nsec *= NSEC_PER_SEC;
1758e0444948SSelwin Sebastian 			nsec += rte_le_to_cpu_32(desc->write.desc0);
1759e0444948SSelwin Sebastian 			if (nsec != 0xffffffffffffffffULL) {
1760e0444948SSelwin Sebastian 				if (pmt == 0x01)
1761e0444948SSelwin Sebastian 					*timestamp = rte_ns_to_timespec(nsec);
1762e0444948SSelwin Sebastian 				PMD_DRV_LOG(DEBUG,
1763e0444948SSelwin Sebastian 					"flags = 0x%x nsec = %"PRIu64"\n",
1764e0444948SSelwin Sebastian 					flags, nsec);
1765e0444948SSelwin Sebastian 			}
1766e0444948SSelwin Sebastian 		}
1767e0444948SSelwin Sebastian 	}
1768e0444948SSelwin Sebastian 
1769e0444948SSelwin Sebastian 	return 0;
1770e0444948SSelwin Sebastian }
1771e0444948SSelwin Sebastian 
1772e0444948SSelwin Sebastian static int
1773e0444948SSelwin Sebastian axgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
1774e0444948SSelwin Sebastian 				struct timespec *timestamp)
1775e0444948SSelwin Sebastian {
1776e0444948SSelwin Sebastian 	uint64_t nsec;
1777e0444948SSelwin Sebastian 	struct axgbe_port *pdata = dev->data->dev_private;
1778e0444948SSelwin Sebastian 	unsigned int tx_snr, tx_ssr;
1779e0444948SSelwin Sebastian 
1780e0444948SSelwin Sebastian 	rte_delay_us(5);
1781e0444948SSelwin Sebastian 	if (pdata->vdata->tx_tstamp_workaround) {
1782e0444948SSelwin Sebastian 		tx_snr = AXGMAC_IOREAD(pdata, MAC_TXSNR);
1783e0444948SSelwin Sebastian 		tx_ssr = AXGMAC_IOREAD(pdata, MAC_TXSSR);
1784e0444948SSelwin Sebastian 
1785e0444948SSelwin Sebastian 	} else {
1786e0444948SSelwin Sebastian 		tx_ssr = AXGMAC_IOREAD(pdata, MAC_TXSSR);
1787e0444948SSelwin Sebastian 		tx_snr = AXGMAC_IOREAD(pdata, MAC_TXSNR);
1788e0444948SSelwin Sebastian 	}
1789e0444948SSelwin Sebastian 	if (AXGMAC_GET_BITS(tx_snr, MAC_TXSNR, TXTSSTSMIS)) {
1790e0444948SSelwin Sebastian 		PMD_DRV_LOG(DEBUG, "Waiting for TXTSSTSMIS\n");
1791e0444948SSelwin Sebastian 		return 0;
1792e0444948SSelwin Sebastian 	}
1793e0444948SSelwin Sebastian 	nsec = tx_ssr;
1794e0444948SSelwin Sebastian 	nsec *= NSEC_PER_SEC;
1795e0444948SSelwin Sebastian 	nsec += tx_snr;
1796e0444948SSelwin Sebastian 	PMD_DRV_LOG(DEBUG, "nsec = %"PRIu64" tx_ssr = %d tx_snr = %d\n",
1797e0444948SSelwin Sebastian 			nsec, tx_ssr, tx_snr);
1798e0444948SSelwin Sebastian 	*timestamp = rte_ns_to_timespec(nsec);
1799e0444948SSelwin Sebastian 	return 0;
1800e0444948SSelwin Sebastian }
1801e0444948SSelwin Sebastian 
180286578516SGirish Nandibasappa static int
180386578516SGirish Nandibasappa axgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vid, int on)
180486578516SGirish Nandibasappa {
180586578516SGirish Nandibasappa 	struct axgbe_port *pdata = dev->data->dev_private;
180686578516SGirish Nandibasappa 	unsigned long vid_bit, vid_idx;
180786578516SGirish Nandibasappa 
180886578516SGirish Nandibasappa 	vid_bit = VLAN_TABLE_BIT(vid);
180986578516SGirish Nandibasappa 	vid_idx = VLAN_TABLE_IDX(vid);
181086578516SGirish Nandibasappa 
181186578516SGirish Nandibasappa 	if (on) {
181286578516SGirish Nandibasappa 		PMD_DRV_LOG(DEBUG, "Set VLAN vid=%d for device = %s\n",
181386578516SGirish Nandibasappa 			    vid, pdata->eth_dev->device->name);
181486578516SGirish Nandibasappa 		pdata->active_vlans[vid_idx] |= vid_bit;
181586578516SGirish Nandibasappa 	} else {
181686578516SGirish Nandibasappa 		PMD_DRV_LOG(DEBUG, "Reset VLAN vid=%d for device = %s\n",
181786578516SGirish Nandibasappa 			    vid, pdata->eth_dev->device->name);
181886578516SGirish Nandibasappa 		pdata->active_vlans[vid_idx] &= ~vid_bit;
181986578516SGirish Nandibasappa 	}
182086578516SGirish Nandibasappa 	pdata->hw_if.update_vlan_hash_table(pdata);
182186578516SGirish Nandibasappa 	return 0;
182286578516SGirish Nandibasappa }
182386578516SGirish Nandibasappa 
182486578516SGirish Nandibasappa static int
182586578516SGirish Nandibasappa axgbe_vlan_tpid_set(struct rte_eth_dev *dev,
182686578516SGirish Nandibasappa 		    enum rte_vlan_type vlan_type,
182786578516SGirish Nandibasappa 		    uint16_t tpid)
182886578516SGirish Nandibasappa {
182986578516SGirish Nandibasappa 	struct axgbe_port *pdata = dev->data->dev_private;
183086578516SGirish Nandibasappa 	uint32_t reg = 0;
183186578516SGirish Nandibasappa 	uint32_t qinq = 0;
183286578516SGirish Nandibasappa 
183386578516SGirish Nandibasappa 	qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP);
183486578516SGirish Nandibasappa 	PMD_DRV_LOG(DEBUG, "EDVLP: qinq = 0x%x\n", qinq);
183586578516SGirish Nandibasappa 
183686578516SGirish Nandibasappa 	switch (vlan_type) {
1837295968d1SFerruh Yigit 	case RTE_ETH_VLAN_TYPE_INNER:
1838295968d1SFerruh Yigit 		PMD_DRV_LOG(DEBUG, "RTE_ETH_VLAN_TYPE_INNER\n");
183986578516SGirish Nandibasappa 		if (qinq) {
184086578516SGirish Nandibasappa 			if (tpid != 0x8100 && tpid != 0x88a8)
184186578516SGirish Nandibasappa 				PMD_DRV_LOG(ERR,
184286578516SGirish Nandibasappa 					    "tag supported 0x8100/0x88A8\n");
184386578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "qinq with inner tag\n");
184486578516SGirish Nandibasappa 
184586578516SGirish Nandibasappa 			/*Enable Inner VLAN Tag */
184686578516SGirish Nandibasappa 			AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERIVLT, 1);
184786578516SGirish Nandibasappa 			reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, ERIVLT);
184886578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "bit ERIVLT = 0x%x\n", reg);
184986578516SGirish Nandibasappa 
185086578516SGirish Nandibasappa 		} else {
185186578516SGirish Nandibasappa 			PMD_DRV_LOG(ERR,
185286578516SGirish Nandibasappa 				    "Inner type not supported in single tag\n");
185386578516SGirish Nandibasappa 		}
185486578516SGirish Nandibasappa 		break;
1855295968d1SFerruh Yigit 	case RTE_ETH_VLAN_TYPE_OUTER:
1856295968d1SFerruh Yigit 		PMD_DRV_LOG(DEBUG, "RTE_ETH_VLAN_TYPE_OUTER\n");
185786578516SGirish Nandibasappa 		if (qinq) {
185886578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "double tagging is enabled\n");
185986578516SGirish Nandibasappa 			/*Enable outer VLAN tag*/
186086578516SGirish Nandibasappa 			AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, ERIVLT, 0);
186186578516SGirish Nandibasappa 			reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, ERIVLT);
186286578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "bit ERIVLT = 0x%x\n", reg);
186386578516SGirish Nandibasappa 
186486578516SGirish Nandibasappa 			AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 1);
186586578516SGirish Nandibasappa 			reg = AXGMAC_IOREAD_BITS(pdata, MAC_VLANIR, CSVL);
186686578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "bit CSVL = 0x%x\n", reg);
186786578516SGirish Nandibasappa 		} else {
186886578516SGirish Nandibasappa 			if (tpid != 0x8100 && tpid != 0x88a8)
186986578516SGirish Nandibasappa 				PMD_DRV_LOG(ERR,
187086578516SGirish Nandibasappa 					    "tag supported 0x8100/0x88A8\n");
187186578516SGirish Nandibasappa 		}
187286578516SGirish Nandibasappa 		break;
1873295968d1SFerruh Yigit 	case RTE_ETH_VLAN_TYPE_MAX:
1874295968d1SFerruh Yigit 		PMD_DRV_LOG(ERR, "RTE_ETH_VLAN_TYPE_MAX\n");
187586578516SGirish Nandibasappa 		break;
1876295968d1SFerruh Yigit 	case RTE_ETH_VLAN_TYPE_UNKNOWN:
1877295968d1SFerruh Yigit 		PMD_DRV_LOG(ERR, "RTE_ETH_VLAN_TYPE_UNKNOWN\n");
187886578516SGirish Nandibasappa 		break;
187986578516SGirish Nandibasappa 	}
188086578516SGirish Nandibasappa 	return 0;
188186578516SGirish Nandibasappa }
188286578516SGirish Nandibasappa 
188386578516SGirish Nandibasappa static void axgbe_vlan_extend_enable(struct axgbe_port *pdata)
188486578516SGirish Nandibasappa {
188586578516SGirish Nandibasappa 	int qinq = 0;
188686578516SGirish Nandibasappa 
188786578516SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EDVLP, 1);
188886578516SGirish Nandibasappa 	qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP);
188986578516SGirish Nandibasappa 	PMD_DRV_LOG(DEBUG, "vlan double tag enabled EDVLP:qinq=0x%x\n", qinq);
189086578516SGirish Nandibasappa }
189186578516SGirish Nandibasappa 
189286578516SGirish Nandibasappa static void axgbe_vlan_extend_disable(struct axgbe_port *pdata)
189386578516SGirish Nandibasappa {
189486578516SGirish Nandibasappa 	int qinq = 0;
189586578516SGirish Nandibasappa 
189686578516SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_VLANTR, EDVLP, 0);
189786578516SGirish Nandibasappa 	qinq = AXGMAC_IOREAD_BITS(pdata, MAC_VLANTR, EDVLP);
189886578516SGirish Nandibasappa 	PMD_DRV_LOG(DEBUG, "vlan double tag disable EDVLP:qinq=0x%x\n", qinq);
189986578516SGirish Nandibasappa }
190086578516SGirish Nandibasappa 
190186578516SGirish Nandibasappa static int
190286578516SGirish Nandibasappa axgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
190386578516SGirish Nandibasappa {
190486578516SGirish Nandibasappa 	struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
190586578516SGirish Nandibasappa 	struct axgbe_port *pdata = dev->data->dev_private;
190686578516SGirish Nandibasappa 
190786578516SGirish Nandibasappa 	/* Indicate that VLAN Tx CTAGs come from context descriptors */
190886578516SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, CSVL, 0);
190986578516SGirish Nandibasappa 	AXGMAC_IOWRITE_BITS(pdata, MAC_VLANIR, VLTI, 1);
191086578516SGirish Nandibasappa 
1911295968d1SFerruh Yigit 	if (mask & RTE_ETH_VLAN_STRIP_MASK) {
1912295968d1SFerruh Yigit 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
191386578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "Strip ON for device = %s\n",
191486578516SGirish Nandibasappa 				    pdata->eth_dev->device->name);
191586578516SGirish Nandibasappa 			pdata->hw_if.enable_rx_vlan_stripping(pdata);
191686578516SGirish Nandibasappa 		} else {
191786578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "Strip OFF for device = %s\n",
191886578516SGirish Nandibasappa 				    pdata->eth_dev->device->name);
191986578516SGirish Nandibasappa 			pdata->hw_if.disable_rx_vlan_stripping(pdata);
192086578516SGirish Nandibasappa 		}
192186578516SGirish Nandibasappa 	}
1922295968d1SFerruh Yigit 	if (mask & RTE_ETH_VLAN_FILTER_MASK) {
1923295968d1SFerruh Yigit 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
192486578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "Filter ON for device = %s\n",
192586578516SGirish Nandibasappa 				    pdata->eth_dev->device->name);
192686578516SGirish Nandibasappa 			pdata->hw_if.enable_rx_vlan_filtering(pdata);
192786578516SGirish Nandibasappa 		} else {
192886578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "Filter OFF for device = %s\n",
192986578516SGirish Nandibasappa 				    pdata->eth_dev->device->name);
193086578516SGirish Nandibasappa 			pdata->hw_if.disable_rx_vlan_filtering(pdata);
193186578516SGirish Nandibasappa 		}
193286578516SGirish Nandibasappa 	}
1933295968d1SFerruh Yigit 	if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
1934295968d1SFerruh Yigit 		if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
193586578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "enabling vlan extended mode\n");
193686578516SGirish Nandibasappa 			axgbe_vlan_extend_enable(pdata);
193786578516SGirish Nandibasappa 			/* Set global registers with default ethertype*/
1938295968d1SFerruh Yigit 			axgbe_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
193986578516SGirish Nandibasappa 					    RTE_ETHER_TYPE_VLAN);
1940295968d1SFerruh Yigit 			axgbe_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
194186578516SGirish Nandibasappa 					    RTE_ETHER_TYPE_VLAN);
194286578516SGirish Nandibasappa 		} else {
194386578516SGirish Nandibasappa 			PMD_DRV_LOG(DEBUG, "disabling vlan extended mode\n");
194486578516SGirish Nandibasappa 			axgbe_vlan_extend_disable(pdata);
194586578516SGirish Nandibasappa 		}
194686578516SGirish Nandibasappa 	}
194786578516SGirish Nandibasappa 	return 0;
194886578516SGirish Nandibasappa }
194986578516SGirish Nandibasappa 
1950572890efSRavi Kumar static void axgbe_get_all_hw_features(struct axgbe_port *pdata)
1951572890efSRavi Kumar {
195286578516SGirish Nandibasappa 	unsigned int mac_hfr0, mac_hfr1, mac_hfr2, mac_hfr3;
1953572890efSRavi Kumar 	struct axgbe_hw_features *hw_feat = &pdata->hw_feat;
1954572890efSRavi Kumar 
1955572890efSRavi Kumar 	mac_hfr0 = AXGMAC_IOREAD(pdata, MAC_HWF0R);
1956572890efSRavi Kumar 	mac_hfr1 = AXGMAC_IOREAD(pdata, MAC_HWF1R);
1957572890efSRavi Kumar 	mac_hfr2 = AXGMAC_IOREAD(pdata, MAC_HWF2R);
195886578516SGirish Nandibasappa 	mac_hfr3 = AXGMAC_IOREAD(pdata, MAC_HWF3R);
1959572890efSRavi Kumar 
1960572890efSRavi Kumar 	memset(hw_feat, 0, sizeof(*hw_feat));
1961572890efSRavi Kumar 
1962572890efSRavi Kumar 	hw_feat->version = AXGMAC_IOREAD(pdata, MAC_VR);
1963572890efSRavi Kumar 
1964572890efSRavi Kumar 	/* Hardware feature register 0 */
1965572890efSRavi Kumar 	hw_feat->gmii        = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, GMIISEL);
1966572890efSRavi Kumar 	hw_feat->vlhash      = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, VLHASH);
1967572890efSRavi Kumar 	hw_feat->sma         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SMASEL);
1968572890efSRavi Kumar 	hw_feat->rwk         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RWKSEL);
1969572890efSRavi Kumar 	hw_feat->mgk         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MGKSEL);
1970572890efSRavi Kumar 	hw_feat->mmc         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, MMCSEL);
1971572890efSRavi Kumar 	hw_feat->aoe         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, ARPOFFSEL);
1972572890efSRavi Kumar 	hw_feat->ts          = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSEL);
1973572890efSRavi Kumar 	hw_feat->eee         = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, EEESEL);
1974572890efSRavi Kumar 	hw_feat->tx_coe      = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TXCOESEL);
1975572890efSRavi Kumar 	hw_feat->rx_coe      = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, RXCOESEL);
1976572890efSRavi Kumar 	hw_feat->addn_mac    = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R,
1977572890efSRavi Kumar 					      ADDMACADRSEL);
1978572890efSRavi Kumar 	hw_feat->ts_src      = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, TSSTSSEL);
1979572890efSRavi Kumar 	hw_feat->sa_vlan_ins = AXGMAC_GET_BITS(mac_hfr0, MAC_HWF0R, SAVLANINS);
1980572890efSRavi Kumar 
1981572890efSRavi Kumar 	/* Hardware feature register 1 */
1982572890efSRavi Kumar 	hw_feat->rx_fifo_size  = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R,
1983572890efSRavi Kumar 						RXFIFOSIZE);
1984572890efSRavi Kumar 	hw_feat->tx_fifo_size  = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R,
1985572890efSRavi Kumar 						TXFIFOSIZE);
1986572890efSRavi Kumar 	hw_feat->adv_ts_hi     = AXGMAC_GET_BITS(mac_hfr1,
1987572890efSRavi Kumar 						 MAC_HWF1R, ADVTHWORD);
1988572890efSRavi Kumar 	hw_feat->dma_width     = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, ADDR64);
1989572890efSRavi Kumar 	hw_feat->dcb           = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DCBEN);
1990572890efSRavi Kumar 	hw_feat->sph           = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, SPHEN);
1991572890efSRavi Kumar 	hw_feat->tso           = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, TSOEN);
1992572890efSRavi Kumar 	hw_feat->dma_debug     = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, DBGMEMA);
1993572890efSRavi Kumar 	hw_feat->rss           = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, RSSEN);
1994572890efSRavi Kumar 	hw_feat->tc_cnt	       = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R, NUMTC);
1995572890efSRavi Kumar 	hw_feat->hash_table_size = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R,
1996572890efSRavi Kumar 						  HASHTBLSZ);
1997572890efSRavi Kumar 	hw_feat->l3l4_filter_num = AXGMAC_GET_BITS(mac_hfr1, MAC_HWF1R,
1998572890efSRavi Kumar 						  L3L4FNUM);
1999572890efSRavi Kumar 
2000572890efSRavi Kumar 	/* Hardware feature register 2 */
2001572890efSRavi Kumar 	hw_feat->rx_q_cnt     = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXQCNT);
2002572890efSRavi Kumar 	hw_feat->tx_q_cnt     = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXQCNT);
2003572890efSRavi Kumar 	hw_feat->rx_ch_cnt    = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, RXCHCNT);
2004572890efSRavi Kumar 	hw_feat->tx_ch_cnt    = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, TXCHCNT);
2005572890efSRavi Kumar 	hw_feat->pps_out_num  = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, PPSOUTNUM);
2006572890efSRavi Kumar 	hw_feat->aux_snap_num = AXGMAC_GET_BITS(mac_hfr2, MAC_HWF2R,
2007572890efSRavi Kumar 						AUXSNAPNUM);
2008572890efSRavi Kumar 
200986578516SGirish Nandibasappa 	/* Hardware feature register 3 */
201086578516SGirish Nandibasappa 	hw_feat->tx_q_vlan_tag_ins  = AXGMAC_GET_BITS(mac_hfr3,
201186578516SGirish Nandibasappa 						      MAC_HWF3R, CBTISEL);
201286578516SGirish Nandibasappa 	hw_feat->no_of_vlan_extn    = AXGMAC_GET_BITS(mac_hfr3,
201386578516SGirish Nandibasappa 						      MAC_HWF3R, NRVF);
201486578516SGirish Nandibasappa 
2015572890efSRavi Kumar 	/* Translate the Hash Table size into actual number */
2016572890efSRavi Kumar 	switch (hw_feat->hash_table_size) {
2017572890efSRavi Kumar 	case 0:
2018572890efSRavi Kumar 		break;
2019572890efSRavi Kumar 	case 1:
2020572890efSRavi Kumar 		hw_feat->hash_table_size = 64;
2021572890efSRavi Kumar 		break;
2022572890efSRavi Kumar 	case 2:
2023572890efSRavi Kumar 		hw_feat->hash_table_size = 128;
2024572890efSRavi Kumar 		break;
2025572890efSRavi Kumar 	case 3:
2026572890efSRavi Kumar 		hw_feat->hash_table_size = 256;
2027572890efSRavi Kumar 		break;
2028572890efSRavi Kumar 	}
2029572890efSRavi Kumar 
2030572890efSRavi Kumar 	/* Translate the address width setting into actual number */
2031572890efSRavi Kumar 	switch (hw_feat->dma_width) {
2032572890efSRavi Kumar 	case 0:
2033572890efSRavi Kumar 		hw_feat->dma_width = 32;
2034572890efSRavi Kumar 		break;
2035572890efSRavi Kumar 	case 1:
2036572890efSRavi Kumar 		hw_feat->dma_width = 40;
2037572890efSRavi Kumar 		break;
2038572890efSRavi Kumar 	case 2:
2039572890efSRavi Kumar 		hw_feat->dma_width = 48;
2040572890efSRavi Kumar 		break;
2041572890efSRavi Kumar 	default:
2042572890efSRavi Kumar 		hw_feat->dma_width = 32;
2043572890efSRavi Kumar 	}
2044572890efSRavi Kumar 
2045572890efSRavi Kumar 	/* The Queue, Channel and TC counts are zero based so increment them
2046572890efSRavi Kumar 	 * to get the actual number
2047572890efSRavi Kumar 	 */
2048572890efSRavi Kumar 	hw_feat->rx_q_cnt++;
2049572890efSRavi Kumar 	hw_feat->tx_q_cnt++;
2050572890efSRavi Kumar 	hw_feat->rx_ch_cnt++;
2051572890efSRavi Kumar 	hw_feat->tx_ch_cnt++;
2052572890efSRavi Kumar 	hw_feat->tc_cnt++;
2053572890efSRavi Kumar 
2054572890efSRavi Kumar 	/* Translate the fifo sizes into actual numbers */
2055572890efSRavi Kumar 	hw_feat->rx_fifo_size = 1 << (hw_feat->rx_fifo_size + 7);
2056572890efSRavi Kumar 	hw_feat->tx_fifo_size = 1 << (hw_feat->tx_fifo_size + 7);
2057572890efSRavi Kumar }
2058572890efSRavi Kumar 
2059572890efSRavi Kumar static void axgbe_init_all_fptrs(struct axgbe_port *pdata)
2060572890efSRavi Kumar {
2061572890efSRavi Kumar 	axgbe_init_function_ptrs_dev(&pdata->hw_if);
20624ac7516bSRavi Kumar 	axgbe_init_function_ptrs_phy(&pdata->phy_if);
20634ac7516bSRavi Kumar 	axgbe_init_function_ptrs_i2c(&pdata->i2c_if);
20644ac7516bSRavi Kumar 	pdata->vdata->init_function_ptrs_phy_impl(&pdata->phy_if);
2065572890efSRavi Kumar }
2066572890efSRavi Kumar 
2067572890efSRavi Kumar static void axgbe_set_counts(struct axgbe_port *pdata)
2068572890efSRavi Kumar {
2069572890efSRavi Kumar 	/* Set all the function pointers */
2070572890efSRavi Kumar 	axgbe_init_all_fptrs(pdata);
2071572890efSRavi Kumar 
2072572890efSRavi Kumar 	/* Populate the hardware features */
2073572890efSRavi Kumar 	axgbe_get_all_hw_features(pdata);
2074572890efSRavi Kumar 
2075572890efSRavi Kumar 	/* Set default max values if not provided */
2076572890efSRavi Kumar 	if (!pdata->tx_max_channel_count)
2077572890efSRavi Kumar 		pdata->tx_max_channel_count = pdata->hw_feat.tx_ch_cnt;
2078572890efSRavi Kumar 	if (!pdata->rx_max_channel_count)
2079572890efSRavi Kumar 		pdata->rx_max_channel_count = pdata->hw_feat.rx_ch_cnt;
2080572890efSRavi Kumar 
2081572890efSRavi Kumar 	if (!pdata->tx_max_q_count)
2082572890efSRavi Kumar 		pdata->tx_max_q_count = pdata->hw_feat.tx_q_cnt;
2083572890efSRavi Kumar 	if (!pdata->rx_max_q_count)
2084572890efSRavi Kumar 		pdata->rx_max_q_count = pdata->hw_feat.rx_q_cnt;
2085572890efSRavi Kumar 
2086572890efSRavi Kumar 	/* Calculate the number of Tx and Rx rings to be created
2087572890efSRavi Kumar 	 *  -Tx (DMA) Channels map 1-to-1 to Tx Queues so set
2088572890efSRavi Kumar 	 *   the number of Tx queues to the number of Tx channels
2089572890efSRavi Kumar 	 *   enabled
2090572890efSRavi Kumar 	 *  -Rx (DMA) Channels do not map 1-to-1 so use the actual
2091572890efSRavi Kumar 	 *   number of Rx queues or maximum allowed
2092572890efSRavi Kumar 	 */
2093572890efSRavi Kumar 	pdata->tx_ring_count = RTE_MIN(pdata->hw_feat.tx_ch_cnt,
2094572890efSRavi Kumar 				     pdata->tx_max_channel_count);
2095572890efSRavi Kumar 	pdata->tx_ring_count = RTE_MIN(pdata->tx_ring_count,
2096572890efSRavi Kumar 				     pdata->tx_max_q_count);
2097572890efSRavi Kumar 
2098572890efSRavi Kumar 	pdata->tx_q_count = pdata->tx_ring_count;
2099572890efSRavi Kumar 
2100572890efSRavi Kumar 	pdata->rx_ring_count = RTE_MIN(pdata->hw_feat.rx_ch_cnt,
2101572890efSRavi Kumar 				     pdata->rx_max_channel_count);
2102572890efSRavi Kumar 
2103572890efSRavi Kumar 	pdata->rx_q_count = RTE_MIN(pdata->hw_feat.rx_q_cnt,
2104572890efSRavi Kumar 				  pdata->rx_max_q_count);
2105572890efSRavi Kumar }
2106572890efSRavi Kumar 
2107572890efSRavi Kumar static void axgbe_default_config(struct axgbe_port *pdata)
2108572890efSRavi Kumar {
2109572890efSRavi Kumar 	pdata->pblx8 = DMA_PBL_X8_ENABLE;
2110572890efSRavi Kumar 	pdata->tx_sf_mode = MTL_TSF_ENABLE;
2111572890efSRavi Kumar 	pdata->tx_threshold = MTL_TX_THRESHOLD_64;
2112572890efSRavi Kumar 	pdata->tx_pbl = DMA_PBL_32;
2113572890efSRavi Kumar 	pdata->tx_osp_mode = DMA_OSP_ENABLE;
2114572890efSRavi Kumar 	pdata->rx_sf_mode = MTL_RSF_ENABLE;
2115572890efSRavi Kumar 	pdata->rx_threshold = MTL_RX_THRESHOLD_64;
2116572890efSRavi Kumar 	pdata->rx_pbl = DMA_PBL_32;
2117572890efSRavi Kumar 	pdata->pause_autoneg = 1;
2118572890efSRavi Kumar 	pdata->tx_pause = 0;
2119572890efSRavi Kumar 	pdata->rx_pause = 0;
2120572890efSRavi Kumar 	pdata->phy_speed = SPEED_UNKNOWN;
2121572890efSRavi Kumar 	pdata->power_down = 0;
2122572890efSRavi Kumar }
2123572890efSRavi Kumar 
2124b0db927bSChandubabu Namburu /*
2125b0db927bSChandubabu Namburu  * Return PCI root complex device id on success else 0
2126b0db927bSChandubabu Namburu  */
2127b0db927bSChandubabu Namburu static uint16_t
2128b0db927bSChandubabu Namburu get_pci_rc_devid(void)
2129991e0b1dSSelwin Sebastian {
2130b0db927bSChandubabu Namburu 	char pci_sysfs[PATH_MAX];
2131b0db927bSChandubabu Namburu 	const struct rte_pci_addr pci_rc_addr = {0, 0, 0, 0};
2132b0db927bSChandubabu Namburu 	unsigned long device_id;
2133991e0b1dSSelwin Sebastian 
2134b0db927bSChandubabu Namburu 	snprintf(pci_sysfs, sizeof(pci_sysfs), "%s/" PCI_PRI_FMT "/device",
2135b0db927bSChandubabu Namburu 		 rte_pci_get_sysfs_path(), pci_rc_addr.domain,
2136b0db927bSChandubabu Namburu 		 pci_rc_addr.bus, pci_rc_addr.devid, pci_rc_addr.function);
2137b0db927bSChandubabu Namburu 
2138b0db927bSChandubabu Namburu 	/* get device id */
2139b0db927bSChandubabu Namburu 	if (eal_parse_sysfs_value(pci_sysfs, &device_id) < 0) {
2140b0db927bSChandubabu Namburu 		PMD_INIT_LOG(ERR, "Error in reading PCI sysfs\n");
2141991e0b1dSSelwin Sebastian 		return 0;
2142991e0b1dSSelwin Sebastian 	}
2143991e0b1dSSelwin Sebastian 
2144b0db927bSChandubabu Namburu 	return (uint16_t)device_id;
2145991e0b1dSSelwin Sebastian }
2146991e0b1dSSelwin Sebastian 
21478691632fSRavi Kumar /*
21488691632fSRavi Kumar  * It returns 0 on success.
21498691632fSRavi Kumar  */
21508691632fSRavi Kumar static int
21518691632fSRavi Kumar eth_axgbe_dev_init(struct rte_eth_dev *eth_dev)
21528691632fSRavi Kumar {
21538691632fSRavi Kumar 	PMD_INIT_FUNC_TRACE();
21548691632fSRavi Kumar 	struct axgbe_port *pdata;
21558691632fSRavi Kumar 	struct rte_pci_device *pci_dev;
2156572890efSRavi Kumar 	uint32_t reg, mac_lo, mac_hi;
215749a5e622SChandu Babu N 	uint32_t len;
2158572890efSRavi Kumar 	int ret;
21598691632fSRavi Kumar 
21609e890103SRavi Kumar 	eth_dev->dev_ops = &axgbe_eth_dev_ops;
21619e890103SRavi Kumar 
2162cbfc6111SFerruh Yigit 	eth_dev->rx_descriptor_status = axgbe_dev_rx_descriptor_status;
2163cbfc6111SFerruh Yigit 	eth_dev->tx_descriptor_status = axgbe_dev_tx_descriptor_status;
2164cbfc6111SFerruh Yigit 
21658691632fSRavi Kumar 	/*
21668691632fSRavi Kumar 	 * For secondary processes, we don't initialise any further as primary
21678691632fSRavi Kumar 	 * has already done this work.
21688691632fSRavi Kumar 	 */
21698691632fSRavi Kumar 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
21708691632fSRavi Kumar 		return 0;
21718691632fSRavi Kumar 
2172f30e69b4SFerruh Yigit 	eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2173f30e69b4SFerruh Yigit 
21740bc212a8SStephen Hemminger 	pdata = eth_dev->data->dev_private;
2175572890efSRavi Kumar 	/* initial state */
21764693ae4aSJoyce Kong 	rte_bit_relaxed_set32(AXGBE_DOWN, &pdata->dev_state);
21774693ae4aSJoyce Kong 	rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state);
21788691632fSRavi Kumar 	pdata->eth_dev = eth_dev;
21798691632fSRavi Kumar 
21808691632fSRavi Kumar 	pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
21818691632fSRavi Kumar 	pdata->pci_dev = pci_dev;
21828691632fSRavi Kumar 
2183572890efSRavi Kumar 	pdata->xgmac_regs =
21847784d0d3SRavi Kumar 		(void *)pci_dev->mem_resource[AXGBE_AXGMAC_BAR].addr;
21857784d0d3SRavi Kumar 	pdata->xprop_regs = (void *)((uint8_t *)pdata->xgmac_regs
21867784d0d3SRavi Kumar 				     + AXGBE_MAC_PROP_OFFSET);
21877784d0d3SRavi Kumar 	pdata->xi2c_regs = (void *)((uint8_t *)pdata->xgmac_regs
21887784d0d3SRavi Kumar 				    + AXGBE_I2C_CTRL_OFFSET);
21897784d0d3SRavi Kumar 	pdata->xpcs_regs = (void *)pci_dev->mem_resource[AXGBE_XPCS_BAR].addr;
2190572890efSRavi Kumar 
2191572890efSRavi Kumar 	/* version specific driver data*/
2192572890efSRavi Kumar 	if (pci_dev->id.device_id == AMD_PCI_AXGBE_DEVICE_V2A)
2193572890efSRavi Kumar 		pdata->vdata = &axgbe_v2a;
2194572890efSRavi Kumar 	else
2195572890efSRavi Kumar 		pdata->vdata = &axgbe_v2b;
2196572890efSRavi Kumar 
2197f7706f88SSelwin Sebastian 	/*
2198f7706f88SSelwin Sebastian 	 * Use PCI root complex device ID to identify the CPU
2199f7706f88SSelwin Sebastian 	 */
2200f7706f88SSelwin Sebastian 	switch (get_pci_rc_devid()) {
2201f7706f88SSelwin Sebastian 	case AMD_PCI_RV_ROOT_COMPLEX_ID:
2202f7706f88SSelwin Sebastian 		pdata->xpcs_window_def_reg = PCS_V2_RV_WINDOW_DEF;
2203f7706f88SSelwin Sebastian 		pdata->xpcs_window_sel_reg = PCS_V2_RV_WINDOW_SELECT;
2204f7706f88SSelwin Sebastian 		break;
2205f7706f88SSelwin Sebastian 	case AMD_PCI_YC_ROOT_COMPLEX_ID:
2206f7706f88SSelwin Sebastian 		pdata->xpcs_window_def_reg = PCS_V2_YC_WINDOW_DEF;
2207f7706f88SSelwin Sebastian 		pdata->xpcs_window_sel_reg = PCS_V2_YC_WINDOW_SELECT;
22083e02a95bSSelwin Sebastian 		/* Yellow Carp devices do not need cdr workaround */
22093e02a95bSSelwin Sebastian 		pdata->vdata->an_cdr_workaround = 0;
2210f7706f88SSelwin Sebastian 		break;
2211f7706f88SSelwin Sebastian 	case AMD_PCI_SNOWY_ROOT_COMPLEX_ID:
2212f7706f88SSelwin Sebastian 		pdata->xpcs_window_def_reg = PCS_V2_WINDOW_DEF;
2213f7706f88SSelwin Sebastian 		pdata->xpcs_window_sel_reg = PCS_V2_WINDOW_SELECT;
2214f7706f88SSelwin Sebastian 		break;
2215f7706f88SSelwin Sebastian 	default:
2216f7706f88SSelwin Sebastian 		PMD_DRV_LOG(ERR, "No supported devices found\n");
2217f7706f88SSelwin Sebastian 		return -ENODEV;
2218f7706f88SSelwin Sebastian 	}
2219f7706f88SSelwin Sebastian 
2220572890efSRavi Kumar 	/* Configure the PCS indirect addressing support */
2221991e0b1dSSelwin Sebastian 	reg = XPCS32_IOREAD(pdata, pdata->xpcs_window_def_reg);
2222572890efSRavi Kumar 	pdata->xpcs_window = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, OFFSET);
2223572890efSRavi Kumar 	pdata->xpcs_window <<= 6;
2224572890efSRavi Kumar 	pdata->xpcs_window_size = XPCS_GET_BITS(reg, PCS_V2_WINDOW_DEF, SIZE);
2225572890efSRavi Kumar 	pdata->xpcs_window_size = 1 << (pdata->xpcs_window_size + 7);
2226572890efSRavi Kumar 	pdata->xpcs_window_mask = pdata->xpcs_window_size - 1;
2227991e0b1dSSelwin Sebastian 
2228572890efSRavi Kumar 	PMD_INIT_LOG(DEBUG,
2229572890efSRavi Kumar 		     "xpcs window :%x, size :%x, mask :%x ", pdata->xpcs_window,
2230572890efSRavi Kumar 		     pdata->xpcs_window_size, pdata->xpcs_window_mask);
2231572890efSRavi Kumar 	XP_IOWRITE(pdata, XP_INT_EN, 0x1fffff);
2232572890efSRavi Kumar 
2233572890efSRavi Kumar 	/* Retrieve the MAC address */
2234572890efSRavi Kumar 	mac_lo = XP_IOREAD(pdata, XP_MAC_ADDR_LO);
2235572890efSRavi Kumar 	mac_hi = XP_IOREAD(pdata, XP_MAC_ADDR_HI);
2236572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[0] = mac_lo & 0xff;
2237572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[1] = (mac_lo >> 8) & 0xff;
2238572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[2] = (mac_lo >> 16) & 0xff;
2239572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[3] = (mac_lo >> 24) & 0xff;
2240572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[4] = mac_hi & 0xff;
2241572890efSRavi Kumar 	pdata->mac_addr.addr_bytes[5] = (mac_hi >> 8)  &  0xff;
2242572890efSRavi Kumar 
224349a5e622SChandu Babu N 	len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_MAC_ADDRS;
224449a5e622SChandu Babu N 	eth_dev->data->mac_addrs = rte_zmalloc("axgbe_mac_addr", len, 0);
224549a5e622SChandu Babu N 
2246572890efSRavi Kumar 	if (!eth_dev->data->mac_addrs) {
2247572890efSRavi Kumar 		PMD_INIT_LOG(ERR,
224849a5e622SChandu Babu N 			     "Failed to alloc %u bytes needed to "
224949a5e622SChandu Babu N 			     "store MAC addresses", len);
2250572890efSRavi Kumar 		return -ENOMEM;
2251572890efSRavi Kumar 	}
2252572890efSRavi Kumar 
2253e01d9b2eSChandu Babu N 	/* Allocate memory for storing hash filter MAC addresses */
2254e01d9b2eSChandu Babu N 	len = RTE_ETHER_ADDR_LEN * AXGBE_MAX_HASH_MAC_ADDRS;
2255e01d9b2eSChandu Babu N 	eth_dev->data->hash_mac_addrs = rte_zmalloc("axgbe_hash_mac_addr",
2256e01d9b2eSChandu Babu N 						    len, 0);
2257e01d9b2eSChandu Babu N 
2258e01d9b2eSChandu Babu N 	if (eth_dev->data->hash_mac_addrs == NULL) {
2259e01d9b2eSChandu Babu N 		PMD_INIT_LOG(ERR,
2260e01d9b2eSChandu Babu N 			     "Failed to allocate %d bytes needed to "
2261e01d9b2eSChandu Babu N 			     "store MAC addresses", len);
2262e01d9b2eSChandu Babu N 		return -ENOMEM;
2263e01d9b2eSChandu Babu N 	}
2264e01d9b2eSChandu Babu N 
2265538da7a1SOlivier Matz 	if (!rte_is_valid_assigned_ether_addr(&pdata->mac_addr))
2266538da7a1SOlivier Matz 		rte_eth_random_addr(pdata->mac_addr.addr_bytes);
2267572890efSRavi Kumar 
2268572890efSRavi Kumar 	/* Copy the permanent MAC address */
2269538da7a1SOlivier Matz 	rte_ether_addr_copy(&pdata->mac_addr, &eth_dev->data->mac_addrs[0]);
2270572890efSRavi Kumar 
2271572890efSRavi Kumar 	/* Clock settings */
2272572890efSRavi Kumar 	pdata->sysclk_rate = AXGBE_V2_DMA_CLOCK_FREQ;
2273572890efSRavi Kumar 	pdata->ptpclk_rate = AXGBE_V2_PTP_CLOCK_FREQ;
2274572890efSRavi Kumar 
2275572890efSRavi Kumar 	/* Set the DMA coherency values */
2276572890efSRavi Kumar 	pdata->coherent = 1;
2277572890efSRavi Kumar 	pdata->axdomain = AXGBE_DMA_OS_AXDOMAIN;
2278572890efSRavi Kumar 	pdata->arcache = AXGBE_DMA_OS_ARCACHE;
2279572890efSRavi Kumar 	pdata->awcache = AXGBE_DMA_OS_AWCACHE;
2280572890efSRavi Kumar 
2281572890efSRavi Kumar 	/* Set the maximum channels and queues */
2282572890efSRavi Kumar 	reg = XP_IOREAD(pdata, XP_PROP_1);
2283572890efSRavi Kumar 	pdata->tx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_DMA);
2284572890efSRavi Kumar 	pdata->rx_max_channel_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_DMA);
2285572890efSRavi Kumar 	pdata->tx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_TX_QUEUES);
2286572890efSRavi Kumar 	pdata->rx_max_q_count = XP_GET_BITS(reg, XP_PROP_1, MAX_RX_QUEUES);
2287572890efSRavi Kumar 
2288572890efSRavi Kumar 	/* Set the hardware channel and queue counts */
2289572890efSRavi Kumar 	axgbe_set_counts(pdata);
2290572890efSRavi Kumar 
2291572890efSRavi Kumar 	/* Set the maximum fifo amounts */
2292572890efSRavi Kumar 	reg = XP_IOREAD(pdata, XP_PROP_2);
2293572890efSRavi Kumar 	pdata->tx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, TX_FIFO_SIZE);
2294572890efSRavi Kumar 	pdata->tx_max_fifo_size *= 16384;
2295572890efSRavi Kumar 	pdata->tx_max_fifo_size = RTE_MIN(pdata->tx_max_fifo_size,
2296572890efSRavi Kumar 					  pdata->vdata->tx_max_fifo_size);
2297572890efSRavi Kumar 	pdata->rx_max_fifo_size = XP_GET_BITS(reg, XP_PROP_2, RX_FIFO_SIZE);
2298572890efSRavi Kumar 	pdata->rx_max_fifo_size *= 16384;
2299572890efSRavi Kumar 	pdata->rx_max_fifo_size = RTE_MIN(pdata->rx_max_fifo_size,
2300572890efSRavi Kumar 					  pdata->vdata->rx_max_fifo_size);
2301572890efSRavi Kumar 	/* Issue software reset to DMA */
2302572890efSRavi Kumar 	ret = pdata->hw_if.exit(pdata);
2303572890efSRavi Kumar 	if (ret)
2304572890efSRavi Kumar 		PMD_DRV_LOG(ERR, "hw_if->exit EBUSY error\n");
2305572890efSRavi Kumar 
2306572890efSRavi Kumar 	/* Set default configuration data */
2307572890efSRavi Kumar 	axgbe_default_config(pdata);
2308572890efSRavi Kumar 
2309572890efSRavi Kumar 	/* Set default max values if not provided */
2310572890efSRavi Kumar 	if (!pdata->tx_max_fifo_size)
2311572890efSRavi Kumar 		pdata->tx_max_fifo_size = pdata->hw_feat.tx_fifo_size;
2312572890efSRavi Kumar 	if (!pdata->rx_max_fifo_size)
2313572890efSRavi Kumar 		pdata->rx_max_fifo_size = pdata->hw_feat.rx_fifo_size;
2314572890efSRavi Kumar 
23159e890103SRavi Kumar 	pdata->tx_desc_count = AXGBE_MAX_RING_DESC;
23169e890103SRavi Kumar 	pdata->rx_desc_count = AXGBE_MAX_RING_DESC;
2317572890efSRavi Kumar 	pthread_mutex_init(&pdata->xpcs_mutex, NULL);
2318572890efSRavi Kumar 	pthread_mutex_init(&pdata->i2c_mutex, NULL);
2319572890efSRavi Kumar 	pthread_mutex_init(&pdata->an_mutex, NULL);
2320572890efSRavi Kumar 	pthread_mutex_init(&pdata->phy_mutex, NULL);
2321572890efSRavi Kumar 
23224ac7516bSRavi Kumar 	ret = pdata->phy_if.phy_init(pdata);
23234ac7516bSRavi Kumar 	if (ret) {
23244ac7516bSRavi Kumar 		rte_free(eth_dev->data->mac_addrs);
2325e7f2fa88SDavid Marchand 		eth_dev->data->mac_addrs = NULL;
23264ac7516bSRavi Kumar 		return ret;
23274ac7516bSRavi Kumar 	}
23284ac7516bSRavi Kumar 
2329d61138d4SHarman Kalra 	rte_intr_callback_register(pci_dev->intr_handle,
2330456ff159SRavi Kumar 				   axgbe_dev_interrupt_handler,
2331456ff159SRavi Kumar 				   (void *)eth_dev);
23328691632fSRavi Kumar 	PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
23338691632fSRavi Kumar 		     eth_dev->data->port_id, pci_dev->id.vendor_id,
23348691632fSRavi Kumar 		     pci_dev->id.device_id);
23358691632fSRavi Kumar 
23368691632fSRavi Kumar 	return 0;
23378691632fSRavi Kumar }
23388691632fSRavi Kumar 
23398691632fSRavi Kumar static int
2340479e6a42SThomas Monjalon axgbe_dev_close(struct rte_eth_dev *eth_dev)
23418691632fSRavi Kumar {
2342456ff159SRavi Kumar 	struct rte_pci_device *pci_dev;
2343456ff159SRavi Kumar 
23448691632fSRavi Kumar 	PMD_INIT_FUNC_TRACE();
23458691632fSRavi Kumar 
2346572890efSRavi Kumar 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2347572890efSRavi Kumar 		return 0;
2348572890efSRavi Kumar 
2349456ff159SRavi Kumar 	pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
23509e890103SRavi Kumar 	axgbe_dev_clear_queues(eth_dev);
2351572890efSRavi Kumar 
2352456ff159SRavi Kumar 	/* disable uio intr before callback unregister */
2353d61138d4SHarman Kalra 	rte_intr_disable(pci_dev->intr_handle);
2354d61138d4SHarman Kalra 	rte_intr_callback_unregister(pci_dev->intr_handle,
2355456ff159SRavi Kumar 				     axgbe_dev_interrupt_handler,
2356456ff159SRavi Kumar 				     (void *)eth_dev);
2357456ff159SRavi Kumar 
23588691632fSRavi Kumar 	return 0;
23598691632fSRavi Kumar }
23608691632fSRavi Kumar 
23618691632fSRavi Kumar static int eth_axgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
23628691632fSRavi Kumar 	struct rte_pci_device *pci_dev)
23638691632fSRavi Kumar {
23648691632fSRavi Kumar 	return rte_eth_dev_pci_generic_probe(pci_dev,
23658691632fSRavi Kumar 		sizeof(struct axgbe_port), eth_axgbe_dev_init);
23668691632fSRavi Kumar }
23678691632fSRavi Kumar 
23688691632fSRavi Kumar static int eth_axgbe_pci_remove(struct rte_pci_device *pci_dev)
23698691632fSRavi Kumar {
2370479e6a42SThomas Monjalon 	return rte_eth_dev_pci_generic_remove(pci_dev, axgbe_dev_close);
23718691632fSRavi Kumar }
23728691632fSRavi Kumar 
23738691632fSRavi Kumar static struct rte_pci_driver rte_axgbe_pmd = {
23748691632fSRavi Kumar 	.id_table = pci_id_axgbe_map,
23758691632fSRavi Kumar 	.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
23768691632fSRavi Kumar 	.probe = eth_axgbe_pci_probe,
23778691632fSRavi Kumar 	.remove = eth_axgbe_pci_remove,
23788691632fSRavi Kumar };
23798691632fSRavi Kumar 
23808691632fSRavi Kumar RTE_PMD_REGISTER_PCI(net_axgbe, rte_axgbe_pmd);
23818691632fSRavi Kumar RTE_PMD_REGISTER_PCI_TABLE(net_axgbe, pci_id_axgbe_map);
23828691632fSRavi Kumar RTE_PMD_REGISTER_KMOD_DEP(net_axgbe, "* igb_uio | uio_pci_generic | vfio-pci");
2383eeded204SDavid Marchand RTE_LOG_REGISTER_SUFFIX(axgbe_logtype_init, init, NOTICE);
2384eeded204SDavid Marchand RTE_LOG_REGISTER_SUFFIX(axgbe_logtype_driver, driver, NOTICE);
2385