1 /*******************************************************************************
3 Copyright (c) 2001-2012, 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 ***************************************************************************/
35 #include "e1000_api.h"
38 STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw);
39 STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw);
40 STATIC void e1000_release_vf(struct e1000_hw *hw);
41 STATIC s32 e1000_acquire_vf(struct e1000_hw *hw);
42 STATIC s32 e1000_setup_link_vf(struct e1000_hw *hw);
43 STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
44 STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw);
45 STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw);
46 STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
48 STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw);
49 STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw);
50 STATIC void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
51 STATIC void e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
52 STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *);
55 * e1000_init_phy_params_vf - Inits PHY params
56 * @hw: pointer to the HW structure
58 * Doesn't do much - there's no PHY available to the VF.
60 STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
62 DEBUGFUNC("e1000_init_phy_params_vf");
63 hw->phy.type = e1000_phy_vf;
64 hw->phy.ops.acquire = e1000_acquire_vf;
65 hw->phy.ops.release = e1000_release_vf;
71 * e1000_init_nvm_params_vf - Inits NVM params
72 * @hw: pointer to the HW structure
74 * Doesn't do much - there's no NVM available to the VF.
76 STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
78 DEBUGFUNC("e1000_init_nvm_params_vf");
79 hw->nvm.type = e1000_nvm_none;
80 hw->nvm.ops.acquire = e1000_acquire_vf;
81 hw->nvm.ops.release = e1000_release_vf;
87 * e1000_init_mac_params_vf - Inits MAC params
88 * @hw: pointer to the HW structure
90 STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
92 struct e1000_mac_info *mac = &hw->mac;
94 DEBUGFUNC("e1000_init_mac_params_vf");
98 * Virtual functions don't care what they're media type is as they
99 * have no direct access to the PHY, or the media. That is handled
100 * by the physical function driver.
102 hw->phy.media_type = e1000_media_type_unknown;
104 /* No ASF features for the VF driver */
105 mac->asf_firmware_present = false;
106 /* ARC subsystem not supported */
107 mac->arc_subsystem_valid = false;
108 /* Disable adaptive IFS mode so the generic funcs don't do anything */
109 mac->adaptive_ifs = false;
110 /* VF's have no MTA Registers - PF feature only */
111 mac->mta_reg_count = 128;
112 /* VF's have no access to RAR entries */
113 mac->rar_entry_count = 1;
115 /* Function pointers */
117 mac->ops.setup_link = e1000_setup_link_vf;
118 /* bus type/speed/width */
119 mac->ops.get_bus_info = e1000_get_bus_info_pcie_vf;
121 mac->ops.reset_hw = e1000_reset_hw_vf;
122 /* hw initialization */
123 mac->ops.init_hw = e1000_init_hw_vf;
125 mac->ops.check_for_link = e1000_check_for_link_vf;
127 mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
128 /* multicast address update */
129 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
130 /* set mac address */
131 mac->ops.rar_set = e1000_rar_set_vf;
132 /* read mac address */
133 mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
136 return E1000_SUCCESS;
140 * e1000_init_function_pointers_vf - Inits function pointers
141 * @hw: pointer to the HW structure
143 void e1000_init_function_pointers_vf(struct e1000_hw *hw)
145 DEBUGFUNC("e1000_init_function_pointers_vf");
147 hw->mac.ops.init_params = e1000_init_mac_params_vf;
148 hw->nvm.ops.init_params = e1000_init_nvm_params_vf;
149 hw->phy.ops.init_params = e1000_init_phy_params_vf;
150 hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
154 * e1000_acquire_vf - Acquire rights to access PHY or NVM.
155 * @hw: pointer to the HW structure
157 * There is no PHY or NVM so we want all attempts to acquire these to fail.
158 * In addition, the MAC registers to access PHY/NVM don't exist so we don't
159 * even want any SW to attempt to use them.
161 STATIC s32 e1000_acquire_vf(struct e1000_hw *hw)
163 return -E1000_ERR_PHY;
167 * e1000_release_vf - Release PHY or NVM
168 * @hw: pointer to the HW structure
170 * There is no PHY or NVM so we want all attempts to acquire these to fail.
171 * In addition, the MAC registers to access PHY/NVM don't exist so we don't
172 * even want any SW to attempt to use them.
174 STATIC void e1000_release_vf(struct e1000_hw *hw)
180 * e1000_setup_link_vf - Sets up link.
181 * @hw: pointer to the HW structure
183 * Virtual functions cannot change link.
185 STATIC s32 e1000_setup_link_vf(struct e1000_hw *hw)
187 DEBUGFUNC("e1000_setup_link_vf");
189 return E1000_SUCCESS;
193 * e1000_get_bus_info_pcie_vf - Gets the bus info.
194 * @hw: pointer to the HW structure
196 * Virtual functions are not really on their own bus.
198 STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
200 struct e1000_bus_info *bus = &hw->bus;
202 DEBUGFUNC("e1000_get_bus_info_pcie_vf");
204 /* Do not set type PCI-E because we don't want disable master to run */
205 bus->type = e1000_bus_type_reserved;
206 bus->speed = e1000_bus_speed_2500;
212 * e1000_get_link_up_info_vf - Gets link info.
213 * @hw: pointer to the HW structure
214 * @speed: pointer to 16 bit value to store link speed.
215 * @duplex: pointer to 16 bit value to store duplex.
217 * Since we cannot read the PHY and get accurate link info, we must rely upon
218 * the status register's data which is often stale and inaccurate.
220 STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
225 DEBUGFUNC("e1000_get_link_up_info_vf");
227 status = E1000_READ_REG(hw, E1000_STATUS);
228 if (status & E1000_STATUS_SPEED_1000) {
230 DEBUGOUT("1000 Mbs, ");
231 } else if (status & E1000_STATUS_SPEED_100) {
233 DEBUGOUT("100 Mbs, ");
236 DEBUGOUT("10 Mbs, ");
239 if (status & E1000_STATUS_FD) {
240 *duplex = FULL_DUPLEX;
241 DEBUGOUT("Full Duplex\n");
243 *duplex = HALF_DUPLEX;
244 DEBUGOUT("Half Duplex\n");
247 return E1000_SUCCESS;
251 * e1000_reset_hw_vf - Resets the HW
252 * @hw: pointer to the HW structure
254 * VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
255 * This is all the reset we can perform on a VF.
257 STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw)
259 struct e1000_mbx_info *mbx = &hw->mbx;
260 u32 timeout = E1000_VF_INIT_TIMEOUT;
261 s32 ret_val = -E1000_ERR_MAC_INIT;
263 u8 *addr = (u8 *)(&msgbuf[1]);
265 DEBUGFUNC("e1000_reset_hw_vf");
267 DEBUGOUT("Issuing a function level reset to MAC\n");
268 ctrl = E1000_READ_REG(hw, E1000_CTRL);
269 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
271 /* we cannot reset while the RSTI / RSTD bits are asserted */
272 while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
278 /* mailbox timeout can now become active */
279 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
281 msgbuf[0] = E1000_VF_RESET;
282 mbx->ops.write_posted(hw, msgbuf, 1, 0);
286 /* set our "perm_addr" based on info provided by PF */
287 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
289 if (msgbuf[0] == (E1000_VF_RESET |
290 E1000_VT_MSGTYPE_ACK))
291 memcpy(hw->mac.perm_addr, addr, 6);
293 ret_val = -E1000_ERR_MAC_INIT;
301 * e1000_init_hw_vf - Inits the HW
302 * @hw: pointer to the HW structure
304 * Not much to do here except clear the PF Reset indication if there is one.
306 STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw)
308 DEBUGFUNC("e1000_init_hw_vf");
310 /* attempt to set and restore our mac address */
311 e1000_rar_set_vf(hw, hw->mac.addr, 0);
313 return E1000_SUCCESS;
317 * e1000_rar_set_vf - set device MAC address
318 * @hw: pointer to the HW structure
319 * @addr: pointer to the receive address
320 * @index receive address array register
322 STATIC void e1000_rar_set_vf(struct e1000_hw *hw, u8 * addr, u32 index)
324 struct e1000_mbx_info *mbx = &hw->mbx;
326 u8 *msg_addr = (u8 *)(&msgbuf[1]);
329 memset(msgbuf, 0, 12);
330 msgbuf[0] = E1000_VF_SET_MAC_ADDR;
331 memcpy(msg_addr, addr, 6);
332 ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
335 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
337 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
339 /* if nacked the address was rejected, use "perm_addr" */
341 (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
342 e1000_read_mac_addr_vf(hw);
346 * e1000_hash_mc_addr_vf - Generate a multicast hash value
347 * @hw: pointer to the HW structure
348 * @mc_addr: pointer to a multicast address
350 * Generates a multicast address hash value which is used to determine
351 * the multicast filter table array address and new table value.
353 STATIC u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
355 u32 hash_value, hash_mask;
358 DEBUGFUNC("e1000_hash_mc_addr_generic");
360 /* Register count multiplied by bits per register */
361 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
364 * The bit_shift is the number of left-shifts
365 * where 0xFF would still fall within the hash mask.
367 while (hash_mask >> bit_shift != 0xFF)
370 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
371 (((u16) mc_addr[5]) << bit_shift)));
376 static void e1000_write_msg_read_ack(struct e1000_hw *hw,
379 struct e1000_mbx_info *mbx = &hw->mbx;
380 u32 retmsg[E1000_VFMAILBOX_SIZE];
381 s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
384 mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
388 * e1000_update_mc_addr_list_vf - Update Multicast addresses
389 * @hw: pointer to the HW structure
390 * @mc_addr_list: array of multicast addresses to program
391 * @mc_addr_count: number of multicast addresses to program
393 * Updates the Multicast Table Array.
394 * The caller must have a packed mc_addr_list of multicast addresses.
396 void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
397 u8 *mc_addr_list, u32 mc_addr_count)
399 u32 msgbuf[E1000_VFMAILBOX_SIZE];
400 u16 *hash_list = (u16 *)&msgbuf[1];
404 DEBUGFUNC("e1000_update_mc_addr_list_vf");
406 /* Each entry in the list uses 1 16 bit word. We have 30
407 * 16 bit words available in our HW msg buffer (minus 1 for the
408 * msg type). That's 30 hash values if we pack 'em right. If
409 * there are more than 30 MC addresses to add then punt the
410 * extras for now and then add code to handle more than 30 later.
411 * It would be unusual for a server to request that many multi-cast
412 * addresses except for in large enterprise network environments.
415 DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
417 if (mc_addr_count > 30) {
418 msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
422 msgbuf[0] = E1000_VF_SET_MULTICAST;
423 msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
425 for (i = 0; i < mc_addr_count; i++) {
426 hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
427 DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
428 hash_list[i] = hash_value & 0x0FFF;
429 mc_addr_list += ETH_ADDR_LEN;
432 e1000_write_msg_read_ack(hw, msgbuf, E1000_VFMAILBOX_SIZE);
436 * e1000_vfta_set_vf - Set/Unset vlan filter table address
437 * @hw: pointer to the HW structure
438 * @vid: determines the vfta register and bit to set/unset
439 * @set: if true then set bit, else clear bit
441 void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
445 msgbuf[0] = E1000_VF_SET_VLAN;
447 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
449 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
451 e1000_write_msg_read_ack(hw, msgbuf, 2);
454 /** e1000_rlpml_set_vf - Set the maximum receive packet length
455 * @hw: pointer to the HW structure
456 * @max_size: value to assign to max frame size
458 void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
462 msgbuf[0] = E1000_VF_SET_LPE;
463 msgbuf[1] = max_size;
465 e1000_write_msg_read_ack(hw, msgbuf, 2);
469 * e1000_promisc_set_vf - Set flags for Unicast or Multicast promisc
470 * @hw: pointer to the HW structure
471 * @uni: boolean indicating unicast promisc status
472 * @multi: boolean indicating multicast promisc status
474 s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
476 struct e1000_mbx_info *mbx = &hw->mbx;
477 u32 msgbuf = E1000_VF_SET_PROMISC;
481 case e1000_promisc_multicast:
482 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
484 case e1000_promisc_enabled:
485 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
486 case e1000_promisc_unicast:
487 msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
488 case e1000_promisc_disabled:
491 return -E1000_ERR_MAC_INIT;
494 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
497 ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
499 if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
500 ret_val = -E1000_ERR_MAC_INIT;
506 * e1000_read_mac_addr_vf - Read device MAC address
507 * @hw: pointer to the HW structure
509 STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
513 for (i = 0; i < ETH_ADDR_LEN; i++)
514 hw->mac.addr[i] = hw->mac.perm_addr[i];
516 return E1000_SUCCESS;
520 * e1000_check_for_link_vf - Check for link for a virtual interface
521 * @hw: pointer to the HW structure
523 * Checks to see if the underlying PF is still talking to the VF and
524 * if it is then it reports the link state to the hardware, otherwise
525 * it reports link down and returns an error.
527 STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw)
529 struct e1000_mbx_info *mbx = &hw->mbx;
530 struct e1000_mac_info *mac = &hw->mac;
531 s32 ret_val = E1000_SUCCESS;
534 DEBUGFUNC("e1000_check_for_link_vf");
537 * We only want to run this if there has been a rst asserted.
538 * in this case that could mean a link change, device reset,
539 * or a virtual function reset
542 /* If we were hit with a reset or timeout drop the link */
543 if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
544 mac->get_link_status = true;
546 if (!mac->get_link_status)
549 /* if link status is down no point in checking to see if pf is up */
550 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
553 /* if the read failed it could just be a mailbox collision, best wait
554 * until we are called again and don't report an error */
555 if (mbx->ops.read(hw, &in_msg, 1, 0))
558 /* if incoming message isn't clear to send we are waiting on response */
559 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
560 /* message is not CTS and is NACK we have lost CTS status */
561 if (in_msg & E1000_VT_MSGTYPE_NACK)
562 ret_val = -E1000_ERR_MAC_INIT;
566 /* at this point we know the PF is talking to us, check and see if
567 * we are still accepting timeout or if we had a timeout failure.
568 * if we failed then we will need to reinit */
570 ret_val = -E1000_ERR_MAC_INIT;
574 /* if we passed all the tests above then the link is up and we no
575 * longer need to check for link */
576 mac->get_link_status = false;