xref: /freebsd/sys/dev/vnic/nic.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
13c0086b8SZbigniew Bodek /*
23c0086b8SZbigniew Bodek  * Copyright (C) 2015 Cavium Inc.
33c0086b8SZbigniew Bodek  * All rights reserved.
43c0086b8SZbigniew Bodek  *
53c0086b8SZbigniew Bodek  * Redistribution and use in source and binary forms, with or without
63c0086b8SZbigniew Bodek  * modification, are permitted provided that the following conditions
73c0086b8SZbigniew Bodek  * are met:
83c0086b8SZbigniew Bodek  * 1. Redistributions of source code must retain the above copyright
93c0086b8SZbigniew Bodek  *    notice, this list of conditions and the following disclaimer.
103c0086b8SZbigniew Bodek  * 2. Redistributions in binary form must reproduce the above copyright
113c0086b8SZbigniew Bodek  *    notice, this list of conditions and the following disclaimer in the
123c0086b8SZbigniew Bodek  *    documentation and/or other materials provided with the distribution.
133c0086b8SZbigniew Bodek  *
143c0086b8SZbigniew Bodek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
153c0086b8SZbigniew Bodek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
163c0086b8SZbigniew Bodek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
173c0086b8SZbigniew Bodek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
183c0086b8SZbigniew Bodek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
193c0086b8SZbigniew Bodek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
203c0086b8SZbigniew Bodek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
213c0086b8SZbigniew Bodek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
223c0086b8SZbigniew Bodek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
233c0086b8SZbigniew Bodek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
243c0086b8SZbigniew Bodek  * SUCH DAMAGE.
253c0086b8SZbigniew Bodek  *
263c0086b8SZbigniew Bodek  */
273c0086b8SZbigniew Bodek 
283c0086b8SZbigniew Bodek #ifndef NIC_H
293c0086b8SZbigniew Bodek #define	NIC_H
303c0086b8SZbigniew Bodek 
312306b72aSZbigniew Bodek /* PCI vendor ID */
322306b72aSZbigniew Bodek #define PCI_VENDOR_ID_CAVIUM			0x177D
333c0086b8SZbigniew Bodek /* PCI device IDs */
343c0086b8SZbigniew Bodek #define	PCI_DEVICE_ID_THUNDER_NIC_PF		0xA01E
353c0086b8SZbigniew Bodek #define	PCI_DEVICE_ID_THUNDER_PASS1_NIC_VF	0x0011
363c0086b8SZbigniew Bodek #define	PCI_DEVICE_ID_THUNDER_NIC_VF		0xA034
373c0086b8SZbigniew Bodek #define	PCI_DEVICE_ID_THUNDER_BGX		0xA026
383c0086b8SZbigniew Bodek 
393c0086b8SZbigniew Bodek /* PCI BAR nos */
403c0086b8SZbigniew Bodek #define	PCI_CFG_REG_BAR_NUM		0
413c0086b8SZbigniew Bodek #define	PCI_MSIX_REG_BAR_NUM		4
423c0086b8SZbigniew Bodek 
433ad422a9SZbigniew Bodek /* PCI revision IDs */
443ad422a9SZbigniew Bodek #define	PCI_REVID_PASS2			8
453ad422a9SZbigniew Bodek 
463c0086b8SZbigniew Bodek /* NIC SRIOV VF count */
473c0086b8SZbigniew Bodek #define	MAX_NUM_VFS_SUPPORTED		128
483c0086b8SZbigniew Bodek #define	DEFAULT_NUM_VF_ENABLED		8
493c0086b8SZbigniew Bodek 
503c0086b8SZbigniew Bodek #define	NIC_TNS_BYPASS_MODE		0
513c0086b8SZbigniew Bodek #define	NIC_TNS_MODE			1
523c0086b8SZbigniew Bodek 
533c0086b8SZbigniew Bodek /* NIC priv flags */
542306b72aSZbigniew Bodek #define	NIC_SRIOV_ENABLED		(1 << 0)
552306b72aSZbigniew Bodek #define	NIC_TNS_ENABLED			(1 << 1)
563c0086b8SZbigniew Bodek 
572306b72aSZbigniew Bodek /* ARM64TODO */
582306b72aSZbigniew Bodek #if 0
593c0086b8SZbigniew Bodek /* VNIC HW optimiation features */
603c0086b8SZbigniew Bodek #define VNIC_RSS_SUPPORT
613c0086b8SZbigniew Bodek #define VNIC_MULTI_QSET_SUPPORT
622306b72aSZbigniew Bodek #endif
633c0086b8SZbigniew Bodek 
643c0086b8SZbigniew Bodek /* Min/Max packet size */
653c0086b8SZbigniew Bodek #define	NIC_HW_MIN_FRS			64
663c0086b8SZbigniew Bodek #define	NIC_HW_MAX_FRS			9200 /* 9216 max packet including FCS */
673c0086b8SZbigniew Bodek 
683c0086b8SZbigniew Bodek /* Max pkinds */
693c0086b8SZbigniew Bodek #define	NIC_MAX_PKIND			16
703c0086b8SZbigniew Bodek 
712306b72aSZbigniew Bodek /*
722306b72aSZbigniew Bodek  * Rx Channels */
733c0086b8SZbigniew Bodek /* Receive channel configuration in TNS bypass mode
743c0086b8SZbigniew Bodek  * Below is configuration in TNS bypass mode
753c0086b8SZbigniew Bodek  * BGX0-LMAC0-CHAN0 - VNIC CHAN0
763c0086b8SZbigniew Bodek  * BGX0-LMAC1-CHAN0 - VNIC CHAN16
773c0086b8SZbigniew Bodek  * ...
783c0086b8SZbigniew Bodek  * BGX1-LMAC0-CHAN0 - VNIC CHAN128
793c0086b8SZbigniew Bodek  * ...
803c0086b8SZbigniew Bodek  * BGX1-LMAC3-CHAN0 - VNIC CHAN174
813c0086b8SZbigniew Bodek  */
823c0086b8SZbigniew Bodek #define	NIC_INTF_COUNT			2  /* Interfaces btw VNIC and TNS/BGX */
833c0086b8SZbigniew Bodek #define	NIC_CHANS_PER_INF		128
843c0086b8SZbigniew Bodek #define	NIC_MAX_CHANS			(NIC_INTF_COUNT * NIC_CHANS_PER_INF)
853c0086b8SZbigniew Bodek #define	NIC_CPI_COUNT			2048 /* No of channel parse indices */
863c0086b8SZbigniew Bodek 
873c0086b8SZbigniew Bodek /* TNS bypass mode: 1-1 mapping between VNIC and BGX:LMAC */
883c0086b8SZbigniew Bodek #define	NIC_MAX_BGX			MAX_BGX_PER_CN88XX
893c0086b8SZbigniew Bodek #define	NIC_CPI_PER_BGX			(NIC_CPI_COUNT / NIC_MAX_BGX)
903c0086b8SZbigniew Bodek #define	NIC_MAX_CPI_PER_LMAC		64 /* Max when CPI_ALG is IP diffserv */
913c0086b8SZbigniew Bodek #define	NIC_RSSI_PER_BGX		(NIC_RSSI_COUNT / NIC_MAX_BGX)
923c0086b8SZbigniew Bodek 
933c0086b8SZbigniew Bodek /* Tx scheduling */
943c0086b8SZbigniew Bodek #define	NIC_MAX_TL4			1024
953c0086b8SZbigniew Bodek #define	NIC_MAX_TL4_SHAPERS		256 /* 1 shaper for 4 TL4s */
963c0086b8SZbigniew Bodek #define	NIC_MAX_TL3			256
973c0086b8SZbigniew Bodek #define	NIC_MAX_TL3_SHAPERS		64  /* 1 shaper for 4 TL3s */
983c0086b8SZbigniew Bodek #define	NIC_MAX_TL2			64
993c0086b8SZbigniew Bodek #define	NIC_MAX_TL2_SHAPERS		2  /* 1 shaper for 32 TL2s */
1003c0086b8SZbigniew Bodek #define	NIC_MAX_TL1			2
1013c0086b8SZbigniew Bodek 
1023c0086b8SZbigniew Bodek /* TNS bypass mode */
1033c0086b8SZbigniew Bodek #define	NIC_TL2_PER_BGX			32
1043c0086b8SZbigniew Bodek #define	NIC_TL4_PER_BGX			(NIC_MAX_TL4 / NIC_MAX_BGX)
1053c0086b8SZbigniew Bodek #define	NIC_TL4_PER_LMAC		(NIC_MAX_TL4 / NIC_CHANS_PER_INF)
1063c0086b8SZbigniew Bodek 
1073c0086b8SZbigniew Bodek /* NIC VF Interrupts */
1083c0086b8SZbigniew Bodek #define	NICVF_INTR_CQ			0
1093c0086b8SZbigniew Bodek #define	NICVF_INTR_SQ			1
1103c0086b8SZbigniew Bodek #define	NICVF_INTR_RBDR			2
1113c0086b8SZbigniew Bodek #define	NICVF_INTR_PKT_DROP		3
1123c0086b8SZbigniew Bodek #define	NICVF_INTR_TCP_TIMER		4
1133c0086b8SZbigniew Bodek #define	NICVF_INTR_MBOX			5
1143c0086b8SZbigniew Bodek #define	NICVF_INTR_QS_ERR		6
1153c0086b8SZbigniew Bodek 
1163c0086b8SZbigniew Bodek #define	NICVF_INTR_CQ_SHIFT		0
1173c0086b8SZbigniew Bodek #define	NICVF_INTR_SQ_SHIFT		8
1183c0086b8SZbigniew Bodek #define	NICVF_INTR_RBDR_SHIFT		16
1193c0086b8SZbigniew Bodek #define	NICVF_INTR_PKT_DROP_SHIFT	20
1203c0086b8SZbigniew Bodek #define	NICVF_INTR_TCP_TIMER_SHIFT	21
1213c0086b8SZbigniew Bodek #define	NICVF_INTR_MBOX_SHIFT		22
1223c0086b8SZbigniew Bodek #define	NICVF_INTR_QS_ERR_SHIFT		23
1233c0086b8SZbigniew Bodek 
1243c0086b8SZbigniew Bodek #define	NICVF_INTR_CQ_MASK		(0xFF << NICVF_INTR_CQ_SHIFT)
1253c0086b8SZbigniew Bodek #define	NICVF_INTR_SQ_MASK		(0xFF << NICVF_INTR_SQ_SHIFT)
1263c0086b8SZbigniew Bodek #define	NICVF_INTR_RBDR_MASK		(0x03 << NICVF_INTR_RBDR_SHIFT)
1272306b72aSZbigniew Bodek #define	NICVF_INTR_PKT_DROP_MASK	(1 << NICVF_INTR_PKT_DROP_SHIFT)
1282306b72aSZbigniew Bodek #define	NICVF_INTR_TCP_TIMER_MASK	(1 << NICVF_INTR_TCP_TIMER_SHIFT)
1292306b72aSZbigniew Bodek #define	NICVF_INTR_MBOX_MASK		(1 << NICVF_INTR_MBOX_SHIFT)
1302306b72aSZbigniew Bodek #define	NICVF_INTR_QS_ERR_MASK		(1 << NICVF_INTR_QS_ERR_SHIFT)
1313c0086b8SZbigniew Bodek 
1323c0086b8SZbigniew Bodek /* MSI-X interrupts */
1333c0086b8SZbigniew Bodek #define	NIC_PF_MSIX_VECTORS		10
1343c0086b8SZbigniew Bodek #define	NIC_VF_MSIX_VECTORS		20
1353c0086b8SZbigniew Bodek 
1363c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_ECC0_SBE		0
1373c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_ECC0_DBE		1
1383c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_ECC1_SBE		2
1393c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_ECC1_DBE		3
1403c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_ECC2_SBE		4
1413c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_ECC2_DBE		5
1423c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_ECC3_SBE		6
1433c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_ECC3_DBE		7
1443c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_MBOX0		8
1453c0086b8SZbigniew Bodek #define	NIC_PF_INTR_ID_MBOX1		9
1463c0086b8SZbigniew Bodek 
1472306b72aSZbigniew Bodek struct msix_entry {
1482306b72aSZbigniew Bodek 	struct resource *	irq_res;
1492306b72aSZbigniew Bodek 	void *			handle;
1502306b72aSZbigniew Bodek };
1512306b72aSZbigniew Bodek 
1522306b72aSZbigniew Bodek /*
1532306b72aSZbigniew Bodek  * Global timer for CQ timer thresh interrupts
1543c0086b8SZbigniew Bodek  * Calculated for SCLK of 700Mhz
1553c0086b8SZbigniew Bodek  * value written should be a 1/16th of what is expected
1563c0086b8SZbigniew Bodek  *
1573c0086b8SZbigniew Bodek  * 1 tick per 0.05usec = value of 2.2
1583c0086b8SZbigniew Bodek  * This 10% would be covered in CQ timer thresh value
1593c0086b8SZbigniew Bodek  */
1603c0086b8SZbigniew Bodek #define NICPF_CLK_PER_INT_TICK		2
1613c0086b8SZbigniew Bodek 
1622306b72aSZbigniew Bodek /*
1632306b72aSZbigniew Bodek  * Time to wait before we decide that a SQ is stuck.
1643c0086b8SZbigniew Bodek  *
1653c0086b8SZbigniew Bodek  * Since both pkt rx and tx notifications are done with same CQ,
1663c0086b8SZbigniew Bodek  * when packets are being received at very high rate (eg: L2 forwarding)
1673c0086b8SZbigniew Bodek  * then freeing transmitted skbs will be delayed and watchdog
1683c0086b8SZbigniew Bodek  * will kick in, resetting interface. Hence keeping this value high.
1693c0086b8SZbigniew Bodek  */
1703c0086b8SZbigniew Bodek #define	NICVF_TX_TIMEOUT		(50 * HZ)
1713c0086b8SZbigniew Bodek 
1723c0086b8SZbigniew Bodek #define	NIC_RSSI_COUNT			4096 /* Total no of RSS indices */
1733c0086b8SZbigniew Bodek #define	NIC_MAX_RSS_HASH_BITS		8
1743c0086b8SZbigniew Bodek #define	NIC_MAX_RSS_IDR_TBL_SIZE	(1 << NIC_MAX_RSS_HASH_BITS)
1753c0086b8SZbigniew Bodek #define	RSS_HASH_KEY_SIZE		5 /* 320 bit key */
1763c0086b8SZbigniew Bodek 
1778191a879SZbigniew Bodek struct nicvf_rss_info {
1788191a879SZbigniew Bodek 	boolean_t enable;
1798191a879SZbigniew Bodek #define	RSS_L2_EXTENDED_HASH_ENA	(1UL << 0)
1808191a879SZbigniew Bodek #define	RSS_IP_HASH_ENA			(1UL << 1)
1818191a879SZbigniew Bodek #define	RSS_TCP_HASH_ENA		(1UL << 2)
1828191a879SZbigniew Bodek #define	RSS_TCP_SYN_DIS			(1UL << 3)
1838191a879SZbigniew Bodek #define	RSS_UDP_HASH_ENA		(1UL << 4)
1848191a879SZbigniew Bodek #define	RSS_L4_EXTENDED_HASH_ENA	(1UL << 5)
1858191a879SZbigniew Bodek #define	RSS_ROCE_ENA			(1UL << 6)
1868191a879SZbigniew Bodek #define	RSS_L3_BI_DIRECTION_ENA		(1UL << 7)
1878191a879SZbigniew Bodek #define	RSS_L4_BI_DIRECTION_ENA		(1UL << 8)
1888191a879SZbigniew Bodek 	uint64_t cfg;
1898191a879SZbigniew Bodek 	uint8_t  hash_bits;
1908191a879SZbigniew Bodek 	uint16_t rss_size;
1918191a879SZbigniew Bodek 	uint8_t  ind_tbl[NIC_MAX_RSS_IDR_TBL_SIZE];
1928191a879SZbigniew Bodek 	uint64_t key[RSS_HASH_KEY_SIZE];
1938191a879SZbigniew Bodek };
1948191a879SZbigniew Bodek 
1953c0086b8SZbigniew Bodek enum rx_stats_reg_offset {
1963c0086b8SZbigniew Bodek 	RX_OCTS = 0x0,
1973c0086b8SZbigniew Bodek 	RX_UCAST = 0x1,
1983c0086b8SZbigniew Bodek 	RX_BCAST = 0x2,
1993c0086b8SZbigniew Bodek 	RX_MCAST = 0x3,
2003c0086b8SZbigniew Bodek 	RX_RED = 0x4,
2013c0086b8SZbigniew Bodek 	RX_RED_OCTS = 0x5,
2023c0086b8SZbigniew Bodek 	RX_ORUN = 0x6,
2033c0086b8SZbigniew Bodek 	RX_ORUN_OCTS = 0x7,
2043c0086b8SZbigniew Bodek 	RX_FCS = 0x8,
2053c0086b8SZbigniew Bodek 	RX_L2ERR = 0x9,
2063c0086b8SZbigniew Bodek 	RX_DRP_BCAST = 0xa,
2073c0086b8SZbigniew Bodek 	RX_DRP_MCAST = 0xb,
2083c0086b8SZbigniew Bodek 	RX_DRP_L3BCAST = 0xc,
2093c0086b8SZbigniew Bodek 	RX_DRP_L3MCAST = 0xd,
2103c0086b8SZbigniew Bodek 	RX_STATS_ENUM_LAST,
2113c0086b8SZbigniew Bodek };
2123c0086b8SZbigniew Bodek 
2133c0086b8SZbigniew Bodek enum tx_stats_reg_offset {
2143c0086b8SZbigniew Bodek 	TX_OCTS = 0x0,
2153c0086b8SZbigniew Bodek 	TX_UCAST = 0x1,
2163c0086b8SZbigniew Bodek 	TX_BCAST = 0x2,
2173c0086b8SZbigniew Bodek 	TX_MCAST = 0x3,
2183c0086b8SZbigniew Bodek 	TX_DROP = 0x4,
2193c0086b8SZbigniew Bodek 	TX_STATS_ENUM_LAST,
2203c0086b8SZbigniew Bodek };
2213c0086b8SZbigniew Bodek 
2223c0086b8SZbigniew Bodek struct nicvf_hw_stats {
2232306b72aSZbigniew Bodek 	uint64_t rx_bytes;
2242306b72aSZbigniew Bodek 	uint64_t rx_ucast_frames;
2252306b72aSZbigniew Bodek 	uint64_t rx_bcast_frames;
2262306b72aSZbigniew Bodek 	uint64_t rx_mcast_frames;
2272306b72aSZbigniew Bodek 	uint64_t rx_fcs_errors;
2282306b72aSZbigniew Bodek 	uint64_t rx_l2_errors;
2292306b72aSZbigniew Bodek 	uint64_t rx_drop_red;
2302306b72aSZbigniew Bodek 	uint64_t rx_drop_red_bytes;
2312306b72aSZbigniew Bodek 	uint64_t rx_drop_overrun;
2322306b72aSZbigniew Bodek 	uint64_t rx_drop_overrun_bytes;
2332306b72aSZbigniew Bodek 	uint64_t rx_drop_bcast;
2342306b72aSZbigniew Bodek 	uint64_t rx_drop_mcast;
2352306b72aSZbigniew Bodek 	uint64_t rx_drop_l3_bcast;
2362306b72aSZbigniew Bodek 	uint64_t rx_drop_l3_mcast;
2372306b72aSZbigniew Bodek 	uint64_t rx_bgx_truncated_pkts;
2382306b72aSZbigniew Bodek 	uint64_t rx_jabber_errs;
2392306b72aSZbigniew Bodek 	uint64_t rx_fcs_errs;
2402306b72aSZbigniew Bodek 	uint64_t rx_bgx_errs;
2412306b72aSZbigniew Bodek 	uint64_t rx_prel2_errs;
2422306b72aSZbigniew Bodek 	uint64_t rx_l2_hdr_malformed;
2432306b72aSZbigniew Bodek 	uint64_t rx_oversize;
2442306b72aSZbigniew Bodek 	uint64_t rx_undersize;
2452306b72aSZbigniew Bodek 	uint64_t rx_l2_len_mismatch;
2462306b72aSZbigniew Bodek 	uint64_t rx_l2_pclp;
2472306b72aSZbigniew Bodek 	uint64_t rx_ip_ver_errs;
2482306b72aSZbigniew Bodek 	uint64_t rx_ip_csum_errs;
2492306b72aSZbigniew Bodek 	uint64_t rx_ip_hdr_malformed;
2502306b72aSZbigniew Bodek 	uint64_t rx_ip_payload_malformed;
2512306b72aSZbigniew Bodek 	uint64_t rx_ip_ttl_errs;
2522306b72aSZbigniew Bodek 	uint64_t rx_l3_pclp;
2532306b72aSZbigniew Bodek 	uint64_t rx_l4_malformed;
2542306b72aSZbigniew Bodek 	uint64_t rx_l4_csum_errs;
2552306b72aSZbigniew Bodek 	uint64_t rx_udp_len_errs;
2562306b72aSZbigniew Bodek 	uint64_t rx_l4_port_errs;
2572306b72aSZbigniew Bodek 	uint64_t rx_tcp_flag_errs;
2582306b72aSZbigniew Bodek 	uint64_t rx_tcp_offset_errs;
2592306b72aSZbigniew Bodek 	uint64_t rx_l4_pclp;
2602306b72aSZbigniew Bodek 	uint64_t rx_truncated_pkts;
2613c0086b8SZbigniew Bodek 
2622306b72aSZbigniew Bodek 	uint64_t tx_bytes_ok;
2632306b72aSZbigniew Bodek 	uint64_t tx_ucast_frames_ok;
2642306b72aSZbigniew Bodek 	uint64_t tx_bcast_frames_ok;
2652306b72aSZbigniew Bodek 	uint64_t tx_mcast_frames_ok;
2662306b72aSZbigniew Bodek 	uint64_t tx_drops;
2673c0086b8SZbigniew Bodek };
2683c0086b8SZbigniew Bodek 
2693c0086b8SZbigniew Bodek struct nicvf_drv_stats {
2703c0086b8SZbigniew Bodek 	/* Rx */
2712306b72aSZbigniew Bodek 	uint64_t rx_frames_ok;
2722306b72aSZbigniew Bodek 	uint64_t rx_frames_64;
2732306b72aSZbigniew Bodek 	uint64_t rx_frames_127;
2742306b72aSZbigniew Bodek 	uint64_t rx_frames_255;
2752306b72aSZbigniew Bodek 	uint64_t rx_frames_511;
2762306b72aSZbigniew Bodek 	uint64_t rx_frames_1023;
2772306b72aSZbigniew Bodek 	uint64_t rx_frames_1518;
2782306b72aSZbigniew Bodek 	uint64_t rx_frames_jumbo;
2792306b72aSZbigniew Bodek 	uint64_t rx_drops;
2803c0086b8SZbigniew Bodek 
2813c0086b8SZbigniew Bodek 	/* Tx */
2822306b72aSZbigniew Bodek 	uint64_t tx_frames_ok;
2832306b72aSZbigniew Bodek 	uint64_t tx_drops;
2842306b72aSZbigniew Bodek 	uint64_t tx_tso;
2852306b72aSZbigniew Bodek 	uint64_t txq_stop;
2862306b72aSZbigniew Bodek 	uint64_t txq_wake;
2873c0086b8SZbigniew Bodek };
2883c0086b8SZbigniew Bodek 
2893c0086b8SZbigniew Bodek struct nicvf {
2903c0086b8SZbigniew Bodek 	struct nicvf		*pnicvf;
2912306b72aSZbigniew Bodek 	device_t		dev;
2923c0086b8SZbigniew Bodek 
293*b9545c57SJustin Hibbits 	if_t 			ifp;
2942306b72aSZbigniew Bodek 	struct sx		core_sx;
2952306b72aSZbigniew Bodek 	struct ifmedia		if_media;
2962306b72aSZbigniew Bodek 	uint32_t		if_flags;
2972306b72aSZbigniew Bodek 
2982306b72aSZbigniew Bodek 	uint8_t			hwaddr[ETHER_ADDR_LEN];
2992306b72aSZbigniew Bodek 	uint8_t			vf_id;
3002306b72aSZbigniew Bodek 	uint8_t			node;
3012306b72aSZbigniew Bodek 	boolean_t		tns_mode:1;
3022306b72aSZbigniew Bodek 	boolean_t		sqs_mode:1;
3032306b72aSZbigniew Bodek 	bool			loopback_supported:1;
3048191a879SZbigniew Bodek 	struct nicvf_rss_info	rss_info;
3052306b72aSZbigniew Bodek 	uint16_t		mtu;
3062306b72aSZbigniew Bodek 	struct queue_set	*qs;
3072306b72aSZbigniew Bodek 	uint8_t			rx_queues;
3082306b72aSZbigniew Bodek 	uint8_t			tx_queues;
3092306b72aSZbigniew Bodek 	uint8_t			max_queues;
3102306b72aSZbigniew Bodek 	struct resource		*reg_base;
3112306b72aSZbigniew Bodek 	boolean_t		link_up;
312af8fe8f1SZbigniew Bodek 	boolean_t		hw_tso;
3132306b72aSZbigniew Bodek 	uint8_t			duplex;
3142306b72aSZbigniew Bodek 	uint32_t		speed;
3152306b72aSZbigniew Bodek 	uint8_t			cpi_alg;
3162306b72aSZbigniew Bodek 	/* Interrupt coalescing settings */
3172306b72aSZbigniew Bodek 	uint32_t		cq_coalesce_usecs;
3182306b72aSZbigniew Bodek 
3192306b72aSZbigniew Bodek 	uint32_t		msg_enable;
3203c0086b8SZbigniew Bodek 	struct nicvf_hw_stats	hw_stats;
3213c0086b8SZbigniew Bodek 	struct nicvf_drv_stats	drv_stats;
3223c0086b8SZbigniew Bodek 	struct bgx_stats	bgx_stats;
3232306b72aSZbigniew Bodek 
3242306b72aSZbigniew Bodek 	/* Interface statistics */
3252306b72aSZbigniew Bodek 	struct callout		stats_callout;
3262306b72aSZbigniew Bodek 	struct mtx		stats_mtx;
3273c0086b8SZbigniew Bodek 
3283c0086b8SZbigniew Bodek 	/* MSI-X  */
3292306b72aSZbigniew Bodek 	boolean_t		msix_enabled;
3302306b72aSZbigniew Bodek 	uint8_t			num_vec;
3313c0086b8SZbigniew Bodek 	struct msix_entry	msix_entries[NIC_VF_MSIX_VECTORS];
3322306b72aSZbigniew Bodek 	struct resource *	msix_table_res;
3333c0086b8SZbigniew Bodek 	char			irq_name[NIC_VF_MSIX_VECTORS][20];
3342306b72aSZbigniew Bodek 	boolean_t		irq_allocated[NIC_VF_MSIX_VECTORS];
3353c0086b8SZbigniew Bodek 
3363c0086b8SZbigniew Bodek 	/* VF <-> PF mailbox communication */
3372306b72aSZbigniew Bodek 	boolean_t		pf_acked;
3382306b72aSZbigniew Bodek 	boolean_t		pf_nacked;
3392306b72aSZbigniew Bodek } __aligned(CACHE_LINE_SIZE);
3403c0086b8SZbigniew Bodek 
3412306b72aSZbigniew Bodek /*
3422306b72aSZbigniew Bodek  * PF <--> VF Mailbox communication
3433c0086b8SZbigniew Bodek  * Eight 64bit registers are shared between PF and VF.
3443c0086b8SZbigniew Bodek  * Separate set for each VF.
3453c0086b8SZbigniew Bodek  * Writing '1' into last register mbx7 means end of message.
3463c0086b8SZbigniew Bodek  */
3473c0086b8SZbigniew Bodek 
3483c0086b8SZbigniew Bodek /* PF <--> VF mailbox communication */
3493c0086b8SZbigniew Bodek #define	NIC_PF_VF_MAILBOX_SIZE		2
3503c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_TIMEOUT		2000 /* ms */
3513c0086b8SZbigniew Bodek 
3523c0086b8SZbigniew Bodek /* Mailbox message types */
3533c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_READY		0x01	/* Is PF ready to rcv msgs */
3543c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_ACK		0x02	/* ACK the message received */
3553c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_NACK		0x03	/* NACK the message received */
3563c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_QS_CFG		0x04	/* Configure Qset */
3573c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_RQ_CFG		0x05	/* Configure receive queue */
3583c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_SQ_CFG		0x06	/* Configure Send queue */
3593c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_RQ_DROP_CFG	0x07	/* Configure receive queue */
3603c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_SET_MAC		0x08	/* Add MAC ID to DMAC filter */
3613c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_SET_MAX_FRS	0x09	/* Set max frame size */
3623c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_CPI_CFG		0x0A	/* Config CPI, RSSI */
3633c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_RSS_SIZE		0x0B	/* Get RSS indir_tbl size */
3643c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_RSS_CFG		0x0C	/* Config RSS table */
3653c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_RSS_CFG_CONT	0x0D	/* RSS config continuation */
3663c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_RQ_BP_CFG		0x0E	/* RQ backpressure config */
3673c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_RQ_SW_SYNC		0x0F	/* Flush inflight pkts to RQ */
3683c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_BGX_STATS		0x10	/* Get stats from BGX */
3693c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_BGX_LINK_CHANGE	0x11	/* BGX:LMAC link status */
3703c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_ALLOC_SQS		0x12	/* Allocate secondary Qset */
3713c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_NICVF_PTR		0x13	/* Send nicvf ptr to PF */
3723c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_PNICVF_PTR		0x14	/* Get primary qset nicvf ptr */
3733c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_SNICVF_PTR		0x15	/* Send sqet nicvf ptr to PVF */
3743c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_LOOPBACK		0x16	/* Set interface in loopback */
3753c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_CFG_DONE		0xF0	/* VF configuration done */
3763c0086b8SZbigniew Bodek #define	NIC_MBOX_MSG_SHUTDOWN		0xF1	/* VF is being shutdown */
3773c0086b8SZbigniew Bodek 
3783c0086b8SZbigniew Bodek struct nic_cfg_msg {
3792306b72aSZbigniew Bodek 	uint8_t		msg;
3802306b72aSZbigniew Bodek 	uint8_t		vf_id;
3812306b72aSZbigniew Bodek 	uint8_t		node_id;
3822306b72aSZbigniew Bodek 	boolean_t	tns_mode:1;
3832306b72aSZbigniew Bodek 	boolean_t	sqs_mode:1;
3842306b72aSZbigniew Bodek 	boolean_t	loopback_supported:1;
3852306b72aSZbigniew Bodek 	uint8_t	mac_addr[ETHER_ADDR_LEN];
3863c0086b8SZbigniew Bodek };
3873c0086b8SZbigniew Bodek 
3883c0086b8SZbigniew Bodek /* Qset configuration */
3893c0086b8SZbigniew Bodek struct qs_cfg_msg {
3902306b72aSZbigniew Bodek 	uint8_t		msg;
3912306b72aSZbigniew Bodek 	uint8_t		num;
3922306b72aSZbigniew Bodek 	uint8_t		sqs_count;
3932306b72aSZbigniew Bodek 	uint64_t	cfg;
3943c0086b8SZbigniew Bodek };
3953c0086b8SZbigniew Bodek 
3963c0086b8SZbigniew Bodek /* Receive queue configuration */
3973c0086b8SZbigniew Bodek struct rq_cfg_msg {
3982306b72aSZbigniew Bodek 	uint8_t		msg;
3992306b72aSZbigniew Bodek 	uint8_t		qs_num;
4002306b72aSZbigniew Bodek 	uint8_t		rq_num;
4012306b72aSZbigniew Bodek 	uint64_t	cfg;
4023c0086b8SZbigniew Bodek };
4033c0086b8SZbigniew Bodek 
4043c0086b8SZbigniew Bodek /* Send queue configuration */
4053c0086b8SZbigniew Bodek struct sq_cfg_msg {
4062306b72aSZbigniew Bodek 	uint8_t		msg;
4072306b72aSZbigniew Bodek 	uint8_t		qs_num;
4082306b72aSZbigniew Bodek 	uint8_t		sq_num;
4092306b72aSZbigniew Bodek 	boolean_t	sqs_mode;
4102306b72aSZbigniew Bodek 	uint64_t	cfg;
4113c0086b8SZbigniew Bodek };
4123c0086b8SZbigniew Bodek 
4133c0086b8SZbigniew Bodek /* Set VF's MAC address */
4143c0086b8SZbigniew Bodek struct set_mac_msg {
4152306b72aSZbigniew Bodek 	uint8_t		msg;
4162306b72aSZbigniew Bodek 	uint8_t		vf_id;
4172306b72aSZbigniew Bodek 	uint8_t		mac_addr[ETHER_ADDR_LEN];
4183c0086b8SZbigniew Bodek };
4193c0086b8SZbigniew Bodek 
4203c0086b8SZbigniew Bodek /* Set Maximum frame size */
4213c0086b8SZbigniew Bodek struct set_frs_msg {
4222306b72aSZbigniew Bodek 	uint8_t		msg;
4232306b72aSZbigniew Bodek 	uint8_t		vf_id;
4242306b72aSZbigniew Bodek 	uint16_t	max_frs;
4253c0086b8SZbigniew Bodek };
4263c0086b8SZbigniew Bodek 
4273c0086b8SZbigniew Bodek /* Set CPI algorithm type */
4283c0086b8SZbigniew Bodek struct cpi_cfg_msg {
4292306b72aSZbigniew Bodek 	uint8_t		msg;
4302306b72aSZbigniew Bodek 	uint8_t		vf_id;
4312306b72aSZbigniew Bodek 	uint8_t		rq_cnt;
4322306b72aSZbigniew Bodek 	uint8_t		cpi_alg;
4333c0086b8SZbigniew Bodek };
4343c0086b8SZbigniew Bodek 
4353c0086b8SZbigniew Bodek /* Get RSS table size */
4363c0086b8SZbigniew Bodek struct rss_sz_msg {
4372306b72aSZbigniew Bodek 	uint8_t		msg;
4382306b72aSZbigniew Bodek 	uint8_t		vf_id;
4392306b72aSZbigniew Bodek 	uint16_t	ind_tbl_size;
4403c0086b8SZbigniew Bodek };
4413c0086b8SZbigniew Bodek 
4423c0086b8SZbigniew Bodek /* Set RSS configuration */
4433c0086b8SZbigniew Bodek struct rss_cfg_msg {
4442306b72aSZbigniew Bodek 	uint8_t		msg;
4452306b72aSZbigniew Bodek 	uint8_t		vf_id;
4462306b72aSZbigniew Bodek 	uint8_t		hash_bits;
4472306b72aSZbigniew Bodek 	uint8_t		tbl_len;
4482306b72aSZbigniew Bodek 	uint8_t		tbl_offset;
4493c0086b8SZbigniew Bodek #define	RSS_IND_TBL_LEN_PER_MBX_MSG	8
4502306b72aSZbigniew Bodek 	uint8_t		ind_tbl[RSS_IND_TBL_LEN_PER_MBX_MSG];
4513c0086b8SZbigniew Bodek };
4523c0086b8SZbigniew Bodek 
4533c0086b8SZbigniew Bodek struct bgx_stats_msg {
4542306b72aSZbigniew Bodek 	uint8_t		msg;
4552306b72aSZbigniew Bodek 	uint8_t		vf_id;
4562306b72aSZbigniew Bodek 	uint8_t		rx;
4572306b72aSZbigniew Bodek 	uint8_t		idx;
4582306b72aSZbigniew Bodek 	uint64_t	stats;
4593c0086b8SZbigniew Bodek };
4603c0086b8SZbigniew Bodek 
4613c0086b8SZbigniew Bodek /* Physical interface link status */
4623c0086b8SZbigniew Bodek struct bgx_link_status {
4632306b72aSZbigniew Bodek 	uint8_t		msg;
4642306b72aSZbigniew Bodek 	uint8_t		link_up;
4652306b72aSZbigniew Bodek 	uint8_t		duplex;
4662306b72aSZbigniew Bodek 	uint32_t	speed;
4673c0086b8SZbigniew Bodek };
4683c0086b8SZbigniew Bodek 
4693c0086b8SZbigniew Bodek /* Set interface in loopback mode */
4703c0086b8SZbigniew Bodek struct set_loopback {
4712306b72aSZbigniew Bodek 	uint8_t		msg;
4722306b72aSZbigniew Bodek 	uint8_t		vf_id;
4732306b72aSZbigniew Bodek 	boolean_t	enable;
4743c0086b8SZbigniew Bodek };
4753c0086b8SZbigniew Bodek 
4763c0086b8SZbigniew Bodek /* 128 bit shared memory between PF and each VF */
4773c0086b8SZbigniew Bodek union nic_mbx {
4782306b72aSZbigniew Bodek 	struct {
4792306b72aSZbigniew Bodek 		uint8_t msg;
4802306b72aSZbigniew Bodek 	} msg;
4813c0086b8SZbigniew Bodek 	struct nic_cfg_msg	nic_cfg;
4823c0086b8SZbigniew Bodek 	struct qs_cfg_msg	qs;
4833c0086b8SZbigniew Bodek 	struct rq_cfg_msg	rq;
4843c0086b8SZbigniew Bodek 	struct sq_cfg_msg	sq;
4853c0086b8SZbigniew Bodek 	struct set_mac_msg	mac;
4863c0086b8SZbigniew Bodek 	struct set_frs_msg	frs;
4873c0086b8SZbigniew Bodek 	struct cpi_cfg_msg	cpi_cfg;
4883c0086b8SZbigniew Bodek 	struct rss_sz_msg	rss_size;
4893c0086b8SZbigniew Bodek 	struct rss_cfg_msg	rss_cfg;
4903c0086b8SZbigniew Bodek 	struct bgx_stats_msg	bgx_stats;
4913c0086b8SZbigniew Bodek 	struct bgx_link_status	link_status;
4923c0086b8SZbigniew Bodek 	struct set_loopback	lbk;
4933c0086b8SZbigniew Bodek };
4943c0086b8SZbigniew Bodek 
4953c0086b8SZbigniew Bodek #define	NIC_NODE_ID_MASK	0x03
4963c0086b8SZbigniew Bodek #define	NIC_NODE_ID_SHIFT	44
4973c0086b8SZbigniew Bodek 
4982306b72aSZbigniew Bodek static __inline int
nic_get_node_id(struct resource * res)4992306b72aSZbigniew Bodek nic_get_node_id(struct resource *res)
5003c0086b8SZbigniew Bodek {
5012306b72aSZbigniew Bodek 	pci_addr_t addr;
5022306b72aSZbigniew Bodek 
5032306b72aSZbigniew Bodek 	addr = rman_get_start(res);
5043c0086b8SZbigniew Bodek 	return ((addr >> NIC_NODE_ID_SHIFT) & NIC_NODE_ID_MASK);
5053c0086b8SZbigniew Bodek }
5063c0086b8SZbigniew Bodek 
5073ad422a9SZbigniew Bodek static __inline boolean_t
pass1_silicon(device_t dev)5083ad422a9SZbigniew Bodek pass1_silicon(device_t dev)
5093ad422a9SZbigniew Bodek {
5103ad422a9SZbigniew Bodek 
5113ad422a9SZbigniew Bodek 	/* Check if the chip revision is < Pass2 */
5123ad422a9SZbigniew Bodek 	return (pci_get_revid(dev) < PCI_REVID_PASS2);
5133ad422a9SZbigniew Bodek }
5143ad422a9SZbigniew Bodek 
5153c0086b8SZbigniew Bodek int nicvf_send_msg_to_pf(struct nicvf *vf, union nic_mbx *mbx);
5163c0086b8SZbigniew Bodek 
5173c0086b8SZbigniew Bodek #endif /* NIC_H */
518