xref: /dflybsd-src/sys/dev/netif/ig_hal/e1000_osdep.h (revision 74dc37549af2a2c5a84a4b9aa9493437b50f294f)
19c80d176SSepherosa Ziehau /******************************************************************************
29c80d176SSepherosa Ziehau 
3*74dc3754SSepherosa Ziehau   Copyright (c) 2001-2015, Intel Corporation
49c80d176SSepherosa Ziehau   All rights reserved.
59c80d176SSepherosa Ziehau 
69c80d176SSepherosa Ziehau   Redistribution and use in source and binary forms, with or without
79c80d176SSepherosa Ziehau   modification, are permitted provided that the following conditions are met:
89c80d176SSepherosa Ziehau 
99c80d176SSepherosa Ziehau    1. Redistributions of source code must retain the above copyright notice,
109c80d176SSepherosa Ziehau       this list of conditions and the following disclaimer.
119c80d176SSepherosa Ziehau 
129c80d176SSepherosa Ziehau    2. Redistributions in binary form must reproduce the above copyright
139c80d176SSepherosa Ziehau       notice, this list of conditions and the following disclaimer in the
149c80d176SSepherosa Ziehau       documentation and/or other materials provided with the distribution.
159c80d176SSepherosa Ziehau 
169c80d176SSepherosa Ziehau    3. Neither the name of the Intel Corporation nor the names of its
179c80d176SSepherosa Ziehau       contributors may be used to endorse or promote products derived from
189c80d176SSepherosa Ziehau       this software without specific prior written permission.
199c80d176SSepherosa Ziehau 
209c80d176SSepherosa Ziehau   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
219c80d176SSepherosa Ziehau   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
229c80d176SSepherosa Ziehau   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
239c80d176SSepherosa Ziehau   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
249c80d176SSepherosa Ziehau   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
259c80d176SSepherosa Ziehau   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
269c80d176SSepherosa Ziehau   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
279c80d176SSepherosa Ziehau   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
289c80d176SSepherosa Ziehau   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
299c80d176SSepherosa Ziehau   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
309c80d176SSepherosa Ziehau   POSSIBILITY OF SUCH DAMAGE.
319c80d176SSepherosa Ziehau 
329c80d176SSepherosa Ziehau ******************************************************************************/
339c80d176SSepherosa Ziehau 
349c80d176SSepherosa Ziehau #ifndef _DRAGONFLY_OS_H_
359c80d176SSepherosa Ziehau #define _DRAGONFLY_OS_H_
369c80d176SSepherosa Ziehau 
379c80d176SSepherosa Ziehau #include <sys/param.h>
389c80d176SSepherosa Ziehau #include <sys/bus.h>
399c80d176SSepherosa Ziehau #include <sys/kernel.h>
409c80d176SSepherosa Ziehau #include <sys/systm.h>
419c80d176SSepherosa Ziehau 
429c80d176SSepherosa Ziehau #include <bus/pci/pcivar.h>
439c80d176SSepherosa Ziehau #include <bus/pci/pcireg.h>
449c80d176SSepherosa Ziehau 
459c80d176SSepherosa Ziehau #define usec_delay(x) DELAY(x)
46*74dc3754SSepherosa Ziehau #define usec_delay_irq(x) usec_delay(x)
479c80d176SSepherosa Ziehau #define msec_delay(x) DELAY(1000*(x))
489c80d176SSepherosa Ziehau #define msec_delay_irq(x) DELAY(1000*(x))
499c80d176SSepherosa Ziehau 
50188478eeSSepherosa Ziehau extern int e1000_debug;
51188478eeSSepherosa Ziehau 
52*74dc3754SSepherosa Ziehau #define DEBUGOUT(S, args...)		\
53188478eeSSepherosa Ziehau do {					\
54188478eeSSepherosa Ziehau 	if (e1000_debug)		\
55188478eeSSepherosa Ziehau 		kprintf(S, ##args);	\
56188478eeSSepherosa Ziehau } while (0)
57*74dc3754SSepherosa Ziehau #define DEBUGOUT1(S, args...)	DEBUGOUT(S, ##args)
58*74dc3754SSepherosa Ziehau #define DEBUGOUT2(S, args...)	DEBUGOUT(S, ##args)
59*74dc3754SSepherosa Ziehau #define DEBUGOUT3(S, args...)	DEBUGOUT(S, ##args)
60*74dc3754SSepherosa Ziehau #define DEBUGOUT7(S, args...)	DEBUGOUT(S, ##args)
61*74dc3754SSepherosa Ziehau #define DEBUGFUNC(F)		DEBUGOUT(F "\n")
629c80d176SSepherosa Ziehau 
639c80d176SSepherosa Ziehau #define CMD_MEM_WRT_INVALIDATE	0x0010  /* BIT_4 */
649c80d176SSepherosa Ziehau #define PCI_COMMAND_REGISTER	PCIR_COMMAND
659c80d176SSepherosa Ziehau 
669c80d176SSepherosa Ziehau /*
679c80d176SSepherosa Ziehau  * These typedefs are necessary due to the new
689c80d176SSepherosa Ziehau  * shared code, they are native to Linux.
699c80d176SSepherosa Ziehau  */
709c80d176SSepherosa Ziehau typedef uint64_t	u64;
719c80d176SSepherosa Ziehau typedef uint32_t	u32;
729c80d176SSepherosa Ziehau typedef uint16_t	u16;
739c80d176SSepherosa Ziehau typedef uint8_t		u8;
749c80d176SSepherosa Ziehau typedef int64_t		s64;
759c80d176SSepherosa Ziehau typedef int32_t		s32;
769c80d176SSepherosa Ziehau typedef int16_t		s16;
779c80d176SSepherosa Ziehau typedef int8_t		s8;
789c80d176SSepherosa Ziehau 
799c80d176SSepherosa Ziehau #define __le16		u16
809c80d176SSepherosa Ziehau #define __le32		u32
819c80d176SSepherosa Ziehau #define __le64		u64
829c80d176SSepherosa Ziehau 
839c80d176SSepherosa Ziehau struct e1000_osdep {
849c80d176SSepherosa Ziehau 	bus_space_tag_t		mem_bus_space_tag;
859c80d176SSepherosa Ziehau 	bus_space_handle_t	mem_bus_space_handle;
869c80d176SSepherosa Ziehau 	bus_space_tag_t		io_bus_space_tag;
879c80d176SSepherosa Ziehau 	bus_space_handle_t	io_bus_space_handle;
889c80d176SSepherosa Ziehau 	bus_space_tag_t		flash_bus_space_tag;
899c80d176SSepherosa Ziehau 	bus_space_handle_t	flash_bus_space_handle;
909c80d176SSepherosa Ziehau 	device_t		dev;
919c80d176SSepherosa Ziehau };
929c80d176SSepherosa Ziehau 
939c80d176SSepherosa Ziehau #define E1000_REGISTER(hw, reg) (((hw)->mac.type >= e1000_82543) \
949c80d176SSepherosa Ziehau     ? reg : e1000_translate_register_82542(reg))
959c80d176SSepherosa Ziehau 
969c80d176SSepherosa Ziehau #define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, E1000_STATUS)
979c80d176SSepherosa Ziehau 
989c80d176SSepherosa Ziehau /* Read from an absolute offset in the adapter's memory space */
999c80d176SSepherosa Ziehau #define E1000_READ_OFFSET(hw, offset) \
1009c80d176SSepherosa Ziehau     bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1019c80d176SSepherosa Ziehau     ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset)
1029c80d176SSepherosa Ziehau 
1039c80d176SSepherosa Ziehau /* Write to an absolute offset in the adapter's memory space */
1049c80d176SSepherosa Ziehau #define E1000_WRITE_OFFSET(hw, offset, value) \
1059c80d176SSepherosa Ziehau     bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1069c80d176SSepherosa Ziehau     ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset, value)
1079c80d176SSepherosa Ziehau 
1089c80d176SSepherosa Ziehau /* Register READ/WRITE macros */
1099c80d176SSepherosa Ziehau 
1109c80d176SSepherosa Ziehau #define E1000_READ_REG(hw, reg) \
1119c80d176SSepherosa Ziehau     bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1129c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
1139c80d176SSepherosa Ziehau         E1000_REGISTER(hw, reg))
1149c80d176SSepherosa Ziehau 
1159c80d176SSepherosa Ziehau #define E1000_WRITE_REG(hw, reg, value) \
1169c80d176SSepherosa Ziehau     bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1179c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
1189c80d176SSepherosa Ziehau         E1000_REGISTER(hw, reg), value)
1199c80d176SSepherosa Ziehau 
1209c80d176SSepherosa Ziehau #define E1000_READ_REG_ARRAY(hw, reg, index) \
1219c80d176SSepherosa Ziehau     bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1229c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
1239c80d176SSepherosa Ziehau         E1000_REGISTER(hw, reg) + ((index)<< 2))
1249c80d176SSepherosa Ziehau 
1259c80d176SSepherosa Ziehau #define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
1269c80d176SSepherosa Ziehau     bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1279c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
1289c80d176SSepherosa Ziehau         E1000_REGISTER(hw, reg) + ((index)<< 2), value)
1299c80d176SSepherosa Ziehau 
1309c80d176SSepherosa Ziehau #define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
1319c80d176SSepherosa Ziehau #define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
1329c80d176SSepherosa Ziehau 
1339c80d176SSepherosa Ziehau #define E1000_READ_REG_ARRAY_BYTE(hw, reg, index) \
1349c80d176SSepherosa Ziehau     bus_space_read_1(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1359c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
1369c80d176SSepherosa Ziehau         E1000_REGISTER(hw, reg) + index)
1379c80d176SSepherosa Ziehau 
1389c80d176SSepherosa Ziehau #define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
1399c80d176SSepherosa Ziehau     bus_space_write_1(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1409c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
1419c80d176SSepherosa Ziehau         E1000_REGISTER(hw, reg) + index, value)
1429c80d176SSepherosa Ziehau 
1439c80d176SSepherosa Ziehau #define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
1449c80d176SSepherosa Ziehau     bus_space_write_2(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
1459c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
1469c80d176SSepherosa Ziehau         E1000_REGISTER(hw, reg) + (index << 1), value)
1479c80d176SSepherosa Ziehau 
1489c80d176SSepherosa Ziehau #define E1000_WRITE_REG_IO(hw, reg, value) do {\
1499c80d176SSepherosa Ziehau     bus_space_write_4(((struct e1000_osdep *)(hw)->back)->io_bus_space_tag, \
1509c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
1519c80d176SSepherosa Ziehau         (hw)->io_base, reg); \
1529c80d176SSepherosa Ziehau     bus_space_write_4(((struct e1000_osdep *)(hw)->back)->io_bus_space_tag, \
1539c80d176SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
1549c80d176SSepherosa Ziehau         (hw)->io_base + 4, value); } while (0)
1559c80d176SSepherosa Ziehau 
1569c80d176SSepherosa Ziehau #define E1000_READ_FLASH_REG(hw, reg) \
1579c80d176SSepherosa Ziehau     bus_space_read_4(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
158*74dc3754SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
1599c80d176SSepherosa Ziehau 
1609c80d176SSepherosa Ziehau #define E1000_READ_FLASH_REG16(hw, reg) \
1619c80d176SSepherosa Ziehau     bus_space_read_2(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
162*74dc3754SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
1639c80d176SSepherosa Ziehau 
1649c80d176SSepherosa Ziehau #define E1000_WRITE_FLASH_REG(hw, reg, value) \
1659c80d176SSepherosa Ziehau     bus_space_write_4(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
166*74dc3754SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
1679c80d176SSepherosa Ziehau 
1689c80d176SSepherosa Ziehau #define E1000_WRITE_FLASH_REG16(hw, reg, value) \
1699c80d176SSepherosa Ziehau     bus_space_write_2(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
170*74dc3754SSepherosa Ziehau         ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
1719c80d176SSepherosa Ziehau 
1729c80d176SSepherosa Ziehau #endif	/* _DRAGONFLY_OS_H_ */
173