1 /************************************************************************** 2 3 Copyright (c) 2001-2006, Intel Corporation 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 9 1. Redistributions of source code must retain the above copyright notice, 10 this list of conditions and the following disclaimer. 11 12 2. Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 3. Neither the name of the Intel Corporation nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 POSSIBILITY OF SUCH DAMAGE. 31 32 ***************************************************************************/ 33 34 /* $OpenBSD: if_em_osdep.h,v 1.15 2024/10/22 21:50:02 jsg Exp $ */ 35 /* $FreeBSD: if_em_osdep.h,v 1.11 2003/05/02 21:17:08 pdeuskar Exp $ */ 36 37 #ifndef _EM_OPENBSD_OS_H_ 38 #define _EM_OPENBSD_OS_H_ 39 40 #define usec_delay(x) DELAY(x) 41 #define msec_delay(x) DELAY(1000*(x)) 42 /* TODO: Should we be paranoid about delaying in interrupt context? */ 43 #define msec_delay_irq(x) DELAY(1000*(x)) 44 45 #define MSGOUT(S, A, B) printf(S "\n", A, B) 46 #define DEBUGFUNC(F) DEBUGOUT(F); 47 #ifdef DBG 48 #define DEBUGOUT(S) printf(S "\n") 49 #define DEBUGOUT1(S,A) printf(S "\n",A) 50 #define DEBUGOUT2(S,A,B) printf(S "\n",A,B) 51 #define DEBUGOUT3(S,A,B,C) printf(S "\n",A,B,C) 52 #define DEBUGOUT7(S,A,B,C,D,E,F,G) printf(S "\n",A,B,C,D,E,F,G) 53 #else 54 #define DEBUGOUT(S) 55 #define DEBUGOUT1(S,A) 56 #define DEBUGOUT2(S,A,B) 57 #define DEBUGOUT3(S,A,B,C) 58 #define DEBUGOUT7(S,A,B,C,D,E,F,G) 59 #endif 60 61 #define CMD_MEM_WRT_INVALIDATE 0x0010 /* BIT_4 */ 62 63 struct em_osdep { 64 bus_space_tag_t mem_bus_space_tag; 65 bus_space_handle_t mem_bus_space_handle; 66 bus_space_tag_t io_bus_space_tag; 67 bus_space_handle_t io_bus_space_handle; 68 bus_space_tag_t flash_bus_space_tag; 69 bus_space_handle_t flash_bus_space_handle; 70 struct device *dev; 71 72 struct pci_attach_args em_pa; 73 74 bus_size_t em_memsize; 75 bus_addr_t em_membase; 76 bus_size_t em_iosize; 77 bus_addr_t em_iobase; 78 bus_size_t em_flashsize; 79 bus_addr_t em_flashbase; 80 size_t em_flashoffset; 81 }; 82 83 #define E1000_WRITE_FLUSH(hw) E1000_READ_REG(hw, STATUS) 84 85 /* Read from an absolute offset in the adapter's memory space */ 86 #define E1000_READ_OFFSET(hw, offset) \ 87 bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 88 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 89 offset) 90 91 /* Write to an absolute offset in the adapter's memory space */ 92 #define E1000_WRITE_OFFSET(hw, offset, value) \ 93 bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 94 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 95 offset, value) 96 97 /* Convert a register name to its offset in the adapter's memory space */ 98 #define E1000_REG_TR(hw, reg) \ 99 ((hw)->mac_type >= em_82543 ? \ 100 reg : em_translate_82542_register(reg)) 101 102 /* Register READ/WRITE macros */ 103 104 #define E1000_READ_REG(hw, reg) \ 105 bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 106 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 107 E1000_REG_TR(hw, E1000_##reg)) 108 109 #define E1000_WRITE_REG(hw, reg, value) \ 110 bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 111 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 112 E1000_REG_TR(hw, E1000_##reg), \ 113 value) 114 115 #define EM_READ_REG(hw, reg) \ 116 bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 117 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 118 reg) 119 120 #define EM_WRITE_REG(hw, reg, value) \ 121 bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 122 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 123 reg, value) 124 125 #define EM_READ_REG_ARRAY(hw, reg, index) \ 126 bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 127 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 128 reg + ((index) << 2)) 129 130 #define EM_WRITE_REG_ARRAY(hw, reg, index, value) \ 131 bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 132 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 133 reg + ((index) << 2), value) 134 135 #define E1000_READ_REG_ARRAY(hw, reg, index) \ 136 bus_space_read_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 137 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 138 E1000_REG_TR(hw, E1000_##reg) + ((index) << 2)) 139 140 #define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \ 141 bus_space_write_4(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 142 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 143 E1000_REG_TR(hw, E1000_##reg) + ((index) << 2), \ 144 value) 145 146 #define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY 147 #define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY 148 149 #define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \ 150 bus_space_write_1(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 151 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 152 E1000_REG_TR(hw, E1000_##reg) + index, \ 153 value) 154 155 #define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \ 156 bus_space_write_2(((struct em_osdep *)(hw)->back)->mem_bus_space_tag, \ 157 ((struct em_osdep *)(hw)->back)->mem_bus_space_handle, \ 158 E1000_REG_TR(hw, E1000_##reg) + (index << 1), \ 159 value) 160 161 #define E1000_READ_ICH_FLASH_REG(hw, reg) \ 162 bus_space_read_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \ 163 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \ 164 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg) 165 166 #define E1000_READ_ICH_FLASH_REG16(hw, reg) \ 167 bus_space_read_2(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \ 168 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \ 169 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg) 170 171 #define E1000_READ_ICH_FLASH_REG32(hw, reg) \ 172 bus_space_read_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \ 173 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \ 174 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg) 175 176 177 #define E1000_WRITE_ICH_FLASH_REG8(hw, reg, value) \ 178 bus_space_write_1(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \ 179 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \ 180 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg, \ 181 value) 182 183 #define E1000_WRITE_ICH_FLASH_REG16(hw, reg, value) \ 184 bus_space_write_2(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \ 185 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \ 186 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg, \ 187 value) 188 189 #define E1000_WRITE_ICH_FLASH_REG32(hw, reg, value) \ 190 bus_space_write_4(((struct em_osdep *)(hw)->back)->flash_bus_space_tag, \ 191 ((struct em_osdep *)(hw)->back)->flash_bus_space_handle, \ 192 ((struct em_osdep *)(hw)->back)->em_flashoffset + reg, \ 193 value) 194 195 #define em_io_read(hw, port) \ 196 bus_space_read_4(((struct em_osdep *)(hw)->back)->io_bus_space_tag, \ 197 ((struct em_osdep *)(hw)->back)->io_bus_space_handle, (port)) 198 199 #define em_io_write(hw, port, value) \ 200 bus_space_write_4(((struct em_osdep *)(hw)->back)->io_bus_space_tag, \ 201 ((struct em_osdep *)(hw)->back)->io_bus_space_handle, \ 202 (port), (value)) 203 204 #ifdef DEBUG 205 #define EM_KASSERT(exp,msg) do { if (!(exp)) panic msg; } while (0) 206 #else 207 #define EM_KASSERT(exp,msg) 208 #endif 209 210 #endif /* _EM_OPENBSD_OS_H_ */ 211