1 /*******************************************************************************
3 Intel 82599 Virtual Function driver
4 Copyright(c) 1999 - 2015 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, see <http://www.gnu.org/licenses/>.
18 The full GNU General Public License is included in this distribution in
19 the file called "COPYING".
22 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *******************************************************************************/
31 * ixgbevf_poll_for_msg - Wait for message notification
32 * @hw: pointer to the HW structure
34 * returns 0 if it successfully received a message notification
36 static s32
ixgbevf_poll_for_msg(struct ixgbe_hw
*hw
)
38 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
39 int countdown
= mbx
->timeout
;
41 while (countdown
&& mbx
->ops
.check_for_msg(hw
)) {
46 /* if we failed, all future posted messages fail until reset */
50 return countdown
? 0 : IXGBE_ERR_MBX
;
54 * ixgbevf_poll_for_ack - Wait for message acknowledgment
55 * @hw: pointer to the HW structure
57 * returns 0 if it successfully received a message acknowledgment
59 static s32
ixgbevf_poll_for_ack(struct ixgbe_hw
*hw
)
61 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
62 int countdown
= mbx
->timeout
;
64 while (countdown
&& mbx
->ops
.check_for_ack(hw
)) {
69 /* if we failed, all future posted messages fail until reset */
73 return countdown
? 0 : IXGBE_ERR_MBX
;
77 * ixgbevf_read_posted_mbx - Wait for message notification and receive message
78 * @hw: pointer to the HW structure
79 * @msg: The message buffer
80 * @size: Length of buffer
82 * returns 0 if it successfully received a message notification and
83 * copied it into the receive buffer.
85 static s32
ixgbevf_read_posted_mbx(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
87 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
88 s32 ret_val
= IXGBE_ERR_MBX
;
93 ret_val
= ixgbevf_poll_for_msg(hw
);
95 /* if ack received read message, otherwise we timed out */
97 ret_val
= mbx
->ops
.read(hw
, msg
, size
);
103 * ixgbevf_write_posted_mbx - Write a message to the mailbox, wait for ack
104 * @hw: pointer to the HW structure
105 * @msg: The message buffer
106 * @size: Length of buffer
108 * returns 0 if it successfully copied message into the buffer and
109 * received an ack to that message within delay * timeout period
111 static s32
ixgbevf_write_posted_mbx(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
113 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
114 s32 ret_val
= IXGBE_ERR_MBX
;
116 /* exit if either we can't write or there isn't a defined timeout */
117 if (!mbx
->ops
.write
|| !mbx
->timeout
)
121 ret_val
= mbx
->ops
.write(hw
, msg
, size
);
123 /* if msg sent wait until we receive an ack */
125 ret_val
= ixgbevf_poll_for_ack(hw
);
131 * ixgbevf_read_v2p_mailbox - read v2p mailbox
132 * @hw: pointer to the HW structure
134 * This function is used to read the v2p mailbox without losing the read to
137 static u32
ixgbevf_read_v2p_mailbox(struct ixgbe_hw
*hw
)
139 u32 v2p_mailbox
= IXGBE_READ_REG(hw
, IXGBE_VFMAILBOX
);
141 v2p_mailbox
|= hw
->mbx
.v2p_mailbox
;
142 hw
->mbx
.v2p_mailbox
|= v2p_mailbox
& IXGBE_VFMAILBOX_R2C_BITS
;
148 * ixgbevf_check_for_bit_vf - Determine if a status bit was set
149 * @hw: pointer to the HW structure
150 * @mask: bitmask for bits to be tested and cleared
152 * This function is used to check for the read to clear bits within
155 static s32
ixgbevf_check_for_bit_vf(struct ixgbe_hw
*hw
, u32 mask
)
157 u32 v2p_mailbox
= ixgbevf_read_v2p_mailbox(hw
);
158 s32 ret_val
= IXGBE_ERR_MBX
;
160 if (v2p_mailbox
& mask
)
163 hw
->mbx
.v2p_mailbox
&= ~mask
;
169 * ixgbevf_check_for_msg_vf - checks to see if the PF has sent mail
170 * @hw: pointer to the HW structure
172 * returns 0 if the PF has set the Status bit or else ERR_MBX
174 static s32
ixgbevf_check_for_msg_vf(struct ixgbe_hw
*hw
)
176 s32 ret_val
= IXGBE_ERR_MBX
;
178 if (!ixgbevf_check_for_bit_vf(hw
, IXGBE_VFMAILBOX_PFSTS
)) {
180 hw
->mbx
.stats
.reqs
++;
187 * ixgbevf_check_for_ack_vf - checks to see if the PF has ACK'd
188 * @hw: pointer to the HW structure
190 * returns 0 if the PF has set the ACK bit or else ERR_MBX
192 static s32
ixgbevf_check_for_ack_vf(struct ixgbe_hw
*hw
)
194 s32 ret_val
= IXGBE_ERR_MBX
;
196 if (!ixgbevf_check_for_bit_vf(hw
, IXGBE_VFMAILBOX_PFACK
)) {
198 hw
->mbx
.stats
.acks
++;
205 * ixgbevf_check_for_rst_vf - checks to see if the PF has reset
206 * @hw: pointer to the HW structure
208 * returns true if the PF has set the reset done bit or else false
210 static s32
ixgbevf_check_for_rst_vf(struct ixgbe_hw
*hw
)
212 s32 ret_val
= IXGBE_ERR_MBX
;
214 if (!ixgbevf_check_for_bit_vf(hw
, (IXGBE_VFMAILBOX_RSTD
|
215 IXGBE_VFMAILBOX_RSTI
))) {
217 hw
->mbx
.stats
.rsts
++;
224 * ixgbevf_obtain_mbx_lock_vf - obtain mailbox lock
225 * @hw: pointer to the HW structure
227 * return 0 if we obtained the mailbox lock
229 static s32
ixgbevf_obtain_mbx_lock_vf(struct ixgbe_hw
*hw
)
231 s32 ret_val
= IXGBE_ERR_MBX
;
233 /* Take ownership of the buffer */
234 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_VFU
);
236 /* reserve mailbox for VF use */
237 if (ixgbevf_read_v2p_mailbox(hw
) & IXGBE_VFMAILBOX_VFU
)
244 * ixgbevf_write_mbx_vf - Write a message to the mailbox
245 * @hw: pointer to the HW structure
246 * @msg: The message buffer
247 * @size: Length of buffer
249 * returns 0 if it successfully copied message into the buffer
251 static s32
ixgbevf_write_mbx_vf(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
256 /* lock the mailbox to prevent PF/VF race condition */
257 ret_val
= ixgbevf_obtain_mbx_lock_vf(hw
);
261 /* flush msg and acks as we are overwriting the message buffer */
262 ixgbevf_check_for_msg_vf(hw
);
263 ixgbevf_check_for_ack_vf(hw
);
265 /* copy the caller specified message to the mailbox memory buffer */
266 for (i
= 0; i
< size
; i
++)
267 IXGBE_WRITE_REG_ARRAY(hw
, IXGBE_VFMBMEM
, i
, msg
[i
]);
270 hw
->mbx
.stats
.msgs_tx
++;
272 /* Drop VFU and interrupt the PF to tell it a message has been sent */
273 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_REQ
);
280 * ixgbevf_read_mbx_vf - Reads a message from the inbox intended for VF
281 * @hw: pointer to the HW structure
282 * @msg: The message buffer
283 * @size: Length of buffer
285 * returns 0 if it successfully read message from buffer
287 static s32
ixgbevf_read_mbx_vf(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
292 /* lock the mailbox to prevent PF/VF race condition */
293 ret_val
= ixgbevf_obtain_mbx_lock_vf(hw
);
297 /* copy the message from the mailbox memory buffer */
298 for (i
= 0; i
< size
; i
++)
299 msg
[i
] = IXGBE_READ_REG_ARRAY(hw
, IXGBE_VFMBMEM
, i
);
301 /* Acknowledge receipt and release mailbox, then we're done */
302 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_ACK
);
305 hw
->mbx
.stats
.msgs_rx
++;
312 * ixgbevf_init_mbx_params_vf - set initial values for VF mailbox
313 * @hw: pointer to the HW structure
315 * Initializes the hw->mbx struct to correct values for VF mailbox
317 static s32
ixgbevf_init_mbx_params_vf(struct ixgbe_hw
*hw
)
319 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
321 /* start mailbox as timed out and let the reset_hw call set the timeout
322 * value to begin communications
325 mbx
->udelay
= IXGBE_VF_MBX_INIT_DELAY
;
327 mbx
->size
= IXGBE_VFMAILBOX_SIZE
;
329 mbx
->stats
.msgs_tx
= 0;
330 mbx
->stats
.msgs_rx
= 0;
338 const struct ixgbe_mbx_operations ixgbevf_mbx_ops
= {
339 .init_params
= ixgbevf_init_mbx_params_vf
,
340 .read
= ixgbevf_read_mbx_vf
,
341 .write
= ixgbevf_write_mbx_vf
,
342 .read_posted
= ixgbevf_read_posted_mbx
,
343 .write_posted
= ixgbevf_write_posted_mbx
,
344 .check_for_msg
= ixgbevf_check_for_msg_vf
,
345 .check_for_ack
= ixgbevf_check_for_ack_vf
,
346 .check_for_rst
= ixgbevf_check_for_rst_vf
,
349 /* Mailbox operations when running on Hyper-V.
350 * On Hyper-V, PF/VF communication is not through the
351 * hardware mailbox; this communication is through
352 * a software mediated path.
353 * Most mail box operations are noop while running on
356 const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops
= {
357 .init_params
= ixgbevf_init_mbx_params_vf
,
358 .check_for_rst
= ixgbevf_check_for_rst_vf
,