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