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