xref: /freebsd/sys/dev/qlnx/qlnxe/qlnx_os.h (revision 9bc300465e48e19d794d88d0c158a2adb92c7197)
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  */
28 
29 /*
30  * File: qlnx_os.h
31  * Author : David C Somayajulu, Cavium, Inc., San Jose, CA 95131.
32  */
33 
34 #ifndef _QLNX_OS_H_
35 #define _QLNX_OS_H_
36 
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/mbuf.h>
40 #include <sys/protosw.h>
41 #include <sys/socket.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/kernel.h>
45 #include <sys/sockio.h>
46 #include <sys/types.h>
47 #include <machine/atomic.h>
48 #include <machine/_inttypes.h>
49 #include <sys/conf.h>
50 
51 #include <net/if.h>
52 #include <net/if_var.h>
53 #include <net/if_arp.h>
54 #include <net/ethernet.h>
55 #include <net/if_dl.h>
56 #include <net/if_media.h>
57 #include <net/bpf.h>
58 #include <net/if_types.h>
59 #include <net/if_vlan_var.h>
60 
61 #include <netinet/in_systm.h>
62 #include <netinet/in.h>
63 #include <netinet/if_ether.h>
64 #include <netinet/ip.h>
65 #include <netinet/ip6.h>
66 #include <netinet/tcp.h>
67 #include <netinet/udp.h>
68 #include <netinet/in_var.h>
69 #include <netinet/tcp_lro.h>
70 
71 #include <sys/bus.h>
72 #include <machine/bus.h>
73 #include <sys/rman.h>
74 #include <machine/resource.h>
75 #include <dev/pci/pcireg.h>
76 #include <dev/pci/pcivar.h>
77 #include <sys/mutex.h>
78 #include <sys/condvar.h>
79 #include <sys/proc.h>
80 #include <sys/sysctl.h>
81 #include <sys/endian.h>
82 #include <sys/taskqueue.h>
83 #include <sys/pcpu.h>
84 
85 #include <sys/unistd.h>
86 #include <sys/kthread.h>
87 #include <sys/libkern.h>
88 #include <sys/smp.h>
89 #include <sys/sched.h>
90 
91 static __inline int qlnx_ms_to_hz(int ms)
92 {
93 	int qlnx_hz;
94 
95 	struct timeval t;
96 
97 	t.tv_sec = ms / 1000;
98 	t.tv_usec = (ms % 1000) * 1000;
99 
100 	qlnx_hz = tvtohz(&t);
101 
102 	if (qlnx_hz < 0)
103 		qlnx_hz = 0x7fffffff;
104 	if (!qlnx_hz)
105 		qlnx_hz = 1;
106 
107 	return (qlnx_hz);
108 }
109 
110 static __inline int qlnx_sec_to_hz(int sec)
111 {
112 	struct timeval t;
113 
114 	t.tv_sec = sec;
115 	t.tv_usec = 0;
116 
117 	return (tvtohz(&t));
118 }
119 
120 MALLOC_DECLARE(M_QLNXBUF);
121 
122 #define qlnx_mdelay(fn, msecs)	\
123 	{\
124 		if (cold) \
125 			DELAY((msecs * 1000)); \
126 		else  \
127 			pause(fn, qlnx_ms_to_hz(msecs)); \
128 	}
129 
130 /*
131  * Locks
132  */
133 #define QLNX_LOCK(ha)		sx_xlock(&ha->hw_lock)
134 #define QLNX_UNLOCK(ha)		sx_xunlock(&ha->hw_lock)
135 
136 /*
137  * structure encapsulating a DMA buffer
138  */
139 struct qlnx_dma {
140         bus_size_t              alignment;
141         uint32_t                size;
142         void                    *dma_b;
143         bus_addr_t              dma_addr;
144         bus_dmamap_t            dma_map;
145         bus_dma_tag_t           dma_tag;
146 };
147 typedef struct qlnx_dma qlnx_dma_t;
148 
149 #endif /* #ifndef _QLNX_OS_H_ */
150