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