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