x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / drivers / net / ethernet / intel / ixgbevf / mbx.c
blob2819abc454c7e71c024ab280ec3a5a1780a07a4b
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
13 more details.
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".
21 Contact Information:
22 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *******************************************************************************/
27 #include "mbx.h"
28 #include "ixgbevf.h"
30 /**
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
35 **/
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)) {
42 countdown--;
43 udelay(mbx->udelay);
46 /* if we failed, all future posted messages fail until reset */
47 if (!countdown)
48 mbx->timeout = 0;
50 return countdown ? 0 : IXGBE_ERR_MBX;
53 /**
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
58 **/
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)) {
65 countdown--;
66 udelay(mbx->udelay);
69 /* if we failed, all future posted messages fail until reset */
70 if (!countdown)
71 mbx->timeout = 0;
73 return countdown ? 0 : IXGBE_ERR_MBX;
76 /**
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.
84 **/
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;
90 if (!mbx->ops.read)
91 goto out;
93 ret_val = ixgbevf_poll_for_msg(hw);
95 /* if ack received read message, otherwise we timed out */
96 if (!ret_val)
97 ret_val = mbx->ops.read(hw, msg, size);
98 out:
99 return ret_val;
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)
118 goto out;
120 /* send msg */
121 ret_val = mbx->ops.write(hw, msg, size);
123 /* if msg sent wait until we receive an ack */
124 if (!ret_val)
125 ret_val = ixgbevf_poll_for_ack(hw);
126 out:
127 return ret_val;
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
135 * clear status bits.
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;
144 return v2p_mailbox;
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
153 * the V2P mailbox.
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)
161 ret_val = 0;
163 hw->mbx.v2p_mailbox &= ~mask;
165 return ret_val;
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)) {
179 ret_val = 0;
180 hw->mbx.stats.reqs++;
183 return ret_val;
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)) {
197 ret_val = 0;
198 hw->mbx.stats.acks++;
201 return ret_val;
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))) {
216 ret_val = 0;
217 hw->mbx.stats.rsts++;
220 return ret_val;
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)
238 ret_val = 0;
240 return ret_val;
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)
253 s32 ret_val;
254 u16 i;
256 /* lock the mailbox to prevent PF/VF race condition */
257 ret_val = ixgbevf_obtain_mbx_lock_vf(hw);
258 if (ret_val)
259 goto out_no_write;
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]);
269 /* update stats */
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);
275 out_no_write:
276 return ret_val;
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)
289 s32 ret_val = 0;
290 u16 i;
292 /* lock the mailbox to prevent PF/VF race condition */
293 ret_val = ixgbevf_obtain_mbx_lock_vf(hw);
294 if (ret_val)
295 goto out_no_read;
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);
304 /* update stats */
305 hw->mbx.stats.msgs_rx++;
307 out_no_read:
308 return ret_val;
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
324 mbx->timeout = 0;
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;
331 mbx->stats.reqs = 0;
332 mbx->stats.acks = 0;
333 mbx->stats.rsts = 0;
335 return 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
354 * Hyper-V.
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,