xref: /freebsd/sys/dev/e1000/e1000_vf.c (revision 505e6bb93f80fa3a7799cd88b0d0cafcaa468491)
1 /******************************************************************************
2   SPDX-License-Identifier: BSD-3-Clause
3 
4   Copyright (c) 2001-2020, Intel Corporation
5   All rights reserved.
6 
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions are met:
9 
10    1. Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12 
13    2. Redistributions in binary form must reproduce the above copyright
14       notice, this list of conditions and the following disclaimer in the
15       documentation and/or other materials provided with the distribution.
16 
17    3. Neither the name of the Intel Corporation nor the names of its
18       contributors may be used to endorse or promote products derived from
19       this software without specific prior written permission.
20 
21   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31   POSSIBILITY OF SUCH DAMAGE.
32 
33 ******************************************************************************/
34 
35 
36 #include "e1000_api.h"
37 
38 
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,
48 				     u16 *duplex);
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 int  e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
53 static s32 e1000_read_mac_addr_vf(struct e1000_hw *);
54 
55 /**
56  *  e1000_init_phy_params_vf - Inits PHY params
57  *  @hw: pointer to the HW structure
58  *
59  *  Doesn't do much - there's no PHY available to the VF.
60  **/
e1000_init_phy_params_vf(struct e1000_hw * hw)61 static s32 e1000_init_phy_params_vf(struct e1000_hw *hw)
62 {
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;
67 
68 	return E1000_SUCCESS;
69 }
70 
71 /**
72  *  e1000_init_nvm_params_vf - Inits NVM params
73  *  @hw: pointer to the HW structure
74  *
75  *  Doesn't do much - there's no NVM available to the VF.
76  **/
e1000_init_nvm_params_vf(struct e1000_hw * hw)77 static s32 e1000_init_nvm_params_vf(struct e1000_hw *hw)
78 {
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;
83 
84 	return E1000_SUCCESS;
85 }
86 
87 /**
88  *  e1000_init_mac_params_vf - Inits MAC params
89  *  @hw: pointer to the HW structure
90  **/
e1000_init_mac_params_vf(struct e1000_hw * hw)91 static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
92 {
93 	struct e1000_mac_info *mac = &hw->mac;
94 
95 	DEBUGFUNC("e1000_init_mac_params_vf");
96 
97 	/* Set media type */
98 	/*
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.
102 	 */
103 	hw->phy.media_type = e1000_media_type_unknown;
104 
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;
115 
116 	/* Function pointers */
117 	/* link setup */
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;
121 	/* reset */
122 	mac->ops.reset_hw = e1000_reset_hw_vf;
123 	/* hw initialization */
124 	mac->ops.init_hw = e1000_init_hw_vf;
125 	/* check for link */
126 	mac->ops.check_for_link = e1000_check_for_link_vf;
127 	/* link info */
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;
135 
136 
137 	return E1000_SUCCESS;
138 }
139 
140 /**
141  *  e1000_init_function_pointers_vf - Inits function pointers
142  *  @hw: pointer to the HW structure
143  **/
e1000_init_function_pointers_vf(struct e1000_hw * hw)144 void e1000_init_function_pointers_vf(struct e1000_hw *hw)
145 {
146 	DEBUGFUNC("e1000_init_function_pointers_vf");
147 
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;
152 }
153 
154 /**
155  *  e1000_acquire_vf - Acquire rights to access PHY or NVM.
156  *  @hw: pointer to the HW structure
157  *
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.
161  **/
e1000_acquire_vf(struct e1000_hw E1000_UNUSEDARG * hw)162 static s32 e1000_acquire_vf(struct e1000_hw E1000_UNUSEDARG *hw)
163 {
164 	return -E1000_ERR_PHY;
165 }
166 
167 /**
168  *  e1000_release_vf - Release PHY or NVM
169  *  @hw: pointer to the HW structure
170  *
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.
174  **/
e1000_release_vf(struct e1000_hw E1000_UNUSEDARG * hw)175 static void e1000_release_vf(struct e1000_hw E1000_UNUSEDARG *hw)
176 {
177 	return;
178 }
179 
180 /**
181  *  e1000_setup_link_vf - Sets up link.
182  *  @hw: pointer to the HW structure
183  *
184  *  Virtual functions cannot change link.
185  **/
e1000_setup_link_vf(struct e1000_hw E1000_UNUSEDARG * hw)186 static s32 e1000_setup_link_vf(struct e1000_hw E1000_UNUSEDARG *hw)
187 {
188 	DEBUGFUNC("e1000_setup_link_vf");
189 
190 	return E1000_SUCCESS;
191 }
192 
193 /**
194  *  e1000_get_bus_info_pcie_vf - Gets the bus info.
195  *  @hw: pointer to the HW structure
196  *
197  *  Virtual functions are not really on their own bus.
198  **/
e1000_get_bus_info_pcie_vf(struct e1000_hw * hw)199 static s32 e1000_get_bus_info_pcie_vf(struct e1000_hw *hw)
200 {
201 	struct e1000_bus_info *bus = &hw->bus;
202 
203 	DEBUGFUNC("e1000_get_bus_info_pcie_vf");
204 
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;
208 
209 	return 0;
210 }
211 
212 /**
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.
217  *
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.
220  **/
e1000_get_link_up_info_vf(struct e1000_hw * hw,u16 * speed,u16 * duplex)221 static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
222 				     u16 *duplex)
223 {
224 	s32 status;
225 
226 	DEBUGFUNC("e1000_get_link_up_info_vf");
227 
228 	status = E1000_READ_REG(hw, E1000_STATUS);
229 	if (status & E1000_STATUS_SPEED_1000) {
230 		*speed = SPEED_1000;
231 		DEBUGOUT("1000 Mbs, ");
232 	} else if (status & E1000_STATUS_SPEED_100) {
233 		*speed = SPEED_100;
234 		DEBUGOUT("100 Mbs, ");
235 	} else {
236 		*speed = SPEED_10;
237 		DEBUGOUT("10 Mbs, ");
238 	}
239 
240 	if (status & E1000_STATUS_FD) {
241 		*duplex = FULL_DUPLEX;
242 		DEBUGOUT("Full Duplex\n");
243 	} else {
244 		*duplex = HALF_DUPLEX;
245 		DEBUGOUT("Half Duplex\n");
246 	}
247 
248 	return E1000_SUCCESS;
249 }
250 
251 /**
252  *  e1000_reset_hw_vf - Resets the HW
253  *  @hw: pointer to the HW structure
254  *
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.
257  **/
e1000_reset_hw_vf(struct e1000_hw * hw)258 static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
259 {
260 	struct e1000_mbx_info *mbx = &hw->mbx;
261 	u32 timeout = E1000_VF_INIT_TIMEOUT;
262 	s32 ret_val = -E1000_ERR_MAC_INIT;
263 	u32 ctrl, msgbuf[3] = { E1000_VF_RESET, ~0U, ~0U };
264 	u8 *addr = (u8 *)(&msgbuf[1]);
265 
266 	DEBUGFUNC("e1000_reset_hw_vf");
267 
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);
271 
272 	/* we cannot reset while the RSTI / RSTD bits are asserted */
273 	while (!mbx->ops.check_for_rst(hw, 0) && timeout) {
274 		timeout--;
275 		usec_delay(5);
276 	}
277 
278 	if (!timeout)
279 		return -E1000_ERR_RESET;
280 
281 	/* mailbox timeout can now become active */
282 	mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
283 
284 	/*
285 	 * Linux PFs return a three-dword, zero-filled NACK when the reset
286 	 * completed without an assigned MAC address.  FreeBSD PFs also use a
287 	 * one-dword NACK while retained queues are still being sanitized.  Seed
288 	 * the unused request payload so the two responses remain distinguishable.
289 	 */
290 	ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
291 	if (ret_val)
292 		return ret_val;
293 
294 	msec_delay(10);
295 
296 	/* set our "perm_addr" based on info provided by PF */
297 	ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
298 	if (!ret_val) {
299 		switch (msgbuf[0]) {
300 		case E1000_VF_RESET | E1000_VT_MSGTYPE_ACK:
301 			memcpy(hw->mac.perm_addr, addr, ETHER_ADDR_LEN);
302 			break;
303 		case E1000_VF_RESET | E1000_VT_MSGTYPE_NACK:
304 			if (msgbuf[1] == 0 && msgbuf[2] == 0)
305 				memset(hw->mac.perm_addr, 0, ETHER_ADDR_LEN);
306 			else
307 				ret_val = -E1000_ERR_MAC_INIT;
308 			break;
309 		default:
310 			ret_val = -E1000_ERR_MAC_INIT;
311 			break;
312 		}
313 	}
314 
315 	return ret_val;
316 }
317 
318 /**
319  *  e1000_init_hw_vf - Inits the HW
320  *  @hw: pointer to the HW structure
321  *
322  *  Not much to do here except clear the PF Reset indication if there is one.
323  **/
e1000_init_hw_vf(struct e1000_hw * hw)324 static s32 e1000_init_hw_vf(struct e1000_hw *hw)
325 {
326 	DEBUGFUNC("e1000_init_hw_vf");
327 
328 	/* attempt to set and restore our mac address */
329 	e1000_rar_set_vf(hw, hw->mac.addr, 0);
330 
331 	return E1000_SUCCESS;
332 }
333 
334 /**
335  *  e1000_rar_set_vf - set device MAC address
336  *  @hw: pointer to the HW structure
337  *  @addr: pointer to the receive address
338  *  @index receive address array register
339  **/
e1000_rar_set_vf(struct e1000_hw * hw,u8 * addr,u32 E1000_UNUSEDARG index)340 static int e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr,
341 			     u32 E1000_UNUSEDARG index)
342 {
343 	struct e1000_mbx_info *mbx = &hw->mbx;
344 	u32 msgbuf[3];
345 	u8 *msg_addr = (u8 *)(&msgbuf[1]);
346 	s32 ret_val;
347 
348 	memset(msgbuf, 0, 12);
349 	msgbuf[0] = E1000_VF_SET_MAC_ADDR;
350 	memcpy(msg_addr, addr, 6);
351 	ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
352 
353 	if (!ret_val)
354 		ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
355 
356 	msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
357 
358 	/* if nacked the address was rejected, use "perm_addr" */
359 	if (!ret_val &&
360 	    (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
361 		e1000_read_mac_addr_vf(hw);
362 
363 	return E1000_SUCCESS;
364 }
365 
366 /**
367  *  e1000_hash_mc_addr_vf - Generate a multicast hash value
368  *  @hw: pointer to the HW structure
369  *  @mc_addr: pointer to a multicast address
370  *
371  *  Generates a multicast address hash value which is used to determine
372  *  the multicast filter table array address and new table value.
373  **/
e1000_hash_mc_addr_vf(struct e1000_hw * hw,u8 * mc_addr)374 static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
375 {
376 	u32 hash_value, hash_mask;
377 	u8 bit_shift = 1;
378 
379 	DEBUGFUNC("e1000_hash_mc_addr_generic");
380 
381 	/* Register count multiplied by bits per register */
382 	hash_mask = (hw->mac.mta_reg_count * 32) - 1;
383 
384 	/*
385 	 * The bit_shift is the number of left-shifts
386 	 * where 0xFF would still fall within the hash mask.
387 	 */
388 	while (bit_shift < 4 && hash_mask >> bit_shift != 0xFF)
389 		bit_shift++;
390 
391 	hash_value = (u32)mc_addr[4];
392 	hash_value >>= 8 - bit_shift;
393 	hash_value |= (u32)mc_addr[5] << bit_shift;
394 	hash_value &= hash_mask;
395 
396 	return hash_value;
397 }
398 
e1000_write_msg_read_ack(struct e1000_hw * hw,u32 * msg,u16 size)399 static void e1000_write_msg_read_ack(struct e1000_hw *hw,
400 				     u32 *msg, u16 size)
401 {
402 	struct e1000_mbx_info *mbx = &hw->mbx;
403 	u32 retmsg[E1000_VFMAILBOX_SIZE];
404 	s32 retval = mbx->ops.write_posted(hw, msg, size, 0);
405 
406 	if (!retval)
407 		mbx->ops.read_posted(hw, retmsg, E1000_VFMAILBOX_SIZE, 0);
408 }
409 
410 /**
411  *  e1000_set_uc_addr_vf - Add or clear secondary unicast addresses
412  *  @hw: pointer to the HW structure
413  *  @sub_cmd: E1000_VF_MAC_FILTER_ADD or E1000_VF_MAC_FILTER_CLR
414  *  @addr: address to add, or a valid compatibility address when clearing
415  *
416  *  Uses the secondary-MAC mailbox subprotocol implemented by Linux igbvf.
417  *  Linux igb PFs validate this field before dispatching the clear subcommand,
418  *  even though they do not otherwise use it for a clear request.
419  **/
420 s32
e1000_set_uc_addr_vf(struct e1000_hw * hw,u32 sub_cmd,u8 * addr)421 e1000_set_uc_addr_vf(struct e1000_hw *hw, u32 sub_cmd, u8 *addr)
422 {
423 	struct e1000_mbx_info *mbx = &hw->mbx;
424 	u32 msgbuf[3] = {};
425 	u32 request;
426 	s32 ret_val;
427 
428 	msgbuf[0] = E1000_VF_SET_MAC_ADDR | sub_cmd;
429 	request = msgbuf[0];
430 	if (addr != NULL)
431 		memcpy(&msgbuf[1], addr, ETHER_ADDR_LEN);
432 
433 	ret_val = mbx->ops.write_posted(hw, msgbuf, 3, 0);
434 	if (ret_val == E1000_SUCCESS)
435 		ret_val = mbx->ops.read_posted(hw, msgbuf, 3, 0);
436 
437 	msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
438 	if (ret_val == E1000_SUCCESS &&
439 	    msgbuf[0] == (request | E1000_VT_MSGTYPE_NACK))
440 		ret_val = -E1000_ERR_NO_SPACE;
441 
442 	return (ret_val);
443 }
444 
445 /**
446  *  e1000_update_mc_addr_list_vf - Update Multicast addresses
447  *  @hw: pointer to the HW structure
448  *  @mc_addr_list: array of multicast addresses to program
449  *  @mc_addr_count: number of multicast addresses to program
450  *
451  *  Updates the Multicast Table Array.
452  *  The caller must have a packed mc_addr_list of multicast addresses.
453  **/
e1000_update_mc_addr_list_vf(struct e1000_hw * hw,u8 * mc_addr_list,u32 mc_addr_count)454 void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
455 				  u8 *mc_addr_list, u32 mc_addr_count)
456 {
457 	u32 msgbuf[E1000_VFMAILBOX_SIZE] = {};
458 	u16 *hash_list = (u16 *)&msgbuf[1];
459 	u32 hash_value;
460 	u32 i;
461 
462 	DEBUGFUNC("e1000_update_mc_addr_list_vf");
463 
464 	/* Each entry in the list uses 1 16 bit word.  We have 30
465 	 * 16 bit words available in our HW msg buffer (minus 1 for the
466 	 * msg type).  That's 30 hash values if we pack 'em right.  If
467 	 * there are more than 30 MC addresses to add then punt the
468 	 * extras for now and then add code to handle more than 30 later.
469 	 * It would be unusual for a server to request that many multi-cast
470 	 * addresses except for in large enterprise network environments.
471 	 */
472 
473 	DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
474 
475 	msgbuf[0] = E1000_VF_SET_MULTICAST;
476 
477 	if (mc_addr_count > 30) {
478 		msgbuf[0] |= E1000_VF_SET_MULTICAST_OVERFLOW;
479 		mc_addr_count = 30;
480 	}
481 
482 	msgbuf[0] |= mc_addr_count << E1000_VT_MSGINFO_SHIFT;
483 
484 	for (i = 0; i < mc_addr_count; i++) {
485 		hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
486 		DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
487 		hash_list[i] = hash_value & 0x0FFF;
488 		mc_addr_list += ETHER_ADDR_LEN;
489 	}
490 
491 	e1000_write_msg_read_ack(hw, msgbuf, E1000_VFMAILBOX_SIZE);
492 }
493 
494 /**
495  *  e1000_vfta_set_vf - Set/Unset vlan filter table address
496  *  @hw: pointer to the HW structure
497  *  @vid: determines the vfta register and bit to set/unset
498  *  @set: if true then set bit, else clear bit
499  *
500  *  Returns success if the PF accepted the request, or an error otherwise.
501  **/
e1000_vfta_set_vf(struct e1000_hw * hw,u16 vid,bool set)502 s32 e1000_vfta_set_vf(struct e1000_hw *hw, u16 vid, bool set)
503 {
504 	struct e1000_mbx_info *mbx = &hw->mbx;
505 	u32 msgbuf[2];
506 	s32 ret_val;
507 
508 	msgbuf[0] = E1000_VF_SET_VLAN;
509 	msgbuf[1] = vid;
510 	/* Setting the 8 bit field MSG INFO to true indicates "add" */
511 	if (set)
512 		msgbuf[0] |= E1000_VF_SET_VLAN_ADD;
513 
514 	ret_val = mbx->ops.write_posted(hw, msgbuf, 2, 0);
515 	if (!ret_val)
516 		ret_val = mbx->ops.read_posted(hw, msgbuf, 1, 0);
517 	if (!ret_val &&
518 	    ((msgbuf[0] & 0xffff) != E1000_VF_SET_VLAN ||
519 	    !(msgbuf[0] & E1000_VT_MSGTYPE_ACK)))
520 		ret_val = -E1000_ERR_MAC_INIT;
521 
522 	return (ret_val);
523 }
524 
525 /** e1000_rlpml_set_vf - Set the maximum receive packet length
526  *  @hw: pointer to the HW structure
527  *  @max_size: value to assign to max frame size
528  **/
e1000_rlpml_set_vf(struct e1000_hw * hw,u16 max_size)529 void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
530 {
531 	u32 msgbuf[2];
532 
533 	msgbuf[0] = E1000_VF_SET_LPE;
534 	msgbuf[1] = max_size;
535 
536 	e1000_write_msg_read_ack(hw, msgbuf, 2);
537 }
538 
539 /**
540  *  e1000_promisc_set_vf - Set flags for Unicast or Multicast promisc
541  *  @hw: pointer to the HW structure
542  *  @uni: boolean indicating unicast promisc status
543  *  @multi: boolean indicating multicast promisc status
544  **/
e1000_promisc_set_vf(struct e1000_hw * hw,enum e1000_promisc_type type)545 s32 e1000_promisc_set_vf(struct e1000_hw *hw, enum e1000_promisc_type type)
546 {
547 	struct e1000_mbx_info *mbx = &hw->mbx;
548 	u32 msgbuf = E1000_VF_SET_PROMISC;
549 	s32 ret_val;
550 
551 	switch (type) {
552 	case e1000_promisc_multicast:
553 		msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
554 		break;
555 	case e1000_promisc_enabled:
556 		msgbuf |= E1000_VF_SET_PROMISC_MULTICAST;
557 		/* FALLTHROUGH */
558 	case e1000_promisc_unicast:
559 		msgbuf |= E1000_VF_SET_PROMISC_UNICAST;
560 		/* FALLTHROUGH */
561 	case e1000_promisc_disabled:
562 		break;
563 	default:
564 		return -E1000_ERR_MAC_INIT;
565 	}
566 
567 	 ret_val = mbx->ops.write_posted(hw, &msgbuf, 1, 0);
568 
569 	if (!ret_val)
570 		ret_val = mbx->ops.read_posted(hw, &msgbuf, 1, 0);
571 
572 	if (!ret_val && !(msgbuf & E1000_VT_MSGTYPE_ACK))
573 		ret_val = -E1000_ERR_MAC_INIT;
574 
575 	return ret_val;
576 }
577 
578 /**
579  *  e1000_read_mac_addr_vf - Read device MAC address
580  *  @hw: pointer to the HW structure
581  **/
e1000_read_mac_addr_vf(struct e1000_hw * hw)582 static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
583 {
584 	int i;
585 
586 	for (i = 0; i < ETHER_ADDR_LEN; i++)
587 		hw->mac.addr[i] = hw->mac.perm_addr[i];
588 
589 	return E1000_SUCCESS;
590 }
591 
592 /**
593  *  e1000_check_for_link_vf - Check for link for a virtual interface
594  *  @hw: pointer to the HW structure
595  *
596  *  Checks to see if the underlying PF is still talking to the VF and
597  *  if it is then it reports the link state to the hardware, otherwise
598  *  it reports link down and returns an error.
599  **/
e1000_check_for_link_vf(struct e1000_hw * hw)600 static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
601 {
602 	struct e1000_mbx_info *mbx = &hw->mbx;
603 	struct e1000_mac_info *mac = &hw->mac;
604 	s32 ret_val = E1000_SUCCESS;
605 	u32 in_msg = 0;
606 
607 	DEBUGFUNC("e1000_check_for_link_vf");
608 
609 	/*
610 	 * We only want to run this if there has been a rst asserted.
611 	 * in this case that could mean a link change, device reset,
612 	 * or a virtual function reset
613 	 */
614 
615 	/* If we were hit with a reset or timeout drop the link */
616 	if (!mbx->ops.check_for_rst(hw, 0) || !mbx->timeout)
617 		mac->get_link_status = true;
618 
619 	if (!mac->get_link_status)
620 		goto out;
621 
622 	/* if link status is down no point in checking to see if pf is up */
623 	if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU))
624 		goto out;
625 
626 	/* if the read failed it could just be a mailbox collision, best wait
627 	 * until we are called again and don't report an error */
628 	if (mbx->ops.read(hw, &in_msg, 1, 0, true))
629 		goto out;
630 
631 	/* if incoming message isn't clear to send we are waiting on response */
632 	if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
633 		/*
634 		 * A NACK or a PF control message without CTS means that the PF
635 		 * discarded our state and requires a new VF reset handshake.
636 		 */
637 		if ((in_msg & E1000_VT_MSGTYPE_NACK) != 0 ||
638 		    (in_msg & 0xffff) == E1000_PF_CONTROL_MSG)
639 			ret_val = -E1000_ERR_MAC_INIT;
640 		goto out;
641 	}
642 
643 	/* at this point we know the PF is talking to us, check and see if
644 	 * we are still accepting timeout or if we had a timeout failure.
645 	 * if we failed then we will need to reinit */
646 	if (!mbx->timeout) {
647 		ret_val = -E1000_ERR_MAC_INIT;
648 		goto out;
649 	}
650 
651 	/* if we passed all the tests above then the link is up and we no
652 	 * longer need to check for link */
653 	mac->get_link_status = false;
654 
655 out:
656 	return ret_val;
657 }
658