xref: /linux/drivers/net/ethernet/intel/ice/ice_osdep.h (revision 9410645520e9b820069761f3450ef6661418e279)
17ec59eeaSAnirudh Venkataramanan /* SPDX-License-Identifier: GPL-2.0 */
27ec59eeaSAnirudh Venkataramanan /* Copyright (c) 2018, Intel Corporation. */
37ec59eeaSAnirudh Venkataramanan 
47ec59eeaSAnirudh Venkataramanan #ifndef _ICE_OSDEP_H_
57ec59eeaSAnirudh Venkataramanan #define _ICE_OSDEP_H_
67ec59eeaSAnirudh Venkataramanan 
77ec59eeaSAnirudh Venkataramanan #include <linux/types.h>
8649c87c6SJacob Keller #include <linux/ctype.h>
9649c87c6SJacob Keller #include <linux/delay.h>
107ec59eeaSAnirudh Venkataramanan #include <linux/io.h>
11649c87c6SJacob Keller #include <linux/bitops.h>
12649c87c6SJacob Keller #include <linux/ethtool.h>
13649c87c6SJacob Keller #include <linux/etherdevice.h>
14649c87c6SJacob Keller #include <linux/if_ether.h>
155f6df173SJacob Keller #include <linux/iopoll.h>
16649c87c6SJacob Keller #include <linux/pci_ids.h>
177ec59eeaSAnirudh Venkataramanan #ifndef CONFIG_64BIT
187ec59eeaSAnirudh Venkataramanan #include <linux/io-64-nonatomic-lo-hi.h>
197ec59eeaSAnirudh Venkataramanan #endif
20bc42afa9SBrett Creeley #include <net/udp_tunnel.h>
217ec59eeaSAnirudh Venkataramanan 
227ec59eeaSAnirudh Venkataramanan #define wr32(a, reg, value)	writel((value), ((a)->hw_addr + (reg)))
237ec59eeaSAnirudh Venkataramanan #define rd32(a, reg)		readl((a)->hw_addr + (reg))
247ec59eeaSAnirudh Venkataramanan #define wr64(a, reg, value)	writeq((value), ((a)->hw_addr + (reg)))
257ec59eeaSAnirudh Venkataramanan #define rd64(a, reg)		readq((a)->hw_addr + (reg))
267ec59eeaSAnirudh Venkataramanan 
275f6df173SJacob Keller #define rd32_poll_timeout(a, addr, val, cond, delay_us, timeout_us) \
285f6df173SJacob Keller 	read_poll_timeout(rd32, val, cond, delay_us, timeout_us, false, a, addr)
295f6df173SJacob Keller 
30f31e4b6fSAnirudh Venkataramanan #define ice_flush(a)		rd32((a), GLGEN_STAT)
3175428f53SJesse Brandeburg #define ICE_M(m, s)		((m ## U) << (s))
327ec59eeaSAnirudh Venkataramanan 
337ec59eeaSAnirudh Venkataramanan struct ice_dma_mem {
347ec59eeaSAnirudh Venkataramanan 	void *va;
357ec59eeaSAnirudh Venkataramanan 	dma_addr_t pa;
367ec59eeaSAnirudh Venkataramanan 	size_t size;
377ec59eeaSAnirudh Venkataramanan };
387ec59eeaSAnirudh Venkataramanan 
39649c87c6SJacob Keller struct ice_hw;
40649c87c6SJacob Keller struct device *ice_hw_to_dev(struct ice_hw *hw);
417ec59eeaSAnirudh Venkataramanan 
427ec59eeaSAnirudh Venkataramanan #ifdef CONFIG_DYNAMIC_DEBUG
437ec59eeaSAnirudh Venkataramanan #define ice_debug(hw, type, fmt, args...) \
447ec59eeaSAnirudh Venkataramanan 	dev_dbg(ice_hw_to_dev(hw), fmt, ##args)
457ec59eeaSAnirudh Venkataramanan 
46*74ce564aSPrzemek Kitszel #define _ice_debug_array(hw, type, prefix, rowsize, groupsize, buf, len) \
47*74ce564aSPrzemek Kitszel 	print_hex_dump_debug(prefix, DUMP_PREFIX_OFFSET,		 \
48*74ce564aSPrzemek Kitszel 			     rowsize, groupsize, buf, len, false)
49*74ce564aSPrzemek Kitszel #else /* CONFIG_DYNAMIC_DEBUG */
507ec59eeaSAnirudh Venkataramanan #define ice_debug(hw, type, fmt, args...)			\
517ec59eeaSAnirudh Venkataramanan do {								\
527ec59eeaSAnirudh Venkataramanan 	if ((type) & (hw)->debug_mask)				\
537ec59eeaSAnirudh Venkataramanan 		dev_info(ice_hw_to_dev(hw), fmt, ##args);	\
547ec59eeaSAnirudh Venkataramanan } while (0)
557ec59eeaSAnirudh Venkataramanan 
567ec59eeaSAnirudh Venkataramanan #ifdef DEBUG
57*74ce564aSPrzemek Kitszel #define _ice_debug_array(hw, type, prefix, rowsize, groupsize, buf, len) \
587ec59eeaSAnirudh Venkataramanan do {								\
597ec59eeaSAnirudh Venkataramanan 	if ((type) & (hw)->debug_mask)				\
60*74ce564aSPrzemek Kitszel 		print_hex_dump_debug(prefix, DUMP_PREFIX_OFFSET,\
617ec59eeaSAnirudh Venkataramanan 				     rowsize, groupsize, buf,	\
627ec59eeaSAnirudh Venkataramanan 				     len, false);		\
637ec59eeaSAnirudh Venkataramanan } while (0)
64*74ce564aSPrzemek Kitszel #else /* DEBUG */
65*74ce564aSPrzemek Kitszel #define _ice_debug_array(hw, type, prefix, rowsize, groupsize, buf, len) \
667ec59eeaSAnirudh Venkataramanan do {								\
677ec59eeaSAnirudh Venkataramanan 	struct ice_hw *hw_l = hw;				\
687ec59eeaSAnirudh Venkataramanan 	if ((type) & (hw_l)->debug_mask) {			\
697ec59eeaSAnirudh Venkataramanan 		u16 len_l = len;				\
707ec59eeaSAnirudh Venkataramanan 		u8 *buf_l = buf;				\
717ec59eeaSAnirudh Venkataramanan 		int i;						\
727ec59eeaSAnirudh Venkataramanan 		for (i = 0; i < (len_l - 16); i += 16)		\
737ec59eeaSAnirudh Venkataramanan 			ice_debug(hw_l, type, "0x%04X  %16ph\n",\
747ec59eeaSAnirudh Venkataramanan 				  i, ((buf_l) + i));		\
757ec59eeaSAnirudh Venkataramanan 		if (i < len_l)					\
767ec59eeaSAnirudh Venkataramanan 			ice_debug(hw_l, type, "0x%04X  %*ph\n", \
777ec59eeaSAnirudh Venkataramanan 				  i, ((len_l) - i), ((buf_l) + i));\
787ec59eeaSAnirudh Venkataramanan 	}							\
797ec59eeaSAnirudh Venkataramanan } while (0)
807ec59eeaSAnirudh Venkataramanan #endif /* DEBUG */
817ec59eeaSAnirudh Venkataramanan #endif /* CONFIG_DYNAMIC_DEBUG */
827ec59eeaSAnirudh Venkataramanan 
83*74ce564aSPrzemek Kitszel #define ice_debug_array(hw, type, rowsize, groupsize, buf, len) \
84*74ce564aSPrzemek Kitszel 	_ice_debug_array(hw, type, KBUILD_MODNAME, rowsize, groupsize, buf, len)
85*74ce564aSPrzemek Kitszel 
86*74ce564aSPrzemek Kitszel #define ice_debug_array_w_prefix(hw, type, prefix, buf, len) \
87*74ce564aSPrzemek Kitszel 	_ice_debug_array(hw, type, prefix, 16, 1, buf, len)
88*74ce564aSPrzemek Kitszel 
897ec59eeaSAnirudh Venkataramanan #endif /* _ICE_OSDEP_H_ */
90