ql_os.h revision 331722
1/* 2 * Copyright (c) 2013-2016 Qlogic Corporation 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: stable/11/sys/dev/qlxgbe/ql_os.h 331722 2018-03-29 02:50:57Z eadler $ 28 */ 29/* 30 * File: ql_os.h 31 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656. 32 */ 33 34#ifndef _QL_OS_H_ 35#define _QL_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#if __FreeBSD_version < 900044 52#error FreeBSD Version not supported - use version >= 900044 53#endif 54 55#include <net/if.h> 56#include <net/if_var.h> 57#include <net/if_arp.h> 58#include <net/ethernet.h> 59#include <net/if_dl.h> 60#include <net/if_media.h> 61#include <net/bpf.h> 62#include <net/if_types.h> 63#include <net/if_vlan_var.h> 64 65#include <netinet/in_systm.h> 66#include <netinet/in.h> 67#include <netinet/if_ether.h> 68#include <netinet/ip.h> 69#include <netinet/ip6.h> 70#include <netinet/tcp.h> 71#include <netinet/udp.h> 72#include <netinet/in_var.h> 73#include <netinet/tcp_lro.h> 74 75#include <sys/bus.h> 76#include <machine/bus.h> 77#include <sys/rman.h> 78#include <machine/resource.h> 79#include <dev/pci/pcireg.h> 80#include <dev/pci/pcivar.h> 81#include <sys/mutex.h> 82#include <sys/condvar.h> 83#include <sys/proc.h> 84#include <sys/sysctl.h> 85#include <sys/endian.h> 86#include <sys/taskqueue.h> 87#include <sys/pcpu.h> 88 89#include <sys/unistd.h> 90#include <sys/kthread.h> 91 92#define QLA_USEC_DELAY(usec) DELAY(usec) 93 94static __inline int qla_ms_to_hz(int ms) 95{ 96 int qla_hz; 97 98 struct timeval t; 99 100 t.tv_sec = ms / 1000; 101 t.tv_usec = (ms % 1000) * 1000; 102 103 qla_hz = tvtohz(&t); 104 105 if (qla_hz < 0) 106 qla_hz = 0x7fffffff; 107 if (!qla_hz) 108 qla_hz = 1; 109 110 return (qla_hz); 111} 112 113static __inline int qla_sec_to_hz(int sec) 114{ 115 struct timeval t; 116 117 t.tv_sec = sec; 118 t.tv_usec = 0; 119 120 return (tvtohz(&t)); 121} 122 123static __inline uint64_t qla_get_usec_timestamp(void) 124{ 125 struct timeval tv; 126 127 microuptime(&tv); 128 129 return ((uint64_t)(((uint64_t)tv.tv_sec) * 1000000 + tv.tv_usec)); 130} 131 132#define qla_host_to_le16(x) htole16(x) 133#define qla_host_to_le32(x) htole32(x) 134#define qla_host_to_le64(x) htole64(x) 135#define qla_host_to_be16(x) htobe16(x) 136#define qla_host_to_be32(x) htobe32(x) 137#define qla_host_to_be64(x) htobe64(x) 138 139#define qla_le16_to_host(x) le16toh(x) 140#define qla_le32_to_host(x) le32toh(x) 141#define qla_le64_to_host(x) le64toh(x) 142#define qla_be16_to_host(x) be16toh(x) 143#define qla_be32_to_host(x) be32toh(x) 144#define qla_be64_to_host(x) be64toh(x) 145 146MALLOC_DECLARE(M_QLA83XXBUF); 147 148#define qla_mdelay(fn, msecs) \ 149 {\ 150 if (cold) \ 151 DELAY((msecs * 1000)); \ 152 else \ 153 pause(fn, qla_ms_to_hz(msecs)); \ 154 } 155 156/* 157 * Locks 158 */ 159#define QLA_LOCK(ha, str, to_ms, no_sleep) qla_lock(ha, str, to_ms, no_sleep) 160#define QLA_UNLOCK(ha, str) qla_unlock(ha, str) 161 162/* 163 * structure encapsulating a DMA buffer 164 */ 165struct qla_dma { 166 bus_size_t alignment; 167 uint32_t size; 168 void *dma_b; 169 bus_addr_t dma_addr; 170 bus_dmamap_t dma_map; 171 bus_dma_tag_t dma_tag; 172}; 173typedef struct qla_dma qla_dma_t; 174 175 176#endif /* #ifndef _QL_OS_H_ */ 177