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