161ae650dSJack F Vogel /******************************************************************************
261ae650dSJack F Vogel
3*f4cc2d17SEric Joyner Copyright (c) 2013-2018, Intel Corporation
461ae650dSJack F Vogel All rights reserved.
561ae650dSJack F Vogel
661ae650dSJack F Vogel Redistribution and use in source and binary forms, with or without
761ae650dSJack F Vogel modification, are permitted provided that the following conditions are met:
861ae650dSJack F Vogel
961ae650dSJack F Vogel 1. Redistributions of source code must retain the above copyright notice,
1061ae650dSJack F Vogel this list of conditions and the following disclaimer.
1161ae650dSJack F Vogel
1261ae650dSJack F Vogel 2. Redistributions in binary form must reproduce the above copyright
1361ae650dSJack F Vogel notice, this list of conditions and the following disclaimer in the
1461ae650dSJack F Vogel documentation and/or other materials provided with the distribution.
1561ae650dSJack F Vogel
1661ae650dSJack F Vogel 3. Neither the name of the Intel Corporation nor the names of its
1761ae650dSJack F Vogel contributors may be used to endorse or promote products derived from
1861ae650dSJack F Vogel this software without specific prior written permission.
1961ae650dSJack F Vogel
2061ae650dSJack F Vogel THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2161ae650dSJack F Vogel AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2261ae650dSJack F Vogel IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2361ae650dSJack F Vogel ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2461ae650dSJack F Vogel LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2561ae650dSJack F Vogel CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2661ae650dSJack F Vogel SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2761ae650dSJack F Vogel INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2861ae650dSJack F Vogel CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2961ae650dSJack F Vogel ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3061ae650dSJack F Vogel POSSIBILITY OF SUCH DAMAGE.
3161ae650dSJack F Vogel
3261ae650dSJack F Vogel ******************************************************************************/
3361ae650dSJack F Vogel
3461ae650dSJack F Vogel #ifndef _I40E_OSDEP_H_
3561ae650dSJack F Vogel #define _I40E_OSDEP_H_
3661ae650dSJack F Vogel
3761ae650dSJack F Vogel #include <sys/types.h>
3861ae650dSJack F Vogel #include <sys/param.h>
3961ae650dSJack F Vogel #include <sys/systm.h>
4061ae650dSJack F Vogel #include <sys/endian.h>
4161ae650dSJack F Vogel #include <sys/mbuf.h>
4261ae650dSJack F Vogel #include <sys/protosw.h>
4361ae650dSJack F Vogel #include <sys/socket.h>
4461ae650dSJack F Vogel #include <sys/malloc.h>
4561ae650dSJack F Vogel #include <sys/kernel.h>
4661ae650dSJack F Vogel #include <sys/bus.h>
4761ae650dSJack F Vogel #include <machine/bus.h>
4861ae650dSJack F Vogel #include <sys/rman.h>
4961ae650dSJack F Vogel #include <machine/resource.h>
5061ae650dSJack F Vogel #include <vm/vm.h>
5161ae650dSJack F Vogel #include <vm/pmap.h>
5261ae650dSJack F Vogel #include <machine/clock.h>
5361ae650dSJack F Vogel #include <dev/pci/pcivar.h>
5461ae650dSJack F Vogel #include <dev/pci/pcireg.h>
5561ae650dSJack F Vogel
5661ae650dSJack F Vogel #define i40e_usec_delay(x) DELAY(x)
5761ae650dSJack F Vogel #define i40e_msec_delay(x) DELAY(1000 * (x))
5861ae650dSJack F Vogel
5961ae650dSJack F Vogel #define DBG 0
6061ae650dSJack F Vogel #define MSGOUT(S, A, B) printf(S "\n", A, B)
6161ae650dSJack F Vogel #define DEBUGFUNC(F) DEBUGOUT(F);
6261ae650dSJack F Vogel #if DBG
6361ae650dSJack F Vogel #define DEBUGOUT(S) printf(S "\n")
6461ae650dSJack F Vogel #define DEBUGOUT1(S,A) printf(S "\n",A)
6561ae650dSJack F Vogel #define DEBUGOUT2(S,A,B) printf(S "\n",A,B)
6661ae650dSJack F Vogel #define DEBUGOUT3(S,A,B,C) printf(S "\n",A,B,C)
6761ae650dSJack F Vogel #define DEBUGOUT7(S,A,B,C,D,E,F,G) printf(S "\n",A,B,C,D,E,F,G)
6861ae650dSJack F Vogel #else
6961ae650dSJack F Vogel #define DEBUGOUT(S)
7061ae650dSJack F Vogel #define DEBUGOUT1(S,A)
7161ae650dSJack F Vogel #define DEBUGOUT2(S,A,B)
7261ae650dSJack F Vogel #define DEBUGOUT3(S,A,B,C)
7361ae650dSJack F Vogel #define DEBUGOUT6(S,A,B,C,D,E,F)
7461ae650dSJack F Vogel #define DEBUGOUT7(S,A,B,C,D,E,F,G)
7561ae650dSJack F Vogel #endif
7661ae650dSJack F Vogel
774294f337SSean Bruno /* Remove unused shared code macros */
7861ae650dSJack F Vogel #define UNREFERENCED_PARAMETER(_p)
7961ae650dSJack F Vogel #define UNREFERENCED_1PARAMETER(_p)
8061ae650dSJack F Vogel #define UNREFERENCED_2PARAMETER(_p, _q)
8161ae650dSJack F Vogel #define UNREFERENCED_3PARAMETER(_p, _q, _r)
8261ae650dSJack F Vogel #define UNREFERENCED_4PARAMETER(_p, _q, _r, _s)
834294f337SSean Bruno #define UNREFERENCED_5PARAMETER(_p, _q, _r, _s, _t)
8461ae650dSJack F Vogel
8561ae650dSJack F Vogel #define STATIC static
8661ae650dSJack F Vogel #define INLINE inline
8761ae650dSJack F Vogel
8861ae650dSJack F Vogel #define FALSE 0
8961ae650dSJack F Vogel #define false 0 /* shared code requires this */
9061ae650dSJack F Vogel #define TRUE 1
9161ae650dSJack F Vogel #define true 1
9261ae650dSJack F Vogel #define CMD_MEM_WRT_INVALIDATE 0x0010 /* BIT_4 */
9361ae650dSJack F Vogel #define PCI_COMMAND_REGISTER PCIR_COMMAND
9461ae650dSJack F Vogel #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
9561ae650dSJack F Vogel
9661ae650dSJack F Vogel #define i40e_memset(a, b, c, d) memset((a), (b), (c))
9761ae650dSJack F Vogel #define i40e_memcpy(a, b, c, d) memcpy((a), (b), (c))
9861ae650dSJack F Vogel
9961ae650dSJack F Vogel #define CPU_TO_LE16(o) htole16(o)
10061ae650dSJack F Vogel #define CPU_TO_LE32(s) htole32(s)
10161ae650dSJack F Vogel #define CPU_TO_LE64(h) htole64(h)
10261ae650dSJack F Vogel #define LE16_TO_CPU(a) le16toh(a)
10361ae650dSJack F Vogel #define LE32_TO_CPU(c) le32toh(c)
10461ae650dSJack F Vogel #define LE64_TO_CPU(k) le64toh(k)
10561ae650dSJack F Vogel
10661ae650dSJack F Vogel #define I40E_NTOHS(a) ntohs(a)
10761ae650dSJack F Vogel #define I40E_NTOHL(a) ntohl(a)
10861ae650dSJack F Vogel #define I40E_HTONS(a) htons(a)
10961ae650dSJack F Vogel #define I40E_HTONL(a) htonl(a)
11061ae650dSJack F Vogel
11161ae650dSJack F Vogel #define FIELD_SIZEOF(x, y) (sizeof(((x*)0)->y))
11261ae650dSJack F Vogel
11361ae650dSJack F Vogel typedef uint8_t u8;
11461ae650dSJack F Vogel typedef int8_t s8;
11561ae650dSJack F Vogel typedef uint16_t u16;
11661ae650dSJack F Vogel typedef int16_t s16;
11761ae650dSJack F Vogel typedef uint32_t u32;
11861ae650dSJack F Vogel typedef int32_t s32;
11961ae650dSJack F Vogel typedef uint64_t u64;
12061ae650dSJack F Vogel
12161ae650dSJack F Vogel /* long string relief */
12261ae650dSJack F Vogel typedef enum i40e_status_code i40e_status;
12361ae650dSJack F Vogel
12461ae650dSJack F Vogel #define __le16 u16
12561ae650dSJack F Vogel #define __le32 u32
12661ae650dSJack F Vogel #define __le64 u64
12761ae650dSJack F Vogel #define __be16 u16
12861ae650dSJack F Vogel #define __be32 u32
12961ae650dSJack F Vogel #define __be64 u64
13061ae650dSJack F Vogel
13161ae650dSJack F Vogel /* SW spinlock */
13261ae650dSJack F Vogel struct i40e_spinlock {
13361ae650dSJack F Vogel struct mtx mutex;
13461ae650dSJack F Vogel };
13561ae650dSJack F Vogel
13661ae650dSJack F Vogel #define le16_to_cpu
13761ae650dSJack F Vogel
138f894ad88SBjoern A. Zeeb #if defined(__amd64__) || defined(i386)
13961ae650dSJack F Vogel static __inline
prefetch(void * x)14061ae650dSJack F Vogel void prefetch(void *x)
14161ae650dSJack F Vogel {
14261ae650dSJack F Vogel __asm volatile("prefetcht0 %0" :: "m" (*(unsigned long *)x));
14361ae650dSJack F Vogel }
144f894ad88SBjoern A. Zeeb #else
145f894ad88SBjoern A. Zeeb #define prefetch(x)
146f894ad88SBjoern A. Zeeb #endif
14761ae650dSJack F Vogel
148e5100ee2SJack F Vogel struct i40e_osdep {
14961ae650dSJack F Vogel bus_space_tag_t mem_bus_space_tag;
15061ae650dSJack F Vogel bus_space_handle_t mem_bus_space_handle;
15161ae650dSJack F Vogel bus_size_t mem_bus_space_size;
152cf3c0c32SRyan Stone uint32_t flush_reg;
153cb6b8299SEric Joyner int i2c_intfc_num;
154bd937497SJean-Sébastien Pédron device_t dev;
15561ae650dSJack F Vogel };
15661ae650dSJack F Vogel
15761ae650dSJack F Vogel struct i40e_dma_mem {
15861ae650dSJack F Vogel void *va;
15961ae650dSJack F Vogel u64 pa;
16061ae650dSJack F Vogel bus_dma_tag_t tag;
16161ae650dSJack F Vogel bus_dmamap_t map;
16261ae650dSJack F Vogel bus_size_t size;
16361ae650dSJack F Vogel };
16461ae650dSJack F Vogel
16561ae650dSJack F Vogel struct i40e_virt_mem {
16661ae650dSJack F Vogel void *va;
16761ae650dSJack F Vogel u32 size;
16861ae650dSJack F Vogel };
16961ae650dSJack F Vogel
1706c426059SEric Joyner struct i40e_hw; /* forward decl */
1716c426059SEric Joyner u16 i40e_read_pci_cfg(struct i40e_hw *, u32);
1726c426059SEric Joyner void i40e_write_pci_cfg(struct i40e_hw *, u32, u16);
1736c426059SEric Joyner
17461ae650dSJack F Vogel /*
1756c426059SEric Joyner ** i40e_debug - OS dependent version of shared code debug printing
1766c426059SEric Joyner */
1776c426059SEric Joyner enum i40e_debug_mask;
1784294f337SSean Bruno #define i40e_debug(h, m, s, ...) i40e_debug_shared(h, m, s, ##__VA_ARGS__)
1794294f337SSean Bruno extern void i40e_debug_shared(struct i40e_hw *hw, enum i40e_debug_mask mask,
1806c426059SEric Joyner char *fmt_str, ...);
1816c426059SEric Joyner
1824294f337SSean Bruno /* Non-busy-wait that uses kern_yield() */
1834294f337SSean Bruno void i40e_msec_pause(int);
1844294f337SSean Bruno
185cb6b8299SEric Joyner const char * ixl_vc_opcode_str(uint16_t op);
186cb6b8299SEric Joyner
1876c426059SEric Joyner /*
1886c426059SEric Joyner ** This hardware supports either 16 or 32 byte rx descriptors;
1896c426059SEric Joyner ** the driver only uses the 32 byte kind.
19061ae650dSJack F Vogel */
19161ae650dSJack F Vogel #define i40e_rx_desc i40e_32byte_rx_desc
19261ae650dSJack F Vogel
19361ae650dSJack F Vogel static __inline uint32_t
rd32_osdep(struct i40e_osdep * osdep,uint32_t reg)19461ae650dSJack F Vogel rd32_osdep(struct i40e_osdep *osdep, uint32_t reg)
19561ae650dSJack F Vogel {
19661ae650dSJack F Vogel
19761ae650dSJack F Vogel KASSERT(reg < osdep->mem_bus_space_size,
198be771cdaSJack F Vogel ("ixl: register offset %#jx too large (max is %#jx)",
19913b40804SSteven Hartland (uintmax_t)reg, (uintmax_t)osdep->mem_bus_space_size));
20061ae650dSJack F Vogel
20161ae650dSJack F Vogel return (bus_space_read_4(osdep->mem_bus_space_tag,
20261ae650dSJack F Vogel osdep->mem_bus_space_handle, reg));
20361ae650dSJack F Vogel }
20461ae650dSJack F Vogel
20561ae650dSJack F Vogel static __inline void
wr32_osdep(struct i40e_osdep * osdep,uint32_t reg,uint32_t value)20661ae650dSJack F Vogel wr32_osdep(struct i40e_osdep *osdep, uint32_t reg, uint32_t value)
20761ae650dSJack F Vogel {
20861ae650dSJack F Vogel
20961ae650dSJack F Vogel KASSERT(reg < osdep->mem_bus_space_size,
210be771cdaSJack F Vogel ("ixl: register offset %#jx too large (max is %#jx)",
21113b40804SSteven Hartland (uintmax_t)reg, (uintmax_t)osdep->mem_bus_space_size));
21261ae650dSJack F Vogel
21361ae650dSJack F Vogel bus_space_write_4(osdep->mem_bus_space_tag,
21461ae650dSJack F Vogel osdep->mem_bus_space_handle, reg, value);
21561ae650dSJack F Vogel }
21661ae650dSJack F Vogel
217cf3c0c32SRyan Stone static __inline void
ixl_flush_osdep(struct i40e_osdep * osdep)218cf3c0c32SRyan Stone ixl_flush_osdep(struct i40e_osdep *osdep)
219cf3c0c32SRyan Stone {
220cf3c0c32SRyan Stone rd32_osdep(osdep, osdep->flush_reg);
221cf3c0c32SRyan Stone }
222cf3c0c32SRyan Stone
22361ae650dSJack F Vogel #define rd32(a, reg) rd32_osdep((a)->back, (reg))
22461ae650dSJack F Vogel #define wr32(a, reg, value) wr32_osdep((a)->back, (reg), (value))
22561ae650dSJack F Vogel
22661ae650dSJack F Vogel #define rd64(a, reg) (\
22761ae650dSJack F Vogel bus_space_read_8( ((struct i40e_osdep *)(a)->back)->mem_bus_space_tag, \
22861ae650dSJack F Vogel ((struct i40e_osdep *)(a)->back)->mem_bus_space_handle, \
22961ae650dSJack F Vogel reg))
23061ae650dSJack F Vogel
23161ae650dSJack F Vogel #define wr64(a, reg, value) (\
23261ae650dSJack F Vogel bus_space_write_8( ((struct i40e_osdep *)(a)->back)->mem_bus_space_tag, \
23361ae650dSJack F Vogel ((struct i40e_osdep *)(a)->back)->mem_bus_space_handle, \
23461ae650dSJack F Vogel reg, value))
23561ae650dSJack F Vogel
236cf3c0c32SRyan Stone #define ixl_flush(a) ixl_flush_osdep((a)->back)
23761ae650dSJack F Vogel
238ceebc2f3SEric Joyner enum i40e_status_code i40e_read_nvm_word_srctl(struct i40e_hw *hw, u16 offset,
239ceebc2f3SEric Joyner u16 *data);
240ceebc2f3SEric Joyner
24161ae650dSJack F Vogel #endif /* _I40E_OSDEP_H_ */
242