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#include "e1000_mbx.h"
29
30
31
32
33
34
35
36
37
38
39s32 igb_read_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
40{
41 struct e1000_mbx_info *mbx = &hw->mbx;
42 s32 ret_val = -E1000_ERR_MBX;
43
44
45 if (size > mbx->size)
46 size = mbx->size;
47
48 if (mbx->ops.read)
49 ret_val = mbx->ops.read(hw, msg, size, mbx_id);
50
51 return ret_val;
52}
53
54
55
56
57
58
59
60
61
62
63s32 igb_write_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
64{
65 struct e1000_mbx_info *mbx = &hw->mbx;
66 s32 ret_val = 0;
67
68 if (size > mbx->size)
69 ret_val = -E1000_ERR_MBX;
70
71 else if (mbx->ops.write)
72 ret_val = mbx->ops.write(hw, msg, size, mbx_id);
73
74 return ret_val;
75}
76
77
78
79
80
81
82
83
84s32 igb_check_for_msg(struct e1000_hw *hw, u16 mbx_id)
85{
86 struct e1000_mbx_info *mbx = &hw->mbx;
87 s32 ret_val = -E1000_ERR_MBX;
88
89 if (mbx->ops.check_for_msg)
90 ret_val = mbx->ops.check_for_msg(hw, mbx_id);
91
92 return ret_val;
93}
94
95
96
97
98
99
100
101
102s32 igb_check_for_ack(struct e1000_hw *hw, u16 mbx_id)
103{
104 struct e1000_mbx_info *mbx = &hw->mbx;
105 s32 ret_val = -E1000_ERR_MBX;
106
107 if (mbx->ops.check_for_ack)
108 ret_val = mbx->ops.check_for_ack(hw, mbx_id);
109
110 return ret_val;
111}
112
113
114
115
116
117
118
119
120s32 igb_check_for_rst(struct e1000_hw *hw, u16 mbx_id)
121{
122 struct e1000_mbx_info *mbx = &hw->mbx;
123 s32 ret_val = -E1000_ERR_MBX;
124
125 if (mbx->ops.check_for_rst)
126 ret_val = mbx->ops.check_for_rst(hw, mbx_id);
127
128 return ret_val;
129}
130
131
132
133
134
135
136
137
138static s32 igb_poll_for_msg(struct e1000_hw *hw, u16 mbx_id)
139{
140 struct e1000_mbx_info *mbx = &hw->mbx;
141 int countdown = mbx->timeout;
142
143 if (!countdown || !mbx->ops.check_for_msg)
144 goto out;
145
146 while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) {
147 countdown--;
148 if (!countdown)
149 break;
150 udelay(mbx->usec_delay);
151 }
152
153
154 if (!countdown)
155 mbx->timeout = 0;
156out:
157 return countdown ? 0 : -E1000_ERR_MBX;
158}
159
160
161
162
163
164
165
166
167static s32 igb_poll_for_ack(struct e1000_hw *hw, u16 mbx_id)
168{
169 struct e1000_mbx_info *mbx = &hw->mbx;
170 int countdown = mbx->timeout;
171
172 if (!countdown || !mbx->ops.check_for_ack)
173 goto out;
174
175 while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) {
176 countdown--;
177 if (!countdown)
178 break;
179 udelay(mbx->usec_delay);
180 }
181
182
183 if (!countdown)
184 mbx->timeout = 0;
185out:
186 return countdown ? 0 : -E1000_ERR_MBX;
187}
188
189
190
191
192
193
194
195
196
197
198
199static s32 igb_read_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
200{
201 struct e1000_mbx_info *mbx = &hw->mbx;
202 s32 ret_val = -E1000_ERR_MBX;
203
204 if (!mbx->ops.read)
205 goto out;
206
207 ret_val = igb_poll_for_msg(hw, mbx_id);
208
209 if (!ret_val)
210 ret_val = mbx->ops.read(hw, msg, size, mbx_id);
211out:
212 return ret_val;
213}
214
215
216
217
218
219
220
221
222
223
224
225static s32 igb_write_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
226{
227 struct e1000_mbx_info *mbx = &hw->mbx;
228 s32 ret_val = -E1000_ERR_MBX;
229
230
231 if (!mbx->ops.write || !mbx->timeout)
232 goto out;
233
234
235 ret_val = mbx->ops.write(hw, msg, size, mbx_id);
236
237
238 if (!ret_val)
239 ret_val = igb_poll_for_ack(hw, mbx_id);
240out:
241 return ret_val;
242}
243
244static s32 igb_check_for_bit_pf(struct e1000_hw *hw, u32 mask)
245{
246 u32 mbvficr = rd32(E1000_MBVFICR);
247 s32 ret_val = -E1000_ERR_MBX;
248
249 if (mbvficr & mask) {
250 ret_val = 0;
251 wr32(E1000_MBVFICR, mask);
252 }
253
254 return ret_val;
255}
256
257
258
259
260
261
262
263
264static s32 igb_check_for_msg_pf(struct e1000_hw *hw, u16 vf_number)
265{
266 s32 ret_val = -E1000_ERR_MBX;
267
268 if (!igb_check_for_bit_pf(hw, E1000_MBVFICR_VFREQ_VF1 << vf_number)) {
269 ret_val = 0;
270 hw->mbx.stats.reqs++;
271 }
272
273 return ret_val;
274}
275
276
277
278
279
280
281
282
283static s32 igb_check_for_ack_pf(struct e1000_hw *hw, u16 vf_number)
284{
285 s32 ret_val = -E1000_ERR_MBX;
286
287 if (!igb_check_for_bit_pf(hw, E1000_MBVFICR_VFACK_VF1 << vf_number)) {
288 ret_val = 0;
289 hw->mbx.stats.acks++;
290 }
291
292 return ret_val;
293}
294
295
296
297
298
299
300
301
302static s32 igb_check_for_rst_pf(struct e1000_hw *hw, u16 vf_number)
303{
304 u32 vflre = rd32(E1000_VFLRE);
305 s32 ret_val = -E1000_ERR_MBX;
306
307 if (vflre & (1 << vf_number)) {
308 ret_val = 0;
309 wr32(E1000_VFLRE, (1 << vf_number));
310 hw->mbx.stats.rsts++;
311 }
312
313 return ret_val;
314}
315
316
317
318
319
320
321
322
323static s32 igb_obtain_mbx_lock_pf(struct e1000_hw *hw, u16 vf_number)
324{
325 s32 ret_val = -E1000_ERR_MBX;
326 u32 p2v_mailbox;
327
328
329
330 wr32(E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_PFU);
331
332
333 p2v_mailbox = rd32(E1000_P2VMAILBOX(vf_number));
334 if (p2v_mailbox & E1000_P2VMAILBOX_PFU)
335 ret_val = 0;
336
337 return ret_val;
338}
339
340
341
342
343
344
345
346
347
348
349static s32 igb_write_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
350 u16 vf_number)
351{
352 s32 ret_val;
353 u16 i;
354
355
356 ret_val = igb_obtain_mbx_lock_pf(hw, vf_number);
357 if (ret_val)
358 goto out_no_write;
359
360
361 igb_check_for_msg_pf(hw, vf_number);
362 igb_check_for_ack_pf(hw, vf_number);
363
364
365 for (i = 0; i < size; i++)
366 array_wr32(E1000_VMBMEM(vf_number), i, msg[i]);
367
368
369 wr32(E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_STS);
370
371
372 hw->mbx.stats.msgs_tx++;
373
374out_no_write:
375 return ret_val;
376
377}
378
379
380
381
382
383
384
385
386
387
388
389
390static s32 igb_read_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
391 u16 vf_number)
392{
393 s32 ret_val;
394 u16 i;
395
396
397 ret_val = igb_obtain_mbx_lock_pf(hw, vf_number);
398 if (ret_val)
399 goto out_no_read;
400
401
402 for (i = 0; i < size; i++)
403 msg[i] = array_rd32(E1000_VMBMEM(vf_number), i);
404
405
406 wr32(E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_ACK);
407
408
409 hw->mbx.stats.msgs_rx++;
410
411out_no_read:
412 return ret_val;
413}
414
415
416
417
418
419
420
421s32 igb_init_mbx_params_pf(struct e1000_hw *hw)
422{
423 struct e1000_mbx_info *mbx = &hw->mbx;
424
425 if (hw->mac.type == e1000_82576) {
426 mbx->timeout = 0;
427 mbx->usec_delay = 0;
428
429 mbx->size = E1000_VFMAILBOX_SIZE;
430
431 mbx->ops.read = igb_read_mbx_pf;
432 mbx->ops.write = igb_write_mbx_pf;
433 mbx->ops.read_posted = igb_read_posted_mbx;
434 mbx->ops.write_posted = igb_write_posted_mbx;
435 mbx->ops.check_for_msg = igb_check_for_msg_pf;
436 mbx->ops.check_for_ack = igb_check_for_ack_pf;
437 mbx->ops.check_for_rst = igb_check_for_rst_pf;
438
439 mbx->stats.msgs_tx = 0;
440 mbx->stats.msgs_rx = 0;
441 mbx->stats.reqs = 0;
442 mbx->stats.acks = 0;
443 mbx->stats.rsts = 0;
444 }
445
446 return 0;
447}
448
449