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