1/*-
2 * Copyright 2021 Intel Corp
3 * Copyright 2021 Rubicon Communications, LLC (Netgate)
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _FREEBSD_OS_H_
8#define _FREEBSD_OS_H_
9
10#include <sys/types.h>
11#include <sys/param.h>
12#include <sys/systm.h>
13#include <sys/lock.h>
14#include <sys/mutex.h>
15#include <sys/mbuf.h>
16#include <sys/protosw.h>
17#include <sys/socket.h>
18#include <sys/malloc.h>
19#include <sys/kernel.h>
20#include <sys/bus.h>
21
22#include <net/ethernet.h>
23#include <net/if.h>
24#include <net/if_var.h>
25#include <net/iflib.h>
26
27#include <machine/bus.h>
28#include <sys/rman.h>
29#include <machine/resource.h>
30#include <vm/vm.h>
31#include <vm/pmap.h>
32#include <machine/clock.h>
33#include <dev/pci/pcivar.h>
34#include <dev/pci/pcireg.h>
35
36#define usec_delay(x) DELAY(x)
37#define usec_delay_irq(x) usec_delay(x)
38#define msec_delay(x) DELAY(1000*(x))
39#define msec_delay_irq(x) DELAY(1000*(x))
40
41/* Enable/disable debugging statements in shared code */
42#define DBG		0
43
44#define DEBUGOUT(...) \
45    do { if (DBG) printf(__VA_ARGS__); } while (0)
46#define DEBUGOUT1(...)			DEBUGOUT(__VA_ARGS__)
47#define DEBUGOUT2(...)			DEBUGOUT(__VA_ARGS__)
48#define DEBUGOUT3(...)			DEBUGOUT(__VA_ARGS__)
49#define DEBUGOUT7(...)			DEBUGOUT(__VA_ARGS__)
50#define DEBUGFUNC(F)			DEBUGOUT(F "\n")
51
52typedef uint64_t	u64;
53typedef uint32_t	u32;
54typedef uint16_t	u16;
55typedef uint8_t		u8;
56typedef int64_t		s64;
57typedef int32_t		s32;
58typedef int16_t		s16;
59typedef int8_t		s8;
60
61#define __le16		u16
62#define __le32		u32
63#define __le64		u64
64
65struct igc_osdep
66{
67	bus_space_tag_t    mem_bus_space_tag;
68	bus_space_handle_t mem_bus_space_handle;
69	bus_space_tag_t    io_bus_space_tag;
70	bus_space_handle_t io_bus_space_handle;
71	bus_space_tag_t    flash_bus_space_tag;
72	bus_space_handle_t flash_bus_space_handle;
73	device_t           dev;
74	if_ctx_t           ctx;
75};
76
77#define IGC_REGISTER(hw, reg) reg
78
79#define IGC_WRITE_FLUSH(a) IGC_READ_REG(a, IGC_STATUS)
80
81/* Read from an absolute offset in the adapter's memory space */
82#define IGC_READ_OFFSET(hw, offset) \
83    bus_space_read_4(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
84    ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, offset)
85
86/* Write to an absolute offset in the adapter's memory space */
87#define IGC_WRITE_OFFSET(hw, offset, value) \
88    bus_space_write_4(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
89    ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, offset, value)
90
91/* Register READ/WRITE macros */
92
93#define IGC_READ_REG(hw, reg) \
94    bus_space_read_4(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
95        ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, \
96        IGC_REGISTER(hw, reg))
97
98#define IGC_WRITE_REG(hw, reg, value) \
99    bus_space_write_4(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
100        ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, \
101        IGC_REGISTER(hw, reg), value)
102
103#define IGC_READ_REG_ARRAY(hw, reg, index) \
104    bus_space_read_4(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
105        ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, \
106        IGC_REGISTER(hw, reg) + ((index)<< 2))
107
108#define IGC_WRITE_REG_ARRAY(hw, reg, index, value) \
109    bus_space_write_4(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
110        ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, \
111        IGC_REGISTER(hw, reg) + ((index)<< 2), value)
112
113#define IGC_READ_REG_ARRAY_DWORD IGC_READ_REG_ARRAY
114#define IGC_WRITE_REG_ARRAY_DWORD IGC_WRITE_REG_ARRAY
115
116#define IGC_READ_REG_ARRAY_BYTE(hw, reg, index) \
117    bus_space_read_1(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
118        ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, \
119        IGC_REGISTER(hw, reg) + index)
120
121#define IGC_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
122    bus_space_write_1(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
123        ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, \
124        IGC_REGISTER(hw, reg) + index, value)
125
126#define IGC_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
127    bus_space_write_2(((struct igc_osdep *)(hw)->back)->mem_bus_space_tag, \
128        ((struct igc_osdep *)(hw)->back)->mem_bus_space_handle, \
129        IGC_REGISTER(hw, reg) + (index << 1), value)
130
131#endif  /* _FREEBSD_OS_H_ */
132