1 /*******************************************************************************
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 2009 - 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, 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 *******************************************************************************/
30 * e1000_poll_for_msg - Wait for message notification
31 * @hw: pointer to the HW structure
33 * returns SUCCESS if it successfully received a message notification
35 static s32
e1000_poll_for_msg(struct e1000_hw
*hw
)
37 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
38 int countdown
= mbx
->timeout
;
40 if (!mbx
->ops
.check_for_msg
)
43 while (countdown
&& mbx
->ops
.check_for_msg(hw
)) {
45 udelay(mbx
->usec_delay
);
48 /* if we failed, all future posted messages fail until reset */
52 return countdown
? E1000_SUCCESS
: -E1000_ERR_MBX
;
56 * e1000_poll_for_ack - Wait for message acknowledgment
57 * @hw: pointer to the HW structure
59 * returns SUCCESS if it successfully received a message acknowledgment
61 static s32
e1000_poll_for_ack(struct e1000_hw
*hw
)
63 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
64 int countdown
= mbx
->timeout
;
66 if (!mbx
->ops
.check_for_ack
)
69 while (countdown
&& mbx
->ops
.check_for_ack(hw
)) {
71 udelay(mbx
->usec_delay
);
74 /* if we failed, all future posted messages fail until reset */
78 return countdown
? E1000_SUCCESS
: -E1000_ERR_MBX
;
82 * e1000_read_posted_mbx - Wait for message notification and receive message
83 * @hw: pointer to the HW structure
84 * @msg: The message buffer
85 * @size: Length of buffer
87 * returns SUCCESS if it successfully received a message notification and
88 * copied it into the receive buffer.
90 static s32
e1000_read_posted_mbx(struct e1000_hw
*hw
, u32
*msg
, u16 size
)
92 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
93 s32 ret_val
= -E1000_ERR_MBX
;
98 ret_val
= e1000_poll_for_msg(hw
);
100 /* if ack received read message, otherwise we timed out */
102 ret_val
= mbx
->ops
.read(hw
, msg
, size
);
108 * e1000_write_posted_mbx - Write a message to the mailbox, wait for ack
109 * @hw: pointer to the HW structure
110 * @msg: The message buffer
111 * @size: Length of buffer
113 * returns SUCCESS if it successfully copied message into the buffer and
114 * received an ack to that message within delay * timeout period
116 static s32
e1000_write_posted_mbx(struct e1000_hw
*hw
, u32
*msg
, u16 size
)
118 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
119 s32 ret_val
= -E1000_ERR_MBX
;
121 /* exit if we either can't write or there isn't a defined timeout */
122 if (!mbx
->ops
.write
|| !mbx
->timeout
)
126 ret_val
= mbx
->ops
.write(hw
, msg
, size
);
128 /* if msg sent wait until we receive an ack */
130 ret_val
= e1000_poll_for_ack(hw
);
136 * e1000_read_v2p_mailbox - read v2p mailbox
137 * @hw: pointer to the HW structure
139 * This function is used to read the v2p mailbox without losing the read to
142 static u32
e1000_read_v2p_mailbox(struct e1000_hw
*hw
)
144 u32 v2p_mailbox
= er32(V2PMAILBOX(0));
146 v2p_mailbox
|= hw
->dev_spec
.vf
.v2p_mailbox
;
147 hw
->dev_spec
.vf
.v2p_mailbox
|= v2p_mailbox
& E1000_V2PMAILBOX_R2C_BITS
;
153 * e1000_check_for_bit_vf - Determine if a status bit was set
154 * @hw: pointer to the HW structure
155 * @mask: bitmask for bits to be tested and cleared
157 * This function is used to check for the read to clear bits within
160 static s32
e1000_check_for_bit_vf(struct e1000_hw
*hw
, u32 mask
)
162 u32 v2p_mailbox
= e1000_read_v2p_mailbox(hw
);
163 s32 ret_val
= -E1000_ERR_MBX
;
165 if (v2p_mailbox
& mask
)
166 ret_val
= E1000_SUCCESS
;
168 hw
->dev_spec
.vf
.v2p_mailbox
&= ~mask
;
174 * e1000_check_for_msg_vf - checks to see if the PF has sent mail
175 * @hw: pointer to the HW structure
177 * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
179 static s32
e1000_check_for_msg_vf(struct e1000_hw
*hw
)
181 s32 ret_val
= -E1000_ERR_MBX
;
183 if (!e1000_check_for_bit_vf(hw
, E1000_V2PMAILBOX_PFSTS
)) {
184 ret_val
= E1000_SUCCESS
;
185 hw
->mbx
.stats
.reqs
++;
192 * e1000_check_for_ack_vf - checks to see if the PF has ACK'd
193 * @hw: pointer to the HW structure
195 * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
197 static s32
e1000_check_for_ack_vf(struct e1000_hw
*hw
)
199 s32 ret_val
= -E1000_ERR_MBX
;
201 if (!e1000_check_for_bit_vf(hw
, E1000_V2PMAILBOX_PFACK
)) {
202 ret_val
= E1000_SUCCESS
;
203 hw
->mbx
.stats
.acks
++;
210 * e1000_check_for_rst_vf - checks to see if the PF has reset
211 * @hw: pointer to the HW structure
213 * returns true if the PF has set the reset done bit or else false
215 static s32
e1000_check_for_rst_vf(struct e1000_hw
*hw
)
217 s32 ret_val
= -E1000_ERR_MBX
;
219 if (!e1000_check_for_bit_vf(hw
, (E1000_V2PMAILBOX_RSTD
|
220 E1000_V2PMAILBOX_RSTI
))) {
221 ret_val
= E1000_SUCCESS
;
222 hw
->mbx
.stats
.rsts
++;
229 * e1000_obtain_mbx_lock_vf - obtain mailbox lock
230 * @hw: pointer to the HW structure
232 * return SUCCESS if we obtained the mailbox lock
234 static s32
e1000_obtain_mbx_lock_vf(struct e1000_hw
*hw
)
236 s32 ret_val
= -E1000_ERR_MBX
;
238 /* Take ownership of the buffer */
239 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_VFU
);
241 /* reserve mailbox for VF use */
242 if (e1000_read_v2p_mailbox(hw
) & E1000_V2PMAILBOX_VFU
)
243 ret_val
= E1000_SUCCESS
;
249 * e1000_write_mbx_vf - Write a message to the mailbox
250 * @hw: pointer to the HW structure
251 * @msg: The message buffer
252 * @size: Length of buffer
254 * returns SUCCESS if it successfully copied message into the buffer
256 static s32
e1000_write_mbx_vf(struct e1000_hw
*hw
, u32
*msg
, u16 size
)
261 /* lock the mailbox to prevent pf/vf race condition */
262 err
= e1000_obtain_mbx_lock_vf(hw
);
266 /* flush any ack or msg as we are going to overwrite mailbox */
267 e1000_check_for_ack_vf(hw
);
268 e1000_check_for_msg_vf(hw
);
270 /* copy the caller specified message to the mailbox memory buffer */
271 for (i
= 0; i
< size
; i
++)
272 array_ew32(VMBMEM(0), i
, msg
[i
]);
275 hw
->mbx
.stats
.msgs_tx
++;
277 /* Drop VFU and interrupt the PF to tell it a message has been sent */
278 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_REQ
);
285 * e1000_read_mbx_vf - Reads a message from the inbox intended for VF
286 * @hw: pointer to the HW structure
287 * @msg: The message buffer
288 * @size: Length of buffer
290 * returns SUCCESS if it successfully read message from buffer
292 static s32
e1000_read_mbx_vf(struct e1000_hw
*hw
, u32
*msg
, u16 size
)
297 /* lock the mailbox to prevent pf/vf race condition */
298 err
= e1000_obtain_mbx_lock_vf(hw
);
302 /* copy the message from the mailbox memory buffer */
303 for (i
= 0; i
< size
; i
++)
304 msg
[i
] = array_er32(VMBMEM(0), i
);
306 /* Acknowledge receipt and release mailbox, then we're done */
307 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_ACK
);
310 hw
->mbx
.stats
.msgs_rx
++;
317 * e1000_init_mbx_params_vf - set initial values for VF mailbox
318 * @hw: pointer to the HW structure
320 * Initializes the hw->mbx struct to correct values for VF mailbox
322 s32
e1000_init_mbx_params_vf(struct e1000_hw
*hw
)
324 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
326 /* start mailbox as timed out and let the reset_hw call set the timeout
327 * value to being communications
330 mbx
->usec_delay
= E1000_VF_MBX_INIT_DELAY
;
332 mbx
->size
= E1000_VFMAILBOX_SIZE
;
334 mbx
->ops
.read
= e1000_read_mbx_vf
;
335 mbx
->ops
.write
= e1000_write_mbx_vf
;
336 mbx
->ops
.read_posted
= e1000_read_posted_mbx
;
337 mbx
->ops
.write_posted
= e1000_write_posted_mbx
;
338 mbx
->ops
.check_for_msg
= e1000_check_for_msg_vf
;
339 mbx
->ops
.check_for_ack
= e1000_check_for_ack_vf
;
340 mbx
->ops
.check_for_rst
= e1000_check_for_rst_vf
;
342 mbx
->stats
.msgs_tx
= 0;
343 mbx
->stats
.msgs_rx
= 0;
348 return E1000_SUCCESS
;