ixgbe_mbx.c revision 1.17 1 /* $NetBSD: ixgbe_mbx.c,v 1.17 2022/01/18 09:16:38 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.17 2022/01/18 09:16:38 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
726 static void ixgbe_clear_msg_pf(struct ixgbe_hw *hw, u16 vf_id)
727 {
728 u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
729 s32 index = IXGBE_PFMBICR_INDEX(vf_id);
730 u32 pfmbicr;
731
732 pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
733
734 if (pfmbicr & (IXGBE_PFMBICR_VFREQ_VF1 << vf_shift))
735 hw->mbx.stats.reqs.ev_count++;
736
737 IXGBE_WRITE_REG(hw, IXGBE_PFMBICR(index),
738 IXGBE_PFMBICR_VFREQ_VF1 << vf_shift);
739 }
740
741 static void ixgbe_clear_ack_pf(struct ixgbe_hw *hw, u16 vf_id)
742 {
743 u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
744 s32 index = IXGBE_PFMBICR_INDEX(vf_id);
745 u32 pfmbicr;
746
747 pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
748
749 if (pfmbicr & (IXGBE_PFMBICR_VFACK_VF1 << vf_shift))
750 hw->mbx.stats.acks.ev_count++;
751
752 IXGBE_WRITE_REG(hw, IXGBE_PFMBICR(index),
753 IXGBE_PFMBICR_VFACK_VF1 << vf_shift);
754 }
755
756 static s32 ixgbe_check_for_bit_pf(struct ixgbe_hw *hw, u32 mask, s32 index)
757 {
758 u32 pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
759
760 if (pfmbicr & mask)
761 return IXGBE_SUCCESS;
762
763 return IXGBE_ERR_MBX;
764 }
765
766 /**
767 * ixgbe_check_for_msg_pf - checks to see if the VF has sent mail
768 * @hw: pointer to the HW structure
769 * @vf_id: the VF index
770 *
771 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
772 **/
773 static s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_id)
774 {
775 u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
776 s32 index = IXGBE_PFMBICR_INDEX(vf_id);
777
778 DEBUGFUNC("ixgbe_check_for_msg_pf");
779
780 if (!ixgbe_check_for_bit_pf(hw, IXGBE_PFMBICR_VFREQ_VF1 << vf_shift,
781 index))
782 return IXGBE_SUCCESS;
783
784 return IXGBE_ERR_MBX;
785 }
786
787 /**
788 * ixgbe_check_for_ack_pf - checks to see if the VF has ACKed
789 * @hw: pointer to the HW structure
790 * @vf_id: the VF index
791 *
792 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
793 **/
794 static s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_id)
795 {
796 u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
797 s32 index = IXGBE_PFMBICR_INDEX(vf_id);
798 s32 ret_val = IXGBE_ERR_MBX;
799
800 DEBUGFUNC("ixgbe_check_for_ack_pf");
801
802 if (!ixgbe_check_for_bit_pf(hw, IXGBE_PFMBICR_VFACK_VF1 << vf_shift,
803 index)) {
804 ret_val = IXGBE_SUCCESS;
805 /* TODO: should this be autocleared? */
806 ixgbe_clear_ack_pf(hw, vf_id);
807 }
808
809 return ret_val;
810 }
811
812 /**
813 * ixgbe_check_for_rst_pf - checks to see if the VF has reset
814 * @hw: pointer to the HW structure
815 * @vf_id: the VF index
816 *
817 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
818 **/
819 static s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_id)
820 {
821 u32 vf_shift = IXGBE_PFVFLRE_SHIFT(vf_id);
822 u32 index = IXGBE_PFVFLRE_INDEX(vf_id);
823 s32 ret_val = IXGBE_ERR_MBX;
824 u32 vflre = 0;
825
826 DEBUGFUNC("ixgbe_check_for_rst_pf");
827
828 switch (hw->mac.type) {
829 case ixgbe_mac_82599EB:
830 vflre = IXGBE_READ_REG(hw, IXGBE_PFVFLRE(index));
831 break;
832 case ixgbe_mac_X550:
833 case ixgbe_mac_X550EM_x:
834 case ixgbe_mac_X550EM_a:
835 case ixgbe_mac_X540:
836 vflre = IXGBE_READ_REG(hw, IXGBE_PFVFLREC(index));
837 break;
838 default:
839 break;
840 }
841
842 if (vflre & (1 << vf_shift)) {
843 ret_val = IXGBE_SUCCESS;
844 IXGBE_WRITE_REG(hw, IXGBE_PFVFLREC(index), (1 << vf_shift));
845 hw->mbx.stats.rsts.ev_count++;
846 }
847
848 return ret_val;
849 }
850
851 /**
852 * ixgbe_obtain_mbx_lock_pf - obtain mailbox lock
853 * @hw: pointer to the HW structure
854 * @vf_id: the VF index
855 *
856 * return SUCCESS if we obtained the mailbox lock
857 **/
858 static s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_id)
859 {
860 struct ixgbe_mbx_info *mbx = &hw->mbx;
861 int countdown = mbx->timeout;
862 s32 ret_val = IXGBE_ERR_MBX;
863 u32 pf_mailbox;
864
865 DEBUGFUNC("ixgbe_obtain_mbx_lock_pf");
866
867 if (!mbx->timeout)
868 return IXGBE_ERR_CONFIG;
869
870 while (countdown--) {
871 /* Reserve mailbox for PF use */
872 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
873 pf_mailbox |= IXGBE_PFMAILBOX_PFU;
874 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
875
876 /* Verify that PF is the owner of the lock */
877 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
878 if (pf_mailbox & IXGBE_PFMAILBOX_PFU) {
879 ret_val = IXGBE_SUCCESS;
880 break;
881 }
882
883 /* Wait a bit before trying again */
884 usec_delay(mbx->usec_delay);
885 }
886
887 if (ret_val != IXGBE_SUCCESS) {
888 ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
889 "Failed to obtain mailbox lock");
890 ret_val = IXGBE_ERR_TIMEOUT;
891 }
892
893 return ret_val;
894 }
895
896 /**
897 * ixgbe_release_mbx_lock_pf - release mailbox lock
898 * @hw: pointer to the HW structure
899 * @vf_id: the VF index
900 **/
901 static void ixgbe_release_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_id)
902 {
903 u32 pf_mailbox;
904
905 DEBUGFUNC("ixgbe_release_mbx_lock_pf");
906
907 /* Return ownership of the buffer */
908 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
909 pf_mailbox &= ~IXGBE_PFMAILBOX_PFU;
910 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
911 }
912
913 /**
914 * ixgbe_write_mbx_pf_legacy - Places a message in the mailbox
915 * @hw: pointer to the HW structure
916 * @msg: The message buffer
917 * @size: Length of buffer
918 * @vf_id: the VF index
919 *
920 * returns SUCCESS if it successfully copied message into the buffer
921 **/
922 static s32 ixgbe_write_mbx_pf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
923 u16 vf_id)
924 {
925 s32 ret_val;
926 u16 i;
927
928 DEBUGFUNC("ixgbe_write_mbx_pf_legacy");
929
930 /* lock the mailbox to prevent pf/vf race condition */
931 ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
932 if (ret_val)
933 return ret_val;
934
935 /* flush msg and acks as we are overwriting the message buffer */
936 ixgbe_check_for_msg_pf(hw, vf_id);
937 ixgbe_clear_msg_pf(hw, vf_id);
938 ixgbe_check_for_ack_pf(hw, vf_id);
939 ixgbe_clear_ack_pf(hw, vf_id);
940
941 /* copy the caller specified message to the mailbox memory buffer */
942 for (i = 0; i < size; i++)
943 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, msg[i]);
944
945 /* Interrupt VF to tell it a message has been sent and release buffer*/
946 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), IXGBE_PFMAILBOX_STS);
947
948 /* update stats */
949 hw->mbx.stats.msgs_tx.ev_count++;
950
951 return IXGBE_SUCCESS;
952 }
953
954 /**
955 * ixgbe_write_mbx_pf - Places a message in the mailbox
956 * @hw: pointer to the HW structure
957 * @msg: The message buffer
958 * @size: Length of buffer
959 * @vf_id: the VF index
960 *
961 * returns SUCCESS if it successfully copied message into the buffer
962 **/
963 static s32 ixgbe_write_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
964 u16 vf_id)
965 {
966 u32 pf_mailbox;
967 s32 ret_val;
968 u16 i;
969
970 DEBUGFUNC("ixgbe_write_mbx_pf");
971
972 /* lock the mailbox to prevent pf/vf race condition */
973 ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
974 if (ret_val)
975 goto out;
976
977 /* flush msg and acks as we are overwriting the message buffer */
978 ixgbe_clear_msg_pf(hw, vf_id);
979 ixgbe_clear_ack_pf(hw, vf_id);
980
981 /* copy the caller specified message to the mailbox memory buffer */
982 for (i = 0; i < size; i++)
983 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, msg[i]);
984
985 /* Interrupt VF to tell it a message has been sent */
986 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
987 pf_mailbox |= IXGBE_PFMAILBOX_STS;
988 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
989
990 /* if msg sent wait until we receive an ack */
991 ixgbe_poll_for_ack(hw, vf_id);
992
993 /* update stats */
994 hw->mbx.stats.msgs_tx.ev_count++;
995
996 out:
997 hw->mbx.ops[vf_id].release(hw, vf_id);
998
999 return ret_val;
1000
1001 }
1002
1003 /**
1004 * ixgbe_read_mbx_pf_legacy - Read a message from the mailbox
1005 * @hw: pointer to the HW structure
1006 * @msg: The message buffer
1007 * @size: Length of buffer
1008 * @vf_id: the VF index
1009 *
1010 * This function copies a message from the mailbox buffer to the caller's
1011 * memory buffer. The presumption is that the caller knows that there was
1012 * a message due to a VF request so no polling for message is needed.
1013 **/
1014 static s32 ixgbe_read_mbx_pf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
1015 u16 vf_id)
1016 {
1017 s32 ret_val;
1018 u16 i;
1019
1020 DEBUGFUNC("ixgbe_read_mbx_pf_legacy");
1021
1022 /* lock the mailbox to prevent pf/vf race condition */
1023 ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
1024 if (ret_val != IXGBE_SUCCESS)
1025 return ret_val;
1026
1027 /* copy the message to the mailbox memory buffer */
1028 for (i = 0; i < size; i++)
1029 msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i);
1030
1031 /* Acknowledge the message and release buffer */
1032 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), IXGBE_PFMAILBOX_ACK);
1033
1034 /* update stats */
1035 hw->mbx.stats.msgs_rx.ev_count++;
1036
1037 return IXGBE_SUCCESS;
1038 }
1039
1040 /**
1041 * ixgbe_read_mbx_pf - Read a message from the mailbox
1042 * @hw: pointer to the HW structure
1043 * @msg: The message buffer
1044 * @size: Length of buffer
1045 * @vf_id: the VF index
1046 *
1047 * This function copies a message from the mailbox buffer to the caller's
1048 * memory buffer. The presumption is that the caller knows that there was
1049 * a message due to a VF request so no polling for message is needed.
1050 **/
1051 static s32 ixgbe_read_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
1052 u16 vf_id)
1053 {
1054 u32 pf_mailbox;
1055 s32 ret_val;
1056 u16 i;
1057
1058 DEBUGFUNC("ixgbe_read_mbx_pf");
1059
1060 /* check if there is a message from VF */
1061 ret_val = ixgbe_check_for_msg_pf(hw, vf_id);
1062 if (ret_val != IXGBE_SUCCESS)
1063 return IXGBE_ERR_MBX_NOMSG;
1064
1065 ixgbe_clear_msg_pf(hw, vf_id);
1066
1067 /* copy the message to the mailbox memory buffer */
1068 for (i = 0; i < size; i++)
1069 msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i);
1070
1071 /* Acknowledge the message and release buffer */
1072 pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
1073 pf_mailbox |= IXGBE_PFMAILBOX_ACK;
1074 IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
1075
1076 /* update stats */
1077 hw->mbx.stats.msgs_rx.ev_count++;
1078
1079 return IXGBE_SUCCESS;
1080 }
1081
1082 /**
1083 * ixgbe_clear_mbx_pf - Clear Mailbox Memory
1084 * @hw: pointer to the HW structure
1085 * @vf_id: the VF index
1086 *
1087 * Set VFMBMEM of given VF to 0x0.
1088 **/
1089 static s32 ixgbe_clear_mbx_pf(struct ixgbe_hw *hw, u16 vf_id)
1090 {
1091 u16 mbx_size = hw->mbx.size;
1092 u16 i;
1093
1094 if (vf_id > 63)
1095 return IXGBE_ERR_PARAM;
1096
1097 for (i = 0; i < mbx_size; ++i)
1098 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, 0x0);
1099
1100 return IXGBE_SUCCESS;
1101 }
1102
1103 /**
1104 * ixgbe_init_mbx_params_pf_id - set initial values for pf mailbox
1105 * @hw: pointer to the HW structure
1106 * @vf_id: the VF index
1107 *
1108 * Initializes single set of the hw->mbx struct to correct values for pf mailbox
1109 * Set of legacy functions is being used here
1110 */
1111 void ixgbe_init_mbx_params_pf_id(struct ixgbe_hw *hw, u16 vf_id)
1112 {
1113 struct ixgbe_mbx_info *mbx = &hw->mbx;
1114
1115 mbx->ops[vf_id].release = ixgbe_release_mbx_lock_dummy;
1116 mbx->ops[vf_id].read = ixgbe_read_mbx_pf_legacy;
1117 mbx->ops[vf_id].write = ixgbe_write_mbx_pf_legacy;
1118 mbx->ops[vf_id].check_for_msg = ixgbe_check_for_msg_pf;
1119 mbx->ops[vf_id].check_for_ack = ixgbe_check_for_ack_pf;
1120 mbx->ops[vf_id].check_for_rst = ixgbe_check_for_rst_pf;
1121 mbx->ops[vf_id].clear = ixgbe_clear_mbx_pf;
1122 }
1123
1124 /**
1125 * ixgbe_init_mbx_params_pf - set initial values for pf mailbox
1126 * @hw: pointer to the HW structure
1127 *
1128 * Initializes all sets of the hw->mbx struct to correct values for pf
1129 * mailbox. One set corresponds to single VF. It also initializes counters
1130 * and general variables. A set of legacy functions is used by default.
1131 */
1132 void ixgbe_init_mbx_params_pf(struct ixgbe_hw *hw)
1133 {
1134 u16 i;
1135 struct ixgbe_mbx_info *mbx = &hw->mbx;
1136
1137 /* Ensure we are not calling this function from VF */
1138 if (hw->mac.type != ixgbe_mac_82599EB &&
1139 hw->mac.type != ixgbe_mac_X550 &&
1140 hw->mac.type != ixgbe_mac_X550EM_x &&
1141 hw->mac.type != ixgbe_mac_X550EM_a &&
1142 hw->mac.type != ixgbe_mac_X540)
1143 return;
1144
1145 /* Initialize common mailbox settings */
1146 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
1147 mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
1148 mbx->size = IXGBE_VFMAILBOX_SIZE;
1149
1150 /* Initialize counters with zeroes */
1151 mbx->stats.msgs_tx.ev_count = 0;
1152 mbx->stats.msgs_rx.ev_count = 0;
1153 mbx->stats.reqs.ev_count = 0;
1154 mbx->stats.acks.ev_count = 0;
1155 mbx->stats.rsts.ev_count = 0;
1156
1157 /* No matter of VF number, we initialize params for all 64 VFs. */
1158 /* TODO: 1. Add a define for max VF and refactor SHARED to get rid
1159 * of magic number for that (63 or 64 depending on use case.)
1160 * 2. rewrite the code to dynamically allocate mbx->ops[vf_id] for
1161 * certain number of VFs instead of default maximum value of 64 (0..63)
1162 */
1163 for (i = 0; i < 64; i++)
1164 ixgbe_init_mbx_params_pf_id(hw, i);
1165 }
1166
1167 /**
1168 * ixgbe_upgrade_mbx_params_pf - Upgrade initial values for pf mailbox
1169 * @hw: pointer to the HW structure
1170 * @vf_id: the VF index
1171 *
1172 * Initializes the hw->mbx struct to new function set for improved
1173 * stability and handling of messages.
1174 */
1175 void ixgbe_upgrade_mbx_params_pf(struct ixgbe_hw *hw, u16 vf_id)
1176 {
1177 struct ixgbe_mbx_info *mbx = &hw->mbx;
1178
1179 /* Ensure we are not calling this function from VF */
1180 if (hw->mac.type != ixgbe_mac_82599EB &&
1181 hw->mac.type != ixgbe_mac_X550 &&
1182 hw->mac.type != ixgbe_mac_X550EM_x &&
1183 hw->mac.type != ixgbe_mac_X550EM_a &&
1184 hw->mac.type != ixgbe_mac_X540)
1185 return;
1186
1187 mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
1188 mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
1189 mbx->size = IXGBE_VFMAILBOX_SIZE;
1190
1191 mbx->ops[vf_id].release = ixgbe_release_mbx_lock_pf;
1192 mbx->ops[vf_id].read = ixgbe_read_mbx_pf;
1193 mbx->ops[vf_id].write = ixgbe_write_mbx_pf;
1194 mbx->ops[vf_id].check_for_msg = ixgbe_check_for_msg_pf;
1195 mbx->ops[vf_id].check_for_ack = ixgbe_check_for_ack_pf;
1196 mbx->ops[vf_id].check_for_rst = ixgbe_check_for_rst_pf;
1197 mbx->ops[vf_id].clear = ixgbe_clear_mbx_pf;
1198
1199 mbx->stats.msgs_tx.ev_count = 0;
1200 mbx->stats.msgs_rx.ev_count = 0;
1201 mbx->stats.reqs.ev_count = 0;
1202 mbx->stats.acks.ev_count = 0;
1203 mbx->stats.rsts.ev_count = 0;
1204 }
1205