iPXE
igbvf_vf.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_vf.h"
32 
33 
34 static s32 igbvf_init_mac_params_vf(struct e1000_hw *hw);
35 static s32 igbvf_check_for_link_vf(struct e1000_hw *hw);
36 static s32 igbvf_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
37  u16 *duplex);
38 static s32 igbvf_init_hw_vf(struct e1000_hw *hw);
39 static s32 igbvf_reset_hw_vf(struct e1000_hw *hw);
40 static void igbvf_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
41 static void igbvf_rar_set_vf(struct e1000_hw *, u8 *, u32);
42 static s32 igbvf_read_mac_addr_vf(struct e1000_hw *);
43 
44 /**
45  * igbvf_init_mac_params_vf - Inits MAC params
46  * @hw: pointer to the HW structure
47  **/
49 {
50  struct e1000_mac_info *mac = &hw->mac;
51 
52  DEBUGFUNC("igbvf_init_mac_params_vf");
53 
54  /* VF's have no MTA Registers - PF feature only */
55  mac->mta_reg_count = 128;
56  /* VF's have no access to RAR entries */
57  mac->rar_entry_count = 1;
58 
59  /* Function pointers */
60  /* reset */
61  mac->ops.reset_hw = igbvf_reset_hw_vf;
62  /* hw initialization */
63  mac->ops.init_hw = igbvf_init_hw_vf;
64  /* check for link */
65  mac->ops.check_for_link = igbvf_check_for_link_vf;
66  /* link info */
67  mac->ops.get_link_up_info = igbvf_get_link_up_info_vf;
68  /* multicast address update */
69  mac->ops.update_mc_addr_list = igbvf_update_mc_addr_list_vf;
70  /* set mac address */
71  mac->ops.rar_set = igbvf_rar_set_vf;
72  /* read mac address */
73  mac->ops.read_mac_addr = igbvf_read_mac_addr_vf;
74 
75 
76  return E1000_SUCCESS;
77 }
78 
79 /**
80  * igbvf_init_function_pointers_vf - Inits function pointers
81  * @hw: pointer to the HW structure
82  **/
84 {
85  DEBUGFUNC("igbvf_init_function_pointers_vf");
86 
87  hw->mac.ops.init_params = igbvf_init_mac_params_vf;
88  hw->mbx.ops.init_params = igbvf_init_mbx_params_vf;
89 }
90 
91 /**
92  * igbvf_get_link_up_info_vf - Gets link info.
93  * @hw: pointer to the HW structure
94  * @speed: pointer to 16 bit value to store link speed.
95  * @duplex: pointer to 16 bit value to store duplex.
96  *
97  * Since we cannot read the PHY and get accurate link info, we must rely upon
98  * the status register's data which is often stale and inaccurate.
99  **/
100 static s32 igbvf_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
101  u16 *duplex)
102 {
103  s32 status;
104 
105  DEBUGFUNC("igbvf_get_link_up_info_vf");
106 
109  *speed = SPEED_1000;
110  DEBUGOUT("1000 Mbs, ");
111  } else if (status & E1000_STATUS_SPEED_100) {
112  *speed = SPEED_100;
113  DEBUGOUT("100 Mbs, ");
114  } else {
115  *speed = SPEED_10;
116  DEBUGOUT("10 Mbs, ");
117  }
118 
119  if (status & E1000_STATUS_FD) {
120  *duplex = FULL_DUPLEX;
121  DEBUGOUT("Full Duplex\n");
122  } else {
123  *duplex = HALF_DUPLEX;
124  DEBUGOUT("Half Duplex\n");
125  }
126 
127  return E1000_SUCCESS;
128 }
129 
130 /**
131  * igbvf_reset_hw_vf - Resets the HW
132  * @hw: pointer to the HW structure
133  *
134  * VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
135  * This is all the reset we can perform on a VF.
136  **/
138 {
139  struct e1000_mbx_info *mbx = &hw->mbx;
141  s32 ret_val = -E1000_ERR_MAC_INIT;
142  u32 ctrl, msgbuf[3];
143  u8 *addr = (u8 *)(&msgbuf[1]);
144 
145  DEBUGFUNC("igbvf_reset_hw_vf");
146 
147  DEBUGOUT("Issuing a function level reset to MAC\n");
150 
151  /* we cannot reset while the RSTI / RSTD bits are asserted */
152  while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
153  timeout--;
154  usec_delay(5);
155  }
156 
157  if (timeout) {
158  /* mailbox timeout can now become active */
160 
161  msgbuf[0] = E1000_VF_RESET;
162  mbx->ops.write_posted(hw, msgbuf, 1, 0);
163 
164  msec_delay(10);
165 
166  /* set our "perm_addr" based on info provided by PF */
167  ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
168  if (!ret_val) {
169  if (msgbuf[0] == (E1000_VF_RESET |
171  memcpy(hw->mac.perm_addr, addr, 6);
172  else
173  ret_val = -E1000_ERR_MAC_INIT;
174  }
175  }
176 
177  return ret_val;
178 }
179 
180 /**
181  * igbvf_init_hw_vf - Inits the HW
182  * @hw: pointer to the HW structure
183  *
184  * Not much to do here except clear the PF Reset indication if there is one.
185  **/
187 {
188  DEBUGFUNC("igbvf_init_hw_vf");
189 
190  /* attempt to set and restore our mac address */
191  igbvf_rar_set_vf(hw, hw->mac.addr, 0);
192 
193  return E1000_SUCCESS;
194 }
195 
196 /**
197  * igbvf_rar_set_vf - set device MAC address
198  * @hw: pointer to the HW structure
199  * @addr: pointer to the receive address
200  * @index receive address array register
201  **/
203 {
204  struct e1000_mbx_info *mbx = &hw->mbx;
205  u32 msgbuf[3];
206  u8 *msg_addr = (u8 *)(&msgbuf[1]);
207  s32 ret_val;
208 
209  memset(msgbuf, 0, 12);
210  msgbuf[0] = E1000_VF_SET_MAC_ADDR;
211  memcpy(msg_addr, addr, 6);
212  ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
213 
214  if (!ret_val)
215  ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
216 
217  msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
218 
219  /* if nacked the address was rejected, use "perm_addr" */
220  if (!ret_val &&
221  (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
223 }
224 
225 /**
226  * igbvf_hash_mc_addr_vf - Generate a multicast hash value
227  * @hw: pointer to the HW structure
228  * @mc_addr: pointer to a multicast address
229  *
230  * Generates a multicast address hash value which is used to determine
231  * the multicast filter table array address and new table value. See
232  * igbvf_mta_set_generic()
233  **/
234 static u32 igbvf_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
235 {
236  u32 hash_value, hash_mask;
237  u8 bit_shift = 0;
238 
239  DEBUGFUNC("igbvf_hash_mc_addr_generic");
240 
241  /* Register count multiplied by bits per register */
242  hash_mask = (hw->mac.mta_reg_count * 32) - 1;
243 
244  /*
245  * The bit_shift is the number of left-shifts
246  * where 0xFF would still fall within the hash mask.
247  */
248  while (hash_mask >> bit_shift != 0xFF)
249  bit_shift++;
250 
251  hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
252  (((u16) mc_addr[5]) << bit_shift)));
253 
254  return hash_value;
255 }
256 
257 /**
258  * igbvf_update_mc_addr_list_vf - Update Multicast addresses
259  * @hw: pointer to the HW structure
260  * @mc_addr_list: array of multicast addresses to program
261  * @mc_addr_count: number of multicast addresses to program
262  *
263  * Updates the Multicast Table Array.
264  * The caller must have a packed mc_addr_list of multicast addresses.
265  **/
267  u8 *mc_addr_list, u32 mc_addr_count)
268 {
269  struct e1000_mbx_info *mbx = &hw->mbx;
270  u32 msgbuf[E1000_VFMAILBOX_SIZE];
271  u16 *hash_list = (u16 *)&msgbuf[1];
272  u32 hash_value;
273  u32 i;
274 
275  DEBUGFUNC("igbvf_update_mc_addr_list_vf");
276 
277  /* Each entry in the list uses 1 16 bit word. We have 30
278  * 16 bit words available in our HW msg buffer (minus 1 for the
279  * msg type). That's 30 hash values if we pack 'em right. If
280  * there are more than 30 MC addresses to add then punt the
281  * extras for now and then add code to handle more than 30 later.
282  * It would be unusual for a server to request that many multi-cast
283  * addresses except for in large enterprise network environments.
284  */
285 
286  DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
287 
288  msgbuf[0] = E1000_VF_SET_MULTICAST;
289 
290  if (mc_addr_count > 30) {
291  msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
292  mc_addr_count = 30;
293  }
294 
295  msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
296 
297  for (i = 0; i < mc_addr_count; i++) {
298  hash_value = igbvf_hash_mc_addr_vf(hw, mc_addr_list);
299  DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
300  hash_list[i] = hash_value & 0x0FFF;
301  mc_addr_list += ETH_ADDR_LEN;
302  }
303 
304  mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE, 0);
305 }
306 
307 /**
308  * igbvf_vfta_set_vf - Set/Unset vlan filter table address
309  * @hw: pointer to the HW structure
310  * @vid: determines the vfta register and bit to set/unset
311  * @set: if true then set bit, else clear bit
312  **/
313 void igbvf_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
314 {
315  struct e1000_mbx_info *mbx = &hw->mbx;
316  u32 msgbuf[2];
317 
318  msgbuf[0] = E1000_VF_SET_VLAN;
319  msgbuf[1] = vid;
320  /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
321  if (set)
322  msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
323 
324  mbx->ops.write_posted(hw, msgbuf, 2, 0);
325 }
326 
327 /** igbvf_rlpml_set_vf - Set the maximum receive packet length
328  * @hw: pointer to the HW structure
329  * @max_size: value to assign to max frame size
330  **/
331 void igbvf_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
332 {
333  struct e1000_mbx_info *mbx = &hw->mbx;
334  u32 msgbuf[2];
335 
336  msgbuf[0] = E1000_VF_SET_LPE;
337  msgbuf[1] = max_size;
338 
339  mbx->ops.write_posted(hw, msgbuf, 2, 0);
340 }
341 
342 /**
343  * igbvf_promisc_set_vf - Set flags for Unicast or Multicast promisc
344  * @hw: pointer to the HW structure
345  * @uni: boolean indicating unicast promisc status
346  * @multi: boolean indicating multicast promisc status
347  **/
349 {
350  struct e1000_mbx_info *mbx = &hw->mbx;
351  u32 msgbuf = E1000_VF_SET_PROMISC;
352  s32 ret_val;
353 
354  switch (type) {
357  break;
360  /* Fall through */
364  break;
365  default:
366  return -E1000_ERR_MAC_INIT;
367  }
368 
369  ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
370 
371  if (!ret_val)
372  ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
373 
374  if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
375  ret_val = -E1000_ERR_MAC_INIT;
376 
377  return ret_val;
378 }
379 
380 /**
381  * igbvf_read_mac_addr_vf - Read device MAC address
382  * @hw: pointer to the HW structure
383  **/
385 {
386  int i;
387 
388  for (i = 0; i < ETH_ADDR_LEN; i++)
389  hw->mac.addr[i] = hw->mac.perm_addr[i];
390 
391  return E1000_SUCCESS;
392 }
393 
394 /**
395  * igbvf_check_for_link_vf - Check for link for a virtual interface
396  * @hw: pointer to the HW structure
397  *
398  * Checks to see if the underlying PF is still talking to the VF and
399  * if it is then it reports the link state to the hardware, otherwise
400  * it reports link down and returns an error.
401  **/
403 {
404  struct e1000_mbx_info *mbx = &hw->mbx;
405  struct e1000_mac_info *mac = &hw->mac;
406  s32 ret_val = E1000_SUCCESS;
407  u32 in_msg = 0;
408 
409  DEBUGFUNC("igbvf_check_for_link_vf");
410 
411  /*
412  * We only want to run this if there has been a rst asserted.
413  * in this case that could mean a link change, device reset,
414  * or a virtual function reset
415  */
416 
417  /* If we were hit with a reset drop the link */
418  if (!mbx->ops.check_for_rst(hw, 0))
419  mac->get_link_status = true;
420 
421  if (!mac->get_link_status)
422  goto out;
423 
424  /* if link status is down no point in checking to see if pf is up */
426  goto out;
427 
428  /* if the read failed it could just be a mailbox collision, best wait
429  * until we are called again and don't report an error */
430  if (mbx->ops.read(hw, &in_msg, 1, 0))
431  goto out;
432 
433  /* if incoming message isn't clear to send we are waiting on response */
434  if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
435  /* message is not CTS and is NACK we have lost CTS status */
436  if (in_msg & E1000_VT_MSGTYPE_NACK)
437  ret_val = -E1000_ERR_MAC_INIT;
438  goto out;
439  }
440 
441  /* at this point we know the PF is talking to us, check and see if
442  * we are still accepting timeout or if we had a timeout failure.
443  * if we failed then we will need to reinit */
444  if (!mbx->timeout) {
445  ret_val = -E1000_ERR_MAC_INIT;
446  goto out;
447  }
448 
449  /* if we passed all the tests above then the link is up and we no
450  * longer need to check for link */
451  mac->get_link_status = false;
452 
453 out:
454  return ret_val;
455 }
456 
#define SPEED_1000
Definition: atl1e.h:52
#define u16
Definition: vga.h:20
#define DEBUGOUT(S)
Definition: igbvf_osdep.h:68
uint16_t u16
Definition: stdint.h:21
#define E1000_VF_SET_PROMISC
Definition: igbvf_mbx.h:75
s32(* read_posted)(struct e1000_hw *, u32 *, u16, u16)
Definition: igbvf_vf.h:281
#define E1000_VF_MBX_INIT_TIMEOUT
Definition: igbvf_mbx.h:81
#define E1000_STATUS_SPEED_100
#define E1000_CTRL
Definition: igbvf_regs.h:34
void igbvf_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
igbvf_rlpml_set_vf - Set the maximum receive packet length @hw: pointer to the HW structure @max_size...
Definition: igbvf_vf.c:331
static s32 igbvf_init_hw_vf(struct e1000_hw *hw)
igbvf_init_hw_vf - Inits the HW @hw: pointer to the HW structure
Definition: igbvf_vf.c:186
struct option_descriptor set[0]
Definition: nvo_cmd.c:111
#define E1000_VT_MSGTYPE_CTS
Definition: igbvf_mbx.h:61
int32_t s32
Definition: stdint.h:22
#define E1000_VT_MSGTYPE_NACK
Definition: igbvf_mbx.h:59
#define DEBUGOUT1(S, A...)
Definition: igbvf_osdep.h:69
uint8_t mac[ETH_ALEN]
MAC address.
Definition: ena.h:24
#define E1000_VF_SET_MULTICAST_OVERFLOW
Definition: igbvf_mbx.h:71
#define SPEED_10
Definition: atl1e.h:50
Definition: hw.c:16
__be32 out[4]
Definition: CIB_PRM.h:36
#define E1000_STATUS
Definition: igbvf_regs.h:36
s32(* read)(struct e1000_hw *, u32 *, u16, u16)
Definition: igbvf_vf.h:279
uint8_t status
Status.
Definition: ena.h:16
#define SPEED_100
Definition: atl1e.h:51
struct e1000_mbx_operations ops
Definition: igbvf_vf.h:298
#define E1000_VT_MSGTYPE_ACK
Definition: igbvf_mbx.h:57
#define usec_delay(x)
Definition: igbvf_osdep.h:59
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void igbvf_rar_set_vf(struct e1000_hw *, u8 *, u32)
static void igbvf_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32)
igbvf_update_mc_addr_list_vf - Update Multicast addresses @hw: pointer to the HW structure @mc_addr_l...
Definition: igbvf_vf.c:266
#define E1000_VF_SET_VLAN
Definition: igbvf_mbx.h:72
#define E1000_VF_SET_PROMISC_UNICAST
Definition: igbvf_mbx.h:76
#define E1000_VF_SET_PROMISC_MULTICAST
Definition: igbvf_mbx.h:77
#define E1000_VF_RESET
Definition: igbvf_mbx.h:67
static s32 igbvf_init_mac_params_vf(struct e1000_hw *hw)
igbvf_init_mac_params_vf - Inits MAC params @hw: pointer to the HW structure
Definition: igbvf_vf.c:48
static s32 igbvf_check_for_link_vf(struct e1000_hw *hw)
igbvf_check_for_link_vf - Check for link for a virtual interface @hw: pointer to the HW structure
Definition: igbvf_vf.c:402
#define E1000_WRITE_REG(a, reg, value)
Definition: igbvf_osdep.h:76
#define E1000_CTRL_RST
static s32 igbvf_read_mac_addr_vf(struct e1000_hw *)
igbvf_read_mac_addr_vf - Read device MAC address @hw: pointer to the HW structure
Definition: igbvf_vf.c:384
void igbvf_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
igbvf_vfta_set_vf - Set/Unset vlan filter table address @hw: pointer to the HW structure @vid: determ...
Definition: igbvf_vf.c:313
#define E1000_STATUS_SPEED_1000
#define E1000_STATUS_LU
#define E1000_SUCCESS
static s32 igbvf_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed, u16 *duplex)
igbvf_get_link_up_info_vf - Gets link info.
Definition: igbvf_vf.c:100
u32 addr
Definition: sky2.h:8
static s32 igbvf_reset_hw_vf(struct e1000_hw *hw)
igbvf_reset_hw_vf - Resets the HW @hw: pointer to the HW structure
Definition: igbvf_vf.c:137
#define msec_delay(x)
Definition: igbvf_osdep.h:60
#define E1000_VFMAILBOX_SIZE
Definition: igbvf_mbx.h:51
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
duplex
Definition: nic.h:40
#define E1000_VF_SET_MULTICAST
Definition: igbvf_mbx.h:69
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
#define E1000_VF_SET_LPE
Definition: igbvf_mbx.h:74
s32(* check_for_rst)(struct e1000_hw *, u16)
Definition: igbvf_vf.h:285
#define E1000_VF_INIT_TIMEOUT
Definition: igbvf_vf.h:59
uint32_t type
Operating system type.
Definition: ena.h:12
s32 igbvf_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
igbvf_promisc_set_vf - Set flags for Unicast or Multicast promisc @hw: pointer to the HW structure @u...
Definition: igbvf_vf.c:348
void igbvf_init_function_pointers_vf(struct e1000_hw *hw)
igbvf_init_function_pointers_vf - Inits function pointers @hw: pointer to the HW structure
Definition: igbvf_vf.c:83
FILE_LICENCE(GPL2_ONLY)
u8 ctrl
Definition: sky2.h:10
e1000_promisc_type
Definition: igbvf_vf.h:333
#define E1000_STATUS_FD
s32(* write_posted)(struct e1000_hw *, u32 *, u16, u16)
Definition: igbvf_vf.h:282
#define DEBUGFUNC(F)
Definition: igbvf_osdep.h:71
void timeout(int)
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
static u32 igbvf_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
igbvf_hash_mc_addr_vf - Generate a multicast hash value @hw: pointer to the HW structure @mc_addr: po...
Definition: igbvf_vf.c:234
#define ETH_ADDR_LEN
uint8_t u8
Definition: stdint.h:19
uint32_t u32
Definition: stdint.h:23
#define E1000_ERR_MAC_INIT
#define E1000_VF_SET_VLAN_ADD
Definition: igbvf_mbx.h:73
#define E1000_VF_SET_MAC_ADDR
Definition: igbvf_mbx.h:68
if(natsemi->flags &NATSEMI_64BIT) return 1
void * memset(void *dest, int character, size_t len) __nonnull
#define E1000_VT_MSGINFO_SHIFT
Definition: igbvf_mbx.h:63
#define E1000_READ_REG(a, reg)
Definition: igbvf_osdep.h:79