i40e: move to drivers/net/
[dpdk.git] / lib / librte_pmd_ixgbe / ixgbe / ixgbe_mbx.c
index 1f885bb..c00c2f7 100644 (file)
@@ -1,6 +1,6 @@
 /*******************************************************************************
 
-Copyright (c) 2001-2012, Intel Corporation
+Copyright (c) 2001-2014, Intel Corporation
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
  *  @size: Length of buffer
  *  @mbx_id: id of mailbox to read
  *
- *  returns SUCCESS if it successfuly read message from buffer
+ *  returns SUCCESS if it successfully read message from buffer
  **/
 s32 ixgbe_read_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
 {
@@ -76,10 +76,11 @@ s32 ixgbe_write_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
 
        DEBUGFUNC("ixgbe_write_mbx");
 
-       if (size > mbx->size)
+       if (size > mbx->size) {
                ret_val = IXGBE_ERR_MBX;
-
-       else if (mbx->ops.write)
+               ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
+                            "Invalid mailbox message size %d", size);
+       } else if (mbx->ops.write)
                ret_val = mbx->ops.write(hw, msg, size, mbx_id);
 
        return ret_val;
@@ -152,7 +153,7 @@ s32 ixgbe_check_for_rst(struct ixgbe_hw *hw, u16 mbx_id)
  *
  *  returns SUCCESS if it successfully received a message notification
  **/
-static s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
+STATIC s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
 {
        struct ixgbe_mbx_info *mbx = &hw->mbx;
        int countdown = mbx->timeout;
@@ -169,6 +170,10 @@ static s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
                usec_delay(mbx->usec_delay);
        }
 
+       if (countdown == 0)
+               ERROR_REPORT2(IXGBE_ERROR_POLLING,
+                          "Polling for VF%d mailbox message timedout", mbx_id);
+
 out:
        return countdown ? IXGBE_SUCCESS : IXGBE_ERR_MBX;
 }
@@ -180,7 +185,7 @@ out:
  *
  *  returns SUCCESS if it successfully received a message acknowledgement
  **/
-static s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
+STATIC s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
 {
        struct ixgbe_mbx_info *mbx = &hw->mbx;
        int countdown = mbx->timeout;
@@ -197,6 +202,10 @@ static s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
                usec_delay(mbx->usec_delay);
        }
 
+       if (countdown == 0)
+               ERROR_REPORT2(IXGBE_ERROR_POLLING,
+                            "Polling for VF%d mailbox ack timedout", mbx_id);
+
 out:
        return countdown ? IXGBE_SUCCESS : IXGBE_ERR_MBX;
 }
@@ -241,7 +250,7 @@ out:
  *  received an ack to that message within delay * timeout period
  **/
 s32 ixgbe_write_posted_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size,
-                           u16 mbx_id)
+                          u16 mbx_id)
 {
        struct ixgbe_mbx_info *mbx = &hw->mbx;
        s32 ret_val = IXGBE_ERR_MBX;
@@ -283,7 +292,7 @@ void ixgbe_init_mbx_ops_generic(struct ixgbe_hw *hw)
  *  This function is used to read the v2p mailbox without losing the read to
  *  clear status bits.
  **/
-static u32 ixgbe_read_v2p_mailbox(struct ixgbe_hw *hw)
+STATIC u32 ixgbe_read_v2p_mailbox(struct ixgbe_hw *hw)
 {
        u32 v2p_mailbox = IXGBE_READ_REG(hw, IXGBE_VFMAILBOX);
 
@@ -301,7 +310,7 @@ static u32 ixgbe_read_v2p_mailbox(struct ixgbe_hw *hw)
  *  This function is used to check for the read to clear bits within
  *  the V2P mailbox.
  **/
-static s32 ixgbe_check_for_bit_vf(struct ixgbe_hw *hw, u32 mask)
+STATIC s32 ixgbe_check_for_bit_vf(struct ixgbe_hw *hw, u32 mask)
 {
        u32 v2p_mailbox = ixgbe_read_v2p_mailbox(hw);
        s32 ret_val = IXGBE_ERR_MBX;
@@ -321,7 +330,7 @@ static s32 ixgbe_check_for_bit_vf(struct ixgbe_hw *hw, u32 mask)
  *
  *  returns SUCCESS if the PF has set the Status bit or else ERR_MBX
  **/
-static s32 ixgbe_check_for_msg_vf(struct ixgbe_hw *hw, u16 mbx_id)
+STATIC s32 ixgbe_check_for_msg_vf(struct ixgbe_hw *hw, u16 mbx_id)
 {
        s32 ret_val = IXGBE_ERR_MBX;
 
@@ -343,7 +352,7 @@ static s32 ixgbe_check_for_msg_vf(struct ixgbe_hw *hw, u16 mbx_id)
  *
  *  returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
  **/
-static s32 ixgbe_check_for_ack_vf(struct ixgbe_hw *hw, u16 mbx_id)
+STATIC s32 ixgbe_check_for_ack_vf(struct ixgbe_hw *hw, u16 mbx_id)
 {
        s32 ret_val = IXGBE_ERR_MBX;
 
@@ -363,9 +372,9 @@ static s32 ixgbe_check_for_ack_vf(struct ixgbe_hw *hw, u16 mbx_id)
  *  @hw: pointer to the HW structure
  *  @mbx_id: id of mailbox to check
  *
- *  returns TRUE if the PF has set the reset done bit or else FALSE
+ *  returns true if the PF has set the reset done bit or else false
  **/
-static s32 ixgbe_check_for_rst_vf(struct ixgbe_hw *hw, u16 mbx_id)
+STATIC s32 ixgbe_check_for_rst_vf(struct ixgbe_hw *hw, u16 mbx_id)
 {
        s32 ret_val = IXGBE_ERR_MBX;
 
@@ -373,7 +382,7 @@ static s32 ixgbe_check_for_rst_vf(struct ixgbe_hw *hw, u16 mbx_id)
        DEBUGFUNC("ixgbe_check_for_rst_vf");
 
        if (!ixgbe_check_for_bit_vf(hw, (IXGBE_VFMAILBOX_RSTD |
-                                        IXGBE_VFMAILBOX_RSTI))) {
+           IXGBE_VFMAILBOX_RSTI))) {
                ret_val = IXGBE_SUCCESS;
                hw->mbx.stats.rsts++;
        }
@@ -387,7 +396,7 @@ static s32 ixgbe_check_for_rst_vf(struct ixgbe_hw *hw, u16 mbx_id)
  *
  *  return SUCCESS if we obtained the mailbox lock
  **/
-static s32 ixgbe_obtain_mbx_lock_vf(struct ixgbe_hw *hw)
+STATIC s32 ixgbe_obtain_mbx_lock_vf(struct ixgbe_hw *hw)
 {
        s32 ret_val = IXGBE_ERR_MBX;
 
@@ -412,8 +421,8 @@ static s32 ixgbe_obtain_mbx_lock_vf(struct ixgbe_hw *hw)
  *
  *  returns SUCCESS if it successfully copied message into the buffer
  **/
-static s32 ixgbe_write_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
-                              u16 mbx_id)
+STATIC s32 ixgbe_write_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
+                             u16 mbx_id)
 {
        s32 ret_val;
        u16 i;
@@ -435,6 +444,17 @@ static s32 ixgbe_write_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
        for (i = 0; i < size; i++)
                IXGBE_WRITE_REG_ARRAY(hw, IXGBE_VFMBMEM, i, msg[i]);
 
+       /*
+        * Complete the remaining mailbox data registers with zero to reset
+        * the data sent in a previous exchange (in either side) with the PF,
+        * including exchanges performed by another Guest OS to which that VF
+        * was previously assigned.
+        */
+       while (i < hw->mbx.size) {
+               IXGBE_WRITE_REG_ARRAY(hw, IXGBE_VFMBMEM, i, 0);
+               i++;
+       }
+
        /* update stats */
        hw->mbx.stats.msgs_tx++;
 
@@ -452,10 +472,10 @@ out_no_write:
  *  @size: Length of buffer
  *  @mbx_id: id of mailbox to read
  *
- *  returns SUCCESS if it successfuly read message from buffer
+ *  returns SUCCESS if it successfully read message from buffer
  **/
-static s32 ixgbe_read_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
-                             u16 mbx_id)
+STATIC s32 ixgbe_read_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
+                            u16 mbx_id)
 {
        s32 ret_val = IXGBE_SUCCESS;
        u16 i;
@@ -514,7 +534,7 @@ void ixgbe_init_mbx_params_vf(struct ixgbe_hw *hw)
        mbx->stats.rsts = 0;
 }
 
-static s32 ixgbe_check_for_bit_pf(struct ixgbe_hw *hw, u32 mask, s32 index)
+STATIC s32 ixgbe_check_for_bit_pf(struct ixgbe_hw *hw, u32 mask, s32 index)
 {
        u32 mbvficr = IXGBE_READ_REG(hw, IXGBE_MBVFICR(index));
        s32 ret_val = IXGBE_ERR_MBX;
@@ -534,7 +554,7 @@ static s32 ixgbe_check_for_bit_pf(struct ixgbe_hw *hw, u32 mask, s32 index)
  *
  *  returns SUCCESS if the VF has set the Status bit or else ERR_MBX
  **/
-static s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_number)
+STATIC s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_number)
 {
        s32 ret_val = IXGBE_ERR_MBX;
        s32 index = IXGBE_MBVFICR_INDEX(vf_number);
@@ -543,7 +563,7 @@ static s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_number)
        DEBUGFUNC("ixgbe_check_for_msg_pf");
 
        if (!ixgbe_check_for_bit_pf(hw, IXGBE_MBVFICR_VFREQ_VF1 << vf_bit,
-                                   index)) {
+                                   index)) {
                ret_val = IXGBE_SUCCESS;
                hw->mbx.stats.reqs++;
        }
@@ -558,7 +578,7 @@ static s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_number)
  *
  *  returns SUCCESS if the VF has set the Status bit or else ERR_MBX
  **/
-static s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_number)
+STATIC s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_number)
 {
        s32 ret_val = IXGBE_ERR_MBX;
        s32 index = IXGBE_MBVFICR_INDEX(vf_number);
@@ -567,7 +587,7 @@ static s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_number)
        DEBUGFUNC("ixgbe_check_for_ack_pf");
 
        if (!ixgbe_check_for_bit_pf(hw, IXGBE_MBVFICR_VFACK_VF1 << vf_bit,
-                                   index)) {
+                                   index)) {
                ret_val = IXGBE_SUCCESS;
                hw->mbx.stats.acks++;
        }
@@ -582,7 +602,7 @@ static s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_number)
  *
  *  returns SUCCESS if the VF has set the Status bit or else ERR_MBX
  **/
-static s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_number)
+STATIC s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_number)
 {
        u32 reg_offset = (vf_number < 32) ? 0 : 1;
        u32 vf_shift = vf_number % 32;
@@ -595,6 +615,8 @@ static s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_number)
        case ixgbe_mac_82599EB:
                vflre = IXGBE_READ_REG(hw, IXGBE_VFLRE(reg_offset));
                break;
+       case ixgbe_mac_X550:
+       case ixgbe_mac_X550EM_x:
        case ixgbe_mac_X540:
                vflre = IXGBE_READ_REG(hw, IXGBE_VFLREC(reg_offset));
                break;
@@ -618,7 +640,7 @@ static s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_number)
  *
  *  return SUCCESS if we obtained the mailbox lock
  **/
-static s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_number)
+STATIC s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_number)
 {
        s32 ret_val = IXGBE_ERR_MBX;
        u32 p2v_mailbox;
@@ -632,6 +654,10 @@ static s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_number)
        p2v_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_number));
        if (p2v_mailbox & IXGBE_PFMAILBOX_PFU)
                ret_val = IXGBE_SUCCESS;
+       else
+               ERROR_REPORT2(IXGBE_ERROR_POLLING,
+                          "Failed to obtain mailbox lock for VF%d", vf_number);
+
 
        return ret_val;
 }
@@ -645,8 +671,8 @@ static s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_number)
  *
  *  returns SUCCESS if it successfully copied message into the buffer
  **/
-static s32 ixgbe_write_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
-                              u16 vf_number)
+STATIC s32 ixgbe_write_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
+                             u16 vf_number)
 {
        s32 ret_val;
        u16 i;
@@ -666,6 +692,17 @@ static s32 ixgbe_write_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
        for (i = 0; i < size; i++)
                IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i, msg[i]);
 
+       /*
+        * Complete the remaining mailbox data registers with zero to reset
+        * the data sent in a previous exchange (in either side) with the VF,
+        * including exchanges performed by another Guest OS to which that VF
+        * was previously assigned.
+        */
+       while (i < hw->mbx.size) {
+               IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_number), i, 0);
+               i++;
+       }
+
        /* Interrupt VF to tell it a message has been sent and release buffer*/
        IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_number), IXGBE_PFMAILBOX_STS);
 
@@ -688,8 +725,8 @@ out_no_write:
  *  memory buffer.  The presumption is that the caller knows that there was
  *  a message due to a VF request so no polling for message is needed.
  **/
-static s32 ixgbe_read_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
-                             u16 vf_number)
+STATIC s32 ixgbe_read_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
+                            u16 vf_number)
 {
        s32 ret_val;
        u16 i;
@@ -726,6 +763,8 @@ void ixgbe_init_mbx_params_pf(struct ixgbe_hw *hw)
        struct ixgbe_mbx_info *mbx = &hw->mbx;
 
        if (hw->mac.type != ixgbe_mac_82599EB &&
+           hw->mac.type != ixgbe_mac_X550 &&
+           hw->mac.type != ixgbe_mac_X550EM_x &&
            hw->mac.type != ixgbe_mac_X540)
                return;