1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
8 * ixgbevf_poll_for_msg - Wait for message notification
9 * @hw: pointer to the HW structure
11 * returns 0 if it successfully received a message notification
13 static s32
ixgbevf_poll_for_msg(struct ixgbe_hw
*hw
)
15 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
16 int countdown
= mbx
->timeout
;
18 while (countdown
&& mbx
->ops
.check_for_msg(hw
)) {
23 /* if we failed, all future posted messages fail until reset */
27 return countdown
? 0 : IXGBE_ERR_MBX
;
31 * ixgbevf_poll_for_ack - Wait for message acknowledgment
32 * @hw: pointer to the HW structure
34 * returns 0 if it successfully received a message acknowledgment
36 static s32
ixgbevf_poll_for_ack(struct ixgbe_hw
*hw
)
38 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
39 int countdown
= mbx
->timeout
;
41 while (countdown
&& mbx
->ops
.check_for_ack(hw
)) {
46 /* if we failed, all future posted messages fail until reset */
50 return countdown
? 0 : IXGBE_ERR_MBX
;
54 * ixgbevf_read_posted_mbx - Wait for message notification and receive message
55 * @hw: pointer to the HW structure
56 * @msg: The message buffer
57 * @size: Length of buffer
59 * returns 0 if it successfully received a message notification and
60 * copied it into the receive buffer.
62 static s32
ixgbevf_read_posted_mbx(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
64 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
65 s32 ret_val
= IXGBE_ERR_MBX
;
70 ret_val
= ixgbevf_poll_for_msg(hw
);
72 /* if ack received read message, otherwise we timed out */
74 ret_val
= mbx
->ops
.read(hw
, msg
, size
);
80 * ixgbevf_write_posted_mbx - Write a message to the mailbox, wait for ack
81 * @hw: pointer to the HW structure
82 * @msg: The message buffer
83 * @size: Length of buffer
85 * returns 0 if it successfully copied message into the buffer and
86 * received an ack to that message within delay * timeout period
88 static s32
ixgbevf_write_posted_mbx(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
90 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
91 s32 ret_val
= IXGBE_ERR_MBX
;
93 /* exit if either we can't write or there isn't a defined timeout */
94 if (!mbx
->ops
.write
|| !mbx
->timeout
)
98 ret_val
= mbx
->ops
.write(hw
, msg
, size
);
100 /* if msg sent wait until we receive an ack */
102 ret_val
= ixgbevf_poll_for_ack(hw
);
108 * ixgbevf_read_v2p_mailbox - read v2p mailbox
109 * @hw: pointer to the HW structure
111 * This function is used to read the v2p mailbox without losing the read to
114 static u32
ixgbevf_read_v2p_mailbox(struct ixgbe_hw
*hw
)
116 u32 v2p_mailbox
= IXGBE_READ_REG(hw
, IXGBE_VFMAILBOX
);
118 v2p_mailbox
|= hw
->mbx
.v2p_mailbox
;
119 hw
->mbx
.v2p_mailbox
|= v2p_mailbox
& IXGBE_VFMAILBOX_R2C_BITS
;
125 * ixgbevf_check_for_bit_vf - Determine if a status bit was set
126 * @hw: pointer to the HW structure
127 * @mask: bitmask for bits to be tested and cleared
129 * This function is used to check for the read to clear bits within
132 static s32
ixgbevf_check_for_bit_vf(struct ixgbe_hw
*hw
, u32 mask
)
134 u32 v2p_mailbox
= ixgbevf_read_v2p_mailbox(hw
);
135 s32 ret_val
= IXGBE_ERR_MBX
;
137 if (v2p_mailbox
& mask
)
140 hw
->mbx
.v2p_mailbox
&= ~mask
;
146 * ixgbevf_check_for_msg_vf - checks to see if the PF has sent mail
147 * @hw: pointer to the HW structure
149 * returns 0 if the PF has set the Status bit or else ERR_MBX
151 static s32
ixgbevf_check_for_msg_vf(struct ixgbe_hw
*hw
)
153 s32 ret_val
= IXGBE_ERR_MBX
;
155 if (!ixgbevf_check_for_bit_vf(hw
, IXGBE_VFMAILBOX_PFSTS
)) {
157 hw
->mbx
.stats
.reqs
++;
164 * ixgbevf_check_for_ack_vf - checks to see if the PF has ACK'd
165 * @hw: pointer to the HW structure
167 * returns 0 if the PF has set the ACK bit or else ERR_MBX
169 static s32
ixgbevf_check_for_ack_vf(struct ixgbe_hw
*hw
)
171 s32 ret_val
= IXGBE_ERR_MBX
;
173 if (!ixgbevf_check_for_bit_vf(hw
, IXGBE_VFMAILBOX_PFACK
)) {
175 hw
->mbx
.stats
.acks
++;
182 * ixgbevf_check_for_rst_vf - checks to see if the PF has reset
183 * @hw: pointer to the HW structure
185 * returns true if the PF has set the reset done bit or else false
187 static s32
ixgbevf_check_for_rst_vf(struct ixgbe_hw
*hw
)
189 s32 ret_val
= IXGBE_ERR_MBX
;
191 if (!ixgbevf_check_for_bit_vf(hw
, (IXGBE_VFMAILBOX_RSTD
|
192 IXGBE_VFMAILBOX_RSTI
))) {
194 hw
->mbx
.stats
.rsts
++;
201 * ixgbevf_obtain_mbx_lock_vf - obtain mailbox lock
202 * @hw: pointer to the HW structure
204 * return 0 if we obtained the mailbox lock
206 static s32
ixgbevf_obtain_mbx_lock_vf(struct ixgbe_hw
*hw
)
208 s32 ret_val
= IXGBE_ERR_MBX
;
210 /* Take ownership of the buffer */
211 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_VFU
);
213 /* reserve mailbox for VF use */
214 if (ixgbevf_read_v2p_mailbox(hw
) & IXGBE_VFMAILBOX_VFU
)
221 * ixgbevf_write_mbx_vf - Write a message to the mailbox
222 * @hw: pointer to the HW structure
223 * @msg: The message buffer
224 * @size: Length of buffer
226 * returns 0 if it successfully copied message into the buffer
228 static s32
ixgbevf_write_mbx_vf(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
233 /* lock the mailbox to prevent PF/VF race condition */
234 ret_val
= ixgbevf_obtain_mbx_lock_vf(hw
);
238 /* flush msg and acks as we are overwriting the message buffer */
239 ixgbevf_check_for_msg_vf(hw
);
240 ixgbevf_check_for_ack_vf(hw
);
242 /* copy the caller specified message to the mailbox memory buffer */
243 for (i
= 0; i
< size
; i
++)
244 IXGBE_WRITE_REG_ARRAY(hw
, IXGBE_VFMBMEM
, i
, msg
[i
]);
247 hw
->mbx
.stats
.msgs_tx
++;
249 /* Drop VFU and interrupt the PF to tell it a message has been sent */
250 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_REQ
);
257 * ixgbevf_read_mbx_vf - Reads a message from the inbox intended for VF
258 * @hw: pointer to the HW structure
259 * @msg: The message buffer
260 * @size: Length of buffer
262 * returns 0 if it successfully read message from buffer
264 static s32
ixgbevf_read_mbx_vf(struct ixgbe_hw
*hw
, u32
*msg
, u16 size
)
269 /* lock the mailbox to prevent PF/VF race condition */
270 ret_val
= ixgbevf_obtain_mbx_lock_vf(hw
);
274 /* copy the message from the mailbox memory buffer */
275 for (i
= 0; i
< size
; i
++)
276 msg
[i
] = IXGBE_READ_REG_ARRAY(hw
, IXGBE_VFMBMEM
, i
);
278 /* Acknowledge receipt and release mailbox, then we're done */
279 IXGBE_WRITE_REG(hw
, IXGBE_VFMAILBOX
, IXGBE_VFMAILBOX_ACK
);
282 hw
->mbx
.stats
.msgs_rx
++;
289 * ixgbevf_init_mbx_params_vf - set initial values for VF mailbox
290 * @hw: pointer to the HW structure
292 * Initializes the hw->mbx struct to correct values for VF mailbox
294 static s32
ixgbevf_init_mbx_params_vf(struct ixgbe_hw
*hw
)
296 struct ixgbe_mbx_info
*mbx
= &hw
->mbx
;
298 /* start mailbox as timed out and let the reset_hw call set the timeout
299 * value to begin communications
302 mbx
->udelay
= IXGBE_VF_MBX_INIT_DELAY
;
304 mbx
->size
= IXGBE_VFMAILBOX_SIZE
;
306 mbx
->stats
.msgs_tx
= 0;
307 mbx
->stats
.msgs_rx
= 0;
315 const struct ixgbe_mbx_operations ixgbevf_mbx_ops
= {
316 .init_params
= ixgbevf_init_mbx_params_vf
,
317 .read
= ixgbevf_read_mbx_vf
,
318 .write
= ixgbevf_write_mbx_vf
,
319 .read_posted
= ixgbevf_read_posted_mbx
,
320 .write_posted
= ixgbevf_write_posted_mbx
,
321 .check_for_msg
= ixgbevf_check_for_msg_vf
,
322 .check_for_ack
= ixgbevf_check_for_ack_vf
,
323 .check_for_rst
= ixgbevf_check_for_rst_vf
,
326 /* Mailbox operations when running on Hyper-V.
327 * On Hyper-V, PF/VF communication is not through the
328 * hardware mailbox; this communication is through
329 * a software mediated path.
330 * Most mail box operations are noop while running on
333 const struct ixgbe_mbx_operations ixgbevf_hv_mbx_ops
= {
334 .init_params
= ixgbevf_init_mbx_params_vf
,
335 .check_for_rst
= ixgbevf_check_for_rst_vf
,