2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011-2013 Qlogic Corporation
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
33 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
39 #include <sys/param.h>
40 #include <sys/systm.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>
52 #if __FreeBSD_version < 700112
53 #error FreeBSD Version not supported - use version >= 700112
57 #include <net/if_var.h>
58 #include <net/if_arp.h>
59 #include <net/ethernet.h>
60 #include <net/if_dl.h>
61 #include <net/if_media.h>
63 #include <net/if_types.h>
64 #include <net/if_vlan_var.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/in.h>
68 #include <netinet/if_ether.h>
69 #include <netinet/ip.h>
70 #include <netinet/ip6.h>
71 #include <netinet/tcp.h>
72 #include <netinet/udp.h>
73 #include <netinet/in_var.h>
74 #include <netinet/tcp_lro.h>
77 #include <machine/bus.h>
79 #include <machine/resource.h>
80 #include <dev/pci/pcireg.h>
81 #include <dev/pci/pcivar.h>
82 #include <sys/mutex.h>
83 #include <sys/condvar.h>
85 #include <sys/sysctl.h>
86 #include <sys/endian.h>
87 #include <sys/taskqueue.h>
90 #include <sys/unistd.h>
91 #include <sys/kthread.h>
93 #define QLA_USEC_DELAY(usec) DELAY(usec)
95 static __inline int qla_ms_to_hz(int ms)
101 t.tv_sec = ms / 1000;
102 t.tv_usec = (ms % 1000) * 1000;
114 static __inline int qla_sec_to_hz(int sec)
125 #define qla_host_to_le16(x) htole16(x)
126 #define qla_host_to_le32(x) htole32(x)
127 #define qla_host_to_le64(x) htole64(x)
128 #define qla_host_to_be16(x) htobe16(x)
129 #define qla_host_to_be32(x) htobe32(x)
130 #define qla_host_to_be64(x) htobe64(x)
132 #define qla_le16_to_host(x) le16toh(x)
133 #define qla_le32_to_host(x) le32toh(x)
134 #define qla_le64_to_host(x) le64toh(x)
135 #define qla_be16_to_host(x) be16toh(x)
136 #define qla_be32_to_host(x) be32toh(x)
137 #define qla_be64_to_host(x) be64toh(x)
139 MALLOC_DECLARE(M_QLA8XXXBUF);
141 #define qla_mdelay(fn, msecs) \
144 DELAY((msecs * 1000)); \
146 pause(fn, qla_ms_to_hz(msecs)); \
152 #define QLA_LOCK(ha, str) qla_lock(ha, str);
153 #define QLA_UNLOCK(ha, str) qla_unlock(ha, str)
155 #define QLA_TX_LOCK(ha) mtx_lock(&ha->tx_lock);
156 #define QLA_TX_UNLOCK(ha) mtx_unlock(&ha->tx_lock);
158 #define QLA_RX_LOCK(ha) mtx_lock(&ha->rx_lock);
159 #define QLA_RX_UNLOCK(ha) mtx_unlock(&ha->rx_lock);
161 #define QLA_RXJ_LOCK(ha) mtx_lock(&ha->rxj_lock);
162 #define QLA_RXJ_UNLOCK(ha) mtx_unlock(&ha->rxj_lock);
165 * structure encapsulating a DMA buffer
168 bus_size_t alignment;
172 bus_dmamap_t dma_map;
173 bus_dma_tag_t dma_tag;
175 typedef struct qla_dma qla_dma_t;
177 #define QL_ASSERT(x, y) if (!x) panic y
179 #endif /* #ifndef _QLA_OS_H_ */