Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe_mbx.c revision 1.16
      1  1.16  msaitoh /* $NetBSD: ixgbe_mbx.c,v 1.16 2021/12/24 05:11:04 msaitoh Exp $ */
      2   1.7  msaitoh 
      3   1.1   dyoung /******************************************************************************
      4   1.9  msaitoh   SPDX-License-Identifier: BSD-3-Clause
      5   1.1   dyoung 
      6  1.14  msaitoh   Copyright (c) 2001-2020, Intel Corporation
      7   1.1   dyoung   All rights reserved.
      8   1.7  msaitoh 
      9   1.7  msaitoh   Redistribution and use in source and binary forms, with or without
     10   1.1   dyoung   modification, are permitted provided that the following conditions are met:
     11   1.7  msaitoh 
     12   1.7  msaitoh    1. Redistributions of source code must retain the above copyright notice,
     13   1.1   dyoung       this list of conditions and the following disclaimer.
     14   1.7  msaitoh 
     15   1.7  msaitoh    2. Redistributions in binary form must reproduce the above copyright
     16   1.7  msaitoh       notice, this list of conditions and the following disclaimer in the
     17   1.1   dyoung       documentation and/or other materials provided with the distribution.
     18   1.7  msaitoh 
     19   1.7  msaitoh    3. Neither the name of the Intel Corporation nor the names of its
     20   1.7  msaitoh       contributors may be used to endorse or promote products derived from
     21   1.1   dyoung       this software without specific prior written permission.
     22   1.7  msaitoh 
     23   1.1   dyoung   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     24   1.7  msaitoh   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.7  msaitoh   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.7  msaitoh   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     27   1.7  msaitoh   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28   1.7  msaitoh   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29   1.7  msaitoh   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30   1.7  msaitoh   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31   1.7  msaitoh   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32   1.1   dyoung   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33   1.1   dyoung   POSSIBILITY OF SUCH DAMAGE.
     34   1.1   dyoung 
     35   1.1   dyoung ******************************************************************************/
     36  1.10  msaitoh /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_mbx.c 326022 2017-11-20 19:36:21Z pfg $*/
     37   1.1   dyoung 
     38  1.12  msaitoh #include <sys/cdefs.h>
     39  1.16  msaitoh __KERNEL_RCSID(0, "$NetBSD: ixgbe_mbx.c,v 1.16 2021/12/24 05:11:04 msaitoh Exp $");
     40  1.12  msaitoh 
     41   1.1   dyoung #include "ixgbe_type.h"
     42   1.1   dyoung #include "ixgbe_mbx.h"
     43   1.1   dyoung 
     44  1.16  msaitoh static s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id);
     45  1.16  msaitoh static s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id);
     46  1.16  msaitoh 
     47   1.1   dyoung /**
     48  1.15  msaitoh  * ixgbe_read_mbx - Reads a message from the mailbox
     49  1.15  msaitoh  * @hw: pointer to the HW structure
     50  1.15  msaitoh  * @msg: The message buffer
     51  1.15  msaitoh  * @size: Length of buffer
     52  1.15  msaitoh  * @mbx_id: id of mailbox to read
     53  1.15  msaitoh  *
     54  1.15  msaitoh  * returns SUCCESS if it successfully read message from buffer
     55  1.15  msaitoh  **/
     56  1.15  msaitoh s32 ixgbe_read_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
     57  1.15  msaitoh {
     58  1.15  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
     59  1.15  msaitoh 
     60  1.15  msaitoh 	DEBUGFUNC("ixgbe_read_mbx");
     61  1.15  msaitoh 
     62  1.15  msaitoh 	/* limit read to size of mailbox */
     63  1.16  msaitoh 	if (size > mbx->size) {
     64  1.16  msaitoh 		ERROR_REPORT3(IXGBE_ERROR_ARGUMENT,
     65  1.16  msaitoh 			      "Invalid mailbox message size %u, changing to %u",
     66  1.16  msaitoh 			      size, mbx->size);
     67  1.16  msaitoh 		size = mbx->size;
     68  1.16  msaitoh 	}
     69  1.16  msaitoh 
     70  1.16  msaitoh 	if (mbx->ops[mbx_id].read)
     71  1.16  msaitoh 		return mbx->ops[mbx_id].read(hw, msg, size, mbx_id);
     72  1.16  msaitoh 
     73  1.16  msaitoh 	return IXGBE_ERR_CONFIG;
     74  1.16  msaitoh }
     75  1.16  msaitoh 
     76  1.16  msaitoh /**
     77  1.16  msaitoh  * ixgbe_poll_mbx - Wait for message and read it from the mailbox
     78  1.16  msaitoh  * @hw: pointer to the HW structure
     79  1.16  msaitoh  * @msg: The message buffer
     80  1.16  msaitoh  * @size: Length of buffer
     81  1.16  msaitoh  * @mbx_id: id of mailbox to read
     82  1.16  msaitoh  *
     83  1.16  msaitoh  * returns SUCCESS if it successfully read message from buffer
     84  1.16  msaitoh  **/
     85  1.16  msaitoh s32 ixgbe_poll_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
     86  1.16  msaitoh {
     87  1.16  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
     88  1.16  msaitoh 	s32 ret_val;
     89  1.16  msaitoh 
     90  1.16  msaitoh 	DEBUGFUNC("ixgbe_poll_mbx");
     91  1.16  msaitoh 
     92  1.16  msaitoh 	if (!mbx->ops[mbx_id].read || !mbx->ops[mbx_id].check_for_msg ||
     93  1.16  msaitoh 	    !mbx->timeout)
     94  1.16  msaitoh 		return IXGBE_ERR_CONFIG;
     95  1.16  msaitoh 
     96  1.16  msaitoh 	/* limit read to size of mailbox */
     97  1.16  msaitoh 	if (size > mbx->size) {
     98  1.16  msaitoh 		ERROR_REPORT3(IXGBE_ERROR_ARGUMENT,
     99  1.16  msaitoh 			      "Invalid mailbox message size %u, changing to %u",
    100  1.16  msaitoh 			      size, mbx->size);
    101  1.15  msaitoh 		size = mbx->size;
    102  1.16  msaitoh 	}
    103  1.15  msaitoh 
    104  1.16  msaitoh 	ret_val = ixgbe_poll_for_msg(hw, mbx_id);
    105  1.16  msaitoh 	/* if ack received read message, otherwise we timed out */
    106  1.16  msaitoh 	if (!ret_val)
    107  1.16  msaitoh 		return mbx->ops[mbx_id].read(hw, msg, size, mbx_id);
    108  1.15  msaitoh 
    109  1.15  msaitoh 	return ret_val;
    110  1.15  msaitoh }
    111  1.15  msaitoh 
    112  1.15  msaitoh /**
    113  1.16  msaitoh  * ixgbe_write_mbx - Write a message to the mailbox and wait for ACK
    114  1.15  msaitoh  * @hw: pointer to the HW structure
    115  1.15  msaitoh  * @msg: The message buffer
    116  1.15  msaitoh  * @size: Length of buffer
    117  1.15  msaitoh  * @mbx_id: id of mailbox to write
    118  1.15  msaitoh  *
    119  1.16  msaitoh  * returns SUCCESS if it successfully copied message into the buffer and
    120  1.16  msaitoh  * received an ACK to that message within specified period
    121  1.15  msaitoh  **/
    122  1.15  msaitoh s32 ixgbe_write_mbx(struct ixgbe_hw *hw, u32 *msg, u16 size, u16 mbx_id)
    123  1.15  msaitoh {
    124  1.15  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    125  1.16  msaitoh 	s32 ret_val = IXGBE_ERR_MBX;
    126  1.15  msaitoh 
    127  1.15  msaitoh 	DEBUGFUNC("ixgbe_write_mbx");
    128  1.15  msaitoh 
    129  1.16  msaitoh 	/*
    130  1.16  msaitoh 	 * exit if either we can't write, release
    131  1.16  msaitoh 	 * or there is no timeout defined
    132  1.16  msaitoh 	 */
    133  1.16  msaitoh 	if (!mbx->ops[mbx_id].write || !mbx->ops[mbx_id].check_for_ack ||
    134  1.16  msaitoh 	    !mbx->ops[mbx_id].release || !mbx->timeout)
    135  1.16  msaitoh 		return IXGBE_ERR_CONFIG;
    136  1.16  msaitoh 
    137  1.15  msaitoh 	if (size > mbx->size) {
    138  1.16  msaitoh 		ret_val = IXGBE_ERR_PARAM;
    139  1.15  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
    140  1.16  msaitoh 			     "Invalid mailbox message size %u", size);
    141  1.16  msaitoh 	} else {
    142  1.16  msaitoh 		ret_val = mbx->ops[mbx_id].write(hw, msg, size, mbx_id);
    143  1.16  msaitoh 	}
    144  1.15  msaitoh 
    145  1.15  msaitoh 	return ret_val;
    146  1.15  msaitoh }
    147  1.15  msaitoh 
    148  1.15  msaitoh /**
    149  1.15  msaitoh  * ixgbe_check_for_msg - checks to see if someone sent us mail
    150  1.15  msaitoh  * @hw: pointer to the HW structure
    151  1.15  msaitoh  * @mbx_id: id of mailbox to check
    152  1.15  msaitoh  *
    153  1.15  msaitoh  * returns SUCCESS if the Status bit was found or else ERR_MBX
    154  1.15  msaitoh  **/
    155  1.15  msaitoh s32 ixgbe_check_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
    156  1.15  msaitoh {
    157  1.15  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    158  1.16  msaitoh 	s32 ret_val = IXGBE_ERR_CONFIG;
    159  1.15  msaitoh 
    160  1.15  msaitoh 	DEBUGFUNC("ixgbe_check_for_msg");
    161  1.15  msaitoh 
    162  1.16  msaitoh 	if (mbx->ops[mbx_id].check_for_msg)
    163  1.16  msaitoh 		ret_val = mbx->ops[mbx_id].check_for_msg(hw, mbx_id);
    164  1.15  msaitoh 
    165  1.15  msaitoh 	return ret_val;
    166  1.15  msaitoh }
    167  1.15  msaitoh 
    168  1.15  msaitoh /**
    169  1.15  msaitoh  * ixgbe_check_for_ack - checks to see if someone sent us ACK
    170  1.15  msaitoh  * @hw: pointer to the HW structure
    171  1.15  msaitoh  * @mbx_id: id of mailbox to check
    172  1.15  msaitoh  *
    173  1.15  msaitoh  * returns SUCCESS if the Status bit was found or else ERR_MBX
    174  1.15  msaitoh  **/
    175  1.15  msaitoh s32 ixgbe_check_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
    176  1.15  msaitoh {
    177  1.15  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    178  1.16  msaitoh 	s32 ret_val = IXGBE_ERR_CONFIG;
    179  1.15  msaitoh 
    180  1.15  msaitoh 	DEBUGFUNC("ixgbe_check_for_ack");
    181  1.15  msaitoh 
    182  1.16  msaitoh 	if (mbx->ops[mbx_id].check_for_ack)
    183  1.16  msaitoh 		ret_val = mbx->ops[mbx_id].check_for_ack(hw, mbx_id);
    184  1.15  msaitoh 
    185  1.15  msaitoh 	return ret_val;
    186  1.15  msaitoh }
    187  1.15  msaitoh 
    188  1.15  msaitoh /**
    189  1.15  msaitoh  * ixgbe_check_for_rst - checks to see if other side has reset
    190  1.15  msaitoh  * @hw: pointer to the HW structure
    191  1.15  msaitoh  * @mbx_id: id of mailbox to check
    192  1.15  msaitoh  *
    193  1.15  msaitoh  * returns SUCCESS if the Status bit was found or else ERR_MBX
    194  1.15  msaitoh  **/
    195  1.15  msaitoh s32 ixgbe_check_for_rst(struct ixgbe_hw *hw, u16 mbx_id)
    196  1.15  msaitoh {
    197  1.15  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    198  1.16  msaitoh 	s32 ret_val = IXGBE_ERR_CONFIG;
    199  1.15  msaitoh 
    200  1.15  msaitoh 	DEBUGFUNC("ixgbe_check_for_rst");
    201  1.15  msaitoh 
    202  1.16  msaitoh 	if (mbx->ops[mbx_id].check_for_rst)
    203  1.16  msaitoh 		ret_val = mbx->ops[mbx_id].check_for_rst(hw, mbx_id);
    204  1.15  msaitoh 
    205  1.15  msaitoh 	return ret_val;
    206  1.15  msaitoh }
    207  1.15  msaitoh 
    208  1.15  msaitoh /**
    209  1.13  msaitoh  * ixgbe_clear_mbx - Clear Mailbox Memory
    210  1.13  msaitoh  * @hw: pointer to the HW structure
    211  1.16  msaitoh  * @mbx_id: id of mailbox to write
    212  1.11  msaitoh  *
    213  1.13  msaitoh  * Set VFMBMEM of given VF to 0x0.
    214  1.11  msaitoh  **/
    215  1.16  msaitoh s32 ixgbe_clear_mbx(struct ixgbe_hw *hw, u16 mbx_id)
    216  1.11  msaitoh {
    217  1.11  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    218  1.16  msaitoh 	s32 ret_val = IXGBE_ERR_CONFIG;
    219  1.11  msaitoh 
    220  1.11  msaitoh 	DEBUGFUNC("ixgbe_clear_mbx");
    221  1.11  msaitoh 
    222  1.16  msaitoh 	if (mbx->ops[mbx_id].clear)
    223  1.16  msaitoh 		ret_val = mbx->ops[mbx_id].clear(hw, mbx_id);
    224  1.11  msaitoh 
    225  1.11  msaitoh 	return ret_val;
    226  1.11  msaitoh }
    227  1.11  msaitoh 
    228  1.11  msaitoh /**
    229  1.13  msaitoh  * ixgbe_poll_for_msg - Wait for message notification
    230  1.13  msaitoh  * @hw: pointer to the HW structure
    231  1.13  msaitoh  * @mbx_id: id of mailbox to write
    232   1.1   dyoung  *
    233  1.13  msaitoh  * returns SUCCESS if it successfully received a message notification
    234   1.1   dyoung  **/
    235   1.1   dyoung static s32 ixgbe_poll_for_msg(struct ixgbe_hw *hw, u16 mbx_id)
    236   1.1   dyoung {
    237   1.1   dyoung 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    238   1.1   dyoung 	int countdown = mbx->timeout;
    239   1.1   dyoung 
    240   1.1   dyoung 	DEBUGFUNC("ixgbe_poll_for_msg");
    241   1.1   dyoung 
    242  1.16  msaitoh 	if (!countdown || !mbx->ops[mbx_id].check_for_msg)
    243  1.16  msaitoh 		return IXGBE_ERR_CONFIG;
    244   1.1   dyoung 
    245  1.16  msaitoh 	while (countdown && mbx->ops[mbx_id].check_for_msg(hw, mbx_id)) {
    246   1.1   dyoung 		countdown--;
    247   1.1   dyoung 		if (!countdown)
    248   1.1   dyoung 			break;
    249   1.1   dyoung 		usec_delay(mbx->usec_delay);
    250   1.1   dyoung 	}
    251   1.1   dyoung 
    252  1.16  msaitoh 	if (countdown == 0) {
    253   1.4  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_POLLING,
    254  1.16  msaitoh 			   "Polling for VF%u mailbox message timedout", mbx_id);
    255  1.16  msaitoh 		return IXGBE_ERR_TIMEOUT;
    256  1.16  msaitoh 	}
    257   1.4  msaitoh 
    258  1.16  msaitoh 	return IXGBE_SUCCESS;
    259   1.1   dyoung }
    260   1.1   dyoung 
    261   1.1   dyoung /**
    262  1.13  msaitoh  * ixgbe_poll_for_ack - Wait for message acknowledgment
    263  1.13  msaitoh  * @hw: pointer to the HW structure
    264  1.13  msaitoh  * @mbx_id: id of mailbox to write
    265   1.1   dyoung  *
    266  1.13  msaitoh  * returns SUCCESS if it successfully received a message acknowledgment
    267   1.1   dyoung  **/
    268   1.1   dyoung static s32 ixgbe_poll_for_ack(struct ixgbe_hw *hw, u16 mbx_id)
    269   1.1   dyoung {
    270   1.1   dyoung 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    271   1.1   dyoung 	int countdown = mbx->timeout;
    272   1.1   dyoung 
    273   1.1   dyoung 	DEBUGFUNC("ixgbe_poll_for_ack");
    274   1.1   dyoung 
    275  1.16  msaitoh 	if (!countdown || !mbx->ops[mbx_id].check_for_ack)
    276  1.16  msaitoh 		return IXGBE_ERR_CONFIG;
    277   1.1   dyoung 
    278  1.16  msaitoh 	while (countdown && mbx->ops[mbx_id].check_for_ack(hw, mbx_id)) {
    279   1.1   dyoung 		countdown--;
    280   1.1   dyoung 		if (!countdown)
    281   1.1   dyoung 			break;
    282   1.1   dyoung 		usec_delay(mbx->usec_delay);
    283   1.1   dyoung 	}
    284   1.1   dyoung 
    285  1.16  msaitoh 	if (countdown == 0) {
    286   1.4  msaitoh 		ERROR_REPORT2(IXGBE_ERROR_POLLING,
    287  1.16  msaitoh 			     "Polling for VF%u mailbox ack timedout", mbx_id);
    288  1.16  msaitoh 		return IXGBE_ERR_TIMEOUT;
    289  1.16  msaitoh 	}
    290   1.4  msaitoh 
    291  1.16  msaitoh 	return IXGBE_SUCCESS;
    292   1.1   dyoung }
    293   1.1   dyoung 
    294  1.16  msaitoh 
    295   1.1   dyoung /**
    296  1.16  msaitoh  * ixgbe_read_mailbox_vf - read VF's mailbox register
    297  1.13  msaitoh  * @hw: pointer to the HW structure
    298   1.1   dyoung  *
    299  1.16  msaitoh  * This function is used to read the mailbox register dedicated for VF without
    300  1.16  msaitoh  * losing the read to clear status bits.
    301   1.1   dyoung  **/
    302  1.16  msaitoh static u32 ixgbe_read_mailbox_vf(struct ixgbe_hw *hw)
    303   1.1   dyoung {
    304  1.16  msaitoh 	u32 vf_mailbox = IXGBE_READ_REG(hw, IXGBE_VFMAILBOX);
    305   1.1   dyoung 
    306  1.16  msaitoh 	vf_mailbox |= hw->mbx.vf_mailbox;
    307  1.16  msaitoh 	hw->mbx.vf_mailbox |= vf_mailbox & IXGBE_VFMAILBOX_R2C_BITS;
    308   1.1   dyoung 
    309  1.16  msaitoh 	return vf_mailbox;
    310   1.1   dyoung }
    311   1.1   dyoung 
    312  1.16  msaitoh static void ixgbe_clear_msg_vf(struct ixgbe_hw *hw)
    313   1.1   dyoung {
    314  1.16  msaitoh 	u32 vf_mailbox = ixgbe_read_mailbox_vf(hw);
    315   1.1   dyoung 
    316  1.16  msaitoh 	if (vf_mailbox & IXGBE_VFMAILBOX_PFSTS) {
    317  1.16  msaitoh 		hw->mbx.stats.reqs.ev_count++;
    318  1.16  msaitoh 		hw->mbx.vf_mailbox &= ~IXGBE_VFMAILBOX_PFSTS;
    319  1.16  msaitoh 	}
    320   1.1   dyoung }
    321   1.1   dyoung 
    322  1.16  msaitoh static void ixgbe_clear_ack_vf(struct ixgbe_hw *hw)
    323   1.1   dyoung {
    324  1.16  msaitoh 	u32 vf_mailbox = ixgbe_read_mailbox_vf(hw);
    325   1.1   dyoung 
    326  1.16  msaitoh 	if (vf_mailbox & IXGBE_VFMAILBOX_PFACK) {
    327  1.16  msaitoh 		hw->mbx.stats.acks.ev_count++;
    328  1.16  msaitoh 		hw->mbx.vf_mailbox &= ~IXGBE_VFMAILBOX_PFACK;
    329  1.16  msaitoh 	}
    330   1.1   dyoung }
    331   1.1   dyoung 
    332  1.16  msaitoh static void ixgbe_clear_rst_vf(struct ixgbe_hw *hw)
    333   1.1   dyoung {
    334  1.16  msaitoh 	u32 vf_mailbox = ixgbe_read_mailbox_vf(hw);
    335   1.1   dyoung 
    336  1.16  msaitoh 	if (vf_mailbox & (IXGBE_VFMAILBOX_RSTI | IXGBE_VFMAILBOX_RSTD)) {
    337  1.16  msaitoh 		hw->mbx.stats.rsts.ev_count++;
    338  1.16  msaitoh 		hw->mbx.vf_mailbox &= ~(IXGBE_VFMAILBOX_RSTI |
    339  1.16  msaitoh 					IXGBE_VFMAILBOX_RSTD);
    340  1.16  msaitoh 	}
    341   1.1   dyoung }
    342   1.1   dyoung 
    343   1.1   dyoung /**
    344  1.13  msaitoh  * ixgbe_check_for_bit_vf - Determine if a status bit was set
    345  1.13  msaitoh  * @hw: pointer to the HW structure
    346  1.13  msaitoh  * @mask: bitmask for bits to be tested and cleared
    347   1.1   dyoung  *
    348  1.13  msaitoh  * This function is used to check for the read to clear bits within
    349  1.13  msaitoh  * the V2P mailbox.
    350   1.1   dyoung  **/
    351   1.1   dyoung static s32 ixgbe_check_for_bit_vf(struct ixgbe_hw *hw, u32 mask)
    352   1.1   dyoung {
    353  1.16  msaitoh 	u32 vf_mailbox = ixgbe_read_mailbox_vf(hw);
    354   1.1   dyoung 
    355  1.16  msaitoh 	if (vf_mailbox & mask)
    356  1.16  msaitoh 		return IXGBE_SUCCESS;
    357   1.1   dyoung 
    358  1.16  msaitoh 	return IXGBE_ERR_MBX;
    359   1.1   dyoung }
    360   1.1   dyoung 
    361   1.1   dyoung /**
    362  1.13  msaitoh  * ixgbe_check_for_msg_vf - checks to see if the PF has sent mail
    363  1.13  msaitoh  * @hw: pointer to the HW structure
    364  1.13  msaitoh  * @mbx_id: id of mailbox to check
    365   1.1   dyoung  *
    366  1.13  msaitoh  * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
    367   1.1   dyoung  **/
    368   1.1   dyoung static s32 ixgbe_check_for_msg_vf(struct ixgbe_hw *hw, u16 mbx_id)
    369   1.1   dyoung {
    370   1.2  msaitoh 	UNREFERENCED_1PARAMETER(mbx_id);
    371   1.1   dyoung 	DEBUGFUNC("ixgbe_check_for_msg_vf");
    372   1.1   dyoung 
    373   1.1   dyoung 	if (!ixgbe_check_for_bit_vf(hw, IXGBE_VFMAILBOX_PFSTS)) {
    374   1.8  msaitoh 		hw->mbx.stats.reqs.ev_count++;
    375  1.16  msaitoh 		return IXGBE_SUCCESS;
    376   1.1   dyoung 	}
    377   1.1   dyoung 
    378  1.16  msaitoh 	return IXGBE_ERR_MBX;
    379   1.1   dyoung }
    380   1.1   dyoung 
    381   1.1   dyoung /**
    382  1.13  msaitoh  * ixgbe_check_for_ack_vf - checks to see if the PF has ACK'd
    383  1.13  msaitoh  * @hw: pointer to the HW structure
    384  1.13  msaitoh  * @mbx_id: id of mailbox to check
    385   1.1   dyoung  *
    386  1.13  msaitoh  * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
    387   1.1   dyoung  **/
    388   1.1   dyoung static s32 ixgbe_check_for_ack_vf(struct ixgbe_hw *hw, u16 mbx_id)
    389   1.1   dyoung {
    390   1.2  msaitoh 	UNREFERENCED_1PARAMETER(mbx_id);
    391   1.1   dyoung 	DEBUGFUNC("ixgbe_check_for_ack_vf");
    392   1.1   dyoung 
    393   1.1   dyoung 	if (!ixgbe_check_for_bit_vf(hw, IXGBE_VFMAILBOX_PFACK)) {
    394  1.16  msaitoh 		/* TODO: should this be autocleared? */
    395  1.16  msaitoh 		ixgbe_clear_ack_vf(hw);
    396   1.8  msaitoh 		hw->mbx.stats.acks.ev_count++;
    397  1.16  msaitoh 		return IXGBE_SUCCESS;
    398   1.1   dyoung 	}
    399   1.1   dyoung 
    400  1.16  msaitoh 	return IXGBE_ERR_MBX;
    401   1.1   dyoung }
    402   1.1   dyoung 
    403   1.1   dyoung /**
    404  1.13  msaitoh  * ixgbe_check_for_rst_vf - checks to see if the PF has reset
    405  1.13  msaitoh  * @hw: pointer to the HW structure
    406  1.13  msaitoh  * @mbx_id: id of mailbox to check
    407   1.1   dyoung  *
    408  1.13  msaitoh  * returns TRUE if the PF has set the reset done bit or else FALSE
    409   1.1   dyoung  **/
    410   1.1   dyoung static s32 ixgbe_check_for_rst_vf(struct ixgbe_hw *hw, u16 mbx_id)
    411   1.1   dyoung {
    412   1.2  msaitoh 	UNREFERENCED_1PARAMETER(mbx_id);
    413   1.1   dyoung 	DEBUGFUNC("ixgbe_check_for_rst_vf");
    414   1.1   dyoung 
    415  1.16  msaitoh 	if (!ixgbe_check_for_bit_vf(hw, IXGBE_VFMAILBOX_RSTI |
    416  1.16  msaitoh 					  IXGBE_VFMAILBOX_RSTD)) {
    417  1.16  msaitoh 		/* TODO: should this be autocleared? */
    418  1.16  msaitoh 		ixgbe_clear_rst_vf(hw);
    419   1.8  msaitoh 		hw->mbx.stats.rsts.ev_count++;
    420  1.16  msaitoh 		return IXGBE_SUCCESS;
    421   1.1   dyoung 	}
    422   1.1   dyoung 
    423  1.16  msaitoh 	return IXGBE_ERR_MBX;
    424   1.1   dyoung }
    425   1.1   dyoung 
    426   1.1   dyoung /**
    427  1.13  msaitoh  * ixgbe_obtain_mbx_lock_vf - obtain mailbox lock
    428  1.13  msaitoh  * @hw: pointer to the HW structure
    429   1.1   dyoung  *
    430  1.13  msaitoh  * return SUCCESS if we obtained the mailbox lock
    431   1.1   dyoung  **/
    432   1.1   dyoung static s32 ixgbe_obtain_mbx_lock_vf(struct ixgbe_hw *hw)
    433   1.1   dyoung {
    434  1.16  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    435  1.16  msaitoh 	int countdown = mbx->timeout;
    436   1.1   dyoung 	s32 ret_val = IXGBE_ERR_MBX;
    437  1.16  msaitoh 	u32 vf_mailbox;
    438   1.1   dyoung 
    439   1.1   dyoung 	DEBUGFUNC("ixgbe_obtain_mbx_lock_vf");
    440   1.1   dyoung 
    441  1.16  msaitoh 	if (!mbx->timeout)
    442  1.16  msaitoh 		return IXGBE_ERR_CONFIG;
    443  1.16  msaitoh 
    444  1.16  msaitoh 	while (countdown--) {
    445  1.16  msaitoh 		/* Reserve mailbox for VF use */
    446  1.16  msaitoh 		vf_mailbox = ixgbe_read_mailbox_vf(hw);
    447  1.16  msaitoh 		vf_mailbox |= IXGBE_VFMAILBOX_VFU;
    448  1.16  msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, vf_mailbox);
    449  1.16  msaitoh 
    450  1.16  msaitoh 		/* Verify that VF is the owner of the lock */
    451  1.16  msaitoh 		if (ixgbe_read_mailbox_vf(hw) & IXGBE_VFMAILBOX_VFU) {
    452  1.16  msaitoh 			ret_val = IXGBE_SUCCESS;
    453  1.16  msaitoh 			break;
    454  1.16  msaitoh 		}
    455  1.16  msaitoh 
    456  1.16  msaitoh 		/* Wait a bit before trying again */
    457  1.16  msaitoh 		usec_delay(mbx->usec_delay);
    458  1.16  msaitoh 	}
    459   1.1   dyoung 
    460  1.16  msaitoh 	if (ret_val != IXGBE_SUCCESS) {
    461  1.16  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
    462  1.16  msaitoh 				"Failed to obtain mailbox lock");
    463  1.16  msaitoh 		ret_val = IXGBE_ERR_TIMEOUT;
    464  1.16  msaitoh 	}
    465   1.1   dyoung 
    466   1.1   dyoung 	return ret_val;
    467   1.1   dyoung }
    468   1.1   dyoung 
    469   1.1   dyoung /**
    470  1.16  msaitoh  * ixgbe_release_mbx_lock_dummy - release mailbox lock
    471  1.16  msaitoh  * @hw: pointer to the HW structure
    472  1.16  msaitoh  * @mbx_id: id of mailbox to read
    473  1.16  msaitoh  **/
    474  1.16  msaitoh static void ixgbe_release_mbx_lock_dummy(struct ixgbe_hw *hw, u16 mbx_id)
    475  1.16  msaitoh {
    476  1.16  msaitoh 	UNREFERENCED_2PARAMETER(hw, mbx_id);
    477  1.16  msaitoh 
    478  1.16  msaitoh 	DEBUGFUNC("ixgbe_release_mbx_lock_dummy");
    479  1.16  msaitoh }
    480  1.16  msaitoh 
    481  1.16  msaitoh /**
    482  1.16  msaitoh  * ixgbe_release_mbx_lock_vf - release mailbox lock
    483  1.16  msaitoh  * @hw: pointer to the HW structure
    484  1.16  msaitoh  * @mbx_id: id of mailbox to read
    485  1.16  msaitoh  **/
    486  1.16  msaitoh static void ixgbe_release_mbx_lock_vf(struct ixgbe_hw *hw, u16 mbx_id)
    487  1.16  msaitoh {
    488  1.16  msaitoh 	u32 vf_mailbox;
    489  1.16  msaitoh 
    490  1.16  msaitoh 	UNREFERENCED_1PARAMETER(mbx_id);
    491  1.16  msaitoh 
    492  1.16  msaitoh 	DEBUGFUNC("ixgbe_release_mbx_lock_vf");
    493  1.16  msaitoh 
    494  1.16  msaitoh 	/* Return ownership of the buffer */
    495  1.16  msaitoh 	vf_mailbox = ixgbe_read_mailbox_vf(hw);
    496  1.16  msaitoh 	vf_mailbox &= ~IXGBE_VFMAILBOX_VFU;
    497  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, vf_mailbox);
    498  1.16  msaitoh }
    499  1.16  msaitoh 
    500  1.16  msaitoh /**
    501  1.16  msaitoh  * ixgbe_write_mbx_vf_legacy - Write a message to the mailbox
    502  1.16  msaitoh  * @hw: pointer to the HW structure
    503  1.16  msaitoh  * @msg: The message buffer
    504  1.16  msaitoh  * @size: Length of buffer
    505  1.16  msaitoh  * @mbx_id: id of mailbox to write
    506  1.16  msaitoh  *
    507  1.16  msaitoh  * returns SUCCESS if it successfully copied message into the buffer
    508  1.16  msaitoh  **/
    509  1.16  msaitoh static s32 ixgbe_write_mbx_vf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
    510  1.16  msaitoh 				     u16 mbx_id)
    511  1.16  msaitoh {
    512  1.16  msaitoh 	s32 ret_val;
    513  1.16  msaitoh 	u16 i;
    514  1.16  msaitoh 
    515  1.16  msaitoh 	UNREFERENCED_1PARAMETER(mbx_id);
    516  1.16  msaitoh 	DEBUGFUNC("ixgbe_write_mbx_vf_legacy");
    517  1.16  msaitoh 
    518  1.16  msaitoh 	/* lock the mailbox to prevent pf/vf race condition */
    519  1.16  msaitoh 	ret_val = ixgbe_obtain_mbx_lock_vf(hw);
    520  1.16  msaitoh 	if (ret_val)
    521  1.16  msaitoh 		return ret_val;
    522  1.16  msaitoh 
    523  1.16  msaitoh 	/* flush msg and acks as we are overwriting the message buffer */
    524  1.16  msaitoh 	ixgbe_check_for_msg_vf(hw, 0);
    525  1.16  msaitoh 	ixgbe_clear_msg_vf(hw);
    526  1.16  msaitoh 	ixgbe_check_for_ack_vf(hw, 0);
    527  1.16  msaitoh 	ixgbe_clear_ack_vf(hw);
    528  1.16  msaitoh 
    529  1.16  msaitoh 	/* copy the caller specified message to the mailbox memory buffer */
    530  1.16  msaitoh 	for (i = 0; i < size; i++)
    531  1.16  msaitoh 		IXGBE_WRITE_REG_ARRAY(hw, IXGBE_VFMBMEM, i, msg[i]);
    532  1.16  msaitoh 
    533  1.16  msaitoh 	/* update stats */
    534  1.16  msaitoh 	hw->mbx.stats.msgs_tx.ev_count++;
    535  1.16  msaitoh 
    536  1.16  msaitoh 	/* interrupt the PF to tell it a message has been sent */
    537  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_REQ);
    538  1.16  msaitoh 
    539  1.16  msaitoh 	return IXGBE_SUCCESS;
    540  1.16  msaitoh }
    541  1.16  msaitoh 
    542  1.16  msaitoh /**
    543  1.13  msaitoh  * ixgbe_write_mbx_vf - Write a message to the mailbox
    544  1.13  msaitoh  * @hw: pointer to the HW structure
    545  1.13  msaitoh  * @msg: The message buffer
    546  1.13  msaitoh  * @size: Length of buffer
    547  1.13  msaitoh  * @mbx_id: id of mailbox to write
    548   1.1   dyoung  *
    549  1.13  msaitoh  * returns SUCCESS if it successfully copied message into the buffer
    550   1.1   dyoung  **/
    551   1.1   dyoung static s32 ixgbe_write_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
    552   1.2  msaitoh 			      u16 mbx_id)
    553   1.1   dyoung {
    554  1.16  msaitoh 	u32 vf_mailbox;
    555   1.1   dyoung 	s32 ret_val;
    556   1.1   dyoung 	u16 i;
    557   1.1   dyoung 
    558   1.2  msaitoh 	UNREFERENCED_1PARAMETER(mbx_id);
    559   1.1   dyoung 
    560   1.1   dyoung 	DEBUGFUNC("ixgbe_write_mbx_vf");
    561   1.1   dyoung 
    562   1.1   dyoung 	/* lock the mailbox to prevent pf/vf race condition */
    563   1.1   dyoung 	ret_val = ixgbe_obtain_mbx_lock_vf(hw);
    564   1.1   dyoung 	if (ret_val)
    565  1.16  msaitoh 		goto out;
    566   1.1   dyoung 
    567   1.1   dyoung 	/* flush msg and acks as we are overwriting the message buffer */
    568  1.16  msaitoh 	ixgbe_clear_msg_vf(hw);
    569  1.16  msaitoh 	ixgbe_clear_ack_vf(hw);
    570   1.1   dyoung 
    571   1.1   dyoung 	/* copy the caller specified message to the mailbox memory buffer */
    572   1.1   dyoung 	for (i = 0; i < size; i++)
    573   1.1   dyoung 		IXGBE_WRITE_REG_ARRAY(hw, IXGBE_VFMBMEM, i, msg[i]);
    574   1.1   dyoung 
    575   1.1   dyoung 	/* update stats */
    576   1.8  msaitoh 	hw->mbx.stats.msgs_tx.ev_count++;
    577   1.1   dyoung 
    578  1.16  msaitoh 	/* interrupt the PF to tell it a message has been sent */
    579  1.16  msaitoh 	vf_mailbox = ixgbe_read_mailbox_vf(hw);
    580  1.16  msaitoh 	vf_mailbox |= IXGBE_VFMAILBOX_REQ;
    581  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, vf_mailbox);
    582  1.16  msaitoh 
    583  1.16  msaitoh 	/* if msg sent wait until we receive an ack */
    584  1.16  msaitoh 	ixgbe_poll_for_ack(hw, mbx_id);
    585  1.16  msaitoh 
    586  1.16  msaitoh out:
    587  1.16  msaitoh 	hw->mbx.ops[mbx_id].release(hw, mbx_id);
    588   1.1   dyoung 
    589   1.1   dyoung 	return ret_val;
    590   1.1   dyoung }
    591   1.1   dyoung 
    592   1.1   dyoung /**
    593  1.16  msaitoh  * ixgbe_read_mbx_vf_legacy - Reads a message from the inbox intended for vf
    594  1.13  msaitoh  * @hw: pointer to the HW structure
    595  1.13  msaitoh  * @msg: The message buffer
    596  1.13  msaitoh  * @size: Length of buffer
    597  1.13  msaitoh  * @mbx_id: id of mailbox to read
    598   1.1   dyoung  *
    599  1.13  msaitoh  * returns SUCCESS if it successfully read message from buffer
    600   1.1   dyoung  **/
    601  1.16  msaitoh static s32 ixgbe_read_mbx_vf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
    602  1.16  msaitoh 				    u16 mbx_id)
    603   1.1   dyoung {
    604  1.16  msaitoh 	s32 ret_val;
    605   1.1   dyoung 	u16 i;
    606   1.1   dyoung 
    607  1.16  msaitoh 	DEBUGFUNC("ixgbe_read_mbx_vf_legacy");
    608   1.2  msaitoh 	UNREFERENCED_1PARAMETER(mbx_id);
    609   1.1   dyoung 
    610   1.1   dyoung 	/* lock the mailbox to prevent pf/vf race condition */
    611   1.1   dyoung 	ret_val = ixgbe_obtain_mbx_lock_vf(hw);
    612   1.1   dyoung 	if (ret_val)
    613  1.16  msaitoh 		return ret_val;
    614   1.1   dyoung 
    615   1.1   dyoung 	/* copy the message from the mailbox memory buffer */
    616   1.1   dyoung 	for (i = 0; i < size; i++)
    617   1.1   dyoung 		msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_VFMBMEM, i);
    618   1.1   dyoung 
    619   1.1   dyoung 	/* Acknowledge receipt and release mailbox, then we're done */
    620   1.1   dyoung 	IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, IXGBE_VFMAILBOX_ACK);
    621   1.1   dyoung 
    622   1.1   dyoung 	/* update stats */
    623   1.8  msaitoh 	hw->mbx.stats.msgs_rx.ev_count++;
    624   1.1   dyoung 
    625  1.16  msaitoh 	return IXGBE_SUCCESS;
    626  1.16  msaitoh }
    627  1.16  msaitoh 
    628  1.16  msaitoh /**
    629  1.16  msaitoh  * ixgbe_read_mbx_vf - Reads a message from the inbox intended for vf
    630  1.16  msaitoh  * @hw: pointer to the HW structure
    631  1.16  msaitoh  * @msg: The message buffer
    632  1.16  msaitoh  * @size: Length of buffer
    633  1.16  msaitoh  * @mbx_id: id of mailbox to read
    634  1.16  msaitoh  *
    635  1.16  msaitoh  * returns SUCCESS if it successfully read message from buffer
    636  1.16  msaitoh  **/
    637  1.16  msaitoh static s32 ixgbe_read_mbx_vf(struct ixgbe_hw *hw, u32 *msg, u16 size,
    638  1.16  msaitoh 			     u16 mbx_id)
    639  1.16  msaitoh {
    640  1.16  msaitoh 	u32 vf_mailbox;
    641  1.16  msaitoh 	s32 ret_val;
    642  1.16  msaitoh 	u16 i;
    643  1.16  msaitoh 
    644  1.16  msaitoh 	DEBUGFUNC("ixgbe_read_mbx_vf");
    645  1.16  msaitoh 	UNREFERENCED_1PARAMETER(mbx_id);
    646  1.16  msaitoh 
    647  1.16  msaitoh 	/* check if there is a message from PF */
    648  1.16  msaitoh 	ret_val = ixgbe_check_for_msg_vf(hw, 0);
    649  1.16  msaitoh 	if (ret_val != IXGBE_SUCCESS)
    650  1.16  msaitoh 		return IXGBE_ERR_MBX_NOMSG;
    651  1.16  msaitoh 
    652  1.16  msaitoh 	ixgbe_clear_msg_vf(hw);
    653  1.16  msaitoh 
    654  1.16  msaitoh 	/* copy the message from the mailbox memory buffer */
    655  1.16  msaitoh 	for (i = 0; i < size; i++)
    656  1.16  msaitoh 		msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_VFMBMEM, i);
    657  1.16  msaitoh 
    658  1.16  msaitoh 	/* Acknowledge receipt */
    659  1.16  msaitoh 	vf_mailbox = ixgbe_read_mailbox_vf(hw);
    660  1.16  msaitoh 	vf_mailbox |= IXGBE_VFMAILBOX_ACK;
    661  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_VFMAILBOX, vf_mailbox);
    662  1.16  msaitoh 
    663  1.16  msaitoh 	/* update stats */
    664  1.16  msaitoh 	hw->mbx.stats.msgs_rx.ev_count++;
    665  1.16  msaitoh 
    666  1.16  msaitoh 	return IXGBE_SUCCESS;
    667   1.1   dyoung }
    668   1.1   dyoung 
    669   1.1   dyoung /**
    670  1.13  msaitoh  * ixgbe_init_mbx_params_vf - set initial values for vf mailbox
    671  1.13  msaitoh  * @hw: pointer to the HW structure
    672   1.1   dyoung  *
    673  1.16  msaitoh  * Initializes single set the hw->mbx struct to correct values for vf mailbox
    674  1.16  msaitoh  * Set of legacy functions is being used here
    675  1.16  msaitoh  */
    676  1.16  msaitoh void ixgbe_init_mbx_params_vf(struct ixgbe_hw *hw)
    677  1.16  msaitoh {
    678  1.16  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    679  1.16  msaitoh 
    680  1.16  msaitoh 	mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
    681  1.16  msaitoh 	mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
    682  1.16  msaitoh 
    683  1.16  msaitoh 	mbx->size = IXGBE_VFMAILBOX_SIZE;
    684  1.16  msaitoh 
    685  1.16  msaitoh 	/* VF has only one mailbox connection, no need for more IDs */
    686  1.16  msaitoh 	mbx->ops[0].release = ixgbe_release_mbx_lock_dummy;
    687  1.16  msaitoh 	mbx->ops[0].read = ixgbe_read_mbx_vf_legacy;
    688  1.16  msaitoh 	mbx->ops[0].write = ixgbe_write_mbx_vf_legacy;
    689  1.16  msaitoh 	mbx->ops[0].check_for_msg = ixgbe_check_for_msg_vf;
    690  1.16  msaitoh 	mbx->ops[0].check_for_ack = ixgbe_check_for_ack_vf;
    691  1.16  msaitoh 	mbx->ops[0].check_for_rst = ixgbe_check_for_rst_vf;
    692  1.16  msaitoh 	mbx->ops[0].clear = NULL;
    693  1.16  msaitoh 
    694  1.16  msaitoh 	mbx->stats.msgs_tx.ev_count = 0;
    695  1.16  msaitoh 	mbx->stats.msgs_rx.ev_count = 0;
    696  1.16  msaitoh 	mbx->stats.reqs.ev_count = 0;
    697  1.16  msaitoh 	mbx->stats.acks.ev_count = 0;
    698  1.16  msaitoh 	mbx->stats.rsts.ev_count = 0;
    699  1.16  msaitoh }
    700  1.16  msaitoh 
    701  1.16  msaitoh /**
    702  1.16  msaitoh  * ixgbe_upgrade_mbx_params_vf - set initial values for vf mailbox
    703  1.16  msaitoh  * @hw: pointer to the HW structure
    704  1.16  msaitoh  *
    705  1.13  msaitoh  * Initializes the hw->mbx struct to correct values for vf mailbox
    706   1.1   dyoung  */
    707  1.16  msaitoh void ixgbe_upgrade_mbx_params_vf(struct ixgbe_hw *hw)
    708   1.1   dyoung {
    709   1.1   dyoung 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    710   1.1   dyoung 
    711  1.16  msaitoh 	mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
    712   1.1   dyoung 	mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
    713   1.1   dyoung 
    714   1.1   dyoung 	mbx->size = IXGBE_VFMAILBOX_SIZE;
    715   1.1   dyoung 
    716  1.16  msaitoh 	/* VF has only one mailbox connection, no need for more IDs */
    717  1.16  msaitoh 	mbx->ops[0].release = ixgbe_release_mbx_lock_vf;
    718  1.16  msaitoh 	mbx->ops[0].read = ixgbe_read_mbx_vf;
    719  1.16  msaitoh 	mbx->ops[0].write = ixgbe_write_mbx_vf;
    720  1.16  msaitoh 	mbx->ops[0].check_for_msg = ixgbe_check_for_msg_vf;
    721  1.16  msaitoh 	mbx->ops[0].check_for_ack = ixgbe_check_for_ack_vf;
    722  1.16  msaitoh 	mbx->ops[0].check_for_rst = ixgbe_check_for_rst_vf;
    723  1.16  msaitoh 	mbx->ops[0].clear = NULL;
    724   1.1   dyoung 
    725   1.8  msaitoh 	mbx->stats.msgs_tx.ev_count = 0;
    726   1.8  msaitoh 	mbx->stats.msgs_rx.ev_count = 0;
    727   1.8  msaitoh 	mbx->stats.reqs.ev_count = 0;
    728   1.8  msaitoh 	mbx->stats.acks.ev_count = 0;
    729   1.8  msaitoh 	mbx->stats.rsts.ev_count = 0;
    730   1.1   dyoung }
    731   1.1   dyoung 
    732  1.16  msaitoh static void ixgbe_clear_msg_pf(struct ixgbe_hw *hw, u16 vf_id)
    733  1.16  msaitoh {
    734  1.16  msaitoh 	u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
    735  1.16  msaitoh 	s32 index = IXGBE_PFMBICR_INDEX(vf_id);
    736  1.16  msaitoh 	u32 pfmbicr;
    737  1.16  msaitoh 
    738  1.16  msaitoh 	pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
    739  1.16  msaitoh 
    740  1.16  msaitoh 	if (pfmbicr & (IXGBE_PFMBICR_VFREQ_VF1 << vf_shift))
    741  1.16  msaitoh 		hw->mbx.stats.reqs.ev_count++;
    742  1.16  msaitoh 
    743  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFMBICR(index),
    744  1.16  msaitoh 			IXGBE_PFMBICR_VFREQ_VF1 << vf_shift);
    745  1.16  msaitoh }
    746  1.16  msaitoh 
    747  1.16  msaitoh static void ixgbe_clear_ack_pf(struct ixgbe_hw *hw, u16 vf_id)
    748  1.16  msaitoh {
    749  1.16  msaitoh 	u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
    750  1.16  msaitoh 	s32 index = IXGBE_PFMBICR_INDEX(vf_id);
    751  1.16  msaitoh 	u32 pfmbicr;
    752  1.16  msaitoh 
    753  1.16  msaitoh 	pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
    754  1.16  msaitoh 
    755  1.16  msaitoh 	if (pfmbicr & (IXGBE_PFMBICR_VFACK_VF1 << vf_shift))
    756  1.16  msaitoh 		hw->mbx.stats.acks.ev_count++;
    757  1.16  msaitoh 
    758  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFMBICR(index),
    759  1.16  msaitoh 			IXGBE_PFMBICR_VFACK_VF1 << vf_shift);
    760  1.16  msaitoh }
    761  1.16  msaitoh 
    762   1.1   dyoung static s32 ixgbe_check_for_bit_pf(struct ixgbe_hw *hw, u32 mask, s32 index)
    763   1.1   dyoung {
    764  1.16  msaitoh 	u32 pfmbicr = IXGBE_READ_REG(hw, IXGBE_PFMBICR(index));
    765   1.1   dyoung 
    766  1.16  msaitoh 	if (pfmbicr & mask)
    767  1.16  msaitoh 		return IXGBE_SUCCESS;
    768   1.1   dyoung 
    769  1.16  msaitoh 	return IXGBE_ERR_MBX;
    770   1.1   dyoung }
    771   1.1   dyoung 
    772   1.1   dyoung /**
    773  1.13  msaitoh  * ixgbe_check_for_msg_pf - checks to see if the VF has sent mail
    774  1.13  msaitoh  * @hw: pointer to the HW structure
    775  1.16  msaitoh  * @vf_id: the VF index
    776   1.1   dyoung  *
    777  1.13  msaitoh  * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
    778   1.1   dyoung  **/
    779  1.16  msaitoh static s32 ixgbe_check_for_msg_pf(struct ixgbe_hw *hw, u16 vf_id)
    780   1.1   dyoung {
    781  1.16  msaitoh 	u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
    782  1.16  msaitoh 	s32 index = IXGBE_PFMBICR_INDEX(vf_id);
    783   1.1   dyoung 
    784   1.1   dyoung 	DEBUGFUNC("ixgbe_check_for_msg_pf");
    785   1.1   dyoung 
    786  1.16  msaitoh 	if (!ixgbe_check_for_bit_pf(hw, IXGBE_PFMBICR_VFREQ_VF1 << vf_shift,
    787  1.16  msaitoh 				    index))
    788  1.16  msaitoh 		return IXGBE_SUCCESS;
    789   1.1   dyoung 
    790  1.16  msaitoh 	return IXGBE_ERR_MBX;
    791   1.1   dyoung }
    792   1.1   dyoung 
    793   1.1   dyoung /**
    794  1.13  msaitoh  * ixgbe_check_for_ack_pf - checks to see if the VF has ACKed
    795  1.13  msaitoh  * @hw: pointer to the HW structure
    796  1.16  msaitoh  * @vf_id: the VF index
    797   1.1   dyoung  *
    798  1.13  msaitoh  * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
    799   1.1   dyoung  **/
    800  1.16  msaitoh static s32 ixgbe_check_for_ack_pf(struct ixgbe_hw *hw, u16 vf_id)
    801   1.1   dyoung {
    802  1.16  msaitoh 	u32 vf_shift = IXGBE_PFMBICR_SHIFT(vf_id);
    803  1.16  msaitoh 	s32 index = IXGBE_PFMBICR_INDEX(vf_id);
    804   1.1   dyoung 	s32 ret_val = IXGBE_ERR_MBX;
    805   1.1   dyoung 
    806   1.1   dyoung 	DEBUGFUNC("ixgbe_check_for_ack_pf");
    807   1.1   dyoung 
    808  1.16  msaitoh 	if (!ixgbe_check_for_bit_pf(hw, IXGBE_PFMBICR_VFACK_VF1 << vf_shift,
    809   1.2  msaitoh 				    index)) {
    810   1.1   dyoung 		ret_val = IXGBE_SUCCESS;
    811  1.16  msaitoh 		/* TODO: should this be autocleared? */
    812  1.16  msaitoh 		ixgbe_clear_ack_pf(hw, vf_id);
    813   1.1   dyoung 	}
    814   1.1   dyoung 
    815   1.1   dyoung 	return ret_val;
    816   1.1   dyoung }
    817   1.1   dyoung 
    818   1.1   dyoung /**
    819  1.13  msaitoh  * ixgbe_check_for_rst_pf - checks to see if the VF has reset
    820  1.13  msaitoh  * @hw: pointer to the HW structure
    821  1.16  msaitoh  * @vf_id: the VF index
    822   1.1   dyoung  *
    823  1.13  msaitoh  * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
    824   1.1   dyoung  **/
    825  1.16  msaitoh static s32 ixgbe_check_for_rst_pf(struct ixgbe_hw *hw, u16 vf_id)
    826   1.1   dyoung {
    827  1.16  msaitoh 	u32 vf_shift = IXGBE_PFVFLRE_SHIFT(vf_id);
    828  1.16  msaitoh 	u32 index = IXGBE_PFVFLRE_INDEX(vf_id);
    829  1.16  msaitoh 	s32 ret_val = IXGBE_ERR_MBX;
    830   1.1   dyoung 	u32 vflre = 0;
    831   1.1   dyoung 
    832   1.1   dyoung 	DEBUGFUNC("ixgbe_check_for_rst_pf");
    833   1.1   dyoung 
    834   1.1   dyoung 	switch (hw->mac.type) {
    835   1.1   dyoung 	case ixgbe_mac_82599EB:
    836  1.16  msaitoh 		vflre = IXGBE_READ_REG(hw, IXGBE_PFVFLRE(index));
    837   1.1   dyoung 		break;
    838   1.4  msaitoh 	case ixgbe_mac_X550:
    839   1.4  msaitoh 	case ixgbe_mac_X550EM_x:
    840   1.7  msaitoh 	case ixgbe_mac_X550EM_a:
    841   1.2  msaitoh 	case ixgbe_mac_X540:
    842  1.16  msaitoh 		vflre = IXGBE_READ_REG(hw, IXGBE_PFVFLREC(index));
    843   1.2  msaitoh 		break;
    844   1.1   dyoung 	default:
    845   1.1   dyoung 		break;
    846   1.1   dyoung 	}
    847   1.1   dyoung 
    848   1.1   dyoung 	if (vflre & (1 << vf_shift)) {
    849   1.1   dyoung 		ret_val = IXGBE_SUCCESS;
    850  1.16  msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_PFVFLREC(index), (1 << vf_shift));
    851   1.8  msaitoh 		hw->mbx.stats.rsts.ev_count++;
    852   1.1   dyoung 	}
    853   1.1   dyoung 
    854   1.1   dyoung 	return ret_val;
    855   1.1   dyoung }
    856   1.1   dyoung 
    857   1.1   dyoung /**
    858  1.13  msaitoh  * ixgbe_obtain_mbx_lock_pf - obtain mailbox lock
    859  1.13  msaitoh  * @hw: pointer to the HW structure
    860  1.16  msaitoh  * @vf_id: the VF index
    861   1.1   dyoung  *
    862  1.13  msaitoh  * return SUCCESS if we obtained the mailbox lock
    863   1.1   dyoung  **/
    864  1.16  msaitoh static s32 ixgbe_obtain_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_id)
    865   1.1   dyoung {
    866  1.16  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
    867  1.16  msaitoh 	int countdown = mbx->timeout;
    868   1.1   dyoung 	s32 ret_val = IXGBE_ERR_MBX;
    869  1.16  msaitoh 	u32 pf_mailbox;
    870   1.1   dyoung 
    871   1.1   dyoung 	DEBUGFUNC("ixgbe_obtain_mbx_lock_pf");
    872   1.1   dyoung 
    873  1.16  msaitoh 	if (!mbx->timeout)
    874  1.16  msaitoh 		return IXGBE_ERR_CONFIG;
    875  1.16  msaitoh 
    876  1.16  msaitoh 	while (countdown--) {
    877  1.16  msaitoh 		/* Reserve mailbox for PF use */
    878  1.16  msaitoh 		pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
    879  1.16  msaitoh 		pf_mailbox |= IXGBE_PFMAILBOX_PFU;
    880  1.16  msaitoh 		IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
    881  1.16  msaitoh 
    882  1.16  msaitoh 		/* Verify that PF is the owner of the lock */
    883  1.16  msaitoh 		pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
    884  1.16  msaitoh 		if (pf_mailbox & IXGBE_PFMAILBOX_PFU) {
    885  1.16  msaitoh 			ret_val = IXGBE_SUCCESS;
    886  1.16  msaitoh 			break;
    887  1.16  msaitoh 		}
    888   1.1   dyoung 
    889  1.16  msaitoh 		/* Wait a bit before trying again */
    890  1.16  msaitoh 		usec_delay(mbx->usec_delay);
    891  1.16  msaitoh 	}
    892   1.4  msaitoh 
    893  1.16  msaitoh 	if (ret_val != IXGBE_SUCCESS) {
    894  1.16  msaitoh 		ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
    895  1.16  msaitoh 			      "Failed to obtain mailbox lock");
    896  1.16  msaitoh 		ret_val = IXGBE_ERR_TIMEOUT;
    897  1.16  msaitoh 	}
    898   1.1   dyoung 
    899   1.1   dyoung 	return ret_val;
    900   1.1   dyoung }
    901   1.1   dyoung 
    902   1.1   dyoung /**
    903  1.16  msaitoh  * ixgbe_release_mbx_lock_pf - release mailbox lock
    904  1.16  msaitoh  * @hw: pointer to the HW structure
    905  1.16  msaitoh  * @vf_id: the VF index
    906  1.16  msaitoh  **/
    907  1.16  msaitoh static void ixgbe_release_mbx_lock_pf(struct ixgbe_hw *hw, u16 vf_id)
    908  1.16  msaitoh {
    909  1.16  msaitoh 	u32 pf_mailbox;
    910  1.16  msaitoh 
    911  1.16  msaitoh 	DEBUGFUNC("ixgbe_release_mbx_lock_pf");
    912  1.16  msaitoh 
    913  1.16  msaitoh 	/* Return ownership of the buffer */
    914  1.16  msaitoh 	pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
    915  1.16  msaitoh 	pf_mailbox &= ~IXGBE_PFMAILBOX_PFU;
    916  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
    917  1.16  msaitoh }
    918  1.16  msaitoh 
    919  1.16  msaitoh /**
    920  1.16  msaitoh  * ixgbe_write_mbx_pf_legacy - Places a message in the mailbox
    921  1.16  msaitoh  * @hw: pointer to the HW structure
    922  1.16  msaitoh  * @msg: The message buffer
    923  1.16  msaitoh  * @size: Length of buffer
    924  1.16  msaitoh  * @vf_id: the VF index
    925  1.16  msaitoh  *
    926  1.16  msaitoh  * returns SUCCESS if it successfully copied message into the buffer
    927  1.16  msaitoh  **/
    928  1.16  msaitoh static s32 ixgbe_write_mbx_pf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
    929  1.16  msaitoh 				     u16 vf_id)
    930  1.16  msaitoh {
    931  1.16  msaitoh 	s32 ret_val;
    932  1.16  msaitoh 	u16 i;
    933  1.16  msaitoh 
    934  1.16  msaitoh 	DEBUGFUNC("ixgbe_write_mbx_pf_legacy");
    935  1.16  msaitoh 
    936  1.16  msaitoh 	/* lock the mailbox to prevent pf/vf race condition */
    937  1.16  msaitoh 	ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
    938  1.16  msaitoh 	if (ret_val)
    939  1.16  msaitoh 		return ret_val;
    940  1.16  msaitoh 
    941  1.16  msaitoh 	/* flush msg and acks as we are overwriting the message buffer */
    942  1.16  msaitoh 	ixgbe_check_for_msg_pf(hw, vf_id);
    943  1.16  msaitoh 	ixgbe_clear_msg_pf(hw, vf_id);
    944  1.16  msaitoh 	ixgbe_check_for_ack_pf(hw, vf_id);
    945  1.16  msaitoh 	ixgbe_clear_ack_pf(hw, vf_id);
    946  1.16  msaitoh 
    947  1.16  msaitoh 	/* copy the caller specified message to the mailbox memory buffer */
    948  1.16  msaitoh 	for (i = 0; i < size; i++)
    949  1.16  msaitoh 		IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, msg[i]);
    950  1.16  msaitoh 
    951  1.16  msaitoh 	/* Interrupt VF to tell it a message has been sent and release buffer*/
    952  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), IXGBE_PFMAILBOX_STS);
    953  1.16  msaitoh 
    954  1.16  msaitoh 	/* update stats */
    955  1.16  msaitoh 	hw->mbx.stats.msgs_tx.ev_count++;
    956  1.16  msaitoh 
    957  1.16  msaitoh 	return IXGBE_SUCCESS;
    958  1.16  msaitoh }
    959  1.16  msaitoh 
    960  1.16  msaitoh /**
    961  1.13  msaitoh  * ixgbe_write_mbx_pf - Places a message in the mailbox
    962  1.13  msaitoh  * @hw: pointer to the HW structure
    963  1.13  msaitoh  * @msg: The message buffer
    964  1.13  msaitoh  * @size: Length of buffer
    965  1.16  msaitoh  * @vf_id: the VF index
    966   1.1   dyoung  *
    967  1.13  msaitoh  * returns SUCCESS if it successfully copied message into the buffer
    968   1.1   dyoung  **/
    969   1.1   dyoung static s32 ixgbe_write_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
    970  1.16  msaitoh 			      u16 vf_id)
    971   1.1   dyoung {
    972  1.16  msaitoh 	u32 pf_mailbox;
    973   1.1   dyoung 	s32 ret_val;
    974   1.1   dyoung 	u16 i;
    975   1.1   dyoung 
    976   1.1   dyoung 	DEBUGFUNC("ixgbe_write_mbx_pf");
    977   1.1   dyoung 
    978   1.1   dyoung 	/* lock the mailbox to prevent pf/vf race condition */
    979  1.16  msaitoh 	ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
    980   1.1   dyoung 	if (ret_val)
    981  1.16  msaitoh 		goto out;
    982   1.1   dyoung 
    983   1.1   dyoung 	/* flush msg and acks as we are overwriting the message buffer */
    984  1.16  msaitoh 	ixgbe_clear_msg_pf(hw, vf_id);
    985  1.16  msaitoh 	ixgbe_clear_ack_pf(hw, vf_id);
    986   1.1   dyoung 
    987   1.1   dyoung 	/* copy the caller specified message to the mailbox memory buffer */
    988   1.1   dyoung 	for (i = 0; i < size; i++)
    989  1.16  msaitoh 		IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, msg[i]);
    990   1.1   dyoung 
    991  1.16  msaitoh 	/* Interrupt VF to tell it a message has been sent */
    992  1.16  msaitoh 	pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
    993  1.16  msaitoh 	pf_mailbox |= IXGBE_PFMAILBOX_STS;
    994  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
    995  1.16  msaitoh 
    996  1.16  msaitoh 	/* if msg sent wait until we receive an ack */
    997  1.16  msaitoh 	ixgbe_poll_for_ack(hw, vf_id);
    998   1.1   dyoung 
    999   1.1   dyoung 	/* update stats */
   1000   1.8  msaitoh 	hw->mbx.stats.msgs_tx.ev_count++;
   1001   1.1   dyoung 
   1002  1.16  msaitoh out:
   1003  1.16  msaitoh 	hw->mbx.ops[vf_id].release(hw, vf_id);
   1004  1.16  msaitoh 
   1005   1.1   dyoung 	return ret_val;
   1006   1.1   dyoung 
   1007   1.1   dyoung }
   1008   1.1   dyoung 
   1009   1.1   dyoung /**
   1010  1.16  msaitoh  * ixgbe_read_mbx_pf_legacy - Read a message from the mailbox
   1011  1.16  msaitoh  * @hw: pointer to the HW structure
   1012  1.16  msaitoh  * @msg: The message buffer
   1013  1.16  msaitoh  * @size: Length of buffer
   1014  1.16  msaitoh  * @vf_id: the VF index
   1015  1.16  msaitoh  *
   1016  1.16  msaitoh  * This function copies a message from the mailbox buffer to the caller's
   1017  1.16  msaitoh  * memory buffer.  The presumption is that the caller knows that there was
   1018  1.16  msaitoh  * a message due to a VF request so no polling for message is needed.
   1019  1.16  msaitoh  **/
   1020  1.16  msaitoh static s32 ixgbe_read_mbx_pf_legacy(struct ixgbe_hw *hw, u32 *msg, u16 size,
   1021  1.16  msaitoh 				    u16 vf_id)
   1022  1.16  msaitoh {
   1023  1.16  msaitoh 	s32 ret_val;
   1024  1.16  msaitoh 	u16 i;
   1025  1.16  msaitoh 
   1026  1.16  msaitoh 	DEBUGFUNC("ixgbe_read_mbx_pf_legacy");
   1027  1.16  msaitoh 
   1028  1.16  msaitoh 	/* lock the mailbox to prevent pf/vf race condition */
   1029  1.16  msaitoh 	ret_val = ixgbe_obtain_mbx_lock_pf(hw, vf_id);
   1030  1.16  msaitoh 	if (ret_val != IXGBE_SUCCESS)
   1031  1.16  msaitoh 		return ret_val;
   1032  1.16  msaitoh 
   1033  1.16  msaitoh 	/* copy the message to the mailbox memory buffer */
   1034  1.16  msaitoh 	for (i = 0; i < size; i++)
   1035  1.16  msaitoh 		msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i);
   1036  1.16  msaitoh 
   1037  1.16  msaitoh 	/* Acknowledge the message and release buffer */
   1038  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), IXGBE_PFMAILBOX_ACK);
   1039  1.16  msaitoh 
   1040  1.16  msaitoh 	/* update stats */
   1041  1.16  msaitoh 	hw->mbx.stats.msgs_rx.ev_count++;
   1042  1.16  msaitoh 
   1043  1.16  msaitoh 	return IXGBE_SUCCESS;
   1044  1.16  msaitoh }
   1045  1.16  msaitoh 
   1046  1.16  msaitoh /**
   1047  1.13  msaitoh  * ixgbe_read_mbx_pf - Read a message from the mailbox
   1048  1.13  msaitoh  * @hw: pointer to the HW structure
   1049  1.13  msaitoh  * @msg: The message buffer
   1050  1.13  msaitoh  * @size: Length of buffer
   1051  1.16  msaitoh  * @vf_id: the VF index
   1052  1.13  msaitoh  *
   1053  1.13  msaitoh  * This function copies a message from the mailbox buffer to the caller's
   1054  1.13  msaitoh  * memory buffer.  The presumption is that the caller knows that there was
   1055  1.13  msaitoh  * a message due to a VF request so no polling for message is needed.
   1056   1.1   dyoung  **/
   1057   1.1   dyoung static s32 ixgbe_read_mbx_pf(struct ixgbe_hw *hw, u32 *msg, u16 size,
   1058  1.16  msaitoh 			     u16 vf_id)
   1059   1.1   dyoung {
   1060  1.16  msaitoh 	u32 pf_mailbox;
   1061   1.1   dyoung 	s32 ret_val;
   1062   1.1   dyoung 	u16 i;
   1063   1.1   dyoung 
   1064   1.1   dyoung 	DEBUGFUNC("ixgbe_read_mbx_pf");
   1065   1.1   dyoung 
   1066  1.16  msaitoh 	/* check if there is a message from VF */
   1067  1.16  msaitoh 	ret_val = ixgbe_check_for_msg_pf(hw, vf_id);
   1068  1.16  msaitoh 	if (ret_val != IXGBE_SUCCESS)
   1069  1.16  msaitoh 		return IXGBE_ERR_MBX_NOMSG;
   1070  1.16  msaitoh 
   1071  1.16  msaitoh 	ixgbe_clear_msg_pf(hw, vf_id);
   1072   1.1   dyoung 
   1073   1.1   dyoung 	/* copy the message to the mailbox memory buffer */
   1074   1.1   dyoung 	for (i = 0; i < size; i++)
   1075  1.16  msaitoh 		msg[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i);
   1076   1.1   dyoung 
   1077   1.1   dyoung 	/* Acknowledge the message and release buffer */
   1078  1.16  msaitoh 	pf_mailbox = IXGBE_READ_REG(hw, IXGBE_PFMAILBOX(vf_id));
   1079  1.16  msaitoh 	pf_mailbox |= IXGBE_PFMAILBOX_ACK;
   1080  1.16  msaitoh 	IXGBE_WRITE_REG(hw, IXGBE_PFMAILBOX(vf_id), pf_mailbox);
   1081   1.1   dyoung 
   1082   1.1   dyoung 	/* update stats */
   1083   1.8  msaitoh 	hw->mbx.stats.msgs_rx.ev_count++;
   1084   1.1   dyoung 
   1085  1.16  msaitoh 	return IXGBE_SUCCESS;
   1086   1.1   dyoung }
   1087   1.1   dyoung 
   1088   1.1   dyoung /**
   1089  1.13  msaitoh  * ixgbe_clear_mbx_pf - Clear Mailbox Memory
   1090  1.13  msaitoh  * @hw: pointer to the HW structure
   1091  1.16  msaitoh  * @vf_id: the VF index
   1092  1.11  msaitoh  *
   1093  1.13  msaitoh  * Set VFMBMEM of given VF to 0x0.
   1094  1.11  msaitoh  **/
   1095  1.16  msaitoh static s32 ixgbe_clear_mbx_pf(struct ixgbe_hw *hw, u16 vf_id)
   1096  1.11  msaitoh {
   1097  1.11  msaitoh 	u16 mbx_size = hw->mbx.size;
   1098  1.11  msaitoh 	u16 i;
   1099  1.11  msaitoh 
   1100  1.16  msaitoh 	if (vf_id > 63)
   1101  1.11  msaitoh 		return IXGBE_ERR_PARAM;
   1102  1.11  msaitoh 
   1103  1.11  msaitoh 	for (i = 0; i < mbx_size; ++i)
   1104  1.16  msaitoh 		IXGBE_WRITE_REG_ARRAY(hw, IXGBE_PFMBMEM(vf_id), i, 0x0);
   1105  1.11  msaitoh 
   1106  1.11  msaitoh 	return IXGBE_SUCCESS;
   1107  1.11  msaitoh }
   1108  1.11  msaitoh 
   1109  1.11  msaitoh /**
   1110  1.16  msaitoh  * ixgbe_init_mbx_params_pf_id - set initial values for pf mailbox
   1111  1.16  msaitoh  * @hw: pointer to the HW structure
   1112  1.16  msaitoh  * @vf_id: the VF index
   1113  1.16  msaitoh  *
   1114  1.16  msaitoh  * Initializes single set of the hw->mbx struct to correct values for pf mailbox
   1115  1.16  msaitoh  * Set of legacy functions is being used here
   1116  1.16  msaitoh  */
   1117  1.16  msaitoh void ixgbe_init_mbx_params_pf_id(struct ixgbe_hw *hw, u16 vf_id)
   1118  1.16  msaitoh {
   1119  1.16  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
   1120  1.16  msaitoh 
   1121  1.16  msaitoh 	mbx->ops[vf_id].release = ixgbe_release_mbx_lock_dummy;
   1122  1.16  msaitoh 	mbx->ops[vf_id].read = ixgbe_read_mbx_pf_legacy;
   1123  1.16  msaitoh 	mbx->ops[vf_id].write = ixgbe_write_mbx_pf_legacy;
   1124  1.16  msaitoh 	mbx->ops[vf_id].check_for_msg = ixgbe_check_for_msg_pf;
   1125  1.16  msaitoh 	mbx->ops[vf_id].check_for_ack = ixgbe_check_for_ack_pf;
   1126  1.16  msaitoh 	mbx->ops[vf_id].check_for_rst = ixgbe_check_for_rst_pf;
   1127  1.16  msaitoh 	mbx->ops[vf_id].clear = ixgbe_clear_mbx_pf;
   1128  1.16  msaitoh }
   1129  1.16  msaitoh 
   1130  1.16  msaitoh /**
   1131  1.13  msaitoh  * ixgbe_init_mbx_params_pf - set initial values for pf mailbox
   1132  1.13  msaitoh  * @hw: pointer to the HW structure
   1133   1.1   dyoung  *
   1134  1.16  msaitoh  * Initializes all sets of the hw->mbx struct to correct values for pf
   1135  1.16  msaitoh  * mailbox. One set corresponds to single VF. It also initializes counters
   1136  1.16  msaitoh  * and general variables. A set of legacy functions is used by default.
   1137   1.1   dyoung  */
   1138   1.1   dyoung void ixgbe_init_mbx_params_pf(struct ixgbe_hw *hw)
   1139   1.1   dyoung {
   1140  1.16  msaitoh 	u16 i;
   1141   1.1   dyoung 	struct ixgbe_mbx_info *mbx = &hw->mbx;
   1142   1.1   dyoung 
   1143  1.16  msaitoh 	/* Ensure we are not calling this function from VF */
   1144   1.2  msaitoh 	if (hw->mac.type != ixgbe_mac_82599EB &&
   1145   1.4  msaitoh 	    hw->mac.type != ixgbe_mac_X550 &&
   1146   1.4  msaitoh 	    hw->mac.type != ixgbe_mac_X550EM_x &&
   1147   1.7  msaitoh 	    hw->mac.type != ixgbe_mac_X550EM_a &&
   1148   1.2  msaitoh 	    hw->mac.type != ixgbe_mac_X540)
   1149   1.1   dyoung 		return;
   1150   1.1   dyoung 
   1151  1.16  msaitoh 	/* Initialize common mailbox settings */
   1152  1.16  msaitoh 	mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
   1153  1.16  msaitoh 	mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
   1154  1.16  msaitoh 	mbx->size = IXGBE_VFMAILBOX_SIZE;
   1155  1.16  msaitoh 
   1156  1.16  msaitoh 	/* Initialize counters with zeroes */
   1157  1.16  msaitoh 	mbx->stats.msgs_tx.ev_count = 0;
   1158  1.16  msaitoh 	mbx->stats.msgs_rx.ev_count = 0;
   1159  1.16  msaitoh 	mbx->stats.reqs.ev_count = 0;
   1160  1.16  msaitoh 	mbx->stats.acks.ev_count = 0;
   1161  1.16  msaitoh 	mbx->stats.rsts.ev_count = 0;
   1162  1.16  msaitoh 
   1163  1.16  msaitoh 	/* No matter of VF number, we initialize params for all 64 VFs. */
   1164  1.16  msaitoh 	/* TODO: 1. Add a define for max VF and refactor SHARED to get rid
   1165  1.16  msaitoh 	 * of magic number for that (63 or 64 depending on use case.)
   1166  1.16  msaitoh 	 * 2. rewrite the code to dynamically allocate mbx->ops[vf_id] for
   1167  1.16  msaitoh 	 * certain number of VFs instead of default maximum value of 64 (0..63)
   1168  1.16  msaitoh 	 */
   1169  1.16  msaitoh 	for (i = 0; i < 64; i++)
   1170  1.16  msaitoh 		ixgbe_init_mbx_params_pf_id(hw, i);
   1171  1.16  msaitoh }
   1172  1.16  msaitoh 
   1173  1.16  msaitoh /**
   1174  1.16  msaitoh  * ixgbe_upgrade_mbx_params_pf - Upgrade initial values for pf mailbox
   1175  1.16  msaitoh  * @hw: pointer to the HW structure
   1176  1.16  msaitoh  * @vf_id: the VF index
   1177  1.16  msaitoh  *
   1178  1.16  msaitoh  * Initializes the hw->mbx struct to new function set for improved
   1179  1.16  msaitoh  * stability and handling of messages.
   1180  1.16  msaitoh  */
   1181  1.16  msaitoh void ixgbe_upgrade_mbx_params_pf(struct ixgbe_hw *hw, u16 vf_id)
   1182  1.16  msaitoh {
   1183  1.16  msaitoh 	struct ixgbe_mbx_info *mbx = &hw->mbx;
   1184  1.16  msaitoh 
   1185  1.16  msaitoh    /* Ensure we are not calling this function from VF */
   1186  1.16  msaitoh 	if (hw->mac.type != ixgbe_mac_82599EB &&
   1187  1.16  msaitoh 	    hw->mac.type != ixgbe_mac_X550 &&
   1188  1.16  msaitoh 	    hw->mac.type != ixgbe_mac_X550EM_x &&
   1189  1.16  msaitoh 	    hw->mac.type != ixgbe_mac_X550EM_a &&
   1190  1.16  msaitoh 	    hw->mac.type != ixgbe_mac_X540)
   1191  1.16  msaitoh 		return;
   1192   1.1   dyoung 
   1193  1.16  msaitoh 	mbx->timeout = IXGBE_VF_MBX_INIT_TIMEOUT;
   1194  1.16  msaitoh 	mbx->usec_delay = IXGBE_VF_MBX_INIT_DELAY;
   1195   1.1   dyoung 	mbx->size = IXGBE_VFMAILBOX_SIZE;
   1196   1.1   dyoung 
   1197  1.16  msaitoh 	mbx->ops[vf_id].release = ixgbe_release_mbx_lock_pf;
   1198  1.16  msaitoh 	mbx->ops[vf_id].read = ixgbe_read_mbx_pf;
   1199  1.16  msaitoh 	mbx->ops[vf_id].write = ixgbe_write_mbx_pf;
   1200  1.16  msaitoh 	mbx->ops[vf_id].check_for_msg = ixgbe_check_for_msg_pf;
   1201  1.16  msaitoh 	mbx->ops[vf_id].check_for_ack = ixgbe_check_for_ack_pf;
   1202  1.16  msaitoh 	mbx->ops[vf_id].check_for_rst = ixgbe_check_for_rst_pf;
   1203  1.16  msaitoh 	mbx->ops[vf_id].clear = ixgbe_clear_mbx_pf;
   1204   1.1   dyoung 
   1205   1.8  msaitoh 	mbx->stats.msgs_tx.ev_count = 0;
   1206   1.8  msaitoh 	mbx->stats.msgs_rx.ev_count = 0;
   1207   1.8  msaitoh 	mbx->stats.reqs.ev_count = 0;
   1208   1.8  msaitoh 	mbx->stats.acks.ev_count = 0;
   1209   1.8  msaitoh 	mbx->stats.rsts.ev_count = 0;
   1210   1.1   dyoung }
   1211