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