1 /*******************************************************************************
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 2009 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 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
31 * e1000_poll_for_msg - Wait for message notification
32 * @hw: pointer to the HW structure
34 * returns SUCCESS if it successfully received a message notification
36 static s32
e1000_poll_for_msg(struct e1000_hw
*hw
)
38 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
39 int countdown
= mbx
->timeout
;
41 if (!mbx
->ops
.check_for_msg
)
44 while (countdown
&& mbx
->ops
.check_for_msg(hw
)) {
46 udelay(mbx
->usec_delay
);
49 /* if we failed, all future posted messages fail until reset */
53 return countdown
? E1000_SUCCESS
: -E1000_ERR_MBX
;
57 * e1000_poll_for_ack - Wait for message acknowledgement
58 * @hw: pointer to the HW structure
60 * returns SUCCESS if it successfully received a message acknowledgement
62 static s32
e1000_poll_for_ack(struct e1000_hw
*hw
)
64 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
65 int countdown
= mbx
->timeout
;
67 if (!mbx
->ops
.check_for_ack
)
70 while (countdown
&& mbx
->ops
.check_for_ack(hw
)) {
72 udelay(mbx
->usec_delay
);
75 /* if we failed, all future posted messages fail until reset */
79 return countdown
? E1000_SUCCESS
: -E1000_ERR_MBX
;
83 * e1000_read_posted_mbx - Wait for message notification and receive message
84 * @hw: pointer to the HW structure
85 * @msg: The message buffer
86 * @size: Length of buffer
88 * returns SUCCESS if it successfully received a message notification and
89 * copied it into the receive buffer.
91 static s32
e1000_read_posted_mbx(struct e1000_hw
*hw
, u32
*msg
, u16 size
)
93 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
94 s32 ret_val
= -E1000_ERR_MBX
;
99 ret_val
= e1000_poll_for_msg(hw
);
101 /* if ack received read message, otherwise we timed out */
103 ret_val
= mbx
->ops
.read(hw
, msg
, size
);
109 * e1000_write_posted_mbx - Write a message to the mailbox, wait for ack
110 * @hw: pointer to the HW structure
111 * @msg: The message buffer
112 * @size: Length of buffer
114 * returns SUCCESS if it successfully copied message into the buffer and
115 * received an ack to that message within delay * timeout period
117 static s32
e1000_write_posted_mbx(struct e1000_hw
*hw
, u32
*msg
, u16 size
)
119 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
120 s32 ret_val
= -E1000_ERR_MBX
;
122 /* exit if we either can't write or there isn't a defined timeout */
123 if (!mbx
->ops
.write
|| !mbx
->timeout
)
127 ret_val
= mbx
->ops
.write(hw
, msg
, size
);
129 /* if msg sent wait until we receive an ack */
131 ret_val
= e1000_poll_for_ack(hw
);
137 * e1000_read_v2p_mailbox - read v2p mailbox
138 * @hw: pointer to the HW structure
140 * This function is used to read the v2p mailbox without losing the read to
143 static u32
e1000_read_v2p_mailbox(struct e1000_hw
*hw
)
145 u32 v2p_mailbox
= er32(V2PMAILBOX(0));
147 v2p_mailbox
|= hw
->dev_spec
.vf
.v2p_mailbox
;
148 hw
->dev_spec
.vf
.v2p_mailbox
|= v2p_mailbox
& E1000_V2PMAILBOX_R2C_BITS
;
154 * e1000_check_for_bit_vf - Determine if a status bit was set
155 * @hw: pointer to the HW structure
156 * @mask: bitmask for bits to be tested and cleared
158 * This function is used to check for the read to clear bits within
161 static s32
e1000_check_for_bit_vf(struct e1000_hw
*hw
, u32 mask
)
163 u32 v2p_mailbox
= e1000_read_v2p_mailbox(hw
);
164 s32 ret_val
= -E1000_ERR_MBX
;
166 if (v2p_mailbox
& mask
)
167 ret_val
= E1000_SUCCESS
;
169 hw
->dev_spec
.vf
.v2p_mailbox
&= ~mask
;
175 * e1000_check_for_msg_vf - checks to see if the PF has sent mail
176 * @hw: pointer to the HW structure
178 * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
180 static s32
e1000_check_for_msg_vf(struct e1000_hw
*hw
)
182 s32 ret_val
= -E1000_ERR_MBX
;
184 if (!e1000_check_for_bit_vf(hw
, E1000_V2PMAILBOX_PFSTS
)) {
185 ret_val
= E1000_SUCCESS
;
186 hw
->mbx
.stats
.reqs
++;
193 * e1000_check_for_ack_vf - checks to see if the PF has ACK'd
194 * @hw: pointer to the HW structure
196 * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
198 static s32
e1000_check_for_ack_vf(struct e1000_hw
*hw
)
200 s32 ret_val
= -E1000_ERR_MBX
;
202 if (!e1000_check_for_bit_vf(hw
, E1000_V2PMAILBOX_PFACK
)) {
203 ret_val
= E1000_SUCCESS
;
204 hw
->mbx
.stats
.acks
++;
211 * e1000_check_for_rst_vf - checks to see if the PF has reset
212 * @hw: pointer to the HW structure
214 * returns true if the PF has set the reset done bit or else false
216 static s32
e1000_check_for_rst_vf(struct e1000_hw
*hw
)
218 s32 ret_val
= -E1000_ERR_MBX
;
220 if (!e1000_check_for_bit_vf(hw
, (E1000_V2PMAILBOX_RSTD
|
221 E1000_V2PMAILBOX_RSTI
))) {
222 ret_val
= E1000_SUCCESS
;
223 hw
->mbx
.stats
.rsts
++;
230 * e1000_obtain_mbx_lock_vf - obtain mailbox lock
231 * @hw: pointer to the HW structure
233 * return SUCCESS if we obtained the mailbox lock
235 static s32
e1000_obtain_mbx_lock_vf(struct e1000_hw
*hw
)
237 s32 ret_val
= -E1000_ERR_MBX
;
239 /* Take ownership of the buffer */
240 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_VFU
);
242 /* reserve mailbox for vf use */
243 if (e1000_read_v2p_mailbox(hw
) & E1000_V2PMAILBOX_VFU
)
244 ret_val
= E1000_SUCCESS
;
250 * e1000_write_mbx_vf - Write a message to the mailbox
251 * @hw: pointer to the HW structure
252 * @msg: The message buffer
253 * @size: Length of buffer
255 * returns SUCCESS if it successfully copied message into the buffer
257 static s32
e1000_write_mbx_vf(struct e1000_hw
*hw
, u32
*msg
, u16 size
)
262 /* lock the mailbox to prevent pf/vf race condition */
263 err
= e1000_obtain_mbx_lock_vf(hw
);
267 /* flush any ack or msg as we are going to overwrite mailbox */
268 e1000_check_for_ack_vf(hw
);
269 e1000_check_for_msg_vf(hw
);
271 /* copy the caller specified message to the mailbox memory buffer */
272 for (i
= 0; i
< size
; i
++)
273 array_ew32(VMBMEM(0), i
, msg
[i
]);
276 hw
->mbx
.stats
.msgs_tx
++;
278 /* Drop VFU and interrupt the PF to tell it a message has been sent */
279 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_REQ
);
286 * e1000_read_mbx_vf - Reads a message from the inbox intended for vf
287 * @hw: pointer to the HW structure
288 * @msg: The message buffer
289 * @size: Length of buffer
291 * returns SUCCESS if it successfuly read message from buffer
293 static s32
e1000_read_mbx_vf(struct e1000_hw
*hw
, u32
*msg
, u16 size
)
298 /* lock the mailbox to prevent pf/vf race condition */
299 err
= e1000_obtain_mbx_lock_vf(hw
);
303 /* copy the message from the mailbox memory buffer */
304 for (i
= 0; i
< size
; i
++)
305 msg
[i
] = array_er32(VMBMEM(0), i
);
307 /* Acknowledge receipt and release mailbox, then we're done */
308 ew32(V2PMAILBOX(0), E1000_V2PMAILBOX_ACK
);
311 hw
->mbx
.stats
.msgs_rx
++;
318 * e1000_init_mbx_params_vf - set initial values for vf mailbox
319 * @hw: pointer to the HW structure
321 * Initializes the hw->mbx struct to correct values for vf mailbox
323 s32
e1000_init_mbx_params_vf(struct e1000_hw
*hw
)
325 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
327 /* start mailbox as timed out and let the reset_hw call set the timeout
328 * 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
;