1 /*******************************************************************************
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 1999 - 2008 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 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
27 *******************************************************************************/
29 FILE_LICENCE ( GPL2_ONLY );
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,
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 *);
45 * igbvf_init_mac_params_vf - Inits MAC params
46 * @hw: pointer to the HW structure
48 static s32 igbvf_init_mac_params_vf(struct e1000_hw *hw)
50 struct e1000_mac_info *mac = &hw->mac;
52 DEBUGFUNC("igbvf_init_mac_params_vf");
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;
59 /* Function pointers */
61 mac->ops.reset_hw = igbvf_reset_hw_vf;
62 /* hw initialization */
63 mac->ops.init_hw = igbvf_init_hw_vf;
65 mac->ops.check_for_link = igbvf_check_for_link_vf;
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;
71 mac->ops.rar_set = igbvf_rar_set_vf;
72 /* read mac address */
73 mac->ops.read_mac_addr = igbvf_read_mac_addr_vf;
80 * igbvf_init_function_pointers_vf - Inits function pointers
81 * @hw: pointer to the HW structure
83 void igbvf_init_function_pointers_vf(struct e1000_hw *hw)
85 DEBUGFUNC("igbvf_init_function_pointers_vf");
87 hw->mac.ops.init_params = igbvf_init_mac_params_vf;
88 hw->mbx.ops.init_params = igbvf_init_mbx_params_vf;
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.
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.
100 static s32 igbvf_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
105 DEBUGFUNC("igbvf_get_link_up_info_vf");
107 status = E1000_READ_REG(hw, E1000_STATUS);
108 if (status & E1000_STATUS_SPEED_1000) {
110 DEBUGOUT("1000 Mbs, ");
111 } else if (status & E1000_STATUS_SPEED_100) {
113 DEBUGOUT("100 Mbs, ");
116 DEBUGOUT("10 Mbs, ");
119 if (status & E1000_STATUS_FD) {
120 *duplex = FULL_DUPLEX;
121 DEBUGOUT("Full Duplex\n");
123 *duplex = HALF_DUPLEX;
124 DEBUGOUT("Half Duplex\n");
127 return E1000_SUCCESS;
131 * igbvf_reset_hw_vf - Resets the HW
132 * @hw: pointer to the HW structure
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.
137 static s32 igbvf_reset_hw_vf(struct e1000_hw *hw)
139 struct e1000_mbx_info *mbx = &hw->mbx;
140 u32 timeout = E1000_VF_INIT_TIMEOUT;
141 s32 ret_val = -E1000_ERR_MAC_INIT;
143 u8 *addr = (u8 *)(&msgbuf[1]);
145 DEBUGFUNC("igbvf_reset_hw_vf");
147 DEBUGOUT("Issuing a function level reset to MAC\n");
148 ctrl = E1000_READ_REG(hw, E1000_CTRL);
149 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
151 /* we cannot reset while the RSTI / RSTD bits are asserted */
152 while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
158 /* mailbox timeout can now become active */
159 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
161 msgbuf[0] = E1000_VF_RESET;
162 mbx->ops.write_posted(hw, msgbuf, 1, 0);
166 /* set our "perm_addr" based on info provided by PF */
167 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
169 if (msgbuf[0] == (E1000_VF_RESET |
170 E1000_VT_MSGTYPE_ACK))
171 memcpy(hw->mac.perm_addr, addr, 6);
173 ret_val = -E1000_ERR_MAC_INIT;
181 * igbvf_init_hw_vf - Inits the HW
182 * @hw: pointer to the HW structure
184 * Not much to do here except clear the PF Reset indication if there is one.
186 static s32 igbvf_init_hw_vf(struct e1000_hw *hw)
188 DEBUGFUNC("igbvf_init_hw_vf");
190 /* attempt to set and restore our mac address */
191 igbvf_rar_set_vf(hw, hw->mac.addr, 0);
193 return E1000_SUCCESS;
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
202 static void igbvf_rar_set_vf(struct e1000_hw *hw, u8 * addr, u32 index __unused)
204 struct e1000_mbx_info *mbx = &hw->mbx;
206 u8 *msg_addr = (u8 *)(&msgbuf[1]);
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);
215 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
217 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
219 /* if nacked the address was rejected, use "perm_addr" */
221 (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
222 igbvf_read_mac_addr_vf(hw);
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
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()
234 static u32 igbvf_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
236 u32 hash_value, hash_mask;
239 DEBUGFUNC("igbvf_hash_mc_addr_generic");
241 /* Register count multiplied by bits per register */
242 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
245 * The bit_shift is the number of left-shifts
246 * where 0xFF would still fall within the hash mask.
248 while (hash_mask >> bit_shift != 0xFF)
251 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
252 (((u16) mc_addr[5]) << bit_shift)));
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
263 * Updates the Multicast Table Array.
264 * The caller must have a packed mc_addr_list of multicast addresses.
266 void igbvf_update_mc_addr_list_vf(struct e1000_hw *hw,
267 u8 *mc_addr_list, u32 mc_addr_count)
269 struct e1000_mbx_info *mbx = &hw->mbx;
270 u32 msgbuf[E1000_VFMAILBOX_SIZE];
271 u16 *hash_list = (u16 *)&msgbuf[1];
275 DEBUGFUNC("igbvf_update_mc_addr_list_vf");
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.
286 DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
288 msgbuf[0] = E1000_VF_SET_MULTICAST;
290 if (mc_addr_count > 30) {
291 msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
295 msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
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;
304 mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE, 0);
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
313 void igbvf_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
315 struct e1000_mbx_info *mbx = &hw->mbx;
318 msgbuf[0] = E1000_VF_SET_VLAN;
320 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
322 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
324 mbx->ops.write_posted(hw, msgbuf, 2, 0);
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
331 void igbvf_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
333 struct e1000_mbx_info *mbx = &hw->mbx;
336 msgbuf[0] = E1000_VF_SET_LPE;
337 msgbuf[1] = max_size;
339 mbx->ops.write_posted(hw, msgbuf, 2, 0);
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
348 s32 igbvf_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
350 struct e1000_mbx_info *mbx = &hw->mbx;
351 u32 msgbuf = E1000_VF_SET_PROMISC;
355 case e1000_promisc_multicast:
356 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
358 case e1000_promisc_enabled:
359 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
360 case e1000_promisc_unicast:
361 msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
362 case e1000_promisc_disabled:
365 return -E1000_ERR_MAC_INIT;
368 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
371 ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
373 if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
374 ret_val = -E1000_ERR_MAC_INIT;
380 * igbvf_read_mac_addr_vf - Read device MAC address
381 * @hw: pointer to the HW structure
383 static s32 igbvf_read_mac_addr_vf(struct e1000_hw *hw)
387 for (i = 0; i < ETH_ADDR_LEN; i++)
388 hw->mac.addr[i] = hw->mac.perm_addr[i];
390 return E1000_SUCCESS;
394 * igbvf_check_for_link_vf - Check for link for a virtual interface
395 * @hw: pointer to the HW structure
397 * Checks to see if the underlying PF is still talking to the VF and
398 * if it is then it reports the link state to the hardware, otherwise
399 * it reports link down and returns an error.
401 static s32 igbvf_check_for_link_vf(struct e1000_hw *hw)
403 struct e1000_mbx_info *mbx = &hw->mbx;
404 struct e1000_mac_info *mac = &hw->mac;
405 s32 ret_val = E1000_SUCCESS;
408 DEBUGFUNC("igbvf_check_for_link_vf");
411 * We only want to run this if there has been a rst asserted.
412 * in this case that could mean a link change, device reset,
413 * or a virtual function reset
416 /* If we were hit with a reset drop the link */
417 if (!mbx->ops.check_for_rst(hw, 0))
418 mac->get_link_status = true;
420 if (!mac->get_link_status)
423 /* if link status is down no point in checking to see if pf is up */
424 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
427 /* if the read failed it could just be a mailbox collision, best wait
428 * until we are called again and don't report an error */
429 if (mbx->ops.read(hw, &in_msg, 1, 0))
432 /* if incoming message isn't clear to send we are waiting on response */
433 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
434 /* message is not CTS and is NACK we have lost CTS status */
435 if (in_msg & E1000_VT_MSGTYPE_NACK)
436 ret_val = -E1000_ERR_MAC_INIT;
440 /* at this point we know the PF is talking to us, check and see if
441 * we are still accepting timeout or if we had a timeout failure.
442 * if we failed then we will need to reinit */
444 ret_val = -E1000_ERR_MAC_INIT;
448 /* if we passed all the tests above then the link is up and we no
449 * longer need to check for link */
450 mac->get_link_status = false;