xref: /freebsd/sys/dev/qlxgb/qla_os.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4088fc971SDavid C Somayajulu  * Copyright (c) 2011-2013 Qlogic Corporation
50bc7cf6fSBjoern A. Zeeb  * All rights reserved.
60bc7cf6fSBjoern A. Zeeb  *
70bc7cf6fSBjoern A. Zeeb  *  Redistribution and use in source and binary forms, with or without
80bc7cf6fSBjoern A. Zeeb  *  modification, are permitted provided that the following conditions
90bc7cf6fSBjoern A. Zeeb  *  are met:
100bc7cf6fSBjoern A. Zeeb  *
110bc7cf6fSBjoern A. Zeeb  *  1. Redistributions of source code must retain the above copyright
120bc7cf6fSBjoern A. Zeeb  *     notice, this list of conditions and the following disclaimer.
130bc7cf6fSBjoern A. Zeeb  *  2. Redistributions in binary form must reproduce the above copyright
140bc7cf6fSBjoern A. Zeeb  *     notice, this list of conditions and the following disclaimer in the
150bc7cf6fSBjoern A. Zeeb  *     documentation and/or other materials provided with the distribution.
160bc7cf6fSBjoern A. Zeeb  *
170bc7cf6fSBjoern A. Zeeb  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
180bc7cf6fSBjoern A. Zeeb  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
190bc7cf6fSBjoern A. Zeeb  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
200bc7cf6fSBjoern A. Zeeb  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
210bc7cf6fSBjoern A. Zeeb  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
220bc7cf6fSBjoern A. Zeeb  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
230bc7cf6fSBjoern A. Zeeb  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
240bc7cf6fSBjoern A. Zeeb  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
250bc7cf6fSBjoern A. Zeeb  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
260bc7cf6fSBjoern A. Zeeb  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
270bc7cf6fSBjoern A. Zeeb  *  POSSIBILITY OF SUCH DAMAGE.
280bc7cf6fSBjoern A. Zeeb  */
290bc7cf6fSBjoern A. Zeeb /*
300bc7cf6fSBjoern A. Zeeb  * File: qla_os.h
310bc7cf6fSBjoern A. Zeeb  * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
320bc7cf6fSBjoern A. Zeeb  */
330bc7cf6fSBjoern A. Zeeb 
340bc7cf6fSBjoern A. Zeeb #ifndef _QLA_OS_H_
350bc7cf6fSBjoern A. Zeeb #define _QLA_OS_H_
360bc7cf6fSBjoern A. Zeeb 
37618aa8cdSJohn Baldwin #include "opt_inet.h"
38618aa8cdSJohn Baldwin 
390bc7cf6fSBjoern A. Zeeb #include <sys/param.h>
400bc7cf6fSBjoern A. Zeeb #include <sys/systm.h>
410bc7cf6fSBjoern A. Zeeb #include <sys/mbuf.h>
420bc7cf6fSBjoern A. Zeeb #include <sys/protosw.h>
430bc7cf6fSBjoern A. Zeeb #include <sys/socket.h>
440bc7cf6fSBjoern A. Zeeb #include <sys/malloc.h>
450bc7cf6fSBjoern A. Zeeb #include <sys/module.h>
460bc7cf6fSBjoern A. Zeeb #include <sys/kernel.h>
470bc7cf6fSBjoern A. Zeeb #include <sys/sockio.h>
480bc7cf6fSBjoern A. Zeeb #include <sys/types.h>
490bc7cf6fSBjoern A. Zeeb #include <machine/atomic.h>
500bc7cf6fSBjoern A. Zeeb #include <sys/conf.h>
510bc7cf6fSBjoern A. Zeeb 
520bc7cf6fSBjoern A. Zeeb #include <net/if.h>
53c3322cb9SGleb Smirnoff #include <net/if_var.h>
540bc7cf6fSBjoern A. Zeeb #include <net/if_arp.h>
550bc7cf6fSBjoern A. Zeeb #include <net/ethernet.h>
560bc7cf6fSBjoern A. Zeeb #include <net/if_dl.h>
570bc7cf6fSBjoern A. Zeeb #include <net/if_media.h>
580bc7cf6fSBjoern A. Zeeb #include <net/bpf.h>
590bc7cf6fSBjoern A. Zeeb #include <net/if_types.h>
600bc7cf6fSBjoern A. Zeeb #include <net/if_vlan_var.h>
610bc7cf6fSBjoern A. Zeeb 
620bc7cf6fSBjoern A. Zeeb #include <netinet/in_systm.h>
630bc7cf6fSBjoern A. Zeeb #include <netinet/in.h>
640bc7cf6fSBjoern A. Zeeb #include <netinet/if_ether.h>
650bc7cf6fSBjoern A. Zeeb #include <netinet/ip.h>
660bc7cf6fSBjoern A. Zeeb #include <netinet/ip6.h>
670bc7cf6fSBjoern A. Zeeb #include <netinet/tcp.h>
680bc7cf6fSBjoern A. Zeeb #include <netinet/udp.h>
690bc7cf6fSBjoern A. Zeeb #include <netinet/in_var.h>
700bc7cf6fSBjoern A. Zeeb #include <netinet/tcp_lro.h>
710bc7cf6fSBjoern A. Zeeb 
720bc7cf6fSBjoern A. Zeeb #include <sys/bus.h>
730bc7cf6fSBjoern A. Zeeb #include <machine/bus.h>
740bc7cf6fSBjoern A. Zeeb #include <sys/rman.h>
750bc7cf6fSBjoern A. Zeeb #include <machine/resource.h>
760bc7cf6fSBjoern A. Zeeb #include <dev/pci/pcireg.h>
770bc7cf6fSBjoern A. Zeeb #include <dev/pci/pcivar.h>
780bc7cf6fSBjoern A. Zeeb #include <sys/mutex.h>
790bc7cf6fSBjoern A. Zeeb #include <sys/condvar.h>
800bc7cf6fSBjoern A. Zeeb #include <sys/proc.h>
810bc7cf6fSBjoern A. Zeeb #include <sys/sysctl.h>
820bc7cf6fSBjoern A. Zeeb #include <sys/endian.h>
830bc7cf6fSBjoern A. Zeeb #include <sys/taskqueue.h>
840bc7cf6fSBjoern A. Zeeb #include <sys/pcpu.h>
850bc7cf6fSBjoern A. Zeeb 
860bc7cf6fSBjoern A. Zeeb #include <sys/unistd.h>
870bc7cf6fSBjoern A. Zeeb #include <sys/kthread.h>
880bc7cf6fSBjoern A. Zeeb 
890bc7cf6fSBjoern A. Zeeb #define QLA_USEC_DELAY(usec)	DELAY(usec)
900bc7cf6fSBjoern A. Zeeb 
qla_ms_to_hz(int ms)910bc7cf6fSBjoern A. Zeeb static __inline int qla_ms_to_hz(int ms)
920bc7cf6fSBjoern A. Zeeb {
930bc7cf6fSBjoern A. Zeeb 	int qla_hz;
940bc7cf6fSBjoern A. Zeeb 
950bc7cf6fSBjoern A. Zeeb 	struct timeval t;
960bc7cf6fSBjoern A. Zeeb 
970bc7cf6fSBjoern A. Zeeb 	t.tv_sec = ms / 1000;
980bc7cf6fSBjoern A. Zeeb 	t.tv_usec = (ms % 1000) * 1000;
990bc7cf6fSBjoern A. Zeeb 
1000bc7cf6fSBjoern A. Zeeb 	qla_hz = tvtohz(&t);
1010bc7cf6fSBjoern A. Zeeb 
1020bc7cf6fSBjoern A. Zeeb 	if (qla_hz < 0)
1030bc7cf6fSBjoern A. Zeeb 		qla_hz = 0x7fffffff;
1040bc7cf6fSBjoern A. Zeeb 	if (!qla_hz)
1050bc7cf6fSBjoern A. Zeeb 		qla_hz = 1;
1060bc7cf6fSBjoern A. Zeeb 
1070bc7cf6fSBjoern A. Zeeb 	return (qla_hz);
1080bc7cf6fSBjoern A. Zeeb }
1090bc7cf6fSBjoern A. Zeeb 
qla_sec_to_hz(int sec)1100bc7cf6fSBjoern A. Zeeb static __inline int qla_sec_to_hz(int sec)
1110bc7cf6fSBjoern A. Zeeb {
1120bc7cf6fSBjoern A. Zeeb 	struct timeval t;
1130bc7cf6fSBjoern A. Zeeb 
1140bc7cf6fSBjoern A. Zeeb 	t.tv_sec = sec;
1150bc7cf6fSBjoern A. Zeeb 	t.tv_usec = 0;
1160bc7cf6fSBjoern A. Zeeb 
1170bc7cf6fSBjoern A. Zeeb 	return (tvtohz(&t));
1180bc7cf6fSBjoern A. Zeeb }
1190bc7cf6fSBjoern A. Zeeb 
1200bc7cf6fSBjoern A. Zeeb #define qla_host_to_le16(x)	htole16(x)
1210bc7cf6fSBjoern A. Zeeb #define qla_host_to_le32(x)	htole32(x)
1220bc7cf6fSBjoern A. Zeeb #define qla_host_to_le64(x)	htole64(x)
1230bc7cf6fSBjoern A. Zeeb #define qla_host_to_be16(x)	htobe16(x)
1240bc7cf6fSBjoern A. Zeeb #define qla_host_to_be32(x)	htobe32(x)
1250bc7cf6fSBjoern A. Zeeb #define qla_host_to_be64(x)	htobe64(x)
1260bc7cf6fSBjoern A. Zeeb 
1270bc7cf6fSBjoern A. Zeeb #define qla_le16_to_host(x)	le16toh(x)
1280bc7cf6fSBjoern A. Zeeb #define qla_le32_to_host(x)	le32toh(x)
1290bc7cf6fSBjoern A. Zeeb #define qla_le64_to_host(x)	le64toh(x)
1300bc7cf6fSBjoern A. Zeeb #define qla_be16_to_host(x)	be16toh(x)
1310bc7cf6fSBjoern A. Zeeb #define qla_be32_to_host(x)	be32toh(x)
1320bc7cf6fSBjoern A. Zeeb #define qla_be64_to_host(x)	be64toh(x)
1330bc7cf6fSBjoern A. Zeeb 
1340bc7cf6fSBjoern A. Zeeb MALLOC_DECLARE(M_QLA8XXXBUF);
1350bc7cf6fSBjoern A. Zeeb 
1360bc7cf6fSBjoern A. Zeeb #define qla_mdelay(fn, msecs)	\
1370bc7cf6fSBjoern A. Zeeb 	{\
1380bc7cf6fSBjoern A. Zeeb 		if (cold) \
1390bc7cf6fSBjoern A. Zeeb 			DELAY((msecs * 1000)); \
1400bc7cf6fSBjoern A. Zeeb 		else  \
1410bc7cf6fSBjoern A. Zeeb 			pause(fn, qla_ms_to_hz(msecs)); \
1420bc7cf6fSBjoern A. Zeeb 	}
1430bc7cf6fSBjoern A. Zeeb 
1440bc7cf6fSBjoern A. Zeeb /*
1450bc7cf6fSBjoern A. Zeeb  * Locks
1460bc7cf6fSBjoern A. Zeeb  */
1470bc7cf6fSBjoern A. Zeeb #define QLA_LOCK(ha, str) qla_lock(ha, str);
1480bc7cf6fSBjoern A. Zeeb #define QLA_UNLOCK(ha, str) qla_unlock(ha, str)
1490bc7cf6fSBjoern A. Zeeb 
1500bc7cf6fSBjoern A. Zeeb #define QLA_TX_LOCK(ha)		mtx_lock(&ha->tx_lock);
1510bc7cf6fSBjoern A. Zeeb #define QLA_TX_UNLOCK(ha)	mtx_unlock(&ha->tx_lock);
1520bc7cf6fSBjoern A. Zeeb 
1530bc7cf6fSBjoern A. Zeeb #define QLA_RX_LOCK(ha)		mtx_lock(&ha->rx_lock);
1540bc7cf6fSBjoern A. Zeeb #define QLA_RX_UNLOCK(ha)	mtx_unlock(&ha->rx_lock);
1550bc7cf6fSBjoern A. Zeeb 
1560bc7cf6fSBjoern A. Zeeb #define QLA_RXJ_LOCK(ha)	mtx_lock(&ha->rxj_lock);
1570bc7cf6fSBjoern A. Zeeb #define QLA_RXJ_UNLOCK(ha)	mtx_unlock(&ha->rxj_lock);
1580bc7cf6fSBjoern A. Zeeb 
1590bc7cf6fSBjoern A. Zeeb /*
1600bc7cf6fSBjoern A. Zeeb  * structure encapsulating a DMA buffer
1610bc7cf6fSBjoern A. Zeeb  */
1620bc7cf6fSBjoern A. Zeeb struct qla_dma {
1630bc7cf6fSBjoern A. Zeeb         bus_size_t              alignment;
1640bc7cf6fSBjoern A. Zeeb         uint32_t                size;
1650bc7cf6fSBjoern A. Zeeb         void                    *dma_b;
1660bc7cf6fSBjoern A. Zeeb         bus_addr_t              dma_addr;
1670bc7cf6fSBjoern A. Zeeb         bus_dmamap_t            dma_map;
1680bc7cf6fSBjoern A. Zeeb         bus_dma_tag_t           dma_tag;
1690bc7cf6fSBjoern A. Zeeb };
1700bc7cf6fSBjoern A. Zeeb typedef struct qla_dma qla_dma_t;
1710bc7cf6fSBjoern A. Zeeb 
1720bc7cf6fSBjoern A. Zeeb #define QL_ASSERT(x, y) if (!x) panic y
1730bc7cf6fSBjoern A. Zeeb 
1740bc7cf6fSBjoern A. Zeeb #endif /* #ifndef _QLA_OS_H_ */
175