1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
9 STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw);
10 STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw);
11 STATIC void e1000_release_vf(struct e1000_hw *hw);
12 STATIC s32 e1000_acquire_vf(struct e1000_hw *hw);
13 STATIC s32 e1000_setup_link_vf(struct e1000_hw *hw);
14 STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw);
15 STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw);
16 STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw);
17 STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
19 STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw);
20 STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw);
21 STATIC void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *, u32);
22 STATIC int e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
23 STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *);
26 * e1000_init_phy_params_vf - Inits PHY params
27 * @hw: pointer to the HW structure
29 * Doesn't do much - there's no PHY available to the VF.
31 STATIC s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
33 DEBUGFUNC("e1000_init_phy_params_vf");
34 hw->phy.type = e1000_phy_vf;
35 hw->phy.ops.acquire = e1000_acquire_vf;
36 hw->phy.ops.release = e1000_release_vf;
42 * e1000_init_nvm_params_vf - Inits NVM params
43 * @hw: pointer to the HW structure
45 * Doesn't do much - there's no NVM available to the VF.
47 STATIC s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
49 DEBUGFUNC("e1000_init_nvm_params_vf");
50 hw->nvm.type = e1000_nvm_none;
51 hw->nvm.ops.acquire = e1000_acquire_vf;
52 hw->nvm.ops.release = e1000_release_vf;
58 * e1000_init_mac_params_vf - Inits MAC params
59 * @hw: pointer to the HW structure
61 STATIC s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
63 struct e1000_mac_info *mac = &hw->mac;
65 DEBUGFUNC("e1000_init_mac_params_vf");
69 * Virtual functions don't care what they're media type is as they
70 * have no direct access to the PHY, or the media. That is handled
71 * by the physical function driver.
73 hw->phy.media_type = e1000_media_type_unknown;
75 /* No ASF features for the VF driver */
76 mac->asf_firmware_present = false;
77 /* ARC subsystem not supported */
78 mac->arc_subsystem_valid = false;
79 /* Disable adaptive IFS mode so the generic funcs don't do anything */
80 mac->adaptive_ifs = false;
81 /* VF's have no MTA Registers - PF feature only */
82 mac->mta_reg_count = 128;
83 /* VF's have no access to RAR entries */
84 mac->rar_entry_count = 1;
86 /* Function pointers */
88 mac->ops.setup_link = e1000_setup_link_vf;
89 /* bus type/speed/width */
90 mac->ops.get_bus_info = e1000_get_bus_info_pcie_vf;
92 mac->ops.reset_hw = e1000_reset_hw_vf;
93 /* hw initialization */
94 mac->ops.init_hw = e1000_init_hw_vf;
96 mac->ops.check_for_link = e1000_check_for_link_vf;
98 mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
99 /* multicast address update */
100 mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
101 /* set mac address */
102 mac->ops.rar_set = e1000_rar_set_vf;
103 /* read mac address */
104 mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
107 return E1000_SUCCESS;
111 * e1000_init_function_pointers_vf - Inits function pointers
112 * @hw: pointer to the HW structure
114 void e1000_init_function_pointers_vf(struct e1000_hw *hw)
116 DEBUGFUNC("e1000_init_function_pointers_vf");
118 hw->mac.ops.init_params = e1000_init_mac_params_vf;
119 hw->nvm.ops.init_params = e1000_init_nvm_params_vf;
120 hw->phy.ops.init_params = e1000_init_phy_params_vf;
121 hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
125 * e1000_acquire_vf - Acquire rights to access PHY or NVM.
126 * @hw: pointer to the HW structure
128 * There is no PHY or NVM so we want all attempts to acquire these to fail.
129 * In addition, the MAC registers to access PHY/NVM don't exist so we don't
130 * even want any SW to attempt to use them.
132 STATIC s32 e1000_acquire_vf(struct e1000_hw E1000_UNUSEDARG *hw)
134 UNREFERENCED_1PARAMETER(hw);
135 return -E1000_ERR_PHY;
139 * e1000_release_vf - Release PHY or NVM
140 * @hw: pointer to the HW structure
142 * There is no PHY or NVM so we want all attempts to acquire these to fail.
143 * In addition, the MAC registers to access PHY/NVM don't exist so we don't
144 * even want any SW to attempt to use them.
146 STATIC void e1000_release_vf(struct e1000_hw E1000_UNUSEDARG *hw)
148 UNREFERENCED_1PARAMETER(hw);
153 * e1000_setup_link_vf - Sets up link.
154 * @hw: pointer to the HW structure
156 * Virtual functions cannot change link.
158 STATIC s32 e1000_setup_link_vf(struct e1000_hw E1000_UNUSEDARG *hw)
160 DEBUGFUNC("e1000_setup_link_vf");
161 UNREFERENCED_1PARAMETER(hw);
163 return E1000_SUCCESS;
167 * e1000_get_bus_info_pcie_vf - Gets the bus info.
168 * @hw: pointer to the HW structure
170 * Virtual functions are not really on their own bus.
172 STATIC s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
174 struct e1000_bus_info *bus = &hw->bus;
176 DEBUGFUNC("e1000_get_bus_info_pcie_vf");
178 /* Do not set type PCI-E because we don't want disable master to run */
179 bus->type = e1000_bus_type_reserved;
180 bus->speed = e1000_bus_speed_2500;
186 * e1000_get_link_up_info_vf - Gets link info.
187 * @hw: pointer to the HW structure
188 * @speed: pointer to 16 bit value to store link speed.
189 * @duplex: pointer to 16 bit value to store duplex.
191 * Since we cannot read the PHY and get accurate link info, we must rely upon
192 * the status register's data which is often stale and inaccurate.
194 STATIC s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
199 DEBUGFUNC("e1000_get_link_up_info_vf");
201 status = E1000_READ_REG(hw, E1000_STATUS);
202 if (status & E1000_STATUS_SPEED_1000) {
204 DEBUGOUT("1000 Mbs, ");
205 } else if (status & E1000_STATUS_SPEED_100) {
207 DEBUGOUT("100 Mbs, ");
210 DEBUGOUT("10 Mbs, ");
213 if (status & E1000_STATUS_FD) {
214 *duplex = FULL_DUPLEX;
215 DEBUGOUT("Full Duplex\n");
217 *duplex = HALF_DUPLEX;
218 DEBUGOUT("Half Duplex\n");
221 return E1000_SUCCESS;
225 * e1000_reset_hw_vf - Resets the HW
226 * @hw: pointer to the HW structure
228 * VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
229 * This is all the reset we can perform on a VF.
231 STATIC s32 e1000_reset_hw_vf(struct e1000_hw *hw)
233 struct e1000_mbx_info *mbx = &hw->mbx;
234 u32 timeout = E1000_VF_INIT_TIMEOUT;
235 s32 ret_val = -E1000_ERR_MAC_INIT;
237 u8 *addr = (u8 *)(&msgbuf[1]);
239 DEBUGFUNC("e1000_reset_hw_vf");
241 DEBUGOUT("Issuing a function level reset to MAC\n");
242 ctrl = E1000_READ_REG(hw, E1000_CTRL);
243 E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
245 /* we cannot reset while the RSTI / RSTD bits are asserted */
246 while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
252 /* mailbox timeout can now become active */
253 mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
255 msgbuf[0] = E1000_VF_RESET;
256 mbx->ops.write_posted(hw, msgbuf, 1, 0);
260 /* set our "perm_addr" based on info provided by PF */
261 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
263 if (msgbuf[0] == (E1000_VF_RESET |
264 E1000_VT_MSGTYPE_ACK))
265 memcpy(hw->mac.perm_addr, addr, 6);
267 ret_val = -E1000_ERR_MAC_INIT;
275 * e1000_init_hw_vf - Inits the HW
276 * @hw: pointer to the HW structure
278 * Not much to do here except clear the PF Reset indication if there is one.
280 STATIC s32 e1000_init_hw_vf(struct e1000_hw *hw)
282 DEBUGFUNC("e1000_init_hw_vf");
284 /* attempt to set and restore our mac address */
285 e1000_rar_set_vf(hw, hw->mac.addr, 0);
287 return E1000_SUCCESS;
291 * e1000_rar_set_vf - set device MAC address
292 * @hw: pointer to the HW structure
293 * @addr: pointer to the receive address
294 * @index receive address array register
296 STATIC int e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr,
297 u32 E1000_UNUSEDARG index)
299 struct e1000_mbx_info *mbx = &hw->mbx;
301 u8 *msg_addr = (u8 *)(&msgbuf[1]);
304 UNREFERENCED_1PARAMETER(index);
305 memset(msgbuf, 0, 12);
306 msgbuf[0] = E1000_VF_SET_MAC_ADDR;
307 memcpy(msg_addr, addr, 6);
308 ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
311 ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
313 msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
315 /* if nacked the address was rejected, use "perm_addr" */
317 (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
318 e1000_read_mac_addr_vf(hw);
320 return E1000_SUCCESS;
324 * e1000_hash_mc_addr_vf - Generate a multicast hash value
325 * @hw: pointer to the HW structure
326 * @mc_addr: pointer to a multicast address
328 * Generates a multicast address hash value which is used to determine
329 * the multicast filter table array address and new table value.
331 STATIC u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
333 u32 hash_value, hash_mask;
336 DEBUGFUNC("e1000_hash_mc_addr_generic");
338 /* Register count multiplied by bits per register */
339 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
342 * The bit_shift is the number of left-shifts
343 * where 0xFF would still fall within the hash mask.
345 while (hash_mask >> bit_shift != 0xFF)
348 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
349 (((u16) mc_addr[5]) << bit_shift)));
354 STATIC void e1000_write_msg_read_ack(struct e1000_hw *hw,
357 struct e1000_mbx_info *mbx = &hw->mbx;
358 u32 retmsg[E1000_VFMAILBOX_SIZE];
359 s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
362 mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
366 * e1000_update_mc_addr_list_vf - Update Multicast addresses
367 * @hw: pointer to the HW structure
368 * @mc_addr_list: array of multicast addresses to program
369 * @mc_addr_count: number of multicast addresses to program
371 * Updates the Multicast Table Array.
372 * The caller must have a packed mc_addr_list of multicast addresses.
374 void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
375 u8 *mc_addr_list, u32 mc_addr_count)
377 u32 msgbuf[E1000_VFMAILBOX_SIZE];
378 u16 *hash_list = (u16 *)&msgbuf[1];
382 DEBUGFUNC("e1000_update_mc_addr_list_vf");
384 /* Each entry in the list uses 1 16 bit word. We have 30
385 * 16 bit words available in our HW msg buffer (minus 1 for the
386 * msg type). That's 30 hash values if we pack 'em right. If
387 * there are more than 30 MC addresses to add then punt the
388 * extras for now and then add code to handle more than 30 later.
389 * It would be unusual for a server to request that many multi-cast
390 * addresses except for in large enterprise network environments.
393 DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
395 msgbuf[0] = E1000_VF_SET_MULTICAST;
397 if (mc_addr_count > 30) {
398 msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
402 msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
404 for (i = 0; i < mc_addr_count; i++) {
405 hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
406 DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
407 hash_list[i] = hash_value & 0x0FFF;
408 mc_addr_list += ETH_ADDR_LEN;
411 e1000_write_msg_read_ack(hw, msgbuf, E1000_VFMAILBOX_SIZE);
415 * e1000_vfta_set_vf - Set/Unset vlan filter table address
416 * @hw: pointer to the HW structure
417 * @vid: determines the vfta register and bit to set/unset
418 * @set: if true then set bit, else clear bit
420 void e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
424 msgbuf[0] = E1000_VF_SET_VLAN;
426 /* Setting the 8 bit field MSG INFO to TRUE indicates "add" */
428 msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
430 e1000_write_msg_read_ack(hw, msgbuf, 2);
433 /** e1000_rlpml_set_vf - Set the maximum receive packet length
434 * @hw: pointer to the HW structure
435 * @max_size: value to assign to max frame size
437 void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
441 msgbuf[0] = E1000_VF_SET_LPE;
442 msgbuf[1] = max_size;
444 e1000_write_msg_read_ack(hw, msgbuf, 2);
448 * e1000_promisc_set_vf - Set flags for Unicast or Multicast promisc
449 * @hw: pointer to the HW structure
450 * @uni: boolean indicating unicast promisc status
451 * @multi: boolean indicating multicast promisc status
453 s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
455 struct e1000_mbx_info *mbx = &hw->mbx;
456 u32 msgbuf = E1000_VF_SET_PROMISC;
460 case e1000_promisc_multicast:
461 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
463 case e1000_promisc_enabled:
464 msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
466 case e1000_promisc_unicast:
467 msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
469 case e1000_promisc_disabled:
472 return -E1000_ERR_MAC_INIT;
475 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
478 ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
480 if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
481 ret_val = -E1000_ERR_MAC_INIT;
487 * e1000_read_mac_addr_vf - Read device MAC address
488 * @hw: pointer to the HW structure
490 STATIC s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
494 for (i = 0; i < ETH_ADDR_LEN; i++)
495 hw->mac.addr[i] = hw->mac.perm_addr[i];
497 return E1000_SUCCESS;
501 * e1000_check_for_link_vf - Check for link for a virtual interface
502 * @hw: pointer to the HW structure
504 * Checks to see if the underlying PF is still talking to the VF and
505 * if it is then it reports the link state to the hardware, otherwise
506 * it reports link down and returns an error.
508 STATIC s32 e1000_check_for_link_vf(struct e1000_hw *hw)
510 struct e1000_mbx_info *mbx = &hw->mbx;
511 struct e1000_mac_info *mac = &hw->mac;
512 s32 ret_val = E1000_SUCCESS;
515 DEBUGFUNC("e1000_check_for_link_vf");
518 * We only want to run this if there has been a rst asserted.
519 * in this case that could mean a link change, device reset,
520 * or a virtual function reset
523 /* If we were hit with a reset or timeout drop the link */
524 if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
525 mac->get_link_status = true;
527 if (!mac->get_link_status)
530 /* if link status is down no point in checking to see if pf is up */
531 if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
534 /* if the read failed it could just be a mailbox collision, best wait
535 * until we are called again and don't report an error */
536 if (mbx->ops.read(hw, &in_msg, 1, 0))
539 /* if incoming message isn't clear to send we are waiting on response */
540 if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
541 /* message is not CTS and is NACK we have lost CTS status */
542 if (in_msg & E1000_VT_MSGTYPE_NACK)
543 ret_val = -E1000_ERR_MAC_INIT;
547 /* at this point we know the PF is talking to us, check and see if
548 * we are still accepting timeout or if we had a timeout failure.
549 * if we failed then we will need to reinit */
551 ret_val = -E1000_ERR_MAC_INIT;
555 /* if we passed all the tests above then the link is up and we no
556 * longer need to check for link */
557 mac->get_link_status = false;