xref: /freebsd/sys/dev/qlnx/qlnxe/qlnx_os.h (revision 8c784bb8cf36911b828652f0bf7e88f443abec50)
1 /*
2  * Copyright (c) 2017-2018 Cavium, Inc.
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  *
29  */
30 
31 /*
32  * File: qlnx_os.h
33  * Author : David C Somayajulu, Cavium, Inc., San Jose, CA 95131.
34  */
35 
36 #ifndef _QLNX_OS_H_
37 #define _QLNX_OS_H_
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/mbuf.h>
42 #include <sys/protosw.h>
43 #include <sys/socket.h>
44 #include <sys/malloc.h>
45 #include <sys/module.h>
46 #include <sys/kernel.h>
47 #include <sys/sockio.h>
48 #include <sys/types.h>
49 #include <machine/atomic.h>
50 #include <machine/_inttypes.h>
51 #include <sys/conf.h>
52 
53 #include <net/if.h>
54 #include <net/if_var.h>
55 #include <net/if_arp.h>
56 #include <net/ethernet.h>
57 #include <net/if_dl.h>
58 #include <net/if_media.h>
59 #include <net/bpf.h>
60 #include <net/if_types.h>
61 #include <net/if_vlan_var.h>
62 
63 #include <netinet/in_systm.h>
64 #include <netinet/in.h>
65 #include <netinet/if_ether.h>
66 #include <netinet/ip.h>
67 #include <netinet/ip6.h>
68 #include <netinet/tcp.h>
69 #include <netinet/udp.h>
70 #include <netinet/in_var.h>
71 #include <netinet/tcp_lro.h>
72 
73 #include <sys/bus.h>
74 #include <machine/bus.h>
75 #include <sys/rman.h>
76 #include <machine/resource.h>
77 #include <dev/pci/pcireg.h>
78 #include <dev/pci/pcivar.h>
79 #include <sys/mutex.h>
80 #include <sys/condvar.h>
81 #include <sys/proc.h>
82 #include <sys/sysctl.h>
83 #include <sys/endian.h>
84 #include <sys/taskqueue.h>
85 #include <sys/pcpu.h>
86 
87 #include <sys/unistd.h>
88 #include <sys/kthread.h>
89 #include <sys/libkern.h>
90 #include <sys/smp.h>
91 #include <sys/sched.h>
92 
93 #ifdef CONFIG_ECORE_SRIOV
94 #include <sys/nv.h>
95 #include <sys/iov_schema.h>
96 #include <dev/pci/pci_iov.h>
97 #endif /* #ifdef CONFIG_ECORE_SRIOV */
98 
99 static __inline int qlnx_ms_to_hz(int ms)
100 {
101 	int qlnx_hz;
102 
103 	struct timeval t;
104 
105 	t.tv_sec = ms / 1000;
106 	t.tv_usec = (ms % 1000) * 1000;
107 
108 	qlnx_hz = tvtohz(&t);
109 
110 	if (qlnx_hz < 0)
111 		qlnx_hz = 0x7fffffff;
112 	if (!qlnx_hz)
113 		qlnx_hz = 1;
114 
115 	return (qlnx_hz);
116 }
117 
118 static __inline int qlnx_sec_to_hz(int sec)
119 {
120 	struct timeval t;
121 
122 	t.tv_sec = sec;
123 	t.tv_usec = 0;
124 
125 	return (tvtohz(&t));
126 }
127 
128 MALLOC_DECLARE(M_QLNXBUF);
129 
130 #define qlnx_mdelay(fn, msecs)	\
131 	{\
132 		if (cold) \
133 			DELAY((msecs * 1000)); \
134 		else  \
135 			pause(fn, qlnx_ms_to_hz(msecs)); \
136 	}
137 
138 /*
139  * Locks
140  */
141 #define QLNX_LOCK(ha)		mtx_lock(&ha->hw_lock)
142 #define QLNX_UNLOCK(ha)		mtx_unlock(&ha->hw_lock)
143 
144 /*
145  * structure encapsulating a DMA buffer
146  */
147 struct qlnx_dma {
148         bus_size_t              alignment;
149         uint32_t                size;
150         void                    *dma_b;
151         bus_addr_t              dma_addr;
152         bus_dmamap_t            dma_map;
153         bus_dma_tag_t           dma_tag;
154 };
155 typedef struct qlnx_dma qlnx_dma_t;
156 
157 #endif /* #ifndef _QLNX_OS_H_ */
158