aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlexander Duyck <alexander.h.duyck@intel.com>2009-10-05 02:33:46 -0400
committerDavid S. Miller <davem@davemloft.net>2009-10-06 17:59:20 -0400
commit0acb6fde5fc84009be1c7efc0aaa8e69e394a2e2 (patch)
tree266ae1b7b50bac51992a0ca4b7605949b0dde192 /drivers
parent747d49baaf4e3f4ad5ae77477830da026eeef69d (diff)
igb: add function to handle mailbox lock
Both the read and write mailbox functions need to acquire the mailbox lock. Since that is the case we might as well combine both of the procedures into one function so it is easier to maintain. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/igb/e1000_mbx.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/drivers/net/igb/e1000_mbx.c b/drivers/net/igb/e1000_mbx.c
index ed9058eca45c..ef645f604d89 100644
--- a/drivers/net/igb/e1000_mbx.c
+++ b/drivers/net/igb/e1000_mbx.c
@@ -305,6 +305,30 @@ static s32 igb_check_for_rst_pf(struct e1000_hw *hw, u16 vf_number)
305} 305}
306 306
307/** 307/**
308 * igb_obtain_mbx_lock_pf - obtain mailbox lock
309 * @hw: pointer to the HW structure
310 * @vf_number: the VF index
311 *
312 * return SUCCESS if we obtained the mailbox lock
313 **/
314static s32 igb_obtain_mbx_lock_pf(struct e1000_hw *hw, u16 vf_number)
315{
316 s32 ret_val = -E1000_ERR_MBX;
317 u32 p2v_mailbox;
318
319
320 /* Take ownership of the buffer */
321 wr32(E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_PFU);
322
323 /* reserve mailbox for vf use */
324 p2v_mailbox = rd32(E1000_P2VMAILBOX(vf_number));
325 if (p2v_mailbox & E1000_P2VMAILBOX_PFU)
326 ret_val = 0;
327
328 return ret_val;
329}
330
331/**
308 * igb_write_mbx_pf - Places a message in the mailbox 332 * igb_write_mbx_pf - Places a message in the mailbox
309 * @hw: pointer to the HW structure 333 * @hw: pointer to the HW structure
310 * @msg: The message buffer 334 * @msg: The message buffer
@@ -316,27 +340,17 @@ static s32 igb_check_for_rst_pf(struct e1000_hw *hw, u16 vf_number)
316static s32 igb_write_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size, 340static s32 igb_write_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
317 u16 vf_number) 341 u16 vf_number)
318{ 342{
319 u32 p2v_mailbox; 343 s32 ret_val;
320 s32 ret_val = 0;
321 u16 i; 344 u16 i;
322 345
323 /* Take ownership of the buffer */ 346 /* lock the mailbox to prevent pf/vf race condition */
324 wr32(E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_PFU); 347 ret_val = igb_obtain_mbx_lock_pf(hw, vf_number);
325 348 if (ret_val)
326 /* Make sure we have ownership now... */
327 p2v_mailbox = rd32(E1000_P2VMAILBOX(vf_number));
328 if (!(p2v_mailbox & E1000_P2VMAILBOX_PFU)) {
329 /* failed to grab ownership */
330 ret_val = -E1000_ERR_MBX;
331 goto out_no_write; 349 goto out_no_write;
332 }
333 350
334 /* 351 /* flush msg and acks as we are overwriting the message buffer */
335 * flush any ack or msg which may already be in the queue
336 * as they are likely the result of an error
337 */
338 igb_check_for_ack_pf(hw, vf_number);
339 igb_check_for_msg_pf(hw, vf_number); 352 igb_check_for_msg_pf(hw, vf_number);
353 igb_check_for_ack_pf(hw, vf_number);
340 354
341 /* copy the caller specified message to the mailbox memory buffer */ 355 /* copy the caller specified message to the mailbox memory buffer */
342 for (i = 0; i < size; i++) 356 for (i = 0; i < size; i++)
@@ -367,20 +381,13 @@ out_no_write:
367static s32 igb_read_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size, 381static s32 igb_read_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
368 u16 vf_number) 382 u16 vf_number)
369{ 383{
370 u32 p2v_mailbox; 384 s32 ret_val;
371 s32 ret_val = 0;
372 u16 i; 385 u16 i;
373 386
374 /* Take ownership of the buffer */ 387 /* lock the mailbox to prevent pf/vf race condition */
375 wr32(E1000_P2VMAILBOX(vf_number), E1000_P2VMAILBOX_PFU); 388 ret_val = igb_obtain_mbx_lock_pf(hw, vf_number);
376 389 if (ret_val)
377 /* Make sure we have ownership now... */
378 p2v_mailbox = rd32(E1000_P2VMAILBOX(vf_number));
379 if (!(p2v_mailbox & E1000_P2VMAILBOX_PFU)) {
380 /* failed to grab ownership */
381 ret_val = -E1000_ERR_MBX;
382 goto out_no_read; 390 goto out_no_read;
383 }
384 391
385 /* copy the message to the mailbox memory buffer */ 392 /* copy the message to the mailbox memory buffer */
386 for (i = 0; i < size; i++) 393 for (i = 0; i < size; i++)
@@ -392,8 +399,6 @@ static s32 igb_read_mbx_pf(struct e1000_hw *hw, u32 *msg, u16 size,
392 /* update stats */ 399 /* update stats */
393 hw->mbx.stats.msgs_rx++; 400 hw->mbx.stats.msgs_rx++;
394 401
395 ret_val = 0;
396
397out_no_read: 402out_no_read:
398 return ret_val; 403 return ret_val;
399} 404}