iPXE
igbvf_mbx.c
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  Intel(R) 82576 Virtual Function Linux driver
4  Copyright(c) 1999 - 2008 Intel Corporation.
5 
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.
9 
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.
14 
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.
18 
19  The full GNU General Public License is included in this distribution in
20  the file called "COPYING".
21 
22  Contact Information:
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
26 
27 *******************************************************************************/
28 
29 FILE_LICENCE ( GPL2_ONLY );
30 
31 #include "igbvf_mbx.h"
32 
33 /**
34  * igbvf_poll_for_msg - Wait for message notification
35  * @hw: pointer to the HW structure
36  * @mbx_id: id of mailbox to write
37  *
38  * returns SUCCESS if it successfully received a message notification
39  **/
40 static s32 igbvf_poll_for_msg(struct e1000_hw *hw, u16 mbx_id)
41 {
42  struct e1000_mbx_info *mbx = &hw->mbx;
43  int countdown = mbx->timeout;
44 
45  DEBUGFUNC("igbvf_poll_for_msg");
46 
47  if (!countdown || !mbx->ops.check_for_msg)
48  goto out;
49 
50  while (countdown && mbx->ops.check_for_msg(hw, mbx_id)) {
51  countdown--;
52  if (!countdown)
53  break;
54  usec_delay(mbx->usec_delay);
55  }
56 
57  /* if we failed, all future posted messages fail until reset */
58  if (!countdown)
59  mbx->timeout = 0;
60 out:
61  return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
62 }
63 
64 /**
65  * igbvf_poll_for_ack - Wait for message acknowledgement
66  * @hw: pointer to the HW structure
67  * @mbx_id: id of mailbox to write
68  *
69  * returns SUCCESS if it successfully received a message acknowledgement
70  **/
71 static s32 igbvf_poll_for_ack(struct e1000_hw *hw, u16 mbx_id)
72 {
73  struct e1000_mbx_info *mbx = &hw->mbx;
74  int countdown = mbx->timeout;
75 
76  DEBUGFUNC("igbvf_poll_for_ack");
77 
78  if (!countdown || !mbx->ops.check_for_ack)
79  goto out;
80 
81  while (countdown && mbx->ops.check_for_ack(hw, mbx_id)) {
82  countdown--;
83  if (!countdown)
84  break;
85  usec_delay(mbx->usec_delay);
86  }
87 
88  /* if we failed, all future posted messages fail until reset */
89  if (!countdown)
90  mbx->timeout = 0;
91 out:
92  return countdown ? E1000_SUCCESS : -E1000_ERR_MBX;
93 }
94 
95 /**
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
101  *
102  * returns SUCCESS if it successfully received a message notification and
103  * copied it into the receive buffer.
104  **/
106  u16 mbx_id)
107 {
108  struct e1000_mbx_info *mbx = &hw->mbx;
109  s32 ret_val = -E1000_ERR_MBX;
110 
111  DEBUGFUNC("igbvf_read_posted_mbx");
112 
113  if (!mbx->ops.read)
114  goto out;
115 
116  ret_val = igbvf_poll_for_msg(hw, mbx_id);
117 
118  /* if ack received read message, otherwise we timed out */
119  if (!ret_val)
120  ret_val = mbx->ops.read(hw, msg, size, mbx_id);
121 out:
122  return ret_val;
123 }
124 
125 /**
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
131  *
132  * returns SUCCESS if it successfully copied message into the buffer and
133  * received an ack to that message within delay * timeout period
134  **/
136  u16 mbx_id)
137 {
138  struct e1000_mbx_info *mbx = &hw->mbx;
139  s32 ret_val = -E1000_ERR_MBX;
140 
141  DEBUGFUNC("igbvf_write_posted_mbx");
142 
143  /* exit if either we can't write or there isn't a defined timeout */
144  if (!mbx->ops.write || !mbx->timeout)
145  goto out;
146 
147  /* send msg */
148  ret_val = mbx->ops.write(hw, msg, size, mbx_id);
149 
150  /* if msg sent wait until we receive an ack */
151  if (!ret_val)
152  ret_val = igbvf_poll_for_ack(hw, mbx_id);
153 out:
154  return ret_val;
155 }
156 
157 /**
158  * igbvf_init_mbx_ops_generic - Initialize NVM function pointers
159  * @hw: pointer to the HW structure
160  *
161  * Setups up the function pointers to no-op functions
162  **/
164 {
165  struct e1000_mbx_info *mbx = &hw->mbx;
168 }
169 
170 /**
171  * igbvf_read_v2p_mailbox - read v2p mailbox
172  * @hw: pointer to the HW structure
173  *
174  * This function is used to read the v2p mailbox without losing the read to
175  * clear status bits.
176  **/
178 {
179  u32 v2p_mailbox = E1000_READ_REG(hw, E1000_V2PMAILBOX(0));
180 
181  v2p_mailbox |= hw->dev_spec.vf.v2p_mailbox;
182  hw->dev_spec.vf.v2p_mailbox |= v2p_mailbox & E1000_V2PMAILBOX_R2C_BITS;
183 
184  return v2p_mailbox;
185 }
186 
187 /**
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
191  *
192  * This function is used to check for the read to clear bits within
193  * the V2P mailbox.
194  **/
195 static s32 igbvf_check_for_bit_vf(struct e1000_hw *hw, u32 mask)
196 {
197  u32 v2p_mailbox = igbvf_read_v2p_mailbox(hw);
198  s32 ret_val = -E1000_ERR_MBX;
199 
200  if (v2p_mailbox & mask)
201  ret_val = E1000_SUCCESS;
202 
203  hw->dev_spec.vf.v2p_mailbox &= ~mask;
204 
205  return ret_val;
206 }
207 
208 /**
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
212  *
213  * returns SUCCESS if the PF has set the Status bit or else ERR_MBX
214  **/
216 {
217  s32 ret_val = -E1000_ERR_MBX;
218 
219  DEBUGFUNC("igbvf_check_for_msg_vf");
220 
222  ret_val = E1000_SUCCESS;
223  hw->mbx.stats.reqs++;
224  }
225 
226  return ret_val;
227 }
228 
229 /**
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
233  *
234  * returns SUCCESS if the PF has set the ACK bit or else ERR_MBX
235  **/
237 {
238  s32 ret_val = -E1000_ERR_MBX;
239 
240  DEBUGFUNC("igbvf_check_for_ack_vf");
241 
243  ret_val = E1000_SUCCESS;
244  hw->mbx.stats.acks++;
245  }
246 
247  return ret_val;
248 }
249 
250 /**
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
254  *
255  * returns true if the PF has set the reset done bit or else false
256  **/
258 {
259  s32 ret_val = -E1000_ERR_MBX;
260 
261  DEBUGFUNC("igbvf_check_for_rst_vf");
262 
265  ret_val = E1000_SUCCESS;
266  hw->mbx.stats.rsts++;
267  }
268 
269  return ret_val;
270 }
271 
272 /**
273  * igbvf_obtain_mbx_lock_vf - obtain mailbox lock
274  * @hw: pointer to the HW structure
275  *
276  * return SUCCESS if we obtained the mailbox lock
277  **/
279 {
280  s32 ret_val = -E1000_ERR_MBX;
281 
282  DEBUGFUNC("igbvf_obtain_mbx_lock_vf");
283 
284  /* Take ownership of the buffer */
286 
287  /* reserve mailbox for vf use */
289  ret_val = E1000_SUCCESS;
290 
291  return ret_val;
292 }
293 
294 /**
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
300  *
301  * returns SUCCESS if it successfully copied message into the buffer
302  **/
304  u16 mbx_id __unused)
305 {
306  s32 ret_val;
307  u16 i;
308 
309 
310  DEBUGFUNC("igbvf_write_mbx_vf");
311 
312  /* lock the mailbox to prevent pf/vf race condition */
313  ret_val = igbvf_obtain_mbx_lock_vf(hw);
314  if (ret_val)
315  goto out_no_write;
316 
317  /* flush msg and acks as we are overwriting the message buffer */
320 
321  /* copy the caller specified message to the mailbox memory buffer */
322  for (i = 0; i < size; i++)
324 
325  /* update stats */
326  hw->mbx.stats.msgs_tx++;
327 
328  /* Drop VFU and interrupt the PF to tell it a message has been sent */
330 
331 out_no_write:
332  return ret_val;
333 }
334 
335 /**
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
341  *
342  * returns SUCCESS if it successfuly read message from buffer
343  **/
345  u16 mbx_id __unused)
346 {
347  s32 ret_val = E1000_SUCCESS;
348  u16 i;
349 
350  DEBUGFUNC("igbvf_read_mbx_vf");
351 
352  /* lock the mailbox to prevent pf/vf race condition */
353  ret_val = igbvf_obtain_mbx_lock_vf(hw);
354  if (ret_val)
355  goto out_no_read;
356 
357  /* copy the message from the mailbox memory buffer */
358  for (i = 0; i < size; i++)
360 
361  /* Acknowledge receipt and release mailbox, then we're done */
363 
364  /* update stats */
365  hw->mbx.stats.msgs_rx++;
366 
367 out_no_read:
368  return ret_val;
369 }
370 
371 /**
372  * igbvf_init_mbx_params_vf - set initial values for vf mailbox
373  * @hw: pointer to the HW structure
374  *
375  * Initializes the hw->mbx struct to correct values for vf mailbox
376  */
378 {
379  struct e1000_mbx_info *mbx = &hw->mbx;
380 
381  /* start mailbox as timed out and let the reset_hw call set the timeout
382  * value to begin communications */
383  mbx->timeout = 0;
385 
386  mbx->size = E1000_VFMAILBOX_SIZE;
387 
388  mbx->ops.read = igbvf_read_mbx_vf;
395 
396  mbx->stats.msgs_tx = 0;
397  mbx->stats.msgs_rx = 0;
398  mbx->stats.reqs = 0;
399  mbx->stats.acks = 0;
400  mbx->stats.rsts = 0;
401 
402  return E1000_SUCCESS;
403 }
404 
#define E1000_READ_REG_ARRAY(a, reg, offset)
Definition: igbvf_osdep.h:84
uint16_t u16
Definition: stdint.h:21
s32(* read_posted)(struct e1000_hw *, u32 *, u16, u16)
Definition: igbvf_vf.h:281
#define E1000_V2PMAILBOX_RSTD
Definition: igbvf_mbx.h:48
static s32 igbvf_poll_for_ack(struct e1000_hw *hw, u16 mbx_id)
igbvf_poll_for_ack - Wait for message acknowledgement @hw: pointer to the HW structure @mbx_id: id of...
Definition: igbvf_mbx.c:71
static s32 igbvf_poll_for_msg(struct e1000_hw *hw, u16 mbx_id)
igbvf_poll_for_msg - Wait for message notification @hw: pointer to the HW structure @mbx_id: id of ma...
Definition: igbvf_mbx.c:40
int32_t s32
Definition: stdint.h:22
static u32 igbvf_read_v2p_mailbox(struct e1000_hw *hw)
igbvf_read_v2p_mailbox - read v2p mailbox @hw: pointer to the HW structure
Definition: igbvf_mbx.c:177
static s32 igbvf_check_for_bit_vf(struct e1000_hw *hw, u32 mask)
igbvf_check_for_bit_vf - Determine if a status bit was set @hw: pointer to the HW structure @mask: bi...
Definition: igbvf_mbx.c:195
#define E1000_V2PMAILBOX_R2C_BITS
Definition: igbvf_mbx.h:49
Definition: hw.c:16
#define E1000_V2PMAILBOX_PFACK
Definition: igbvf_mbx.h:46
s32(* read)(struct e1000_hw *, u32 *, u16, u16)
Definition: igbvf_vf.h:279
struct e1000_mbx_operations ops
Definition: igbvf_vf.h:298
static s32 igbvf_read_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
igbvf_read_posted_mbx - Wait for message notification and receive message @hw: pointer to the HW stru...
Definition: igbvf_mbx.c:105
#define usec_delay(x)
Definition: igbvf_osdep.h:59
struct e1000_mbx_stats stats
Definition: igbvf_vf.h:299
#define E1000_WRITE_REG_ARRAY(a, reg, offset, value)
Definition: igbvf_osdep.h:81
static s32 igbvf_read_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id __unused)
igbvf_read_mbx_vf - Reads a message from the inbox intended for vf @hw: pointer to the HW structure @...
Definition: igbvf_mbx.c:344
#define E1000_V2PMAILBOX_VFU
Definition: igbvf_mbx.h:43
void igbvf_init_mbx_ops_generic(struct e1000_hw *hw)
igbvf_init_mbx_ops_generic - Initialize NVM function pointers @hw: pointer to the HW structure
Definition: igbvf_mbx.c:163
__be32 out[4]
Definition: CIB_PRM.h:36
#define E1000_V2PMAILBOX_PFSTS
Definition: igbvf_mbx.h:45
static s32 igbvf_check_for_rst_vf(struct e1000_hw *hw, u16 mbx_id __unused)
igbvf_check_for_rst_vf - checks to see if the PF has reset @hw: pointer to the HW structure @mbx_id: ...
Definition: igbvf_mbx.c:257
#define E1000_WRITE_REG(a, reg, value)
Definition: igbvf_osdep.h:76
static s32 igbvf_check_for_msg_vf(struct e1000_hw *hw, u16 mbx_id __unused)
igbvf_check_for_msg_vf - checks to see if the PF has sent mail @hw: pointer to the HW structure @mbx_...
Definition: igbvf_mbx.c:215
static s32 igbvf_obtain_mbx_lock_vf(struct e1000_hw *hw)
igbvf_obtain_mbx_lock_vf - obtain mailbox lock @hw: pointer to the HW structure
Definition: igbvf_mbx.c:278
#define E1000_SUCCESS
#define E1000_ERR_MBX
s32(* write)(struct e1000_hw *, u32 *, u16, u16)
Definition: igbvf_vf.h:280
#define E1000_V2PMAILBOX(_n)
Definition: igbvf_mbx.h:37
#define E1000_VFMAILBOX_SIZE
Definition: igbvf_mbx.h:51
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
#define E1000_V2PMAILBOX_REQ
Definition: igbvf_mbx.h:41
s32 igbvf_init_mbx_params_vf(struct e1000_hw *hw)
igbvf_init_mbx_params_vf - set initial values for vf mailbox @hw: pointer to the HW structure
Definition: igbvf_mbx.c:377
s32(* check_for_rst)(struct e1000_hw *, u16)
Definition: igbvf_vf.h:285
static s32 igbvf_check_for_ack_vf(struct e1000_hw *hw, u16 mbx_id __unused)
igbvf_check_for_ack_vf - checks to see if the PF has ACK'd @hw: pointer to the HW structure @mbx_id: ...
Definition: igbvf_mbx.c:236
s32(* check_for_ack)(struct e1000_hw *, u16)
Definition: igbvf_vf.h:284
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
static s32 igbvf_write_posted_mbx(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id)
igbvf_write_posted_mbx - Write a message to the mailbox, wait for ack @hw: pointer to the HW structur...
Definition: igbvf_mbx.c:135
#define E1000_VMBMEM(_n)
Definition: igbvf_mbx.h:38
static s32 igbvf_write_mbx_vf(struct e1000_hw *hw, u32 *msg, u16 size, u16 mbx_id __unused)
igbvf_write_mbx_vf - Write a message to the mailbox @hw: pointer to the HW structure @msg: The messag...
Definition: igbvf_mbx.c:303
s32(* write_posted)(struct e1000_hw *, u32 *, u16, u16)
Definition: igbvf_vf.h:282
#define DEBUGFUNC(F)
Definition: igbvf_osdep.h:71
#define E1000_VF_MBX_INIT_DELAY
Definition: igbvf_mbx.h:82
#define E1000_V2PMAILBOX_RSTI
Definition: igbvf_mbx.h:47
FILE_LICENCE(GPL2_ONLY)
s32(* check_for_msg)(struct e1000_hw *, u16)
Definition: igbvf_vf.h:283
#define E1000_V2PMAILBOX_ACK
Definition: igbvf_mbx.h:42
uint32_t u32
Definition: stdint.h:23
static void msg(unsigned int row, const char *fmt,...)
Print message centred on specified row.
Definition: settings_ui.c:285
#define E1000_READ_REG(a, reg)
Definition: igbvf_osdep.h:79