Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2001-2020 Intel Corporation
3 : : */
4 : :
5 : : #include "e1000_mbx.h"
6 : :
7 : : /**
8 : : * e1000_null_mbx_check_for_flag - No-op function, return 0
9 : : * @hw: pointer to the HW structure
10 : : * @mbx_id: id of mailbox to read
11 : : **/
12 : 0 : STATIC s32 e1000_null_mbx_check_for_flag(struct e1000_hw E1000_UNUSEDARG *hw,
13 : : u16 E1000_UNUSEDARG mbx_id)
14 : : {
15 : 0 : DEBUGFUNC("e1000_null_mbx_check_flag");
16 : : UNREFERENCED_2PARAMETER(hw, mbx_id);
17 : :
18 : 0 : return E1000_SUCCESS;
19 : : }
20 : :
21 : : /**
22 : : * e1000_null_mbx_transact - No-op function, return 0
23 : : * @hw: pointer to the HW structure
24 : : * @msg: The message buffer
25 : : * @size: Length of buffer
26 : : * @mbx_id: id of mailbox to read
27 : : **/
28 : 0 : STATIC s32 e1000_null_mbx_transact(struct e1000_hw E1000_UNUSEDARG *hw,
29 : : u32 E1000_UNUSEDARG *msg,
30 : : u16 E1000_UNUSEDARG size,
31 : : u16 E1000_UNUSEDARG mbx_id)
32 : : {
33 : 0 : DEBUGFUNC("e1000_null_mbx_rw_msg");
34 : : UNREFERENCED_4PARAMETER(hw, msg, size, mbx_id);
35 : :
36 : 0 : return E1000_SUCCESS;
37 : : }
38 : :
39 : : /**
40 : : * e1000_read_mbx - Reads a message from the mailbox
41 : : * @hw: pointer to the HW structure
42 : : * @msg: The message buffer
43 : : * @size: Length of buffer
44 : : * @mbx_id: id of mailbox to read
45 : : *
46 : : * returns SUCCESS if it successfully read message from buffer
47 : : **/
48 : 0 : s32 e1000_read_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
49 : : {
50 : : struct e1000_mbx_info *mbx = &hw->mbx;
51 : : s32 ret_val = -E1000_ERR_MBX;
52 : :
53 : 0 : DEBUGFUNC("e1000_read_mbx");
54 : :
55 : : /* limit read to size of mailbox */
56 : 0 : if (size > mbx->size)
57 : : size = mbx->size;
58 : :
59 [ # # ]: 0 : if (mbx->ops.read)
60 : 0 : ret_val = mbx->ops.read(hw, msg, size, mbx_id);
61 : :
62 : 0 : return ret_val;
63 : : }
64 : :
65 : : /**
66 : : * e1000_write_mbx - Write a message to the mailbox
67 : : * @hw: pointer to the HW structure
68 : : * @msg: The message buffer
69 : : * @size: Length of buffer
70 : : * @mbx_id: id of mailbox to write
71 : : *
72 : : * returns SUCCESS if it successfully copied message into the buffer
73 : : **/
74 : 0 : s32 e1000_write_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
75 : : {
76 : : struct e1000_mbx_info *mbx = &hw->mbx;
77 : : s32 ret_val = E1000_SUCCESS;
78 : :
79 : 0 : DEBUGFUNC("e1000_write_mbx");
80 : :
81 [ # # ]: 0 : if (size > mbx->size)
82 : : ret_val = -E1000_ERR_MBX;
83 : :
84 [ # # ]: 0 : else if (mbx->ops.write)
85 : 0 : ret_val = mbx->ops.write(hw, msg, size, mbx_id);
86 : :
87 : 0 : return ret_val;
88 : : }
89 : :
90 : : /**
91 : : * e1000_check_for_msg - checks to see if someone sent us mail
92 : : * @hw: pointer to the HW structure
93 : : * @mbx_id: id of mailbox to check
94 : : *
95 : : * returns SUCCESS if the Status bit was found or else ERR_MBX
96 : : **/
97 : 0 : s32 e1000_check_for_msg(struct e1000_hw *hw, u16 mbx_id)
98 : : {
99 : : struct e1000_mbx_info *mbx = &hw->mbx;
100 : : s32 ret_val = -E1000_ERR_MBX;
101 : :
102 : 0 : DEBUGFUNC("e1000_check_for_msg");
103 : :
104 [ # # ]: 0 : if (mbx->ops.check_for_msg)
105 : 0 : ret_val = mbx->ops.check_for_msg(hw, mbx_id);
106 : :
107 : 0 : return ret_val;
108 : : }
109 : :
110 : : /**
111 : : * e1000_check_for_ack - checks to see if someone sent us ACK
112 : : * @hw: pointer to the HW structure
113 : : * @mbx_id: id of mailbox to check
114 : : *
115 : : * returns SUCCESS if the Status bit was found or else ERR_MBX
116 : : **/
117 : 0 : s32 e1000_check_for_ack(struct e1000_hw *hw, u16 mbx_id)
118 : : {
119 : : struct e1000_mbx_info *mbx = &hw->mbx;
120 : : s32 ret_val = -E1000_ERR_MBX;
121 : :
122 : 0 : DEBUGFUNC("e1000_check_for_ack");
123 : :
124 [ # # ]: 0 : if (mbx->ops.check_for_ack)
125 : 0 : ret_val = mbx->ops.check_for_ack(hw, mbx_id);
126 : :
127 : 0 : return ret_val;
128 : : }
129 : :
130 : : /**
131 : : * e1000_check_for_rst - checks to see if other side has reset
132 : : * @hw: pointer to the HW structure
133 : : * @mbx_id: id of mailbox to check
134 : : *
135 : : * returns SUCCESS if the Status bit was found or else ERR_MBX
136 : : **/
137 : 0 : s32 e1000_check_for_rst(struct e1000_hw *hw, u16 mbx_id)
138 : : {
139 : : struct e1000_mbx_info *mbx = &hw->mbx;
140 : : s32 ret_val = -E1000_ERR_MBX;
141 : :
142 : 0 : DEBUGFUNC("e1000_check_for_rst");
143 : :
144 [ # # ]: 0 : if (mbx->ops.check_for_rst)
145 : 0 : ret_val = mbx->ops.check_for_rst(hw, mbx_id);
146 : :
147 : 0 : return ret_val;
148 : : }
149 : :
150 : : /**
151 : : * e1000_poll_for_msg - Wait for message notification
152 : : * @hw: pointer to the HW structure
153 : : * @mbx_id: id of mailbox to write
154 : : *
155 : : * returns SUCCESS if it successfully received a message notification
156 : : **/
157 : 0 : STATIC s32 e1000_poll_for_msg(struct e1000_hw *hw, u16 mbx_id)
158 : : {
159 : : struct e1000_mbx_info *mbx = &hw->mbx;
160 : 0 : int countdown = mbx->timeout;
161 : :
162 : 0 : DEBUGFUNC("e1000_poll_for_msg");
163 : :
164 [ # # # # ]: 0 : if (!countdown || !mbx->ops.check_for_msg)
165 : 0 : goto out;
166 : :
167 [ # # ]: 0 : while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) {
168 : 0 : countdown--;
169 [ # # ]: 0 : if (!countdown)
170 : : break;
171 : 0 : usec_delay(mbx->usec_delay);
172 : : }
173 : :
174 : : /* if we failed, all future posted messages fail until reset */
175 [ # # ]: 0 : if (!countdown)
176 : 0 : mbx->timeout = 0;
177 : 0 : out:
178 [ # # ]: 0 : return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
179 : : }
180 : :
181 : : /**
182 : : * e1000_poll_for_ack - Wait for message acknowledgement
183 : : * @hw: pointer to the HW structure
184 : : * @mbx_id: id of mailbox to write
185 : : *
186 : : * returns SUCCESS if it successfully received a message acknowledgement
187 : : **/
188 : 0 : STATIC s32 e1000_poll_for_ack(struct e1000_hw *hw, u16 mbx_id)
189 : : {
190 : : struct e1000_mbx_info *mbx = &hw->mbx;
191 : 0 : int countdown = mbx->timeout;
192 : :
193 : 0 : DEBUGFUNC("e1000_poll_for_ack");
194 : :
195 [ # # # # ]: 0 : if (!countdown || !mbx->ops.check_for_ack)
196 : 0 : goto out;
197 : :
198 [ # # ]: 0 : while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) {
199 : 0 : countdown--;
200 [ # # ]: 0 : if (!countdown)
201 : : break;
202 : 0 : usec_delay(mbx->usec_delay);
203 : : }
204 : :
205 : : /* if we failed, all future posted messages fail until reset */
206 [ # # ]: 0 : if (!countdown)
207 : 0 : mbx->timeout = 0;
208 : 0 : out:
209 [ # # ]: 0 : return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
210 : : }
211 : :
212 : : /**
213 : : * e1000_read_posted_mbx - Wait for message notification and receive message
214 : : * @hw: pointer to the HW structure
215 : : * @msg: The message buffer
216 : : * @size: Length of buffer
217 : : * @mbx_id: id of mailbox to write
218 : : *
219 : : * returns SUCCESS if it successfully received a message notification and
220 : : * copied it into the receive buffer.
221 : : **/
222 : 0 : s32 e1000_read_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
223 : : {
224 : : struct e1000_mbx_info *mbx = &hw->mbx;
225 : : s32 ret_val = -E1000_ERR_MBX;
226 : :
227 : 0 : DEBUGFUNC("e1000_read_posted_mbx");
228 : :
229 [ # # ]: 0 : if (!mbx->ops.read)
230 : 0 : goto out;
231 : :
232 : 0 : ret_val = e1000_poll_for_msg(hw, mbx_id);
233 : :
234 : : /* if ack received read message, otherwise we timed out */
235 [ # # ]: 0 : if (!ret_val)
236 : 0 : ret_val = mbx->ops.read(hw, msg, size, mbx_id);
237 : 0 : out:
238 : 0 : return ret_val;
239 : : }
240 : :
241 : : /**
242 : : * e1000_write_posted_mbx - Write a message to the mailbox, wait for ack
243 : : * @hw: pointer to the HW structure
244 : : * @msg: The message buffer
245 : : * @size: Length of buffer
246 : : * @mbx_id: id of mailbox to write
247 : : *
248 : : * returns SUCCESS if it successfully copied message into the buffer and
249 : : * received an ack to that message within delay * timeout period
250 : : **/
251 : 0 : s32 e1000_write_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
252 : : {
253 : : struct e1000_mbx_info *mbx = &hw->mbx;
254 : : s32 ret_val = -E1000_ERR_MBX;
255 : :
256 : 0 : DEBUGFUNC("e1000_write_posted_mbx");
257 : :
258 : : /* exit if either we can't write or there isn't a defined timeout */
259 [ # # # # ]: 0 : if (!mbx->ops.write || !mbx->timeout)
260 : 0 : goto out;
261 : :
262 : : /* send msg */
263 : 0 : ret_val = mbx->ops.write(hw, msg, size, mbx_id);
264 : :
265 : : /* if msg sent wait until we receive an ack */
266 [ # # ]: 0 : if (!ret_val)
267 : 0 : ret_val = e1000_poll_for_ack(hw, mbx_id);
268 : 0 : out:
269 : 0 : return ret_val;
270 : : }
271 : :
272 : : /**
273 : : * e1000_init_mbx_ops_generic - Initialize mbx function pointers
274 : : * @hw: pointer to the HW structure
275 : : *
276 : : * Sets the function pointers to no-op functions
277 : : **/
278 : 0 : void e1000_init_mbx_ops_generic(struct e1000_hw *hw)
279 : : {
280 : : struct e1000_mbx_info *mbx = &hw->mbx;
281 : 0 : mbx->ops.init_params = e1000_null_ops_generic;
282 : 0 : mbx->ops.read = e1000_null_mbx_transact;
283 : 0 : mbx->ops.write = e1000_null_mbx_transact;
284 : 0 : mbx->ops.check_for_msg = e1000_null_mbx_check_for_flag;
285 : 0 : mbx->ops.check_for_ack = e1000_null_mbx_check_for_flag;
286 : 0 : mbx->ops.check_for_rst = e1000_null_mbx_check_for_flag;
287 : 0 : mbx->ops.read_posted = e1000_read_posted_mbx;
288 : 0 : mbx->ops.write_posted = e1000_write_posted_mbx;
289 : 0 : }
290 : :
291 : : /**
292 : : * e1000_read_v2p_mailbox - read v2p mailbox
293 : : * @hw: pointer to the HW structure
294 : : *
295 : : * This function is used to read the v2p mailbox without losing the read to
296 : : * clear status bits.
297 : : **/
298 : : STATIC u32 e1000_read_v2p_mailbox(struct e1000_hw *hw)
299 : : {
300 : 0 : u32 v2p_mailbox = E1000_READ_REG(hw, E1000_V2PMAILBOX(0));
301 : :
302 : 0 : v2p_mailbox |= hw->dev_spec.vf.v2p_mailbox;
303 : 0 : hw->dev_spec.vf.v2p_mailbox |= v2p_mailbox & E1000_V2PMAILBOX_R2C_BITS;
304 : :
305 : : return v2p_mailbox;
306 : : }
307 : :
308 : : /**
309 : : * e1000_check_for_bit_vf - Determine if a status bit was set
310 : : * @hw: pointer to the HW structure
311 : : * @mask: bitmask for bits to be tested and cleared
312 : : *
313 : : * This function is used to check for the read to clear bits within
314 : : * the V2P mailbox.
315 : : **/
316 : : STATIC s32 e1000_check_for_bit_vf(struct e1000_hw *hw, u32 mask)
317 : : {
318 : : u32 v2p_mailbox = e1000_read_v2p_mailbox(hw);
319 : : s32 ret_val = -E1000_ERR_MBX;
320 : :
321 [ # # # # : 0 : if (v2p_mailbox & mask)
# # ]
322 : : ret_val = E1000_SUCCESS;
323 : :
324 : 0 : hw->dev_spec.vf.v2p_mailbox &= ~mask;
325 : :
326 : : return ret_val;
327 : : }
328 : :
329 : : /**
330 : : * e1000_check_for_msg_vf - checks to see if the PF has sent mail
331 : : * @hw: pointer to the HW structure
332 : : * @mbx_id: id of mailbox to check
333 : : *
334 : : * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
335 : : **/
336 : 0 : STATIC s32 e1000_check_for_msg_vf(struct e1000_hw *hw,
337 : : u16 E1000_UNUSEDARG mbx_id)
338 : : {
339 : : s32 ret_val = -E1000_ERR_MBX;
340 : :
341 : : UNREFERENCED_1PARAMETER(mbx_id);
342 : 0 : DEBUGFUNC("e1000_check_for_msg_vf");
343 : :
344 [ # # ]: 0 : if (!e1000_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFSTS)) {
345 : : ret_val = E1000_SUCCESS;
346 : 0 : hw->mbx.stats.reqs++;
347 : : }
348 : :
349 : 0 : return ret_val;
350 : : }
351 : :
352 : : /**
353 : : * e1000_check_for_ack_vf - checks to see if the PF has ACK'd
354 : : * @hw: pointer to the HW structure
355 : : * @mbx_id: id of mailbox to check
356 : : *
357 : : * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
358 : : **/
359 : 0 : STATIC s32 e1000_check_for_ack_vf(struct e1000_hw *hw,
360 : : u16 E1000_UNUSEDARG mbx_id)
361 : : {
362 : : s32 ret_val = -E1000_ERR_MBX;
363 : :
364 : : UNREFERENCED_1PARAMETER(mbx_id);
365 : 0 : DEBUGFUNC("e1000_check_for_ack_vf");
366 : :
367 [ # # ]: 0 : if (!e1000_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFACK)) {
368 : : ret_val = E1000_SUCCESS;
369 : 0 : hw->mbx.stats.acks++;
370 : : }
371 : :
372 : 0 : return ret_val;
373 : : }
374 : :
375 : : /**
376 : : * e1000_check_for_rst_vf - checks to see if the PF has reset
377 : : * @hw: pointer to the HW structure
378 : : * @mbx_id: id of mailbox to check
379 : : *
380 : : * returns true if the PF has set the reset done bit or else false
381 : : **/
382 : 0 : STATIC s32 e1000_check_for_rst_vf(struct e1000_hw *hw,
383 : : u16 E1000_UNUSEDARG mbx_id)
384 : : {
385 : : s32 ret_val = -E1000_ERR_MBX;
386 : :
387 : : UNREFERENCED_1PARAMETER(mbx_id);
388 : 0 : DEBUGFUNC("e1000_check_for_rst_vf");
389 : :
390 [ # # ]: 0 : if (!e1000_check_for_bit_vf(hw, (E1000_V2PMAILBOX_RSTD |
391 : : E1000_V2PMAILBOX_RSTI))) {
392 : : ret_val = E1000_SUCCESS;
393 : 0 : hw->mbx.stats.rsts++;
394 : : }
395 : :
396 : 0 : return ret_val;
397 : : }
398 : :
399 : : /**
400 : : * e1000_obtain_mbx_lock_vf - obtain mailbox lock
401 : : * @hw: pointer to the HW structure
402 : : *
403 : : * return SUCCESS if we obtained the mailbox lock
404 : : **/
405 : 0 : STATIC s32 e1000_obtain_mbx_lock_vf(struct e1000_hw *hw)
406 : : {
407 : : s32 ret_val = -E1000_ERR_MBX;
408 : : int count = 10;
409 : :
410 : 0 : DEBUGFUNC("e1000_obtain_mbx_lock_vf");
411 : :
412 : : do {
413 : : /* Take ownership of the buffer */
414 : 0 : E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_VFU);
415 : :
416 : : /* reserve mailbox for vf use */
417 [ # # ]: 0 : if (e1000_read_v2p_mailbox(hw) & E1000_V2PMAILBOX_VFU) {
418 : : ret_val = E1000_SUCCESS;
419 : : break;
420 : : }
421 : 0 : usec_delay(1000);
422 [ # # ]: 0 : } while (count-- > 0);
423 : :
424 : 0 : return ret_val;
425 : : }
426 : :
427 : : /**
428 : : * e1000_write_mbx_vf - Write a message to the mailbox
429 : : * @hw: pointer to the HW structure
430 : : * @msg: The message buffer
431 : : * @size: Length of buffer
432 : : * @mbx_id: id of mailbox to write
433 : : *
434 : : * returns SUCCESS if it successfully copied message into the buffer
435 : : **/
436 : 0 : STATIC s32 e1000_write_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
437 : : u16 E1000_UNUSEDARG mbx_id)
438 : : {
439 : : s32 ret_val;
440 : : u16 i;
441 : :
442 : : UNREFERENCED_1PARAMETER(mbx_id);
443 : :
444 : 0 : DEBUGFUNC("e1000_write_mbx_vf");
445 : :
446 : : /* lock the mailbox to prevent pf/vf race condition */
447 : 0 : ret_val = e1000_obtain_mbx_lock_vf(hw);
448 [ # # ]: 0 : if (ret_val)
449 : 0 : goto out_no_write;
450 : :
451 : : /* flush msg and acks as we are overwriting the message buffer */
452 : 0 : e1000_check_for_msg_vf(hw, 0);
453 : 0 : e1000_check_for_ack_vf(hw, 0);
454 : :
455 : : /* copy the caller specified message to the mailbox memory buffer */
456 [ # # ]: 0 : for (i = 0; i < size; i++)
457 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VMBMEM(0), i, msg[i]);
458 : :
459 : : /* update stats */
460 : 0 : hw->mbx.stats.msgs_tx++;
461 : :
462 : : /* Drop VFU and interrupt the PF to tell it a message has been sent */
463 : 0 : E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_REQ);
464 : :
465 : 0 : out_no_write:
466 : 0 : return ret_val;
467 : : }
468 : :
469 : : /**
470 : : * e1000_read_mbx_vf - Reads a message from the inbox intended for vf
471 : : * @hw: pointer to the HW structure
472 : : * @msg: The message buffer
473 : : * @size: Length of buffer
474 : : * @mbx_id: id of mailbox to read
475 : : *
476 : : * returns SUCCESS if it successfully read message from buffer
477 : : **/
478 : 0 : STATIC s32 e1000_read_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
479 : : u16 E1000_UNUSEDARG mbx_id)
480 : : {
481 : : s32 ret_val = E1000_SUCCESS;
482 : : u16 i;
483 : :
484 : 0 : DEBUGFUNC("e1000_read_mbx_vf");
485 : : UNREFERENCED_1PARAMETER(mbx_id);
486 : :
487 : : /* lock the mailbox to prevent pf/vf race condition */
488 : 0 : ret_val = e1000_obtain_mbx_lock_vf(hw);
489 [ # # ]: 0 : if (ret_val)
490 : 0 : goto out_no_read;
491 : :
492 : : /* copy the message from the mailbox memory buffer */
493 [ # # ]: 0 : for (i = 0; i < size; i++)
494 : 0 : msg[i] = E1000_READ_REG_ARRAY(hw, E1000_VMBMEM(0), i);
495 : :
496 : : /* Acknowledge receipt and release mailbox, then we're done */
497 : 0 : E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_ACK);
498 : :
499 : : /* update stats */
500 : 0 : hw->mbx.stats.msgs_rx++;
501 : :
502 : 0 : out_no_read:
503 : 0 : return ret_val;
504 : : }
505 : :
506 : : /**
507 : : * e1000_init_mbx_params_vf - set initial values for vf mailbox
508 : : * @hw: pointer to the HW structure
509 : : *
510 : : * Initializes the hw->mbx struct to correct values for vf mailbox
511 : : */
512 : 0 : s32 e1000_init_mbx_params_vf(struct e1000_hw *hw)
513 : : {
514 : : struct e1000_mbx_info *mbx = &hw->mbx;
515 : :
516 : : /* start mailbox as timed out and let the reset_hw call set the timeout
517 : : * value to begin communications */
518 : 0 : mbx->timeout = 0;
519 : 0 : mbx->usec_delay = E1000_VF_MBX_INIT_DELAY;
520 : :
521 : 0 : mbx->size = E1000_VFMAILBOX_SIZE;
522 : :
523 : 0 : mbx->ops.read = e1000_read_mbx_vf;
524 : 0 : mbx->ops.write = e1000_write_mbx_vf;
525 : 0 : mbx->ops.read_posted = e1000_read_posted_mbx;
526 : 0 : mbx->ops.write_posted = e1000_write_posted_mbx;
527 : 0 : mbx->ops.check_for_msg = e1000_check_for_msg_vf;
528 : 0 : mbx->ops.check_for_ack = e1000_check_for_ack_vf;
529 : 0 : mbx->ops.check_for_rst = e1000_check_for_rst_vf;
530 : :
531 : 0 : mbx->stats.msgs_tx = 0;
532 : 0 : mbx->stats.msgs_rx = 0;
533 : 0 : mbx->stats.reqs = 0;
534 : 0 : mbx->stats.acks = 0;
535 : 0 : mbx->stats.rsts = 0;
536 : :
537 : 0 : return E1000_SUCCESS;
538 : : }
539 : :
540 : : STATIC s32 e1000_check_for_bit_pf(struct e1000_hw *hw, u32 mask)
541 : : {
542 : 0 : u32 mbvficr = E1000_READ_REG(hw, E1000_MBVFICR);
543 : : s32 ret_val = -E1000_ERR_MBX;
544 : :
545 [ # # # # ]: 0 : if (mbvficr & mask) {
546 : : ret_val = E1000_SUCCESS;
547 : 0 : E1000_WRITE_REG(hw, E1000_MBVFICR, mask);
548 : : }
549 : :
550 : : return ret_val;
551 : : }
552 : :
553 : : /**
554 : : * e1000_check_for_msg_pf - checks to see if the VF has sent mail
555 : : * @hw: pointer to the HW structure
556 : : * @vf_number: the VF index
557 : : *
558 : : * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
559 : : **/
560 : 0 : STATIC s32 e1000_check_for_msg_pf(struct e1000_hw *hw, u16 vf_number)
561 : : {
562 : : s32 ret_val = -E1000_ERR_MBX;
563 : :
564 : 0 : DEBUGFUNC("e1000_check_for_msg_pf");
565 : :
566 : 0 : if (!e1000_check_for_bit_pf(hw, E1000_MBVFICR_VFREQ_VF1 << vf_number)) {
567 : : ret_val = E1000_SUCCESS;
568 : 0 : hw->mbx.stats.reqs++;
569 : : }
570 : :
571 : 0 : return ret_val;
572 : : }
573 : :
574 : : /**
575 : : * e1000_check_for_ack_pf - checks to see if the VF has ACKed
576 : : * @hw: pointer to the HW structure
577 : : * @vf_number: the VF index
578 : : *
579 : : * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
580 : : **/
581 : 0 : STATIC s32 e1000_check_for_ack_pf(struct e1000_hw *hw, u16 vf_number)
582 : : {
583 : : s32 ret_val = -E1000_ERR_MBX;
584 : :
585 : 0 : DEBUGFUNC("e1000_check_for_ack_pf");
586 : :
587 : 0 : if (!e1000_check_for_bit_pf(hw, E1000_MBVFICR_VFACK_VF1 << vf_number)) {
588 : : ret_val = E1000_SUCCESS;
589 : 0 : hw->mbx.stats.acks++;
590 : : }
591 : :
592 : 0 : return ret_val;
593 : : }
594 : :
595 : : /**
596 : : * e1000_check_for_rst_pf - checks to see if the VF has reset
597 : : * @hw: pointer to the HW structure
598 : : * @vf_number: the VF index
599 : : *
600 : : * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
601 : : **/
602 : 0 : STATIC s32 e1000_check_for_rst_pf(struct e1000_hw *hw, u16 vf_number)
603 : : {
604 : 0 : u32 vflre = E1000_READ_REG(hw, E1000_VFLRE);
605 : : s32 ret_val = -E1000_ERR_MBX;
606 : :
607 : 0 : DEBUGFUNC("e1000_check_for_rst_pf");
608 : :
609 [ # # ]: 0 : if (vflre & (1 << vf_number)) {
610 : : ret_val = E1000_SUCCESS;
611 : 0 : E1000_WRITE_REG(hw, E1000_VFLRE, (1 << vf_number));
612 : 0 : hw->mbx.stats.rsts++;
613 : : }
614 : :
615 : 0 : return ret_val;
616 : : }
617 : :
618 : : /**
619 : : * e1000_obtain_mbx_lock_pf - obtain mailbox lock
620 : : * @hw: pointer to the HW structure
621 : : * @vf_number: the VF index
622 : : *
623 : : * return SUCCESS if we obtained the mailbox lock
624 : : **/
625 : 0 : STATIC s32 e1000_obtain_mbx_lock_pf(struct e1000_hw *hw, u16 vf_number)
626 : : {
627 : : s32 ret_val = -E1000_ERR_MBX;
628 : : u32 p2v_mailbox;
629 : : int count = 10;
630 : :
631 : 0 : DEBUGFUNC("e1000_obtain_mbx_lock_pf");
632 : :
633 : : do {
634 : : /* Take ownership of the buffer */
635 : 0 : E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number),
636 : : E1000_P2VMAILBOX_PFU);
637 : :
638 : : /* reserve mailbox for pf use */
639 : 0 : p2v_mailbox = E1000_READ_REG(hw, E1000_P2VMAILBOX(vf_number));
640 [ # # ]: 0 : if (p2v_mailbox & E1000_P2VMAILBOX_PFU) {
641 : : ret_val = E1000_SUCCESS;
642 : : break;
643 : : }
644 : 0 : usec_delay(1000);
645 [ # # ]: 0 : } while (count-- > 0);
646 : :
647 : 0 : return ret_val;
648 : :
649 : : }
650 : :
651 : : /**
652 : : * e1000_write_mbx_pf - Places a message in the mailbox
653 : : * @hw: pointer to the HW structure
654 : : * @msg: The message buffer
655 : : * @size: Length of buffer
656 : : * @vf_number: the VF index
657 : : *
658 : : * returns SUCCESS if it successfully copied message into the buffer
659 : : **/
660 : 0 : STATIC s32 e1000_write_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
661 : : u16 vf_number)
662 : : {
663 : : s32 ret_val;
664 : : u16 i;
665 : :
666 : 0 : DEBUGFUNC("e1000_write_mbx_pf");
667 : :
668 : : /* lock the mailbox to prevent pf/vf race condition */
669 : 0 : ret_val = e1000_obtain_mbx_lock_pf(hw, vf_number);
670 [ # # ]: 0 : if (ret_val)
671 : 0 : goto out_no_write;
672 : :
673 : : /* flush msg and acks as we are overwriting the message buffer */
674 : 0 : e1000_check_for_msg_pf(hw, vf_number);
675 : 0 : e1000_check_for_ack_pf(hw, vf_number);
676 : :
677 : : /* copy the caller specified message to the mailbox memory buffer */
678 [ # # ]: 0 : for (i = 0; i < size; i++)
679 : 0 : E1000_WRITE_REG_ARRAY(hw, E1000_VMBMEM(vf_number), i, msg[i]);
680 : :
681 : : /* Interrupt VF to tell it a message has been sent and release buffer*/
682 : 0 : E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_STS);
683 : :
684 : : /* update stats */
685 : 0 : hw->mbx.stats.msgs_tx++;
686 : :
687 : 0 : out_no_write:
688 : 0 : return ret_val;
689 : :
690 : : }
691 : :
692 : : /**
693 : : * e1000_read_mbx_pf - Read a message from the mailbox
694 : : * @hw: pointer to the HW structure
695 : : * @msg: The message buffer
696 : : * @size: Length of buffer
697 : : * @vf_number: the VF index
698 : : *
699 : : * This function copies a message from the mailbox buffer to the caller's
700 : : * memory buffer. The presumption is that the caller knows that there was
701 : : * a message due to a VF request so no polling for message is needed.
702 : : **/
703 : 0 : STATIC s32 e1000_read_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
704 : : u16 vf_number)
705 : : {
706 : : s32 ret_val;
707 : : u16 i;
708 : :
709 : 0 : DEBUGFUNC("e1000_read_mbx_pf");
710 : :
711 : : /* lock the mailbox to prevent pf/vf race condition */
712 : 0 : ret_val = e1000_obtain_mbx_lock_pf(hw, vf_number);
713 [ # # ]: 0 : if (ret_val)
714 : 0 : goto out_no_read;
715 : :
716 : : /* copy the message to the mailbox memory buffer */
717 [ # # ]: 0 : for (i = 0; i < size; i++)
718 : 0 : msg[i] = E1000_READ_REG_ARRAY(hw, E1000_VMBMEM(vf_number), i);
719 : :
720 : : /* Acknowledge the message and release buffer */
721 : 0 : E1000_WRITE_REG(hw, E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_ACK);
722 : :
723 : : /* update stats */
724 : 0 : hw->mbx.stats.msgs_rx++;
725 : :
726 : 0 : out_no_read:
727 : 0 : return ret_val;
728 : : }
729 : :
730 : : /**
731 : : * e1000_init_mbx_params_pf - set initial values for pf mailbox
732 : : * @hw: pointer to the HW structure
733 : : *
734 : : * Initializes the hw->mbx struct to correct values for pf mailbox
735 : : */
736 : 0 : s32 e1000_init_mbx_params_pf(struct e1000_hw *hw)
737 : : {
738 : : struct e1000_mbx_info *mbx = &hw->mbx;
739 : :
740 [ # # ]: 0 : switch (hw->mac.type) {
741 : 0 : case e1000_82576:
742 : : case e1000_i350:
743 : : case e1000_i354:
744 : 0 : mbx->timeout = 0;
745 : 0 : mbx->usec_delay = 0;
746 : :
747 : 0 : mbx->size = E1000_VFMAILBOX_SIZE;
748 : :
749 : 0 : mbx->ops.read = e1000_read_mbx_pf;
750 : 0 : mbx->ops.write = e1000_write_mbx_pf;
751 : 0 : mbx->ops.read_posted = e1000_read_posted_mbx;
752 : 0 : mbx->ops.write_posted = e1000_write_posted_mbx;
753 : 0 : mbx->ops.check_for_msg = e1000_check_for_msg_pf;
754 : 0 : mbx->ops.check_for_ack = e1000_check_for_ack_pf;
755 : 0 : mbx->ops.check_for_rst = e1000_check_for_rst_pf;
756 : :
757 : 0 : mbx->stats.msgs_tx = 0;
758 : 0 : mbx->stats.msgs_rx = 0;
759 : 0 : mbx->stats.reqs = 0;
760 : 0 : mbx->stats.acks = 0;
761 : 0 : mbx->stats.rsts = 0;
762 : : /* Fall through */
763 : 0 : default:
764 : 0 : return E1000_SUCCESS;
765 : : }
766 : : }
767 : :
|