1 /*******************************************************************************
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 1999 - 2008 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 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 FILE_LICENCE ( GPL2_ONLY );
31 #include "igbvf_mbx.h"
34 * igbvf_poll_for_msg - Wait for message notification
35 * @hw: pointer to the HW structure
36 * @mbx_id: id of mailbox to write
38 * returns SUCCESS if it successfully received a message notification
40 static s32 igbvf_poll_for_msg(struct e1000_hw *hw, u16 mbx_id)
42 struct e1000_mbx_info *mbx = &hw->mbx;
43 int countdown = mbx->timeout;
45 DEBUGFUNC("igbvf_poll_for_msg");
47 if (!countdown || !mbx->ops.check_for_msg)
50 while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) {
54 usec_delay(mbx->usec_delay);
57 /* if we failed, all future posted messages fail until reset */
61 return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
65 * igbvf_poll_for_ack - Wait for message acknowledgement
66 * @hw: pointer to the HW structure
67 * @mbx_id: id of mailbox to write
69 * returns SUCCESS if it successfully received a message acknowledgement
71 static s32 igbvf_poll_for_ack(struct e1000_hw *hw, u16 mbx_id)
73 struct e1000_mbx_info *mbx = &hw->mbx;
74 int countdown = mbx->timeout;
76 DEBUGFUNC("igbvf_poll_for_ack");
78 if (!countdown || !mbx->ops.check_for_ack)
81 while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) {
85 usec_delay(mbx->usec_delay);
88 /* if we failed, all future posted messages fail until reset */
92 return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
96 * igbvf_read_posted_mbx - Wait for message notification and receive message
97 * @hw: pointer to the HW structure
98 * @msg: The message buffer
99 * @size: Length of buffer
100 * @mbx_id: id of mailbox to write
102 * returns SUCCESS if it successfully received a message notification and
103 * copied it into the receive buffer.
105 static s32 igbvf_read_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size,
108 struct e1000_mbx_info *mbx = &hw->mbx;
109 s32 ret_val = -E1000_ERR_MBX;
111 DEBUGFUNC("igbvf_read_posted_mbx");
116 ret_val = igbvf_poll_for_msg(hw, mbx_id);
118 /* if ack received read message, otherwise we timed out */
120 ret_val = mbx->ops.read(hw, msg, size, mbx_id);
126 * igbvf_write_posted_mbx - Write a message to the mailbox, wait for ack
127 * @hw: pointer to the HW structure
128 * @msg: The message buffer
129 * @size: Length of buffer
130 * @mbx_id: id of mailbox to write
132 * returns SUCCESS if it successfully copied message into the buffer and
133 * received an ack to that message within delay * timeout period
135 static s32 igbvf_write_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size,
138 struct e1000_mbx_info *mbx = &hw->mbx;
139 s32 ret_val = -E1000_ERR_MBX;
141 DEBUGFUNC("igbvf_write_posted_mbx");
143 /* exit if either we can't write or there isn't a defined timeout */
144 if (!mbx->ops.write || !mbx->timeout)
148 ret_val = mbx->ops.write(hw, msg, size, mbx_id);
150 /* if msg sent wait until we receive an ack */
152 ret_val = igbvf_poll_for_ack(hw, mbx_id);
158 * igbvf_init_mbx_ops_generic - Initialize NVM function pointers
159 * @hw: pointer to the HW structure
161 * Setups up the function pointers to no-op functions
163 void igbvf_init_mbx_ops_generic(struct e1000_hw *hw)
165 struct e1000_mbx_info *mbx = &hw->mbx;
166 mbx->ops.read_posted = igbvf_read_posted_mbx;
167 mbx->ops.write_posted = igbvf_write_posted_mbx;
171 * igbvf_read_v2p_mailbox - read v2p mailbox
172 * @hw: pointer to the HW structure
174 * This function is used to read the v2p mailbox without losing the read to
177 static u32 igbvf_read_v2p_mailbox(struct e1000_hw *hw)
179 u32 v2p_mailbox = E1000_READ_REG(hw, E1000_V2PMAILBOX(0));
181 v2p_mailbox |= hw->dev_spec.vf.v2p_mailbox;
182 hw->dev_spec.vf.v2p_mailbox |= v2p_mailbox & E1000_V2PMAILBOX_R2C_BITS;
188 * igbvf_check_for_bit_vf - Determine if a status bit was set
189 * @hw: pointer to the HW structure
190 * @mask: bitmask for bits to be tested and cleared
192 * This function is used to check for the read to clear bits within
195 static s32 igbvf_check_for_bit_vf(struct e1000_hw *hw, u32 mask)
197 u32 v2p_mailbox = igbvf_read_v2p_mailbox(hw);
198 s32 ret_val = -E1000_ERR_MBX;
200 if (v2p_mailbox & mask)
201 ret_val = E1000_SUCCESS;
203 hw->dev_spec.vf.v2p_mailbox &= ~mask;
209 * igbvf_check_for_msg_vf - checks to see if the PF has sent mail
210 * @hw: pointer to the HW structure
211 * @mbx_id: id of mailbox to check
213 * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
215 static s32 igbvf_check_for_msg_vf(struct e1000_hw *hw, u16 mbx_id __unused)
217 s32 ret_val = -E1000_ERR_MBX;
219 DEBUGFUNC("igbvf_check_for_msg_vf");
221 if (!igbvf_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFSTS)) {
222 ret_val = E1000_SUCCESS;
223 hw->mbx.stats.reqs++;
230 * igbvf_check_for_ack_vf - checks to see if the PF has ACK'd
231 * @hw: pointer to the HW structure
232 * @mbx_id: id of mailbox to check
234 * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
236 static s32 igbvf_check_for_ack_vf(struct e1000_hw *hw, u16 mbx_id __unused)
238 s32 ret_val = -E1000_ERR_MBX;
240 DEBUGFUNC("igbvf_check_for_ack_vf");
242 if (!igbvf_check_for_bit_vf(hw, E1000_V2PMAILBOX_PFACK)) {
243 ret_val = E1000_SUCCESS;
244 hw->mbx.stats.acks++;
251 * igbvf_check_for_rst_vf - checks to see if the PF has reset
252 * @hw: pointer to the HW structure
253 * @mbx_id: id of mailbox to check
255 * returns true if the PF has set the reset done bit or else false
257 static s32 igbvf_check_for_rst_vf(struct e1000_hw *hw, u16 mbx_id __unused)
259 s32 ret_val = -E1000_ERR_MBX;
261 DEBUGFUNC("igbvf_check_for_rst_vf");
263 if (!igbvf_check_for_bit_vf(hw, (E1000_V2PMAILBOX_RSTD |
264 E1000_V2PMAILBOX_RSTI))) {
265 ret_val = E1000_SUCCESS;
266 hw->mbx.stats.rsts++;
273 * igbvf_obtain_mbx_lock_vf - obtain mailbox lock
274 * @hw: pointer to the HW structure
276 * return SUCCESS if we obtained the mailbox lock
278 static s32 igbvf_obtain_mbx_lock_vf(struct e1000_hw *hw)
280 s32 ret_val = -E1000_ERR_MBX;
282 DEBUGFUNC("igbvf_obtain_mbx_lock_vf");
284 /* Take ownership of the buffer */
285 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_VFU);
287 /* reserve mailbox for vf use */
288 if (igbvf_read_v2p_mailbox(hw) & E1000_V2PMAILBOX_VFU)
289 ret_val = E1000_SUCCESS;
295 * igbvf_write_mbx_vf - Write a message to the mailbox
296 * @hw: pointer to the HW structure
297 * @msg: The message buffer
298 * @size: Length of buffer
299 * @mbx_id: id of mailbox to write
301 * returns SUCCESS if it successfully copied message into the buffer
303 static s32 igbvf_write_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
310 DEBUGFUNC("igbvf_write_mbx_vf");
312 /* lock the mailbox to prevent pf/vf race condition */
313 ret_val = igbvf_obtain_mbx_lock_vf(hw);
317 /* flush msg and acks as we are overwriting the message buffer */
318 igbvf_check_for_msg_vf(hw, 0);
319 igbvf_check_for_ack_vf(hw, 0);
321 /* copy the caller specified message to the mailbox memory buffer */
322 for (i = 0; i < size; i++)
323 E1000_WRITE_REG_ARRAY(hw, E1000_VMBMEM(0), i, msg[i]);
326 hw->mbx.stats.msgs_tx++;
328 /* Drop VFU and interrupt the PF to tell it a message has been sent */
329 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_REQ);
336 * igbvf_read_mbx_vf - Reads a message from the inbox intended for vf
337 * @hw: pointer to the HW structure
338 * @msg: The message buffer
339 * @size: Length of buffer
340 * @mbx_id: id of mailbox to read
342 * returns SUCCESS if it successfuly read message from buffer
344 static s32 igbvf_read_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size,
347 s32 ret_val = E1000_SUCCESS;
350 DEBUGFUNC("igbvf_read_mbx_vf");
352 /* lock the mailbox to prevent pf/vf race condition */
353 ret_val = igbvf_obtain_mbx_lock_vf(hw);
357 /* copy the message from the mailbox memory buffer */
358 for (i = 0; i < size; i++)
359 msg[i] = E1000_READ_REG_ARRAY(hw, E1000_VMBMEM(0), i);
361 /* Acknowledge receipt and release mailbox, then we're done */
362 E1000_WRITE_REG(hw, E1000_V2PMAILBOX(0), E1000_V2PMAILBOX_ACK);
365 hw->mbx.stats.msgs_rx++;
372 * igbvf_init_mbx_params_vf - set initial values for vf mailbox
373 * @hw: pointer to the HW structure
375 * Initializes the hw->mbx struct to correct values for vf mailbox
377 s32 igbvf_init_mbx_params_vf(struct e1000_hw *hw)
379 struct e1000_mbx_info *mbx = &hw->mbx;
381 /* start mailbox as timed out and let the reset_hw call set the timeout
382 * value to begin communications */
384 mbx->usec_delay = E1000_VF_MBX_INIT_DELAY;
386 mbx->size = E1000_VFMAILBOX_SIZE;
388 mbx->ops.read = igbvf_read_mbx_vf;
389 mbx->ops.write = igbvf_write_mbx_vf;
390 mbx->ops.read_posted = igbvf_read_posted_mbx;
391 mbx->ops.write_posted = igbvf_write_posted_mbx;
392 mbx->ops.check_for_msg = igbvf_check_for_msg_vf;
393 mbx->ops.check_for_ack = igbvf_check_for_ack_vf;
394 mbx->ops.check_for_rst = igbvf_check_for_rst_vf;
396 mbx->stats.msgs_tx = 0;
397 mbx->stats.msgs_rx = 0;
402 return E1000_SUCCESS;