1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-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 *******************************************************************************/
28 #include "e1000_mbx.h"
31 * igb_read_mbx - Reads a message from the mailbox
32 * @hw: pointer to the HW structure
33 * @msg: The message buffer
34 * @size: Length of buffer
35 * @mbx_id: id of mailbox to read
37 * returns SUCCESS if it successfuly read message from buffer
39 s32
igb_read_mbx(struct e1000_hw
*hw
, u32
*msg
, u16 size
, u16 mbx_id
)
41 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
42 s32 ret_val
= -E1000_ERR_MBX
;
44 /* limit read to size of mailbox */
49 ret_val
= mbx
->ops
.read(hw
, msg
, size
, mbx_id
);
55 * igb_write_mbx - Write a message to the mailbox
56 * @hw: pointer to the HW structure
57 * @msg: The message buffer
58 * @size: Length of buffer
59 * @mbx_id: id of mailbox to write
61 * returns SUCCESS if it successfully copied message into the buffer
63 s32
igb_write_mbx(struct e1000_hw
*hw
, u32
*msg
, u16 size
, u16 mbx_id
)
65 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
69 ret_val
= -E1000_ERR_MBX
;
71 else if (mbx
->ops
.write
)
72 ret_val
= mbx
->ops
.write(hw
, msg
, size
, mbx_id
);
78 * igb_check_for_msg - checks to see if someone sent us mail
79 * @hw: pointer to the HW structure
80 * @mbx_id: id of mailbox to check
82 * returns SUCCESS if the Status bit was found or else ERR_MBX
84 s32
igb_check_for_msg(struct e1000_hw
*hw
, u16 mbx_id
)
86 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
87 s32 ret_val
= -E1000_ERR_MBX
;
89 if (mbx
->ops
.check_for_msg
)
90 ret_val
= mbx
->ops
.check_for_msg(hw
, mbx_id
);
96 * igb_check_for_ack - checks to see if someone sent us ACK
97 * @hw: pointer to the HW structure
98 * @mbx_id: id of mailbox to check
100 * returns SUCCESS if the Status bit was found or else ERR_MBX
102 s32
igb_check_for_ack(struct e1000_hw
*hw
, u16 mbx_id
)
104 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
105 s32 ret_val
= -E1000_ERR_MBX
;
107 if (mbx
->ops
.check_for_ack
)
108 ret_val
= mbx
->ops
.check_for_ack(hw
, mbx_id
);
114 * igb_check_for_rst - checks to see if other side has reset
115 * @hw: pointer to the HW structure
116 * @mbx_id: id of mailbox to check
118 * returns SUCCESS if the Status bit was found or else ERR_MBX
120 s32
igb_check_for_rst(struct e1000_hw
*hw
, u16 mbx_id
)
122 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
123 s32 ret_val
= -E1000_ERR_MBX
;
125 if (mbx
->ops
.check_for_rst
)
126 ret_val
= mbx
->ops
.check_for_rst(hw
, mbx_id
);
132 * igb_poll_for_msg - Wait for message notification
133 * @hw: pointer to the HW structure
134 * @mbx_id: id of mailbox to write
136 * returns SUCCESS if it successfully received a message notification
138 static s32
igb_poll_for_msg(struct e1000_hw
*hw
, u16 mbx_id
)
140 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
141 int countdown
= mbx
->timeout
;
143 if (!countdown
|| !mbx
->ops
.check_for_msg
)
146 while (mbx
->ops
.check_for_msg(hw
, mbx_id
)) {
150 udelay(mbx
->usec_delay
);
153 return countdown
? 0 : -E1000_ERR_MBX
;
157 * igb_poll_for_ack - Wait for message acknowledgement
158 * @hw: pointer to the HW structure
159 * @mbx_id: id of mailbox to write
161 * returns SUCCESS if it successfully received a message acknowledgement
163 static s32
igb_poll_for_ack(struct e1000_hw
*hw
, u16 mbx_id
)
165 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
166 int countdown
= mbx
->timeout
;
168 if (!countdown
|| !mbx
->ops
.check_for_ack
)
171 while (mbx
->ops
.check_for_ack(hw
, mbx_id
)) {
175 udelay(mbx
->usec_delay
);
178 return countdown
? 0 : -E1000_ERR_MBX
;
182 * igb_read_posted_mbx - Wait for message notification and receive message
183 * @hw: pointer to the HW structure
184 * @msg: The message buffer
185 * @size: Length of buffer
186 * @mbx_id: id of mailbox to write
188 * returns SUCCESS if it successfully received a message notification and
189 * copied it into the receive buffer.
191 static s32
igb_read_posted_mbx(struct e1000_hw
*hw
, u32
*msg
, u16 size
, u16 mbx_id
)
193 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
194 s32 ret_val
= -E1000_ERR_MBX
;
199 ret_val
= igb_poll_for_msg(hw
, mbx_id
);
202 ret_val
= mbx
->ops
.read(hw
, msg
, size
, mbx_id
);
208 * igb_write_posted_mbx - Write a message to the mailbox, wait for ack
209 * @hw: pointer to the HW structure
210 * @msg: The message buffer
211 * @size: Length of buffer
212 * @mbx_id: id of mailbox to write
214 * returns SUCCESS if it successfully copied message into the buffer and
215 * received an ack to that message within delay * timeout period
217 static s32
igb_write_posted_mbx(struct e1000_hw
*hw
, u32
*msg
, u16 size
, u16 mbx_id
)
219 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
226 ret_val
= mbx
->ops
.write(hw
, msg
, size
, mbx_id
);
228 /* if msg sent wait until we receive an ack */
230 ret_val
= igb_poll_for_ack(hw
, mbx_id
);
235 static s32
igb_check_for_bit_pf(struct e1000_hw
*hw
, u32 mask
)
237 u32 mbvficr
= rd32(E1000_MBVFICR
);
238 s32 ret_val
= -E1000_ERR_MBX
;
240 if (mbvficr
& mask
) {
242 wr32(E1000_MBVFICR
, mask
);
249 * igb_check_for_msg_pf - checks to see if the VF has sent mail
250 * @hw: pointer to the HW structure
251 * @vf_number: the VF index
253 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
255 static s32
igb_check_for_msg_pf(struct e1000_hw
*hw
, u16 vf_number
)
257 s32 ret_val
= -E1000_ERR_MBX
;
259 if (!igb_check_for_bit_pf(hw
, E1000_MBVFICR_VFREQ_VF1
<< vf_number
)) {
261 hw
->mbx
.stats
.reqs
++;
268 * igb_check_for_ack_pf - checks to see if the VF has ACKed
269 * @hw: pointer to the HW structure
270 * @vf_number: the VF index
272 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
274 static s32
igb_check_for_ack_pf(struct e1000_hw
*hw
, u16 vf_number
)
276 s32 ret_val
= -E1000_ERR_MBX
;
278 if (!igb_check_for_bit_pf(hw
, E1000_MBVFICR_VFACK_VF1
<< vf_number
)) {
280 hw
->mbx
.stats
.acks
++;
287 * igb_check_for_rst_pf - checks to see if the VF has reset
288 * @hw: pointer to the HW structure
289 * @vf_number: the VF index
291 * returns SUCCESS if the VF has set the Status bit or else ERR_MBX
293 static s32
igb_check_for_rst_pf(struct e1000_hw
*hw
, u16 vf_number
)
295 u32 vflre
= rd32(E1000_VFLRE
);
296 s32 ret_val
= -E1000_ERR_MBX
;
298 if (vflre
& (1 << vf_number
)) {
300 wr32(E1000_VFLRE
, (1 << vf_number
));
301 hw
->mbx
.stats
.rsts
++;
308 * igb_write_mbx_pf - Places a message in the mailbox
309 * @hw: pointer to the HW structure
310 * @msg: The message buffer
311 * @size: Length of buffer
312 * @vf_number: the VF index
314 * returns SUCCESS if it successfully copied message into the buffer
316 static s32
igb_write_mbx_pf(struct e1000_hw
*hw
, u32
*msg
, u16 size
,
323 /* Take ownership of the buffer */
324 wr32(E1000_P2VMAILBOX(vf_number
), E1000_P2VMAILBOX_PFU
);
326 /* Make sure we have ownership now... */
327 p2v_mailbox
= rd32(E1000_P2VMAILBOX(vf_number
));
328 if (!(p2v_mailbox
& E1000_P2VMAILBOX_PFU
)) {
329 /* failed to grab ownership */
330 ret_val
= -E1000_ERR_MBX
;
335 * flush any ack or msg which may already be in the queue
336 * as they are likely the result of an error
338 igb_check_for_ack_pf(hw
, vf_number
);
339 igb_check_for_msg_pf(hw
, vf_number
);
341 /* copy the caller specified message to the mailbox memory buffer */
342 for (i
= 0; i
< size
; i
++)
343 array_wr32(E1000_VMBMEM(vf_number
), i
, msg
[i
]);
345 /* Interrupt VF to tell it a message has been sent and release buffer*/
346 wr32(E1000_P2VMAILBOX(vf_number
), E1000_P2VMAILBOX_STS
);
349 hw
->mbx
.stats
.msgs_tx
++;
357 * igb_read_mbx_pf - Read a message from the mailbox
358 * @hw: pointer to the HW structure
359 * @msg: The message buffer
360 * @size: Length of buffer
361 * @vf_number: the VF index
363 * This function copies a message from the mailbox buffer to the caller's
364 * memory buffer. The presumption is that the caller knows that there was
365 * a message due to a VF request so no polling for message is needed.
367 static s32
igb_read_mbx_pf(struct e1000_hw
*hw
, u32
*msg
, u16 size
,
374 /* Take ownership of the buffer */
375 wr32(E1000_P2VMAILBOX(vf_number
), E1000_P2VMAILBOX_PFU
);
377 /* Make sure we have ownership now... */
378 p2v_mailbox
= rd32(E1000_P2VMAILBOX(vf_number
));
379 if (!(p2v_mailbox
& E1000_P2VMAILBOX_PFU
)) {
380 /* failed to grab ownership */
381 ret_val
= -E1000_ERR_MBX
;
385 /* copy the message to the mailbox memory buffer */
386 for (i
= 0; i
< size
; i
++)
387 msg
[i
] = array_rd32(E1000_VMBMEM(vf_number
), i
);
389 /* Acknowledge the message and release buffer */
390 wr32(E1000_P2VMAILBOX(vf_number
), E1000_P2VMAILBOX_ACK
);
393 hw
->mbx
.stats
.msgs_rx
++;
402 * e1000_init_mbx_params_pf - set initial values for pf mailbox
403 * @hw: pointer to the HW structure
405 * Initializes the hw->mbx struct to correct values for pf mailbox
407 s32
igb_init_mbx_params_pf(struct e1000_hw
*hw
)
409 struct e1000_mbx_info
*mbx
= &hw
->mbx
;
411 if (hw
->mac
.type
== e1000_82576
) {
415 mbx
->size
= E1000_VFMAILBOX_SIZE
;
417 mbx
->ops
.read
= igb_read_mbx_pf
;
418 mbx
->ops
.write
= igb_write_mbx_pf
;
419 mbx
->ops
.read_posted
= igb_read_posted_mbx
;
420 mbx
->ops
.write_posted
= igb_write_posted_mbx
;
421 mbx
->ops
.check_for_msg
= igb_check_for_msg_pf
;
422 mbx
->ops
.check_for_ack
= igb_check_for_ack_pf
;
423 mbx
->ops
.check_for_rst
= igb_check_for_rst_pf
;
425 mbx
->stats
.msgs_tx
= 0;
426 mbx
->stats
.msgs_rx
= 0;