xref: /openbsd/sys/dev/pci/if_igc.h (revision fb54a5a4)
1*fb54a5a4Sbluhm /*	$OpenBSD: if_igc.h,v 1.4 2024/05/21 11:19:39 bluhm Exp $	*/
283306792Spatrick /*-
383306792Spatrick  * SPDX-License-Identifier: BSD-2-Clause
483306792Spatrick  *
583306792Spatrick  * Copyright (c) 2016 Nicole Graziano <nicole@nextbsd.org>
683306792Spatrick  * All rights reserved.
783306792Spatrick  * Copyright (c) 2021 Rubicon Communications, LLC (Netgate)
883306792Spatrick  *
983306792Spatrick  * Redistribution and use in source and binary forms, with or without
1083306792Spatrick  * modification, are permitted provided that the following conditions
1183306792Spatrick  * are met:
1283306792Spatrick  * 1. Redistributions of source code must retain the above copyright
1383306792Spatrick  *    notice, this list of conditions and the following disclaimer.
1483306792Spatrick  * 2. Redistributions in binary form must reproduce the above copyright
1583306792Spatrick  *    notice, this list of conditions and the following disclaimer in the
1683306792Spatrick  *    documentation and/or other materials provided with the distribution.
1783306792Spatrick  *
1883306792Spatrick  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1983306792Spatrick  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2083306792Spatrick  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2183306792Spatrick  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2283306792Spatrick  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2383306792Spatrick  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2483306792Spatrick  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2583306792Spatrick  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2683306792Spatrick  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2783306792Spatrick  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2883306792Spatrick  * SUCH DAMAGE.
2983306792Spatrick  *
3083306792Spatrick  * $FreeBSD$
3183306792Spatrick  */
3283306792Spatrick 
3383306792Spatrick #ifndef _IGC_H_
3483306792Spatrick #define _IGC_H_
3583306792Spatrick 
3683306792Spatrick #include <dev/pci/igc_api.h>
3783306792Spatrick #include <dev/pci/igc_i225.h>
3883306792Spatrick 
3983306792Spatrick /*
4083306792Spatrick  * IGC_MAX_TXD: Maximum number of Transmit Descriptors
4183306792Spatrick  * Valid Range: 128-4096
4283306792Spatrick  * Default Value: 1024
4383306792Spatrick  *   This value is the number of transmit descriptors allocated by the driver.
4483306792Spatrick  *   Increasing this value allows the driver to queue more transmits. Each
4583306792Spatrick  *   descriptor is 16 bytes.
4683306792Spatrick  *   Since TDLEN should be multiple of 128bytes, the number of transmit
474b1a56afSjsg  *   descriptors should meet the following condition.
4883306792Spatrick  *      (num_tx_desc * sizeof(struct igc_tx_desc)) % 128 == 0
4983306792Spatrick  */
5083306792Spatrick #define IGC_MIN_TXD		128
5183306792Spatrick #define IGC_MAX_TXD		4096
5283306792Spatrick #define IGC_DEFAULT_TXD		1024
5383306792Spatrick #define IGC_DEFAULT_MULTI_TXD	4096
5483306792Spatrick #define IGC_MAX_TXD		4096
5583306792Spatrick 
5683306792Spatrick /*
5783306792Spatrick  * IGC_MAX_RXD - Maximum number of receive Descriptors
5883306792Spatrick  * Valid Range: 128-4096
5983306792Spatrick  * Default Value: 1024
6083306792Spatrick  *   This value is the number of receive descriptors allocated by the driver.
6183306792Spatrick  *   Increasing this value allows the driver to buffer more incoming packets.
6283306792Spatrick  *   Each descriptor is 16 bytes.  A receive buffer is also allocated for each
6383306792Spatrick  *   descriptor. The maximum MTU size is 16110.
6483306792Spatrick  *   Since TDLEN should be multiple of 128bytes, the number of transmit
654b1a56afSjsg  *   descriptors should meet the following condition.
6683306792Spatrick  *      (num_tx_desc * sizeof(struct igc_tx_desc)) % 128 == 0
6783306792Spatrick  */
6883306792Spatrick #define IGC_MIN_RXD		128
6983306792Spatrick #define IGC_MAX_RXD		4096
7083306792Spatrick #define IGC_DEFAULT_RXD		1024
7183306792Spatrick #define IGC_DEFAULT_MULTI_RXD	4096
7283306792Spatrick #define IGC_MAX_RXD		4096
7383306792Spatrick 
7483306792Spatrick /*
7583306792Spatrick  * IGC_TIDV_VAL - Transmit Interrupt Delay Value
7683306792Spatrick  * Valid Range: 0-65535 (0=off)
7783306792Spatrick  * Default Value: 64
7883306792Spatrick  *   This value delays the generation of transmit interrupts in units of
7983306792Spatrick  *   1.024 microseconds. Transmit interrupt reduction can improve CPU
8083306792Spatrick  *   efficiency if properly tuned for specific network traffic. If the
8183306792Spatrick  *   system is reporting dropped transmits, this value may be set too high
8283306792Spatrick  *   causing the driver to run out of available transmit descriptors.
8383306792Spatrick  */
8483306792Spatrick #define IGC_TIDV_VAL		64
8583306792Spatrick 
8683306792Spatrick /*
8783306792Spatrick  * IGC_TADV_VAL - Transmit Absolute Interrupt Delay Value
8883306792Spatrick  * Valid Range: 0-65535 (0=off)
8983306792Spatrick  * Default Value: 64
9083306792Spatrick  *   This value, in units of 1.024 microseconds, limits the delay in which a
9183306792Spatrick  *   transmit interrupt is generated. Useful only if IGC_TIDV is non-zero,
9283306792Spatrick  *   this value ensures that an interrupt is generated after the initial
9383306792Spatrick  *   packet is sent on the wire within the set amount of time.  Proper tuning,
9483306792Spatrick  *   along with IGC_TIDV_VAL, may improve traffic throughput in specific
9583306792Spatrick  *   network conditions.
9683306792Spatrick  */
9783306792Spatrick #define IGC_TADV_VAL		64
9883306792Spatrick 
9983306792Spatrick /*
10083306792Spatrick  * IGC_RDTR_VAL - Receive Interrupt Delay Timer (Packet Timer)
10183306792Spatrick  * Valid Range: 0-65535 (0=off)
10283306792Spatrick  * Default Value: 0
10383306792Spatrick  *   This value delays the generation of receive interrupts in units of 1.024
10483306792Spatrick  *   microseconds.  Receive interrupt reduction can improve CPU efficiency if
10583306792Spatrick  *   properly tuned for specific network traffic. Increasing this value adds
10683306792Spatrick  *   extra latency to frame reception and can end up decreasing the throughput
10783306792Spatrick  *   of TCP traffic. If the system is reporting dropped receives, this value
10883306792Spatrick  *   may be set too high, causing the driver to run out of available receive
10983306792Spatrick  *   descriptors.
11083306792Spatrick  *
11183306792Spatrick  *   CAUTION: When setting IGC_RDTR to a value other than 0, adapters
11283306792Spatrick  *            may hang (stop transmitting) under certain network conditions.
11383306792Spatrick  *            If this occurs a WATCHDOG message is logged in the system
11483306792Spatrick  *            event log. In addition, the controller is automatically reset,
11583306792Spatrick  *            restoring the network connection. To eliminate the potential
11683306792Spatrick  *            for the hang ensure that IGC_RDTR is set to 0.
11783306792Spatrick  */
11883306792Spatrick #define IGC_RDTR_VAL		0
11983306792Spatrick 
12083306792Spatrick /*
12183306792Spatrick  * Receive Interrupt Absolute Delay Timer
12283306792Spatrick  * Valid Range: 0-65535 (0=off)
12383306792Spatrick  * Default Value: 64
12483306792Spatrick  *   This value, in units of 1.024 microseconds, limits the delay in which a
12583306792Spatrick  *   receive interrupt is generated. Useful only if IGC_RDTR is non-zero,
12683306792Spatrick  *   this value ensures that an interrupt is generated after the initial
12783306792Spatrick  *   packet is received within the set amount of time.  Proper tuning,
12883306792Spatrick  *   along with IGC_RDTR, may improve traffic throughput in specific network
12983306792Spatrick  *   conditions.
13083306792Spatrick  */
13183306792Spatrick #define IGC_RADV_VAL		64
13283306792Spatrick 
13383306792Spatrick /*
1344b1a56afSjsg  * This parameter controls whether or not autonegotiation is enabled.
13583306792Spatrick  *              0 - Disable autonegotiation
13683306792Spatrick  *              1 - Enable  autonegotiation
13783306792Spatrick  */
13883306792Spatrick #define DO_AUTO_NEG		true
13983306792Spatrick 
14083306792Spatrick #define AUTONEG_ADV_DEFAULT						\
14183306792Spatrick 	(ADVERTISE_10_HALF | ADVERTISE_10_FULL | ADVERTISE_100_HALF |	\
14283306792Spatrick 	ADVERTISE_100_FULL | ADVERTISE_1000_FULL | ADVERTISE_2500_FULL)
14383306792Spatrick 
14483306792Spatrick #define AUTO_ALL_MODES		0
14583306792Spatrick 
14683306792Spatrick /*
1474b1a56afSjsg  * Miscellaneous constants
14883306792Spatrick  */
14983306792Spatrick #define MAX_NUM_MULTICAST_ADDRESSES	128
15083306792Spatrick #define IGC_FC_PAUSE_TIME		0x0680
15183306792Spatrick 
15283306792Spatrick #define IGC_TXPBSIZE		20408
15383306792Spatrick #define IGC_PKTTYPE_MASK	0x0000FFF0
15483306792Spatrick #define IGC_DMCTLX_DCFLUSH_DIS	0x80000000	/* Disable DMA Coalesce Flush */
15583306792Spatrick 
15683306792Spatrick #define IGC_RX_PTHRESH		8
15783306792Spatrick #define IGC_RX_HTHRESH		8
15883306792Spatrick #define IGC_RX_WTHRESH		4
15983306792Spatrick 
16083306792Spatrick #define IGC_TX_PTHRESH		8
16183306792Spatrick #define IGC_TX_HTHRESH		1
16283306792Spatrick 
16383306792Spatrick /*
16483306792Spatrick  * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be
16583306792Spatrick  * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will
16683306792Spatrick  * also optimize cache line size effect. H/W supports up to cache line size 128.
16783306792Spatrick  */
16883306792Spatrick #define IGC_DBA_ALIGN		128
16983306792Spatrick 
17083306792Spatrick /*
17183306792Spatrick  * This parameter controls the duration of transmit watchdog timer.
17283306792Spatrick  */
17383306792Spatrick #define IGC_TX_TIMEOUT		5	/* set to 5 seconds */
17483306792Spatrick 
17583306792Spatrick #define IGC_PCIREG		PCI_MAPREG_START
17683306792Spatrick 
17783306792Spatrick #define IGC_MAX_VECTORS		8
17883306792Spatrick 
17983306792Spatrick /* Enable/disable debugging statements in shared code */
18083306792Spatrick #define DBG	0
18183306792Spatrick 
18283306792Spatrick #define DEBUGOUT(...)							\
18383306792Spatrick 	do { if (DBG) printf(__VA_ARGS__); } while (0)
18483306792Spatrick #define DEBUGOUT1(...)		DEBUGOUT(__VA_ARGS__)
18583306792Spatrick #define DEBUGOUT2(...)		DEBUGOUT(__VA_ARGS__)
18683306792Spatrick #define DEBUGOUT3(...)		DEBUGOUT(__VA_ARGS__)
18783306792Spatrick #define DEBUGOUT7(...)		DEBUGOUT(__VA_ARGS__)
18883306792Spatrick #define DEBUGFUNC(F)		DEBUGOUT(F "\n")
18983306792Spatrick 
19083306792Spatrick /* Compatibility glue. */
19183306792Spatrick #define roundup2(size, unit)	(((size) + (unit) - 1) & ~((unit) - 1))
19283306792Spatrick #define msec_delay(x)		DELAY(1000 * (x))
19383306792Spatrick 
19483306792Spatrick #define IGC_MAX_SCATTER		40
19583306792Spatrick #define IGC_TSO_SIZE		65535
19683306792Spatrick 
19783306792Spatrick #define MAX_INTS_PER_SEC	8000
19883306792Spatrick #define DEFAULT_ITR		(1000000000/(MAX_INTS_PER_SEC * 256))
19983306792Spatrick 
20083306792Spatrick /* Forward declaration. */
20183306792Spatrick struct igc_hw;
202bf6ccf13Sdlg struct kstat;
20383306792Spatrick 
20483306792Spatrick struct igc_osdep {
20583306792Spatrick 	bus_dma_tag_t		os_dmat;
20683306792Spatrick 	bus_space_tag_t		os_memt;
20783306792Spatrick 	bus_space_handle_t	os_memh;
20883306792Spatrick 
20983306792Spatrick 	bus_size_t		os_memsize;
21083306792Spatrick 	bus_addr_t		os_membase;
21183306792Spatrick 
21283306792Spatrick 	void			*os_sc;
21383306792Spatrick 	struct pci_attach_args	os_pa;
21483306792Spatrick };
21583306792Spatrick 
21683306792Spatrick 
21783306792Spatrick struct igc_tx_buf {
21883306792Spatrick 	uint32_t	eop_index;
21983306792Spatrick 	struct mbuf	*m_head;
22083306792Spatrick 	bus_dmamap_t	map;
22183306792Spatrick };
22283306792Spatrick 
22383306792Spatrick struct igc_rx_buf {
22483306792Spatrick 	struct mbuf	*buf;
22583306792Spatrick 	struct mbuf	*fmp;	/* First mbuf pointers. */
22683306792Spatrick 	bus_dmamap_t	map;
22783306792Spatrick };
22883306792Spatrick 
22983306792Spatrick /*
23083306792Spatrick  * Bus dma allocation structure used by igc_dma_malloc and igc_dma_free.
23183306792Spatrick  */
23283306792Spatrick struct igc_dma_alloc {
23383306792Spatrick 	caddr_t			dma_vaddr;
23483306792Spatrick 	bus_dma_tag_t		dma_tag;
23583306792Spatrick 	bus_dmamap_t		dma_map;
23683306792Spatrick 	bus_dma_segment_t	dma_seg;
23783306792Spatrick 	bus_size_t		dma_size;
23883306792Spatrick 	int			dma_nseg;
23983306792Spatrick };
24083306792Spatrick 
24183306792Spatrick /*
24283306792Spatrick  * Driver queue struct: this is the interrupt container
24383306792Spatrick  * for the associated tx and rx ring.
24483306792Spatrick  */
24583306792Spatrick struct igc_queue {
24683306792Spatrick 	struct igc_softc	*sc;
24783306792Spatrick 	uint32_t		msix;
24883306792Spatrick 	uint32_t		eims;
24983306792Spatrick 	uint32_t		eitr_setting;
25083306792Spatrick 	char			name[16];
25183306792Spatrick 	pci_intr_handle_t	ih;
25283306792Spatrick 	void			*tag;
253*fb54a5a4Sbluhm 	struct igc_txring	*txr;
254*fb54a5a4Sbluhm 	struct igc_rxring	*rxr;
25583306792Spatrick };
25683306792Spatrick 
25783306792Spatrick /*
25883306792Spatrick  * The transmit ring, one per tx queue.
25983306792Spatrick  */
260*fb54a5a4Sbluhm struct igc_txring {
26183306792Spatrick 	struct igc_softc	*sc;
26283306792Spatrick 	struct ifqueue		*ifq;
26383306792Spatrick 	uint32_t		me;
26483306792Spatrick 	uint32_t		watchdog_timer;
26583306792Spatrick 	union igc_adv_tx_desc	*tx_base;
26683306792Spatrick 	struct igc_tx_buf	*tx_buffers;
26783306792Spatrick 	struct igc_dma_alloc	txdma;
26883306792Spatrick 	uint32_t		next_avail_desc;
26983306792Spatrick 	uint32_t		next_to_clean;
27083306792Spatrick 	bus_dma_tag_t		txtag;
27183306792Spatrick };
27283306792Spatrick 
27383306792Spatrick /*
27483306792Spatrick  * The Receive ring, one per rx queue.
27583306792Spatrick  */
276*fb54a5a4Sbluhm struct igc_rxring {
27783306792Spatrick 	struct igc_softc	*sc;
27883306792Spatrick 	struct ifiqueue		*ifiq;
27983306792Spatrick 	uint32_t		me;
28083306792Spatrick 	union igc_adv_rx_desc	*rx_base;
28183306792Spatrick 	struct igc_rx_buf	*rx_buffers;
28283306792Spatrick 	struct igc_dma_alloc	rxdma;
28383306792Spatrick 	uint32_t		last_desc_filled;
28483306792Spatrick 	uint32_t		next_to_check;
28583306792Spatrick 	struct timeout		rx_refill;
28683306792Spatrick 	struct if_rxring	rx_ring;
28783306792Spatrick };
28883306792Spatrick 
28983306792Spatrick /* Our adapter structure. */
29083306792Spatrick struct igc_softc {
29183306792Spatrick 	struct device		sc_dev;
29283306792Spatrick 	struct arpcom		sc_ac;
29383306792Spatrick 	struct ifmedia		media;
29483306792Spatrick 	struct intrmap		*sc_intrmap;
29583306792Spatrick 
29683306792Spatrick 	struct igc_osdep	osdep;
29783306792Spatrick 	struct igc_hw		hw;
29883306792Spatrick 
29983306792Spatrick 	uint16_t		fc;
30083306792Spatrick 	uint16_t		link_active;
30183306792Spatrick 	uint16_t		link_speed;
30283306792Spatrick 	uint16_t		link_duplex;
30383306792Spatrick 	uint32_t		dmac;
30483306792Spatrick 
30583306792Spatrick 	void			*tag;
30683306792Spatrick 
30783306792Spatrick 	int			num_tx_desc;
30883306792Spatrick 	int			num_rx_desc;
30983306792Spatrick 
31083306792Spatrick 	uint32_t		max_frame_size;
31183306792Spatrick 	uint32_t		rx_mbuf_sz;
31283306792Spatrick 	uint32_t		linkvec;
31383306792Spatrick 	uint32_t		msix_linkmask;
31483306792Spatrick 	uint32_t		msix_queuesmask;
31583306792Spatrick 
31683306792Spatrick 	unsigned int		sc_nqueues;
31783306792Spatrick 	struct igc_queue	*queues;
31883306792Spatrick 
319*fb54a5a4Sbluhm 	struct igc_txring	*tx_rings;
320*fb54a5a4Sbluhm 	struct igc_rxring	*rx_rings;
32183306792Spatrick 
32283306792Spatrick 	/* Multicast array memory */
32383306792Spatrick 	uint8_t			*mta;
324bf6ccf13Sdlg 
325bf6ccf13Sdlg 	/* Counters */
326bf6ccf13Sdlg 	struct mutex		 ks_mtx;
327bf6ccf13Sdlg 	struct timeout		 ks_tmo;
328bf6ccf13Sdlg 	struct kstat		*ks;
32983306792Spatrick };
33083306792Spatrick 
33183306792Spatrick #define DEVNAME(_sc)    ((_sc)->sc_dev.dv_xname)
33283306792Spatrick 
33383306792Spatrick /* Register READ/WRITE macros */
33483306792Spatrick #define IGC_WRITE_FLUSH(a)	IGC_READ_REG(a, IGC_STATUS)
33583306792Spatrick #define IGC_READ_REG(a, reg)						\
33683306792Spatrick         bus_space_read_4(((struct igc_osdep *)(a)->back)->os_memt,	\
33783306792Spatrick         ((struct igc_osdep *)(a)->back)->os_memh, reg)
33883306792Spatrick #define IGC_WRITE_REG(a, reg, value)					\
33983306792Spatrick         bus_space_write_4(((struct igc_osdep *)(a)->back)->os_memt,	\
34083306792Spatrick         ((struct igc_osdep *)(a)->back)->os_memh, reg, value)
34183306792Spatrick #define IGC_READ_REG_ARRAY(a, reg, off)					\
34283306792Spatrick         bus_space_read_4(((struct igc_osdep *)(a)->back)->os_memt,	\
34383306792Spatrick         ((struct igc_osdep *)(a)->back)->os_memh, (reg + ((off) << 2)))
34483306792Spatrick #define IGC_WRITE_REG_ARRAY(a, reg, off, value)				\
34583306792Spatrick         bus_space_write_4(((struct igc_osdep *)(a)->back)->os_memt,	\
34683306792Spatrick         ((struct igc_osdep *)(a)->back)->os_memh,			\
34783306792Spatrick 	(reg + ((off) << 2)),value)
34883306792Spatrick 
34983306792Spatrick #endif /* _IGC_H_ */
350