xref: /netbsd-src/sys/dev/pci/ixgbe/ixgbe_netbsd.h (revision 475940bb89abd5b6f2696a71a5f792b6b96fdb06)
1*475940bbSknakahara /* $NetBSD: ixgbe_netbsd.h,v 1.17 2022/09/16 03:05:51 knakahara Exp $ */
297579f7aSdyoung /*
397579f7aSdyoung  * Copyright (c) 2011 The NetBSD Foundation, Inc.
497579f7aSdyoung  * All rights reserved.
597579f7aSdyoung  *
697579f7aSdyoung  * This code is derived from software contributed to The NetBSD Foundation
797579f7aSdyoung  * by Coyote Point Systems, Inc.
897579f7aSdyoung  *
997579f7aSdyoung  * Redistribution and use in source and binary forms, with or without
1097579f7aSdyoung  * modification, are permitted provided that the following conditions
1197579f7aSdyoung  * are met:
1297579f7aSdyoung  * 1. Redistributions of source code must retain the above copyright
1397579f7aSdyoung  *    notice, this list of conditions and the following disclaimer.
1497579f7aSdyoung  * 2. Redistributions in binary form must reproduce the above copyright
1597579f7aSdyoung  *    notice, this list of conditions and the following disclaimer in the
1697579f7aSdyoung  *    documentation and/or other materials provided with the distribution.
1797579f7aSdyoung  *
1897579f7aSdyoung  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1997579f7aSdyoung  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2097579f7aSdyoung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2197579f7aSdyoung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2297579f7aSdyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2397579f7aSdyoung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2497579f7aSdyoung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2597579f7aSdyoung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2697579f7aSdyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2797579f7aSdyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2897579f7aSdyoung  * POSSIBILITY OF SUCH DAMAGE.
2997579f7aSdyoung  */
3097579f7aSdyoung 
3197579f7aSdyoung #ifndef _IXGBE_NETBSD_H
3297579f7aSdyoung #define _IXGBE_NETBSD_H
3397579f7aSdyoung 
34*475940bbSknakahara #ifdef _KERNEL_OPT
35*475940bbSknakahara #include "opt_if_ixg.h"
36*475940bbSknakahara #endif
37*475940bbSknakahara 
38a1cede5aSmsaitoh #if 0 /* Enable this if you don't want to use TX multiqueue function */
39da07f8e1Smsaitoh #define	IXGBE_LEGACY_TX	1
40a6d68e79Smsaitoh #endif
41da07f8e1Smsaitoh 
4297579f7aSdyoung #define	ETHERCAP_VLAN_HWCSUM	0
4397579f7aSdyoung #define	MJUM9BYTES	(9 * 1024)
4497579f7aSdyoung #define	MJUM16BYTES	(16 * 1024)
4597579f7aSdyoung #define	MJUMPAGESIZE	PAGE_SIZE
4697579f7aSdyoung 
4797579f7aSdyoung #define IFCAP_RXCSUM	\
4897579f7aSdyoung 	(IFCAP_CSUM_IPv4_Rx|IFCAP_CSUM_TCPv4_Rx|IFCAP_CSUM_UDPv4_Rx|\
4997579f7aSdyoung 	IFCAP_CSUM_TCPv6_Rx|IFCAP_CSUM_UDPv6_Rx)
5097579f7aSdyoung 
5197579f7aSdyoung #define IFCAP_TXCSUM	\
5297579f7aSdyoung 	(IFCAP_CSUM_IPv4_Tx|IFCAP_CSUM_TCPv4_Tx|IFCAP_CSUM_UDPv4_Tx|\
5397579f7aSdyoung 	IFCAP_CSUM_TCPv6_Tx|IFCAP_CSUM_UDPv6_Tx)
5497579f7aSdyoung 
5597579f7aSdyoung #define IFCAP_HWCSUM	(IFCAP_RXCSUM|IFCAP_TXCSUM)
5697579f7aSdyoung 
572edbe6ebSmsaitoh 
582edbe6ebSmsaitoh /* Helper macros for evcnt(9) .*/
592edbe6ebSmsaitoh #ifdef __HAVE_ATOMIC64_LOADSTORE
602edbe6ebSmsaitoh #define IXGBE_EVC_LOAD(evp)				\
612edbe6ebSmsaitoh 	atomic_load_relaxed(&((evp)->ev_count))
622edbe6ebSmsaitoh #define IXGBE_EVC_STORE(evp, val)			\
632edbe6ebSmsaitoh 	atomic_store_relaxed(&((evp)->ev_count), (val))
642edbe6ebSmsaitoh #define IXGBE_EVC_ADD(evp, val)					\
652edbe6ebSmsaitoh 	atomic_store_relaxed(&((evp)->ev_count),		\
662edbe6ebSmsaitoh 	    atomic_load_relaxed(&((evp)->ev_count)) + (val))
672edbe6ebSmsaitoh #else
68285eb806Smsaitoh #define IXGBE_EVC_LOAD(evp)		((evp)->ev_count))
69285eb806Smsaitoh #define IXGBE_EVC_STORE(evp, val)	((evp)->ev_count = (val))
70285eb806Smsaitoh #define IXGBE_EVC_ADD(evp, val)		((evp)->ev_count += (val))
712edbe6ebSmsaitoh #endif
722edbe6ebSmsaitoh 
732edbe6ebSmsaitoh #define IXGBE_EVC_REGADD(hw, stats, regname, evname)			\
742edbe6ebSmsaitoh 	IXGBE_EVC_ADD(&(stats)->evname, IXGBE_READ_REG((hw), (regname)))
752edbe6ebSmsaitoh 
762edbe6ebSmsaitoh /*
772edbe6ebSmsaitoh  * Copy a register value to variable "evname" for later use.
782edbe6ebSmsaitoh  * "evname" is also the name of the evcnt.
792edbe6ebSmsaitoh  */
802edbe6ebSmsaitoh #define IXGBE_EVC_REGADD2(hw, stats, regname, evname)		\
812edbe6ebSmsaitoh 	do {							\
822edbe6ebSmsaitoh 		(evname) = IXGBE_READ_REG((hw), (regname));	\
832edbe6ebSmsaitoh 		IXGBE_EVC_ADD(&(stats)->evname, (evname));	\
842edbe6ebSmsaitoh 	} while (/*CONSTCOND*/0)
852edbe6ebSmsaitoh 
8697579f7aSdyoung struct ixgbe_dma_tag {
8797579f7aSdyoung 	bus_dma_tag_t	dt_dmat;
8897579f7aSdyoung 	bus_size_t	dt_alignment;
8997579f7aSdyoung 	bus_size_t	dt_boundary;
9097579f7aSdyoung 	bus_size_t	dt_maxsize;
9197579f7aSdyoung 	int		dt_nsegments;
9297579f7aSdyoung 	bus_size_t	dt_maxsegsize;
9397579f7aSdyoung 	int		dt_flags;
9497579f7aSdyoung };
9597579f7aSdyoung 
9697579f7aSdyoung typedef struct ixgbe_dma_tag ixgbe_dma_tag_t;
9797579f7aSdyoung 
985d514447Smsaitoh int ixgbe_dma_tag_create(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t,
995d514447Smsaitoh     int, bus_size_t, int, ixgbe_dma_tag_t **);
10097579f7aSdyoung void ixgbe_dma_tag_destroy(ixgbe_dma_tag_t *);
10197579f7aSdyoung int ixgbe_dmamap_create(ixgbe_dma_tag_t *, int, bus_dmamap_t *);
10297579f7aSdyoung void ixgbe_dmamap_destroy(ixgbe_dma_tag_t *, bus_dmamap_t);
10397579f7aSdyoung void ixgbe_dmamap_sync(ixgbe_dma_tag_t *, bus_dmamap_t, int);
10497579f7aSdyoung void ixgbe_dmamap_unload(ixgbe_dma_tag_t *, bus_dmamap_t);
10597579f7aSdyoung 
1068ab7d327Smsaitoh struct mbuf *ixgbe_getcl(void);
107d241219aSmsaitoh void ixgbe_pci_enable_busmaster(pci_chipset_tag_t, pcitag_t);
10897579f7aSdyoung 
10922298f59Smsaitoh u_int atomic_load_acq_uint(volatile u_int *);
11022298f59Smsaitoh 
11197579f7aSdyoung #endif /* _IXGBE_NETBSD_H */
112