ixgbe_mbx.c revision 1.16 1 /* $NetBSD: ixgbe_mbx.c,v 1.16 2021/12/24 05:11:04 msaitoh Exp $ */
2
3 /******************************************************************************
4 SPDX-License-Identifier: BSD-3-Clause
5
6 Copyright (c) 2001-2020, Intel Corporation
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14
15 2. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18
19 3. Neither the name of the Intel Corporation nor the names of its
20 contributors may be used to endorse or promote products derived from
21 this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34
35 ******************************************************************************/
36 /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_mbx.c 326022 2017-11-20 19:36:21Z pfg $*/
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: ixgbe_mbx.c,v 1.16 2021/12/24 05:11:04 msaitoh Exp $");
40
41 #include "ixgbe_type.h"
42 #include "ixgbe_mbx.h"
43
44 static s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id);
45 static s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id);
46
47 /**
48 * ixgbe_read_mbx - Reads a message from the mailbox
49 * @hw: pointer to the HW structure
50 * @msg: The message buffer
51 * @size: Length of buffer
52 * @mbx_id: id of mailbox to read
53 *
54 * returns SUCCESS if it successfully read message from buffer
55 **/
56 s32 ixgbe_read_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
57 {
58 struct ixgbe_mbx_info *mbx = &hw->mbx;
59
60 DEBUGFUNC("ixgbe_read_mbx");
61
62 /* limit read to size of mailbox */
63 if (size > mbx->size) {
64 ERROR_REPORT3(IXGBE_ERROR_ARGUMENT,
65 "Invalid mailbox message size %u, changing to %u",
66 size, mbx->size);
67 size = mbx->size;
68 }
69
70 if (mbx->ops[mbx_id].read)
71 return mbx->ops[mbx_id].read(hw, msg, size, mbx_id);
72
73 return IXGBE_ERR_CONFIG;
74 }
75
76 /**
77 * ixgbe_poll_mbx - Wait for message and read it from the mailbox
78 * @hw: pointer to the HW structure
79 * @msg: The message buffer
80 * @size: Length of buffer
81 * @mbx_id: id of mailbox to read
82 *
83 * returns SUCCESS if it successfully read message from buffer
84 **/
85 s32 ixgbe_poll_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
86 {
87 struct ixgbe_mbx_info *mbx = &hw->mbx;
88 s32 ret_val;
89
90 DEBUGFUNC("ixgbe_poll_mbx");
91
92 if (!mbx->ops[mbx_id].read || !mbx->ops[mbx_id].check_for_msg ||
93 !mbx->timeout)
94 return IXGBE_ERR_CONFIG;
95
96 /* limit read to size of mailbox */
97 if (size > mbx->size) {
98 ERROR_REPORT3(IXGBE_ERROR_ARGUMENT,
99 "Invalid mailbox message size %u, changing to %u",
100 size, mbx->size);
101 size = mbx->size;
102 }
103
104 ret_val = ixgbe_poll_for_msg(hw, mbx_id);
105 /* if ack received read message, otherwise we timed out */
106 if (!ret_val)
107 return mbx->ops[mbx_id].read(hw, msg, size, mbx_id);
108
109 return ret_val;
110 }
111
112 /**
113 * ixgbe_write_mbx - Write a message to the mailbox and wait for ACK
114 * @hw: pointer to the HW structure
115 * @msg: The message buffer
116 * @size: Length of buffer
117 * @mbx_id: id of mailbox to write
118 *
119 * returns SUCCESS if it successfully copied message into the buffer and
120 * received an ACK to that message within specified period
121 **/
122 s32 ixgbe_write_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
123 {
124 struct ixgbe_mbx_info *mbx = &hw->mbx;
125 s32 ret_val = IXGBE_ERR_MBX;
126
127 DEBUGFUNC("ixgbe_write_mbx");
128
129 /*
130 * exit if either we can't write, release
131 * or there is no timeout defined
132 */
133 if (!mbx->ops[mbx_id].write || !mbx->ops[mbx_id].check_for_ack ||
134 !mbx->ops[mbx_id].release || !mbx->timeout)
135 return IXGBE_ERR_CONFIG;
136
137 if (size > mbx->size) {
138 ret_val = IXGBE_ERR_PARAM;
139 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
140 "Invalid mailbox message size %u", size);
141 } else {
142 ret_val = mbx->ops[mbx_id].write(hw, msg, size, mbx_id);
143 }
144
145 return ret_val;
146 }
147
148 /**
149 * ixgbe_check_for_msg - checks to see if someone sent us mail
150 * @hw: pointer to the HW structure
151 * @mbx_id: id of mailbox to check
152 *
153 * returns SUCCESS if the Status bit was found or else ERR_MBX
154 **/
155 s32 ixgbe_check_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
156 {
157 struct ixgbe_mbx_info *mbx = &hw->mbx;
158 s32 ret_val = IXGBE_ERR_CONFIG;
159
160 DEBUGFUNC("ixgbe_check_for_msg");
161
162 if (mbx->ops[mbx_id].check_for_msg)
163 ret_val = mbx->ops[mbx_id].check_for_msg(hw, mbx_id);
164
165 return ret_val;
166 }
167
168 /**
169 * ixgbe_check_for_ack - checks to see if someone sent us ACK
170 * @hw: pointer to the HW structure
171 * @mbx_id: id of mailbox to check
172 *
173 * returns SUCCESS if the Status bit was found or else ERR_MBX
174 **/
175 s32 ixgbe_check_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
176 {
177 struct ixgbe_mbx_info *mbx = &hw->mbx;
178 s32 ret_val = IXGBE_ERR_CONFIG;
179
180 DEBUGFUNC("ixgbe_check_for_ack");
181
182 if (mbx->ops[mbx_id].check_for_ack)
183 ret_val = mbx->ops[mbx_id].check_for_ack(hw, mbx_id);
184
185 return ret_val;
186 }
187
188 /**
189 * ixgbe_check_for_rst - checks to see if other side has reset
190 * @hw: pointer to the HW structure
191 * @mbx_id: id of mailbox to check
192 *
193 * returns SUCCESS if the Status bit was found or else ERR_MBX
194 **/
195 s32 ixgbe_check_for_rst(struct ixgbe_hw *hw, u16 mbx_id)
196 {
197 struct ixgbe_mbx_info *mbx = &hw->mbx;
198 s32 ret_val = IXGBE_ERR_CONFIG;
199
200 DEBUGFUNC("ixgbe_check_for_rst");
201
202 if (mbx->ops[mbx_id].check_for_rst)
203 ret_val = mbx->ops[mbx_id].check_for_rst(hw, mbx_id);
204
205 return ret_val;
206 }
207
208 /**
209 * ixgbe_clear_mbx - Clear Mailbox Memory
210 * @hw: pointer to the HW structure
211 * @mbx_id: id of mailbox to write
212 *
213 * Set VFMBMEM of given VF to 0x0.
214 **/
215 s32 ixgbe_clear_mbx(struct ixgbe_hw *hw, u16 mbx_id)
216 {
217 struct ixgbe_mbx_info *mbx = &hw->mbx;
218 s32 ret_val = IXGBE_ERR_CONFIG;
219
220 DEBUGFUNC("ixgbe_clear_mbx");
221
222 if (mbx->ops[mbx_id].clear)
223 ret_val = mbx->ops[mbx_id].clear(hw, mbx_id);
224
225 return ret_val;
226 }
227
228 /**
229 * ixgbe_poll_for_msg - Wait for message notification
230 * @hw: pointer to the HW structure
231 * @mbx_id: id of mailbox to write
232 *
233 * returns SUCCESS if it successfully received a message notification
234 **/
235 static s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
236 {
237 struct ixgbe_mbx_info *mbx = &hw->mbx;
238 int countdown = mbx->timeout;
239
240 DEBUGFUNC("ixgbe_poll_for_msg");
241
242 if (!countdown || !mbx->ops[mbx_id].check_for_msg)
243 return IXGBE_ERR_CONFIG;
244
245 while (countdown && mbx->ops[mbx_id].check_for_msg(hw, mbx_id)) {
246 countdown--;
247 if (!countdown)
248 break;
249 usec_delay(mbx->usec_delay);
250 }
251
252 if (countdown == 0) {
253 ERROR_REPORT2(IXGBE_ERROR_POLLING,
254 "Polling for VF%u mailbox message timedout", mbx_id);
255 return IXGBE_ERR_TIMEOUT;
256 }
257
258 return IXGBE_SUCCESS;
259 }
260
261 /**
262 * ixgbe_poll_for_ack - Wait for message acknowledgment
263 * @hw: pointer to the HW structure
264 * @mbx_id: id of mailbox to write
265 *
266 * returns SUCCESS if it successfully received a message acknowledgment
267 **/
268 static s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
269 {
270 struct ixgbe_mbx_info *mbx = &hw->mbx;
271 int countdown = mbx->timeout;
272
273 DEBUGFUNC("ixgbe_poll_for_ack");
274
275 if (!countdown || !mbx->ops[mbx_id].check_for_ack)
276 return IXGBE_ERR_CONFIG;
277
278 while (countdown && mbx->ops[mbx_id].check_for_ack(hw, mbx_id)) {
279 countdown--;
280 if (!countdown)
281 break;
282 usec_delay(mbx->usec_delay);
283 }
284
285 if (countdown == 0) {
286 ERROR_REPORT2(IXGBE_ERROR_POLLING,
287 "Polling for VF%u mailbox ack timedout", mbx_id);
288 return IXGBE_ERR_TIMEOUT;
289 }
290
291 return IXGBE_SUCCESS;
292 }
293
294
295 /**
296 * ixgbe_read_mailbox_vf - read VF's mailbox register
297 * @hw: pointer to the HW structure
298 *
299 * This function is used to read the mailbox register dedicated for VF without
300 * losing the read to clear status bits.
301 **/
302 static u32 ixgbe_read_mailbox_vf(struct ixgbe_hw *hw)
303 {
304 u32 vf_mailbox = IXGBE_READ_REG(hw, IXGBE_VFMAILBOX);
305
306 vf_mailbox |= hw->mbx.vf_mailbox;
307 hw->mbx.vf_mailbox |= vf_mailbox & IXGBE_VFMAILBOX_R2C_BITS;
308
309 return vf_mailbox;
310 }
311
312 static void ixgbe_clear_msg_vf(struct ixgbe_hw *hw)
313 {
314 u32 vf_mailbox = ixgbe_read_mailbox_vf(hw);
315
316 if (vf_mailbox & IXGBE_VFMAILBOX_PFSTS) {
317 hw->mbx.stats.reqs.ev_count++;
318 hw->mbx.vf_mailbox &= ~IXGBE_VFMAILBOX_PFSTS;
319 }
320 }
321
322 static void ixgbe_clear_ack_vf(struct ixgbe_hw *hw)
323 {
324 u32 vf_mailbox = ixgbe_read_mailbox_vf(hw);
325
326 if (vf_mailbox & IXGBE_VFMAILBOX_PFACK) {
327 hw->mbx.stats.acks.ev_count++;
328 hw->mbx.vf_mailbox &= ~IXGBE_VFMAILBOX_PFACK;
329 }
330 }
331
332 static void ixgbe_clear_rst_vf(struct ixgbe_hw *hw)
333 {
334 u32 vf_mailbox = ixgbe_read_mailbox_vf(hw);
335
336 if (vf_mailbox & (IXGBE_VFMAILBOX_RSTI | IXGBE_VFMAILBOX_RSTD)) {
337 hw->mbx.stats.rsts.ev_count++;
338 hw->mbx.vf_mailbox &= ~(IXGBE_VFMAILBOX_RSTI |
339 IXGBE_VFMAILBOX_RSTD);
340 }
341 }
342
343 /**
344 * ixgbe_check_for_bit_vf - Determine if a status bit was set
345 * @hw: pointer to the HW structure
346 * @mask: bitmask for bits to be tested and cleared
347 *
348 * This function is used to check for the read to clear bits within
349 * the V2P mailbox.
350 **/
351 static s32 ixgbe_check_for_bit_vf(struct ixgbe_hw *hw, u32 mask)
352 {
353 u32 vf_mailbox = ixgbe_read_mailbox_vf(hw);
354
355 if (vf_mailbox & mask)
356 return IXGBE_SUCCESS;
357
358 return IXGBE_ERR_MBX;
359 }
360
361 /**
362 * ixgbe_check_for_msg_vf - checks to see if the PF has sent mail
363 * @hw: pointer to the HW structure
364 * @mbx_id: id of mailbox to check
365 *
366 * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
367 **/
368 static s32 ixgbe_check_for_msg_vf(struct ixgbe_hw *hw, u16 mbx_id)
369 {
370 UNREFERENCED_1PARAMETER(mbx_id);
371 DEBUGFUNC("ixgbe_check_for_msg_vf");
372
373 if (!ixgbe_check_for_bit_vf(hw, IXGBE_VFMAILBOX_PFSTS)) {
374 hw->mbx.stats.reqs.ev_count++;
375 return IXGBE_SUCCESS;
376 }
377
378 return IXGBE_ERR_MBX;
379 }
380
381 /**
382 * ixgbe_check_for_ack_vf - checks to see if the PF has ACK'd
383 * @hw: pointer to the HW structure
384 * @mbx_id: id of mailbox to check
385 *
386 * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
387 **/
388 static s32 ixgbe_check_for_ack_vf(struct ixgbe_hw *hw, u16 mbx_id)
389 {
390 UNREFERENCED_1PARAMETER(mbx_id);
391 DEBUGFUNC("ixgbe_check_for_ack_vf");
392
393 if (!ixgbe_check_for_bit_vf(hw, IXGBE_VFMAILBOX_PFACK)) {
394 /* TODO: should this be autocleared? */
395 ixgbe_clear_ack_vf(hw);
396 hw->mbx.stats.acks.ev_count++;
397 return IXGBE_SUCCESS;
398 }
399
400 return IXGBE_ERR_MBX;
401 }
402
403 /**
404 * ixgbe_check_for_rst_vf - checks to see if the PF has reset
405 * @hw: pointer to the HW structure
406 * @mbx_id: id of mailbox to check
407 *
408 * returns TRUE if the PF has set the reset done bit or else FALSE
409 **/
410 static s32 ixgbe_check_for_rst_vf(struct ixgbe_hw *hw, u16 mbx_id)
411 {
412 UNREFERENCED_1PARAMETER(mbx_id);
413 DEBUGFUNC("ixgbe_check_for_rst_vf");
414
415 if (!ixgbe_check_for_bit_vf(hw, IXGBE_VFMAILBOX_RSTI |
416 IXGBE_VFMAILBOX_RSTD)) {
417 /* TODO: should this be autocleared? */
418 ixgbe_clear_rst_vf(hw);
419 hw->mbx.stats.rsts.ev_count++;
420 return IXGBE_SUCCESS;
421 }
422
423 return IXGBE_ERR_MBX;
424 }
425
426 /**
427 * ixgbe_obtain_mbx_lock_vf - obtain mailbox lock
428 * @hw: pointer to the HW structure
429 *
430 * return SUCCESS if we obtained the mailbox lock
431 **/
432 static s32 ixgbe_obtain_mbx_lock_vf(struct ixgbe_hw *hw)
433 {
434 struct ixgbe_mbx_info *mbx = &hw->mbx;
435 int countdown = mbx->timeout;
436 s32 ret_val = IXGBE_ERR_MBX;
437 u32 vf_mailbox;
438
439 DEBUGFUNC("ixgbe_obtain_mbx_lock_vf");
440
441 if (!mbx->timeout)
442 return IXGBE_ERR_CONFIG;
443
444 while (countdown--) {
445 /* Reserve mailbox for VF use */
446 vf_mailbox = ixgbe_read_mailbox_vf(hw);
447 vf_mailbox |= IXGBE_VFMAILBOX_VFU;
448 IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, vf_mailbox);
449
450 /* Verify that VF is the owner of the lock */
451 if (ixgbe_read_mailbox_vf(hw) & IXGBE_VFMAILBOX_VFU) {
452 ret_val = IXGBE_SUCCESS;
453 break;
454 }
455
456 /* Wait a bit before trying again */
457 usec_delay(mbx->usec_delay);
458 }
459
460 if (ret_val != IXGBE_SUCCESS) {
461 ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
462 "Failed to obtain mailbox lock");
463 ret_val = IXGBE_ERR_TIMEOUT;
464 }
465
466 return ret_val;
467 }
468
469 /**
470 * ixgbe_release_mbx_lock_dummy - release mailbox lock
471 * @hw: pointer to the HW structure
472 * @mbx_id: id of mailbox to read
473 **/
474 static void ixgbe_release_mbx_lock_dummy(struct ixgbe_hw *hw, u16 mbx_id)
475 {
476 UNREFERENCED_2PARAMETER(hw, mbx_id);
477
478 DEBUGFUNC("ixgbe_release_mbx_lock_dummy");
479 }
480
481 /**
482 * ixgbe_release_mbx_lock_vf - release mailbox lock
483 * @hw: pointer to the HW structure
484 * @mbx_id: id of mailbox to read
485 **/
486 static void ixgbe_release_mbx_lock_vf(struct ixgbe_hw *hw, u16 mbx_id)
487 {
488 u32 vf_mailbox;
489
490 UNREFERENCED_1PARAMETER(mbx_id);
491
492 DEBUGFUNC("ixgbe_release_mbx_lock_vf");
493
494 /* Return ownership of the buffer */
495 vf_mailbox = ixgbe_read_mailbox_vf(hw);
496 vf_mailbox &= ~IXGBE_VFMAILBOX_VFU;
497 IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, vf_mailbox);
498 }
499
500 /**
501 * ixgbe_write_mbx_vf_legacy - Write a message to the mailbox
502 * @hw: pointer to the HW structure
503 * @msg: The message buffer
504 * @size: Length of buffer
505 * @mbx_id: id of mailbox to write
506 *
507 * returns SUCCESS if it successfully copied message into the buffer
508 **/
509 static s32 ixgbe_write_mbx_vf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
510 u16 mbx_id)
511 {
512 s32 ret_val;
513 u16 i;
514
515 UNREFERENCED_1PARAMETER(mbx_id);
516 DEBUGFUNC("ixgbe_write_mbx_vf_legacy");
517
518 /* lock the mailbox to prevent pf/vf race condition */
519 ret_val = ixgbe_obtain_mbx_lock_vf(hw);
520 if (ret_val)
521 return ret_val;
522
523 /* flush msg and acks as we are overwriting the message buffer */
524 ixgbe_check_for_msg_vf(hw, 0);
525 ixgbe_clear_msg_vf(hw);
526 ixgbe_check_for_ack_vf(hw, 0);
527 ixgbe_clear_ack_vf(hw);
528
529 /* copy the caller specified message to the mailbox memory buffer */
530 for (i = 0; i < size; i++)
531 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_VFMBMEM, i, msg[i]);
532
533 /* update stats */
534 hw->mbx.stats.msgs_tx.ev_count++;
535
536 /* interrupt the PF to tell it a message has been sent */
537 IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_REQ);
538
539 return IXGBE_SUCCESS;
540 }
541
542 /**
543 * ixgbe_write_mbx_vf - Write a message to the mailbox
544 * @hw: pointer to the HW structure
545 * @msg: The message buffer
546 * @size: Length of buffer
547 * @mbx_id: id of mailbox to write
548 *
549 * returns SUCCESS if it successfully copied message into the buffer
550 **/
551 static s32 ixgbe_write_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
552 u16 mbx_id)
553 {
554 u32 vf_mailbox;
555 s32 ret_val;
556 u16 i;
557
558 UNREFERENCED_1PARAMETER(mbx_id);
559
560 DEBUGFUNC("ixgbe_write_mbx_vf");
561
562 /* lock the mailbox to prevent pf/vf race condition */
563 ret_val = ixgbe_obtain_mbx_lock_vf(hw);
564 if (ret_val)
565 goto out;
566
567 /* flush msg and acks as we are overwriting the message buffer */
568 ixgbe_clear_msg_vf(hw);
569 ixgbe_clear_ack_vf(hw);
570
571 /* copy the caller specified message to the mailbox memory buffer */
572 for (i = 0; i < size; i++)
573 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_VFMBMEM, i, msg[i]);
574
575 /* update stats */
576 hw->mbx.stats.msgs_tx.ev_count++;
577
578 /* interrupt the PF to tell it a message has been sent */
579 vf_mailbox = ixgbe_read_mailbox_vf(hw);
580 vf_mailbox |= IXGBE_VFMAILBOX_REQ;
581 IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, vf_mailbox);
582
583 /* if msg sent wait until we receive an ack */
584 ixgbe_poll_for_ack(hw, mbx_id);
585
586 out:
587 hw->mbx.ops[mbx_id].release(hw, mbx_id);
588
589 return ret_val;
590 }
591
592 /**
593 * ixgbe_read_mbx_vf_legacy - Reads a message from the inbox intended for vf
594 * @hw: pointer to the HW structure
595 * @msg: The message buffer
596 * @size: Length of buffer
597 * @mbx_id: id of mailbox to read
598 *
599 * returns SUCCESS if it successfully read message from buffer
600 **/
601 static s32 ixgbe_read_mbx_vf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
602 u16 mbx_id)
603 {
604 s32 ret_val;
605 u16 i;
606
607 DEBUGFUNC("ixgbe_read_mbx_vf_legacy");
608 UNREFERENCED_1PARAMETER(mbx_id);
609
610 /* lock the mailbox to prevent pf/vf race condition */
611 ret_val = ixgbe_obtain_mbx_lock_vf(hw);
612 if (ret_val)
613 return ret_val;
614
615 /* copy the message from the mailbox memory buffer */
616 for (i = 0; i < size; i++)
617 msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_VFMBMEM, i);
618
619 /* Acknowledge receipt and release mailbox, then we're done */
620 IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_ACK);
621
622 /* update stats */
623 hw->mbx.stats.msgs_rx.ev_count++;
624
625 return IXGBE_SUCCESS;
626 }
627
628 /**
629 * ixgbe_read_mbx_vf - Reads a message from the inbox intended for vf
630 * @hw: pointer to the HW structure
631 * @msg: The message buffer
632 * @size: Length of buffer
633 * @mbx_id: id of mailbox to read
634 *
635 * returns SUCCESS if it successfully read message from buffer
636 **/
637 static s32 ixgbe_read_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
638 u16 mbx_id)
639 {
640 u32 vf_mailbox;
641 s32 ret_val;
642 u16 i;
643
644 DEBUGFUNC("ixgbe_read_mbx_vf");
645 UNREFERENCED_1PARAMETER(mbx_id);
646
647 /* check if there is a message from PF */
648 ret_val = ixgbe_check_for_msg_vf(hw, 0);
649 if (ret_val != IXGBE_SUCCESS)
650 return IXGBE_ERR_MBX_NOMSG;
651
652 ixgbe_clear_msg_vf(hw);
653
654 /* copy the message from the mailbox memory buffer */
655 for (i = 0; i < size; i++)
656 msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_VFMBMEM, i);
657
658 /* Acknowledge receipt */
659 vf_mailbox = ixgbe_read_mailbox_vf(hw);
660 vf_mailbox |= IXGBE_VFMAILBOX_ACK;
661 IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, vf_mailbox);
662
663 /* update stats */
664 hw->mbx.stats.msgs_rx.ev_count++;
665
666 return IXGBE_SUCCESS;
667 }
668
669 /**
670 * ixgbe_init_mbx_params_vf - set initial values for vf mailbox
671 * @hw: pointer to the HW structure
672 *
673 * Initializes single set the hw->mbx struct to correct values for vf mailbox
674 * Set of legacy functions is being used here
675 */
676 void ixgbe_init_mbx_params_vf(struct ixgbe_hw *hw)
677 {
678 struct ixgbe_mbx_info *mbx = &hw->mbx;
679
680 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
681 mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
682
683 mbx->size = IXGBE_VFMAILBOX_SIZE;
684
685 /* VF has only one mailbox connection, no need for more IDs */
686 mbx->ops[0].release = ixgbe_release_mbx_lock_dummy;
687 mbx->ops[0].read = ixgbe_read_mbx_vf_legacy;
688 mbx->ops[0].write = ixgbe_write_mbx_vf_legacy;
689 mbx->ops[0].check_for_msg = ixgbe_check_for_msg_vf;
690 mbx->ops[0].check_for_ack = ixgbe_check_for_ack_vf;
691 mbx->ops[0].check_for_rst = ixgbe_check_for_rst_vf;
692 mbx->ops[0].clear = NULL;
693
694 mbx->stats.msgs_tx.ev_count = 0;
695 mbx->stats.msgs_rx.ev_count = 0;
696 mbx->stats.reqs.ev_count = 0;
697 mbx->stats.acks.ev_count = 0;
698 mbx->stats.rsts.ev_count = 0;
699 }
700
701 /**
702 * ixgbe_upgrade_mbx_params_vf - set initial values for vf mailbox
703 * @hw: pointer to the HW structure
704 *
705 * Initializes the hw->mbx struct to correct values for vf mailbox
706 */
707 void ixgbe_upgrade_mbx_params_vf(struct ixgbe_hw *hw)
708 {
709 struct ixgbe_mbx_info *mbx = &hw->mbx;
710
711 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
712 mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
713
714 mbx->size = IXGBE_VFMAILBOX_SIZE;
715
716 /* VF has only one mailbox connection, no need for more IDs */
717 mbx->ops[0].release = ixgbe_release_mbx_lock_vf;
718 mbx->ops[0].read = ixgbe_read_mbx_vf;
719 mbx->ops[0].write = ixgbe_write_mbx_vf;
720 mbx->ops[0].check_for_msg = ixgbe_check_for_msg_vf;
721 mbx->ops[0].check_for_ack = ixgbe_check_for_ack_vf;
722 mbx->ops[0].check_for_rst = ixgbe_check_for_rst_vf;
723 mbx->ops[0].clear = NULL;
724
725 mbx->stats.msgs_tx.ev_count = 0;
726 mbx->stats.msgs_rx.ev_count = 0;
727 mbx->stats.reqs.ev_count = 0;
728 mbx->stats.acks.ev_count = 0;
729 mbx->stats.rsts.ev_count = 0;
730 }
731
732 static void ixgbe_clear_msg_pf(struct ixgbe_hw *hw, u16 vf_id)
733 {
734 u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
735 s32 index = IXGBE_PFMBICR_INDEX(vf_id);
736 u32 pfmbicr;
737
738 pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
739
740 if (pfmbicr & (IXGBE_PFMBICR_VFREQ_VF1 << vf_shift))
741 hw->mbx.stats.reqs.ev_count++;
742
743 IXGBE_WRITE_REG(hw, IXGBE_PFMBICR(index),
744 IXGBE_PFMBICR_VFREQ_VF1 << vf_shift);
745 }
746
747 static void ixgbe_clear_ack_pf(struct ixgbe_hw *hw, u16 vf_id)
748 {
749 u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
750 s32 index = IXGBE_PFMBICR_INDEX(vf_id);
751 u32 pfmbicr;
752
753 pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
754
755 if (pfmbicr & (IXGBE_PFMBICR_VFACK_VF1 << vf_shift))
756 hw->mbx.stats.acks.ev_count++;
757
758 IXGBE_WRITE_REG(hw, IXGBE_PFMBICR(index),
759 IXGBE_PFMBICR_VFACK_VF1 << vf_shift);
760 }
761
762 static s32 ixgbe_check_for_bit_pf(struct ixgbe_hw *hw, u32 mask, s32 index)
763 {
764 u32 pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
765
766 if (pfmbicr & mask)
767 return IXGBE_SUCCESS;
768
769 return IXGBE_ERR_MBX;
770 }
771
772 /**
773 * ixgbe_check_for_msg_pf - checks to see if the VF has sent mail
774 * @hw: pointer to the HW structure
775 * @vf_id: the VF index
776 *
777 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
778 **/
779 static s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_id)
780 {
781 u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
782 s32 index = IXGBE_PFMBICR_INDEX(vf_id);
783
784 DEBUGFUNC("ixgbe_check_for_msg_pf");
785
786 if (!ixgbe_check_for_bit_pf(hw, IXGBE_PFMBICR_VFREQ_VF1 << vf_shift,
787 index))
788 return IXGBE_SUCCESS;
789
790 return IXGBE_ERR_MBX;
791 }
792
793 /**
794 * ixgbe_check_for_ack_pf - checks to see if the VF has ACKed
795 * @hw: pointer to the HW structure
796 * @vf_id: the VF index
797 *
798 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
799 **/
800 static s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_id)
801 {
802 u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
803 s32 index = IXGBE_PFMBICR_INDEX(vf_id);
804 s32 ret_val = IXGBE_ERR_MBX;
805
806 DEBUGFUNC("ixgbe_check_for_ack_pf");
807
808 if (!ixgbe_check_for_bit_pf(hw, IXGBE_PFMBICR_VFACK_VF1 << vf_shift,
809 index)) {
810 ret_val = IXGBE_SUCCESS;
811 /* TODO: should this be autocleared? */
812 ixgbe_clear_ack_pf(hw, vf_id);
813 }
814
815 return ret_val;
816 }
817
818 /**
819 * ixgbe_check_for_rst_pf - checks to see if the VF has reset
820 * @hw: pointer to the HW structure
821 * @vf_id: the VF index
822 *
823 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
824 **/
825 static s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_id)
826 {
827 u32 vf_shift = IXGBE_PFVFLRE_SHIFT(vf_id);
828 u32 index = IXGBE_PFVFLRE_INDEX(vf_id);
829 s32 ret_val = IXGBE_ERR_MBX;
830 u32 vflre = 0;
831
832 DEBUGFUNC("ixgbe_check_for_rst_pf");
833
834 switch (hw->mac.type) {
835 case ixgbe_mac_82599EB:
836 vflre = IXGBE_READ_REG(hw, IXGBE_PFVFLRE(index));
837 break;
838 case ixgbe_mac_X550:
839 case ixgbe_mac_X550EM_x:
840 case ixgbe_mac_X550EM_a:
841 case ixgbe_mac_X540:
842 vflre = IXGBE_READ_REG(hw, IXGBE_PFVFLREC(index));
843 break;
844 default:
845 break;
846 }
847
848 if (vflre & (1 << vf_shift)) {
849 ret_val = IXGBE_SUCCESS;
850 IXGBE_WRITE_REG(hw, IXGBE_PFVFLREC(index), (1 << vf_shift));
851 hw->mbx.stats.rsts.ev_count++;
852 }
853
854 return ret_val;
855 }
856
857 /**
858 * ixgbe_obtain_mbx_lock_pf - obtain mailbox lock
859 * @hw: pointer to the HW structure
860 * @vf_id: the VF index
861 *
862 * return SUCCESS if we obtained the mailbox lock
863 **/
864 static s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_id)
865 {
866 struct ixgbe_mbx_info *mbx = &hw->mbx;
867 int countdown = mbx->timeout;
868 s32 ret_val = IXGBE_ERR_MBX;
869 u32 pf_mailbox;
870
871 DEBUGFUNC("ixgbe_obtain_mbx_lock_pf");
872
873 if (!mbx->timeout)
874 return IXGBE_ERR_CONFIG;
875
876 while (countdown--) {
877 /* Reserve mailbox for PF use */
878 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
879 pf_mailbox |= IXGBE_PFMAILBOX_PFU;
880 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
881
882 /* Verify that PF is the owner of the lock */
883 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
884 if (pf_mailbox & IXGBE_PFMAILBOX_PFU) {
885 ret_val = IXGBE_SUCCESS;
886 break;
887 }
888
889 /* Wait a bit before trying again */
890 usec_delay(mbx->usec_delay);
891 }
892
893 if (ret_val != IXGBE_SUCCESS) {
894 ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
895 "Failed to obtain mailbox lock");
896 ret_val = IXGBE_ERR_TIMEOUT;
897 }
898
899 return ret_val;
900 }
901
902 /**
903 * ixgbe_release_mbx_lock_pf - release mailbox lock
904 * @hw: pointer to the HW structure
905 * @vf_id: the VF index
906 **/
907 static void ixgbe_release_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_id)
908 {
909 u32 pf_mailbox;
910
911 DEBUGFUNC("ixgbe_release_mbx_lock_pf");
912
913 /* Return ownership of the buffer */
914 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
915 pf_mailbox &= ~IXGBE_PFMAILBOX_PFU;
916 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
917 }
918
919 /**
920 * ixgbe_write_mbx_pf_legacy - Places a message in the mailbox
921 * @hw: pointer to the HW structure
922 * @msg: The message buffer
923 * @size: Length of buffer
924 * @vf_id: the VF index
925 *
926 * returns SUCCESS if it successfully copied message into the buffer
927 **/
928 static s32 ixgbe_write_mbx_pf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
929 u16 vf_id)
930 {
931 s32 ret_val;
932 u16 i;
933
934 DEBUGFUNC("ixgbe_write_mbx_pf_legacy");
935
936 /* lock the mailbox to prevent pf/vf race condition */
937 ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
938 if (ret_val)
939 return ret_val;
940
941 /* flush msg and acks as we are overwriting the message buffer */
942 ixgbe_check_for_msg_pf(hw, vf_id);
943 ixgbe_clear_msg_pf(hw, vf_id);
944 ixgbe_check_for_ack_pf(hw, vf_id);
945 ixgbe_clear_ack_pf(hw, vf_id);
946
947 /* copy the caller specified message to the mailbox memory buffer */
948 for (i = 0; i < size; i++)
949 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, msg[i]);
950
951 /* Interrupt VF to tell it a message has been sent and release buffer*/
952 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), IXGBE_PFMAILBOX_STS);
953
954 /* update stats */
955 hw->mbx.stats.msgs_tx.ev_count++;
956
957 return IXGBE_SUCCESS;
958 }
959
960 /**
961 * ixgbe_write_mbx_pf - Places a message in the mailbox
962 * @hw: pointer to the HW structure
963 * @msg: The message buffer
964 * @size: Length of buffer
965 * @vf_id: the VF index
966 *
967 * returns SUCCESS if it successfully copied message into the buffer
968 **/
969 static s32 ixgbe_write_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
970 u16 vf_id)
971 {
972 u32 pf_mailbox;
973 s32 ret_val;
974 u16 i;
975
976 DEBUGFUNC("ixgbe_write_mbx_pf");
977
978 /* lock the mailbox to prevent pf/vf race condition */
979 ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
980 if (ret_val)
981 goto out;
982
983 /* flush msg and acks as we are overwriting the message buffer */
984 ixgbe_clear_msg_pf(hw, vf_id);
985 ixgbe_clear_ack_pf(hw, vf_id);
986
987 /* copy the caller specified message to the mailbox memory buffer */
988 for (i = 0; i < size; i++)
989 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, msg[i]);
990
991 /* Interrupt VF to tell it a message has been sent */
992 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
993 pf_mailbox |= IXGBE_PFMAILBOX_STS;
994 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
995
996 /* if msg sent wait until we receive an ack */
997 ixgbe_poll_for_ack(hw, vf_id);
998
999 /* update stats */
1000 hw->mbx.stats.msgs_tx.ev_count++;
1001
1002 out:
1003 hw->mbx.ops[vf_id].release(hw, vf_id);
1004
1005 return ret_val;
1006
1007 }
1008
1009 /**
1010 * ixgbe_read_mbx_pf_legacy - Read a message from the mailbox
1011 * @hw: pointer to the HW structure
1012 * @msg: The message buffer
1013 * @size: Length of buffer
1014 * @vf_id: the VF index
1015 *
1016 * This function copies a message from the mailbox buffer to the caller's
1017 * memory buffer. The presumption is that the caller knows that there was
1018 * a message due to a VF request so no polling for message is needed.
1019 **/
1020 static s32 ixgbe_read_mbx_pf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
1021 u16 vf_id)
1022 {
1023 s32 ret_val;
1024 u16 i;
1025
1026 DEBUGFUNC("ixgbe_read_mbx_pf_legacy");
1027
1028 /* lock the mailbox to prevent pf/vf race condition */
1029 ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
1030 if (ret_val != IXGBE_SUCCESS)
1031 return ret_val;
1032
1033 /* copy the message to the mailbox memory buffer */
1034 for (i = 0; i < size; i++)
1035 msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i);
1036
1037 /* Acknowledge the message and release buffer */
1038 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), IXGBE_PFMAILBOX_ACK);
1039
1040 /* update stats */
1041 hw->mbx.stats.msgs_rx.ev_count++;
1042
1043 return IXGBE_SUCCESS;
1044 }
1045
1046 /**
1047 * ixgbe_read_mbx_pf - Read a message from the mailbox
1048 * @hw: pointer to the HW structure
1049 * @msg: The message buffer
1050 * @size: Length of buffer
1051 * @vf_id: the VF index
1052 *
1053 * This function copies a message from the mailbox buffer to the caller's
1054 * memory buffer. The presumption is that the caller knows that there was
1055 * a message due to a VF request so no polling for message is needed.
1056 **/
1057 static s32 ixgbe_read_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
1058 u16 vf_id)
1059 {
1060 u32 pf_mailbox;
1061 s32 ret_val;
1062 u16 i;
1063
1064 DEBUGFUNC("ixgbe_read_mbx_pf");
1065
1066 /* check if there is a message from VF */
1067 ret_val = ixgbe_check_for_msg_pf(hw, vf_id);
1068 if (ret_val != IXGBE_SUCCESS)
1069 return IXGBE_ERR_MBX_NOMSG;
1070
1071 ixgbe_clear_msg_pf(hw, vf_id);
1072
1073 /* copy the message to the mailbox memory buffer */
1074 for (i = 0; i < size; i++)
1075 msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i);
1076
1077 /* Acknowledge the message and release buffer */
1078 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
1079 pf_mailbox |= IXGBE_PFMAILBOX_ACK;
1080 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
1081
1082 /* update stats */
1083 hw->mbx.stats.msgs_rx.ev_count++;
1084
1085 return IXGBE_SUCCESS;
1086 }
1087
1088 /**
1089 * ixgbe_clear_mbx_pf - Clear Mailbox Memory
1090 * @hw: pointer to the HW structure
1091 * @vf_id: the VF index
1092 *
1093 * Set VFMBMEM of given VF to 0x0.
1094 **/
1095 static s32 ixgbe_clear_mbx_pf(struct ixgbe_hw *hw, u16 vf_id)
1096 {
1097 u16 mbx_size = hw->mbx.size;
1098 u16 i;
1099
1100 if (vf_id > 63)
1101 return IXGBE_ERR_PARAM;
1102
1103 for (i = 0; i < mbx_size; ++i)
1104 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, 0x0);
1105
1106 return IXGBE_SUCCESS;
1107 }
1108
1109 /**
1110 * ixgbe_init_mbx_params_pf_id - set initial values for pf mailbox
1111 * @hw: pointer to the HW structure
1112 * @vf_id: the VF index
1113 *
1114 * Initializes single set of the hw->mbx struct to correct values for pf mailbox
1115 * Set of legacy functions is being used here
1116 */
1117 void ixgbe_init_mbx_params_pf_id(struct ixgbe_hw *hw, u16 vf_id)
1118 {
1119 struct ixgbe_mbx_info *mbx = &hw->mbx;
1120
1121 mbx->ops[vf_id].release = ixgbe_release_mbx_lock_dummy;
1122 mbx->ops[vf_id].read = ixgbe_read_mbx_pf_legacy;
1123 mbx->ops[vf_id].write = ixgbe_write_mbx_pf_legacy;
1124 mbx->ops[vf_id].check_for_msg = ixgbe_check_for_msg_pf;
1125 mbx->ops[vf_id].check_for_ack = ixgbe_check_for_ack_pf;
1126 mbx->ops[vf_id].check_for_rst = ixgbe_check_for_rst_pf;
1127 mbx->ops[vf_id].clear = ixgbe_clear_mbx_pf;
1128 }
1129
1130 /**
1131 * ixgbe_init_mbx_params_pf - set initial values for pf mailbox
1132 * @hw: pointer to the HW structure
1133 *
1134 * Initializes all sets of the hw->mbx struct to correct values for pf
1135 * mailbox. One set corresponds to single VF. It also initializes counters
1136 * and general variables. A set of legacy functions is used by default.
1137 */
1138 void ixgbe_init_mbx_params_pf(struct ixgbe_hw *hw)
1139 {
1140 u16 i;
1141 struct ixgbe_mbx_info *mbx = &hw->mbx;
1142
1143 /* Ensure we are not calling this function from VF */
1144 if (hw->mac.type != ixgbe_mac_82599EB &&
1145 hw->mac.type != ixgbe_mac_X550 &&
1146 hw->mac.type != ixgbe_mac_X550EM_x &&
1147 hw->mac.type != ixgbe_mac_X550EM_a &&
1148 hw->mac.type != ixgbe_mac_X540)
1149 return;
1150
1151 /* Initialize common mailbox settings */
1152 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
1153 mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
1154 mbx->size = IXGBE_VFMAILBOX_SIZE;
1155
1156 /* Initialize counters with zeroes */
1157 mbx->stats.msgs_tx.ev_count = 0;
1158 mbx->stats.msgs_rx.ev_count = 0;
1159 mbx->stats.reqs.ev_count = 0;
1160 mbx->stats.acks.ev_count = 0;
1161 mbx->stats.rsts.ev_count = 0;
1162
1163 /* No matter of VF number, we initialize params for all 64 VFs. */
1164 /* TODO: 1. Add a define for max VF and refactor SHARED to get rid
1165 * of magic number for that (63 or 64 depending on use case.)
1166 * 2. rewrite the code to dynamically allocate mbx->ops[vf_id] for
1167 * certain number of VFs instead of default maximum value of 64 (0..63)
1168 */
1169 for (i = 0; i < 64; i++)
1170 ixgbe_init_mbx_params_pf_id(hw, i);
1171 }
1172
1173 /**
1174 * ixgbe_upgrade_mbx_params_pf - Upgrade initial values for pf mailbox
1175 * @hw: pointer to the HW structure
1176 * @vf_id: the VF index
1177 *
1178 * Initializes the hw->mbx struct to new function set for improved
1179 * stability and handling of messages.
1180 */
1181 void ixgbe_upgrade_mbx_params_pf(struct ixgbe_hw *hw, u16 vf_id)
1182 {
1183 struct ixgbe_mbx_info *mbx = &hw->mbx;
1184
1185 /* Ensure we are not calling this function from VF */
1186 if (hw->mac.type != ixgbe_mac_82599EB &&
1187 hw->mac.type != ixgbe_mac_X550 &&
1188 hw->mac.type != ixgbe_mac_X550EM_x &&
1189 hw->mac.type != ixgbe_mac_X550EM_a &&
1190 hw->mac.type != ixgbe_mac_X540)
1191 return;
1192
1193 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
1194 mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
1195 mbx->size = IXGBE_VFMAILBOX_SIZE;
1196
1197 mbx->ops[vf_id].release = ixgbe_release_mbx_lock_pf;
1198 mbx->ops[vf_id].read = ixgbe_read_mbx_pf;
1199 mbx->ops[vf_id].write = ixgbe_write_mbx_pf;
1200 mbx->ops[vf_id].check_for_msg = ixgbe_check_for_msg_pf;
1201 mbx->ops[vf_id].check_for_ack = ixgbe_check_for_ack_pf;
1202 mbx->ops[vf_id].check_for_rst = ixgbe_check_for_rst_pf;
1203 mbx->ops[vf_id].clear = ixgbe_clear_mbx_pf;
1204
1205 mbx->stats.msgs_tx.ev_count = 0;
1206 mbx->stats.msgs_rx.ev_count = 0;
1207 mbx->stats.reqs.ev_count = 0;
1208 mbx->stats.acks.ev_count = 0;
1209 mbx->stats.rsts.ev_count = 0;
1210 }
1211