1*f173c2b7SSean Bruno /* 2*f173c2b7SSean Bruno * BSD LICENSE 3*f173c2b7SSean Bruno * 4*f173c2b7SSean Bruno * Copyright(c) 2017 Cavium, Inc.. All rights reserved. 5*f173c2b7SSean Bruno * All rights reserved. 6*f173c2b7SSean Bruno * 7*f173c2b7SSean Bruno * Redistribution and use in source and binary forms, with or without 8*f173c2b7SSean Bruno * modification, are permitted provided that the following conditions 9*f173c2b7SSean Bruno * are met: 10*f173c2b7SSean Bruno * 11*f173c2b7SSean Bruno * * Redistributions of source code must retain the above copyright 12*f173c2b7SSean Bruno * notice, this list of conditions and the following disclaimer. 13*f173c2b7SSean Bruno * * Redistributions in binary form must reproduce the above copyright 14*f173c2b7SSean Bruno * notice, this list of conditions and the following disclaimer in 15*f173c2b7SSean Bruno * the documentation and/or other materials provided with the 16*f173c2b7SSean Bruno * distribution. 17*f173c2b7SSean Bruno * * Neither the name of Cavium, Inc. nor the names of its 18*f173c2b7SSean Bruno * contributors may be used to endorse or promote products derived 19*f173c2b7SSean Bruno * from this software without specific prior written permission. 20*f173c2b7SSean Bruno * 21*f173c2b7SSean Bruno * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22*f173c2b7SSean Bruno * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23*f173c2b7SSean Bruno * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24*f173c2b7SSean Bruno * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25*f173c2b7SSean Bruno * OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26*f173c2b7SSean Bruno * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27*f173c2b7SSean Bruno * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28*f173c2b7SSean Bruno * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29*f173c2b7SSean Bruno * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30*f173c2b7SSean Bruno * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31*f173c2b7SSean Bruno * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32*f173c2b7SSean Bruno */ 33*f173c2b7SSean Bruno /*$FreeBSD$*/ 34*f173c2b7SSean Bruno 35*f173c2b7SSean Bruno #ifndef __LIO_BSD_H__ 36*f173c2b7SSean Bruno #define __LIO_BSD_H__ 37*f173c2b7SSean Bruno 38*f173c2b7SSean Bruno #include <sys/param.h> 39*f173c2b7SSean Bruno #include <sys/socket.h> 40*f173c2b7SSean Bruno #include <sys/kernel.h> 41*f173c2b7SSean Bruno #include <sys/module.h> 42*f173c2b7SSean Bruno #include <sys/sockio.h> 43*f173c2b7SSean Bruno 44*f173c2b7SSean Bruno #include <net/if.h> 45*f173c2b7SSean Bruno #include <net/if_var.h> 46*f173c2b7SSean Bruno #include <net/bpf.h> 47*f173c2b7SSean Bruno #include <net/ethernet.h> 48*f173c2b7SSean Bruno #include <net/if_dl.h> 49*f173c2b7SSean Bruno #include <net/if_media.h> 50*f173c2b7SSean Bruno 51*f173c2b7SSean Bruno #include <net/if_types.h> 52*f173c2b7SSean Bruno #include <net/if_vlan_var.h> 53*f173c2b7SSean Bruno #include <net/if_gif.h> 54*f173c2b7SSean Bruno 55*f173c2b7SSean Bruno #include <netinet/tcp_lro.h> 56*f173c2b7SSean Bruno 57*f173c2b7SSean Bruno #include <sys/bus.h> 58*f173c2b7SSean Bruno #include <machine/bus.h> 59*f173c2b7SSean Bruno #include <sys/rman.h> 60*f173c2b7SSean Bruno #include <vm/vm.h> 61*f173c2b7SSean Bruno #include <vm/pmap.h> 62*f173c2b7SSean Bruno #include <dev/pci/pcivar.h> 63*f173c2b7SSean Bruno #include <dev/pci/pcireg.h> 64*f173c2b7SSean Bruno #include <sys/sysctl.h> 65*f173c2b7SSean Bruno #include <sys/taskqueue.h> 66*f173c2b7SSean Bruno #include <sys/smp.h> 67*f173c2b7SSean Bruno #include <sys/kthread.h> 68*f173c2b7SSean Bruno #include <sys/firmware.h> 69*f173c2b7SSean Bruno 70*f173c2b7SSean Bruno #include <vm/vm_extern.h> 71*f173c2b7SSean Bruno #include <vm/vm_kern.h> 72*f173c2b7SSean Bruno 73*f173c2b7SSean Bruno #ifndef PCI_VENDOR_ID_CAVIUM 74*f173c2b7SSean Bruno #define PCI_VENDOR_ID_CAVIUM 0x177D 75*f173c2b7SSean Bruno #endif 76*f173c2b7SSean Bruno 77*f173c2b7SSean Bruno #define BIT(nr) (1UL << (nr)) 78*f173c2b7SSean Bruno 79*f173c2b7SSean Bruno #define lio_check_timeout(a, b) ((int)((b) - (a)) < 0) 80*f173c2b7SSean Bruno 81*f173c2b7SSean Bruno #define lio_ms_to_ticks(x) \ 82*f173c2b7SSean Bruno ((hz > 1000) ? ((x) * (hz/1000)) : ((x) / (1000/hz))) 83*f173c2b7SSean Bruno 84*f173c2b7SSean Bruno #define lio_mdelay(x) do { \ 85*f173c2b7SSean Bruno if (cold) \ 86*f173c2b7SSean Bruno DELAY(1000 * (x)); \ 87*f173c2b7SSean Bruno else \ 88*f173c2b7SSean Bruno pause("Wait", lio_ms_to_ticks(x)); \ 89*f173c2b7SSean Bruno } while(0) 90*f173c2b7SSean Bruno 91*f173c2b7SSean Bruno #define lio_sleep_timeout(timeout) lio_mdelay((timeout)) 92*f173c2b7SSean Bruno 93*f173c2b7SSean Bruno typedef uint32_t __be32; 94*f173c2b7SSean Bruno typedef uint64_t __be64; 95*f173c2b7SSean Bruno 96*f173c2b7SSean Bruno #define lio_dev_info(oct, format, args...) \ 97*f173c2b7SSean Bruno device_printf(oct->device, "Info: " format, ##args) 98*f173c2b7SSean Bruno #define lio_dev_warn(oct, format, args...) \ 99*f173c2b7SSean Bruno device_printf(oct->device, "Warn: " format, ##args) 100*f173c2b7SSean Bruno #define lio_dev_err(oct, format, args...) \ 101*f173c2b7SSean Bruno device_printf(oct->device, "Error: " format, ##args) 102*f173c2b7SSean Bruno 103*f173c2b7SSean Bruno #ifdef LIO_DEBUG 104*f173c2b7SSean Bruno #define lio_dev_dbg(oct, format, args...) \ 105*f173c2b7SSean Bruno device_printf(oct->device, "Debug: " format, ##args) 106*f173c2b7SSean Bruno #else 107*f173c2b7SSean Bruno #define lio_dev_dbg(oct, format, args...) {do { } while (0); } 108*f173c2b7SSean Bruno #endif 109*f173c2b7SSean Bruno 110*f173c2b7SSean Bruno struct lio_stailq_node { 111*f173c2b7SSean Bruno STAILQ_ENTRY (lio_stailq_node) entries; 112*f173c2b7SSean Bruno }; 113*f173c2b7SSean Bruno STAILQ_HEAD (lio_stailq_head, lio_stailq_node); 114*f173c2b7SSean Bruno 115*f173c2b7SSean Bruno static inline struct lio_stailq_node * 116*f173c2b7SSean Bruno lio_delete_first_node(struct lio_stailq_head *root) 117*f173c2b7SSean Bruno { 118*f173c2b7SSean Bruno struct lio_stailq_node *node; 119*f173c2b7SSean Bruno 120*f173c2b7SSean Bruno if (STAILQ_EMPTY(root)) 121*f173c2b7SSean Bruno node = NULL; 122*f173c2b7SSean Bruno else 123*f173c2b7SSean Bruno node = STAILQ_FIRST(root); 124*f173c2b7SSean Bruno 125*f173c2b7SSean Bruno if (node != NULL) 126*f173c2b7SSean Bruno STAILQ_REMOVE_HEAD(root, entries); 127*f173c2b7SSean Bruno 128*f173c2b7SSean Bruno return (node); 129*f173c2b7SSean Bruno } 130*f173c2b7SSean Bruno 131*f173c2b7SSean Bruno #endif /* __LIO_BSD_H__ */ 132