xref: /illumos-gate/usr/src/uts/common/io/i40e/i40e_osdep.h (revision f3a1073761f959966ab629695ee17f4417413796)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
14  * Copyright 2016 Joyent, Inc.
15  */
16 
17 #ifndef _I40E_OSDEP_H
18 #define	_I40E_OSDEP_H
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <sys/types.h>
25 #include <sys/ddi.h>
26 #include <sys/sunddi.h>
27 #include <sys/pci_cap.h>
28 #include <sys/sysmacros.h>
29 #include <sys/stdbool.h>
30 
31 #define	DEBUGOUT(S)				i40e_debug(NULL, 0, S)
32 #define	DEBUGOUT1(S, A)				i40e_debug(NULL, 0, S, A)
33 #define	DEBUGOUT2(S, A, B)			i40e_debug(NULL, 0, S, A, B)
34 #define	DEBUGOUT3(S, A, B, C)			i40e_debug(NULL, 0, S, A, B, C)
35 #define	DEBUGOUT4(S, A, B, C, D)		\
36 	i40e_debug(NULL, 0, S, A, B, C, D)
37 #define	DEBUGOUT5(S, A, B, C, D, E)		\
38 	i40e_debug(NULL, 0, S, A, B, C, D, E)
39 #define	DEBUGOUT6(S, A, B, C, D, E, F)		\
40 	i40e_debug(NULL, 0, S, A, B, C, D, E, F)
41 #define	DEBUGOUT7(S, A, B, C, D, E, F, G)	\
42 	i40e_debug(NULL, 0, S, A, B, C, D, E, F, G)
43 #define	DEBUGFUNC(F)				DEBUGOUT(F);
44 
45 
46 #define	UNREFERENCED_PARAMETER(x)		_NOTE(ARGUNUSED(x))
47 #define	UNREFERENCED_1PARAMETER(_p)		UNREFERENCED_PARAMETER(_p)
48 #define	UNREFERENCED_2PARAMETER(_p, _q)		_NOTE(ARGUNUSED(_p, _q))
49 #define	UNREFERENCED_3PARAMETER(_p, _q, _r)	_NOTE(ARGUNUSED(_p, _q, _r))
50 #define	UNREFERENCED_4PARAMETER(_p, _q, _r, _s)	_NOTE(ARGUNUSED(_p, _q, _r, _s))
51 
52 #define	INLINE  inline
53 
54 /*
55  * The mdb dmod needs to use this code as well, but mdb already defines TRUE and
56  * FALSE in the module API. Thus we don't define these if we're building the
57  * dmod, as indicated by _I40E_MDB_DMOD. However, if we don't define these, then
58  * the shared code will be upset.
59  */
60 #ifndef _I40E_MDB_DMOD
61 #define	FALSE	false
62 #define	TRUE	true
63 #endif /* _I40E_MDB_DMOD */
64 
65 
66 #define	CPU_TO_LE16(o)	LE_16(o)
67 #define	CPU_TO_LE32(s)	LE_32(s)
68 #define	CPU_TO_LE64(h)	LE_64(h)
69 #define	LE16_TO_CPU(a)	LE_16(a)
70 #define	LE32_TO_CPU(c)	LE_32(c)
71 #define	LE64_TO_CPU(k)	LE_64(k)
72 
73 #define	I40E_NTOHS(a)	ntohs(a)
74 #define	I40E_NTOHL(a)	ntohl(a)
75 #define	I40E_HTONS(a)	htons(a)
76 #define	I40E_HTONL(a)	htonl(a)
77 
78 #define	i40e_memset(a, b, c, d)  memset((a), (b), (c))
79 #define	i40e_memcpy(a, b, c, d)  bcopy((b), (a), (c))
80 
81 #define	i40e_usec_delay(x) drv_usecwait(x)
82 #define	i40e_msec_delay(x) drv_usecwait(1000 * (x))
83 
84 #define	FIELD_SIZEOF(x, y) (sizeof (((x*)0)->y))
85 
86 #define	BIT(a)		(1UL << (a))
87 #define	BIT_ULL(a)	(1ULL << (a))
88 
89 typedef uint8_t		u8;
90 typedef int8_t		s8;
91 typedef uint16_t	u16;
92 typedef int16_t		s16;
93 typedef uint32_t	u32;
94 typedef int32_t		s32;
95 typedef uint64_t	u64;
96 
97 /* long string relief */
98 typedef enum i40e_status_code i40e_status;
99 
100 #define	__le16  u16
101 #define	__le32  u32
102 #define	__le64  u64
103 #define	__be16  u16
104 #define	__be32  u32
105 #define	__be64  u64
106 
107 /*
108  * Most other systems use spin locks for interrupts. However, illumos always
109  * uses a single kmutex_t for both and we decide what to do based on IPL (hint:
110  * it's not going to be a true spin lock, we'll use an adaptive mutex).
111  */
112 struct i40e_spinlock {
113 	kmutex_t ispl_mutex;
114 };
115 
116 /*
117  * Note, while prefetch is strictly not present on all architectures, (it's an
118  * SSE extension on i386), it is expected that the platforms provide it.
119  */
120 #define	prefetch(x) prefetch_read_many(x)
121 
122 struct i40e_osdep {
123 	off_t			ios_reg_size;
124 	ddi_acc_handle_t	ios_reg_handle;
125 	ddi_acc_handle_t	ios_cfg_handle;
126 	struct i40e		*ios_i40e;
127 };
128 
129 /*
130  * This structure and its members are defined by the common code. This means we
131  * cannot structure prefix it, even if we want to.
132  */
133 struct i40e_virt_mem {
134 	void	*va;
135 	u32	size;
136 };
137 
138 /*
139  * The first three members of this structure are defined by the common code.
140  * This means we cannot structure prefix them, even if we wanted to.
141  */
142 struct i40e_dma_mem {
143 	void			*va;	/* Virtual address. */
144 	u64			pa;	/* Physical (DMA/Hardware) address. */
145 	size_t			size;	/* Buffer size. */
146 
147 	/* illumos-private members */
148 	ddi_acc_handle_t	idm_acc_handle;	/* Data access handle */
149 	ddi_dma_handle_t	idm_dma_handle;	/* DMA handle */
150 	uint32_t		idm_alignment;	/* Requested alignment */
151 };
152 
153 struct i40e_hw; /* forward decl */
154 
155 #define	OS_DEP(hw) ((struct i40e_osdep *)((hw)->back))
156 #define	i40e_read_pci_cfg(hw, reg) \
157 	(pci_config_get16(OS_DEP(hw)->ios_cfg_handle, (reg)))
158 #define	i40e_write_pci_cfg(hw, reg, value) \
159 	(pci_config_put16(OS_DEP(hw)->ios_cfg_handle, (reg), (value)))
160 
161 /*
162  * Intel expects that the symbol wr32 and rd32 be defined to something which can
163  * read and write the 32-bit register in PCI space.
164  *
165  * To make it easier for readers and satisfy the general agreement that macros
166  * should be in all capitals, we use our own versions of these macros.
167  */
168 #define	wr32(hw, reg, value) \
169 	ddi_put32(OS_DEP(hw)->ios_reg_handle, \
170 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + (reg)), (value))
171 #define	rd32(hw, reg) \
172 	ddi_get32(OS_DEP(hw)->ios_reg_handle, \
173 	    (uint32_t *)((uintptr_t)(hw)->hw_addr + (reg)))
174 #define	I40E_WRITE_REG	wr32
175 #define	I40E_READ_REG	rd32
176 
177 /*
178  * The use of GLGEN_STAT presumes that we're only using this file for a PF
179  * driver. If we end up doing a VF driver, then we'll want to logically change
180  * this.
181  */
182 #define	i40e_flush(hw) (void) rd32(hw, I40E_GLGEN_STAT)
183 
184 extern void i40e_debug(void *, u32, char *, ...);
185 extern boolean_t i40e_set_hw_bus_info(struct i40e_hw *);
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 
191 #endif /* _I40E_OSDEP_H */
192