1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
32 * ixgbevf_poll_for_msg - Wait for message notification
33 * @hw: pointer to the HW structure
35 * returns 0 if it successfully received a message notification
37 static s32
ixgbevf_poll_for_msg(struct ixgbe_hw
*hw
)
39 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
40 int countdown
= mbx
->timeout
;
42 while (countdown
&& mbx
->ops
.check_for_msg(hw
)) {
47 /* if we failed, all future posted messages fail until reset */
51 return countdown
? 0 : IXGBE_ERR_MBX
;
55 * ixgbevf_poll_for_ack - Wait for message acknowledgement
56 * @hw: pointer to the HW structure
58 * returns 0 if it successfully received a message acknowledgement
60 static s32
ixgbevf_poll_for_ack(struct ixgbe_hw
*hw
)
62 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
63 int countdown
= mbx
->timeout
;
65 while (countdown
&& mbx
->ops
.check_for_ack(hw
)) {
70 /* if we failed, all future posted messages fail until reset */
74 return countdown
? 0 : IXGBE_ERR_MBX
;
78 * ixgbevf_read_posted_mbx - Wait for message notification and receive message
79 * @hw: pointer to the HW structure
80 * @msg: The message buffer
81 * @size: Length of buffer
83 * returns 0 if it successfully received a message notification and
84 * copied it into the receive buffer.
86 static s32
ixgbevf_read_posted_mbx(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
88 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
89 s32 ret_val
= IXGBE_ERR_MBX
;
91 ret_val
= ixgbevf_poll_for_msg(hw
);
93 /* if ack received read message, otherwise we timed out */
95 ret_val
= mbx
->ops
.read(hw
, msg
, size
);
101 * ixgbevf_write_posted_mbx - Write a message to the mailbox, wait for ack
102 * @hw: pointer to the HW structure
103 * @msg: The message buffer
104 * @size: Length of buffer
106 * returns 0 if it successfully copied message into the buffer and
107 * received an ack to that message within delay * timeout period
109 static s32
ixgbevf_write_posted_mbx(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
111 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
115 ret_val
= mbx
->ops
.write(hw
, msg
, size
);
117 /* if msg sent wait until we receive an ack */
119 ret_val
= ixgbevf_poll_for_ack(hw
);
125 * ixgbevf_read_v2p_mailbox - read v2p mailbox
126 * @hw: pointer to the HW structure
128 * This function is used to read the v2p mailbox without losing the read to
131 static u32
ixgbevf_read_v2p_mailbox(struct ixgbe_hw
*hw
)
133 u32 v2p_mailbox
= IXGBE_READ_REG(hw
, IXGBE_VFMAILBOX
);
135 v2p_mailbox
|= hw
->mbx
.v2p_mailbox
;
136 hw
->mbx
.v2p_mailbox
|= v2p_mailbox
& IXGBE_VFMAILBOX_R2C_BITS
;
142 * ixgbevf_check_for_bit_vf - Determine if a status bit was set
143 * @hw: pointer to the HW structure
144 * @mask: bitmask for bits to be tested and cleared
146 * This function is used to check for the read to clear bits within
149 static s32
ixgbevf_check_for_bit_vf(struct ixgbe_hw
*hw
, u32 mask
)
151 u32 v2p_mailbox
= ixgbevf_read_v2p_mailbox(hw
);
152 s32 ret_val
= IXGBE_ERR_MBX
;
154 if (v2p_mailbox
& mask
)
157 hw
->mbx
.v2p_mailbox
&= ~mask
;
163 * ixgbevf_check_for_msg_vf - checks to see if the PF has sent mail
164 * @hw: pointer to the HW structure
166 * returns 0 if the PF has set the Status bit or else ERR_MBX
168 static s32
ixgbevf_check_for_msg_vf(struct ixgbe_hw
*hw
)
170 s32 ret_val
= IXGBE_ERR_MBX
;
172 if (!ixgbevf_check_for_bit_vf(hw
, IXGBE_VFMAILBOX_PFSTS
)) {
174 hw
->mbx
.stats
.reqs
++;
181 * ixgbevf_check_for_ack_vf - checks to see if the PF has ACK'd
182 * @hw: pointer to the HW structure
184 * returns 0 if the PF has set the ACK bit or else ERR_MBX
186 static s32
ixgbevf_check_for_ack_vf(struct ixgbe_hw
*hw
)
188 s32 ret_val
= IXGBE_ERR_MBX
;
190 if (!ixgbevf_check_for_bit_vf(hw
, IXGBE_VFMAILBOX_PFACK
)) {
192 hw
->mbx
.stats
.acks
++;
199 * ixgbevf_check_for_rst_vf - checks to see if the PF has reset
200 * @hw: pointer to the HW structure
202 * returns true if the PF has set the reset done bit or else false
204 static s32
ixgbevf_check_for_rst_vf(struct ixgbe_hw
*hw
)
206 s32 ret_val
= IXGBE_ERR_MBX
;
208 if (!ixgbevf_check_for_bit_vf(hw
, (IXGBE_VFMAILBOX_RSTD
|
209 IXGBE_VFMAILBOX_RSTI
))) {
211 hw
->mbx
.stats
.rsts
++;
218 * ixgbevf_obtain_mbx_lock_vf - obtain mailbox lock
219 * @hw: pointer to the HW structure
221 * return 0 if we obtained the mailbox lock
223 static s32
ixgbevf_obtain_mbx_lock_vf(struct ixgbe_hw
*hw
)
225 s32 ret_val
= IXGBE_ERR_MBX
;
227 /* Take ownership of the buffer */
228 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_VFU
);
230 /* reserve mailbox for vf use */
231 if (ixgbevf_read_v2p_mailbox(hw
) & IXGBE_VFMAILBOX_VFU
)
238 * ixgbevf_write_mbx_vf - Write a message to the mailbox
239 * @hw: pointer to the HW structure
240 * @msg: The message buffer
241 * @size: Length of buffer
243 * returns 0 if it successfully copied message into the buffer
245 static s32
ixgbevf_write_mbx_vf(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
251 /* lock the mailbox to prevent pf/vf race condition */
252 ret_val
= ixgbevf_obtain_mbx_lock_vf(hw
);
256 /* flush msg and acks as we are overwriting the message buffer */
257 ixgbevf_check_for_msg_vf(hw
);
258 ixgbevf_check_for_ack_vf(hw
);
260 /* copy the caller specified message to the mailbox memory buffer */
261 for (i
= 0; i
< size
; i
++)
262 IXGBE_WRITE_REG_ARRAY(hw
, IXGBE_VFMBMEM
, i
, msg
[i
]);
265 hw
->mbx
.stats
.msgs_tx
++;
267 /* Drop VFU and interrupt the PF to tell it a message has been sent */
268 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_REQ
);
275 * ixgbevf_read_mbx_vf - Reads a message from the inbox intended for vf
276 * @hw: pointer to the HW structure
277 * @msg: The message buffer
278 * @size: Length of buffer
280 * returns 0 if it successfully read message from buffer
282 static s32
ixgbevf_read_mbx_vf(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
287 /* lock the mailbox to prevent pf/vf race condition */
288 ret_val
= ixgbevf_obtain_mbx_lock_vf(hw
);
292 /* copy the message from the mailbox memory buffer */
293 for (i
= 0; i
< size
; i
++)
294 msg
[i
] = IXGBE_READ_REG_ARRAY(hw
, IXGBE_VFMBMEM
, i
);
296 /* Acknowledge receipt and release mailbox, then we're done */
297 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_ACK
);
300 hw
->mbx
.stats
.msgs_rx
++;
307 * ixgbevf_init_mbx_params_vf - set initial values for vf mailbox
308 * @hw: pointer to the HW structure
310 * Initializes the hw->mbx struct to correct values for vf mailbox
312 static s32
ixgbevf_init_mbx_params_vf(struct ixgbe_hw
*hw
)
314 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
316 /* start mailbox as timed out and let the reset_hw call set the timeout
317 * value to begin communications */
319 mbx
->udelay
= IXGBE_VF_MBX_INIT_DELAY
;
321 mbx
->size
= IXGBE_VFMAILBOX_SIZE
;
323 mbx
->stats
.msgs_tx
= 0;
324 mbx
->stats
.msgs_rx
= 0;
332 const struct ixgbe_mbx_operations ixgbevf_mbx_ops
= {
333 .init_params
= ixgbevf_init_mbx_params_vf
,
334 .read
= ixgbevf_read_mbx_vf
,
335 .write
= ixgbevf_write_mbx_vf
,
336 .read_posted
= ixgbevf_read_posted_mbx
,
337 .write_posted
= ixgbevf_write_posted_mbx
,
338 .check_for_msg
= ixgbevf_check_for_msg_vf
,
339 .check_for_ack
= ixgbevf_check_for_ack_vf
,
340 .check_for_rst
= ixgbevf_check_for_rst_vf
,