xref: /freebsd/sys/dev/liquidio/lio_bsd.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1f173c2b7SSean Bruno /*
2f173c2b7SSean Bruno  *   BSD LICENSE
3f173c2b7SSean Bruno  *
4f173c2b7SSean Bruno  *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
5f173c2b7SSean Bruno  *   All rights reserved.
6f173c2b7SSean Bruno  *
7f173c2b7SSean Bruno  *   Redistribution and use in source and binary forms, with or without
8f173c2b7SSean Bruno  *   modification, are permitted provided that the following conditions
9f173c2b7SSean Bruno  *   are met:
10f173c2b7SSean Bruno  *
11f173c2b7SSean Bruno  *     * Redistributions of source code must retain the above copyright
12f173c2b7SSean Bruno  *       notice, this list of conditions and the following disclaimer.
13f173c2b7SSean Bruno  *     * Redistributions in binary form must reproduce the above copyright
14f173c2b7SSean Bruno  *       notice, this list of conditions and the following disclaimer in
15f173c2b7SSean Bruno  *       the documentation and/or other materials provided with the
16f173c2b7SSean Bruno  *       distribution.
17f173c2b7SSean Bruno  *     * Neither the name of Cavium, Inc. nor the names of its
18f173c2b7SSean Bruno  *       contributors may be used to endorse or promote products derived
19f173c2b7SSean Bruno  *       from this software without specific prior written permission.
20f173c2b7SSean Bruno  *
21f173c2b7SSean Bruno  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22f173c2b7SSean Bruno  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23f173c2b7SSean Bruno  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24f173c2b7SSean Bruno  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25f173c2b7SSean Bruno  *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26f173c2b7SSean Bruno  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27f173c2b7SSean Bruno  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28f173c2b7SSean Bruno  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29f173c2b7SSean Bruno  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30f173c2b7SSean Bruno  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31f173c2b7SSean Bruno  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32f173c2b7SSean Bruno  */
33f173c2b7SSean Bruno 
34f173c2b7SSean Bruno #ifndef __LIO_BSD_H__
35f173c2b7SSean Bruno #define __LIO_BSD_H__
36f173c2b7SSean Bruno 
37f173c2b7SSean Bruno #include <sys/param.h>
38*f89d2072SXin LI #include <sys/gsb_crc32.h>
39e2e050c8SConrad Meyer #include <sys/eventhandler.h>
40f173c2b7SSean Bruno #include <sys/socket.h>
41f173c2b7SSean Bruno #include <sys/kernel.h>
42f173c2b7SSean Bruno #include <sys/module.h>
43f173c2b7SSean Bruno #include <sys/sockio.h>
44f173c2b7SSean Bruno 
45f173c2b7SSean Bruno #include <net/if.h>
46f173c2b7SSean Bruno #include <net/if_var.h>
47f173c2b7SSean Bruno #include <net/bpf.h>
48f173c2b7SSean Bruno #include <net/ethernet.h>
49f173c2b7SSean Bruno #include <net/if_dl.h>
50f173c2b7SSean Bruno #include <net/if_media.h>
51f173c2b7SSean Bruno 
52f173c2b7SSean Bruno #include <net/if_types.h>
53f173c2b7SSean Bruno #include <net/if_vlan_var.h>
54f173c2b7SSean Bruno 
559f855fb2SAndrey V. Elsukov #include <netinet/in.h>
56f173c2b7SSean Bruno #include <netinet/tcp_lro.h>
57f173c2b7SSean Bruno 
58f173c2b7SSean Bruno #include <sys/bus.h>
59f173c2b7SSean Bruno #include <machine/bus.h>
60f173c2b7SSean Bruno #include <sys/rman.h>
61f173c2b7SSean Bruno #include <vm/vm.h>
62f173c2b7SSean Bruno #include <vm/pmap.h>
63f173c2b7SSean Bruno #include <dev/pci/pcivar.h>
64f173c2b7SSean Bruno #include <dev/pci/pcireg.h>
65f173c2b7SSean Bruno #include <sys/sysctl.h>
66f173c2b7SSean Bruno #include <sys/taskqueue.h>
67f173c2b7SSean Bruno #include <sys/smp.h>
68f173c2b7SSean Bruno #include <sys/kthread.h>
69f173c2b7SSean Bruno #include <sys/firmware.h>
70f173c2b7SSean Bruno 
71f173c2b7SSean Bruno #include <vm/vm_extern.h>
72f173c2b7SSean Bruno #include <vm/vm_kern.h>
73f173c2b7SSean Bruno 
74f173c2b7SSean Bruno #ifndef PCI_VENDOR_ID_CAVIUM
75f173c2b7SSean Bruno #define PCI_VENDOR_ID_CAVIUM	0x177D
76f173c2b7SSean Bruno #endif
77f173c2b7SSean Bruno 
78f173c2b7SSean Bruno #define BIT(nr)		(1UL << (nr))
79f173c2b7SSean Bruno 
80f173c2b7SSean Bruno #define lio_check_timeout(a, b)  ((int)((b) - (a)) < 0)
81f173c2b7SSean Bruno 
82f173c2b7SSean Bruno #define lio_ms_to_ticks(x)				\
83f173c2b7SSean Bruno 	((hz > 1000) ? ((x) * (hz/1000)) : ((x) / (1000/hz)))
84f173c2b7SSean Bruno 
85f173c2b7SSean Bruno #define lio_mdelay(x) do {				\
86f173c2b7SSean Bruno 	if (cold)					\
87f173c2b7SSean Bruno 		DELAY(1000 * (x));			\
88f173c2b7SSean Bruno 	else						\
89f173c2b7SSean Bruno 		pause("Wait", lio_ms_to_ticks(x));	\
90f173c2b7SSean Bruno } while(0)
91f173c2b7SSean Bruno 
92f173c2b7SSean Bruno #define lio_sleep_timeout(timeout)	lio_mdelay((timeout))
93f173c2b7SSean Bruno 
94f173c2b7SSean Bruno typedef uint32_t __be32;
95f173c2b7SSean Bruno typedef uint64_t __be64;
96f173c2b7SSean Bruno 
97f173c2b7SSean Bruno #define lio_dev_info(oct, format, args...)		\
98f173c2b7SSean Bruno 	device_printf(oct->device, "Info: " format, ##args)
99f173c2b7SSean Bruno #define lio_dev_warn(oct, format, args...)		\
100f173c2b7SSean Bruno 	device_printf(oct->device, "Warn: " format, ##args)
101f173c2b7SSean Bruno #define lio_dev_err(oct, format, args...)		\
102f173c2b7SSean Bruno 	device_printf(oct->device, "Error: " format, ##args)
103f173c2b7SSean Bruno 
104f173c2b7SSean Bruno #ifdef LIO_DEBUG
105f173c2b7SSean Bruno #define lio_dev_dbg(oct, format, args...)		\
106f173c2b7SSean Bruno 	device_printf(oct->device, "Debug: " format, ##args)
107f173c2b7SSean Bruno #else
108f173c2b7SSean Bruno #define lio_dev_dbg(oct, format, args...)	{do { } while (0); }
109f173c2b7SSean Bruno #endif
110f173c2b7SSean Bruno 
111f173c2b7SSean Bruno struct lio_stailq_node {
112f173c2b7SSean Bruno 	STAILQ_ENTRY (lio_stailq_node) entries;
113f173c2b7SSean Bruno };
114f173c2b7SSean Bruno STAILQ_HEAD (lio_stailq_head, lio_stailq_node);
115f173c2b7SSean Bruno 
116f173c2b7SSean Bruno static inline struct lio_stailq_node *
lio_delete_first_node(struct lio_stailq_head * root)117f173c2b7SSean Bruno lio_delete_first_node(struct lio_stailq_head *root)
118f173c2b7SSean Bruno {
119f173c2b7SSean Bruno 	struct lio_stailq_node *node;
120f173c2b7SSean Bruno 
121f173c2b7SSean Bruno 	if (STAILQ_EMPTY(root))
122f173c2b7SSean Bruno 		node = NULL;
123f173c2b7SSean Bruno 	else
124f173c2b7SSean Bruno 		node = STAILQ_FIRST(root);
125f173c2b7SSean Bruno 
126f173c2b7SSean Bruno 	if (node != NULL)
127f173c2b7SSean Bruno 		STAILQ_REMOVE_HEAD(root, entries);
128f173c2b7SSean Bruno 
129f173c2b7SSean Bruno 	return (node);
130f173c2b7SSean Bruno }
131f173c2b7SSean Bruno 
132f173c2b7SSean Bruno #endif	/* __LIO_BSD_H__ */
133