Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/* Copyright(c) 2009 - 2018 Intel Corporation. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  3
  4#include "vf.h"
  5
  6static s32 e1000_check_for_link_vf(struct e1000_hw *hw);
  7static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
  8				     u16 *duplex);
  9static s32 e1000_init_hw_vf(struct e1000_hw *hw);
 10static s32 e1000_reset_hw_vf(struct e1000_hw *hw);
 11
 12static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *,
 13					 u32, u32, u32);
 14static void e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
 15static s32 e1000_read_mac_addr_vf(struct e1000_hw *);
 16static s32 e1000_set_uc_addr_vf(struct e1000_hw *hw, u32 subcmd, u8 *addr);
 17static s32 e1000_set_vfta_vf(struct e1000_hw *, u16, bool);
 18
 19/**
 20 *  e1000_init_mac_params_vf - Inits MAC params
 21 *  @hw: pointer to the HW structure
 22 **/
 23static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
 24{
 25	struct e1000_mac_info *mac = &hw->mac;
 26
 27	/* VF's have no MTA Registers - PF feature only */
 28	mac->mta_reg_count = 128;
 29	/* VF's have no access to RAR entries  */
 30	mac->rar_entry_count = 1;
 31
 32	/* Function pointers */
 33	/* reset */
 34	mac->ops.reset_hw = e1000_reset_hw_vf;
 35	/* hw initialization */
 36	mac->ops.init_hw = e1000_init_hw_vf;
 37	/* check for link */
 38	mac->ops.check_for_link = e1000_check_for_link_vf;
 39	/* link info */
 40	mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
 41	/* multicast address update */
 42	mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
 43	/* set mac address */
 44	mac->ops.rar_set = e1000_rar_set_vf;
 45	/* read mac address */
 46	mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
 47	/* set mac filter */
 48	mac->ops.set_uc_addr = e1000_set_uc_addr_vf;
 49	/* set vlan filter table array */
 50	mac->ops.set_vfta = e1000_set_vfta_vf;
 51
 52	return E1000_SUCCESS;
 53}
 54
 55/**
 56 *  e1000_init_function_pointers_vf - Inits function pointers
 57 *  @hw: pointer to the HW structure
 58 **/
 59void e1000_init_function_pointers_vf(struct e1000_hw *hw)
 60{
 61	hw->mac.ops.init_params = e1000_init_mac_params_vf;
 62	hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
 63}
 64
 65/**
 66 *  e1000_get_link_up_info_vf - Gets link info.
 67 *  @hw: pointer to the HW structure
 68 *  @speed: pointer to 16 bit value to store link speed.
 69 *  @duplex: pointer to 16 bit value to store duplex.
 70 *
 71 *  Since we cannot read the PHY and get accurate link info, we must rely upon
 72 *  the status register's data which is often stale and inaccurate.
 73 **/
 74static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
 75				     u16 *duplex)
 76{
 77	s32 status;
 78
 79	status = er32(STATUS);
 80	if (status & E1000_STATUS_SPEED_1000)
 81		*speed = SPEED_1000;
 82	else if (status & E1000_STATUS_SPEED_100)
 83		*speed = SPEED_100;
 84	else
 85		*speed = SPEED_10;
 86
 87	if (status & E1000_STATUS_FD)
 88		*duplex = FULL_DUPLEX;
 89	else
 90		*duplex = HALF_DUPLEX;
 91
 92	return E1000_SUCCESS;
 93}
 94
 95/**
 96 *  e1000_reset_hw_vf - Resets the HW
 97 *  @hw: pointer to the HW structure
 98 *
 99 *  VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
100 *  This is all the reset we can perform on a VF.
101 **/
102static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
103{
104	struct e1000_mbx_info *mbx = &hw->mbx;
105	u32 timeout = E1000_VF_INIT_TIMEOUT;
106	u32 ret_val = -E1000_ERR_MAC_INIT;
107	u32 msgbuf[3];
108	u8 *addr = (u8 *)(&msgbuf[1]);
109	u32 ctrl;
110
111	/* assert VF queue/interrupt reset */
112	ctrl = er32(CTRL);
113	ew32(CTRL, ctrl | E1000_CTRL_RST);
114
115	/* we cannot initialize while the RSTI / RSTD bits are asserted */
116	while (!mbx->ops.check_for_rst(hw) && timeout) {
117		timeout--;
118		udelay(5);
119	}
120
121	if (timeout) {
122		/* mailbox timeout can now become active */
123		mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
124
125		/* notify PF of VF reset completion */
126		msgbuf[0] = E1000_VF_RESET;
127		mbx->ops.write_posted(hw, msgbuf, 1);
128
129		mdelay(10);
130
131		/* set our "perm_addr" based on info provided by PF */
132		ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
133		if (!ret_val) {
134			if (msgbuf[0] == (E1000_VF_RESET |
135					  E1000_VT_MSGTYPE_ACK))
136				memcpy(hw->mac.perm_addr, addr, ETH_ALEN);
137			else
138				ret_val = -E1000_ERR_MAC_INIT;
139		}
140	}
141
142	return ret_val;
143}
144
145/**
146 *  e1000_init_hw_vf - Inits the HW
147 *  @hw: pointer to the HW structure
148 *
149 *  Not much to do here except clear the PF Reset indication if there is one.
150 **/
151static s32 e1000_init_hw_vf(struct e1000_hw *hw)
152{
153	/* attempt to set and restore our mac address */
154	e1000_rar_set_vf(hw, hw->mac.addr, 0);
155
156	return E1000_SUCCESS;
157}
158
159/**
160 *  e1000_hash_mc_addr_vf - Generate a multicast hash value
161 *  @hw: pointer to the HW structure
162 *  @mc_addr: pointer to a multicast address
163 *
164 *  Generates a multicast address hash value which is used to determine
165 *  the multicast filter table array address and new table value.  See
166 *  e1000_mta_set_generic()
167 **/
168static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
169{
170	u32 hash_value, hash_mask;
171	u8 bit_shift = 0;
172
173	/* Register count multiplied by bits per register */
174	hash_mask = (hw->mac.mta_reg_count * 32) - 1;
175
176	/* The bit_shift is the number of left-shifts
 
177	 * where 0xFF would still fall within the hash mask.
178	 */
179	while (hash_mask >> bit_shift != 0xFF)
180		bit_shift++;
181
182	hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
183				  (((u16)mc_addr[5]) << bit_shift)));
184
185	return hash_value;
186}
187
188/**
189 *  e1000_update_mc_addr_list_vf - Update Multicast addresses
190 *  @hw: pointer to the HW structure
191 *  @mc_addr_list: array of multicast addresses to program
192 *  @mc_addr_count: number of multicast addresses to program
193 *  @rar_used_count: the first RAR register free to program
194 *  @rar_count: total number of supported Receive Address Registers
195 *
196 *  Updates the Receive Address Registers and Multicast Table Array.
197 *  The caller must have a packed mc_addr_list of multicast addresses.
198 *  The parameter rar_count will usually be hw->mac.rar_entry_count
199 *  unless there are workarounds that change this.
200 **/
201static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
202					 u8 *mc_addr_list, u32 mc_addr_count,
203					 u32 rar_used_count, u32 rar_count)
204{
205	struct e1000_mbx_info *mbx = &hw->mbx;
206	u32 msgbuf[E1000_VFMAILBOX_SIZE];
207	u16 *hash_list = (u16 *)&msgbuf[1];
208	u32 hash_value;
209	u32 cnt, i;
210	s32 ret_val;
211
212	/* Each entry in the list uses 1 16 bit word.  We have 30
213	 * 16 bit words available in our HW msg buffer (minus 1 for the
214	 * msg type).  That's 30 hash values if we pack 'em right.  If
215	 * there are more than 30 MC addresses to add then punt the
216	 * extras for now and then add code to handle more than 30 later.
217	 * It would be unusual for a server to request that many multi-cast
218	 * addresses except for in large enterprise network environments.
219	 */
220
221	cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
222	msgbuf[0] = E1000_VF_SET_MULTICAST;
223	msgbuf[0] |= cnt << E1000_VT_MSGINFO_SHIFT;
224
225	for (i = 0; i < cnt; i++) {
226		hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
227		hash_list[i] = hash_value & 0x0FFFF;
228		mc_addr_list += ETH_ALEN;
229	}
230
231	ret_val = mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE);
232	if (!ret_val)
233		mbx->ops.read_posted(hw, msgbuf, 1);
234}
235
236/**
237 *  e1000_set_vfta_vf - Set/Unset vlan filter table address
238 *  @hw: pointer to the HW structure
239 *  @vid: determines the vfta register and bit to set/unset
240 *  @set: if true then set bit, else clear bit
241 **/
242static s32 e1000_set_vfta_vf(struct e1000_hw *hw, u16 vid, bool set)
243{
244	struct e1000_mbx_info *mbx = &hw->mbx;
245	u32 msgbuf[2];
246	s32 err;
247
248	msgbuf[0] = E1000_VF_SET_VLAN;
249	msgbuf[1] = vid;
250	/* Setting the 8 bit field MSG INFO to true indicates "add" */
251	if (set)
252		msgbuf[0] |= BIT(E1000_VT_MSGINFO_SHIFT);
253
254	mbx->ops.write_posted(hw, msgbuf, 2);
255
256	err = mbx->ops.read_posted(hw, msgbuf, 2);
257
258	msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
259
260	/* if nacked the vlan was rejected */
261	if (!err && (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK)))
262		err = -E1000_ERR_MAC_INIT;
263
264	return err;
265}
266
267/**
268 *  e1000_rlpml_set_vf - Set the maximum receive packet length
269 *  @hw: pointer to the HW structure
270 *  @max_size: value to assign to max frame size
271 **/
272void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
273{
274	struct e1000_mbx_info *mbx = &hw->mbx;
275	u32 msgbuf[2];
276	s32 ret_val;
277
278	msgbuf[0] = E1000_VF_SET_LPE;
279	msgbuf[1] = max_size;
280
281	ret_val = mbx->ops.write_posted(hw, msgbuf, 2);
282	if (!ret_val)
283		mbx->ops.read_posted(hw, msgbuf, 1);
284}
285
286/**
287 *  e1000_rar_set_vf - set device MAC address
288 *  @hw: pointer to the HW structure
289 *  @addr: pointer to the receive address
290 *  @index: receive address array register
291 **/
292static void e1000_rar_set_vf(struct e1000_hw *hw, u8 *addr, u32 index)
293{
294	struct e1000_mbx_info *mbx = &hw->mbx;
295	u32 msgbuf[3];
296	u8 *msg_addr = (u8 *)(&msgbuf[1]);
297	s32 ret_val;
298
299	memset(msgbuf, 0, 12);
300	msgbuf[0] = E1000_VF_SET_MAC_ADDR;
301	memcpy(msg_addr, addr, ETH_ALEN);
302	ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
303
304	if (!ret_val)
305		ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
306
307	msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
308
309	/* if nacked the address was rejected, use "perm_addr" */
310	if (!ret_val &&
311	    (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
312		e1000_read_mac_addr_vf(hw);
313}
314
315/**
316 *  e1000_read_mac_addr_vf - Read device MAC address
317 *  @hw: pointer to the HW structure
318 **/
319static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
320{
321	memcpy(hw->mac.addr, hw->mac.perm_addr, ETH_ALEN);
322
323	return E1000_SUCCESS;
324}
325
326/**
327 *  e1000_set_uc_addr_vf - Set or clear unicast filters
328 *  @hw: pointer to the HW structure
329 *  @sub_cmd: add or clear filters
330 *  @addr: pointer to the filter MAC address
331 **/
332static s32 e1000_set_uc_addr_vf(struct e1000_hw *hw, u32 sub_cmd, u8 *addr)
333{
334	struct e1000_mbx_info *mbx = &hw->mbx;
335	u32 msgbuf[3], msgbuf_chk;
336	u8 *msg_addr = (u8 *)(&msgbuf[1]);
337	s32 ret_val;
338
339	memset(msgbuf, 0, sizeof(msgbuf));
340	msgbuf[0] |= sub_cmd;
341	msgbuf[0] |= E1000_VF_SET_MAC_ADDR;
342	msgbuf_chk = msgbuf[0];
343
344	if (addr)
345		memcpy(msg_addr, addr, ETH_ALEN);
346
347	ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
348
349	if (!ret_val)
350		ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
351
352	msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
353
354	if (!ret_val) {
355		msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
356
357		if (msgbuf[0] == (msgbuf_chk | E1000_VT_MSGTYPE_NACK))
358			return -ENOSPC;
359	}
360
361	return ret_val;
362}
363
364/**
365 *  e1000_check_for_link_vf - Check for link for a virtual interface
366 *  @hw: pointer to the HW structure
367 *
368 *  Checks to see if the underlying PF is still talking to the VF and
369 *  if it is then it reports the link state to the hardware, otherwise
370 *  it reports link down and returns an error.
371 **/
372static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
373{
374	struct e1000_mbx_info *mbx = &hw->mbx;
375	struct e1000_mac_info *mac = &hw->mac;
376	s32 ret_val = E1000_SUCCESS;
377	u32 in_msg = 0;
378
379	/* We only want to run this if there has been a rst asserted.
 
380	 * in this case that could mean a link change, device reset,
381	 * or a virtual function reset
382	 */
383
384	/* If we were hit with a reset or timeout drop the link */
385	if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
386		mac->get_link_status = true;
387
388	if (!mac->get_link_status)
389		goto out;
390
391	/* if link status is down no point in checking to see if PF is up */
392	if (!(er32(STATUS) & E1000_STATUS_LU))
393		goto out;
394
395	/* if the read failed it could just be a mailbox collision, best wait
396	 * until we are called again and don't report an error
397	 */
398	if (mbx->ops.read(hw, &in_msg, 1))
399		goto out;
400
401	/* if incoming message isn't clear to send we are waiting on response */
402	if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
403		/* msg is not CTS and is NACK we must have lost CTS status */
404		if (in_msg & E1000_VT_MSGTYPE_NACK)
405			ret_val = -E1000_ERR_MAC_INIT;
406		goto out;
407	}
408
409	/* the PF is talking, if we timed out in the past we reinit */
410	if (!mbx->timeout) {
411		ret_val = -E1000_ERR_MAC_INIT;
412		goto out;
413	}
414
415	/* if we passed all the tests above then the link is up and we no
416	 * longer need to check for link
417	 */
418	mac->get_link_status = false;
419
420out:
421	return ret_val;
422}
423
v3.15
  1/*******************************************************************************
  2
  3  Intel(R) 82576 Virtual Function Linux driver
  4  Copyright(c) 2009 - 2012 Intel Corporation.
  5
  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.
  9
 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
 13  more details.
 14
 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.
 18
 19  The full GNU General Public License is included in this distribution in
 20  the file called "COPYING".
 21
 22  Contact Information:
 23  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
 24  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
 25
 26*******************************************************************************/
 27
 28
 29#include "vf.h"
 30
 31static s32 e1000_check_for_link_vf(struct e1000_hw *hw);
 32static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
 33                                     u16 *duplex);
 34static s32 e1000_init_hw_vf(struct e1000_hw *hw);
 35static s32 e1000_reset_hw_vf(struct e1000_hw *hw);
 36
 37static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw, u8 *,
 38                                         u32, u32, u32);
 39static void e1000_rar_set_vf(struct e1000_hw *, u8 *, u32);
 40static s32 e1000_read_mac_addr_vf(struct e1000_hw *);
 
 41static s32 e1000_set_vfta_vf(struct e1000_hw *, u16, bool);
 42
 43/**
 44 *  e1000_init_mac_params_vf - Inits MAC params
 45 *  @hw: pointer to the HW structure
 46 **/
 47static s32 e1000_init_mac_params_vf(struct e1000_hw *hw)
 48{
 49	struct e1000_mac_info *mac = &hw->mac;
 50
 51	/* VF's have no MTA Registers - PF feature only */
 52	mac->mta_reg_count = 128;
 53	/* VF's have no access to RAR entries  */
 54	mac->rar_entry_count = 1;
 55
 56	/* Function pointers */
 57	/* reset */
 58	mac->ops.reset_hw = e1000_reset_hw_vf;
 59	/* hw initialization */
 60	mac->ops.init_hw = e1000_init_hw_vf;
 61	/* check for link */
 62	mac->ops.check_for_link = e1000_check_for_link_vf;
 63	/* link info */
 64	mac->ops.get_link_up_info = e1000_get_link_up_info_vf;
 65	/* multicast address update */
 66	mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_vf;
 67	/* set mac address */
 68	mac->ops.rar_set = e1000_rar_set_vf;
 69	/* read mac address */
 70	mac->ops.read_mac_addr = e1000_read_mac_addr_vf;
 
 
 71	/* set vlan filter table array */
 72	mac->ops.set_vfta = e1000_set_vfta_vf;
 73
 74	return E1000_SUCCESS;
 75}
 76
 77/**
 78 *  e1000_init_function_pointers_vf - Inits function pointers
 79 *  @hw: pointer to the HW structure
 80 **/
 81void e1000_init_function_pointers_vf(struct e1000_hw *hw)
 82{
 83	hw->mac.ops.init_params = e1000_init_mac_params_vf;
 84	hw->mbx.ops.init_params = e1000_init_mbx_params_vf;
 85}
 86
 87/**
 88 *  e1000_get_link_up_info_vf - Gets link info.
 89 *  @hw: pointer to the HW structure
 90 *  @speed: pointer to 16 bit value to store link speed.
 91 *  @duplex: pointer to 16 bit value to store duplex.
 92 *
 93 *  Since we cannot read the PHY and get accurate link info, we must rely upon
 94 *  the status register's data which is often stale and inaccurate.
 95 **/
 96static s32 e1000_get_link_up_info_vf(struct e1000_hw *hw, u16 *speed,
 97                                     u16 *duplex)
 98{
 99	s32 status;
100
101	status = er32(STATUS);
102	if (status & E1000_STATUS_SPEED_1000)
103		*speed = SPEED_1000;
104	else if (status & E1000_STATUS_SPEED_100)
105		*speed = SPEED_100;
106	else
107		*speed = SPEED_10;
108
109	if (status & E1000_STATUS_FD)
110		*duplex = FULL_DUPLEX;
111	else
112		*duplex = HALF_DUPLEX;
113
114	return E1000_SUCCESS;
115}
116
117/**
118 *  e1000_reset_hw_vf - Resets the HW
119 *  @hw: pointer to the HW structure
120 *
121 *  VF's provide a function level reset. This is done using bit 26 of ctrl_reg.
122 *  This is all the reset we can perform on a VF.
123 **/
124static s32 e1000_reset_hw_vf(struct e1000_hw *hw)
125{
126	struct e1000_mbx_info *mbx = &hw->mbx;
127	u32 timeout = E1000_VF_INIT_TIMEOUT;
128	u32 ret_val = -E1000_ERR_MAC_INIT;
129	u32 msgbuf[3];
130	u8 *addr = (u8 *)(&msgbuf[1]);
131	u32 ctrl;
132
133	/* assert vf queue/interrupt reset */
134	ctrl = er32(CTRL);
135	ew32(CTRL, ctrl | E1000_CTRL_RST);
136
137	/* we cannot initialize while the RSTI / RSTD bits are asserted */
138	while (!mbx->ops.check_for_rst(hw) && timeout) {
139		timeout--;
140		udelay(5);
141	}
142
143	if (timeout) {
144		/* mailbox timeout can now become active */
145		mbx->timeout = E1000_VF_MBX_INIT_TIMEOUT;
146
147		/* notify pf of vf reset completion */
148		msgbuf[0] = E1000_VF_RESET;
149		mbx->ops.write_posted(hw, msgbuf, 1);
150
151		msleep(10);
152
153		/* set our "perm_addr" based on info provided by PF */
154		ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
155		if (!ret_val) {
156			if (msgbuf[0] == (E1000_VF_RESET | E1000_VT_MSGTYPE_ACK))
 
157				memcpy(hw->mac.perm_addr, addr, ETH_ALEN);
158			else
159				ret_val = -E1000_ERR_MAC_INIT;
160		}
161	}
162
163	return ret_val;
164}
165
166/**
167 *  e1000_init_hw_vf - Inits the HW
168 *  @hw: pointer to the HW structure
169 *
170 *  Not much to do here except clear the PF Reset indication if there is one.
171 **/
172static s32 e1000_init_hw_vf(struct e1000_hw *hw)
173{
174	/* attempt to set and restore our mac address */
175	e1000_rar_set_vf(hw, hw->mac.addr, 0);
176
177	return E1000_SUCCESS;
178}
179
180/**
181 *  e1000_hash_mc_addr_vf - Generate a multicast hash value
182 *  @hw: pointer to the HW structure
183 *  @mc_addr: pointer to a multicast address
184 *
185 *  Generates a multicast address hash value which is used to determine
186 *  the multicast filter table array address and new table value.  See
187 *  e1000_mta_set_generic()
188 **/
189static u32 e1000_hash_mc_addr_vf(struct e1000_hw *hw, u8 *mc_addr)
190{
191	u32 hash_value, hash_mask;
192	u8 bit_shift = 0;
193
194	/* Register count multiplied by bits per register */
195	hash_mask = (hw->mac.mta_reg_count * 32) - 1;
196
197	/*
198	 * The bit_shift is the number of left-shifts
199	 * where 0xFF would still fall within the hash mask.
200	 */
201	while (hash_mask >> bit_shift != 0xFF)
202		bit_shift++;
203
204	hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
205	                          (((u16) mc_addr[5]) << bit_shift)));
206
207	return hash_value;
208}
209
210/**
211 *  e1000_update_mc_addr_list_vf - Update Multicast addresses
212 *  @hw: pointer to the HW structure
213 *  @mc_addr_list: array of multicast addresses to program
214 *  @mc_addr_count: number of multicast addresses to program
215 *  @rar_used_count: the first RAR register free to program
216 *  @rar_count: total number of supported Receive Address Registers
217 *
218 *  Updates the Receive Address Registers and Multicast Table Array.
219 *  The caller must have a packed mc_addr_list of multicast addresses.
220 *  The parameter rar_count will usually be hw->mac.rar_entry_count
221 *  unless there are workarounds that change this.
222 **/
223static void e1000_update_mc_addr_list_vf(struct e1000_hw *hw,
224                                  u8 *mc_addr_list, u32 mc_addr_count,
225                                  u32 rar_used_count, u32 rar_count)
226{
227	struct e1000_mbx_info *mbx = &hw->mbx;
228	u32 msgbuf[E1000_VFMAILBOX_SIZE];
229	u16 *hash_list = (u16 *)&msgbuf[1];
230	u32 hash_value;
231	u32 cnt, i;
 
232
233	/* Each entry in the list uses 1 16 bit word.  We have 30
234	 * 16 bit words available in our HW msg buffer (minus 1 for the
235	 * msg type).  That's 30 hash values if we pack 'em right.  If
236	 * there are more than 30 MC addresses to add then punt the
237	 * extras for now and then add code to handle more than 30 later.
238	 * It would be unusual for a server to request that many multi-cast
239	 * addresses except for in large enterprise network environments.
240	 */
241
242	cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;
243	msgbuf[0] = E1000_VF_SET_MULTICAST;
244	msgbuf[0] |= cnt << E1000_VT_MSGINFO_SHIFT;
245
246	for (i = 0; i < cnt; i++) {
247		hash_value = e1000_hash_mc_addr_vf(hw, mc_addr_list);
248		hash_list[i] = hash_value & 0x0FFFF;
249		mc_addr_list += ETH_ALEN;
250	}
251
252	mbx->ops.write_posted(hw, msgbuf, E1000_VFMAILBOX_SIZE);
 
 
253}
254
255/**
256 *  e1000_set_vfta_vf - Set/Unset vlan filter table address
257 *  @hw: pointer to the HW structure
258 *  @vid: determines the vfta register and bit to set/unset
259 *  @set: if true then set bit, else clear bit
260 **/
261static s32 e1000_set_vfta_vf(struct e1000_hw *hw, u16 vid, bool set)
262{
263	struct e1000_mbx_info *mbx = &hw->mbx;
264	u32 msgbuf[2];
265	s32 err;
266
267	msgbuf[0] = E1000_VF_SET_VLAN;
268	msgbuf[1] = vid;
269	/* Setting the 8 bit field MSG INFO to true indicates "add" */
270	if (set)
271		msgbuf[0] |= 1 << E1000_VT_MSGINFO_SHIFT;
272
273	mbx->ops.write_posted(hw, msgbuf, 2);
274
275	err = mbx->ops.read_posted(hw, msgbuf, 2);
276
277	msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
278
279	/* if nacked the vlan was rejected */
280	if (!err && (msgbuf[0] == (E1000_VF_SET_VLAN | E1000_VT_MSGTYPE_NACK)))
281		err = -E1000_ERR_MAC_INIT;
282
283	return err;
284}
285
286/**
287 *  e1000_rlpml_set_vf - Set the maximum receive packet length
288 *  @hw: pointer to the HW structure
289 *  @max_size: value to assign to max frame size
290 **/
291void e1000_rlpml_set_vf(struct e1000_hw *hw, u16 max_size)
292{
293	struct e1000_mbx_info *mbx = &hw->mbx;
294	u32 msgbuf[2];
 
295
296	msgbuf[0] = E1000_VF_SET_LPE;
297	msgbuf[1] = max_size;
298
299	mbx->ops.write_posted(hw, msgbuf, 2);
 
 
300}
301
302/**
303 *  e1000_rar_set_vf - set device MAC address
304 *  @hw: pointer to the HW structure
305 *  @addr: pointer to the receive address
306 *  @index: receive address array register
307 **/
308static void e1000_rar_set_vf(struct e1000_hw *hw, u8 * addr, u32 index)
309{
310	struct e1000_mbx_info *mbx = &hw->mbx;
311	u32 msgbuf[3];
312	u8 *msg_addr = (u8 *)(&msgbuf[1]);
313	s32 ret_val;
314
315	memset(msgbuf, 0, 12);
316	msgbuf[0] = E1000_VF_SET_MAC_ADDR;
317	memcpy(msg_addr, addr, ETH_ALEN);
318	ret_val = mbx->ops.write_posted(hw, msgbuf, 3);
319
320	if (!ret_val)
321		ret_val = mbx->ops.read_posted(hw, msgbuf, 3);
322
323	msgbuf[0] &= ~E1000_VT_MSGTYPE_CTS;
324
325	/* if nacked the address was rejected, use "perm_addr" */
326	if (!ret_val &&
327	    (msgbuf[0] == (E1000_VF_SET_MAC_ADDR | E1000_VT_MSGTYPE_NACK)))
328		e1000_read_mac_addr_vf(hw);
329}
330
331/**
332 *  e1000_read_mac_addr_vf - Read device MAC address
333 *  @hw: pointer to the HW structure
334 **/
335static s32 e1000_read_mac_addr_vf(struct e1000_hw *hw)
336{
337	memcpy(hw->mac.addr, hw->mac.perm_addr, ETH_ALEN);
338
339	return E1000_SUCCESS;
340}
341
342/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343 *  e1000_check_for_link_vf - Check for link for a virtual interface
344 *  @hw: pointer to the HW structure
345 *
346 *  Checks to see if the underlying PF is still talking to the VF and
347 *  if it is then it reports the link state to the hardware, otherwise
348 *  it reports link down and returns an error.
349 **/
350static s32 e1000_check_for_link_vf(struct e1000_hw *hw)
351{
352	struct e1000_mbx_info *mbx = &hw->mbx;
353	struct e1000_mac_info *mac = &hw->mac;
354	s32 ret_val = E1000_SUCCESS;
355	u32 in_msg = 0;
356
357	/*
358	 * We only want to run this if there has been a rst asserted.
359	 * in this case that could mean a link change, device reset,
360	 * or a virtual function reset
361	 */
362
363	/* If we were hit with a reset or timeout drop the link */
364	if (!mbx->ops.check_for_rst(hw) || !mbx->timeout)
365		mac->get_link_status = true;
366
367	if (!mac->get_link_status)
368		goto out;
369
370	/* if link status is down no point in checking to see if pf is up */
371	if (!(er32(STATUS) & E1000_STATUS_LU))
372		goto out;
373
374	/* if the read failed it could just be a mailbox collision, best wait
375	 * until we are called again and don't report an error */
 
376	if (mbx->ops.read(hw, &in_msg, 1))
377		goto out;
378
379	/* if incoming message isn't clear to send we are waiting on response */
380	if (!(in_msg & E1000_VT_MSGTYPE_CTS)) {
381		/* message is not CTS and is NACK we must have lost CTS status */
382		if (in_msg & E1000_VT_MSGTYPE_NACK)
383			ret_val = -E1000_ERR_MAC_INIT;
384		goto out;
385	}
386
387	/* the pf is talking, if we timed out in the past we reinit */
388	if (!mbx->timeout) {
389		ret_val = -E1000_ERR_MAC_INIT;
390		goto out;
391	}
392
393	/* if we passed all the tests above then the link is up and we no
394	 * longer need to check for link */
 
395	mac->get_link_status = false;
396
397out:
398	return ret_val;
399}
400