summaryrefslogtreecommitdiff
path: root/drivers/net/wireless/realtek/rtw88/hci.h
blob: 2cba327e6218f171e103ac664c769d262ea9ae0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
/* Copyright(c) 2018-2019  Realtek Corporation
 */

#ifndef	__RTW_HCI_H__
#define __RTW_HCI_H__

/* ops for PCI, USB and SDIO */
struct rtw_hci_ops {
	int (*tx_write)(struct rtw_dev *rtwdev,
			struct rtw_tx_pkt_info *pkt_info,
			struct sk_buff *skb);
	void (*tx_kick_off)(struct rtw_dev *rtwdev);
	int (*setup)(struct rtw_dev *rtwdev);
	int (*start)(struct rtw_dev *rtwdev);
	void (*stop)(struct rtw_dev *rtwdev);
	void (*deep_ps)(struct rtw_dev *rtwdev, bool enter);
	void (*link_ps)(struct rtw_dev *rtwdev, bool enter);
	void (*interface_cfg)(struct rtw_dev *rtwdev);

	int (*write_data_rsvd_page)(struct rtw_dev *rtwdev, u8 *buf, u32 size);
	int (*write_data_h2c)(struct rtw_dev *rtwdev, u8 *buf, u32 size);

	u8 (*read8)(struct rtw_dev *rtwdev, u32 addr);
	u16 (*read16)(struct rtw_dev *rtwdev, u32 addr);
	u32 (*read32)(struct rtw_dev *rtwdev, u32 addr);
	void (*write8)(struct rtw_dev *rtwdev, u32 addr, u8 val);
	void (*write16)(struct rtw_dev *rtwdev, u32 addr, u16 val);
	void (*write32)(struct rtw_dev *rtwdev, u32 addr, u32 val);
};

static inline int rtw_hci_tx_write(struct rtw_dev *rtwdev,
				   struct rtw_tx_pkt_info *pkt_info,
				   struct sk_buff *skb)
{
	return rtwdev->hci.ops->tx_write(rtwdev, pkt_info, skb);
}

static inline void rtw_hci_tx_kick_off(struct rtw_dev *rtwdev)
{
	return rtwdev->hci.ops->tx_kick_off(rtwdev);
}

static inline int rtw_hci_setup(struct rtw_dev *rtwdev)
{
	return rtwdev->hci.ops->setup(rtwdev);
}

static inline int rtw_hci_start(struct rtw_dev *rtwdev)
{
	return rtwdev->hci.ops->start(rtwdev);
}

static inline void rtw_hci_stop(struct rtw_dev *rtwdev)
{
	rtwdev->hci.ops->stop(rtwdev);
}

static inline void rtw_hci_deep_ps(struct rtw_dev *rtwdev, bool enter)
{
	rtwdev->hci.ops->deep_ps(rtwdev, enter);
}

static inline void rtw_hci_link_ps(struct rtw_dev *rtwdev, bool enter)
{
	rtwdev->hci.ops->link_ps(rtwdev, enter);
}

static inline void rtw_hci_interface_cfg(struct rtw_dev *rtwdev)
{
	rtwdev->hci.ops->interface_cfg(rtwdev);
}

static inline int
rtw_hci_write_data_rsvd_page(struct rtw_dev *rtwdev, u8 *buf, u32 size)
{
	return rtwdev->hci.ops->write_data_rsvd_page(rtwdev, buf, size);
}

static inline int
rtw_hci_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)
{
	return rtwdev->hci.ops->write_data_h2c(rtwdev, buf, size);
}

static inline u8 rtw_read8(struct rtw_dev *rtwdev, u32 addr)
{
	return rtwdev->hci.ops->read8(rtwdev, addr);
}

static inline u16 rtw_read16(struct rtw_dev *rtwdev, u32 addr)
{
	return rtwdev->hci.ops->read16(rtwdev, addr);
}

static inline u32 rtw_read32(struct rtw_dev *rtwdev, u32 addr)
{
	return rtwdev->hci.ops->read32(rtwdev, addr);
}

static inline void rtw_write8(struct rtw_dev *rtwdev, u32 addr, u8 val)
{
	rtwdev->hci.ops->write8(rtwdev, addr, val);
}

static inline void rtw_write16(struct rtw_dev *rtwdev, u32 addr, u16 val)
{
	rtwdev->hci.ops->write16(rtwdev, addr, val);
}

static inline void rtw_write32(struct rtw_dev *rtwdev, u32 addr, u32 val)
{
	rtwdev->hci.ops->write32(rtwdev, addr, val);
}

static inline void rtw_write8_set(struct rtw_dev *rtwdev, u32 addr, u8 bit)
{
	u8 val;

	val = rtw_read8(rtwdev, addr);
	rtw_write8(rtwdev, addr, val | bit);
}

static inline void rtw_write16_set(struct rtw_dev *rtwdev, u32 addr, u16 bit)
{
	u16 val;

	val = rtw_read16(rtwdev, addr);
	rtw_write16(rtwdev, addr, val | bit);
}

static inline void rtw_write32_set(struct rtw_dev *rtwdev, u32 addr, u32 bit)
{
	u32 val;

	val = rtw_read32(rtwdev, addr);
	rtw_write32(rtwdev, addr, val | bit);
}

static inline void rtw_write8_clr(struct rtw_dev *rtwdev, u32 addr, u8 bit)
{
	u8 val;

	val = rtw_read8(rtwdev, addr);
	rtw_write8(rtwdev, addr, val & ~bit);
}

static inline void rtw_write16_clr(struct rtw_dev *rtwdev, u32 addr, u16 bit)
{
	u16 val;

	val = rtw_read16(rtwdev, addr);
	rtw_write16(rtwdev, addr, val & ~bit);
}

static inline void rtw_write32_clr(struct rtw_dev *rtwdev, u32 addr, u32 bit)
{
	u32 val;

	val = rtw_read32(rtwdev, addr);
	rtw_write32(rtwdev, addr, val & ~bit);
}

static inline u32
rtw_read_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
	    u32 addr, u32 mask)
{
	unsigned long flags;
	u32 val;

	spin_lock_irqsave(&rtwdev->rf_lock, flags);
	val = rtwdev->chip->ops->read_rf(rtwdev, rf_path, addr, mask);
	spin_unlock_irqrestore(&rtwdev->rf_lock, flags);

	return val;
}

static inline void
rtw_write_rf(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
	     u32 addr, u32 mask, u32 data)
{
	unsigned long flags;

	spin_lock_irqsave(&rtwdev->rf_lock, flags);
	rtwdev->chip->ops->write_rf(rtwdev, rf_path, addr, mask, data);
	spin_unlock_irqrestore(&rtwdev->rf_lock, flags);
}

static inline u32
rtw_read32_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask)
{
	u32 shift = __ffs(mask);
	u32 orig;
	u32 ret;

	orig = rtw_read32(rtwdev, addr);
	ret = (orig & mask) >> shift;

	return ret;
}

static inline u16
rtw_read16_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask)
{
	u32 shift = __ffs(mask);
	u32 orig;
	u32 ret;

	orig = rtw_read16(rtwdev, addr);
	ret = (orig & mask) >> shift;

	return ret;
}

static inline u8
rtw_read8_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask)
{
	u32 shift = __ffs(mask);
	u32 orig;
	u32 ret;

	orig = rtw_read8(rtwdev, addr);
	ret = (orig & mask) >> shift;

	return ret;
}

static inline void
rtw_write32_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u32 data)
{
	u32 shift = __ffs(mask);
	u32 orig;
	u32 set;

	WARN(addr & 0x3, "should be 4-byte aligned, addr = 0x%08x\n", addr);

	orig = rtw_read32(rtwdev, addr);
	set = (orig & ~mask) | ((data << shift) & mask);
	rtw_write32(rtwdev, addr, set);
}

static inline void
rtw_write8_mask(struct rtw_dev *rtwdev, u32 addr, u32 mask, u8 data)
{
	u32 shift;
	u8 orig, set;

	mask &= 0xff;
	shift = __ffs(mask);

	orig = rtw_read8(rtwdev, addr);
	set = (orig & ~mask) | ((data << shift) & mask);
	rtw_write8(rtwdev, addr, set);
}

static inline enum rtw_hci_type rtw_hci_type(struct rtw_dev *rtwdev)
{
	return rtwdev->hci.type;
}

#endif