1 /******************************************************************************
3 Copyright (c) 2001-2011, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
36 #include "e1000_api.h"
39 static s32 e1000_init_phy_params_vf(struct e1000_hw *hw);
40 static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw);
41 static void e1000_release_vf(struct e1000_hw *hw);
42 static s32 e1000_acquire_vf(struct e1000_hw *hw);
43 static s32 e1000_setup_link_vf(struct e1000_hw *hw);
44 static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
45 static s32 e1000_init_mac_params_vf(struct e1000_hw *hw);
46 static s32 e1000_check_for_link_vf(struct e1000_hw *hw);
47 static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
49 static s32 e1000_init_hw_vf(struct e1000_hw *hw);
50 static s32 e1000_reset_hw_vf(struct e1000_hw *hw);
51 static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
52 static void e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
53 static s32 e1000_read_mac_addr_vf(struct e1000_hw *);
56 * e1000_init_phy_params_vf - Inits PHY params
57 * @hw: pointer to the HW structure
59 * Doesn't do much - there's no PHY available to the VF.
61 static s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
63 DEBUGFUNC("e1000_init_phy_params_vf");
64 hw->phy.type = e1000_phy_vf;
65 hw->phy.ops.acquire = e1000_acquire_vf;
66 hw->phy.ops.release = e1000_release_vf;
72 * e1000_init_nvm_params_vf - Inits NVM params
73 * @hw: pointer to the HW structure
75 * Doesn't do much - there's no NVM available to the VF.
77 static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
79 DEBUGFUNC("e1000_init_nvm_params_vf");
80 hw->nvm.type = e1000_nvm_none;
81 hw->nvm.ops.acquire = e1000_acquire_vf;
82 hw->nvm.ops.release = e1000_release_vf;
88 * e1000_init_mac_params_vf - Inits MAC params
89 * @hw: pointer to the HW structure
91 static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
93 struct e1000_mac_info *mac = &hw->mac;
95 DEBUGFUNC("e1000_init_mac_params_vf");
99 * Virtual functions don't care what they're media type is as they
100 * have no direct access to the PHY, or the media. That is handled
101 * by the physical function driver.
103 hw->phy.media_type = e1000_media_type_unknown;
105 /* No ASF features for the VF driver */
106 mac->asf_firmware_present = FALSE;
107 /* ARC subsystem not supported */
108 mac->arc_subsystem_valid = FALSE;
109 /* Disable adaptive IFS mode so the generic funcs don't do anything */
110 mac->adaptive_ifs = FALSE;
111 /* VF's have no MTA Registers - PF feature only */
112 mac->mta_reg_count = 128;
113 /* VF's have no access to RAR entries */
114 mac->rar_entry_count = 1;
116 /* Function pointers */
118 mac->ops.setup_link = e1000_setup_link_vf;
119 /* bus type/speed/width */
120 mac->ops.get_bus_info = e1000_get_bus_info_pcie_vf;
122 mac->ops.reset_hw = e1000_reset_hw_vf;
123 /* hw initialization */
124 mac->ops.init_hw = e1000_init_hw_vf;
126 mac->ops.check_for_link = e1000_check_for_link_vf;
128 mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
129 /* multicast address update */
130 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
131 /* set mac address */
132 mac->ops.rar_set = e1000_rar_set_vf;
133 /* read mac address */
134 mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
137 return E1000_SUCCESS;
141 * e1000_init_function_pointers_vf - Inits function pointers
142 * @hw: pointer to the HW structure
144 void e1000_init_function_pointers_vf(struct e1000_hw *hw)
146 DEBUGFUNC("e1000_init_function_pointers_vf");
148 hw->mac.ops.init_params = e1000_init_mac_params_vf;
149 hw->nvm.ops.init_params = e1000_init_nvm_params_vf;
150 hw->phy.ops.init_params = e1000_init_phy_params_vf;
151 hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
155 * e1000_acquire_vf - Acquire rights to access PHY or NVM.
156 * @hw: pointer to the HW structure
158 * There is no PHY or NVM so we want all attempts to acquire these to fail.
159 * In addition, the MAC registers to access PHY/NVM don't exist so we don't
160 * even want any SW to attempt to use them.
162 static s32 e1000_acquire_vf(struct e1000_hw E1000_UNUSEDARG *hw)
164 return -E1000_ERR_PHY;
168 * e1000_release_vf - Release PHY or NVM
169 * @hw: pointer to the HW structure
171 * There is no PHY or NVM so we want all attempts to acquire these to fail.
172 * In addition, the MAC registers to access PHY/NVM don't exist so we don't
173 * even want any SW to attempt to use them.
175 static void e1000_release_vf(struct e1000_hw E1000_UNUSEDARG *hw)
181 * e1000_setup_link_vf - Sets up link.
182 * @hw: pointer to the HW structure
184 * Virtual functions cannot change link.
186 static s32 e1000_setup_link_vf(struct e1000_hw E1000_UNUSEDARG *hw)
188 DEBUGFUNC("e1000_setup_link_vf");
190 return E1000_SUCCESS;
194 * e1000_get_bus_info_pcie_vf - Gets the bus info.
195 * @hw: pointer to the HW structure
197 * Virtual functions are not really on their own bus.
199 static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
201 struct e1000_bus_info *bus = &hw->bus;
203 DEBUGFUNC("e1000_get_bus_info_pcie_vf");
205 /* Do not set type PCI-E because we don't want disable master to run */
206 bus->type = e1000_bus_type_reserved;
207 bus->speed = e1000_bus_speed_2500;
213 * e1000_get_link_up_info_vf - Gets link info.
214 * @hw: pointer to the HW structure
215 * @speed: pointer to 16 bit value to store link speed.
216 * @duplex: pointer to 16 bit value to store duplex.
218 * Since we cannot read the PHY and get accurate link info, we must rely upon
219 * the status register's data which is often stale and inaccurate.
221 static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
226 DEBUGFUNC("e1000_get_link_up_info_vf");
228 status = E1000_READ_REG(hw, E1000_STATUS);
229 if (status & E1000_STATUS_SPEED_1000) {
231 DEBUGOUT("1000 Mbs, ");
232 } else if (status & E1000_STATUS_SPEED_100) {
234 DEBUGOUT("100 Mbs, ");
237 DEBUGOUT("10 Mbs, ");
240 if (status & E1000_STATUS_FD) {
241 *duplex = FULL_DUPLEX;
242 DEBUGOUT("Full Duplex\n");
244 *duplex = HALF_DUPLEX;
245 DEBUGOUT("Half Duplex\n");
248 return E1000_SUCCESS;
252 * e1000_reset_hw_vf - Resets the HW
253 * @hw: pointer to the HW structure
255 * VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
256 * This is all the reset we can perform on a VF.
258 static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
260 struct e1000_mbx_info *mbx = &hw->mbx;
261 u32 timeout = E1000_VF_INIT_TIMEOUT;
262 s32 ret_val = -E1000_ERR_MAC_INIT;
264 u8 *addr = (u8 *)(&msgbuf[1]);
266 DEBUGFUNC("e1000_reset_hw_vf");
268 DEBUGOUT("Issuing a function level reset to MAC\n");
269 ctrl = E1000_READ_REG(hw, E1000_CTRL);
270 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
272 /* we cannot reset while the RSTI / RSTD bits are asserted */
273 while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
279 /* mailbox timeout can now become active */
280 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
282 msgbuf[0] = E1000_VF_RESET;
283 mbx->ops.write_posted(hw, msgbuf, 1, 0);
287 /* set our "perm_addr" based on info provided by PF */
288 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
290 if (msgbuf[0] == (E1000_VF_RESET |
291 E1000_VT_MSGTYPE_ACK))
292 memcpy(hw->mac.perm_addr, addr, 6);
294 ret_val = -E1000_ERR_MAC_INIT;
302 * e1000_init_hw_vf - Inits the HW
303 * @hw: pointer to the HW structure
305 * Not much to do here except clear the PF Reset indication if there is one.
307 static s32 e1000_init_hw_vf(struct e1000_hw *hw)
309 DEBUGFUNC("e1000_init_hw_vf");
311 /* attempt to set and restore our mac address */
312 e1000_rar_set_vf(hw, hw->mac.addr, 0);
314 return E1000_SUCCESS;
318 * e1000_rar_set_vf - set device MAC address
319 * @hw: pointer to the HW structure
320 * @addr: pointer to the receive address
321 * @index receive address array register
323 static void e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr,
324 u32 E1000_UNUSEDARG index)
326 struct e1000_mbx_info *mbx = &hw->mbx;
328 u8 *msg_addr = (u8 *)(&msgbuf[1]);
331 memset(msgbuf, 0, 12);
332 msgbuf[0] = E1000_VF_SET_MAC_ADDR;
333 memcpy(msg_addr, addr, 6);
334 ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
337 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
339 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
341 /* if nacked the address was rejected, use "perm_addr" */
343 (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
344 e1000_read_mac_addr_vf(hw);
348 * e1000_hash_mc_addr_vf - Generate a multicast hash value
349 * @hw: pointer to the HW structure
350 * @mc_addr: pointer to a multicast address
352 * Generates a multicast address hash value which is used to determine
353 * the multicast filter table array address and new table value.
355 static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
357 u32 hash_value, hash_mask;
360 DEBUGFUNC("e1000_hash_mc_addr_generic");
362 /* Register count multiplied by bits per register */
363 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
366 * The bit_shift is the number of left-shifts
367 * where 0xFF would still fall within the hash mask.
369 while (hash_mask >> bit_shift != 0xFF)
372 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
373 (((u16) mc_addr[5]) << bit_shift)));
378 static void e1000_write_msg_read_ack(struct e1000_hw *hw,
381 struct e1000_mbx_info *mbx = &hw->mbx;
382 u32 retmsg[E1000_VFMAILBOX_SIZE];
383 s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
386 mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
390 * e1000_update_mc_addr_list_vf - Update Multicast addresses
391 * @hw: pointer to the HW structure
392 * @mc_addr_list: array of multicast addresses to program
393 * @mc_addr_count: number of multicast addresses to program
395 * Updates the Multicast Table Array.
396 * The caller must have a packed mc_addr_list of multicast addresses.
398 void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
399 u8 *mc_addr_list, u32 mc_addr_count)
401 u32 msgbuf[E1000_VFMAILBOX_SIZE];
402 u16 *hash_list = (u16 *)&msgbuf[1];
406 DEBUGFUNC("e1000_update_mc_addr_list_vf");
408 /* Each entry in the list uses 1 16 bit word. We have 30
409 * 16 bit words available in our HW msg buffer (minus 1 for the
410 * msg type). That's 30 hash values if we pack 'em right. If
411 * there are more than 30 MC addresses to add then punt the
412 * extras for now and then add code to handle more than 30 later.
413 * It would be unusual for a server to request that many multi-cast
414 * addresses except for in large enterprise network environments.
417 DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
419 if (mc_addr_count > 30) {
420 msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
424 msgbuf[0] = E1000_VF_SET_MULTICAST;
425 msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
427 for (i = 0; i < mc_addr_count; i++) {
428 hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
429 DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
430 hash_list[i] = hash_value & 0x0FFF;
431 mc_addr_list += ETH_ADDR_LEN;
434 e1000_write_msg_read_ack(hw, msgbuf, E1000_VFMAILBOX_SIZE);
438 * e1000_vfta_set_vf - Set/Unset vlan filter table address
439 * @hw: pointer to the HW structure
440 * @vid: determines the vfta register and bit to set/unset
441 * @set: if TRUE then set bit, else clear bit
443 void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
447 msgbuf[0] = E1000_VF_SET_VLAN;
449 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
451 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
453 e1000_write_msg_read_ack(hw, msgbuf, 2);
456 /** e1000_rlpml_set_vf - Set the maximum receive packet length
457 * @hw: pointer to the HW structure
458 * @max_size: value to assign to max frame size
460 void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
464 msgbuf[0] = E1000_VF_SET_LPE;
465 msgbuf[1] = max_size;
467 e1000_write_msg_read_ack(hw, msgbuf, 2);
471 * e1000_promisc_set_vf - Set flags for Unicast or Multicast promisc
472 * @hw: pointer to the HW structure
473 * @uni: boolean indicating unicast promisc status
474 * @multi: boolean indicating multicast promisc status
476 s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
478 struct e1000_mbx_info *mbx = &hw->mbx;
479 u32 msgbuf = E1000_VF_SET_PROMISC;
483 case e1000_promisc_multicast:
484 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
486 case e1000_promisc_enabled:
487 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
488 case e1000_promisc_unicast:
489 msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
490 case e1000_promisc_disabled:
493 return -E1000_ERR_MAC_INIT;
496 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
499 ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
501 if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
502 ret_val = -E1000_ERR_MAC_INIT;
508 * e1000_read_mac_addr_vf - Read device MAC address
509 * @hw: pointer to the HW structure
511 static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
515 for (i = 0; i < ETH_ADDR_LEN; i++)
516 hw->mac.addr[i] = hw->mac.perm_addr[i];
518 return E1000_SUCCESS;
522 * e1000_check_for_link_vf - Check for link for a virtual interface
523 * @hw: pointer to the HW structure
525 * Checks to see if the underlying PF is still talking to the VF and
526 * if it is then it reports the link state to the hardware, otherwise
527 * it reports link down and returns an error.
529 static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
531 struct e1000_mbx_info *mbx = &hw->mbx;
532 struct e1000_mac_info *mac = &hw->mac;
533 s32 ret_val = E1000_SUCCESS;
536 DEBUGFUNC("e1000_check_for_link_vf");
539 * We only want to run this if there has been a rst asserted.
540 * in this case that could mean a link change, device reset,
541 * or a virtual function reset
544 /* If we were hit with a reset or timeout drop the link */
545 if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
546 mac->get_link_status = TRUE;
548 if (!mac->get_link_status)
551 /* if link status is down no point in checking to see if pf is up */
552 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
555 /* if the read failed it could just be a mailbox collision, best wait
556 * until we are called again and don't report an error */
557 if (mbx->ops.read(hw, &in_msg, 1, 0))
560 /* if incoming message isn't clear to send we are waiting on response */
561 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
562 /* message is not CTS and is NACK we have lost CTS status */
563 if (in_msg & E1000_VT_MSGTYPE_NACK)
564 ret_val = -E1000_ERR_MAC_INIT;
568 /* at this point we know the PF is talking to us, check and see if
569 * we are still accepting timeout or if we had a timeout failure.
570 * if we failed then we will need to reinit */
572 ret_val = -E1000_ERR_MAC_INIT;
576 /* if we passed all the tests above then the link is up and we no
577 * longer need to check for link */
578 mac->get_link_status = FALSE;