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