xref: /illumos-gate/usr/src/uts/common/io/cxgbe/shared/osdep.h (revision 4b9db4f6425b1a08fca4390f446072c4a6aae8d5)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source. A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * This file is part of the Chelsio T4 support code.
14  *
15  * Copyright (C) 2010-2013 Chelsio Communications.  All rights reserved.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE.  See the LICENSE file included in this
20  * release for licensing terms and conditions.
21  */
22 
23 /*
24  * Copyright 2024 Oxide Computer Company
25  */
26 
27 #ifndef __CXGBE_OSDEP_H
28 #define	__CXGBE_OSDEP_H
29 
30 #include <sys/ddi.h>
31 #include <sys/sunddi.h>
32 #include <sys/byteorder.h>
33 #include <sys/cmn_err.h>
34 #include <sys/pcie.h>
35 #include <sys/sysmacros.h>
36 #include <sys/inttypes.h>
37 #include <sys/stdbool.h>
38 #include <sys/sysmacros.h>
39 #include <sys/mutex.h>
40 
41 
42 #define	CH_DUMP_MBOX(adap, mbox, data_reg, size)	do {} while (0)
43 
44 #define	PCI_VENDOR_ID		0x00
45 #define	PCI_DEVICE_ID		0x02
46 
47 #define	PCI_BASE_ADDRESS_0	0x10
48 #define	PCI_BASE_ADDRESS_1	0x14
49 #define	PCI_BASE_ADDRESS_2	0x18
50 #define	PCI_BASE_ADDRESS_MEM_MASK	(~0x0fUL)
51 
52 #define	PCI_CAP_ID_EXP		PCI_CAP_ID_PCI_E
53 #define	PCI_EXP_DEVCTL		PCIE_DEVCTL
54 #define	PCI_EXP_DEVCTL_PAYLOAD	PCIE_DEVCTL_MAX_PAYLOAD_MASK
55 #define	PCI_EXP_DEVCTL_READRQ	PCIE_DEVCTL_MAX_READ_REQ_MASK
56 #define	PCI_EXP_LNKCTL		PCIE_LINKCTL
57 #define	PCI_EXP_LNKSTA		PCIE_LINKSTS
58 #define	PCI_EXP_LNKSTA_CLS	PCIE_LINKSTS_SPEED_MASK
59 #define	PCI_EXP_LNKSTA_NLW	PCIE_LINKSTS_NEG_WIDTH_MASK
60 #define	PCI_EXP_DEVCTL2		0x28
61 
62 #define	PCI_VPD_ADDR	2
63 #define	PCI_VPD_ADDR_F	0x8000
64 #define	PCI_VPD_DATA	4
65 
66 #define	__devinit
67 #define	DIV_ROUND_UP(x, y) howmany(x, y)
68 
69 #define	udelay(x) drv_usecwait(x)
70 #define	msleep(x) delay(drv_usectohz(1000ULL * (x)))
71 #define	mdelay(x) drv_usecwait(1000UL * (x))
72 
73 #define	le16_to_cpu(x) LE_16((uint16_t)(x))
74 #define	le32_to_cpu(x) LE_32((uint32_t)(x))
75 #define	le64_to_cpu(x) LE_64((uint64_t)(x))
76 #define	cpu_to_le16(x) LE_16((uint16_t)(x))
77 #define	cpu_to_le32(x) LE_32((uint32_t)(x))
78 #define	cpu_to_le64(x) LE_64((uint64_t)(x))
79 #define	be16_to_cpu(x) BE_16((uint16_t)(x))
80 #define	be32_to_cpu(x) BE_32((uint32_t)(x))
81 #define	be64_to_cpu(x) BE_64((uint64_t)(x))
82 #define	cpu_to_be16(x) BE_16((uint16_t)(x))
83 #define	cpu_to_be32(x) BE_32((uint32_t)(x))
84 #define	cpu_to_be64(x) BE_64((uint64_t)(x))
85 #define	swab32(x) BSWAP_32(x)
86 
87 typedef uint8_t 	u8;
88 typedef uint16_t 	u16;
89 typedef uint32_t 	u32;
90 typedef uint64_t 	u64;
91 
92 typedef uint8_t		__u8;
93 typedef uint16_t	__u16;
94 typedef uint32_t	__u32;
95 typedef uint64_t	__u64;
96 typedef uint8_t		__be8;
97 typedef uint16_t	__be16;
98 typedef uint32_t	__be32;
99 typedef uint64_t	__be64;
100 
101 typedef uint32_t	__le32;
102 
103 typedef int8_t		s8;
104 typedef int16_t		s16;
105 typedef int32_t		s32;
106 typedef int64_t		s64;
107 
108 #if defined(__sparc)
109 #define	__BIG_ENDIAN_BITFIELD
110 #define	PAGE_SIZE 8192
111 #define	PAGE_SHIFT 13
112 #else
113 #define	__LITTLE_ENDIAN_BITFIELD
114 #define	PAGE_SIZE 4096
115 #define	PAGE_SHIFT 12
116 #endif
117 
118 #define	ETH_ALEN		6
119 
120 #define	isspace(x) ((x) == ' ' || (x) == '\t')
121 
122 #ifdef _KERNEL
123 
124 #define	t4_os_alloc(_size)	kmem_alloc(_size, KM_SLEEP)
125 #define	fls(x) ddi_fls(x)
126 
127 static inline int
128 ilog2(long x)
129 {
130 	return (ddi_fls(x) - 1);
131 }
132 
133 typedef kmutex_t t4_os_lock_t;
134 
135 static inline void
136 t4_os_lock(t4_os_lock_t *lock)
137 {
138 	mutex_enter(lock);
139 }
140 
141 static inline void
142 t4_os_unlock(t4_os_lock_t *lock)
143 {
144 	mutex_exit(lock);
145 }
146 
147 #endif /* _KERNEL */
148 
149 #endif /* __CXGBE_OSDEP_H */
150