xref: /linux/drivers/net/ethernet/intel/ice/ice_osdep.h (revision 6015fb905d89063231ed33bc15be19ef0fc339b8)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2018, Intel Corporation. */
3 
4 #ifndef _ICE_OSDEP_H_
5 #define _ICE_OSDEP_H_
6 
7 #include <linux/types.h>
8 #include <linux/io.h>
9 #ifndef CONFIG_64BIT
10 #include <linux/io-64-nonatomic-lo-hi.h>
11 #endif
12 #include <net/udp_tunnel.h>
13 
14 #define wr32(a, reg, value)	writel((value), ((a)->hw_addr + (reg)))
15 #define rd32(a, reg)		readl((a)->hw_addr + (reg))
16 #define wr64(a, reg, value)	writeq((value), ((a)->hw_addr + (reg)))
17 #define rd64(a, reg)		readq((a)->hw_addr + (reg))
18 
19 #define ice_flush(a)		rd32((a), GLGEN_STAT)
20 #define ICE_M(m, s)		((m) << (s))
21 
22 struct ice_dma_mem {
23 	void *va;
24 	dma_addr_t pa;
25 	size_t size;
26 };
27 
28 #define ice_hw_to_dev(ptr)	\
29 	(&(container_of((ptr), struct ice_pf, hw))->pdev->dev)
30 
31 #ifdef CONFIG_DYNAMIC_DEBUG
32 #define ice_debug(hw, type, fmt, args...) \
33 	dev_dbg(ice_hw_to_dev(hw), fmt, ##args)
34 
35 #define ice_debug_array(hw, type, rowsize, groupsize, buf, len) \
36 	print_hex_dump_debug(KBUILD_MODNAME " ",		\
37 			     DUMP_PREFIX_OFFSET, rowsize,	\
38 			     groupsize, buf, len, false)
39 #else
40 #define ice_debug(hw, type, fmt, args...)			\
41 do {								\
42 	if ((type) & (hw)->debug_mask)				\
43 		dev_info(ice_hw_to_dev(hw), fmt, ##args);	\
44 } while (0)
45 
46 #ifdef DEBUG
47 #define ice_debug_array(hw, type, rowsize, groupsize, buf, len) \
48 do {								\
49 	if ((type) & (hw)->debug_mask)				\
50 		print_hex_dump_debug(KBUILD_MODNAME,		\
51 				     DUMP_PREFIX_OFFSET,	\
52 				     rowsize, groupsize, buf,	\
53 				     len, false);		\
54 } while (0)
55 #else
56 #define ice_debug_array(hw, type, rowsize, groupsize, buf, len) \
57 do {								\
58 	struct ice_hw *hw_l = hw;				\
59 	if ((type) & (hw_l)->debug_mask) {			\
60 		u16 len_l = len;				\
61 		u8 *buf_l = buf;				\
62 		int i;						\
63 		for (i = 0; i < (len_l - 16); i += 16)		\
64 			ice_debug(hw_l, type, "0x%04X  %16ph\n",\
65 				  i, ((buf_l) + i));		\
66 		if (i < len_l)					\
67 			ice_debug(hw_l, type, "0x%04X  %*ph\n", \
68 				  i, ((len_l) - i), ((buf_l) + i));\
69 	}							\
70 } while (0)
71 #endif /* DEBUG */
72 #endif /* CONFIG_DYNAMIC_DEBUG */
73 
74 #endif /* _ICE_OSDEP_H_ */
75