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