1
2
3
4 #ifndef _FM10K_MBX_H_
5 #define _FM10K_MBX_H_
6
7
8 struct fm10k_mbx_info;
9
10 #include "fm10k_type.h"
11 #include "fm10k_tlv.h"
12
13
14 #define FM10K_MBMEM(_n) ((_n) + 0x18000)
15 #define FM10K_MBMEM_VF(_n, _m) (((_n) * 0x10) + (_m) + 0x18000)
16 #define FM10K_MBMEM_SM(_n) ((_n) + 0x18400)
17 #define FM10K_MBMEM_PF(_n) ((_n) + 0x18600)
18
19 #define FM10K_MBMEM_PF_XOR (FM10K_MBMEM_SM(0) ^ FM10K_MBMEM_PF(0))
20 #define FM10K_MBX(_n) ((_n) + 0x18800)
21 #define FM10K_MBX_REQ 0x00000002
22 #define FM10K_MBX_ACK 0x00000004
23 #define FM10K_MBX_REQ_INTERRUPT 0x00000008
24 #define FM10K_MBX_ACK_INTERRUPT 0x00000010
25 #define FM10K_MBX_INTERRUPT_ENABLE 0x00000020
26 #define FM10K_MBX_INTERRUPT_DISABLE 0x00000040
27 #define FM10K_MBX_GLOBAL_REQ_INTERRUPT 0x00000200
28 #define FM10K_MBX_GLOBAL_ACK_INTERRUPT 0x00000400
29 #define FM10K_MBICR(_n) ((_n) + 0x18840)
30 #define FM10K_GMBX 0x18842
31
32
33 #define FM10K_VFMBX 0x00010
34 #define FM10K_VFMBMEM(_n) ((_n) + 0x00020)
35 #define FM10K_VFMBMEM_LEN 16
36 #define FM10K_VFMBMEM_VF_XOR (FM10K_VFMBMEM_LEN / 2)
37
38
39 #define FM10K_MBX_DISCONNECT_TIMEOUT 500
40 #define FM10K_MBX_POLL_DELAY 19
41 #define FM10K_MBX_INT_DELAY 20
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 enum fm10k_mbx_state {
81 FM10K_STATE_CLOSED,
82 FM10K_STATE_CONNECT,
83 FM10K_STATE_OPEN,
84 FM10K_STATE_DISCONNECT,
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 #define FM10K_MSG_HDR_MASK(name) \
122 ((0x1u << FM10K_MSG_##name##_SIZE) - 1)
123 #define FM10K_MSG_HDR_FIELD_SET(value, name) \
124 (((u32)(value) & FM10K_MSG_HDR_MASK(name)) << FM10K_MSG_##name##_SHIFT)
125 #define FM10K_MSG_HDR_FIELD_GET(value, name) \
126 ((u16)((value) >> FM10K_MSG_##name##_SHIFT) & FM10K_MSG_HDR_MASK(name))
127
128
129 #define FM10K_MSG_TYPE_SHIFT 0
130 #define FM10K_MSG_TYPE_SIZE 4
131 #define FM10K_MSG_TAIL_SHIFT 4
132 #define FM10K_MSG_TAIL_SIZE 4
133 #define FM10K_MSG_HEAD_SHIFT 8
134 #define FM10K_MSG_HEAD_SIZE 4
135 #define FM10K_MSG_RSVD0_SHIFT 12
136 #define FM10K_MSG_RSVD0_SIZE 4
137
138
139 #define FM10K_MSG_CRC_SHIFT 16
140 #define FM10K_MSG_CRC_SIZE 16
141
142
143 #define FM10K_MSG_CONNECT_SIZE_SHIFT 16
144 #define FM10K_MSG_CONNECT_SIZE_SIZE 16
145
146
147 #define FM10K_MSG_ERR_NO_SHIFT 16
148 #define FM10K_MSG_ERR_NO_SIZE 16
149
150 enum fm10k_msg_type {
151 FM10K_MSG_DATA = 0x8,
152 FM10K_MSG_CONNECT = 0xC,
153 FM10K_MSG_DISCONNECT = 0xD,
154 FM10K_MSG_ERROR = 0xE,
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 #define FM10K_SM_MBX_VERSION 1
184 #define FM10K_SM_MBX_FIFO_LEN (FM10K_MBMEM_PF_XOR - 1)
185
186
187 #define FM10K_MSG_SM_TAIL_SHIFT 0
188 #define FM10K_MSG_SM_TAIL_SIZE 12
189 #define FM10K_MSG_SM_VER_SHIFT 12
190 #define FM10K_MSG_SM_VER_SIZE 4
191 #define FM10K_MSG_SM_HEAD_SHIFT 16
192 #define FM10K_MSG_SM_HEAD_SIZE 12
193 #define FM10K_MSG_SM_ERR_SHIFT 28
194 #define FM10K_MSG_SM_ERR_SIZE 4
195
196
197
198
199
200
201
202 #define FM10K_MBX_ERR(_n) ((_n) - 512)
203 #define FM10K_MBX_ERR_NO_MBX FM10K_MBX_ERR(0x01)
204 #define FM10K_MBX_ERR_NO_SPACE FM10K_MBX_ERR(0x03)
205 #define FM10K_MBX_ERR_TAIL FM10K_MBX_ERR(0x05)
206 #define FM10K_MBX_ERR_HEAD FM10K_MBX_ERR(0x06)
207 #define FM10K_MBX_ERR_SRC FM10K_MBX_ERR(0x08)
208 #define FM10K_MBX_ERR_TYPE FM10K_MBX_ERR(0x09)
209 #define FM10K_MBX_ERR_SIZE FM10K_MBX_ERR(0x0B)
210 #define FM10K_MBX_ERR_BUSY FM10K_MBX_ERR(0x0C)
211 #define FM10K_MBX_ERR_RSVD0 FM10K_MBX_ERR(0x0E)
212 #define FM10K_MBX_ERR_CRC FM10K_MBX_ERR(0x0F)
213
214 #define FM10K_MBX_CRC_SEED 0xFFFF
215
216 struct fm10k_mbx_ops {
217 s32 (*connect)(struct fm10k_hw *, struct fm10k_mbx_info *);
218 void (*disconnect)(struct fm10k_hw *, struct fm10k_mbx_info *);
219 bool (*rx_ready)(struct fm10k_mbx_info *);
220 bool (*tx_ready)(struct fm10k_mbx_info *, u16);
221 bool (*tx_complete)(struct fm10k_mbx_info *);
222 s32 (*enqueue_tx)(struct fm10k_hw *, struct fm10k_mbx_info *,
223 const u32 *);
224 s32 (*process)(struct fm10k_hw *, struct fm10k_mbx_info *);
225 s32 (*register_handlers)(struct fm10k_mbx_info *,
226 const struct fm10k_msg_data *);
227 };
228
229 struct fm10k_mbx_fifo {
230 u32 *buffer;
231 u16 head;
232 u16 tail;
233 u16 size;
234 };
235
236
237 #define FM10K_MBX_TX_BUFFER_SIZE 512
238 #define FM10K_MBX_RX_BUFFER_SIZE 128
239 #define FM10K_MBX_BUFFER_SIZE \
240 (FM10K_MBX_TX_BUFFER_SIZE + FM10K_MBX_RX_BUFFER_SIZE)
241
242
243 #define FM10K_MBX_MSG_MAX_SIZE \
244 ((FM10K_MBX_TX_BUFFER_SIZE - 1) & (FM10K_MBX_RX_BUFFER_SIZE - 1))
245 #define FM10K_VFMBX_MSG_MTU ((FM10K_VFMBMEM_LEN / 2) - 1)
246
247 #define FM10K_MBX_INIT_TIMEOUT 2000
248 #define FM10K_MBX_INIT_DELAY 500
249
250 struct fm10k_mbx_info {
251
252 struct fm10k_mbx_ops ops;
253 const struct fm10k_msg_data *msg_data;
254
255
256 struct fm10k_mbx_fifo rx;
257 struct fm10k_mbx_fifo tx;
258
259
260 u32 timeout;
261 u32 udelay;
262
263
264 u32 mbx_reg, mbmem_reg, mbx_lock, mbx_hdr;
265 u16 max_size, mbmem_len;
266 u16 tail, tail_len, pulled;
267 u16 head, head_len, pushed;
268 u16 local, remote;
269 enum fm10k_mbx_state state;
270
271
272 s32 test_result;
273
274
275 u64 tx_busy;
276 u64 tx_dropped;
277 u64 tx_messages;
278 u64 tx_dwords;
279 u64 tx_mbmem_pulled;
280 u64 rx_messages;
281 u64 rx_dwords;
282 u64 rx_mbmem_pushed;
283 u64 rx_parse_err;
284
285
286 u32 buffer[FM10K_MBX_BUFFER_SIZE];
287 };
288
289 s32 fm10k_pfvf_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
290 const struct fm10k_msg_data *, u8);
291 s32 fm10k_sm_mbx_init(struct fm10k_hw *, struct fm10k_mbx_info *,
292 const struct fm10k_msg_data *);
293
294 #endif