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